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

Side by Side 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: rollback card unmask Created 6 years 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
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/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "ui/base/dragdrop/drag_utils.h" 11 #include "ui/base/dragdrop/drag_utils.h"
12 #include "ui/base/dragdrop/os_exchange_data.h" 12 #include "ui/base/dragdrop/os_exchange_data.h"
13 #include "ui/events/event.h" 13 #include "ui/events/event.h"
14 #include "ui/events/event_utils.h" 14 #include "ui/events/event_utils.h"
15 #include "ui/events/keycodes/keyboard_code_conversion.h"
15 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/point.h" 18 #include "ui/gfx/point.h"
18 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
19 #include "ui/gfx/vector2d.h" 20 #include "ui/gfx/vector2d.h"
20 #include "ui/native_theme/native_theme.h" 21 #include "ui/native_theme/native_theme.h"
21 #include "ui/views/controls/button/menu_button.h" 22 #include "ui/views/controls/button/menu_button.h"
22 #include "ui/views/controls/menu/menu_config.h" 23 #include "ui/views/controls/menu/menu_config.h"
23 #include "ui/views/controls/menu/menu_controller_delegate.h" 24 #include "ui/views/controls/menu/menu_controller_delegate.h"
24 #include "ui/views/controls/menu/menu_host_root_view.h" 25 #include "ui/views/controls/menu/menu_host_root_view.h"
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 794
794 void MenuController::OnDragComplete(bool should_close) { 795 void MenuController::OnDragComplete(bool should_close) {
795 DCHECK(drag_in_progress_); 796 DCHECK(drag_in_progress_);
796 drag_in_progress_ = false; 797 drag_in_progress_ = false;
797 if (showing_ && should_close && GetActiveInstance() == this) { 798 if (showing_ && should_close && GetActiveInstance() == this) {
798 CloseAllNestedMenus(); 799 CloseAllNestedMenus();
799 Cancel(EXIT_ALL); 800 Cancel(EXIT_ALL);
800 } 801 }
801 } 802 }
802 803
804 ui::PostDispatchAction MenuController::OnWillDispatchEvent(
805 const ui::Event& event) {
806 if (exit_type() == MenuController::EXIT_ALL ||
807 exit_type() == MenuController::EXIT_DESTROYED) {
808 TerminateNestedMessageLoop();
809 return ui::POST_DISPATCH_PERFORM_DEFAULT;
810 }
811
812 bool should_quit = false;
813 bool should_perform_default = true;
814 switch (event.type()) {
815 case ui::ET_KEY_PRESSED: {
816 const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event);
817 if (!OnKeyDown(key_event.key_code())) {
818 should_quit = true;
819 should_perform_default = false;
820 break;
821 }
822
823 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed.
824 int flags = key_event.flags();
825 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) {
826 char c = ui::GetCharacterFromKeyCode(key_event.key_code(), flags);
827 if (SelectByChar(c)) {
828 should_quit = true;
829 should_perform_default = false;
830 break;
831 }
832 }
833 should_quit = false;
834 should_perform_default = false;
835 break;
836 }
837 case ui::ET_KEY_RELEASED:
838 should_quit = false;
839 should_perform_default = false;
840 break;
841 default:
842 break;
843 }
844
845 if (should_quit || exit_type() != MenuController::EXIT_NONE)
846 TerminateNestedMessageLoop();
847
848 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT
849 : ui::POST_DISPATCH_NONE;
850 }
851
803 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { 852 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) {
804 if (submenu->IsShowing()) { 853 if (submenu->IsShowing()) {
805 gfx::Point point = GetScreen()->GetCursorScreenPoint(); 854 gfx::Point point = GetScreen()->GetCursorScreenPoint();
806 const SubmenuView* root_submenu = 855 const SubmenuView* root_submenu =
807 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); 856 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu();
808 View::ConvertPointFromScreen( 857 View::ConvertPointFromScreen(
809 root_submenu->GetWidget()->GetRootView(), &point); 858 root_submenu->GetWidget()->GetRootView(), &point);
810 HandleMouseLocation(submenu, point); 859 HandleMouseLocation(submenu, point);
811 } 860 }
812 } 861 }
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 } 2352 }
2304 } 2353 }
2305 2354
2306 gfx::Screen* MenuController::GetScreen() { 2355 gfx::Screen* MenuController::GetScreen() {
2307 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; 2356 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2308 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) 2357 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2309 : gfx::Screen::GetNativeScreen(); 2358 : gfx::Screen::GetNativeScreen();
2310 } 2359 }
2311 2360
2312 } // namespace views 2361 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698