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" | |
8 #include "chrome/browser/ui/panels/panel.h" | 9 #include "chrome/browser/ui/panels/panel.h" |
9 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 10 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
10 #include "chrome/browser/ui/panels/panel_frame_view.h" | 11 #include "chrome/browser/ui/panels/panel_frame_view.h" |
11 #include "chrome/browser/ui/panels/panel_manager.h" | 12 #include "chrome/browser/ui/panels/panel_manager.h" |
12 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
14 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
15 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
16 #include "ui/views/controls/button/image_button.h" | 17 #include "ui/views/controls/button/image_button.h" |
17 #include "ui/views/controls/webview/webview.h" | 18 #include "ui/views/controls/webview/webview.h" |
18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
19 | 20 |
20 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) | 21 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) |
21 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
22 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" | 23 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" |
23 #endif | 24 #endif |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
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 { | |
jennb
2012/08/07 00:38:07
Could also do this as:
const struct AcceleratorMa
| |
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 | |
27 // NativePanelTesting implementation. | 55 // NativePanelTesting implementation. |
28 class NativePanelTestingWin : public NativePanelTesting { | 56 class NativePanelTestingWin : public NativePanelTesting { |
29 public: | 57 public: |
30 explicit NativePanelTestingWin(PanelView* panel_view); | 58 explicit NativePanelTestingWin(PanelView* panel_view); |
31 | 59 |
32 private: | 60 private: |
33 virtual void PressLeftMouseButtonTitlebar( | 61 virtual void PressLeftMouseButtonTitlebar( |
34 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 62 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
35 virtual void ReleaseMouseButtonTitlebar( | 63 virtual void ReleaseMouseButtonTitlebar( |
36 panel::ClickModifier modifier) OVERRIDE; | 64 panel::ClickModifier modifier) OVERRIDE; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 window_->Init(params); | 163 window_->Init(params); |
136 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | 164 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); |
137 window_->set_focus_on_creation(false); | 165 window_->set_focus_on_creation(false); |
138 window_->AddObserver(this); | 166 window_->AddObserver(this); |
139 | 167 |
140 web_view_ = new views::WebView(NULL); | 168 web_view_ = new views::WebView(NULL); |
141 AddChildView(web_view_); | 169 AddChildView(web_view_); |
142 | 170 |
143 OnViewWasResized(); | 171 OnViewWasResized(); |
144 | 172 |
173 // Register accelarators supported by panels. | |
145 views::FocusManager* focus_manager = GetFocusManager(); | 174 views::FocusManager* focus_manager = GetFocusManager(); |
146 ui::Accelerator accelerator(ui::VKEY_ESCAPE, ui::EF_NONE); | 175 for (size_t i = 0; i < arraysize(kPanelAcceleratorMap); ++i) { |
147 focus_manager->RegisterAccelerator( | 176 ui::Accelerator accelerator(kPanelAcceleratorMap[i].keycode, |
177 kPanelAcceleratorMap[i].modifiers); | |
178 accelerator_table_[accelerator] = kPanelAcceleratorMap[i].command_id; | |
179 focus_manager->RegisterAccelerator( | |
148 accelerator, ui::AcceleratorManager::kNormalPriority, this); | 180 accelerator, ui::AcceleratorManager::kNormalPriority, this); |
181 } | |
149 } | 182 } |
150 | 183 |
151 PanelView::~PanelView() { | 184 PanelView::~PanelView() { |
152 web_view_->SetWebContents(NULL); | 185 web_view_->SetWebContents(NULL); |
153 } | 186 } |
154 | 187 |
155 void PanelView::ShowPanel() { | 188 void PanelView::ShowPanel() { |
156 ShowPanelInactive(); | 189 ShowPanelInactive(); |
157 ActivatePanel(); | 190 ActivatePanel(); |
158 } | 191 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 } | 332 } |
300 | 333 |
301 bool PanelView::PreHandlePanelKeyboardEvent( | 334 bool PanelView::PreHandlePanelKeyboardEvent( |
302 const content::NativeWebKeyboardEvent& event, | 335 const content::NativeWebKeyboardEvent& event, |
303 bool* is_keyboard_shortcut) { | 336 bool* is_keyboard_shortcut) { |
304 return false; | 337 return false; |
305 } | 338 } |
306 | 339 |
307 void PanelView::HandlePanelKeyboardEvent( | 340 void PanelView::HandlePanelKeyboardEvent( |
308 const content::NativeWebKeyboardEvent& event) { | 341 const content::NativeWebKeyboardEvent& event) { |
342 views::FocusManager* focus_manager = GetFocusManager(); | |
343 if (focus_manager->shortcut_handling_suspended()) | |
344 return; | |
345 | |
346 ui::Accelerator accelerator( | |
347 static_cast<ui::KeyboardCode>(event.windowsKeyCode), | |
348 content::GetModifiersFromNativeWebKeyboardEvent(event)); | |
349 if (event.type == WebKit::WebInputEvent::KeyUp) | |
350 accelerator.set_type(ui::ET_KEY_RELEASED); | |
351 focus_manager->ProcessAccelerator(accelerator); | |
309 } | 352 } |
310 | 353 |
311 void PanelView::FullScreenModeChanged(bool is_full_screen) { | 354 void PanelView::FullScreenModeChanged(bool is_full_screen) { |
312 if (is_full_screen) { | 355 if (is_full_screen) { |
313 if (window_->IsVisible()) | 356 if (window_->IsVisible()) |
314 window_->Hide(); | 357 window_->Hide(); |
315 } else { | 358 } else { |
316 ShowPanelInactive(); | 359 ShowPanelInactive(); |
317 } | 360 } |
318 } | 361 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 555 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
513 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { | 556 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { |
514 OnTitlebarMouseCaptureLost(); | 557 OnTitlebarMouseCaptureLost(); |
515 return true; | 558 return true; |
516 } | 559 } |
517 | 560 |
518 // No other accelerator is allowed when the drag begins. | 561 // No other accelerator is allowed when the drag begins. |
519 if (mouse_dragging_state_ == DRAGGING_STARTED) | 562 if (mouse_dragging_state_ == DRAGGING_STARTED) |
520 return true; | 563 return true; |
521 | 564 |
522 return views::View::AcceleratorPressed(accelerator); | 565 std::map<ui::Accelerator, int>::const_iterator iter = |
566 accelerator_table_.find(accelerator); | |
567 DCHECK(iter != accelerator_table_.end()); | |
568 return panel_->ExecuteCommandIfEnabled(iter->second); | |
523 } | 569 } |
524 | 570 |
525 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { | 571 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
526 #if defined(OS_WIN) && !defined(USE_AURA) | 572 #if defined(OS_WIN) && !defined(USE_AURA) |
527 // The panel window is in focus (actually accepting keystrokes) if it is | 573 // The panel window is in focus (actually accepting keystrokes) if it is |
528 // active and belongs to a foreground application. | 574 // active and belongs to a foreground application. |
529 bool focused = active && | 575 bool focused = active && |
530 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); | 576 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); |
531 #else | 577 #else |
532 NOTIMPLEMENTED(); | 578 NOTIMPLEMENTED(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 int height = web_view_->size().height(); | 724 int height = web_view_->size().height(); |
679 SkRegion* region = new SkRegion; | 725 SkRegion* region = new SkRegion; |
680 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); | 726 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); |
681 region->op(width - kResizeInsideBoundsSize, 0, width, height, | 727 region->op(width - kResizeInsideBoundsSize, 0, width, height, |
682 SkRegion::kUnion_Op); | 728 SkRegion::kUnion_Op); |
683 region->op(0, height - kResizeInsideBoundsSize, width, height, | 729 region->op(0, height - kResizeInsideBoundsSize, width, height, |
684 SkRegion::kUnion_Op); | 730 SkRegion::kUnion_Op); |
685 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); | 731 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); |
686 #endif | 732 #endif |
687 } | 733 } |
OLD | NEW |