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

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

Issue 11761027: context menu does not work if one already open (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: crbug.com/151074 Created 7 years, 11 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
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | no next file » | 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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 16 matching lines...) Expand all
27 #include "ui/views/view_constants.h" 27 #include "ui/views/view_constants.h"
28 #include "ui/views/views_delegate.h" 28 #include "ui/views/views_delegate.h"
29 #include "ui/views/widget/root_view.h" 29 #include "ui/views/widget/root_view.h"
30 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
31 31
32 #if defined(USE_AURA) 32 #if defined(USE_AURA)
33 #include "ui/aura/env.h" 33 #include "ui/aura/env.h"
34 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
35 #endif 35 #endif
36 36
37 #if defined(USE_X11)
38 #include <X11/Xlib.h>
39 #endif
40
37 using base::Time; 41 using base::Time;
38 using base::TimeDelta; 42 using base::TimeDelta;
39 using ui::OSExchangeData; 43 using ui::OSExchangeData;
40 44
41 // Period of the scroll timer (in milliseconds). 45 // Period of the scroll timer (in milliseconds).
42 static const int kScrollTimerMS = 30; 46 static const int kScrollTimerMS = 30;
43 47
44 // Amount of time from when the drop exits the menu and the menu is hidden. 48 // Amount of time from when the drop exits the menu and the menu is hidden.
45 static const int kCloseOnExitTime = 1200; 49 static const int kCloseOnExitTime = 1200;
46 50
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 return; 800 return;
797 801
798 if (part.type == MenuPart::NONE || 802 if (part.type == MenuPart::NONE ||
799 (part.type == MenuPart::MENU_ITEM && part.menu && 803 (part.type == MenuPart::MENU_ITEM && part.menu &&
800 part.menu->GetRootMenuItem() != state_.item->GetRootMenuItem())) { 804 part.menu->GetRootMenuItem() != state_.item->GetRootMenuItem())) {
801 // Mouse wasn't pressed over any menu, or the active menu, cancel. 805 // Mouse wasn't pressed over any menu, or the active menu, cancel.
802 806
803 // We're going to close and we own the mouse capture. We need to repost the 807 // We're going to close and we own the mouse capture. We need to repost the
804 // mouse down, otherwise the window the user clicked on won't get the 808 // mouse down, otherwise the window the user clicked on won't get the
805 // event. 809 // event.
806 #if defined(OS_WIN) && !defined(USE_AURA) 810 #if (defined(OS_WIN) && !defined(USE_AURA)) || defined(USE_X11)
807 RepostEvent(source, event); 811 RepostEvent(source, event);
808 // NOTE: not reposting on linux seems fine.
809 #endif 812 #endif
810 813
811 // And close. 814 // And close.
812 ExitType exit_type = EXIT_ALL; 815 ExitType exit_type = EXIT_ALL;
813 if (!menu_stack_.empty()) { 816 if (!menu_stack_.empty()) {
814 // We're running nested menus. Only exit all if the mouse wasn't over one 817 // We're running nested menus. Only exit all if the mouse wasn't over one
815 // of the menus from the last run. 818 // of the menus from the last run.
816 gfx::Point screen_loc(event.location()); 819 gfx::Point screen_loc(event.location());
817 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); 820 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
818 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( 821 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu(
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 if (in_client_area) { 1970 if (in_client_area) {
1968 PostMessage(window, event_type, event.native_event().wParam, 1971 PostMessage(window, event_type, event.native_event().wParam,
1969 MAKELPARAM(window_x, window_y)); 1972 MAKELPARAM(window_x, window_y));
1970 } else { 1973 } else {
1971 PostMessage(window, event_type, nc_hit_result, 1974 PostMessage(window, event_type, nc_hit_result,
1972 MAKELPARAM(screen_loc.x(), screen_loc.y())); 1975 MAKELPARAM(screen_loc.x(), screen_loc.y()));
1973 } 1976 }
1974 } 1977 }
1975 } 1978 }
1976 } 1979 }
1977 #endif // defined(OS_WIN) 1980 #elif defined(USE_X11)
1981 void MenuController::RepostEvent(SubmenuView* source,
1982 const ui::LocatedEvent& event) {
1983 if (!state_.item) {
1984 // We some times get an event after closing all the menus. Ignore it.
1985 // Make sure the menu is in fact not visible. If the menu is visible, then
1986 // we're in a bad state where we think the menu isn't visibile but it is.
1987 DCHECK(!source->GetWidget()->IsVisible());
1988 return;
1989 }
1990 if (!event.native_event())
1991 return;
1992 // We putback the X11 event. We set the "send_event" field in the
1993 // XEvent. Otherwise a mouse click would generate a double click
1994 // event. The field "send_event" is in the same place for all event
1995 // types so we can use "xany" regardless of type.
1996 XEvent xevent = *event.native_event();
1997 xevent.xany.send_event = True;
1998 XPutBackEvent(xevent.xany.display, &xevent);
1999 }
2000 #endif
1978 2001
1979 void MenuController::SetDropMenuItem( 2002 void MenuController::SetDropMenuItem(
1980 MenuItemView* new_target, 2003 MenuItemView* new_target,
1981 MenuDelegate::DropPosition new_position) { 2004 MenuDelegate::DropPosition new_position) {
1982 if (new_target == drop_target_ && new_position == drop_position_) 2005 if (new_target == drop_target_ && new_position == drop_position_)
1983 return; 2006 return;
1984 2007
1985 if (drop_target_) { 2008 if (drop_target_) {
1986 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem( 2009 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem(
1987 NULL, MenuDelegate::DROP_NONE); 2010 NULL, MenuDelegate::DROP_NONE);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 (!pending_state_.item->HasSubmenu() || 2147 (!pending_state_.item->HasSubmenu() ||
2125 !pending_state_.item->GetSubmenu()->IsShowing())) { 2148 !pending_state_.item->GetSubmenu()->IsShowing())) {
2126 // On exit if the user hasn't selected an item with a submenu, move the 2149 // On exit if the user hasn't selected an item with a submenu, move the
2127 // selection back to the parent menu item. 2150 // selection back to the parent menu item.
2128 SetSelection(pending_state_.item->GetParentMenuItem(), 2151 SetSelection(pending_state_.item->GetParentMenuItem(),
2129 SELECTION_OPEN_SUBMENU); 2152 SELECTION_OPEN_SUBMENU);
2130 } 2153 }
2131 } 2154 }
2132 2155
2133 } // namespace views 2156 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698