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

Side by Side Diff: chrome/browser/ui/views/frame/browser_frame_mac.mm

Issue 2074643003: MacViews: Views accelerators table should match the Cocoa one. (Closed) Base URL: ssh://bitbucket.browser.yandex-team.ru/chromium/src.git@master
Patch Set: Fix compilation. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/frame/browser_frame_mac.h" 5 #import "chrome/browser/ui/views/frame/browser_frame_mac.h"
6 6
7 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
8 #include "chrome/browser/ui/browser_command_controller.h"
9 #include "chrome/browser/ui/browser_commands.h"
7 #import "chrome/browser/ui/cocoa/browser_window_command_handler.h" 10 #import "chrome/browser/ui/cocoa/browser_window_command_handler.h"
8 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" 11 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h"
9 #include "chrome/browser/ui/views/frame/browser_frame.h" 12 #include "chrome/browser/ui/views/frame/browser_frame.h"
10 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #import "chrome/browser/ui/views/frame/native_widget_mac_frameless_nswindow.h" 14 #import "chrome/browser/ui/views/frame/native_widget_mac_frameless_nswindow.h"
12 #include "components/web_modal/web_contents_modal_dialog_host.h" 15 #include "components/web_modal/web_contents_modal_dialog_host.h"
16 #include "content/public/browser/native_web_keyboard_event.h"
13 #import "ui/base/cocoa/window_size_constants.h" 17 #import "ui/base/cocoa/window_size_constants.h"
14 18
19 namespace {
20
21 bool ShouldHandleKeyboardEvent(const content::NativeWebKeyboardEvent& event) {
22 // |event.skip_in_browser| is true when it shouldn't be handled by the browser
23 // if it was ignored by the renderer. See http://crbug.com/25000.
24 if (event.skip_in_browser)
25 return false;
26
27 // Ignore synthesized keyboard events. See http://crbug.com/23221.
28 if (event.type == content::NativeWebKeyboardEvent::Char)
29 return false;
30
31 // If the event was not synthesized it should have an os_event.
32 DCHECK(event.os_event);
33
34 // Do not fire shortcuts on key up.
35 return [event.os_event type] == NSKeyDown;
36 }
37
38 // Returns true if |event| was handled.
39 bool HandleExtraKeyboardShortcut(NSEvent* event,
40 Browser* browser,
41 ChromeCommandDispatcherDelegate* delegate) {
42 // Send the event to the menu before sending it to the browser/window
43 // shortcut handling, so that if a user configures cmd-left to mean
44 // "previous tab", it takes precedence over the built-in "history back"
45 // binding.
46 if ([[NSApp mainMenu] performKeyEquivalent:event])
47 return true;
48
49 // Invoke ChromeCommandDispatcherDelegate for Mac-specific shortcuts that
50 // can't be handled by accelerator_table.cc.
51 return [delegate
52 handleExtraKeyboardShortcut:event
53 window:browser->window()->GetNativeWindow()];
54 }
55
56 } // namespace
57
15 BrowserFrameMac::BrowserFrameMac(BrowserFrame* browser_frame, 58 BrowserFrameMac::BrowserFrameMac(BrowserFrame* browser_frame,
16 BrowserView* browser_view) 59 BrowserView* browser_view)
17 : views::NativeWidgetMac(browser_frame), 60 : views::NativeWidgetMac(browser_frame),
18 browser_view_(browser_view), 61 browser_view_(browser_view),
19 command_dispatcher_delegate_( 62 command_dispatcher_delegate_(
20 [[ChromeCommandDispatcherDelegate alloc] init]) {} 63 [[ChromeCommandDispatcherDelegate alloc] init]) {}
21 64
22 BrowserFrameMac::~BrowserFrameMac() { 65 BrowserFrameMac::~BrowserFrameMac() {
23 } 66 }
24 67
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 initWithContentRect:ui::kWindowSizeDeterminedLater 104 initWithContentRect:ui::kWindowSizeDeterminedLater
62 styleMask:style_mask 105 styleMask:style_mask
63 backing:NSBackingStoreBuffered 106 backing:NSBackingStoreBuffered
64 defer:NO]); 107 defer:NO]);
65 [ns_window setCommandDispatcherDelegate:command_dispatcher_delegate_]; 108 [ns_window setCommandDispatcherDelegate:command_dispatcher_delegate_];
66 [ns_window setCommandHandler:[[[BrowserWindowCommandHandler alloc] init] 109 [ns_window setCommandHandler:[[[BrowserWindowCommandHandler alloc] init]
67 autorelease]]; 110 autorelease]];
68 return ns_window.autorelease(); 111 return ns_window.autorelease();
69 } 112 }
70 113
114 int BrowserFrameMac::GetMinimizeButtonOffset() const {
115 NOTIMPLEMENTED();
116 return 0;
117 }
118
71 //////////////////////////////////////////////////////////////////////////////// 119 ////////////////////////////////////////////////////////////////////////////////
72 // BrowserFrameMac, NativeBrowserFrame implementation: 120 // BrowserFrameMac, NativeBrowserFrame implementation:
73 121
74 views::Widget::InitParams BrowserFrameMac::GetWidgetParams() { 122 views::Widget::InitParams BrowserFrameMac::GetWidgetParams() {
75 views::Widget::InitParams params; 123 views::Widget::InitParams params;
76 params.native_widget = this; 124 params.native_widget = this;
77 return params; 125 return params;
78 } 126 }
79 127
80 bool BrowserFrameMac::UseCustomFrame() const { 128 bool BrowserFrameMac::UseCustomFrame() const {
81 return false; 129 return false;
82 } 130 }
83 131
84 bool BrowserFrameMac::UsesNativeSystemMenu() const { 132 bool BrowserFrameMac::UsesNativeSystemMenu() const {
85 return true; 133 return true;
86 } 134 }
87 135
88 bool BrowserFrameMac::ShouldSaveWindowPlacement() const { 136 bool BrowserFrameMac::ShouldSaveWindowPlacement() const {
89 return true; 137 return true;
90 } 138 }
91 139
92 void BrowserFrameMac::GetWindowPlacement( 140 void BrowserFrameMac::GetWindowPlacement(
93 gfx::Rect* bounds, 141 gfx::Rect* bounds,
94 ui::WindowShowState* show_state) const { 142 ui::WindowShowState* show_state) const {
95 return NativeWidgetMac::GetWindowPlacement(bounds, show_state); 143 return NativeWidgetMac::GetWindowPlacement(bounds, show_state);
96 } 144 }
97 145
98 int BrowserFrameMac::GetMinimizeButtonOffset() const { 146 // Mac is special because the user could override the menu shortcuts (see
99 NOTIMPLEMENTED(); 147 // comment in HandleExtraKeyboardShortcut), and there's a set of additional
100 return 0; 148 // accelerator tables (handled by ChromeCommandDispatcherDelegate) that couldn't
149 // be ported to accelerator_table.cc: see global_keyboard_shortcuts_views_mac.mm
150 bool BrowserFrameMac::PreHandleKeyboardEvent(
151 const content::NativeWebKeyboardEvent& event) {
152 if (!ShouldHandleKeyboardEvent(event))
153 return false;
154
155 // CommandForKeyEvent consults the [NSApp mainMenu] and Mac-specific
156 // accelerator tables internally.
157 int command_id = CommandForKeyEvent(event.os_event);
158 if (command_id == -1)
159 return false;
160
161 // Only handle a small list of reserved commands that we don't want to be
162 // handled by the renderer.
163 Browser* browser = browser_view_->browser();
164 if (!browser->command_controller()->IsReservedCommandOrKey(
165 command_id, event))
166 return false;
167
168 return HandleExtraKeyboardShortcut(event.os_event, browser,
169 command_dispatcher_delegate_);
101 } 170 }
171
172 bool BrowserFrameMac::HandleKeyboardEvent(
173 const content::NativeWebKeyboardEvent& event) {
174 if (!ShouldHandleKeyboardEvent(event))
175 return false;
176
177 return HandleExtraKeyboardShortcut(event.os_event, browser_view_->browser(),
178 command_dispatcher_delegate_);
179 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_frame_mac.h ('k') | chrome/browser/ui/views/frame/browser_frame_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698