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

Unified Diff: ui/views/cocoa/native_widget_mac_nswindow.mm

Issue 809773006: MacViews: Intercept events for Menus (after AppKit has interpreted keystrokes) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20141205-MacViews-AcceleratedWidget-PLUS-AddingLayers-fromcl-PLUS-bringup
Patch Set: A few more cleanups Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/controls/menu/menu_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/native_widget_mac_nswindow.mm
diff --git a/ui/views/cocoa/native_widget_mac_nswindow.mm b/ui/views/cocoa/native_widget_mac_nswindow.mm
index 7a3d3dcb931c95767957dc5fc4541fb579ecbfcb..9a6fa2ef8f4cd543b28a267046a9659a5db65e21 100644
--- a/ui/views/cocoa/native_widget_mac_nswindow.mm
+++ b/ui/views/cocoa/native_widget_mac_nswindow.mm
@@ -6,11 +6,13 @@
#include "base/mac/foundation_util.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
+#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/widget/native_widget_mac.h"
@interface NativeWidgetMacNSWindow ()
- (ViewsNSWindowDelegate*)viewsNSWindowDelegate;
- (views::Widget*)viewsWidget;
+- (BOOL)hasViewsMenuActive;
@end
@implementation NativeWidgetMacNSWindow
@@ -23,6 +25,12 @@
return [[self viewsNSWindowDelegate] nativeWidgetMac]->GetWidget();
}
+- (BOOL)hasViewsMenuActive {
+ views::MenuController* menuController =
+ views::MenuController::GetActiveInstance();
+ return menuController && menuController->owner() == [self viewsWidget];
+}
+
// Ignore [super canBecome{Key,Main}Window]. The default is NO for windows with
// NSBorderlessWindowMask, which is not the desired behavior.
// Note these can be called via -[NSWindow close] while the widget is being torn
@@ -35,6 +43,24 @@
return [self delegate] && [self viewsWidget]->CanActivate();
}
+// Override sendEvent to allow key events to be forwarded to a toolkit-views
+// menu while it is active, and while still allowing the native subview to
+// retain firstResponder status.
+- (void)sendEvent:(NSEvent*)event {
+ NSEventType type = [event type];
+ if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) {
+ [super sendEvent:event];
+ return;
+ }
+
+ // Send to the menu, after converting the event into an action message using
+ // the content view.
+ if (type == NSKeyDown)
+ [[self contentView] keyDown:event];
+ else
+ [[self contentView] keyUp:event];
+}
+
// Override display, since this is the first opportunity Cocoa gives to detect
// a visibility change in some cases. For example, restoring from the dock first
// calls -[NSWindow display] before any NSWindowDelegate functions and before
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/controls/menu/menu_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698