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 <map> |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
9 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 11 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
10 #include "chrome/browser/ui/panels/panel_frame_view.h" | 12 #include "chrome/browser/ui/panels/panel_frame_view.h" |
11 #include "chrome/browser/ui/panels/panel_manager.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
12 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
14 #include "ui/gfx/path.h" | 16 #include "ui/gfx/path.h" |
15 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
16 #include "ui/views/controls/button/image_button.h" | 18 #include "ui/views/controls/button/image_button.h" |
17 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
18 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
19 | 21 |
20 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) | 22 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) |
21 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
22 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" | 24 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" |
23 #endif | 25 #endif |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
| 29 // Supported accelerators. |
| 30 // Note: We can't use the acclerator table defined in chrome/browser/ui/views |
| 31 // due to checkdeps violation. |
| 32 struct AcceleratorMapping { |
| 33 ui::KeyboardCode keycode; |
| 34 int modifiers; |
| 35 int command_id; |
| 36 }; |
| 37 const AcceleratorMapping kPanelAcceleratorMap[] = { |
| 38 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, |
| 39 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, |
| 40 { ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW }, |
| 41 { ui::VKEY_R, ui::EF_CONTROL_DOWN, IDC_RELOAD }, |
| 42 { ui::VKEY_F5, ui::EF_NONE, IDC_RELOAD }, |
| 43 { ui::VKEY_R, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, |
| 44 IDC_RELOAD_IGNORING_CACHE }, |
| 45 { ui::VKEY_F5, ui::EF_CONTROL_DOWN, IDC_RELOAD_IGNORING_CACHE }, |
| 46 { ui::VKEY_F5, ui::EF_SHIFT_DOWN, IDC_RELOAD_IGNORING_CACHE }, |
| 47 { ui::VKEY_ESCAPE, ui::EF_NONE, IDC_STOP }, |
| 48 { ui::VKEY_OEM_MINUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, |
| 49 { ui::VKEY_SUBTRACT, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, |
| 50 { ui::VKEY_0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, |
| 51 { ui::VKEY_NUMPAD0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, |
| 52 { ui::VKEY_OEM_PLUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, |
| 53 { ui::VKEY_ADD, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, |
| 54 }; |
| 55 |
| 56 const std::map<ui::Accelerator, int>& GetAcceleratorTable() { |
| 57 static std::map<ui::Accelerator, int>* accelerators = NULL; |
| 58 if (!accelerators) { |
| 59 accelerators = new std::map<ui::Accelerator, int>(); |
| 60 for (size_t i = 0; i < arraysize(kPanelAcceleratorMap); ++i) { |
| 61 ui::Accelerator accelerator(kPanelAcceleratorMap[i].keycode, |
| 62 kPanelAcceleratorMap[i].modifiers); |
| 63 (*accelerators)[accelerator] = kPanelAcceleratorMap[i].command_id; |
| 64 } |
| 65 } |
| 66 return *accelerators; |
| 67 } |
| 68 |
27 // NativePanelTesting implementation. | 69 // NativePanelTesting implementation. |
28 class NativePanelTestingWin : public NativePanelTesting { | 70 class NativePanelTestingWin : public NativePanelTesting { |
29 public: | 71 public: |
30 explicit NativePanelTestingWin(PanelView* panel_view); | 72 explicit NativePanelTestingWin(PanelView* panel_view); |
31 | 73 |
32 private: | 74 private: |
33 virtual void PressLeftMouseButtonTitlebar( | 75 virtual void PressLeftMouseButtonTitlebar( |
34 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 76 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
35 virtual void ReleaseMouseButtonTitlebar( | 77 virtual void ReleaseMouseButtonTitlebar( |
36 panel::ClickModifier modifier) OVERRIDE; | 78 panel::ClickModifier modifier) OVERRIDE; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 window_->Init(params); | 177 window_->Init(params); |
136 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | 178 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); |
137 window_->set_focus_on_creation(false); | 179 window_->set_focus_on_creation(false); |
138 window_->AddObserver(this); | 180 window_->AddObserver(this); |
139 | 181 |
140 web_view_ = new views::WebView(NULL); | 182 web_view_ = new views::WebView(NULL); |
141 AddChildView(web_view_); | 183 AddChildView(web_view_); |
142 | 184 |
143 OnViewWasResized(); | 185 OnViewWasResized(); |
144 | 186 |
| 187 // Register accelarators supported by panels. |
145 views::FocusManager* focus_manager = GetFocusManager(); | 188 views::FocusManager* focus_manager = GetFocusManager(); |
146 ui::Accelerator accelerator(ui::VKEY_ESCAPE, ui::EF_NONE); | 189 const std::map<ui::Accelerator, int>& accelerator_table = |
147 focus_manager->RegisterAccelerator( | 190 GetAcceleratorTable(); |
148 accelerator, ui::AcceleratorManager::kNormalPriority, this); | 191 for (std::map<ui::Accelerator, int>::const_iterator iter = |
| 192 accelerator_table.begin(); |
| 193 iter != accelerator_table.end(); ++iter) { |
| 194 focus_manager->RegisterAccelerator( |
| 195 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
| 196 } |
149 } | 197 } |
150 | 198 |
151 PanelView::~PanelView() { | 199 PanelView::~PanelView() { |
152 web_view_->SetWebContents(NULL); | 200 web_view_->SetWebContents(NULL); |
153 } | 201 } |
154 | 202 |
155 void PanelView::ShowPanel() { | 203 void PanelView::ShowPanel() { |
156 ShowPanelInactive(); | 204 ShowPanelInactive(); |
157 ActivatePanel(); | 205 ActivatePanel(); |
158 } | 206 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 347 } |
300 | 348 |
301 bool PanelView::PreHandlePanelKeyboardEvent( | 349 bool PanelView::PreHandlePanelKeyboardEvent( |
302 const content::NativeWebKeyboardEvent& event, | 350 const content::NativeWebKeyboardEvent& event, |
303 bool* is_keyboard_shortcut) { | 351 bool* is_keyboard_shortcut) { |
304 return false; | 352 return false; |
305 } | 353 } |
306 | 354 |
307 void PanelView::HandlePanelKeyboardEvent( | 355 void PanelView::HandlePanelKeyboardEvent( |
308 const content::NativeWebKeyboardEvent& event) { | 356 const content::NativeWebKeyboardEvent& event) { |
| 357 views::FocusManager* focus_manager = GetFocusManager(); |
| 358 if (focus_manager->shortcut_handling_suspended()) |
| 359 return; |
| 360 |
| 361 ui::Accelerator accelerator( |
| 362 static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
| 363 content::GetModifiersFromNativeWebKeyboardEvent(event)); |
| 364 if (event.type == WebKit::WebInputEvent::KeyUp) |
| 365 accelerator.set_type(ui::ET_KEY_RELEASED); |
| 366 focus_manager->ProcessAccelerator(accelerator); |
309 } | 367 } |
310 | 368 |
311 void PanelView::FullScreenModeChanged(bool is_full_screen) { | 369 void PanelView::FullScreenModeChanged(bool is_full_screen) { |
312 if (is_full_screen) { | 370 if (is_full_screen) { |
313 if (window_->IsVisible()) | 371 if (window_->IsVisible()) |
314 window_->Hide(); | 372 window_->Hide(); |
315 } else { | 373 } else { |
316 ShowPanelInactive(); | 374 ShowPanelInactive(); |
317 } | 375 } |
318 } | 376 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 570 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
513 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { | 571 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { |
514 OnTitlebarMouseCaptureLost(); | 572 OnTitlebarMouseCaptureLost(); |
515 return true; | 573 return true; |
516 } | 574 } |
517 | 575 |
518 // No other accelerator is allowed when the drag begins. | 576 // No other accelerator is allowed when the drag begins. |
519 if (mouse_dragging_state_ == DRAGGING_STARTED) | 577 if (mouse_dragging_state_ == DRAGGING_STARTED) |
520 return true; | 578 return true; |
521 | 579 |
522 return views::View::AcceleratorPressed(accelerator); | 580 const std::map<ui::Accelerator, int>& accelerator_table = |
| 581 GetAcceleratorTable(); |
| 582 std::map<ui::Accelerator, int>::const_iterator iter = |
| 583 accelerator_table.find(accelerator); |
| 584 DCHECK(iter != accelerator_table.end()); |
| 585 return panel_->ExecuteCommandIfEnabled(iter->second); |
523 } | 586 } |
524 | 587 |
525 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { | 588 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
526 #if defined(OS_WIN) && !defined(USE_AURA) | 589 #if defined(OS_WIN) && !defined(USE_AURA) |
527 // The panel window is in focus (actually accepting keystrokes) if it is | 590 // The panel window is in focus (actually accepting keystrokes) if it is |
528 // active and belongs to a foreground application. | 591 // active and belongs to a foreground application. |
529 bool focused = active && | 592 bool focused = active && |
530 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); | 593 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); |
531 #else | 594 #else |
532 NOTIMPLEMENTED(); | 595 NOTIMPLEMENTED(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 int height = web_view_->size().height(); | 741 int height = web_view_->size().height(); |
679 SkRegion* region = new SkRegion; | 742 SkRegion* region = new SkRegion; |
680 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); | 743 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); |
681 region->op(width - kResizeInsideBoundsSize, 0, width, height, | 744 region->op(width - kResizeInsideBoundsSize, 0, width, height, |
682 SkRegion::kUnion_Op); | 745 SkRegion::kUnion_Op); |
683 region->op(0, height - kResizeInsideBoundsSize, width, height, | 746 region->op(0, height - kResizeInsideBoundsSize, width, height, |
684 SkRegion::kUnion_Op); | 747 SkRegion::kUnion_Op); |
685 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); | 748 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); |
686 #endif | 749 #endif |
687 } | 750 } |
OLD | NEW |