0

Allows focus to change when capture held

r186536 made it so focus focus changes while capture held are
ignored. Problem is we enter this scenario when activating a
window. In particular the window has capture, then we activate it but
the activation is ignored because it has capture. In this case we need
to allow the focus change else events are completely dropped.

BUG=277593
TEST=covered by tests
R=ananta@chromium.org

Review URL: https://chromiumcodereview.appspot.com/23892006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221645 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
sky@chromium.org
2013-09-06 08:22:00 +00:00
parent bed98921e2
commit 22326044ca
2 changed files with 29 additions and 3 deletions

@ -130,9 +130,12 @@ void FocusController::FocusWindow(aura::Window* window) {
return;
}
// We should not be messing with the focus if the window has capture.
if (window && (aura::client::GetCaptureWindow(window) == window))
// We should not be messing with the focus if the window has capture, unless
// no has focus.
if (window && (aura::client::GetCaptureWindow(window) == window) &&
focused_window_) {
return;
}
// Focusing a window also activates its containing activatable window. Note
// that the rules could redirect activation activation and/or focus.

@ -268,7 +268,8 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
return aura::client::GetFocusClient(root_window())->GetFocusedWindow();
}
int GetFocusedWindowId() {
return GetFocusedWindow()->id();
aura::Window* focused_window = GetFocusedWindow();
return focused_window ? focused_window->id() : -1;
}
void ActivateWindow(aura::Window* window) {
aura::client::GetActivationClient(root_window())->ActivateWindow(window);
@ -303,6 +304,7 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
virtual void ShiftFocusOnActivationDueToHide() {}
virtual void NoShiftActiveOnActivation() {}
virtual void NoFocusChangeOnClickOnCaptureWindow() {}
virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
private:
scoped_ptr<FocusController> focus_controller_;
@ -598,6 +600,24 @@ class FocusControllerDirectTestBase : public FocusControllerTestBase {
aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2);
}
// Verifies focus change is honored while capture held.
virtual void ChangeFocusWhenNothingFocusedAndCaptured() OVERRIDE {
scoped_ptr<aura::client::DefaultCaptureClient> capture_client(
new aura::client::DefaultCaptureClient(root_window()));
aura::Window* w1 = root_window()->GetChildById(1);
aura::client::GetCaptureClient(root_window())->SetCapture(w1);
EXPECT_EQ(-1, GetActiveWindowId());
EXPECT_EQ(-1, GetFocusedWindowId());
FocusWindowById(1);
EXPECT_EQ(1, GetActiveWindowId());
EXPECT_EQ(1, GetFocusedWindowId());
aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
}
private:
DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase);
};
@ -996,5 +1016,8 @@ DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation);
// Clicking on a window which has capture should not result in a focus change.
DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow);
FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
ChangeFocusWhenNothingFocusedAndCaptured);
} // namespace corewm
} // namespace views