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

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: 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) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // Returns true if |menu| doesn't have a mnemonic and first character of the its 100 // Returns true if |menu| doesn't have a mnemonic and first character of the its
101 // title is |key|. 101 // title is |key|.
102 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { 102 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) {
103 if (menu->GetMnemonic()) 103 if (menu->GetMnemonic())
104 return false; 104 return false;
105 105
106 base::string16 lower_title = base::i18n::ToLower(menu->title()); 106 base::string16 lower_title = base::i18n::ToLower(menu->title());
107 return !lower_title.empty() && lower_title[0] == key; 107 return !lower_title.empty() && lower_title[0] == key;
108 } 108 }
109 109
110 #if defined(USE_AURA)
tapted 2014/05/02 00:22:57 I think there will be resistance to this many #ifd
110 aura::Window* GetOwnerRootWindow(views::Widget* owner) { 111 aura::Window* GetOwnerRootWindow(views::Widget* owner) {
111 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL; 112 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL;
112 } 113 }
113 114
114 // ActivationChangeObserverImpl is used to observe activation changes and close 115 // ActivationChangeObserverImpl is used to observe activation changes and close
115 // the menu. Additionally it listens for the root window to be destroyed and 116 // the menu. Additionally it listens for the root window to be destroyed and
116 // cancel the menu as well. 117 // cancel the menu as well.
117 class ActivationChangeObserverImpl 118 class ActivationChangeObserverImpl
118 : public aura::client::ActivationChangeObserver, 119 : public aura::client::ActivationChangeObserver,
119 public aura::WindowObserver, 120 public aura::WindowObserver,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 root_->RemovePreTargetHandler(this); 161 root_->RemovePreTargetHandler(this);
161 root_->RemoveObserver(this); 162 root_->RemoveObserver(this);
162 root_ = NULL; 163 root_ = NULL;
163 } 164 }
164 165
165 MenuController* controller_; 166 MenuController* controller_;
166 aura::Window* root_; 167 aura::Window* root_;
167 168
168 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); 169 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl);
169 }; 170 };
171 #endif // USE_AURA
170 172
171 } // namespace 173 } // namespace
172 174
173 // Returns the first descendant of |view| that is hot tracked. 175 // Returns the first descendant of |view| that is hot tracked.
174 static CustomButton* GetFirstHotTrackedView(View* view) { 176 static CustomButton* GetFirstHotTrackedView(View* view) {
175 if (!view) 177 if (!view)
176 return NULL; 178 return NULL;
177 CustomButton* button = CustomButton::AsCustomButton(view); 179 CustomButton* button = CustomButton::AsCustomButton(view);
178 if (button) { 180 if (button) {
179 if (button->IsHotTracked()) 181 if (button->IsHotTracked())
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 observer.reset(new ActivationChangeObserverImpl(this, root)); 1186 observer.reset(new ActivationChangeObserverImpl(this, root));
1185 aura::client::GetDispatcherClient(root) 1187 aura::client::GetDispatcherClient(root)
1186 ->RunWithDispatcher(&nested_dispatcher); 1188 ->RunWithDispatcher(&nested_dispatcher);
1187 } else { 1189 } else {
1188 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); 1190 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1189 base::MessageLoop::ScopedNestableTaskAllower allow(loop); 1191 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
1190 base::RunLoop run_loop(&nested_dispatcher); 1192 base::RunLoop run_loop(&nested_dispatcher);
1191 run_loop.Run(); 1193 run_loop.Run();
1192 } 1194 }
1193 } 1195 }
1196 #elif defined(OS_MACOSX)
1197 void MenuController::RunMessageLoop(bool nested_menu) {
1198 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1199 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
1200 base::RunLoop run_loop;
1201 run_loop.Run();
1202 }
1194 #else 1203 #else
1195 void MenuController::RunMessageLoop(bool nested_menu) { 1204 void MenuController::RunMessageLoop(bool nested_menu) {
1196 internal::MenuEventDispatcher event_dispatcher(this); 1205 internal::MenuEventDispatcher event_dispatcher(this);
1197 scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher = 1206 scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher =
1198 nested_dispatcher_.Pass(); 1207 nested_dispatcher_.Pass();
1199 if (ui::PlatformEventSource::GetInstance()) { 1208 if (ui::PlatformEventSource::GetInstance()) {
1200 nested_dispatcher_ = 1209 nested_dispatcher_ =
1201 ui::PlatformEventSource::GetInstance()->OverrideDispatcher( 1210 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
1202 &event_dispatcher); 1211 &event_dispatcher);
1203 } 1212 }
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result; 2231 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result;
2223 LPARAM window_coords = MAKELPARAM(window_x, window_y); 2232 LPARAM window_coords = MAKELPARAM(window_x, window_y);
2224 PostMessage(target_window, event_type, target, window_coords); 2233 PostMessage(target_window, event_type, target, window_coords);
2225 return; 2234 return;
2226 } 2235 }
2227 #endif 2236 #endif
2228 // Non-Windows Aura or |window| is in metro mode. 2237 // Non-Windows Aura or |window| is in metro mode.
2229 if (!window) 2238 if (!window)
2230 return; 2239 return;
2231 2240
2241 #if defined(USE_AURA)
2232 aura::Window* root = window->GetRootWindow(); 2242 aura::Window* root = window->GetRootWindow();
2233 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); 2243 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root);
2234 if (!spc) 2244 if (!spc)
2235 return; 2245 return;
2236 2246
2237 gfx::Point root_loc(screen_loc); 2247 gfx::Point root_loc(screen_loc);
2238 spc->ConvertPointFromScreen(root, &root_loc); 2248 spc->ConvertPointFromScreen(root, &root_loc);
2239 2249
2240 ui::MouseEvent clone(static_cast<const ui::MouseEvent&>(event)); 2250 ui::MouseEvent clone(static_cast<const ui::MouseEvent&>(event));
2241 clone.set_location(root_loc); 2251 clone.set_location(root_loc);
2242 clone.set_root_location(root_loc); 2252 clone.set_root_location(root_loc);
2243 root->GetHost()->dispatcher()->RepostEvent(clone); 2253 root->GetHost()->dispatcher()->RepostEvent(clone);
2254 #endif
2244 } 2255 }
2245 2256
2246 void MenuController::SetDropMenuItem( 2257 void MenuController::SetDropMenuItem(
2247 MenuItemView* new_target, 2258 MenuItemView* new_target,
2248 MenuDelegate::DropPosition new_position) { 2259 MenuDelegate::DropPosition new_position) {
2249 if (new_target == drop_target_ && new_position == drop_position_) 2260 if (new_target == drop_target_ && new_position == drop_position_)
2250 return; 2261 return;
2251 2262
2252 if (drop_target_) { 2263 if (drop_target_) {
2253 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem( 2264 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 // the next native message. We quite the nested message loop as soon as 2383 // the next native message. We quite the nested message loop as soon as
2373 // possible to avoid having deleted views classes (such as widgets and 2384 // possible to avoid having deleted views classes (such as widgets and
2374 // rootviews) on the stack when the nested message loop stops. 2385 // rootviews) on the stack when the nested message loop stops.
2375 // 2386 //
2376 // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects 2387 // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects
2377 // the current loop. 2388 // the current loop.
2378 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE && 2389 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE &&
2379 message_loop_depth_; 2390 message_loop_depth_;
2380 2391
2381 if (quit_now) { 2392 if (quit_now) {
2393 #if defined(USE_AURA)
2382 if (owner_) { 2394 if (owner_) {
2383 aura::Window* root = owner_->GetNativeWindow()->GetRootWindow(); 2395 aura::Window* root = owner_->GetNativeWindow()->GetRootWindow();
2384 aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop(); 2396 aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop();
2385 } else { 2397 } else {
2386 base::MessageLoop::current()->QuitNow(); 2398 base::MessageLoop::current()->QuitNow();
2387 } 2399 }
2400 #else
2401 base::MessageLoop::current()->QuitNow();
2402 #endif
2388 // Restore the previous dispatcher. 2403 // Restore the previous dispatcher.
2389 nested_dispatcher_.reset(); 2404 nested_dispatcher_.reset();
2390 } 2405 }
2391 } 2406 }
2392 2407
2393 bool MenuController::ShouldQuitNow() const { 2408 bool MenuController::ShouldQuitNow() const {
2409 #if defined(USE_AURA)
2394 aura::Window* root = GetOwnerRootWindow(owner_); 2410 aura::Window* root = GetOwnerRootWindow(owner_);
2395 return !aura::client::GetDragDropClient(root) || 2411 return !aura::client::GetDragDropClient(root) ||
2396 !aura::client::GetDragDropClient(root)->IsDragDropInProgress(); 2412 !aura::client::GetDragDropClient(root)->IsDragDropInProgress();
2413 #else
2414 return true;
2415 #endif
2397 } 2416 }
2398 2417
2399 void MenuController::HandleMouseLocation(SubmenuView* source, 2418 void MenuController::HandleMouseLocation(SubmenuView* source,
2400 const gfx::Point& mouse_location) { 2419 const gfx::Point& mouse_location) {
2401 if (showing_submenu_) 2420 if (showing_submenu_)
2402 return; 2421 return;
2403 2422
2404 // Ignore mouse events if we're closing the menu. 2423 // Ignore mouse events if we're closing the menu.
2405 if (exit_type_ != EXIT_NONE) 2424 if (exit_type_ != EXIT_NONE)
2406 return; 2425 return;
(...skipping 15 matching lines...) Expand all
2422 (!pending_state_.item->HasSubmenu() || 2441 (!pending_state_.item->HasSubmenu() ||
2423 !pending_state_.item->GetSubmenu()->IsShowing())) { 2442 !pending_state_.item->GetSubmenu()->IsShowing())) {
2424 // On exit if the user hasn't selected an item with a submenu, move the 2443 // On exit if the user hasn't selected an item with a submenu, move the
2425 // selection back to the parent menu item. 2444 // selection back to the parent menu item.
2426 SetSelection(pending_state_.item->GetParentMenuItem(), 2445 SetSelection(pending_state_.item->GetParentMenuItem(),
2427 SELECTION_OPEN_SUBMENU); 2446 SELECTION_OPEN_SUBMENU);
2428 } 2447 }
2429 } 2448 }
2430 2449
2431 gfx::Screen* MenuController::GetScreen() { 2450 gfx::Screen* MenuController::GetScreen() {
2432 aura::Window* root = GetOwnerRootWindow(owner_); 2451 Widget* root = owner_->GetTopLevelWidget();
2433 return root ? gfx::Screen::GetScreenFor(root) 2452 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
Andre 2014/05/01 22:38:43 I'm not sure about this change (limited experience
tapted 2014/05/02 00:22:57 This looks good! (I think :)
2434 : gfx::Screen::GetNativeScreen(); 2453 : gfx::Screen::GetNativeScreen();
2435 } 2454 }
2436 2455
2437 } // namespace views 2456 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698