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

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

Issue 10668037: Close any open menus on activation changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Observe window activation changes from MenuController. Created 8 years, 5 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
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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/drag_utils.h" 23 #include "ui/views/drag_utils.h"
24 #include "ui/views/view_constants.h" 24 #include "ui/views/view_constants.h"
25 #include "ui/views/views_delegate.h" 25 #include "ui/views/views_delegate.h"
26 #include "ui/views/widget/root_view.h" 26 #include "ui/views/widget/root_view.h"
27 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
28 28
29 #if defined(USE_AURA) 29 #if defined(USE_AURA)
30 #include "ui/aura/client/activation_client.h"
30 #include "ui/aura/client/dispatcher_client.h" 31 #include "ui/aura/client/dispatcher_client.h"
31 #include "ui/aura/client/drag_drop_client.h" 32 #include "ui/aura/client/drag_drop_client.h"
32 #include "ui/aura/env.h" 33 #include "ui/aura/env.h"
33 #include "ui/aura/root_window.h" 34 #include "ui/aura/root_window.h"
35 #include "ui/aura/window.h"
34 #endif 36 #endif
35 37
36 using base::Time; 38 using base::Time;
37 using base::TimeDelta; 39 using base::TimeDelta;
38 using ui::OSExchangeData; 40 using ui::OSExchangeData;
39 41
40 // Period of the scroll timer (in milliseconds). 42 // Period of the scroll timer (in milliseconds).
41 static const int kScrollTimerMS = 30; 43 static const int kScrollTimerMS = 30;
42 44
43 // Delay, in ms, between when menus are selected are moused over and the menu 45 // Delay, in ms, between when menus are selected are moused over and the menu
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 ViewsDelegate::views_delegate->AddRef(); 321 ViewsDelegate::views_delegate->AddRef();
320 322
321 // We need to turn on nestable tasks as in some situations (pressing alt-f for 323 // We need to turn on nestable tasks as in some situations (pressing alt-f for
322 // one) the menus are run from a task. If we don't do this and are invoked 324 // one) the menus are run from a task. If we don't do this and are invoked
323 // from a task none of the tasks we schedule are processed and the menu 325 // from a task none of the tasks we schedule are processed and the menu
324 // appears totally broken. 326 // appears totally broken.
325 message_loop_depth_++; 327 message_loop_depth_++;
326 DCHECK_LE(message_loop_depth_, 2); 328 DCHECK_LE(message_loop_depth_, 2);
327 #if defined(USE_AURA) 329 #if defined(USE_AURA)
328 root_window_ = parent->GetNativeWindow()->GetRootWindow(); 330 root_window_ = parent->GetNativeWindow()->GetRootWindow();
331
332 // Observe activation changes to close the window if another window is
333 // activated (crbug.com/131027).
334 if (!nested_menu)
335 aura::client::GetActivationClient(root_window_)->AddObserver(this);
336
329 aura::client::GetDispatcherClient(root_window_)-> 337 aura::client::GetDispatcherClient(root_window_)->
330 RunWithDispatcher(this, parent->GetNativeWindow(), true); 338 RunWithDispatcher(this, parent->GetNativeWindow(), true);
339
340 if (!nested_menu)
341 aura::client::GetActivationClient(root_window_)->RemoveObserver(this);
331 #else 342 #else
332 { 343 {
333 MessageLoopForUI* loop = MessageLoopForUI::current(); 344 MessageLoopForUI* loop = MessageLoopForUI::current();
334 MessageLoop::ScopedNestableTaskAllower allow(loop); 345 MessageLoop::ScopedNestableTaskAllower allow(loop);
335 loop->RunWithDispatcher(this); 346 loop->RunWithDispatcher(this);
336 } 347 }
337 #endif 348 #endif
338 message_loop_depth_--; 349 message_loop_depth_--;
339 350
340 if (ViewsDelegate::views_delegate) 351 if (ViewsDelegate::views_delegate)
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 703
693 StopCancelAllTimer(); 704 StopCancelAllTimer();
694 } 705 }
695 706
696 void MenuController::OnDragExitedScrollButton(SubmenuView* source) { 707 void MenuController::OnDragExitedScrollButton(SubmenuView* source) {
697 StartCancelAllTimer(); 708 StartCancelAllTimer();
698 SetDropMenuItem(NULL, MenuDelegate::DROP_NONE); 709 SetDropMenuItem(NULL, MenuDelegate::DROP_NONE);
699 StopScrolling(); 710 StopScrolling();
700 } 711 }
701 712
702 void MenuController::OnWidgetActivationChanged() {
703 if (!drag_in_progress_)
704 Cancel(EXIT_ALL);
705 }
706
707 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { 713 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) {
708 if (submenu->IsShowing()) { 714 if (submenu->IsShowing()) {
709 gfx::Point point = gfx::Screen::GetCursorScreenPoint(); 715 gfx::Point point = gfx::Screen::GetCursorScreenPoint();
710 const SubmenuView* root_submenu = 716 const SubmenuView* root_submenu =
711 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); 717 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu();
712 views::View::ConvertPointFromScreen( 718 views::View::ConvertPointFromScreen(
713 root_submenu->GetWidget()->GetRootView(), &point); 719 root_submenu->GetWidget()->GetRootView(), &point);
714 HandleMouseLocation(submenu, point); 720 HandleMouseLocation(submenu, point);
715 } 721 }
716 } 722 }
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 pending_state_.item->GetParentMenuItem() && 2123 pending_state_.item->GetParentMenuItem() &&
2118 (!pending_state_.item->HasSubmenu() || 2124 (!pending_state_.item->HasSubmenu() ||
2119 !pending_state_.item->GetSubmenu()->IsShowing())) { 2125 !pending_state_.item->GetSubmenu()->IsShowing())) {
2120 // On exit if the user hasn't selected an item with a submenu, move the 2126 // On exit if the user hasn't selected an item with a submenu, move the
2121 // selection back to the parent menu item. 2127 // selection back to the parent menu item.
2122 SetSelection(pending_state_.item->GetParentMenuItem(), 2128 SetSelection(pending_state_.item->GetParentMenuItem(),
2123 SELECTION_OPEN_SUBMENU); 2129 SELECTION_OPEN_SUBMENU);
2124 } 2130 }
2125 } 2131 }
2126 2132
2133 #if defined(USE_AURA)
2134 void MenuController::OnWindowActivated(aura::Window* active,
2135 aura::Window* old_active) {
2136 if (!drag_in_progress_)
2137 Cancel(EXIT_ALL);
2138 }
2139 #endif
2140
2127 } // namespace views 2141 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698