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(); |
} |