Skip to content

Truly independent web browser

LibWebView+Compositor: Let only an unzoomed pinch hold back later ones

Andreas Kling83201bdb200e
diff --git a/Libraries/LibWebView/CompositorPresentationClient.cpp b/Libraries/LibWebView/CompositorPresentationClient.cpp
index bea063892ca..050cbf133f9 100644
--- a/Libraries/LibWebView/CompositorPresentationClient.cpp
+++ b/Libraries/LibWebView/CompositorPresentationClient.cpp
@@ -94,10 +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)
+void CompositorPresentationClient::did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool 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);
+ page->did_dispatch_input_event_through_compositor(event_id, performed_default_action);
}
}
diff --git a/Libraries/LibWebView/CompositorPresentationClient.h b/Libraries/LibWebView/CompositorPresentationClient.h
index dd2257edbfd..cdb457def6f 100644
--- a/Libraries/LibWebView/CompositorPresentationClient.h
+++ b/Libraries/LibWebView/CompositorPresentationClient.h
@@ -37,7 +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;
+ virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool performed_default_action) override;
};
}
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index fa098dfbe0b..c2ed7f15ee1 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -1052,17 +1052,17 @@ void ViewImplementation::enqueue_input_event(Web::InputEvent event)
// 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()
{
- bool has_earlier_pinch = false;
+ bool has_earlier_pinch_yet_to_zoom = false;
for (size_t index = 0; index < m_pending_input_events.size(); ++index) {
// Pinches in different processes share the tab's visual viewport. A later pinch must not zoom it before an
- // earlier frame has dispatched its wheel event and, if uncanceled, returned for the zoom.
- if (m_pending_input_events[index].event.has<Web::PinchEvent>()) {
- if (has_earlier_pinch)
- continue;
- has_earlier_pinch = true;
- }
+ // earlier frame has dispatched its wheel event and, if uncanceled, returned for the zoom. A pinch the
+ // compositor zoomed for holds back nothing, so a busy page does not hold back the zoom.
+ if (m_pending_input_events[index].event.has<Web::PinchEvent>() && has_earlier_pinch_yet_to_zoom)
+ continue;
if (!m_pending_input_events[index].sent)
send_input_event(index);
+ if (auto const* pinch_event = m_pending_input_events[index].event.get_pointer<Web::PinchEvent>())
+ has_earlier_pinch_yet_to_zoom = !pinch_event->async_zoom_performed_default_action;
if (m_pending_input_events[index].awaits_compositor_dispatch())
return;
}
@@ -1479,18 +1479,23 @@ void ViewImplementation::did_not_dispatch_input_event_through_compositor(Badge<W
send_queued_input_events();
}
-void ViewImplementation::did_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id, bool async_scroll_performed_default_action)
+void ViewImplementation::did_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id, bool 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())
+ if (!pending.routed_through_compositor)
+ return;
+ if (auto* key_event = pending.event.get_pointer<Web::KeyEvent>())
+ key_event->async_scroll_performed_default_action = performed_default_action;
+ else if (auto* pinch_event = pending.event.get_pointer<Web::PinchEvent>())
+ pinch_event->async_zoom_performed_default_action = performed_default_action;
+ else
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();
}
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 3ec918913d0..521a26b0bb3 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -291,7 +291,7 @@ public:
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 did_dispatch_input_event_through_compositor(Badge<WebContentPage>, u64 event_id, bool 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);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index d24deadaf6e..857fad0ca28 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -549,16 +549,16 @@ 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)
+void WebContentPage::did_dispatch_input_event_through_compositor(u64 event_id, bool performed_default_action)
{
if (displays_tab()) {
- view().did_dispatch_input_event_through_compositor({}, event_id, async_scroll_performed_default_action);
+ view().did_dispatch_input_event_through_compositor({}, event_id, 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);
+ display_page->did_dispatch_input_event_through_compositor(event_id, performed_default_action);
}
}
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 4fa823046ba..ce77fa9074d 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -160,7 +160,7 @@ public:
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_dispatch_input_event_through_compositor(u64 event_id, bool 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 897fc69b20a..d1da78ed003 100644
--- a/Services/Compositor/CompositorPresentationClient.ipc
+++ b/Services/Compositor/CompositorPresentationClient.ipc
@@ -10,5 +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) =|
+ did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool performed_default_action) =|
}
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index dd5f4e406e3..9171535821e 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -1195,6 +1195,7 @@ void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId c
// 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_pinch_event_to_web_content(event);
+ presentation->did_dispatch_input_event(context_id, event.id, event.async_zoom_performed_default_action);
}
Compositing::WheelEventAnswer CompositorState::wheel_event_answer_for(AppliedWheelStep const& applied_step, Optional<Web::WheelGestureMark> wheel_gesture_mark)
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 57e037fc244..ca98ddd806d 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -50,7 +50,7 @@ public:
// 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;
+ virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool performed_default_action) = 0;
};
class CompositorStateWebContentClient {
diff --git a/Services/Compositor/ConnectionFromPresentation.cpp b/Services/Compositor/ConnectionFromPresentation.cpp
index 9c8df3577d6..2a5f4481b65 100644
--- a/Services/Compositor/ConnectionFromPresentation.cpp
+++ b/Services/Compositor/ConnectionFromPresentation.cpp
@@ -123,9 +123,9 @@ void ConnectionFromPresentation::did_not_dispatch_input_event(Web::CompositorCon
async_did_not_dispatch_input_event(context_id, event_id);
}
-void ConnectionFromPresentation::did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool async_scroll_performed_default_action)
+void ConnectionFromPresentation::did_dispatch_input_event(Web::CompositorContextId context_id, u64 event_id, bool performed_default_action)
{
- async_did_dispatch_input_event(context_id, event_id, async_scroll_performed_default_action);
+ async_did_dispatch_input_event(context_id, event_id, performed_default_action);
}
void ConnectionFromPresentation::handle_and_dispatch_key_event(Web::CompositorContextId context_id, Web::KeyEvent event, bool allow_keyboard_scroll)
diff --git a/Services/Compositor/ConnectionFromPresentation.h b/Services/Compositor/ConnectionFromPresentation.h
index b1eb255ac22..952241211eb 100644
--- a/Services/Compositor/ConnectionFromPresentation.h
+++ b/Services/Compositor/ConnectionFromPresentation.h
@@ -36,7 +36,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;
+ virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool performed_default_action) override;
virtual void handle_and_dispatch_key_event(Web::CompositorContextId, Web::KeyEvent, bool allow_keyboard_scroll) override;
virtual void handle_and_dispatch_pinch_event(Web::CompositorContextId, Web::PinchEvent) override;
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-zooms-beside-a-busy-task.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-zooms-beside-a-busy-task.txt
index ea933c81864..0b4779e203d 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/pinch-zooms-beside-a-busy-task.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-zooms-beside-a-busy-task.txt
@@ -1,3 +1,3 @@
-compositor scale beside the task: 1.5
+compositor scale beside the task: 3.375
main thread scale beside the task: 1
main thread scale after the task: 3.375