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

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

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