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

Unified Diff: ui/views/controls/menu/menu_controller.cc

Issue 9466028: aura: Repost click events that cause a menu to hide itself. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_controller.cc
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index d3b8e3fe9a0b433aaa8b12d13135cccf51967335..ac880a1aea68ce00963519bd8670c652857146b4 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -27,12 +27,16 @@
#if defined(USE_AURA)
#include "ui/aura/client/dispatcher_client.h"
#include "ui/aura/env.h"
+#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#elif defined(TOOLKIT_USES_GTK)
#include "ui/base/keycodes/keyboard_code_conversion_gtk.h"
#endif
-using base::Time;
+#if defined(USE_AURA) && defined(USE_X11)
+#include <X11/Xlib.h>
+#endif
+
using base::TimeDelta;
using ui::OSExchangeData;
@@ -163,7 +167,7 @@ class MenuController::MenuScrollTask {
if (new_menu == submenu_ && is_scrolling_up_ == new_is_up)
return;
- start_scroll_time_ = Time::Now();
+ start_scroll_time_ = base::Time::Now();
start_y_ = part.submenu->GetVisibleBounds().y();
submenu_ = new_menu;
is_scrolling_up_ = new_is_up;
@@ -190,7 +194,7 @@ class MenuController::MenuScrollTask {
DCHECK(submenu_);
gfx::Rect vis_rect = submenu_->GetVisibleBounds();
const int delta_y = static_cast<int>(
- (Time::Now() - start_scroll_time_).InMilliseconds() *
+ (base::Time::Now() - start_scroll_time_).InMilliseconds() *
pixels_per_second_ / 1000);
vis_rect.set_y(is_scrolling_up_ ?
std::max(0, start_y_ - delta_y) :
@@ -208,7 +212,7 @@ class MenuController::MenuScrollTask {
base::RepeatingTimer<MenuScrollTask> scrolling_timer_;
// Time we started scrolling at.
- Time start_scroll_time_;
+ base::Time start_scroll_time_;
// How many pixels to scroll per second.
int pixels_per_second_;
@@ -785,7 +789,7 @@ void MenuController::SetSelectionOnPointerDown(SubmenuView* source,
// We're going to close and we own the mouse capture. We need to repost the
// mouse down, otherwise the window the user clicked on won't get the
// event.
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN) || defined(USE_AURA)
RepostEvent(source, event);
// NOTE: not reposting on linux seems fine.
#endif
@@ -1836,7 +1840,7 @@ bool MenuController::SelectByChar(char16 character) {
return false;
}
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN)
void MenuController::RepostEvent(SubmenuView* source,
const LocatedEvent& event) {
if (!state_.item) {
@@ -1904,6 +1908,42 @@ void MenuController::RepostEvent(SubmenuView* source,
}
}
}
+#elif defined(USE_AURA)
+void MenuController::RepostEvent(SubmenuView* source,
+ const LocatedEvent& event) {
+ if (!state_.item) {
+ // We some times get an event after closing all the menus. Ignore it.
+ // Make sure the menu is in fact not visible. If the menu is visible, then
+ // we're in a bad state where we think the menu isn't visibile but it is.
+ DCHECK(!source->GetWidget()->IsVisible());
+ return;
+ }
+
+ // Release the capture.
+ SubmenuView* submenu = state_.item->GetRootMenuItem()->GetSubmenu();
+ submenu->ReleaseCapture();
+
+ gfx::Point screen_loc(event.location());
+ View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
+
+ XEvent xevent;
+ xevent.type = ButtonPress;
+ xevent.xbutton.x = screen_loc.x();
+ xevent.xbutton.y = screen_loc.y();
+ xevent.xbutton.state = 0;
+ xevent.xbutton.same_screen = True;
+ int flags = event.flags();
+ if (flags & ui::EF_LEFT_MOUSE_BUTTON)
+ xevent.xbutton.button = 1;
+ else if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
+ xevent.xbutton.button = 2;
+ else if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
+ xevent.xbutton.button = 3;
+ else
+ return;
+
+ aura::RootWindow::GetInstance()->PostNativeEvent(&xevent);
+}
#endif // defined(OS_WIN)
Ben Goodger (Google) 2012/02/24 23:26:15 // defined(USE_AURA)
sadrul 2012/02/24 23:30:28 Done.
void MenuController::SetDropMenuItem(
« 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