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

Issue 809773006: MacViews: Intercept events for Menus (after AppKit has interpreted keystrokes) (Closed)

Created:
6 years ago by tapted
Modified:
5 years, 10 months ago
Reviewers:
Andre
CC:
chromium-reviews, tfarina, tdanderson+views_chromium.org, chrome-apps-syd-reviews_chromium.org, mac-views-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@20141205-MacViews-AcceleratedWidget-PLUS-AddingLayers-fromcl-PLUS-bringup
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

MacViews: Intercept events for Menus (after AppKit has interpreted keystrokes) Currently keystrokes while a menu is open are sent to the window hosting the menu, since it remains `key`. Concretely, this causes all the Menu* interactive_ui_tests to fail since they simulate pressing ESC to dismiss the menu in the tests. Other platforms insert an event dispatcher into the message pump for the nested run loop that shows a menu, and redirect KeyDown events to the MenuController. On Mac, events need to be mapped to "Action" messages by an NSResponder to obey platform behaviour and user customizations (e.g. a "Home" keypress should be interpreted as beginning of document, not beginning of line). The approach in this CL is to check in BridgedContentView, an NSResponder, for an active menu that should be receiving events instead. Action messages are mapped to the KeyCode that toolkit-views expects for that action, and the MenuController is given an opportunity to swallow the event or have it sent on to the key window. BUG=403679

Patch Set 1 #

Patch Set 2 : Always interpretkeyevents #

Patch Set 3 : nicer logic, comments, nits #

Patch Set 4 : rollback card unmask #

Total comments: 2

Patch Set 5 : rebase #

Patch Set 6 : another rebase #

Patch Set 7 : remap all the things. But I do not like it any more - should do something more like linux-aura #

Patch Set 8 : Nice #

Patch Set 9 : Gonna have to make a dispatcher :/ #

Patch Set 10 : Now actually working #

Patch Set 11 : Fix ControlAndSelectTest and InsertionDeletionTest for native events #

Patch Set 12 : Self review #

Patch Set 13 : rebase, and fix aura omgworstgotchaever #

Patch Set 14 : Various cleanups #

Patch Set 15 : A few more cleanups #

Unified diffs Side-by-side diffs Delta from patch set Stats (+711 lines, -305 lines) Patch
M ui/base/test/ui_controls_mac.mm View 1 2 3 4 5 6 7 8 9 10 11 12 3 chunks +4 lines, -96 lines 0 comments Download
M ui/events/keycodes/keyboard_code_conversion_mac.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +1 line, -0 lines 0 comments Download
M ui/events/keycodes/keyboard_code_conversion_mac.mm View 1 2 3 4 5 6 7 8 9 10 11 12 13 2 chunks +108 lines, -108 lines 0 comments Download
M ui/events/test/cocoa_test_event_utils.h View 1 2 3 4 5 6 7 8 9 10 2 chunks +10 lines, -0 lines 0 comments Download
M ui/events/test/cocoa_test_event_utils.mm View 1 2 3 4 5 6 7 8 9 10 11 12 13 2 chunks +99 lines, -0 lines 0 comments Download
M ui/views/cocoa/bridged_content_view.mm View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 6 chunks +231 lines, -20 lines 0 comments Download
M ui/views/cocoa/native_widget_mac_nswindow.mm View 1 2 3 4 5 6 7 8 9 10 11 3 chunks +26 lines, -0 lines 0 comments Download
M ui/views/controls/menu/menu_controller.h View 1 2 3 4 5 1 chunk +4 lines, -0 lines 0 comments Download
M ui/views/controls/menu/menu_controller.cc View 1 2 3 4 5 6 7 8 9 10 3 chunks +55 lines, -0 lines 0 comments Download
M ui/views/controls/menu/menu_event_dispatcher_linux.cc View 1 2 2 chunks +14 lines, -54 lines 0 comments Download
M ui/views/controls/textfield/textfield_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 15 chunks +146 lines, -27 lines 0 comments Download
M ui/views/test/event_generator_delegate_mac.mm View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 chunks +13 lines, -0 lines 0 comments Download

Messages

Total messages: 6 (3 generated)
tapted
Hi Andre - I was hoping you could have an early look at Patchset 4. ...
6 years ago (2014-12-19 00:31:10 UTC) #2
Andre
Looks good, I think this approach should work. A bit unrelated, but I'm still unclear ...
6 years ago (2014-12-19 06:41:57 UTC) #3
tapted
5 years, 10 months ago (2015-01-28 11:18:06 UTC) #6
https://codereview.chromium.org/809773006/diff/60001/ui/views/cocoa/bridged_c...
File ui/views/cocoa/bridged_content_view.mm (right):

https://codereview.chromium.org/809773006/diff/60001/ui/views/cocoa/bridged_c...
ui/views/cocoa/bridged_content_view.mm:182: [self interpretKeyEvents:@[ theEvent
]];
On 2014/12/19 06:41:57, Andre wrote:
> How about when BridgedContentView is not first responder?
> For example, in a browser window, RenderWidgetHostViewMac might be first
> responder.
> Does the key event get forwarded here?

So this was an excellent point :)

it crossed my mind, but I naively thought that it wouldn't matter. Thinking
went: ~"it won't come up since to show a drop-down menu in Views the
RenderWidgetHostViewMac wouldn't have focus anyway". But that's not the case. We
would still want the web content showing focus/firstResponder status, so can't
take it away.

I tried a *lot* of things and eventually got to something that seems to work
pretty nice with a combination of an override of -[NSWindow sendEvent] and an
override of -[NSView inputContext].

But then while adding tests it all got a bit unwieldy, so I've split this up
into 4 CLs:

http://crrev.com/856313003 Mac: Refine ui_controls_mac's SynthesizeKeyEvent()
[landed]
http://crrev.com/882053002 MacViews: Move some key-event utility functions out
of anon namespaces
http://crrev.com/879253002 MacViews: Convert Cocoa action messages into editing
comands for text fields
http://crrev.com/866983006 MacViews: Intercept events for Menus (after AppKit
has turned them into action messages).



the last one has the "interesting" stuff for the event interception (and
highlights the approach I eventually got to), but the textfields one should land
first since it's more mechanical - I'll send it out for your review now.

Powered by Google App Engine
This is Rietveld 408576698