| 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 #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" |
| 11 #include "ui/base/dragdrop/drag_utils.h" | 11 #include "ui/base/dragdrop/drag_utils.h" |
| 12 #include "ui/base/dragdrop/os_exchange_data.h" | 12 #include "ui/base/dragdrop/os_exchange_data.h" |
| 13 #include "ui/base/events.h" | 13 #include "ui/base/events.h" |
| 14 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 18 #include "ui/views/controls/button/menu_button.h" | 18 #include "ui/views/controls/button/menu_button.h" |
| 19 #include "ui/views/controls/menu/menu_config.h" | 19 #include "ui/views/controls/menu/menu_config.h" |
| 20 #include "ui/views/controls/menu/menu_controller_delegate.h" | 20 #include "ui/views/controls/menu/menu_controller_delegate.h" |
| 21 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 21 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
| 22 #include "ui/views/controls/menu/submenu_view.h" | 22 #include "ui/views/controls/menu/submenu_view.h" |
| 23 #include "ui/views/view_constants.h" | 23 #include "ui/views/view_constants.h" |
| 24 #include "ui/views/views_delegate.h" | 24 #include "ui/views/views_delegate.h" |
| 25 #include "ui/views/widget/root_view.h" | 25 #include "ui/views/widget/root_view.h" |
| 26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 | 27 |
| 28 #if defined(USE_AURA) | 28 #if defined(USE_AURA) |
| 29 #include "ui/aura/client/dispatcher_client.h" | 29 #include "ui/aura/client/dispatcher_client.h" |
| 30 #include "ui/aura/client/drag_drop_client.h" |
| 30 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
| 31 #include "ui/aura/root_window.h" | 32 #include "ui/aura/root_window.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 using base::Time; | 35 using base::Time; |
| 35 using base::TimeDelta; | 36 using base::TimeDelta; |
| 36 using ui::OSExchangeData; | 37 using ui::OSExchangeData; |
| 37 | 38 |
| 38 // Period of the scroll timer (in milliseconds). | 39 // Period of the scroll timer (in milliseconds). |
| 39 static const int kScrollTimerMS = 30; | 40 static const int kScrollTimerMS = 30; |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (ViewsDelegate::views_delegate) | 314 if (ViewsDelegate::views_delegate) |
| 314 ViewsDelegate::views_delegate->AddRef(); | 315 ViewsDelegate::views_delegate->AddRef(); |
| 315 | 316 |
| 316 // We need to turn on nestable tasks as in some situations (pressing alt-f for | 317 // We need to turn on nestable tasks as in some situations (pressing alt-f for |
| 317 // one) the menus are run from a task. If we don't do this and are invoked | 318 // one) the menus are run from a task. If we don't do this and are invoked |
| 318 // from a task none of the tasks we schedule are processed and the menu | 319 // from a task none of the tasks we schedule are processed and the menu |
| 319 // appears totally broken. | 320 // appears totally broken. |
| 320 message_loop_depth_++; | 321 message_loop_depth_++; |
| 321 DCHECK_LE(message_loop_depth_, 2); | 322 DCHECK_LE(message_loop_depth_, 2); |
| 322 #if defined(USE_AURA) | 323 #if defined(USE_AURA) |
| 323 aura::client::GetDispatcherClient( | 324 root_window_ = parent->GetNativeWindow()->GetRootWindow(); |
| 324 parent->GetNativeWindow()->GetRootWindow())-> | 325 aura::client::GetDispatcherClient(root_window_)-> |
| 325 RunWithDispatcher(this, parent->GetNativeWindow(), true); | 326 RunWithDispatcher(this, parent->GetNativeWindow(), true); |
| 326 #else | 327 #else |
| 327 { | 328 { |
| 328 MessageLoopForUI* loop = MessageLoopForUI::current(); | 329 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 329 MessageLoop::ScopedNestableTaskAllower allow(loop); | 330 MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 330 loop->RunWithDispatcher(this); | 331 loop->RunWithDispatcher(this); |
| 331 } | 332 } |
| 332 #endif | 333 #endif |
| 333 message_loop_depth_--; | 334 message_loop_depth_--; |
| 334 | 335 |
| 335 if (ViewsDelegate::views_delegate) | 336 if (ViewsDelegate::views_delegate) |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 : blocking_run_(blocking), | 1019 : blocking_run_(blocking), |
| 1019 showing_(false), | 1020 showing_(false), |
| 1020 drop_first_release_event_(false), | 1021 drop_first_release_event_(false), |
| 1021 exit_type_(EXIT_NONE), | 1022 exit_type_(EXIT_NONE), |
| 1022 did_capture_(false), | 1023 did_capture_(false), |
| 1023 result_(NULL), | 1024 result_(NULL), |
| 1024 result_mouse_event_flags_(0), | 1025 result_mouse_event_flags_(0), |
| 1025 drop_target_(NULL), | 1026 drop_target_(NULL), |
| 1026 drop_position_(MenuDelegate::DROP_UNKNOWN), | 1027 drop_position_(MenuDelegate::DROP_UNKNOWN), |
| 1027 owner_(NULL), | 1028 owner_(NULL), |
| 1029 #if defined(USE_AURA) |
| 1030 root_window_(NULL), |
| 1031 #endif |
| 1028 possible_drag_(false), | 1032 possible_drag_(false), |
| 1029 drag_in_progress_(false), | 1033 drag_in_progress_(false), |
| 1030 valid_drop_coordinates_(false), | 1034 valid_drop_coordinates_(false), |
| 1031 last_drop_operation_(MenuDelegate::DROP_UNKNOWN), | 1035 last_drop_operation_(MenuDelegate::DROP_UNKNOWN), |
| 1032 showing_submenu_(false), | 1036 showing_submenu_(false), |
| 1033 menu_button_(NULL), | 1037 menu_button_(NULL), |
| 1034 active_mouse_view_(NULL), | 1038 active_mouse_view_(NULL), |
| 1035 delegate_(delegate), | 1039 delegate_(delegate), |
| 1036 message_loop_depth_(0) { | 1040 message_loop_depth_(0) { |
| 1037 active_instance_ = this; | 1041 active_instance_ = this; |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 // Exit nested message loops as soon as possible. We do this as | 1987 // Exit nested message loops as soon as possible. We do this as |
| 1984 // MessageLoop::Dispatcher is only invoked before native events, which means | 1988 // MessageLoop::Dispatcher is only invoked before native events, which means |
| 1985 // its entirely possible for a Widget::CloseNow() task to be processed before | 1989 // its entirely possible for a Widget::CloseNow() task to be processed before |
| 1986 // the next native message. By using QuitNow() we ensures the nested message | 1990 // the next native message. By using QuitNow() we ensures the nested message |
| 1987 // loop returns as soon as possible and avoids having deleted views classes | 1991 // loop returns as soon as possible and avoids having deleted views classes |
| 1988 // (such as widgets and rootviews) on the stack when the nested message loop | 1992 // (such as widgets and rootviews) on the stack when the nested message loop |
| 1989 // stops. | 1993 // stops. |
| 1990 // | 1994 // |
| 1991 // It's safe to invoke QuitNow multiple times, it only effects the current | 1995 // It's safe to invoke QuitNow multiple times, it only effects the current |
| 1992 // loop. | 1996 // loop. |
| 1993 if (exit_type_ != EXIT_NONE && message_loop_depth_) | 1997 bool quit_now = exit_type_ != EXIT_NONE && message_loop_depth_; |
| 1998 |
| 1999 #if defined(USE_AURA) |
| 2000 // On aura drag and drop runs a nested messgae loop too. If drag and drop is |
| 2001 // active and we quit we would prematurely cancel drag and drop, which we |
| 2002 // don't want. |
| 2003 if (aura::client::GetDragDropClient(root_window_) && |
| 2004 aura::client::GetDragDropClient(root_window_)->IsDragDropInProgress()) |
| 2005 quit_now = false; |
| 2006 #endif |
| 2007 |
| 2008 if (quit_now) |
| 1994 MessageLoop::current()->QuitNow(); | 2009 MessageLoop::current()->QuitNow(); |
| 1995 } | 2010 } |
| 1996 | 2011 |
| 1997 void MenuController::HandleMouseLocation(SubmenuView* source, | 2012 void MenuController::HandleMouseLocation(SubmenuView* source, |
| 1998 const gfx::Point& mouse_location) { | 2013 const gfx::Point& mouse_location) { |
| 1999 if (showing_submenu_) | 2014 if (showing_submenu_) |
| 2000 return; | 2015 return; |
| 2001 | 2016 |
| 2002 MenuPart part = GetMenuPart(source, mouse_location); | 2017 MenuPart part = GetMenuPart(source, mouse_location); |
| 2003 | 2018 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2016 (!pending_state_.item->HasSubmenu() || | 2031 (!pending_state_.item->HasSubmenu() || |
| 2017 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2032 !pending_state_.item->GetSubmenu()->IsShowing())) { |
| 2018 // On exit if the user hasn't selected an item with a submenu, move the | 2033 // On exit if the user hasn't selected an item with a submenu, move the |
| 2019 // selection back to the parent menu item. | 2034 // selection back to the parent menu item. |
| 2020 SetSelection(pending_state_.item->GetParentMenuItem(), | 2035 SetSelection(pending_state_.item->GetParentMenuItem(), |
| 2021 SELECTION_OPEN_SUBMENU); | 2036 SELECTION_OPEN_SUBMENU); |
| 2022 } | 2037 } |
| 2023 } | 2038 } |
| 2024 | 2039 |
| 2025 } // namespace views | 2040 } // namespace views |
| OLD | NEW |