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" | |
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" | |
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) { | |
tapted
2016/10/26 08:40:47
comment?
themblsha
2016/10/26 17:10:03
It's adapted from +[BrowserWindowUtils shouldHandl
tapted
2016/10/28 04:59:48
Hm - it's possible that this and HandleExtraKeyboa
themblsha
2016/10/28 17:32:22
Without my changes the only code path that should
| |
23 // Do not fire shortcuts on key up. | |
24 if ([event.os_event type] != NSKeyDown) | |
25 return false; | |
26 | |
27 if (event.skip_in_browser || | |
28 event.type == content::NativeWebKeyboardEvent::Char) | |
29 return false; | |
30 | |
31 DCHECK(event.os_event != NULL); | |
tapted
2016/10/26 08:40:47
DCHECK(event.os_event) - this should probably be a
themblsha
2016/10/28 17:32:22
I guess it could fail in case the event was simula
tapted
2016/10/31 10:16:57
Ah, good point - I think I've encountered strangen
themblsha
2016/10/31 16:56:29
Makes sense, done.
| |
32 return true; | |
33 } | |
34 | |
35 // Copied from chrome_command_dispatcher_delegate.mm's | |
36 // HandleExtraBrowserKeyboardShortcut and adapted for MacViews to only consult | |
37 // the CommandForMacViewsKeyboardShortcut table. | |
38 bool HandleExtraKeyboardShortcut(NSEvent* event, Browser* browser) { | |
39 // Send the event to the menu before sending it to the browser/window | |
40 // shortcut handling, so that if a user configures cmd-left to mean | |
41 // "previous tab", it takes precedence over the built-in "history back" | |
42 // binding. | |
43 if ([[NSApp mainMenu] performKeyEquivalent:event]) | |
44 return true; | |
45 | |
46 return command_dispatcher::HandleExtraKeyboardShortcut( | |
47 event, browser->window()->GetNativeWindow(), | |
48 CommandForMacViewsKeyboardShortcut); | |
49 } | |
50 | |
51 } // namespace | |
52 | |
15 BrowserFrameMac::BrowserFrameMac(BrowserFrame* browser_frame, | 53 BrowserFrameMac::BrowserFrameMac(BrowserFrame* browser_frame, |
16 BrowserView* browser_view) | 54 BrowserView* browser_view) |
17 : views::NativeWidgetMac(browser_frame), | 55 : views::NativeWidgetMac(browser_frame), |
18 browser_view_(browser_view), | 56 browser_view_(browser_view), |
19 command_dispatcher_delegate_( | 57 command_dispatcher_delegate_( |
20 [[ChromeCommandDispatcherDelegate alloc] init]) {} | 58 [[ChromeCommandDispatcherDelegate alloc] init]) {} |
21 | 59 |
22 BrowserFrameMac::~BrowserFrameMac() { | 60 BrowserFrameMac::~BrowserFrameMac() { |
23 } | 61 } |
24 | 62 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 initWithContentRect:ui::kWindowSizeDeterminedLater | 99 initWithContentRect:ui::kWindowSizeDeterminedLater |
62 styleMask:style_mask | 100 styleMask:style_mask |
63 backing:NSBackingStoreBuffered | 101 backing:NSBackingStoreBuffered |
64 defer:NO]); | 102 defer:NO]); |
65 [ns_window setCommandDispatcherDelegate:command_dispatcher_delegate_]; | 103 [ns_window setCommandDispatcherDelegate:command_dispatcher_delegate_]; |
66 [ns_window setCommandHandler:[[[BrowserWindowCommandHandler alloc] init] | 104 [ns_window setCommandHandler:[[[BrowserWindowCommandHandler alloc] init] |
67 autorelease]]; | 105 autorelease]]; |
68 return ns_window.autorelease(); | 106 return ns_window.autorelease(); |
69 } | 107 } |
70 | 108 |
109 int BrowserFrameMac::GetMinimizeButtonOffset() const { | |
110 NOTIMPLEMENTED(); | |
111 return 0; | |
112 } | |
113 | |
71 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
72 // BrowserFrameMac, NativeBrowserFrame implementation: | 115 // BrowserFrameMac, NativeBrowserFrame implementation: |
73 | 116 |
74 views::Widget::InitParams BrowserFrameMac::GetWidgetParams() { | 117 views::Widget::InitParams BrowserFrameMac::GetWidgetParams() { |
75 views::Widget::InitParams params; | 118 views::Widget::InitParams params; |
76 params.native_widget = this; | 119 params.native_widget = this; |
77 return params; | 120 return params; |
78 } | 121 } |
79 | 122 |
80 bool BrowserFrameMac::UseCustomFrame() const { | 123 bool BrowserFrameMac::UseCustomFrame() const { |
81 return false; | 124 return false; |
82 } | 125 } |
83 | 126 |
84 bool BrowserFrameMac::UsesNativeSystemMenu() const { | 127 bool BrowserFrameMac::UsesNativeSystemMenu() const { |
85 return true; | 128 return true; |
86 } | 129 } |
87 | 130 |
88 bool BrowserFrameMac::ShouldSaveWindowPlacement() const { | 131 bool BrowserFrameMac::ShouldSaveWindowPlacement() const { |
89 return true; | 132 return true; |
90 } | 133 } |
91 | 134 |
92 void BrowserFrameMac::GetWindowPlacement( | 135 void BrowserFrameMac::GetWindowPlacement( |
93 gfx::Rect* bounds, | 136 gfx::Rect* bounds, |
94 ui::WindowShowState* show_state) const { | 137 ui::WindowShowState* show_state) const { |
95 return NativeWidgetMac::GetWindowPlacement(bounds, show_state); | 138 return NativeWidgetMac::GetWindowPlacement(bounds, show_state); |
96 } | 139 } |
97 | 140 |
98 int BrowserFrameMac::GetMinimizeButtonOffset() const { | 141 bool BrowserFrameMac::PreHandleKeyboardEvent( |
99 NOTIMPLEMENTED(); | 142 const content::NativeWebKeyboardEvent& event) { |
100 return 0; | 143 // Copied from BrowserWindowCocoa::PreHandleKeyboardEvent(). |
tapted
2016/10/26 08:40:47
BrowserWindowCocoa may not be with us forever, so
themblsha
2016/10/28 17:32:22
Tried my best to fill the code with sensible comme
| |
144 if (!ShouldHandleKeyboardEvent(event)) | |
145 return false; | |
146 | |
147 // CommandForKeyEventOnMacViews consults the [NSApp mainMenu] and | |
148 // CommandForMacViewsKeyboardShortcut accelerator table internally. | |
149 int command_id = CommandForKeyEventOnMacViews(event.os_event); | |
150 if (command_id == -1) | |
151 return false; | |
152 | |
153 Browser* browser = browser_view_->browser(); | |
154 if (!browser->command_controller()->IsReservedCommandOrKey( | |
155 command_id, event)) | |
156 return false; | |
157 | |
158 return HandleExtraKeyboardShortcut(event.os_event, browser); | |
101 } | 159 } |
160 | |
161 bool BrowserFrameMac::HandleKeyboardEvent( | |
162 const content::NativeWebKeyboardEvent& event) { | |
163 if (!ShouldHandleKeyboardEvent(event)) | |
164 return false; | |
165 | |
166 return HandleExtraKeyboardShortcut(event.os_event, browser_view_->browser()); | |
167 } | |
OLD | NEW |