Commit 2e8c5a83 authored by chinsenj's avatar chinsenj Committed by Commit Bot

cros: Make overview session eat keys on start animation.

If an app has focus while overview starts, it can receive key events.
For apps like Chrome, this can result in visual glitches like fragments
of omnibox appearing during the overview startup animation.

To prevent this behavior, overview session now eats keys during the
start animation.

Test: OverviewSessionTest.EatKeysDuringStartAnimation
Bug: 951324
Change-Id: Ic0f4c0cef94477ea56846eb7d7f115fc74fbcc79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2323741
Commit-Queue: Jeremy Chinsen <chinsenj@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792437}
parent 8f1b1e1a
...@@ -986,8 +986,15 @@ void OverviewSession::OnKeyEvent(ui::KeyEvent* event) { ...@@ -986,8 +986,15 @@ void OverviewSession::OnKeyEvent(ui::KeyEvent* event) {
return; return;
break; break;
} }
default: default: {
// Window activation change happens after overview start animation is
// finished for performance reasons. During the animation, the focused
// window prior to entering overview still has focus so stop events from
// reaching it. See https://crbug.com/951324 for more details.
if (shell->overview_controller()->IsInStartAnimation())
break;
return; return;
}
} }
event->SetHandled(); event->SetHandled();
......
...@@ -3015,6 +3015,62 @@ TEST_P(OverviewSessionTest, ShelfAlignmentChangeWhileInOverview) { ...@@ -3015,6 +3015,62 @@ TEST_P(OverviewSessionTest, ShelfAlignmentChangeWhileInOverview) {
EXPECT_FALSE(InOverviewSession()); EXPECT_FALSE(InOverviewSession());
} }
namespace {
class TestEventHandler : public ui::EventHandler {
public:
TestEventHandler() = default;
~TestEventHandler() override = default;
// ui::EventHandler
void OnKeyEvent(ui::KeyEvent* event) override {
if (event->type() != ui::ET_KEY_PRESSED)
return;
has_seen_event_ = true;
event->SetHandled();
event->StopPropagation();
}
bool HasSeenEvent() { return has_seen_event_; }
void Reset() { has_seen_event_ = false; }
private:
bool has_seen_event_ = false;
};
} // namespace
// Test that keys are eaten when entering overview mode.
TEST_P(OverviewSessionTest, EatKeysDuringStartAnimation) {
std::unique_ptr<aura::Window> test_window(CreateTestWindow());
TestEventHandler test_event_handler;
test_window->SetTargetHandler(&test_event_handler);
test_window->Focus();
ui::ScopedAnimationDurationScaleMode animation_scale(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Keys shouldn't be eaten by overview session normally.
SendKey(ui::VKEY_A);
ASSERT_TRUE(test_window->HasFocus());
EXPECT_TRUE(test_event_handler.HasSeenEvent());
test_event_handler.Reset();
// Keys should be eaten by overview session when entering overview mode.
ToggleOverview();
ASSERT_TRUE(Shell::Get()->overview_controller()->IsInStartAnimation());
ASSERT_TRUE(test_window->HasFocus());
SendKey(ui::VKEY_B);
EXPECT_FALSE(test_event_handler.HasSeenEvent());
EXPECT_TRUE(InOverviewSession());
WaitForOverviewEnterAnimation();
ASSERT_FALSE(Shell::Get()->overview_controller()->IsInStartAnimation());
EXPECT_FALSE(test_window->HasFocus());
ToggleOverview();
SendKey(ui::VKEY_C);
EXPECT_FALSE(InOverviewSession());
EXPECT_TRUE(test_event_handler.HasSeenEvent());
}
// The class to test overview behavior with kDragFromShelfToHomeOrOverview flag // The class to test overview behavior with kDragFromShelfToHomeOrOverview flag
// enabled. // enabled.
class OverviewSessionWithDragFromShelfFeatureTest : public OverviewSessionTest { class OverviewSessionWithDragFromShelfFeatureTest : public OverviewSessionTest {
......
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