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