Commit fe89fd3b authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: makes intercepts events work with capture

If an embedding is created such that the embedder intercepts events, then the
embedder should get events regardless of capture.

BUG=837692,837696
TEST=covered by test

Change-Id: I8ed3e30ff7973d319bb5ac91323382c1743818c1
Reviewed-on: https://chromium-review.googlesource.com/1080092Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563054}
parent fcd54faf
......@@ -144,10 +144,7 @@ class ClientWindowEventHandler : public ui::EventHandler {
return;
}
if (HandleInterceptedKeyEvent(event))
return;
if (ShouldIgnoreEvent(*event))
if (HandleInterceptedEvent(event) || ShouldIgnoreEvent(*event))
return;
auto* owning = client_window_->owning_window_service_client();
......@@ -184,10 +181,14 @@ class ClientWindowEventHandler : public ui::EventHandler {
// window() is the the target.
return true;
}
return ShouldIgnoreEventType(event.type());
}
bool ShouldIgnoreEventType(EventType type) const {
// WindowTreeClient takes care of sending ET_MOUSE_CAPTURE_CHANGED at the
// right point. The enter events are effectively synthetic, and indirectly
// generated in the client as the result of a move event.
switch (event.type()) {
switch (type) {
case ET_MOUSE_CAPTURE_CHANGED:
case ET_MOUSE_ENTERED:
case ET_POINTER_CAPTURE_CHANGED:
......@@ -199,16 +200,16 @@ class ClientWindowEventHandler : public ui::EventHandler {
return false;
}
private:
// If |event| is a KeyEvent that needs to be handled because a client
// intercepts events, then true is returned and the event is handled.
// Otherwise returns false.
bool HandleInterceptedKeyEvent(Event* event) {
if (!event->IsKeyEvent())
// If |window| identifies an embedding and the owning client intercepts
// events, this forwards to the owner and returns true. Otherwise returns
// false.
bool HandleInterceptedEvent(Event* event) {
if (ShouldIgnoreEventType(event->type()))
return false;
// KeyEvents do not go through through ClientWindowTargeter. As a result
// ClientWindowEventHandler has to check for a client intercepting events.
// KeyEvents, and events when there is capture, do not go through through
// ClientWindowTargeter. As a result ClientWindowEventHandler has to check
// for a client intercepting events.
if (client_window_->DoesOwnerInterceptEvents()) {
client_window_->owning_window_service_client()->SendEventToClient(
window(), *event);
......@@ -218,6 +219,7 @@ class ClientWindowEventHandler : public ui::EventHandler {
return false;
}
private:
ClientWindow* const client_window_;
DISALLOW_COPY_AND_ASSIGN(ClientWindowEventHandler);
......@@ -304,6 +306,9 @@ class TopLevelEventHandler : public ClientWindowEventHandler {
return;
}
if (HandleInterceptedEvent(event))
return;
if (!event->IsLocatedEvent()) {
ClientWindowEventHandler::OnEvent(event);
return;
......
......@@ -697,6 +697,51 @@ TEST(WindowServiceClientTest, EventsGoToCaptureWindow) {
LocatedEventToEventTypeAndLocation(drag_event.event.get()));
}
TEST(WindowServiceClientTest, InterceptEventsOnEmbeddedWindowWithCapture) {
EventRecordingWindowDelegate window_delegate;
WindowServiceTestSetup setup;
aura::Window* window = setup.client_test_helper()->NewWindow();
ASSERT_TRUE(window);
setup.delegate()->set_delegate_for_next_top_level(&window_delegate);
aura::Window* top_level = setup.client_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level);
top_level->AddChild(window);
top_level->Show();
window->Show();
// Create an embedding, and a new window in the embedding.
std::unique_ptr<EmbeddingHelper> embedding_helper =
setup.CreateEmbedding(window, mojom::kEmbedFlagEmbedderInterceptsEvents);
ASSERT_TRUE(embedding_helper);
aura::Window* window_in_child =
embedding_helper->client_test_helper->NewWindow();
ASSERT_TRUE(window_in_child);
window_in_child->Show();
window->AddChild(window_in_child);
EXPECT_TRUE(
embedding_helper->client_test_helper->SetCapture(window_in_child));
// Do an initial move (which generates some additional events) and clear
// everything out.
test::EventGenerator event_generator(setup.root());
event_generator.MoveMouseTo(5, 5);
setup.window_tree_client()->ClearInputEvents();
window_delegate.ClearEvents();
embedding_helper->window_tree_client.ClearInputEvents();
// Move the mouse. Even though the window in the embedding has capture, the
// event should go to the parent client (setup.window_tree_client()), because
// the embedding was created such that the embedder (parent) intercepts the
// events.
event_generator.MoveMouseTo(6, 6);
EXPECT_TRUE(window_delegate.events().empty());
EXPECT_EQ("POINTER_MOVED",
EventToEventType(
setup.window_tree_client()->PopInputEvent().event.get()));
EXPECT_TRUE(setup.window_tree_client()->input_events().empty());
EXPECT_TRUE(embedding_helper->window_tree_client.input_events().empty());
}
TEST(WindowServiceClientTest, PointerDownResetOnCaptureChange) {
WindowServiceTestSetup setup;
aura::Window* window = setup.client_test_helper()->NewWindow();
......
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