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

Unified Diff: ui/views/controls/menu/menu_controller.cc

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/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_event_dispatcher_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_controller.cc
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index d1547c41a8c3d4aaec0de657a595a2777328e742..a4874802c450bbdb87f0063e6436722bcea76792 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -12,6 +12,7 @@
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
+#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"
@@ -804,6 +805,54 @@ void MenuController::OnDragComplete(bool should_close) {
}
}
+ui::PostDispatchAction MenuController::OnWillDispatchEvent(
+ const ui::Event& event) {
+ if (exit_type() == MenuController::EXIT_ALL ||
+ exit_type() == MenuController::EXIT_DESTROYED) {
+ TerminateNestedMessageLoop();
+ return ui::POST_DISPATCH_PERFORM_DEFAULT;
+ }
+
+ bool should_quit = false;
+ bool should_perform_default = true;
+ switch (event.type()) {
+ case ui::ET_KEY_PRESSED: {
+ const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event);
+ if (!OnKeyDown(key_event.key_code())) {
+ should_quit = true;
+ should_perform_default = false;
+ break;
+ }
+
+ // Do not check mnemonics if the Alt or Ctrl modifiers are pressed.
+ int flags = key_event.flags();
+ if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) {
+ char c = ui::GetCharacterFromKeyCode(key_event.key_code(), flags);
+ if (SelectByChar(c)) {
+ should_quit = true;
+ should_perform_default = false;
+ break;
+ }
+ }
+ should_quit = false;
+ should_perform_default = false;
+ break;
+ }
+ case ui::ET_KEY_RELEASED:
+ should_quit = false;
+ should_perform_default = false;
+ break;
+ default:
+ break;
+ }
+
+ if (should_quit || exit_type() != MenuController::EXIT_NONE)
+ TerminateNestedMessageLoop();
+
+ return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT
+ : ui::POST_DISPATCH_NONE;
+}
+
void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) {
if (submenu->IsShowing()) {
gfx::Point point = GetScreen()->GetCursorScreenPoint();
@@ -1028,16 +1077,22 @@ bool MenuController::OnKeyDown(ui::KeyboardCode key_code) {
CloseSubmenu();
break;
+// On Mac, treat space the same as return.
+#if !defined(OS_MACOSX)
case ui::VKEY_SPACE:
if (SendAcceleratorToHotTrackedView() == ACCELERATOR_PROCESSED_EXIT)
return false;
break;
+#endif
case ui::VKEY_F4:
if (!is_combobox_)
break;
// Fallthrough to accept or dismiss combobox menus on F4, like windows.
case ui::VKEY_RETURN:
+#if defined(OS_MACOSX)
+ case ui::VKEY_SPACE:
+#endif
if (pending_state_.item) {
if (pending_state_.item->HasSubmenu()) {
if (key_code == ui::VKEY_F4 &&
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_event_dispatcher_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698