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(OS_CHROMEOS) | |
|
oshima
2013/01/08 23:26:10
shouldn't we use USE_X11?
sschmitz
2013/01/18 20:30:16
Done.
| |
| 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 Loading... | |
| 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(OS_CHROMEOS) |
| 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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1988 if (in_client_area) { | 1991 if (in_client_area) { |
| 1989 PostMessage(window, event_type, event.native_event().wParam, | 1992 PostMessage(window, event_type, event.native_event().wParam, |
| 1990 MAKELPARAM(window_x, window_y)); | 1993 MAKELPARAM(window_x, window_y)); |
| 1991 } else { | 1994 } else { |
| 1992 PostMessage(window, event_type, nc_hit_result, | 1995 PostMessage(window, event_type, nc_hit_result, |
| 1993 MAKELPARAM(screen_loc.x(), screen_loc.y())); | 1996 MAKELPARAM(screen_loc.x(), screen_loc.y())); |
| 1994 } | 1997 } |
| 1995 } | 1998 } |
| 1996 } | 1999 } |
| 1997 } | 2000 } |
| 1998 #endif // defined(OS_WIN) | 2001 #elif defined(OS_CHROMEOS) |
| 2002 void MenuController::RepostEvent(SubmenuView* source, | |
| 2003 const ui::LocatedEvent& event) { | |
| 2004 if (!state_.item) { | |
| 2005 // We some times get an event after closing all the menus. Ignore it. | |
| 2006 // Make sure the menu is in fact not visible. If the menu is visible, then | |
| 2007 // we're in a bad state where we think the menu isn't visibile but it is. | |
| 2008 DCHECK(!source->GetWidget()->IsVisible()); | |
| 2009 return; | |
| 2010 } | |
| 2011 | |
| 2012 // Release the capture. | |
| 2013 SubmenuView* submenu = state_.item->GetRootMenuItem()->GetSubmenu(); | |
| 2014 submenu->ReleaseCapture(); | |
| 2015 | |
| 2016 // We putback the X11 event. We set the "send_event" field in the | |
| 2017 // XEvent. Otherwise a mouse click would generate a double click | |
| 2018 // event. The field "send_event" is in the same place for all event | |
| 2019 // types so we can use "xany" regardless of type. | |
| 2020 if (!event.native_event()) | |
| 2021 return; | |
| 2022 XEvent xevent = *event.native_event(); | |
| 2023 xevent.xany.send_event = True; | |
| 2024 XPutBackEvent(xevent.xany.display, &xevent); | |
|
oshima
2013/01/08 23:26:10
Won't this cause clicking on a button actually act
sschmitz
2013/01/18 20:30:16
The function is only invoked when the mouse was no
| |
| 2025 } | |
| 2026 #endif | |
| 1999 | 2027 |
| 2000 void MenuController::SetDropMenuItem( | 2028 void MenuController::SetDropMenuItem( |
| 2001 MenuItemView* new_target, | 2029 MenuItemView* new_target, |
| 2002 MenuDelegate::DropPosition new_position) { | 2030 MenuDelegate::DropPosition new_position) { |
| 2003 if (new_target == drop_target_ && new_position == drop_position_) | 2031 if (new_target == drop_target_ && new_position == drop_position_) |
| 2004 return; | 2032 return; |
| 2005 | 2033 |
| 2006 if (drop_target_) { | 2034 if (drop_target_) { |
| 2007 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem( | 2035 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem( |
| 2008 NULL, MenuDelegate::DROP_NONE); | 2036 NULL, MenuDelegate::DROP_NONE); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 (!pending_state_.item->HasSubmenu() || | 2173 (!pending_state_.item->HasSubmenu() || |
| 2146 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2174 !pending_state_.item->GetSubmenu()->IsShowing())) { |
| 2147 // On exit if the user hasn't selected an item with a submenu, move the | 2175 // On exit if the user hasn't selected an item with a submenu, move the |
| 2148 // selection back to the parent menu item. | 2176 // selection back to the parent menu item. |
| 2149 SetSelection(pending_state_.item->GetParentMenuItem(), | 2177 SetSelection(pending_state_.item->GetParentMenuItem(), |
| 2150 SELECTION_OPEN_SUBMENU); | 2178 SELECTION_OPEN_SUBMENU); |
| 2151 } | 2179 } |
| 2152 } | 2180 } |
| 2153 | 2181 |
| 2154 } // namespace views | 2182 } // namespace views |
| OLD | NEW |