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