From df726d0f416a4bd8a4ec58e197c29150e9ab0892 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Jun 2016 10:26:48 -0700 Subject: [PATCH 1/3] Redispatch key events to handle native shortcuts --- .../mac/bry_inspectable_web_contents_view.mm | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a1b8dd3c0547..e0b497f8403b 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -10,6 +10,44 @@ using namespace brightray; +@interface EventDispatchingWindow : UnderlayOpenGLHostingWindow { + @private + BOOL redispatchingEvent_; +} + +- (void)redispatchKeyEvent:(NSEvent*)event; + +@end + +@implementation EventDispatchingWindow + +- (void)sendEvent:(NSEvent*)event { + if (!redispatchingEvent_) + [super sendEvent:event]; +} + +- (BOOL)performKeyEquivalent:(NSEvent*)event { + if (redispatchingEvent_) + return NO; + else + return [super performKeyEquivalent:event]; + } + +- (void)redispatchKeyEvent:(NSEvent*)event { + NSEventType eventType = [event type]; + if (eventType != NSKeyDown && eventType != NSKeyUp && + eventType != NSFlagsChanged) { + return; + } + + // Redispatch the event. + redispatchingEvent_ = YES; + [NSApp sendEvent:event]; + redispatchingEvent_ = NO; +} + +@end + @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { @@ -132,7 +170,7 @@ using namespace brightray; NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask; - devtools_window_.reset([[UnderlayOpenGLHostingWindow alloc] + devtools_window_.reset([[EventDispatchingWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) styleMask:styleMask backing:NSBackingStoreBuffered From 8bee2d7b7f7201f8484872f868b2663662d5a37c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Jun 2016 10:57:28 -0700 Subject: [PATCH 2/3] Break out EventDispatchingWindow into separate class --- .../mac/bry_inspectable_web_contents_view.mm | 39 +------------------ .../browser/mac/event_dispatching_window.h | 19 +++++++++ .../browser/mac/event_dispatching_window.mm | 34 ++++++++++++++++ brightray/filenames.gypi | 2 + 4 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 brightray/browser/mac/event_dispatching_window.h create mode 100644 brightray/browser/mac/event_dispatching_window.mm diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index e0b497f8403b..ade97d1c5fb5 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -3,6 +3,7 @@ #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_delegate.h" #include "browser/inspectable_web_contents_view_mac.h" +#include "browser/mac/event_dispatching_window.h" #include "content/public/browser/render_widget_host_view.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" @@ -10,44 +11,6 @@ using namespace brightray; -@interface EventDispatchingWindow : UnderlayOpenGLHostingWindow { - @private - BOOL redispatchingEvent_; -} - -- (void)redispatchKeyEvent:(NSEvent*)event; - -@end - -@implementation EventDispatchingWindow - -- (void)sendEvent:(NSEvent*)event { - if (!redispatchingEvent_) - [super sendEvent:event]; -} - -- (BOOL)performKeyEquivalent:(NSEvent*)event { - if (redispatchingEvent_) - return NO; - else - return [super performKeyEquivalent:event]; - } - -- (void)redispatchKeyEvent:(NSEvent*)event { - NSEventType eventType = [event type]; - if (eventType != NSKeyDown && eventType != NSKeyUp && - eventType != NSFlagsChanged) { - return; - } - - // Redispatch the event. - redispatchingEvent_ = YES; - [NSApp sendEvent:event]; - redispatchingEvent_ = NO; -} - -@end - @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { diff --git a/brightray/browser/mac/event_dispatching_window.h b/brightray/browser/mac/event_dispatching_window.h new file mode 100644 index 000000000000..27ed9e6bf2f9 --- /dev/null +++ b/brightray/browser/mac/event_dispatching_window.h @@ -0,0 +1,19 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_EVENT_DISPATCHING_WINDOW_H_ +#define BROWSER_EVENT_DISPATCHING_WINDOW_H_ + +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" + +@interface EventDispatchingWindow : UnderlayOpenGLHostingWindow { + @private + BOOL redispatchingEvent_; +} + +- (void)redispatchKeyEvent:(NSEvent*)event; + +@end + +#endif // BROWSER_EVENT_DISPATCHING_WINDOW_H_ diff --git a/brightray/browser/mac/event_dispatching_window.mm b/brightray/browser/mac/event_dispatching_window.mm new file mode 100644 index 000000000000..08e8edebb0b9 --- /dev/null +++ b/brightray/browser/mac/event_dispatching_window.mm @@ -0,0 +1,34 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/mac/event_dispatching_window.h" + +@implementation EventDispatchingWindow + +- (void)sendEvent:(NSEvent*)event { + if (!redispatchingEvent_) + [super sendEvent:event]; +} + +- (BOOL)performKeyEquivalent:(NSEvent*)event { + if (redispatchingEvent_) + return NO; + else + return [super performKeyEquivalent:event]; + } + +- (void)redispatchKeyEvent:(NSEvent*)event { + NSEventType eventType = [event type]; + if (eventType != NSKeyDown && eventType != NSKeyUp && + eventType != NSFlagsChanged) { + return; + } + + // Redispatch the event. + redispatchingEvent_ = YES; + [NSApp sendEvent:event]; + redispatchingEvent_ = NO; +} + +@end diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 98818759d26d..944b8824da04 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -35,6 +35,8 @@ 'browser/mac/bry_inspectable_web_contents_view.mm', 'browser/mac/cocoa_notification.h', 'browser/mac/cocoa_notification.mm', + 'browser/mac/event_dispatching_window.h', + 'browser/mac/event_dispatching_window.mm', 'browser/mac/notification_center_delegate.h', 'browser/mac/notification_center_delegate.mm', 'browser/mac/notification_presenter_mac.h', From ebc7432893747b9281caef7830008927fe7ce778 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Jun 2016 11:37:29 -0700 Subject: [PATCH 3/3] Remove unused import --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index ade97d1c5fb5..16174ed36174 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -6,7 +6,6 @@ #include "browser/mac/event_dispatching_window.h" #include "content/public/browser/render_widget_host_view.h" -#import "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" using namespace brightray;