| 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/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 Loading... |
| 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 // is sent before the menu appears. Ignore it. | 797 // is sent before the menu appears. Ignore it. |
| 794 if ((event.flags() & ui::EF_RIGHT_MOUSE_BUTTON) && | 798 if ((event.flags() & ui::EF_RIGHT_MOUSE_BUTTON) && |
| 795 (event.flags() & ui::EF_FROM_TOUCH)) | 799 (event.flags() & ui::EF_FROM_TOUCH)) |
| 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 | |
| 804 // mouse down, otherwise the window the user clicked on won't get the | |
| 805 // event. | |
| 806 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 807 RepostEvent(source, event); | |
| 808 // NOTE: not reposting on linux seems fine. | |
| 809 #endif | |
| 810 | |
| 811 // And close. | |
| 812 ExitType exit_type = EXIT_ALL; | 807 ExitType exit_type = EXIT_ALL; |
| 813 if (!menu_stack_.empty()) { | 808 if (!menu_stack_.empty()) { |
| 814 // We're running nested menus. Only exit all if the mouse wasn't over one | 809 // We're running nested menus. Only exit all if the mouse wasn't over one |
| 815 // of the menus from the last run. | 810 // of the menus from the last run. |
| 816 gfx::Point screen_loc(event.location()); | 811 gfx::Point screen_loc(event.location()); |
| 817 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | 812 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); |
| 818 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( | 813 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( |
| 819 menu_stack_.back().item, screen_loc); | 814 menu_stack_.back().item, screen_loc); |
| 820 if (last_part.type != MenuPart::NONE) | 815 if (last_part.type != MenuPart::NONE) |
| 821 exit_type = EXIT_OUTERMOST; | 816 exit_type = EXIT_OUTERMOST; |
| 822 } | 817 } |
| 818 |
| 819 #if defined(OS_WIN) && !defined(USE_AURA) |
| 820 // We're going to close and we own the mouse capture. We need to repost the |
| 821 // mouse down, otherwise the window the user clicked on won't get the |
| 822 // event. |
| 823 RepostEvent(source, event); |
| 824 #elif defined(USE_X11) |
| 825 if (exit_type == EXIT_ALL && state_.item && event.native_event()) { |
| 826 // We will putback the X11 event here, so that the usual |
| 827 // action (e.g. window activation, new context menu) happens |
| 828 // after this context menu and its message loop have exited. We |
| 829 // do not want mouse button events treated as double clicks. |
| 830 // Without the following special precaution a "put back" mouse |
| 831 // button event will result in a double click. We use the |
| 832 // "send_event" flag. When this event is processed later on, the |
| 833 // flag is used to avoid treating it as a double click. The |
| 834 // field "send_event" is in the same place for all event types |
| 835 // so we can use "xany" regardless of event type. |
| 836 XEvent xevent = *event.native_event(); |
| 837 xevent.xany.send_event = True; |
| 838 XPutBackEvent(xevent.xany.display, &xevent); |
| 839 } |
| 840 #endif |
| 841 |
| 842 // And close. |
| 823 Cancel(exit_type); | 843 Cancel(exit_type); |
| 844 |
| 824 return; | 845 return; |
| 825 } | 846 } |
| 826 | 847 |
| 827 // On a press we immediately commit the selection, that way a submenu | 848 // On a press we immediately commit the selection, that way a submenu |
| 828 // pops up immediately rather than after a delay. | 849 // pops up immediately rather than after a delay. |
| 829 int selection_types = SELECTION_UPDATE_IMMEDIATELY; | 850 int selection_types = SELECTION_UPDATE_IMMEDIATELY; |
| 830 if (!part.menu) { | 851 if (!part.menu) { |
| 831 part.menu = part.parent; | 852 part.menu = part.parent; |
| 832 selection_types |= SELECTION_OPEN_SUBMENU; | 853 selection_types |= SELECTION_OPEN_SUBMENU; |
| 833 } else { | 854 } else { |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2145 (!pending_state_.item->HasSubmenu() || | 2166 (!pending_state_.item->HasSubmenu() || |
| 2146 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2167 !pending_state_.item->GetSubmenu()->IsShowing())) { |
| 2147 // On exit if the user hasn't selected an item with a submenu, move the | 2168 // On exit if the user hasn't selected an item with a submenu, move the |
| 2148 // selection back to the parent menu item. | 2169 // selection back to the parent menu item. |
| 2149 SetSelection(pending_state_.item->GetParentMenuItem(), | 2170 SetSelection(pending_state_.item->GetParentMenuItem(), |
| 2150 SELECTION_OPEN_SUBMENU); | 2171 SELECTION_OPEN_SUBMENU); |
| 2151 } | 2172 } |
| 2152 } | 2173 } |
| 2153 | 2174 |
| 2154 } // namespace views | 2175 } // namespace views |
| OLD | NEW |