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

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

Issue 267593005: Refactor menu controller to isolate aura dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and merge with http://crrev.com/269819 Created 6 years, 7 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 #if defined(OS_WIN)
8 #include <windowsx.h>
9 #endif
10
11 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
12 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 10 #include "base/time/time.h"
16 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/window.h"
19 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/aura/window_tree_host.h"
21 #include "ui/base/dragdrop/drag_utils.h" 11 #include "ui/base/dragdrop/drag_utils.h"
22 #include "ui/base/dragdrop/os_exchange_data.h" 12 #include "ui/base/dragdrop/os_exchange_data.h"
23 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/events/event.h" 14 #include "ui/events/event.h"
25 #include "ui/events/event_utils.h" 15 #include "ui/events/event_utils.h"
26 #include "ui/events/platform/platform_event_source.h"
27 #include "ui/events/platform/scoped_event_dispatcher.h"
28 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
29 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
30 #include "ui/gfx/point.h" 18 #include "ui/gfx/point.h"
31 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
32 #include "ui/gfx/vector2d.h" 20 #include "ui/gfx/vector2d.h"
33 #include "ui/native_theme/native_theme.h" 21 #include "ui/native_theme/native_theme.h"
34 #include "ui/views/controls/button/menu_button.h" 22 #include "ui/views/controls/button/menu_button.h"
35 #include "ui/views/controls/menu/menu_config.h" 23 #include "ui/views/controls/menu/menu_config.h"
36 #include "ui/views/controls/menu/menu_controller_delegate.h" 24 #include "ui/views/controls/menu/menu_controller_delegate.h"
37 #include "ui/views/controls/menu/menu_host_root_view.h" 25 #include "ui/views/controls/menu/menu_host_root_view.h"
38 #include "ui/views/controls/menu/menu_item_view.h" 26 #include "ui/views/controls/menu/menu_item_view.h"
27 #include "ui/views/controls/menu/menu_message_loop.h"
39 #include "ui/views/controls/menu/menu_scroll_view_container.h" 28 #include "ui/views/controls/menu/menu_scroll_view_container.h"
40 #include "ui/views/controls/menu/submenu_view.h" 29 #include "ui/views/controls/menu/submenu_view.h"
41 #include "ui/views/drag_utils.h" 30 #include "ui/views/drag_utils.h"
42 #include "ui/views/focus/view_storage.h" 31 #include "ui/views/focus/view_storage.h"
43 #include "ui/views/mouse_constants.h" 32 #include "ui/views/mouse_constants.h"
44 #include "ui/views/view.h" 33 #include "ui/views/view.h"
45 #include "ui/views/view_constants.h" 34 #include "ui/views/view_constants.h"
46 #include "ui/views/views_delegate.h" 35 #include "ui/views/views_delegate.h"
47 #include "ui/views/widget/root_view.h" 36 #include "ui/views/widget/root_view.h"
48 #include "ui/views/widget/tooltip_manager.h" 37 #include "ui/views/widget/tooltip_manager.h"
49 #include "ui/views/widget/widget.h" 38 #include "ui/views/widget/widget.h"
50 #include "ui/wm/public/activation_change_observer.h"
51 #include "ui/wm/public/activation_client.h"
52 #include "ui/wm/public/dispatcher_client.h"
53 #include "ui/wm/public/drag_drop_client.h"
54 39
55 #if defined(OS_WIN) 40 #if defined(OS_WIN)
56 #include "ui/base/win/internal_constants.h" 41 #include "ui/base/win/internal_constants.h"
57 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h"
58 #include "ui/views/win/hwnd_util.h" 42 #include "ui/views/win/hwnd_util.h"
59 #else
60 #include "ui/views/controls/menu/menu_event_dispatcher_linux.h"
61 #endif 43 #endif
62 44
63 using aura::client::ScreenPositionClient;
64 using base::Time; 45 using base::Time;
65 using base::TimeDelta; 46 using base::TimeDelta;
66 using ui::OSExchangeData; 47 using ui::OSExchangeData;
67 48
68 // Period of the scroll timer (in milliseconds). 49 // Period of the scroll timer (in milliseconds).
69 static const int kScrollTimerMS = 30; 50 static const int kScrollTimerMS = 30;
70 51
71 // Amount of time from when the drop exits the menu and the menu is hidden. 52 // Amount of time from when the drop exits the menu and the menu is hidden.
72 static const int kCloseOnExitTime = 1200; 53 static const int kCloseOnExitTime = 1200;
73 54
(...skipping 27 matching lines...) Expand all
101 // Returns true if |menu| doesn't have a mnemonic and first character of the its 82 // Returns true if |menu| doesn't have a mnemonic and first character of the its
102 // title is |key|. 83 // title is |key|.
103 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { 84 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) {
104 if (menu->GetMnemonic()) 85 if (menu->GetMnemonic())
105 return false; 86 return false;
106 87
107 base::string16 lower_title = base::i18n::ToLower(menu->title()); 88 base::string16 lower_title = base::i18n::ToLower(menu->title());
108 return !lower_title.empty() && lower_title[0] == key; 89 return !lower_title.empty() && lower_title[0] == key;
109 } 90 }
110 91
111 aura::Window* GetOwnerRootWindow(views::Widget* owner) {
112 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL;
113 }
114
115 // ActivationChangeObserverImpl is used to observe activation changes and close
116 // the menu. Additionally it listens for the root window to be destroyed and
117 // cancel the menu as well.
118 class ActivationChangeObserverImpl
119 : public aura::client::ActivationChangeObserver,
120 public aura::WindowObserver,
121 public ui::EventHandler {
122 public:
123 ActivationChangeObserverImpl(MenuController* controller, aura::Window* root)
124 : controller_(controller),
125 root_(root) {
126 aura::client::GetActivationClient(root_)->AddObserver(this);
127 root_->AddObserver(this);
128 root_->AddPreTargetHandler(this);
129 }
130
131 virtual ~ActivationChangeObserverImpl() {
132 Cleanup();
133 }
134
135 // aura::client::ActivationChangeObserver:
136 virtual void OnWindowActivated(aura::Window* gained_active,
137 aura::Window* lost_active) OVERRIDE {
138 if (!controller_->drag_in_progress())
139 controller_->CancelAll();
140 }
141
142 // aura::WindowObserver:
143 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
144 Cleanup();
145 }
146
147 // ui::EventHandler:
148 virtual void OnCancelMode(ui::CancelModeEvent* event) OVERRIDE {
149 controller_->CancelAll();
150 }
151
152 private:
153 void Cleanup() {
154 if (!root_)
155 return;
156 // The ActivationClient may have been destroyed by the time we get here.
157 aura::client::ActivationClient* client =
158 aura::client::GetActivationClient(root_);
159 if (client)
160 client->RemoveObserver(this);
161 root_->RemovePreTargetHandler(this);
162 root_->RemoveObserver(this);
163 root_ = NULL;
164 }
165
166 MenuController* controller_;
167 aura::Window* root_;
168
169 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl);
170 };
171
172 } // namespace 92 } // namespace
173 93
174 // Returns the first descendant of |view| that is hot tracked. 94 // Returns the first descendant of |view| that is hot tracked.
175 static CustomButton* GetFirstHotTrackedView(View* view) { 95 static CustomButton* GetFirstHotTrackedView(View* view) {
176 if (!view) 96 if (!view)
177 return NULL; 97 return NULL;
178 CustomButton* button = CustomButton::AsCustomButton(view); 98 CustomButton* button = CustomButton::AsCustomButton(view);
179 if (button) { 99 if (button) {
180 if (button->IsHotTracked()) 100 if (button->IsHotTracked())
181 return button; 101 return button;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return NULL; 352 return NULL;
433 } 353 }
434 354
435 if (button) 355 if (button)
436 menu_button_ = button; 356 menu_button_ = button;
437 357
438 // Make sure Chrome doesn't attempt to shut down while the menu is showing. 358 // Make sure Chrome doesn't attempt to shut down while the menu is showing.
439 if (ViewsDelegate::views_delegate) 359 if (ViewsDelegate::views_delegate)
440 ViewsDelegate::views_delegate->AddRef(); 360 ViewsDelegate::views_delegate->AddRef();
441 361
442 // We need to turn on nestable tasks as in some situations (pressing alt-f for
443 // one) the menus are run from a task. If we don't do this and are invoked
444 // from a task none of the tasks we schedule are processed and the menu
445 // appears totally broken.
446 message_loop_depth_++;
447 DCHECK_LE(message_loop_depth_, 2);
448 RunMessageLoop(nested_menu); 362 RunMessageLoop(nested_menu);
449 message_loop_depth_--;
450 363
451 if (ViewsDelegate::views_delegate) 364 if (ViewsDelegate::views_delegate)
452 ViewsDelegate::views_delegate->ReleaseRef(); 365 ViewsDelegate::views_delegate->ReleaseRef();
453 366
454 // Close any open menus. 367 // Close any open menus.
455 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); 368 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT);
456 369
457 #if defined(OS_WIN) 370 #if defined(OS_WIN)
458 // On Windows, if we select the menu item by touch and if the window at the 371 // On Windows, if we select the menu item by touch and if the window at the
459 // location is another window on the same thread, that window gets a 372 // location is another window on the same thread, that window gets a
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); 781 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu();
869 View::ConvertPointFromScreen( 782 View::ConvertPointFromScreen(
870 root_submenu->GetWidget()->GetRootView(), &point); 783 root_submenu->GetWidget()->GetRootView(), &point);
871 HandleMouseLocation(submenu, point); 784 HandleMouseLocation(submenu, point);
872 } 785 }
873 } 786 }
874 787
875 void MenuController::OnWidgetDestroying(Widget* widget) { 788 void MenuController::OnWidgetDestroying(Widget* widget) {
876 DCHECK_EQ(owner_, widget); 789 DCHECK_EQ(owner_, widget);
877 owner_->RemoveObserver(this); 790 owner_->RemoveObserver(this);
878 owner_ = NULL; 791 owner_ = NULL;
sky 2014/05/15 16:07:32 I think you should NULL out owner_ in MenuMessageL
Andre 2014/05/15 18:45:59 MenuMessageLoop clears owner_ when exiting the loo
sky 2014/05/15 19:33:01 Exactly. I don't like it that MenuMessageLoop may
Andre 2014/05/15 20:57:12 Done. I went with ClearOwner because owner was pas
879 } 792 }
880 793
881 // static 794 // static
882 void MenuController::TurnOffMenuSelectionHoldForTest() { 795 void MenuController::TurnOffMenuSelectionHoldForTest() {
883 menu_selection_hold_time_ms = -1; 796 menu_selection_hold_time_ms = -1;
884 } 797 }
885 798
886 void MenuController::SetSelection(MenuItemView* menu_item, 799 void MenuController::SetSelection(MenuItemView* menu_item,
887 int selection_types) { 800 int selection_types) {
888 size_t paths_differ_at = 0; 801 size_t paths_differ_at = 0;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 drop_position_(MenuDelegate::DROP_UNKNOWN), 1061 drop_position_(MenuDelegate::DROP_UNKNOWN),
1149 owner_(NULL), 1062 owner_(NULL),
1150 possible_drag_(false), 1063 possible_drag_(false),
1151 drag_in_progress_(false), 1064 drag_in_progress_(false),
1152 valid_drop_coordinates_(false), 1065 valid_drop_coordinates_(false),
1153 last_drop_operation_(MenuDelegate::DROP_UNKNOWN), 1066 last_drop_operation_(MenuDelegate::DROP_UNKNOWN),
1154 showing_submenu_(false), 1067 showing_submenu_(false),
1155 menu_button_(NULL), 1068 menu_button_(NULL),
1156 active_mouse_view_id_(ViewStorage::GetInstance()->CreateStorageID()), 1069 active_mouse_view_id_(ViewStorage::GetInstance()->CreateStorageID()),
1157 delegate_(delegate), 1070 delegate_(delegate),
1158 message_loop_depth_(0),
1159 menu_config_(theme), 1071 menu_config_(theme),
1160 closing_event_time_(base::TimeDelta()), 1072 closing_event_time_(base::TimeDelta()),
1161 menu_start_time_(base::TimeTicks()), 1073 menu_start_time_(base::TimeTicks()),
1162 is_combobox_(false), 1074 is_combobox_(false),
1163 item_selected_by_touch_(false) { 1075 item_selected_by_touch_(false),
1076 message_loop_(MenuMessageLoop::Create()) {
1164 active_instance_ = this; 1077 active_instance_ = this;
1165 } 1078 }
1166 1079
1167 MenuController::~MenuController() { 1080 MenuController::~MenuController() {
1168 DCHECK(!showing_); 1081 DCHECK(!showing_);
1169 if (owner_) 1082 if (owner_)
1170 owner_->RemoveObserver(this); 1083 owner_->RemoveObserver(this);
1171 if (active_instance_ == this) 1084 if (active_instance_ == this)
1172 active_instance_ = NULL; 1085 active_instance_ = NULL;
1173 StopShowTimer(); 1086 StopShowTimer();
1174 StopCancelAllTimer(); 1087 StopCancelAllTimer();
1175 } 1088 }
1176 1089
1177 #if defined(OS_WIN)
1178 void MenuController::RunMessageLoop(bool nested_menu) { 1090 void MenuController::RunMessageLoop(bool nested_menu) {
1179 internal::MenuMessagePumpDispatcher nested_dispatcher(this); 1091 message_loop_->Run(this, owner_, nested_menu);
sky 2014/05/15 16:07:32 Inline this and remove the RunMessageLoop function
Andre 2014/05/15 18:45:59 The RunMessageLoop public method is also called by
1180
1181 // |owner_| may be NULL.
1182 aura::Window* root = GetOwnerRootWindow(owner_);
1183 if (root) {
1184 scoped_ptr<ActivationChangeObserverImpl> observer;
1185 if (!nested_menu)
1186 observer.reset(new ActivationChangeObserverImpl(this, root));
1187 aura::client::GetDispatcherClient(root)
1188 ->RunWithDispatcher(&nested_dispatcher);
1189 } else {
1190 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1191 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
1192 base::RunLoop run_loop(&nested_dispatcher);
1193 run_loop.Run();
1194 }
1195 } 1092 }
1196 #else
1197 void MenuController::RunMessageLoop(bool nested_menu) {
1198 internal::MenuEventDispatcher event_dispatcher(this);
1199 scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher =
1200 nested_dispatcher_.Pass();
1201 if (ui::PlatformEventSource::GetInstance()) {
1202 nested_dispatcher_ =
1203 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
1204 &event_dispatcher);
1205 }
1206 // |owner_| may be NULL.
1207 aura::Window* root = GetOwnerRootWindow(owner_);
1208 if (root) {
1209 scoped_ptr<ActivationChangeObserverImpl> observer;
1210 if (!nested_menu)
1211 observer.reset(new ActivationChangeObserverImpl(this, root));
1212 aura::client::GetDispatcherClient(root)->RunWithDispatcher(NULL);
1213 } else {
1214 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1215 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
1216 base::RunLoop run_loop;
1217 run_loop.Run();
1218 }
1219 nested_dispatcher_ = old_dispatcher.Pass();
1220 }
1221 #endif
1222 1093
1223 MenuController::SendAcceleratorResultType 1094 MenuController::SendAcceleratorResultType
1224 MenuController::SendAcceleratorToHotTrackedView() { 1095 MenuController::SendAcceleratorToHotTrackedView() {
1225 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); 1096 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item);
1226 if (!hot_view) 1097 if (!hot_view)
1227 return ACCELERATOR_NOT_PROCESSED; 1098 return ACCELERATOR_NOT_PROCESSED;
1228 1099
1229 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1100 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1230 hot_view->AcceleratorPressed(accelerator); 1101 hot_view->AcceleratorPressed(accelerator);
1231 CustomButton* button = static_cast<CustomButton*>(hot_view); 1102 CustomButton* button = static_cast<CustomButton*>(hot_view);
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result; 2094 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result;
2224 LPARAM window_coords = MAKELPARAM(window_x, window_y); 2095 LPARAM window_coords = MAKELPARAM(window_x, window_y);
2225 PostMessage(target_window, event_type, target, window_coords); 2096 PostMessage(target_window, event_type, target, window_coords);
2226 return; 2097 return;
2227 } 2098 }
2228 #endif 2099 #endif
2229 // Non-Windows Aura or |window| is in metro mode. 2100 // Non-Windows Aura or |window| is in metro mode.
2230 if (!window) 2101 if (!window)
2231 return; 2102 return;
2232 2103
2233 aura::Window* root = window->GetRootWindow(); 2104 message_loop_->RepostEventToWindow(event, window, screen_loc);
2234 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root);
2235 if (!spc)
2236 return;
2237
2238 gfx::Point root_loc(screen_loc);
2239 spc->ConvertPointFromScreen(root, &root_loc);
2240
2241 ui::MouseEvent clone(static_cast<const ui::MouseEvent&>(event));
2242 clone.set_location(root_loc);
2243 clone.set_root_location(root_loc);
2244 root->GetHost()->dispatcher()->RepostEvent(clone);
2245 } 2105 }
2246 2106
2247 void MenuController::SetDropMenuItem( 2107 void MenuController::SetDropMenuItem(
2248 MenuItemView* new_target, 2108 MenuItemView* new_target,
2249 MenuDelegate::DropPosition new_position) { 2109 MenuDelegate::DropPosition new_position) {
2250 if (new_target == drop_target_ && new_position == drop_position_) 2110 if (new_target == drop_target_ && new_position == drop_position_)
2251 return; 2111 return;
2252 2112
2253 if (drop_target_) { 2113 if (drop_target_) {
2254 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem( 2114 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 exit_type_ = type; 2229 exit_type_ = type;
2370 // Exit nested message loops as soon as possible. We do this as 2230 // Exit nested message loops as soon as possible. We do this as
2371 // MessagePumpDispatcher is only invoked before native events, which means 2231 // MessagePumpDispatcher is only invoked before native events, which means
2372 // its entirely possible for a Widget::CloseNow() task to be processed before 2232 // its entirely possible for a Widget::CloseNow() task to be processed before
2373 // the next native message. We quite the nested message loop as soon as 2233 // the next native message. We quite the nested message loop as soon as
2374 // possible to avoid having deleted views classes (such as widgets and 2234 // possible to avoid having deleted views classes (such as widgets and
2375 // rootviews) on the stack when the nested message loop stops. 2235 // rootviews) on the stack when the nested message loop stops.
2376 // 2236 //
2377 // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects 2237 // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects
2378 // the current loop. 2238 // the current loop.
2379 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE && 2239 bool quit_now = message_loop_->ShouldQuitNow() && exit_type_ != EXIT_NONE &&
2380 message_loop_depth_; 2240 message_loop_->message_loop_depth();
2381 if (quit_now) 2241 if (quit_now)
2382 TerminateNestedMessageLoop(); 2242 TerminateNestedMessageLoop();
2383 } 2243 }
2384 2244
2385 void MenuController::TerminateNestedMessageLoop() { 2245 void MenuController::TerminateNestedMessageLoop() {
2386 if (owner_) { 2246 message_loop_->QuitNow();
2387 aura::Window* root = owner_->GetNativeWindow()->GetRootWindow();
2388 aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop();
2389 } else {
2390 base::MessageLoop::current()->QuitNow();
2391 }
2392 // Restore the previous dispatcher.
2393 nested_dispatcher_.reset();
2394 }
2395
2396 bool MenuController::ShouldQuitNow() const {
2397 aura::Window* root = GetOwnerRootWindow(owner_);
2398 return !aura::client::GetDragDropClient(root) ||
2399 !aura::client::GetDragDropClient(root)->IsDragDropInProgress();
2400 } 2247 }
2401 2248
2402 void MenuController::HandleMouseLocation(SubmenuView* source, 2249 void MenuController::HandleMouseLocation(SubmenuView* source,
2403 const gfx::Point& mouse_location) { 2250 const gfx::Point& mouse_location) {
2404 if (showing_submenu_) 2251 if (showing_submenu_)
2405 return; 2252 return;
2406 2253
2407 // Ignore mouse events if we're closing the menu. 2254 // Ignore mouse events if we're closing the menu.
2408 if (exit_type_ != EXIT_NONE) 2255 if (exit_type_ != EXIT_NONE)
2409 return; 2256 return;
(...skipping 15 matching lines...) Expand all
2425 (!pending_state_.item->HasSubmenu() || 2272 (!pending_state_.item->HasSubmenu() ||
2426 !pending_state_.item->GetSubmenu()->IsShowing())) { 2273 !pending_state_.item->GetSubmenu()->IsShowing())) {
2427 // On exit if the user hasn't selected an item with a submenu, move the 2274 // On exit if the user hasn't selected an item with a submenu, move the
2428 // selection back to the parent menu item. 2275 // selection back to the parent menu item.
2429 SetSelection(pending_state_.item->GetParentMenuItem(), 2276 SetSelection(pending_state_.item->GetParentMenuItem(),
2430 SELECTION_OPEN_SUBMENU); 2277 SELECTION_OPEN_SUBMENU);
2431 } 2278 }
2432 } 2279 }
2433 2280
2434 gfx::Screen* MenuController::GetScreen() { 2281 gfx::Screen* MenuController::GetScreen() {
2435 aura::Window* root = GetOwnerRootWindow(owner_); 2282 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2436 return root ? gfx::Screen::GetScreenFor(root) 2283 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2437 : gfx::Screen::GetNativeScreen(); 2284 : gfx::Screen::GetNativeScreen();
2438 } 2285 }
2439 2286
2440 } // namespace views 2287 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698