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

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

Issue 9958152: Consolidate win/x dispatchers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 8 years, 8 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
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"
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 if (GetActiveInstance() == this) { 850 if (GetActiveInstance() == this) {
851 if (showing_) { 851 if (showing_) {
852 // We're still showing, close all menus. 852 // We're still showing, close all menus.
853 CloseAllNestedMenus(); 853 CloseAllNestedMenus();
854 Cancel(EXIT_ALL); 854 Cancel(EXIT_ALL);
855 } // else case, drop was on us. 855 } // else case, drop was on us.
856 } // else case, someone canceled us, don't do anything 856 } // else case, someone canceled us, don't do anything
857 } 857 }
858 858
859 #if defined(OS_WIN) 859 #if defined(OS_WIN)
860 bool MenuController::Dispatch(const MSG& msg) { 860 base::DispatchStatus MenuController::Dispatch(const MSG& msg) {
861 DCHECK(blocking_run_); 861 DCHECK(blocking_run_);
862 862
863 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) { 863 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) {
864 // We must translate/dispatch the message here, otherwise we would drop 864 // We must translate/dispatch the message here, otherwise we would drop
865 // the message on the floor. 865 // the message on the floor.
866 TranslateMessage(&msg); 866 TranslateMessage(&msg);
867 DispatchMessage(&msg); 867 DispatchMessage(&msg);
868 return false; 868 return base::EVENT_QUIT;
869 } 869 }
870 870
871 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here. 871 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here.
872 switch (msg.message) { 872 switch (msg.message) {
873 case WM_CONTEXTMENU: { 873 case WM_CONTEXTMENU: {
874 MenuItemView* item = pending_state_.item; 874 MenuItemView* item = pending_state_.item;
875 if (item && item->GetRootMenuItem() != item) { 875 if (item && item->GetRootMenuItem() != item) {
876 gfx::Point screen_loc(0, item->height()); 876 gfx::Point screen_loc(0, item->height());
877 View::ConvertPointToScreen(item, &screen_loc); 877 View::ConvertPointToScreen(item, &screen_loc);
878 item->GetDelegate()->ShowContextMenu(item, item->GetCommand(), 878 item->GetDelegate()->ShowContextMenu(item, item->GetCommand(),
879 screen_loc, false); 879 screen_loc, false);
880 } 880 }
881 return true; 881 return base::EVENT_PROCESSED;
882 } 882 }
883 883
884 // NOTE: focus wasn't changed when the menu was shown. As such, don't 884 // NOTE: focus wasn't changed when the menu was shown. As such, don't
885 // dispatch key events otherwise the focused window will get the events. 885 // dispatch key events otherwise the focused window will get the events.
886 case WM_KEYDOWN: { 886 case WM_KEYDOWN: {
887 bool result = OnKeyDown(ui::KeyboardCodeFromNative(msg)); 887 bool result = OnKeyDown(ui::KeyboardCodeFromNative(msg));
888 TranslateMessage(&msg); 888 TranslateMessage(&msg);
889 return result; 889 return result ? base::EVENT_PROCESSED : base::EVENT_QUIT;
890 } 890 }
891 case WM_CHAR: 891 case WM_CHAR:
892 return !SelectByChar(static_cast<char16>(msg.wParam)); 892 return SelectByChar(static_cast<char16>(msg.wParam)) ?
893 893 base::EVENT_QUIT : base::EVENT_PROCESSED;
894 case WM_KEYUP: 894 case WM_KEYUP:
895 return true; 895 return base::EVENT_PROCESSED;
896 896
897 case WM_SYSKEYUP: 897 case WM_SYSKEYUP:
898 // We may have been shown on a system key, as such don't do anything 898 // We may have been shown on a system key, as such don't do anything
899 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and 899 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and
900 // close the menu. 900 // close the menu.
901 return true; 901 return base::EVENT_PROCESSED;
902 902
903 case WM_CANCELMODE: 903 case WM_CANCELMODE:
904 case WM_SYSKEYDOWN: 904 case WM_SYSKEYDOWN:
905 // Exit immediately on system keys. 905 // Exit immediately on system keys.
906 Cancel(EXIT_ALL); 906 Cancel(EXIT_ALL);
907 return false; 907 return base::EVENT_QUIT;
908 908
909 default: 909 default:
910 break; 910 break;
911 } 911 }
912 TranslateMessage(&msg); 912 TranslateMessage(&msg);
913 DispatchMessage(&msg); 913 DispatchMessage(&msg);
914 return exit_type_ == EXIT_NONE; 914 return exit_type_ != EXIT_NONE ? base::EVENT_QUIT : base::EVENT_PROCESSED;
915 } 915 }
916 #elif defined(USE_WAYLAND) 916 #elif defined(USE_WAYLAND)
917 base::MessagePumpDispatcher::DispatchStatus 917 base::MessagePumpDispatcher::DispatchStatus
918 MenuController::Dispatch(base::wayland::WaylandEvent* ev) { 918 MenuController::Dispatch(base::wayland::WaylandEvent* ev) {
919 return exit_type_ != EXIT_NONE ? 919 return exit_type_ != EXIT_NONE ? base::EVENT_QUIT :base::EVENT_PROCESSED;
920 base::MessagePumpDispatcher::EVENT_QUIT :
921 base::MessagePumpDispatcher::EVENT_PROCESSED;
922 } 920 }
923 921
924 #elif defined(USE_AURA) 922 #elif defined(USE_AURA)
925 base::MessagePumpDispatcher::DispatchStatus 923 base::DispatchStatus MenuController::Dispatch(const base::NativeEvent& xev) {
926 MenuController::Dispatch(XEvent* xev) { 924 // XEvent* xev = event;
927 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) { 925 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) {
928 aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev); 926 aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev);
929 return base::MessagePumpDispatcher::EVENT_QUIT; 927 return base::EVENT_QUIT;
930 } 928 }
931 switch (ui::EventTypeFromNative(xev)) { 929 switch (ui::EventTypeFromNative(xev)) {
932 case ui::ET_KEY_PRESSED: 930 case ui::ET_KEY_PRESSED:
933 if (!OnKeyDown(ui::KeyboardCodeFromNative(xev))) 931 if (!OnKeyDown(ui::KeyboardCodeFromNative(xev)))
934 return base::MessagePumpDispatcher::EVENT_QUIT; 932 return base::EVENT_QUIT;
935 933
936 return SelectByChar(ui::KeyboardCodeFromNative(xev)) ? 934 return SelectByChar(ui::KeyboardCodeFromNative(xev)) ?
937 base::MessagePumpDispatcher::EVENT_QUIT : 935 base::EVENT_QUIT : base::EVENT_PROCESSED;
938 base::MessagePumpDispatcher::EVENT_PROCESSED;
939 case ui::ET_KEY_RELEASED: 936 case ui::ET_KEY_RELEASED:
940 return base::MessagePumpDispatcher::EVENT_PROCESSED; 937 return base::EVENT_PROCESSED;
941 default: 938 default:
942 break; 939 break;
943 } 940 }
944 941
945 // TODO(oshima): Update Windows' Dispatcher to return DispatchStatus
946 // instead of bool.
947 if (aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev) == 942 if (aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev) ==
948 base::MessagePumpDispatcher::EVENT_IGNORED) 943 base::EVENT_IGNORED)
949 return EVENT_IGNORED; 944 return base::EVENT_IGNORED;
950 return exit_type_ != EXIT_NONE ? 945 return exit_type_ != EXIT_NONE ? base::EVENT_QUIT : base::EVENT_PROCESSED;
951 base::MessagePumpDispatcher::EVENT_QUIT :
952 base::MessagePumpDispatcher::EVENT_PROCESSED;
953 } 946 }
954 #endif 947 #endif
955 948
956 bool MenuController::OnKeyDown(ui::KeyboardCode key_code) { 949 bool MenuController::OnKeyDown(ui::KeyboardCode key_code) {
957 DCHECK(blocking_run_); 950 DCHECK(blocking_run_);
958 951
959 switch (key_code) { 952 switch (key_code) {
960 case ui::VKEY_UP: 953 case ui::VKEY_UP:
961 IncrementSelection(-1); 954 IncrementSelection(-1);
962 break; 955 break;
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 (!pending_state_.item->HasSubmenu() || 2017 (!pending_state_.item->HasSubmenu() ||
2025 !pending_state_.item->GetSubmenu()->IsShowing())) { 2018 !pending_state_.item->GetSubmenu()->IsShowing())) {
2026 // On exit if the user hasn't selected an item with a submenu, move the 2019 // On exit if the user hasn't selected an item with a submenu, move the
2027 // selection back to the parent menu item. 2020 // selection back to the parent menu item.
2028 SetSelection(pending_state_.item->GetParentMenuItem(), 2021 SetSelection(pending_state_.item->GetParentMenuItem(),
2029 SELECTION_OPEN_SUBMENU); 2022 SELECTION_OPEN_SUBMENU);
2030 } 2023 }
2031 } 2024 }
2032 2025
2033 } // namespace views 2026 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698