Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/ui/panels/panel_view.cc

Issue 10834240: Revert 150725 - Accelerator support for browserless panels on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/panels/panel_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/ui/panels/panel.h" 8 #include "chrome/browser/ui/panels/panel.h"
11 #include "chrome/browser/ui/panels/panel_bounds_animation.h" 9 #include "chrome/browser/ui/panels/panel_bounds_animation.h"
12 #include "chrome/browser/ui/panels/panel_frame_view.h" 10 #include "chrome/browser/ui/panels/panel_frame_view.h"
13 #include "chrome/browser/ui/panels/panel_manager.h" 11 #include "chrome/browser/ui/panels/panel_manager.h"
14 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/render_widget_host_view.h" 13 #include "content/public/browser/render_widget_host_view.h"
16 #include "ui/gfx/path.h" 14 #include "ui/gfx/path.h"
17 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
18 #include "ui/views/controls/button/image_button.h" 16 #include "ui/views/controls/button/image_button.h"
19 #include "ui/views/controls/webview/webview.h" 17 #include "ui/views/controls/webview/webview.h"
20 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
21 19
22 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) 20 #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA)
23 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
24 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h" 22 #include "chrome/browser/ui/panels/taskbar_window_thumbnailer_win.h"
25 #endif 23 #endif
26 24
27 namespace { 25 namespace {
28 26
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
69 // NativePanelTesting implementation. 27 // NativePanelTesting implementation.
70 class NativePanelTestingWin : public NativePanelTesting { 28 class NativePanelTestingWin : public NativePanelTesting {
71 public: 29 public:
72 explicit NativePanelTestingWin(PanelView* panel_view); 30 explicit NativePanelTestingWin(PanelView* panel_view);
73 31
74 private: 32 private:
75 virtual void PressLeftMouseButtonTitlebar( 33 virtual void PressLeftMouseButtonTitlebar(
76 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; 34 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE;
77 virtual void ReleaseMouseButtonTitlebar( 35 virtual void ReleaseMouseButtonTitlebar(
78 panel::ClickModifier modifier) OVERRIDE; 36 panel::ClickModifier modifier) OVERRIDE;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 window_->Init(params); 135 window_->Init(params);
178 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 136 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
179 window_->set_focus_on_creation(false); 137 window_->set_focus_on_creation(false);
180 window_->AddObserver(this); 138 window_->AddObserver(this);
181 139
182 web_view_ = new views::WebView(NULL); 140 web_view_ = new views::WebView(NULL);
183 AddChildView(web_view_); 141 AddChildView(web_view_);
184 142
185 OnViewWasResized(); 143 OnViewWasResized();
186 144
187 // Register accelarators supported by panels.
188 views::FocusManager* focus_manager = GetFocusManager(); 145 views::FocusManager* focus_manager = GetFocusManager();
189 const std::map<ui::Accelerator, int>& accelerator_table = 146 ui::Accelerator accelerator(ui::VKEY_ESCAPE, ui::EF_NONE);
190 GetAcceleratorTable(); 147 focus_manager->RegisterAccelerator(
191 for (std::map<ui::Accelerator, int>::const_iterator iter = 148 accelerator, ui::AcceleratorManager::kNormalPriority, this);
192 accelerator_table.begin();
193 iter != accelerator_table.end(); ++iter) {
194 focus_manager->RegisterAccelerator(
195 iter->first, ui::AcceleratorManager::kNormalPriority, this);
196 }
197 } 149 }
198 150
199 PanelView::~PanelView() { 151 PanelView::~PanelView() {
200 web_view_->SetWebContents(NULL); 152 web_view_->SetWebContents(NULL);
201 } 153 }
202 154
203 void PanelView::ShowPanel() { 155 void PanelView::ShowPanel() {
204 ShowPanelInactive(); 156 ShowPanelInactive();
205 ActivatePanel(); 157 ActivatePanel();
206 } 158 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 299 }
348 300
349 bool PanelView::PreHandlePanelKeyboardEvent( 301 bool PanelView::PreHandlePanelKeyboardEvent(
350 const content::NativeWebKeyboardEvent& event, 302 const content::NativeWebKeyboardEvent& event,
351 bool* is_keyboard_shortcut) { 303 bool* is_keyboard_shortcut) {
352 return false; 304 return false;
353 } 305 }
354 306
355 void PanelView::HandlePanelKeyboardEvent( 307 void PanelView::HandlePanelKeyboardEvent(
356 const content::NativeWebKeyboardEvent& event) { 308 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);
367 } 309 }
368 310
369 void PanelView::FullScreenModeChanged(bool is_full_screen) { 311 void PanelView::FullScreenModeChanged(bool is_full_screen) {
370 if (is_full_screen) { 312 if (is_full_screen) {
371 if (window_->IsVisible()) 313 if (window_->IsVisible())
372 window_->Hide(); 314 window_->Hide();
373 } else { 315 } else {
374 ShowPanelInactive(); 316 ShowPanelInactive();
375 } 317 }
376 } 318 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { 512 bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) {
571 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { 513 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) {
572 OnTitlebarMouseCaptureLost(); 514 OnTitlebarMouseCaptureLost();
573 return true; 515 return true;
574 } 516 }
575 517
576 // No other accelerator is allowed when the drag begins. 518 // No other accelerator is allowed when the drag begins.
577 if (mouse_dragging_state_ == DRAGGING_STARTED) 519 if (mouse_dragging_state_ == DRAGGING_STARTED)
578 return true; 520 return true;
579 521
580 const std::map<ui::Accelerator, int>& accelerator_table = 522 return views::View::AcceleratorPressed(accelerator);
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);
586 } 523 }
587 524
588 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { 525 void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) {
589 #if defined(OS_WIN) && !defined(USE_AURA) 526 #if defined(OS_WIN) && !defined(USE_AURA)
590 // 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
591 // active and belongs to a foreground application. 528 // active and belongs to a foreground application.
592 bool focused = active && 529 bool focused = active &&
593 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); 530 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow();
594 #else 531 #else
595 NOTIMPLEMENTED(); 532 NOTIMPLEMENTED();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 int height = web_view_->size().height(); 678 int height = web_view_->size().height();
742 SkRegion* region = new SkRegion; 679 SkRegion* region = new SkRegion;
743 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); 680 region->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op);
744 region->op(width - kResizeInsideBoundsSize, 0, width, height, 681 region->op(width - kResizeInsideBoundsSize, 0, width, height,
745 SkRegion::kUnion_Op); 682 SkRegion::kUnion_Op);
746 region->op(0, height - kResizeInsideBoundsSize, width, height, 683 region->op(0, height - kResizeInsideBoundsSize, width, height,
747 SkRegion::kUnion_Op); 684 SkRegion::kUnion_Op);
748 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region); 685 web_contents->GetRenderViewHost()->GetView()->SetClickthroughRegion(region);
749 #endif 686 #endif
750 } 687 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698