Commit 81c59eed authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

exo: Ignore key events when the target is not an exo::Surface

When an event target is not an exo::Surface, let another handler process
the event.

BUG=b:135076290
TEST=Confirm arrow keys work correctly in a custom tab and a normal ARC
app (such as Google Docs)
TEST=exo_unittests --gtest_filter=KeyboardTest.OnKeyboardKey

Change-Id: I8218aeced9f5a7e15db55099da45ce4cd72e83b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659488
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670244}
parent 5146998f
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/exo/keyboard_device_configuration_delegate.h" #include "components/exo/keyboard_device_configuration_delegate.h"
#include "components/exo/seat.h" #include "components/exo/seat.h"
#include "components/exo/shell_surface.h" #include "components/exo/shell_surface.h"
#include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
...@@ -236,6 +237,14 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) { ...@@ -236,6 +237,14 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) {
if (event->is_repeat()) if (event->is_repeat())
return; return;
// If the event target is not an exo::Surface, let another handler process the
// event. This check may not be necessary once https://crbug.com/624168 is
// resolved.
if (!GetShellMainSurface(static_cast<aura::Window*>(event->target())) &&
!Surface::AsSurface(static_cast<aura::Window*>(event->target()))) {
return;
}
TRACE_EXO_INPUT_EVENT(event); TRACE_EXO_INPUT_EVENT(event);
// Process reserved accelerators before sending it to client. // Process reserved accelerators before sending it to client.
......
...@@ -238,6 +238,28 @@ TEST_F(KeyboardTest, OnKeyboardKey) { ...@@ -238,6 +238,28 @@ TEST_F(KeyboardTest, OnKeyboardKey) {
EXPECT_CALL(delegate, OnKeyboardKey(testing::_, ui::DomCode::US_W, false)); EXPECT_CALL(delegate, OnKeyboardKey(testing::_, ui::DomCode::US_W, false));
generator.ReleaseKey(ui::VKEY_W, ui::EF_CONTROL_DOWN); generator.ReleaseKey(ui::VKEY_W, ui::EF_CONTROL_DOWN);
// Key events should be ignored when the focused window is not an
// exo::Surface.
auto window = CreateChildWindow(shell_surface->GetWidget()->GetNativeWindow(),
gfx::Rect(buffer_size));
// Moving the focus away will trigger the fallback path in GetEffectiveFocus.
// TODO(oshima): Consider removing the fallback path.
EXPECT_CALL(delegate, CanAcceptKeyboardEventsForSurface(surface.get()))
.WillOnce(testing::Return(true));
focus_client->FocusWindow(window.get());
EXPECT_CALL(delegate,
OnKeyboardKey(testing::_, ui::DomCode::ARROW_LEFT, true))
.Times(0);
seat.set_physical_code_for_currently_processing_event_for_testing(
ui::DomCode::ARROW_LEFT);
generator.PressKey(ui::VKEY_LEFT, 0);
EXPECT_CALL(delegate,
OnKeyboardKey(testing::_, ui::DomCode::ARROW_LEFT, false))
.Times(0);
generator.ReleaseKey(ui::VKEY_LEFT, 0);
keyboard.reset(); keyboard.reset();
} }
......
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