Chromium Code Reviews| 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_AURA) && defined(USE_X11) | |
| 38 #include "ui/aura/root_window.h" | |
| 39 #include <X11/Xlib.h> | |
| 40 #endif | |
| 41 | |
| 37 using base::Time; | 42 using base::Time; |
| 38 using base::TimeDelta; | 43 using base::TimeDelta; |
| 39 using ui::OSExchangeData; | 44 using ui::OSExchangeData; |
| 40 | 45 |
| 41 // Period of the scroll timer (in milliseconds). | 46 // Period of the scroll timer (in milliseconds). |
| 42 static const int kScrollTimerMS = 30; | 47 static const int kScrollTimerMS = 30; |
| 43 | 48 |
| 44 // Amount of time from when the drop exits the menu and the menu is hidden. | 49 // Amount of time from when the drop exits the menu and the menu is hidden. |
| 45 static const int kCloseOnExitTime = 1200; | 50 static const int kCloseOnExitTime = 1200; |
| 46 | 51 |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 if (part.type == MenuPart::NONE || | 794 if (part.type == MenuPart::NONE || |
| 790 (part.type == MenuPart::MENU_ITEM && part.menu && | 795 (part.type == MenuPart::MENU_ITEM && part.menu && |
| 791 part.menu->GetRootMenuItem() != state_.item->GetRootMenuItem())) { | 796 part.menu->GetRootMenuItem() != state_.item->GetRootMenuItem())) { |
| 792 // Mouse wasn't pressed over any menu, or the active menu, cancel. | 797 // Mouse wasn't pressed over any menu, or the active menu, cancel. |
| 793 | 798 |
| 794 // We're going to close and we own the mouse capture. We need to repost the | 799 // We're going to close and we own the mouse capture. We need to repost the |
| 795 // mouse down, otherwise the window the user clicked on won't get the | 800 // mouse down, otherwise the window the user clicked on won't get the |
| 796 // event. | 801 // event. |
| 797 #if defined(OS_WIN) && !defined(USE_AURA) | 802 #if defined(OS_WIN) && !defined(USE_AURA) |
| 798 RepostEvent(source, event); | 803 RepostEvent(source, event); |
| 799 // NOTE: not reposting on linux seems fine. | |
| 800 #endif | 804 #endif |
| 801 | 805 |
| 806 #if defined(USE_AURA) && defined(USE_X11) | |
| 807 aura::RootWindow* root_window = | |
| 808 source->GetWidget()->GetNativeWindow()->GetRootWindow(); | |
| 809 #endif | |
| 810 | |
| 811 gfx::Point screen_loc(event.location()); | |
| 812 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | |
| 813 | |
| 802 // And close. | 814 // And close. |
| 803 ExitType exit_type = EXIT_ALL; | 815 ExitType exit_type = EXIT_ALL; |
| 804 if (!menu_stack_.empty()) { | 816 if (!menu_stack_.empty()) { |
| 805 // 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 |
| 806 // of the menus from the last run. | 818 // of the menus from the last run. |
| 807 gfx::Point screen_loc(event.location()); | |
| 808 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | |
| 809 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( | 819 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( |
| 810 menu_stack_.back().item, screen_loc); | 820 menu_stack_.back().item, screen_loc); |
| 811 if (last_part.type != MenuPart::NONE) | 821 if (last_part.type != MenuPart::NONE) |
| 812 exit_type = EXIT_OUTERMOST; | 822 exit_type = EXIT_OUTERMOST; |
| 813 } | 823 } |
| 814 Cancel(exit_type); | 824 Cancel(exit_type); |
| 825 | |
| 826 #if defined(USE_AURA) && defined(USE_X11) | |
| 827 if (exit_type == EXIT_ALL && event.type() == ui::ET_MOUSE_PRESSED) { | |
| 828 XEvent xevent = {0}; | |
| 829 xevent.xbutton.x = screen_loc.x(); | |
| 830 xevent.xbutton.y = screen_loc.y(); | |
| 831 xevent.xbutton.type = ButtonPress; | |
| 832 xevent.xbutton.same_screen = True; | |
| 833 const int event_flags = event.flags(); | |
| 834 bool do_it = true; | |
| 835 if (event_flags & ui::EF_LEFT_MOUSE_BUTTON) { | |
| 836 xevent.xbutton.button = Button1; | |
| 837 xevent.xbutton.state = Button1Mask; | |
| 838 } else if (event_flags & ui::EF_MIDDLE_MOUSE_BUTTON) { | |
| 839 xevent.xbutton.button = Button2; | |
| 840 xevent.xbutton.state = Button2Mask; | |
| 841 } else if (event_flags & ui::EF_RIGHT_MOUSE_BUTTON) { | |
| 842 xevent.xbutton.button = Button3; | |
| 843 xevent.xbutton.state = Button3Mask; | |
| 844 } else { | |
| 845 do_it = false; | |
| 846 } | |
| 847 // RootWindow will take care of other necessary fields. | |
| 848 if (do_it) | |
| 849 root_window->PostNativeEvent(&xevent); | |
|
sky
2013/01/07 16:06:13
Is PostNativeEvent async? I think this code will r
sschmitz
2013/01/08 22:48:57
Done.
| |
| 850 } | |
| 851 #endif | |
| 852 | |
| 815 return; | 853 return; |
| 816 } | 854 } |
| 817 | 855 |
| 818 // On a press we immediately commit the selection, that way a submenu | 856 // On a press we immediately commit the selection, that way a submenu |
| 819 // pops up immediately rather than after a delay. | 857 // pops up immediately rather than after a delay. |
| 820 int selection_types = SELECTION_UPDATE_IMMEDIATELY; | 858 int selection_types = SELECTION_UPDATE_IMMEDIATELY; |
| 821 if (!part.menu) { | 859 if (!part.menu) { |
| 822 part.menu = part.parent; | 860 part.menu = part.parent; |
| 823 selection_types |= SELECTION_OPEN_SUBMENU; | 861 selection_types |= SELECTION_OPEN_SUBMENU; |
| 824 } else { | 862 } else { |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2136 (!pending_state_.item->HasSubmenu() || | 2174 (!pending_state_.item->HasSubmenu() || |
| 2137 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2175 !pending_state_.item->GetSubmenu()->IsShowing())) { |
| 2138 // On exit if the user hasn't selected an item with a submenu, move the | 2176 // On exit if the user hasn't selected an item with a submenu, move the |
| 2139 // selection back to the parent menu item. | 2177 // selection back to the parent menu item. |
| 2140 SetSelection(pending_state_.item->GetParentMenuItem(), | 2178 SetSelection(pending_state_.item->GetParentMenuItem(), |
| 2141 SELECTION_OPEN_SUBMENU); | 2179 SELECTION_OPEN_SUBMENU); |
| 2142 } | 2180 } |
| 2143 } | 2181 } |
| 2144 | 2182 |
| 2145 } // namespace views | 2183 } // namespace views |
| OLD | NEW |