• tapted's avatar
    MacViews: Intercept events for Menus (after AppKit has turned them into action messages). · 370605a7
    tapted authored
    Currently keystrokes while a menu is open are sent to the window hosting
    the menu, since it remains `key`. Menus are a different window, so 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.
    
    Gets the following interactive_ui_tests passing:
    MenuControllerMnemonicTest*{NoMatch,TitleMatch,MnemonicMatch}
    MenuItemViewTestRemoveWithSubmenu{0,1}*
    (and all Menu interactive UI tests pass after this).
    
    BUG=403679
    
    Review URL: https://codereview.chromium.org/866983006
    
    Cr-Commit-Position: refs/heads/master@{#314711}
    370605a7
menu_controller.cc 82.2 KB