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

Side by Side Diff: ui/views/controls/menu/menu_controller.cc

Issue 9224001: Fixes issue with accelerators when a menu is open (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nicer diff Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/menu/menu_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "ui/base/accelerators/accelerator.h"
11 #include "ui/base/dragdrop/os_exchange_data.h" 12 #include "ui/base/dragdrop/os_exchange_data.h"
12 #include "ui/base/events.h" 13 #include "ui/base/events.h"
13 #include "ui/base/keycodes/keyboard_codes.h" 14 #include "ui/base/keycodes/keyboard_codes.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/canvas_skia.h" 16 #include "ui/gfx/canvas_skia.h"
16 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
17 #include "ui/views/controls/button/menu_button.h" 18 #include "ui/views/controls/button/menu_button.h"
18 #include "ui/views/controls/menu/menu_controller_delegate.h" 19 #include "ui/views/controls/menu/menu_controller_delegate.h"
19 #include "ui/views/controls/menu/menu_scroll_view_container.h" 20 #include "ui/views/controls/menu/menu_scroll_view_container.h"
20 #include "ui/views/controls/menu/submenu_view.h" 21 #include "ui/views/controls/menu/submenu_view.h"
21 #include "ui/views/drag_utils.h" 22 #include "ui/views/drag_utils.h"
23 #include "ui/views/focus/focus_manager.h"
22 #include "ui/views/view_constants.h" 24 #include "ui/views/view_constants.h"
23 #include "ui/views/views_delegate.h" 25 #include "ui/views/views_delegate.h"
24 #include "ui/views/widget/root_view.h" 26 #include "ui/views/widget/root_view.h"
25 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
26 28
27 #if defined(USE_AURA) 29 #if defined(USE_AURA)
30 #include "ash/accelerators/accelerator_controller.h"
31 #include "ash/shell.h"
32 #include "ui/aura/event.h"
28 #include "ui/aura/root_window.h" 33 #include "ui/aura/root_window.h"
29 #elif defined(TOOLKIT_USES_GTK) 34 #elif defined(TOOLKIT_USES_GTK)
30 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" 35 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h"
31 #endif 36 #endif
32 37
33 using base::Time; 38 using base::Time;
34 using base::TimeDelta; 39 using base::TimeDelta;
35 using ui::OSExchangeData; 40 using ui::OSExchangeData;
36 41
37 // Period of the scroll timer (in milliseconds). 42 // Period of the scroll timer (in milliseconds).
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 base::MessagePumpDispatcher::EVENT_PROCESSED; 884 base::MessagePumpDispatcher::EVENT_PROCESSED;
880 } 885 }
881 886
882 #elif defined(USE_AURA) 887 #elif defined(USE_AURA)
883 base::MessagePumpDispatcher::DispatchStatus 888 base::MessagePumpDispatcher::DispatchStatus
884 MenuController::Dispatch(XEvent* xev) { 889 MenuController::Dispatch(XEvent* xev) {
885 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) { 890 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) {
886 aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch(xev); 891 aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch(xev);
887 return base::MessagePumpDispatcher::EVENT_QUIT; 892 return base::MessagePumpDispatcher::EVENT_QUIT;
888 } 893 }
894
895 ui::KeyboardCode key_code = ui::KeyboardCodeFromNative(xev);
896 int flags = ui::EventFlagsFromNative(xev);
897
889 switch (ui::EventTypeFromNative(xev)) { 898 switch (ui::EventTypeFromNative(xev)) {
890 case ui::ET_KEY_PRESSED: 899 case ui::ET_KEY_PRESSED:
891 if (!OnKeyDown(ui::KeyboardCodeFromNative(xev))) 900 if (!OnKeyDown(key_code))
892 return base::MessagePumpDispatcher::EVENT_QUIT; 901 return base::MessagePumpDispatcher::EVENT_QUIT;
893 902
894 // OnKeyDown may have set exit_type_. 903 // OnKeyDown may have set exit_type_.
895 // TODO(sky): This shouldn't be necessary if OnKeyDown returns correct 904 // TODO(sky): This shouldn't be necessary if OnKeyDown returns correct
896 // value for space key on edit menu. Fix OnKeyDown and remove this. 905 // value for space key on edit menu. Fix OnKeyDown and remove this.
897 // See crbug.com/107919. 906 // See crbug.com/107919.
898 if (exit_type_ != EXIT_NONE) 907 if (exit_type_ != EXIT_NONE)
899 return base::MessagePumpDispatcher::EVENT_QUIT; 908 return base::MessagePumpDispatcher::EVENT_QUIT;
900 909
901 return SelectByChar(ui::KeyboardCodeFromNative(xev)) ? 910 if (SelectByChar(key_code))
902 base::MessagePumpDispatcher::EVENT_QUIT : 911 return base::MessagePumpDispatcher::EVENT_QUIT;
903 base::MessagePumpDispatcher::EVENT_PROCESSED; 912
913 {
914 const int kModifierFlagMask = (ui::EF_SHIFT_DOWN |
915 ui::EF_CONTROL_DOWN |
916 ui::EF_ALT_DOWN);
917
918 ui::Accelerator accelerator = ui::Accelerator(key_code,
919 flags & kModifierFlagMask);
oshima 2012/01/19 18:29:48 just accelerator(key_code, flags & kModifierFlagMa
920 FocusManager* focus_manager = menu_button_->GetWidget()->
921 GetFocusManager();
oshima 2012/01/19 18:29:48 menu_button_->GetFocusManager()
922 ash::AcceleratorController* accelerator_controller =
923 ash::Shell::GetInstance()->accelerator_controller();
oshima 2012/01/19 18:29:48 have you looked into handling this on aura/ash sid
924 if (focus_manager && focus_manager->ProcessAccelerator(accelerator))
925 return base::MessagePumpDispatcher::EVENT_QUIT;
oshima 2012/01/19 18:29:48 You're executing accelerator inside nested loop wh
926 else if (accelerator_controller && accelerator_controller->
927 Process(accelerator))
928 return base::MessagePumpDispatcher::EVENT_QUIT;
929 }
930 return base::MessagePumpDispatcher::EVENT_PROCESSED;
904 case ui::ET_KEY_RELEASED: 931 case ui::ET_KEY_RELEASED:
905 return base::MessagePumpDispatcher::EVENT_PROCESSED; 932 return base::MessagePumpDispatcher::EVENT_PROCESSED;
906 default: 933 default:
907 break; 934 break;
908 } 935 }
909 936
910 // TODO(oshima): Update Windows' Dispatcher to return DispatchStatus 937 // TODO(oshima): Update Windows' Dispatcher to return DispatchStatus
911 // instead of bool. 938 // instead of bool.
912 if (aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch(xev) == 939 if (aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch(xev) ==
913 base::MessagePumpDispatcher::EVENT_IGNORED) 940 base::MessagePumpDispatcher::EVENT_IGNORED)
914 return EVENT_IGNORED; 941 return EVENT_IGNORED;
915 return exit_type_ != EXIT_NONE ? 942 return exit_type_ != EXIT_NONE ?
916 base::MessagePumpDispatcher::EVENT_QUIT : 943 base::MessagePumpDispatcher::EVENT_QUIT :
917 base::MessagePumpDispatcher::EVENT_PROCESSED; 944 base::MessagePumpDispatcher::EVENT_PROCESSED;
918 } 945 }
919 #else 946 #else
920 bool MenuController::Dispatch(GdkEvent* event) { 947 bool MenuController::Dispatch(GdkEvent* event) {
921 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) { 948 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) {
922 gtk_main_do_event(event); 949 gtk_main_do_eSvent(event);
oshima 2012/01/19 18:29:48 revert this change?
923 return false; 950 return false;
924 } 951 }
925 952
926 switch (event->type) { 953 switch (event->type) {
927 case GDK_KEY_PRESS: { 954 case GDK_KEY_PRESS: {
928 if (!OnKeyDown(ui::WindowsKeyCodeForGdkKeyCode(event->key.keyval))) 955 if (!OnKeyDown(ui::WindowsKeyCodeForGdkKeyCode(event->key.keyval)))
929 return false; 956 return false;
930 957
931 // OnKeyDown may have set exit_type_. 958 // OnKeyDown may have set exit_type_.
932 // TODO(sky): Eliminate this. See crbug.com/107919. 959 // TODO(sky): Eliminate this. See crbug.com/107919.
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 // is necessary to exit from nested loop (See Dispatch methods). 1996 // is necessary to exit from nested loop (See Dispatch methods).
1970 // Send non-op event so that Dispatch method will always be called. 1997 // Send non-op event so that Dispatch method will always be called.
1971 // crbug.com/104684. 1998 // crbug.com/104684.
1972 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) 1999 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED)
1973 aura::RootWindow::GetInstance()->PostNativeEvent(ui::CreateNoopEvent()); 2000 aura::RootWindow::GetInstance()->PostNativeEvent(ui::CreateNoopEvent());
1974 #endif 2001 #endif
1975 } 2002 }
1976 2003
1977 2004
1978 } // namespace views 2005 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698