ladybird/Libraries/LibWeb/CSS/VisualViewport.h
Aliaksandr Kalenik 5595efd46b LibWeb: Avoid display list rebuilds for VV changes
Visual viewport scroll and pinch zoom used to invalidate the full
accumulated visual context tree and display list, even though those
changes only modify the root visual viewport transform. That forced a
full display list rerecord before sending updated compositor state.

Patch the reserved visual viewport AVC node in place instead.
VisualViewport marks the tree for compositor update without
invalidating the display list, and Navigable sends the replacement tree
through the new IPC path before updating scroll state.
2026-06-03 02:12:39 +01:00

66 lines
1.8 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/AffineTransform.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/PixelUnits.h>
namespace Web::CSS {
// https://drafts.csswg.org/cssom-view/#visualviewport
class VisualViewport final : public DOM::EventTarget {
WEB_PLATFORM_OBJECT(VisualViewport, DOM::EventTarget);
GC_DECLARE_ALLOCATOR(VisualViewport);
public:
[[nodiscard]] static GC::Ref<VisualViewport> create(DOM::Document&);
virtual ~VisualViewport() override = default;
CSSPixelPoint offset() const { return m_offset; }
[[nodiscard]] double offset_left() const;
[[nodiscard]] double offset_top() const;
[[nodiscard]] double page_left() const;
[[nodiscard]] double page_top() const;
[[nodiscard]] double width() const;
[[nodiscard]] double height() const;
[[nodiscard]] double scale() const;
void set_onresize(WebIDL::CallbackType*);
WebIDL::CallbackType* onresize();
void set_onscroll(WebIDL::CallbackType*);
WebIDL::CallbackType* onscroll();
void set_onscrollend(WebIDL::CallbackType*);
WebIDL::CallbackType* onscrollend();
void scroll_by(CSSPixelPoint delta);
[[nodiscard]] Gfx::AffineTransform transform() const;
void zoom(CSSPixelPoint position, double scale_delta);
CSSPixelPoint map_to_layout_viewport(CSSPixelPoint) const;
void reset();
private:
explicit VisualViewport(DOM::Document&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
void update_accumulated_visual_context();
GC::Ref<DOM::Document> m_document;
CSSPixelPoint m_offset;
double m_scale { 1.0 };
};
}