OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/panels/panel_view.h" | 5 #include "chrome/browser/ui/panels/panel_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/app/chrome_command_ids.h" | |
9 #include "chrome/browser/ui/panels/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
10 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 9 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
11 #include "chrome/browser/ui/panels/panel_frame_view.h" | 10 #include "chrome/browser/ui/panels/panel_frame_view.h" |
12 #include "chrome/browser/ui/panels/panel_manager.h" | 11 #include "chrome/browser/ui/panels/panel_manager.h" |
13 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
15 #include "ui/gfx/path.h" | 14 #include "ui/gfx/path.h" |
16 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
17 #include "ui/views/controls/button/image_button.h" | 16 #include "ui/views/controls/button/image_button.h" |
18 #include "ui/views/controls/webview/webview.h" | 17 #include "ui/views/controls/webview/webview.h" |
19 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
20 | 19 |
21 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) | 20 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) |
22 #include "base/win/windows_version.h" | 21 #include "base/win/windows_version.h" |
23 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" | 22 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" |
24 #endif | 23 #endif |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 // Supported accelerators. | |
29 // Note: We can't use the acclerator table defined in chrome/browser/ui/views | |
30 // due to checkdeps violation. | |
31 struct AcceleratorMapping { | |
32 ui::KeyboardCode keycode; | |
33 int modifiers; | |
34 int command_id; | |
35 }; | |
36 const AcceleratorMapping kPanelAcceleratorMap[] = { | |
37 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | |
38 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | |
39 { ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW }, | |
40 { ui::VKEY_R, ui::EF_CONTROL_DOWN, IDC_RELOAD }, | |
41 { ui::VKEY_F5, ui::EF_NONE, IDC_RELOAD }, | |
42 { ui::VKEY_R, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, | |
43 IDC_RELOAD_IGNORING_CACHE }, | |
44 { ui::VKEY_F5, ui::EF_CONTROL_DOWN, IDC_RELOAD_IGNORING_CACHE }, | |
45 { ui::VKEY_F5, ui::EF_SHIFT_DOWN, IDC_RELOAD_IGNORING_CACHE }, | |
46 { ui::VKEY_ESCAPE, ui::EF_NONE, IDC_STOP }, | |
47 { ui::VKEY_OEM_MINUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, | |
48 { ui::VKEY_SUBTRACT, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, | |
49 { ui::VKEY_0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, | |
50 { ui::VKEY_NUMPAD0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, | |
51 { ui::VKEY_OEM_PLUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
52 { ui::VKEY_ADD, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
53 }; | |
54 | |
55 // NativePanelTesting implementation. | 27 // NativePanelTesting implementation. |
56 class NativePanelTestingWin : public NativePanelTesting { | 28 class NativePanelTestingWin : public NativePanelTesting { |
57 public: | 29 public: |
58 explicit NativePanelTestingWin(PanelView* panel_view); | 30 explicit NativePanelTestingWin(PanelView* panel_view); |
59 | 31 |
60 private: | 32 private: |
61 virtual void PressLeftMouseButtonTitlebar( | 33 virtual void PressLeftMouseButtonTitlebar( |
62 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 34 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
63 virtual void ReleaseMouseButtonTitlebar( | 35 virtual void ReleaseMouseButtonTitlebar( |
64 panel::ClickModifier modifier) OVERRIDE; | 36 panel::ClickModifier modifier) OVERRIDE; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 return false; | 109 return false; |
138 } | 110 } |
139 | 111 |
140 } // namespace | 112 } // namespace |
141 | 113 |
142 // static | 114 // static |
143 NativePanel* Panel::CreateNativePanel(Panel* panel, const gfx::Rect& bounds) { | 115 NativePanel* Panel::CreateNativePanel(Panel* panel, const gfx::Rect& bounds) { |
144 return new PanelView(panel, bounds); | 116 return new PanelView(panel, bounds); |
145 } | 117 } |
146 | 118 |
147 // static | |
148 std::map<ui::Accelerator, int> PanelView::accelerator_table_; | |
149 | |
150 PanelView::PanelView(Panel* panel, const gfx::Rect& bounds) | 119 PanelView::PanelView(Panel* panel, const gfx::Rect& bounds) |
151 : panel_(panel), | 120 : panel_(panel), |
152 window_(NULL), | 121 window_(NULL), |
153 web_view_(NULL), | 122 web_view_(NULL), |
154 focused_(false), | 123 focused_(false), |
155 mouse_pressed_(false), | 124 mouse_pressed_(false), |
156 mouse_dragging_state_(NO_DRAGGING), | 125 mouse_dragging_state_(NO_DRAGGING), |
157 is_drawing_attention_(false), | 126 is_drawing_attention_(false), |
158 force_to_paint_as_inactive_(false), | 127 force_to_paint_as_inactive_(false), |
159 old_focused_view_(NULL) { | 128 old_focused_view_(NULL) { |
160 window_ = new views::Widget; | 129 window_ = new views::Widget; |
161 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 130 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
162 params.delegate = this; | 131 params.delegate = this; |
163 params.remove_standard_frame = true; | 132 params.remove_standard_frame = true; |
164 params.keep_on_top = true; | 133 params.keep_on_top = true; |
165 params.bounds = bounds; | 134 params.bounds = bounds; |
166 window_->Init(params); | 135 window_->Init(params); |
167 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | 136 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); |
168 window_->set_focus_on_creation(false); | 137 window_->set_focus_on_creation(false); |
169 window_->AddObserver(this); | 138 window_->AddObserver(this); |
170 | 139 |
171 web_view_ = new views::WebView(NULL); | 140 web_view_ = new views::WebView(NULL); |
172 AddChildView(web_view_); | 141 AddChildView(web_view_); |
173 | 142 |
174 OnViewWasResized(); | 143 OnViewWasResized(); |
175 | 144 |
176 // Do a one-time initialization for the accelerator table. | |
177 if (accelerator_table_.empty()) { | |
178 for (size_t i = 0; i < arraysize(kPanelAcceleratorMap); ++i) { | |
179 ui::Accelerator accelerator(kPanelAcceleratorMap[i].keycode, | |
180 kPanelAcceleratorMap[i].modifiers); | |
181 accelerator_table_[accelerator] = kPanelAcceleratorMap[i].command_id; | |
182 } | |
183 } | |
184 | |
185 // Register accelarators supported by panels. | |
186 views::FocusManager* focus_manager = GetFocusManager(); | 145 views::FocusManager* focus_manager = GetFocusManager(); |
187 for (std::map<ui::Accelerator, int>::const_iterator iter = | 146 ui::Accelerator accelerator(ui::VKEY_ESCAPE, ui::EF_NONE); |
188 accelerator_table_.begin(); | 147 focus_manager->RegisterAccelerator( |
189 iter != accelerator_table_.end(); ++iter) { | 148 accelerator, ui::AcceleratorManager::kNormalPriority, this); |
190 focus_manager->RegisterAccelerator( | |
191 iter->first, ui::AcceleratorManager::kNormalPriority, this); | |
192 } | |
193 } | 149 } |
194 | 150 |
195 PanelView::~PanelView() { | 151 PanelView::~PanelView() { |
196 web_view_->SetWebContents(NULL); | 152 web_view_->SetWebContents(NULL); |
197 } | 153 } |
198 | 154 |
199 void PanelView::ShowPanel() { | 155 void PanelView::ShowPanel() { |
200 ShowPanelInactive(); | 156 ShowPanelInactive(); |
201 ActivatePanel(); | 157 ActivatePanel(); |
202 } | 158 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 299 } |
344 | 300 |
345 bool PanelView::PreHandlePanelKeyboardEvent( | 301 bool PanelView::PreHandlePanelKeyboardEvent( |
346 const content::NativeWebKeyboardEvent& event, | 302 const content::NativeWebKeyboardEvent& event, |
347 bool* is_keyboard_shortcut) { | 303 bool* is_keyboard_shortcut) { |
348 return false; | 304 return false; |
349 } | 305 } |
350 | 306 |
351 void PanelView::HandlePanelKeyboardEvent( | 307 void PanelView::HandlePanelKeyboardEvent( |
352 const content::NativeWebKeyboardEvent& event) { | 308 const content::NativeWebKeyboardEvent& event) { |
353 views::FocusManager* focus_manager = GetFocusManager(); | |
354 if (focus_manager->shortcut_handling_suspended()) | |
355 return; | |
356 | |
357 ui::Accelerator accelerator( | |
358 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | |
359 content::GetModifiersFromNativeWebKeyboardEvent(event)); | |
360 if (event.type == WebKit::WebInputEvent::KeyUp) | |
361 accelerator.set_type(ui::ET_KEY_RELEASED); | |
362 focus_manager->ProcessAccelerator(accelerator); | |
363 } | 309 } |
364 | 310 |
365 void PanelView::FullScreenModeChanged(bool is_full_screen) { | 311 void PanelView::FullScreenModeChanged(bool is_full_screen) { |
366 if (is_full_screen) { | 312 if (is_full_screen) { |
367 if (window_->IsVisible()) | 313 if (window_->IsVisible()) |
368 window_->Hide(); | 314 window_->Hide(); |
369 } else { | 315 } else { |
370 ShowPanelInactive(); | 316 ShowPanelInactive(); |
371 } | 317 } |
372 } | 318 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 512 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
567 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { | 513 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { |
568 OnTitlebarMouseCaptureLost(); | 514 OnTitlebarMouseCaptureLost(); |
569 return true; | 515 return true; |
570 } | 516 } |
571 | 517 |
572 // No other accelerator is allowed when the drag begins. | 518 // No other accelerator is allowed when the drag begins. |
573 if (mouse_dragging_state_ == DRAGGING_STARTED) | 519 if (mouse_dragging_state_ == DRAGGING_STARTED) |
574 return true; | 520 return true; |
575 | 521 |
576 std::map<ui::Accelerator, int>::const_iterator iter = | 522 return views::View::AcceleratorPressed(accelerator); |
577 accelerator_table_.find(accelerator); | |
578 DCHECK(iter != accelerator_table_.end()); | |
579 return panel_->ExecuteCommandIfEnabled(iter->second); | |
580 } | 523 } |
581 | 524 |
582 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { | 525 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
583 #if defined(OS_WIN) && !defined(USE_AURA) | 526 #if defined(OS_WIN) && !defined(USE_AURA) |
584 // The panel window is in focus (actually accepting keystrokes) if it is | 527 // The panel window is in focus (actually accepting keystrokes) if it is |
585 // active and belongs to a foreground application. | 528 // active and belongs to a foreground application. |
586 bool focused = active && | 529 bool focused = active && |
587 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); | 530 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); |
588 #else | 531 #else |
589 NOTIMPLEMENTED(); | 532 NOTIMPLEMENTED(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 int height = web_view_->size().height(); | 678 int height = web_view_->size().height(); |
736 SkRegion* region = new SkRegion; | 679 SkRegion* region = new SkRegion; |
737 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); | 680 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); |
738 region->op(width - kResizeInsideBoundsSize, 0, width, height, | 681 region->op(width - kResizeInsideBoundsSize, 0, width, height, |
739 SkRegion::kUnion_Op); | 682 SkRegion::kUnion_Op); |
740 region->op(0, height - kResizeInsideBoundsSize, width, height, | 683 region->op(0, height - kResizeInsideBoundsSize, width, height, |
741 SkRegion::kUnion_Op); | 684 SkRegion::kUnion_Op); |
742 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); | 685 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); |
743 #endif | 686 #endif |
744 } | 687 } |
OLD | NEW |