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..2cc0bfef29f80edf52bde137bf9693caa7b1dafa 100644 |
| --- a/ui/views/controls/menu/menu_host.cc |
| +++ b/ui/views/controls/menu/menu_host.cc |
| @@ -98,7 +98,8 @@ MenuHost::~MenuHost() { |
| void MenuHost::InitMenuHost(Widget* parent, |
| const gfx::Rect& bounds, |
| View* contents_view, |
| - bool do_capture) { |
| + bool do_capture, |
| + bool cancel_active_touches) { |
|
xiyuan
2017/05/12 20:24:56
How about get this from MenuController instead of
|
| TRACE_EVENT0("views", "MenuHost::InitMenuHost"); |
| Widget::InitParams params(Widget::InitParams::TYPE_MENU); |
| const MenuController* menu_controller = |
| @@ -127,28 +128,44 @@ void MenuHost::InitMenuHost(Widget* parent, |
| menu_controller, submenu_, GetNativeView())); |
| #endif |
| + owner_ = parent; |
| + |
| + TransferEvents(owner_, this); |
|
xiyuan
2017/05/12 20:24:56
We probably should only do this for the out-most m
|
| + |
| SetContentsView(contents_view); |
| - ShowMenuHost(do_capture); |
| + ShowMenuHost(do_capture, cancel_active_touches); |
| +} |
| + |
| +void MenuHost::TransferEvents(Widget* source, Widget* target) { |
| + ui::GestureRecognizer::Get()->TransferEventsTo( |
| + source->GetNativeView(), target->GetNativeView(), |
| + ui::GestureRecognizer::ShouldCancelTouches::DontCancel); |
| } |
| bool MenuHost::IsMenuHostVisible() { |
| return IsVisible(); |
| } |
| -void MenuHost::ShowMenuHost(bool do_capture) { |
| +void MenuHost::ShowMenuHost(bool do_capture, bool cancel_active_touches) { |
| // Doing a capture may make us get capture lost. Ignore it while we're in the |
| // process of showing. |
| base::AutoReset<bool> reseter(&ignore_capture_lost_, true); |
| ShowInactive(); |
| + if (cancel_active_touches) { |
|
xiyuan
2017/05/12 20:24:56
This should probably be in the if (do_capture) dow
|
| + ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); |
| + } |
| if (do_capture) { |
| // Cancel existing touches, so we don't miss some touch release/cancel |
| // events due to the menu taking capture. |
| - ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); |
| native_widget_private()->SetCapture(); |
| } |
| } |
| void MenuHost::HideMenuHost() { |
| + if (owner_) { |
| + TransferEvents(this, owner_); |
|
xiyuan
2017/05/12 20:24:56
Similarly, we need to figure out how to do this on
|
| + owner_ = NULL; |
| + } |
| ignore_capture_lost_ = true; |
| ReleaseMenuHostCapture(); |
| Hide(); |