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

Side by Side Diff: ui/views/cocoa/native_widget_mac_nswindow.mm

Issue 1255783002: [Mac] Factor out keyboard shortcut handling from ChromeEventProcessingWindow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@execute
Patch Set: UI_BASE_EXPORT CommandDispatcher Created 5 years, 3 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
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 #import "ui/views/cocoa/native_widget_mac_nswindow.h" 5 #import "ui/views/cocoa/native_widget_mac_nswindow.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #import "ui/views/cocoa/views_nswindow_delegate.h" 8 #import "ui/views/cocoa/views_nswindow_delegate.h"
9 #include "ui/views/controls/menu/menu_controller.h" 9 #include "ui/views/controls/menu/menu_controller.h"
10 #include "ui/views/widget/native_widget_mac.h" 10 #include "ui/views/widget/native_widget_mac.h"
11 #include "ui/views/widget/widget_delegate.h" 11 #include "ui/views/widget/widget_delegate.h"
12 12
13 @interface NativeWidgetMacNSWindow () 13 @interface NativeWidgetMacNSWindow ()
14 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate; 14 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate;
15 - (views::Widget*)viewsWidget; 15 - (views::Widget*)viewsWidget;
16 - (BOOL)hasViewsMenuActive; 16 - (BOOL)hasViewsMenuActive;
17 17
18 // Private API on NSWindow, determines whether the title is drawn on the title 18 // Private API on NSWindow, determines whether the title is drawn on the title
19 // bar. The title is still visible in menus, Expose, etc. 19 // bar. The title is still visible in menus, Expose, etc.
20 - (BOOL)_isTitleHidden; 20 - (BOOL)_isTitleHidden;
21 @end 21 @end
22 22
23 @implementation NativeWidgetMacNSWindow 23 @implementation NativeWidgetMacNSWindow {
24 @private
25 base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
26 }
27
28 - (instancetype)initWithContentRect:(NSRect)contentRect
29 styleMask:(NSUInteger)windowStyle
30 backing:(NSBackingStoreType)bufferingType
31 defer:(BOOL)deferCreation {
32 if ((self = [super initWithContentRect:contentRect
33 styleMask:windowStyle
34 backing:bufferingType
35 defer:deferCreation])) {
36 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]);
37 }
38 return self;
39 }
24 40
25 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate { 41 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate {
26 return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]); 42 return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]);
27 } 43 }
28 44
29 - (views::Widget*)viewsWidget { 45 - (views::Widget*)viewsWidget {
30 return [[self viewsNSWindowDelegate] nativeWidgetMac]->GetWidget(); 46 return [[self viewsNSWindowDelegate] nativeWidgetMac]->GetWidget();
31 } 47 }
32 48
33 - (BOOL)hasViewsMenuActive { 49 - (BOOL)hasViewsMenuActive {
(...skipping 23 matching lines...) Expand all
57 73
58 // Dialogs shouldn't take large shadows away from their parent window. 74 // Dialogs shouldn't take large shadows away from their parent window.
59 views::Widget* widget = [self viewsWidget]; 75 views::Widget* widget = [self viewsWidget];
60 return widget->CanActivate() && !widget->IsDialogBox(); 76 return widget->CanActivate() && !widget->IsDialogBox();
61 } 77 }
62 78
63 // Override sendEvent to allow key events to be forwarded to a toolkit-views 79 // Override sendEvent to allow key events to be forwarded to a toolkit-views
64 // menu while it is active, and while still allowing any native subview to 80 // menu while it is active, and while still allowing any native subview to
65 // retain firstResponder status. 81 // retain firstResponder status.
66 - (void)sendEvent:(NSEvent*)event { 82 - (void)sendEvent:(NSEvent*)event {
83 // Let CommandDispatcher check if this is a redispatched event.
84 if ([commandDispatcher_ preSendEvent:event])
85 return;
86
67 NSEventType type = [event type]; 87 NSEventType type = [event type];
68 if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) { 88 if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) {
69 [super sendEvent:event]; 89 [super sendEvent:event];
70 return; 90 return;
71 } 91 }
72 92
73 // Send to the menu, after converting the event into an action message using 93 // Send to the menu, after converting the event into an action message using
74 // the content view. 94 // the content view.
75 if (type == NSKeyDown) 95 if (type == NSKeyDown)
76 [[self contentView] keyDown:event]; 96 [[self contentView] keyDown:event];
(...skipping 20 matching lines...) Expand all
97 // when ordering in a window for the first time. 117 // when ordering in a window for the first time.
98 - (void)orderWindow:(NSWindowOrderingMode)orderingMode 118 - (void)orderWindow:(NSWindowOrderingMode)orderingMode
99 relativeTo:(NSInteger)otherWindowNumber { 119 relativeTo:(NSInteger)otherWindowNumber {
100 [[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode]; 120 [[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode];
101 [super orderWindow:orderingMode relativeTo:otherWindowNumber]; 121 [super orderWindow:orderingMode relativeTo:otherWindowNumber];
102 [[self viewsNSWindowDelegate] onWindowOrderChanged:nil]; 122 [[self viewsNSWindowDelegate] onWindowOrderChanged:nil];
103 } 123 }
104 124
105 // NSResponder implementation. 125 // NSResponder implementation.
106 126
127 - (BOOL)performKeyEquivalent:(NSEvent*)event {
128 return [commandDispatcher_ performKeyEquivalent:event];
129 }
130
107 - (void)cursorUpdate:(NSEvent*)theEvent { 131 - (void)cursorUpdate:(NSEvent*)theEvent {
108 // The cursor provided by the delegate should only be applied within the 132 // The cursor provided by the delegate should only be applied within the
109 // content area. This is because we rely on the contentView to track the 133 // content area. This is because we rely on the contentView to track the
110 // mouse cursor and forward cursorUpdate: messages up the responder chain. 134 // mouse cursor and forward cursorUpdate: messages up the responder chain.
111 // The cursorUpdate: isn't handled in BridgedContentView because views-style 135 // The cursorUpdate: isn't handled in BridgedContentView because views-style
112 // SetCapture() conflicts with the way tracking events are processed for 136 // SetCapture() conflicts with the way tracking events are processed for
113 // the view during a drag. Since the NSWindow is still in the responder chain 137 // the view during a drag. Since the NSWindow is still in the responder chain
114 // overriding cursorUpdate: here handles both cases. 138 // overriding cursorUpdate: here handles both cases.
115 if (!NSPointInRect([theEvent locationInWindow], [[self contentView] frame])) { 139 if (!NSPointInRect([theEvent locationInWindow], [[self contentView] frame])) {
116 [super cursorUpdate:theEvent]; 140 [super cursorUpdate:theEvent];
117 return; 141 return;
118 } 142 }
119 143
120 NSCursor* cursor = [[self viewsNSWindowDelegate] cursor]; 144 NSCursor* cursor = [[self viewsNSWindowDelegate] cursor];
121 if (cursor) 145 if (cursor)
122 [cursor set]; 146 [cursor set];
123 else 147 else
124 [super cursorUpdate:theEvent]; 148 [super cursorUpdate:theEvent];
125 } 149 }
126 150
151 // CommandDispatchingWindow implementation.
152
153 - (BOOL)redispatchKeyEvent:(NSEvent*)event {
154 return [commandDispatcher_ redispatchKeyEvent:event];
155 }
156
157 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
158 return [super performKeyEquivalent:event];
159 }
160
127 @end 161 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.h ('k') | ui/views/controls/webview/unhandled_keyboard_event_handler_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698