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

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

Issue 1565013002: Don't send touch events to windows like menus when the touch occurs outside the menu bounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build redness Created 4 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/menu/menu_host.cc
diff --git a/ui/views/controls/menu/menu_host.cc b/ui/views/controls/menu/menu_host.cc
index 9840abbdf0f650848ddac72fd05b68470f8eb1bf..ea79f5a133322cef3a37da23dfd99921d79b086b 100644
--- a/ui/views/controls/menu/menu_host.cc
+++ b/ui/views/controls/menu/menu_host.cc
@@ -19,8 +19,51 @@
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/widget.h"
+#if !defined(OS_MACOSX)
+#include "ui/aura/window.h"
+#endif
+
namespace views {
+namespace internal {
+
+#if !defined(OS_MACOSX)
+// This class adds itself as the pre target handler for the |window|
+// passed in. It currently handles touch events and forwards them to the
+// controller. Reason for this approach is views does not get raw touch
+// events which we need to determine if a touch happened outside the bounds
+// of the menu.
+class PreMenuEventDispatchHandler : public ui::EventHandler {
+ public:
+ explicit PreMenuEventDispatchHandler(const MenuController* controller,
+ SubmenuView* submenu,
+ aura::Window* window)
+ : menu_controller_(const_cast<MenuController*>(controller)),
+ submenu_(submenu),
+ window_(window) {
+ window_->AddPreTargetHandler(this);
+ }
+
+ ~PreMenuEventDispatchHandler() override {
+ window_->RemovePreTargetHandler(this);
+ }
+
+ // ui::EventHandler overrides.
+ void OnTouchEvent(ui::TouchEvent* event) override {
+ menu_controller_->OnTouchEvent(submenu_, event);
+ }
+
+ private:
+ MenuController* menu_controller_;
+ SubmenuView* submenu_;
+ aura::Window* window_;
+
+ DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler);
+};
+#endif // OS_MACOSX
+
+} // namespace internal
+
////////////////////////////////////////////////////////////////////////////////
// MenuHost, public:
@@ -61,6 +104,11 @@ void MenuHost::InitMenuHost(Widget* parent,
#endif
Init(params);
+#if !defined(OS_MACOSX)
+ pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler(
+ menu_controller, submenu_, GetNativeView()));
+#endif
+
SetContentsView(contents_view);
ShowMenuHost(do_capture);
}
@@ -93,6 +141,9 @@ void MenuHost::DestroyMenuHost() {
HideMenuHost();
destroying_ = true;
static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu();
+#if !defined(OS_MACOSX)
+ pre_dispatch_handler_.reset();
+#endif
Close();
}

Powered by Google App Engine
This is Rietveld 408576698