Commit b73824ff authored by erikchen's avatar erikchen Committed by Commit Bot

[Reland #1] Remove makeKeyAndOrderFront: from WebContentsViewMac::Focus().

The original CL caused a test failure in
DetachToBrowserTabDragControllerTest.DetachToOwnWindow. This was due to a bug in
the test itself, which was generating an incorrect mouse-up event. This CL fixes
the test to delay generation of the mouse-up event until the new tab dragging
window has been detached.

> WebContentsView::Focus() is supposed to update the first responder of the
> Window, not make the window focused. The latter should go through
> WebContentsDelegate::ActivateContents().
>
> This logic is usually a no-op because the window receiving the call is the
> active window. But in the case where the user quickly switches windows, this can
> cause the old window to re-take focus.
>
> This logic was added in 2009 not because it had the right semantics, but to
> match the behavior of Windows: http://codereview.chromium.org/165492.
>
> Bug: 859614
> Change-Id: I2bc44a825d93159d774c632da17cc2f2d151fc3a
> Reviewed-on: https://chromium-review.googlesource.com/1124772
> Reviewed-by: Avi Drissman <avi@chromium.org>
> Commit-Queue: Erik Chen <erikchen@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#573344}

Bug: 859614
Change-Id: I441a00ad015eb3559718b448fc42f98827beee35
Reviewed-on: https://chromium-review.googlesource.com/1132106Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574159}
parent a3c46f39
......@@ -531,6 +531,24 @@ class DetachToBrowserTabDragControllerTest
return true;
}
void ReleaseMouseAfterWindowDetached() {
// On macOS, we want to avoid generating the input event [which requires an
// associated window] until the window has been detached. Failure to do so
// causes odd behavior [e.g. on macOS 10.10, the mouse-up will reactivate
// the first window].
if (browser_list->size() != 2u) {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&DetachToBrowserTabDragControllerTest::
ReleaseMouseAfterWindowDetached,
base::Unretained(this)),
base::TimeDelta::FromMilliseconds(1));
return;
}
ASSERT_TRUE(ReleaseMouseAsync());
}
bool ReleaseMouseAsync() {
return input_source() == INPUT_SOURCE_MOUSE &&
ui_controls::SendMouseEvents(ui_controls::LEFT, ui_controls::UP);
......@@ -934,7 +952,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToOwnWindowStep2, this)));
if (input_source() == INPUT_SOURCE_MOUSE) {
ASSERT_TRUE(ReleaseMouseAsync());
ReleaseMouseAfterWindowDetached();
QuitWhenNotDragging();
}
......@@ -1008,7 +1026,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToOwnWindowStep2, this)));
if (input_source() == INPUT_SOURCE_MOUSE) {
ASSERT_TRUE(ReleaseMouseAsync());
ReleaseMouseAfterWindowDetached();
QuitWhenNotDragging();
}
......@@ -1077,7 +1095,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToOwnWindowStep2, this)));
if (input_source() == INPUT_SOURCE_MOUSE) {
ASSERT_TRUE(ReleaseMouseAsync());
ReleaseMouseAfterWindowDetached();
QuitWhenNotDragging();
}
......@@ -1134,7 +1152,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToOwnWindowStep2, this)));
if (input_source() == INPUT_SOURCE_MOUSE) {
ASSERT_TRUE(ReleaseMouseAsync());
ReleaseMouseAfterWindowDetached();
QuitWhenNotDragging();
}
......
......@@ -198,9 +198,6 @@ void WebContentsViewMac::Focus() {
gfx::NativeView native_view = GetNativeViewForFocus();
NSWindow* window = [native_view window];
[window makeFirstResponder:native_view];
if (![window isVisible])
return;
[window makeKeyAndOrderFront:nil];
}
void WebContentsViewMac::SetInitialFocus() {
......
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