Commit 0218586c authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Do not set the mouse event handler if Widget::SetCapture() fails.

In particular, Widget::SetCapture() fails if the widget is not visible.

BUG=None
TEST=WidgetCaptureTest.FailedCaptureRequestIsNoop

Review URL: https://codereview.chromium.org/375593002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283633 0039d316-1c4b-4281-b951-d872f2087c98
parent 84520e55
......@@ -915,12 +915,6 @@ void TabDragController::Attach(TabStrip* attached_tabstrip,
// drag isn't prematurely canceled.
attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_);
attached_tabstrip_->OwnDragController(this);
// Redirect all mouse events to the TabStrip so that the tab that originated
// the drag can safely be deleted.
static_cast<views::internal::RootView*>(
attached_tabstrip_->GetWidget()->GetRootView())->SetMouseHandler(
attached_tabstrip_);
}
void TabDragController::Detach(ReleaseCapture release_capture) {
......
......@@ -685,7 +685,6 @@ void DesktopWindowTreeHostWin::HandleCancelMode() {
void DesktopWindowTreeHostWin::HandleCaptureLost() {
OnHostLostWindowCapture();
native_widget_delegate_->OnMouseCaptureLost();
}
void DesktopWindowTreeHostWin::HandleClose() {
......
......@@ -1301,7 +1301,6 @@ void DesktopWindowTreeHostX11::OnCaptureReleased() {
x11_capture_.reset();
g_current_capture = NULL;
OnHostLostWindowCapture();
native_widget_delegate_->OnMouseCaptureLost();
}
void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) {
......
......@@ -938,11 +938,17 @@ NativeWidget* Widget::native_widget() {
}
void Widget::SetCapture(View* view) {
if (!native_widget_->HasCapture()) {
native_widget_->SetCapture();
// Early return if setting capture was unsuccessful.
if (!native_widget_->HasCapture())
return;
}
if (internal::NativeWidgetPrivate::IsMouseButtonDown())
is_mouse_button_pressed_ = true;
root_view_->SetMouseHandler(view);
if (!native_widget_->HasCapture())
native_widget_->SetCapture();
}
void Widget::ReleaseCapture() {
......
......@@ -893,6 +893,39 @@ TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) {
}
#endif
// Test that no state is set if capture fails.
TEST_F(WidgetCaptureTest, FailedCaptureRequestIsNoop) {
Widget widget;
Widget::InitParams params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(400, 400);
widget.Init(params);
MouseView* mouse_view1 = new MouseView;
MouseView* mouse_view2 = new MouseView;
View* contents_view = new View;
contents_view->AddChildView(mouse_view1);
contents_view->AddChildView(mouse_view2);
widget.SetContentsView(contents_view);
mouse_view1->SetBounds(0, 0, 200, 400);
mouse_view2->SetBounds(200, 0, 200, 400);
// Setting capture should fail because |widget| is not visible.
widget.SetCapture(mouse_view1);
EXPECT_FALSE(widget.HasCapture());
widget.Show();
ui::MouseEvent mouse_press_event(ui::ET_MOUSE_PRESSED, gfx::Point(300, 10),
gfx::Point(300, 10), ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details = widget.GetNativeWindow()->GetHost()->
event_processor()->OnEventFromSource(&mouse_press_event);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_FALSE(mouse_view1->pressed());
EXPECT_TRUE(mouse_view2->pressed());
}
#if !defined(OS_CHROMEOS)
// Test that a synthetic mouse exit is sent to the widget which was handling
// mouse events when a different widget grabs capture.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment