Chromium Code Reviews| 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 c6750a6e0cd51be18d9470a45969bed6b27c0e4c..adfe0fc9e02813254145f9892326d2217bb58315 100644 |
| --- a/ui/views/controls/menu/menu_host.cc |
| +++ b/ui/views/controls/menu/menu_host.cc |
| @@ -78,6 +78,12 @@ class PreMenuEventDispatchHandler : public ui::EventHandler, |
| DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler); |
| }; |
| + |
| +void TransferGesture(Widget* source, Widget* target) { |
| + ui::GestureRecognizer::Get()->TransferEventsTo( |
| + source->GetNativeView(), target->GetNativeView(), |
| + ui::GestureRecognizer::ShouldCancelTouches::DontCancel); |
| +} |
| #endif // OS_MACOSX |
| } // namespace internal |
| @@ -125,6 +131,7 @@ void MenuHost::InitMenuHost(Widget* parent, |
| #if !defined(OS_MACOSX) |
| pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( |
| menu_controller, submenu_, GetNativeView())); |
| + owner_ = parent; |
|
sadrul
2017/08/30 20:31:39
What if |owner_| is destroyed after the menu comes
minch1
2017/08/31 23:21:02
Added DCHECK(owner()) when we need to send events
sadrul
2017/09/07 19:58:28
If |owner_| is destroyed, the DCHECK() won't hit t
minch1
2017/09/07 20:54:55
Do you mean that |parent| is destroyed after assig
|
| #endif |
| SetContentsView(contents_view); |
| @@ -141,14 +148,36 @@ void MenuHost::ShowMenuHost(bool do_capture) { |
| base::AutoReset<bool> reseter(&ignore_capture_lost_, true); |
| ShowInactive(); |
| if (do_capture) { |
| +#if !defined(OS_MACOSX) |
|
sadrul
2017/08/30 20:31:39
Do we need the OS_MACOSX checks?
minch1
2017/08/31 23:21:02
I think so. Since GestureRecognizerImplMac current
|
| + MenuController* menu_controller = |
| + submenu_->GetMenuItem()->GetMenuController(); |
| + if (menu_controller && menu_controller->send_gesture_events_to_owner()) { |
| + // TransferGesture when owner needs gesture events so that the incoming |
| + // touch events after MenuHost is created are properly translated into |
| + // gesture events instead of being dropped. |
| + internal::TransferGesture(owner_, this); |
| + } else { |
| + ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); |
| + } |
| +#else // defined(OS_MACOSX) |
| // Cancel existing touches, so we don't miss some touch release/cancel |
| // events due to the menu taking capture. |
| ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); |
| +#endif // !defined(OS_MACOSX) |
| native_widget_private()->SetCapture(); |
| } |
| } |
|
sadrul
2017/08/30 20:31:39
An alternate approach, although probably hackier t
minch1
2017/08/31 23:21:02
Do you mean to do all of these in ShowMenuHost? Tr
|
| void MenuHost::HideMenuHost() { |
| +#if !defined(OS_MACOSX) |
| + MenuController* menu_controller = |
| + submenu_->GetMenuItem()->GetMenuController(); |
| + if (owner_ && menu_controller && |
| + menu_controller->send_gesture_events_to_owner()) { |
| + internal::TransferGesture(this, owner_); |
| + owner_ = nullptr; |
| + } |
| +#endif // !defined(OS_MACOSX) |
| ignore_capture_lost_ = true; |
| ReleaseMenuHostCapture(); |
| Hide(); |