Skip to content

Truly independent web browser

Compositor: Make key input from the UI asynchronous

Andreas Kling41cd77e81aa6
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 18074e11345..0cf1ac26346 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -1479,20 +1479,14 @@ void Application::update_compositor_context_visibility(Web::CompositorContextId
m_compositor_client->async_set_context_visibility(context_id, context_visibility);
}
-bool Application::handle_key_event_in_compositor(Web::CompositorContextId context_id, Web::KeyEvent const& event)
+bool Application::handle_and_dispatch_key_event_in_compositor(Web::CompositorContextId context_id, Web::KeyEvent const& event, bool allow_keyboard_scroll)
{
if (!can_send_compositor_process_ipc(m_compositor_presentation_client))
return false;
- auto result = m_compositor_presentation_client->try_handle_key_event(context_id, event.clone_without_browser_data());
- return !result.is_error() && result.release_value();
-}
+ VERIFY(m_compositor_presentation_client);
-bool Application::dispatch_key_event_to_web_content(Web::CompositorContextId context_id, Web::KeyEvent const& event)
-{
- if (!can_send_compositor_process_ipc(m_compositor_presentation_client))
- return false;
- auto result = m_compositor_presentation_client->try_dispatch_key_event_to_web_content(context_id, event.clone_without_browser_data());
- return !result.is_error() && result.release_value();
+ m_compositor_presentation_client->async_handle_and_dispatch_key_event(context_id, event.clone_without_browser_data(), allow_keyboard_scroll);
+ return true;
}
void Application::handle_pinch_event_in_compositor(Web::CompositorContextId context_id, Web::PinchEvent const& event)
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 0322274cdd1..f95e5fc98bb 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -253,8 +253,7 @@ public:
void update_compositor_ui_overlays(Web::CompositorContextId, Compositing::UIOverlays const&);
void update_compositor_display_metadata(Web::CompositorContextId, Optional<u64> display_id, double refresh_rate);
void update_compositor_context_visibility(Web::CompositorContextId, Web::HTML::VisibilityState);
- bool handle_key_event_in_compositor(Web::CompositorContextId, Web::KeyEvent const&);
- bool dispatch_key_event_to_web_content(Web::CompositorContextId, Web::KeyEvent const&);
+ bool handle_and_dispatch_key_event_in_compositor(Web::CompositorContextId, Web::KeyEvent const&, bool allow_keyboard_scroll);
void handle_pinch_event_in_compositor(Web::CompositorContextId, Web::PinchEvent const&);
bool handle_and_dispatch_mouse_event_in_compositor(Web::CompositorContextId, Web::MouseEvent const&);
void notify_compositor_presented_bitmap_ready_to_paint(Web::CompositorContextId, i32 bitmap_id);
diff --git a/Libraries/LibWebView/CompositorPresentationClient.cpp b/Libraries/LibWebView/CompositorPresentationClient.cpp
index 82796fb46f9..bea063892ca 100644
--- a/Libraries/LibWebView/CompositorPresentationClient.cpp
+++ b/Libraries/LibWebView/CompositorPresentationClient.cpp
@@ -94,4 +94,10 @@ void CompositorPresentationClient::did_not_dispatch_input_event(Web::CompositorC
page->did_not_dispatch_input_event_through_compositor(event_id);
}
+void CompositorPresentationClient::did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool async_scroll_performed_default_action)
+{
+ if (auto* page = page_for_compositor_context_id(context_id))
+ page->did_dispatch_input_event_through_compositor(event_id, async_scroll_performed_default_action);
+}
+
}
diff --git a/Libraries/LibWebView/CompositorPresentationClient.h b/Libraries/LibWebView/CompositorPresentationClient.h
index e5619204fc8..dd2257edbfd 100644
--- a/Libraries/LibWebView/CompositorPresentationClient.h
+++ b/Libraries/LibWebView/CompositorPresentationClient.h
@@ -37,6 +37,7 @@ private:
virtual void did_present_frame(Web::CompositorContextId, Gfx::IntRect content_rect, Gfx::IntRect damage_rect, i32 bitmap_id, double device_pixel_ratio) override;
virtual void did_consume_input_event(Web::CompositorContextId, u64 event_id) override;
virtual void did_not_dispatch_input_event(Web::CompositorContextId, u64 event_id) override;
+ virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool async_scroll_performed_default_action) override;
};
}
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 8ae6a713bcd..719e698915a 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -813,23 +813,6 @@ void ViewImplementation::enqueue_input_event(Web::InputEvent event)
mouse_event->wheel_tick_120ths_y /= zoom_level();
}
- if (key_event && !key_event->native_editing_binding_resolved && Web::is_keyboard_scroll_key(key_event->key, Web::UIEvents::Mod_None)) {
- bool preceding_input_may_change_target = false;
- for (auto const& pending : m_pending_input_events) {
- auto const* key = pending.event.get_pointer<Web::KeyEvent>();
- if (!key || key->type != Web::KeyEvent::Type::KeyDown || !key->async_scroll_performed_default_action)
- preceding_input_may_change_target = true;
- }
- // Always deliver key release to the compositor, even if it could no longer accept a new scroll. A focused
- // navigable another page hosts scrolls there.
- if (&focused_navigable_host() == &page()
- && (key_event->type == Web::KeyEvent::Type::KeyUp
- || (m_has_usable_bitmap && !preceding_input_may_change_target))) {
- auto handled = page().handle_key_event_in_compositor(*key_event);
- key_event->async_scroll_performed_default_action = handled && key_event->type == Web::KeyEvent::Type::KeyDown;
- }
- }
-
// Send the next event over to the WebContent to be handled by JS. We'll later get a message to say whether JS
// prevented the default event behavior, at which point we either discard or handle that event, and then try to
// process the next one.
@@ -845,33 +828,73 @@ void ViewImplementation::enqueue_input_event(Web::InputEvent event)
});
m_inputs_to_open_links_in_new_tabs.append({ Web::input_event_id(pending.event), now });
}
+ // A focused navigable another page hosts takes key events directly.
+ if (pending.event.has<Web::KeyEvent>())
+ pending.endpoint = focused_navigable_host();
+ send_queued_input_events();
+}
+
+// Input waits while the compositor decides whether it forwards a key event, so a key it hands back is not overtaken.
+void ViewImplementation::send_queued_input_events()
+{
+ for (size_t index = 0; index < m_pending_input_events.size(); ++index) {
+ if (!m_pending_input_events[index].sent)
+ send_input_event(index);
+ if (m_pending_input_events[index].awaits_compositor_dispatch())
+ return;
+ }
+}
+
+// A key press may scroll in the compositor only while no earlier input the pages have yet to handle can change its
+// target. Key release always reaches the compositor's keyboard scrolling, even if it could no longer accept a new
+// scroll.
+bool ViewImplementation::may_scroll_for_key_event_in_compositor(size_t index) const
+{
+ auto const& key_event = m_pending_input_events[index].event.get<Web::KeyEvent>();
+ if (key_event.native_editing_binding_resolved || !Web::is_keyboard_scroll_key(key_event.key, Web::UIEvents::Mod_None))
+ return false;
+ if (key_event.type == Web::KeyEvent::Type::KeyUp)
+ return true;
+ if (!m_has_usable_bitmap)
+ return false;
+ for (size_t preceding = 0; preceding < index; ++preceding) {
+ auto const* key = m_pending_input_events[preceding].event.get_pointer<Web::KeyEvent>();
+ if (!key || key->type != Web::KeyEvent::Type::KeyDown || !key->async_scroll_performed_default_action)
+ return false;
+ }
+ return true;
+}
+
+void ViewImplementation::send_input_event(size_t index)
+{
+ auto& pending = m_pending_input_events[index];
+ pending.sent = true;
pending.event.visit(
[&](Web::KeyEvent const& event) {
- auto& host = focused_navigable_host();
- if (&host == &page()) {
- page().dispatch_key_event_to_web_content(event);
- } else {
- pending.endpoint = host;
- host.async_key_event(event.clone_without_browser_data());
- }
+ // The compositor scrolls for the event when it may, then forwards the event to WebContent behind the scroll
+ // updates that produced, or hands it back for direct dispatch.
+ if (pending.endpoint == page() && page().handle_and_dispatch_key_event_in_compositor(event, may_scroll_for_key_event_in_compositor(index)))
+ pending.routed_through_compositor = true;
+ else
+ pending.endpoint->async_key_event(event.clone_without_browser_data());
},
[&](Web::MouseEvent const& event) {
// The compositor scrolls or drags a scrollbar for the event when it can, then forwards the event to
// WebContent behind the scroll updates that produced, consumes it, or hands it back for direct dispatch.
- if (page().handle_and_dispatch_mouse_event_in_compositor(event))
+ if (pending.endpoint->handle_and_dispatch_mouse_event_in_compositor(event))
pending.routed_through_compositor = true;
else
- page().async_mouse_event(event.clone_without_browser_data());
+ pending.endpoint->async_mouse_event(event.clone_without_browser_data());
},
- [this](Web::DragEvent& event) {
+ [&](Web::DragEvent& event) {
auto cloned_event = event.clone_without_browser_data();
cloned_event.files = move(event.files);
- page().async_drag_event(cloned_event);
+ pending.endpoint->async_drag_event(cloned_event);
},
- [this](Web::PinchEvent const& event) {
- page().handle_pinch_event_in_compositor(event);
- page().async_pinch_event(event);
+ [&](Web::PinchEvent const& event) {
+ pending.endpoint->handle_pinch_event_in_compositor(event);
+ pending.endpoint->async_pinch_event(event);
});
}
@@ -1048,6 +1071,7 @@ void ViewImplementation::did_finish_handling_input_event(Badge<WebContentPage>,
return;
auto pending = m_pending_input_events.take(*index);
auto event = move(pending.event);
+ send_queued_input_events();
// The renderer's activation counts from when it handled the event, so the activation the event gives does too. An
// event the page dropped gives none, and opens no link.
@@ -1153,10 +1177,11 @@ bool ViewImplementation::take_input_to_open_link_in_new_tab(Badge<WebContentPage
return true;
}
-void ViewImplementation::did_lose_input_event_endpoint(Badge<WebContentClient>, WebContentPage& page)
+void ViewImplementation::did_lose_input_event_endpoint(Badge<WebContentPage>, WebContentPage& page)
{
- // Nothing will finish the events the lost page held, and a pending event holds back compositor input.
+ // Nothing will finish the events the closed page held, and a pending event holds back compositor input.
m_pending_input_events.remove_all_matching([&](auto const& pending) { return pending.endpoint == page; });
+ send_queued_input_events();
}
void ViewImplementation::did_consume_input_event_in_compositor(Badge<WebContentPage>, u64 event_id)
@@ -1165,6 +1190,7 @@ void ViewImplementation::did_consume_input_event_in_compositor(Badge<WebContentP
// no input to open a link with.
m_pending_input_events.remove_first_matching([&](auto const& pending) { return Web::input_event_id(pending.event) == event_id; });
m_inputs_to_open_links_in_new_tabs.remove_all_matching([&](auto const& input) { return input.event_id == event_id; });
+ send_queued_input_events();
}
void ViewImplementation::did_not_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id)
@@ -1174,14 +1200,35 @@ void ViewImplementation::did_not_dispatch_input_event_through_compositor(Badge<W
return;
auto& pending = m_pending_input_events[*index];
+ if (!pending.routed_through_compositor)
+ return;
pending.routed_through_compositor = false;
pending.event.visit(
+ [&](Web::KeyEvent const& event) {
+ pending.endpoint->async_key_event(event.clone_without_browser_data());
+ },
[&](Web::MouseEvent const& event) {
pending.endpoint->async_mouse_event(event.clone_without_browser_data());
},
[](auto const&) {
VERIFY_NOT_REACHED();
});
+ send_queued_input_events();
+}
+
+void ViewImplementation::did_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id, bool async_scroll_performed_default_action)
+{
+ auto index = m_pending_input_events.find_first_index_if([&](auto const& pending) { return Web::input_event_id(pending.event) == event_id; });
+ if (!index.has_value())
+ return;
+
+ auto& pending = m_pending_input_events[*index];
+ if (!pending.awaits_compositor_dispatch())
+ return;
+ // WebContent finishes the event from here on, as it does an event the view sends it directly.
+ pending.routed_through_compositor = false;
+ pending.event.get<Web::KeyEvent>().async_scroll_performed_default_action = async_scroll_performed_default_action;
+ send_queued_input_events();
}
void ViewImplementation::discard_input_events_routed_through_lost_compositor(Badge<Application>)
@@ -1189,6 +1236,7 @@ void ViewImplementation::discard_input_events_routed_through_lost_compositor(Bad
// The compositor may have forwarded some of these before it died, and WebContent does not de-duplicate event ids,
// so sending them again could run an event twice. Acknowledgements that still arrive for them are ignored.
m_pending_input_events.remove_all_matching([](auto const& pending) { return pending.routed_through_compositor; });
+ send_queued_input_events();
}
void ViewImplementation::set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme)
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 85a94a21403..7d8b3262290 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -232,9 +232,10 @@ public:
void consume_user_activation_of_input_handled_by(Badge<WebContentPage>, WebContentPage const&);
// Opening a link in a new tab takes one key or mouse press the view delivered.
bool take_input_to_open_link_in_new_tab(Badge<WebContentPage>);
- void did_lose_input_event_endpoint(Badge<WebContentClient>, WebContentPage&);
+ void did_lose_input_event_endpoint(Badge<WebContentPage>, WebContentPage&);
void did_consume_input_event_in_compositor(Badge<WebContentPage>, u64 event_id);
void did_not_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id);
+ void did_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id, bool async_scroll_performed_default_action);
void discard_input_events_routed_through_lost_compositor(Badge<Application>);
size_t pending_input_event_count_for_testing() const { return m_pending_input_events.size(); }
void handle_external_url(Badge<WebContentPage>, URL::URL, URL::Origin, bool has_transient_activation);
@@ -876,14 +877,24 @@ protected:
// navigable. A lost page never finishes the events it held.
NonnullRefPtr<WebContentPage> endpoint;
+ // Unset while the event waits for the compositor to decide where an earlier key event goes.
+ bool sent { false };
+
// Set while the compositor decides whether it consumes the event, forwards it or hands it back. A compositor
// that dies forwards none of the events still marked this way.
bool routed_through_compositor { false };
+ // A key event stays routed through the compositor until it forwards the event or hands it back. Later input
+ // waits until then.
+ bool awaits_compositor_dispatch() const { return routed_through_compositor && event.has<Web::KeyEvent>(); }
+
// When the view delivered an event that gives user activation, until something consumes that activation.
Optional<MonotonicTime> user_activation_time {};
};
Vector<PendingInputEvent> m_pending_input_events;
+ void send_queued_input_events();
+ void send_input_event(size_t index);
+ bool may_scroll_for_key_event_in_compositor(size_t index) const;
Optional<size_t> index_of_input_in_flight_giving_user_activation_to(WebContentPage const&) const;
// The key and mouse presses the view delivered that have yet to open a link in a new tab.
diff --git a/Libraries/LibWebView/WebContentClient.cpp b/Libraries/LibWebView/WebContentClient.cpp
index 0afcf644598..b030a6cdd76 100644
--- a/Libraries/LibWebView/WebContentClient.cpp
+++ b/Libraries/LibWebView/WebContentClient.cpp
@@ -530,12 +530,8 @@ void WebContentClient::did_lose_process()
destroy_all_compositor_contexts();
- for (auto const& lost : lost_pages) {
- // The view displaying the tab waits for the events it handed down to this page.
- if (!lost.view_id.has_value())
- lost.page->view().did_lose_input_event_endpoint({}, *lost.page);
+ for (auto const& lost : lost_pages)
lost.page->traversable().did_lose_page(*lost.page, WebContentProcessLost::Yes);
- }
for (auto const& lost : lost_pages)
lost.page->traversable().remove_page(*lost.page);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index c6b6dd86115..1e2745c7af3 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -482,15 +482,11 @@ Web::CompositorContextId WebContentPage::compositor_context_id()
return client().compositor_context_id_for_page(*this);
}
-bool WebContentPage::handle_key_event_in_compositor(Web::KeyEvent const& event)
+bool WebContentPage::handle_and_dispatch_key_event_in_compositor(Web::KeyEvent const& event, bool allow_keyboard_scroll)
{
- return Application::the().handle_key_event_in_compositor(compositor_context_id(), event);
-}
-
-void WebContentPage::dispatch_key_event_to_web_content(Web::KeyEvent const& event)
-{
- if (!Application::the().dispatch_key_event_to_web_content(compositor_context_id(), event))
- async_key_event(event.clone_without_browser_data());
+ auto posted = Application::the().handle_and_dispatch_key_event_in_compositor(compositor_context_id(), event, allow_keyboard_scroll);
+ dbgln_if(COMPOSITOR_DEBUG, "[Compositor] UI posted key event {} for page {} to the compositor: {}", event.id, m_id, posted);
+ return posted;
}
void WebContentPage::handle_pinch_event_in_compositor(Web::PinchEvent const& event)
@@ -536,6 +532,19 @@ void WebContentPage::did_not_dispatch_input_event_through_compositor(u64 event_i
}
}
+void WebContentPage::did_dispatch_input_event_through_compositor(u64 event_id, bool async_scroll_performed_default_action)
+{
+ if (displays_tab()) {
+ view().did_dispatch_input_event_through_compositor({}, event_id, async_scroll_performed_default_action);
+ return;
+ }
+
+ if (auto display_page = traversable().display_page(); display_page) {
+ if (display_page->is_open() && display_page.ptr() != this)
+ display_page->did_dispatch_input_event_through_compositor(event_id, async_scroll_performed_default_action);
+ }
+}
+
void WebContentPage::did_present_bitmap(Gfx::IntRect content_rect, Gfx::IntRect damage_rect, i32 bitmap_id, double device_pixel_ratio)
{
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] UI compositor IPC did_paint for page {} bitmap {} rect={}x{} at {},{}",
@@ -621,6 +630,11 @@ void WebContentPage::close()
{
PictureInPictureManager::the().close_window(*this);
m_is_open = false;
+ // NB: Nothing finishes the input this page held, including a page discarded while its process hosts other pages.
+ if (m_traversable) {
+ if (auto view = m_traversable->view(); view.has_value())
+ view->did_lose_input_event_endpoint({}, *this);
+ }
m_needs_beforeunload_check = true;
m_history_recorded_url_for_current_load.clear();
if (m_client)
@@ -1638,6 +1652,8 @@ void WebContentPage::did_request_key_event_for_testing(Web::KeyEvent event)
client().did_misbehave("did_request_key_event_for_testing"sv, "not driven by WebDriver or a test"sv);
return;
}
+ // Only the compositor sets this, on its way to WebContent.
+ event.async_scroll_performed_default_action = false;
view().enqueue_input_event(move(event));
}
@@ -2681,6 +2697,9 @@ void WebContentPage::did_request_webdriver_mouse_event(u64 request_id, Web::HTML
event.position.translate_by(offset);
event.screen_position.translate_by(offset);
}
+ // Only the compositor sets these, on its way to WebContent.
+ event.async_scroll_performed_default_action = false;
+ event.scrollbar_dragged_by_compositor = {};
view().enqueue_webdriver_mouse_event({}, move(event), move(on_handled));
}
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index c5dbe1d0a79..c89349ebe68 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -126,13 +126,14 @@ public:
void discard();
Web::CompositorContextId compositor_context_id();
- bool handle_key_event_in_compositor(Web::KeyEvent const&);
- void dispatch_key_event_to_web_content(Web::KeyEvent const&);
+ // Returns whether the event was posted; a page without a compositor sends it to WebContent itself.
+ bool handle_and_dispatch_key_event_in_compositor(Web::KeyEvent const&, bool allow_keyboard_scroll);
void handle_pinch_event_in_compositor(Web::PinchEvent const&);
// Returns whether the event was posted; a page without a compositor sends it to WebContent itself.
bool handle_and_dispatch_mouse_event_in_compositor(Web::MouseEvent const&);
void did_consume_input_event_in_compositor(u64 event_id);
void did_not_dispatch_input_event_through_compositor(u64 event_id);
+ void did_dispatch_input_event_through_compositor(u64 event_id, bool async_scroll_performed_default_action);
void did_present_bitmap(Gfx::IntRect content_rect, Gfx::IntRect damage_rect, i32 bitmap_id, double device_pixel_ratio);
void did_present_backing_stores(Vector<i32> bitmap_ids, Vector<Gfx::SharedImage> backing_stores);
void did_add_backing_stores(Vector<i32> bitmap_ids, Vector<Gfx::SharedImage> backing_stores);
diff --git a/Services/Compositor/CompositorPresentationClient.ipc b/Services/Compositor/CompositorPresentationClient.ipc
index 725446c0d6c..897fc69b20a 100644
--- a/Services/Compositor/CompositorPresentationClient.ipc
+++ b/Services/Compositor/CompositorPresentationClient.ipc
@@ -10,4 +10,5 @@ endpoint CompositorPresentationClient
did_present_frame(Web::CompositorContextId context_id, Gfx::IntRect content_rect, Gfx::IntRect damage_rect, i32 bitmap_id, double device_pixel_ratio) =|
did_consume_input_event(Web::CompositorContextId context_id, u64 event_id) =|
did_not_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id) =|
+ did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool async_scroll_performed_default_action) =|
}
diff --git a/Services/Compositor/CompositorPresentationServer.ipc b/Services/Compositor/CompositorPresentationServer.ipc
index 0754b16cf31..0b208e2e64e 100644
--- a/Services/Compositor/CompositorPresentationServer.ipc
+++ b/Services/Compositor/CompositorPresentationServer.ipc
@@ -3,8 +3,7 @@
endpoint CompositorPresentationServer
{
- handle_key_event(Web::CompositorContextId context_id, Web::KeyEvent event) => (bool handled)
- dispatch_key_event_to_web_content(Web::CompositorContextId context_id, Web::KeyEvent event) => (bool dispatched)
+ handle_and_dispatch_key_event(Web::CompositorContextId context_id, Web::KeyEvent event, bool allow_keyboard_scroll) =|
handle_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event) =|
handle_and_dispatch_mouse_event(Web::CompositorContextId context_id, Web::MouseEvent event) =|
presented_bitmap_ready_to_paint(Web::CompositorContextId context_id, i32 bitmap_id) =|
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 6c2c8a2c99a..9e507e84d6a 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -585,24 +585,28 @@ void CompositorState::invalidate_keyboard_scroll_state(Web::CompositorContextId
context->invalidate_keyboard_scroll_state(generation);
}
-bool CompositorState::handle_key_event(Web::CompositorContextId context_id, Web::KeyEvent const& event)
+void CompositorState::handle_and_dispatch_key_event(Web::CompositorContextId context_id, Web::KeyEvent event, bool allow_keyboard_scroll)
{
+ // NB: The presentation connection only passes on input for the contexts bound to it.
+ auto* presentation = presentation_for_context(context_id);
+ VERIFY(presentation);
auto* context = context_if_present(context_id);
- if (!context)
- return false;
- if (event.type == Web::KeyEvent::Type::KeyDown && Web::is_keyboard_scroll_key(event.key, Web::UIEvents::Mod_None))
- dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());
- return apply_context_update_result(context_id, *context, context->handle_key_event(event));
-}
+ if (!context || !context->can_dispatch_input_to_web_content()) {
+ presentation->did_not_dispatch_input_event(context_id, event.id);
+ return;
+ }
-bool CompositorState::dispatch_key_event_to_web_content(Web::CompositorContextId context_id, Web::KeyEvent const& event)
-{
- auto* context = context_if_present(context_id);
- if (!context)
- return false;
+ if (allow_keyboard_scroll) {
+ if (event.type == Web::KeyEvent::Type::KeyDown && Web::is_keyboard_scroll_key(event.key, Web::UIEvents::Mod_None))
+ dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());
+ auto handled = apply_context_update_result(context_id, *context, context->handle_key_event(event));
+ event.async_scroll_performed_default_action = handled && event.type == Web::KeyEvent::Type::KeyDown;
+ }
+
+ // The scroll updates the event produced reach WebContent ahead of the event itself on the same connection.
publish_pending_async_scroll_updates(context_id, *context);
context->dispatch_key_event_to_web_content(event);
- return true;
+ presentation->did_dispatch_input_event(context_id, event.id, event.async_scroll_performed_default_action);
}
void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId context_id, Web::MouseEvent event)
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 84a09658195..64c5cb6d380 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -49,6 +49,8 @@ public:
virtual void did_consume_input_event(Web::CompositorContextId, u64 event_id) = 0;
// No context could take the event; the UI sends it to WebContent itself.
virtual void did_not_dispatch_input_event(Web::CompositorContextId, u64 event_id) = 0;
+ // The compositor forwarded the key event to WebContent, after performing its default action by scrolling if it says so.
+ virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool async_scroll_performed_default_action) = 0;
};
class CompositorStateWebContentClient {
@@ -119,8 +121,7 @@ public:
void on_video_sink_ready(CompositorStateWebContentClient&, Media::VideoSinkHandle, NonnullRefPtr<Media::DisplayingVideoSink> const&);
void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);
void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);
- bool handle_key_event(Web::CompositorContextId, Web::KeyEvent const&);
- bool dispatch_key_event_to_web_content(Web::CompositorContextId, Web::KeyEvent const&);
+ void handle_and_dispatch_key_event(Web::CompositorContextId, Web::KeyEvent, bool allow_keyboard_scroll);
void handle_and_dispatch_mouse_event(Web::CompositorContextId, Web::MouseEvent);
void handle_pinch_event(Web::CompositorContextId, Web::PinchEvent const&);
Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id);
diff --git a/Services/Compositor/ConnectionFromPresentation.cpp b/Services/Compositor/ConnectionFromPresentation.cpp
index 88cf15b18ed..ae416959b3d 100644
--- a/Services/Compositor/ConnectionFromPresentation.cpp
+++ b/Services/Compositor/ConnectionFromPresentation.cpp
@@ -35,7 +35,9 @@ static bool is_valid_key_event(Web::KeyEvent const& event)
{
return is_valid_key_code(event.key)
&& is_valid_modifiers(event.modifiers)
- && event.code_point <= 0x10ffff;
+ && event.code_point <= 0x10ffff
+ // Only the compositor sets this, on its way to WebContent.
+ && !event.async_scroll_performed_default_action;
}
static bool is_valid_mouse_event(Web::MouseEvent const& event)
@@ -118,26 +120,22 @@ void ConnectionFromPresentation::did_not_dispatch_input_event(Web::CompositorCon
async_did_not_dispatch_input_event(context_id, event_id);
}
-Messages::CompositorPresentationServer::HandleKeyEventResponse ConnectionFromPresentation::handle_key_event(Web::CompositorContextId context_id, Web::KeyEvent event)
+void ConnectionFromPresentation::did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool async_scroll_performed_default_action)
{
- if (!is_valid_key_event(event)) {
- did_misbehave("Invalid key event");
- return false;
- }
- if (!is_bound_to(context_id))
- return false;
- return m_compositor_state->handle_key_event(context_id, event);
+ async_did_dispatch_input_event(context_id, event_id, async_scroll_performed_default_action);
}
-Messages::CompositorPresentationServer::DispatchKeyEventToWebContentResponse ConnectionFromPresentation::dispatch_key_event_to_web_content(Web::CompositorContextId context_id, Web::KeyEvent event)
+void ConnectionFromPresentation::handle_and_dispatch_key_event(Web::CompositorContextId context_id, Web::KeyEvent event, bool allow_keyboard_scroll)
{
if (!is_valid_key_event(event)) {
did_misbehave("Invalid key event");
- return false;
+ return;
}
- if (!is_bound_to(context_id))
- return false;
- return m_compositor_state->dispatch_key_event_to_web_content(context_id, event);
+ if (!is_bound_to(context_id)) {
+ did_not_dispatch_input_event(context_id, event.id);
+ return;
+ }
+ m_compositor_state->handle_and_dispatch_key_event(context_id, move(event), allow_keyboard_scroll);
}
void ConnectionFromPresentation::handle_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event)
diff --git a/Services/Compositor/ConnectionFromPresentation.h b/Services/Compositor/ConnectionFromPresentation.h
index 6d56a3f6033..1a12c2c2b90 100644
--- a/Services/Compositor/ConnectionFromPresentation.h
+++ b/Services/Compositor/ConnectionFromPresentation.h
@@ -36,9 +36,9 @@ private:
virtual void did_present_frame(Web::CompositorContextId, Gfx::IntRect content_rect, Gfx::IntRect damage_rect, i32 bitmap_id, double device_pixel_ratio) override;
virtual void did_consume_input_event(Web::CompositorContextId, u64 event_id) override;
virtual void did_not_dispatch_input_event(Web::CompositorContextId, u64 event_id) override;
+ virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool async_scroll_performed_default_action) override;
- virtual Messages::CompositorPresentationServer::HandleKeyEventResponse handle_key_event(Web::CompositorContextId, Web::KeyEvent) override;
- virtual Messages::CompositorPresentationServer::DispatchKeyEventToWebContentResponse dispatch_key_event_to_web_content(Web::CompositorContextId, Web::KeyEvent) override;
+ virtual void handle_and_dispatch_key_event(Web::CompositorContextId, Web::KeyEvent, bool allow_keyboard_scroll) override;
virtual void handle_pinch_event(Web::CompositorContextId, Web::PinchEvent) override;
virtual void handle_and_dispatch_mouse_event(Web::CompositorContextId, Web::MouseEvent) override;
virtual void presented_bitmap_ready_to_paint(Web::CompositorContextId, i32 bitmap_id) override;