Skip to content

Truly independent web browser

LibWeb+LibCompositing: Keep the compositor's zoom through main jumps

Andreas Klingea3a9c8529e1
diff --git a/Libraries/LibCompositing/Types.h b/Libraries/LibCompositing/Types.h
index a19eafbb5dc..5c8d32072bb 100644
--- a/Libraries/LibCompositing/Types.h
+++ b/Libraries/LibCompositing/Types.h
@@ -272,7 +272,8 @@ struct ScrollRequest {
instant_scroll_is_for_user_input = later.instant_scroll_is_for_user_input;
if (later.jump_offset.has_value()) {
jump_offset = later.jump_offset;
- visual_viewport_scale = later.visual_viewport_scale;
+ if (later.visual_viewport_scale.has_value())
+ visual_viewport_scale = later.visual_viewport_scale;
relative_scroll = later.relative_scroll;
relative_scroll_moves_visual_viewport_first = later.relative_scroll_moves_visual_viewport_first;
} else if (later.relative_scroll.has_value()) {
diff --git a/Libraries/LibWeb/CSS/VisualViewport.cpp b/Libraries/LibWeb/CSS/VisualViewport.cpp
index 926b734a261..4367b0aa415 100644
--- a/Libraries/LibWeb/CSS/VisualViewport.cpp
+++ b/Libraries/LibWeb/CSS/VisualViewport.cpp
@@ -208,6 +208,7 @@ void VisualViewport::zoom(CSSPixelPoint position, double scale_delta)
new_offset = { clamp(new_offset.x(), 0.0f, max_x_offset), clamp(new_offset.y(), 0.0f, max_y_offset) };
m_scale = new_scale;
+ m_scale_is_new_to_compositor = true;
auto old_offset = m_offset;
m_offset = (new_offset / m_scale).to_type<CSSPixels>();
if (m_offset != old_offset)
@@ -223,6 +224,13 @@ void VisualViewport::set_scale_zoomed_by_compositor(double scale)
did_change_offset_or_scale();
}
+Optional<double> VisualViewport::take_scale_for_compositor()
+{
+ if (!exchange(m_scale_is_new_to_compositor, false))
+ return {};
+ return m_scale;
+}
+
CSSPixelPoint VisualViewport::map_to_layout_viewport(CSSPixelPoint position) const
{
auto inverse = transform().inverse().value_or({});
@@ -242,6 +250,7 @@ CSSPixelRect VisualViewport::map_from_layout_viewport(CSSPixelRect const& rect)
void VisualViewport::reset()
{
m_scale = 1.0;
+ m_scale_is_new_to_compositor = true;
auto old_offset = m_offset;
m_offset = { 0, 0 };
if (m_offset != old_offset) {
diff --git a/Libraries/LibWeb/CSS/VisualViewport.h b/Libraries/LibWeb/CSS/VisualViewport.h
index 749ddc56e5d..ebc2efa86fb 100644
--- a/Libraries/LibWeb/CSS/VisualViewport.h
+++ b/Libraries/LibWeb/CSS/VisualViewport.h
@@ -52,6 +52,8 @@ public:
[[nodiscard]] Gfx::AffineTransform transform() const;
void zoom(CSSPixelPoint position, double scale_delta);
void set_scale_zoomed_by_compositor(double scale);
+ // The scale, if this thread changed it since the compositor last heard of it.
+ Optional<double> take_scale_for_compositor();
CSSPixelPoint map_to_layout_viewport(CSSPixelPoint) const;
CSSPixelPoint map_from_layout_viewport(CSSPixelPoint) const;
CSSPixelRect map_from_layout_viewport(CSSPixelRect const&) const;
@@ -69,6 +71,7 @@ private:
GC::Ref<DOM::Document> m_document;
CSSPixelPoint m_offset;
double m_scale { 1.0 };
+ bool m_scale_is_new_to_compositor { false };
};
}
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 6291c38d921..6cf05ea5392 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -7277,8 +7277,11 @@ void LocalNavigable::request_scroll_jump(Web::AsyncScrollNodeStableID stable_nod
scroll_request.relative_scroll.clear();
scroll_request.relative_scroll_moves_visual_viewport_first = false;
scroll_request.instant_scroll_is_for_user_input = trigger != ScrollTrigger::Programmatic;
- if (stable_node_id.kind == Web::AsyncScrollNodeKind::VisualViewport)
- scroll_request.visual_viewport_scale = active_document()->visual_viewport()->scale();
+ // NB: The compositor zooms on its own, so the scale this thread knows may be old. Only a change made here goes along.
+ if (stable_node_id.kind == Web::AsyncScrollNodeKind::VisualViewport) {
+ if (auto scale = active_document()->visual_viewport()->take_scale_for_compositor(); scale.has_value())
+ scroll_request.visual_viewport_scale = static_cast<float>(scale.value());
+ }
}
void LocalNavigable::request_smooth_scroll(Web::AsyncScrollNodeStableID stable_node_id, Compositing::RequestedSmoothScroll smooth_scroll)
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-survives-a-script-scroll-with-the-old-scale.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-survives-a-script-scroll-with-the-old-scale.txt
index c0a45a5fbfc..5f430af2baa 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/pinch-survives-a-script-scroll-with-the-old-scale.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-survives-a-script-scroll-with-the-old-scale.txt
@@ -1,2 +1,2 @@
beside the task: compositor scale: 3, main thread scale: 1.5
-after the task: compositor scale: 1.5, main thread scale: 1.5
+after the task: compositor scale: 3, main thread scale: 3