Chromium Code Reviews| Index: ui/views/widget/widget.cc |
| diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc |
| index 17675e73c44d8c90681eabff93600f6de4b5d1d4..b49dc2bbcb4297e4105b34a93f8d04da98d243c5 100644 |
| --- a/ui/views/widget/widget.cc |
| +++ b/ui/views/widget/widget.cc |
| @@ -1171,19 +1171,29 @@ void Widget::OnMouseEvent(ui::MouseEvent* event) { |
| // use an observer to make sure we are still alive. |
| WidgetDeletionObserver widget_deletion_observer(this); |
| + gfx::NativeView current_capture = |
| + internal::NativeWidgetPrivate::GetCapture( |
| + native_widget_->GetNativeView()); |
| // Make sure we're still visible before we attempt capture as the mouse |
| // press processing may have made the window hide (as happens with menus). |
| - // It is possible for a View to show a context menu on mouse-press. Since |
| - // the menu does a capture and starts a nested message-loop, the release |
| - // would go to the menu. The next click (i.e. both mouse-press and release |
| - // events) also go to the menu. The menu (and the nested message-loop) |
| - // gets closed after this second release event. The code then resumes from |
| - // here. So make sure that the mouse-button is still down before doing a |
| - // capture. |
| + // It is possible for a View to show a context menu on mouse-press, which |
|
sky
2016/05/06 20:03:32
Can you make this comment more general and not ent
jonross
2016/05/09 16:50:25
Done.
|
| + // takes capture. |
| + // |
| + // Menus which use a nested message-loop, receive the release. The next |
| + // click (i.e. both mouse-press and release events) also go to the menu. |
| + // The menu (and the nested message-loop) gets closed after this second |
| + // release event. The code then resumes from here. So make sure that the |
| + // mouse-button is still down before doing a capture. |
| + // |
| + // Menus which do not use a nested message-loop will return here, holding |
| + // capture. This will lead to capture having changed, in which case we do |
| + // not give capture back to the |native_widget_|. |
| if (root_view && root_view->OnMousePressed(*event) && |
| widget_deletion_observer.IsWidgetAlive() && IsVisible() && |
| - internal::NativeWidgetPrivate::IsMouseButtonDown()) { |
| + internal::NativeWidgetPrivate::IsMouseButtonDown() && |
| + current_capture == internal::NativeWidgetPrivate::GetCapture( |
| + native_widget_->GetNativeView())) { |
| is_mouse_button_pressed_ = true; |
| if (!native_widget_->HasCapture()) |
| native_widget_->SetCapture(); |