OLD | NEW |
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 |
11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "ui/aura/client/dispatcher_client.h" |
16 #include "ui/base/dragdrop/drag_utils.h" | 17 #include "ui/base/dragdrop/drag_utils.h" |
17 #include "ui/base/dragdrop/os_exchange_data.h" | 18 #include "ui/base/dragdrop/os_exchange_data.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
20 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
21 #include "ui/events/keycodes/keyboard_code_conversion.h" | 22 #include "ui/events/keycodes/keyboard_code_conversion.h" |
22 #include "ui/events/keycodes/keyboard_codes.h" | 23 #include "ui/events/keycodes/keyboard_codes.h" |
23 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
25 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2295 | 2296 |
2296 View* MenuController::GetActiveMouseView() { | 2297 View* MenuController::GetActiveMouseView() { |
2297 return ViewStorage::GetInstance()->RetrieveView(active_mouse_view_id_); | 2298 return ViewStorage::GetInstance()->RetrieveView(active_mouse_view_id_); |
2298 } | 2299 } |
2299 | 2300 |
2300 void MenuController::SetExitType(ExitType type) { | 2301 void MenuController::SetExitType(ExitType type) { |
2301 exit_type_ = type; | 2302 exit_type_ = type; |
2302 // Exit nested message loops as soon as possible. We do this as | 2303 // Exit nested message loops as soon as possible. We do this as |
2303 // MessagePumpDispatcher is only invoked before native events, which means | 2304 // MessagePumpDispatcher is only invoked before native events, which means |
2304 // its entirely possible for a Widget::CloseNow() task to be processed before | 2305 // its entirely possible for a Widget::CloseNow() task to be processed before |
2305 // the next native message. By using QuitNow() we ensures the nested message | 2306 // the next native message. We quite the nested message loop as soon as |
2306 // loop returns as soon as possible and avoids having deleted views classes | 2307 // possible to avoid having deleted views classes (such as widgets and |
2307 // (such as widgets and rootviews) on the stack when the nested message loop | 2308 // rootviews) on the stack when the nested message loop stops. |
2308 // stops. | |
2309 // | 2309 // |
2310 // It's safe to invoke QuitNow multiple times, it only effects the current | 2310 // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects |
2311 // loop. | 2311 // the current loop. |
2312 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE && | 2312 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE && |
2313 message_loop_depth_; | 2313 message_loop_depth_; |
2314 | 2314 |
2315 if (quit_now) | 2315 if (quit_now) { |
2316 base::MessageLoop::current()->QuitNow(); | 2316 if (owner_) { |
| 2317 aura::Window* root = owner_->GetNativeWindow()->GetRootWindow(); |
| 2318 aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop(); |
| 2319 } else { |
| 2320 base::MessageLoop::current()->QuitNow(); |
| 2321 } |
| 2322 } |
2317 } | 2323 } |
2318 | 2324 |
2319 void MenuController::HandleMouseLocation(SubmenuView* source, | 2325 void MenuController::HandleMouseLocation(SubmenuView* source, |
2320 const gfx::Point& mouse_location) { | 2326 const gfx::Point& mouse_location) { |
2321 if (showing_submenu_) | 2327 if (showing_submenu_) |
2322 return; | 2328 return; |
2323 | 2329 |
2324 // Ignore mouse events if we're closing the menu. | 2330 // Ignore mouse events if we're closing the menu. |
2325 if (exit_type_ != EXIT_NONE) | 2331 if (exit_type_ != EXIT_NONE) |
2326 return; | 2332 return; |
(...skipping 15 matching lines...) Expand all Loading... |
2342 (!pending_state_.item->HasSubmenu() || | 2348 (!pending_state_.item->HasSubmenu() || |
2343 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2349 !pending_state_.item->GetSubmenu()->IsShowing())) { |
2344 // On exit if the user hasn't selected an item with a submenu, move the | 2350 // On exit if the user hasn't selected an item with a submenu, move the |
2345 // selection back to the parent menu item. | 2351 // selection back to the parent menu item. |
2346 SetSelection(pending_state_.item->GetParentMenuItem(), | 2352 SetSelection(pending_state_.item->GetParentMenuItem(), |
2347 SELECTION_OPEN_SUBMENU); | 2353 SELECTION_OPEN_SUBMENU); |
2348 } | 2354 } |
2349 } | 2355 } |
2350 | 2356 |
2351 } // namespace views | 2357 } // namespace views |
OLD | NEW |