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

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: Similarity=30 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 24
25 - (instancetype)initWithContentRect:(NSRect)contentRect
26 styleMask:(NSUInteger)windowStyle
27 backing:(NSBackingStoreType)bufferingType
28 defer:(BOOL)deferCreation {
29 if ((self = [super initWithContentRect:contentRect
30 styleMask:windowStyle
31 backing:bufferingType
32 defer:deferCreation])) {
33 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]);
34 }
35 return self;
36 }
37
25 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate { 38 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate {
26 return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]); 39 return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]);
27 } 40 }
28 41
29 - (views::Widget*)viewsWidget { 42 - (views::Widget*)viewsWidget {
30 return [[self viewsNSWindowDelegate] nativeWidgetMac]->GetWidget(); 43 return [[self viewsNSWindowDelegate] nativeWidgetMac]->GetWidget();
31 } 44 }
32 45
33 - (BOOL)hasViewsMenuActive { 46 - (BOOL)hasViewsMenuActive {
34 views::MenuController* menuController = 47 views::MenuController* menuController =
(...skipping 22 matching lines...) Expand all
57 70
58 // Dialogs shouldn't take large shadows away from their parent window. 71 // Dialogs shouldn't take large shadows away from their parent window.
59 views::Widget* widget = [self viewsWidget]; 72 views::Widget* widget = [self viewsWidget];
60 return widget->CanActivate() && !widget->IsDialogBox(); 73 return widget->CanActivate() && !widget->IsDialogBox();
61 } 74 }
62 75
63 // Override sendEvent to allow key events to be forwarded to a toolkit-views 76 // 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 77 // menu while it is active, and while still allowing any native subview to
65 // retain firstResponder status. 78 // retain firstResponder status.
66 - (void)sendEvent:(NSEvent*)event { 79 - (void)sendEvent:(NSEvent*)event {
80 // Let CommandDispatcher check if this is a redispatched event.
81 if ([commandDispatcher_ preSendEvent:event])
82 return;
83
67 NSEventType type = [event type]; 84 NSEventType type = [event type];
68 if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) { 85 if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) {
69 [super sendEvent:event]; 86 [super sendEvent:event];
70 return; 87 return;
71 } 88 }
72 89
73 // Send to the menu, after converting the event into an action message using 90 // Send to the menu, after converting the event into an action message using
74 // the content view. 91 // the content view.
75 if (type == NSKeyDown) 92 if (type == NSKeyDown)
76 [[self contentView] keyDown:event]; 93 [[self contentView] keyDown:event];
(...skipping 20 matching lines...) Expand all
97 // when ordering in a window for the first time. 114 // when ordering in a window for the first time.
98 - (void)orderWindow:(NSWindowOrderingMode)orderingMode 115 - (void)orderWindow:(NSWindowOrderingMode)orderingMode
99 relativeTo:(NSInteger)otherWindowNumber { 116 relativeTo:(NSInteger)otherWindowNumber {
100 [[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode]; 117 [[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode];
101 [super orderWindow:orderingMode relativeTo:otherWindowNumber]; 118 [super orderWindow:orderingMode relativeTo:otherWindowNumber];
102 [[self viewsNSWindowDelegate] onWindowOrderChanged:nil]; 119 [[self viewsNSWindowDelegate] onWindowOrderChanged:nil];
103 } 120 }
104 121
105 // NSResponder implementation. 122 // NSResponder implementation.
106 123
124 - (BOOL)performKeyEquivalent:(NSEvent*)event {
125 return [commandDispatcher_ performKeyEquivalent:event];
126 }
127
107 - (void)cursorUpdate:(NSEvent*)theEvent { 128 - (void)cursorUpdate:(NSEvent*)theEvent {
108 // The cursor provided by the delegate should only be applied within the 129 // 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 130 // content area. This is because we rely on the contentView to track the
110 // mouse cursor and forward cursorUpdate: messages up the responder chain. 131 // mouse cursor and forward cursorUpdate: messages up the responder chain.
111 // The cursorUpdate: isn't handled in BridgedContentView because views-style 132 // The cursorUpdate: isn't handled in BridgedContentView because views-style
112 // SetCapture() conflicts with the way tracking events are processed for 133 // 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 134 // the view during a drag. Since the NSWindow is still in the responder chain
114 // overriding cursorUpdate: here handles both cases. 135 // overriding cursorUpdate: here handles both cases.
115 if (!NSPointInRect([theEvent locationInWindow], [[self contentView] frame])) { 136 if (!NSPointInRect([theEvent locationInWindow], [[self contentView] frame])) {
116 [super cursorUpdate:theEvent]; 137 [super cursorUpdate:theEvent];
117 return; 138 return;
118 } 139 }
119 140
120 NSCursor* cursor = [[self viewsNSWindowDelegate] cursor]; 141 NSCursor* cursor = [[self viewsNSWindowDelegate] cursor];
121 if (cursor) 142 if (cursor)
122 [cursor set]; 143 [cursor set];
123 else 144 else
124 [super cursorUpdate:theEvent]; 145 [super cursorUpdate:theEvent];
125 } 146 }
126 147
148 // CommandDispatcher implementation.
149
150 - (BOOL)redispatchKeyEvent:(NSEvent*)event {
151 return [commandDispatcher_ redispatchKeyEvent:event];
152 }
153
154 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
155 return [super performKeyEquivalent:event];
156 }
157
158 // Public methods.
tapted 2015/08/26 06:46:54 nit: new methods before overrides (in the follow-u
jackhou1 2015/08/26 07:38:17 Done.
159
160 - (void)setCommandDispatcherDelegate:(id<CommandDispatcherDelegate>)delegate {
161 [commandDispatcher_ setDelegate:delegate];
162 }
163
127 @end 164 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698