1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:48:13 +00:00

LibWeb: Make Document::paintable() return a ViewportPaintable

This commit is contained in:
Andreas Kling 2023-08-19 09:29:04 +02:00
parent 8bb275f2ea
commit 25375bf1d5
10 changed files with 34 additions and 11 deletions

View file

@ -835,9 +835,9 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
return IdentifierStyleValue::create(ValueID::None);
// The transform matrix is held by the StackingContext, so we need to make sure we have one first.
auto const* viewport = layout_node.document().paintable_box();
auto const* viewport = layout_node.document().paintable();
VERIFY(viewport);
const_cast<Painting::ViewportPaintable&>(verify_cast<Painting::ViewportPaintable>(*viewport)).build_stacking_context_tree_if_needed();
const_cast<Painting::ViewportPaintable&>(*viewport).build_stacking_context_tree_if_needed();
VERIFY(layout_node.paintable());
auto const& paintable_box = verify_cast<Painting::PaintableBox const>(layout_node.paintable());

View file

@ -87,6 +87,7 @@
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/ViewportPaintable.h>
#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGTitleElement.h>
@ -3396,4 +3397,14 @@ void Document::shared_declarative_refresh_steps(StringView input, JS::GCPtr<HTML
}
}
Painting::ViewportPaintable const* Document::paintable() const
{
return static_cast<Painting::ViewportPaintable const*>(Node::paintable());
}
Painting::ViewportPaintable* Document::paintable()
{
return static_cast<Painting::ViewportPaintable*>(Node::paintable());
}
}

View file

@ -210,6 +210,9 @@ public:
Layout::Viewport const* layout_node() const;
Layout::Viewport* layout_node();
Painting::ViewportPaintable const* paintable() const;
Painting::ViewportPaintable* paintable();
void schedule_style_update();
void schedule_layout_update();

View file

@ -1445,6 +1445,13 @@ Painting::Paintable const* Node::paintable() const
return layout_node()->paintable();
}
Painting::Paintable* Node::paintable()
{
if (!layout_node())
return nullptr;
return layout_node()->paintable();
}
Painting::PaintableBox const* Node::paintable_box() const
{
if (!layout_node())

View file

@ -185,6 +185,7 @@ public:
Painting::PaintableBox const* paintable_box() const;
Painting::PaintableBox* paintable_box();
Painting::Paintable const* paintable() const;
Painting::Paintable* paintable();
void set_layout_node(Badge<Layout::Node>, JS::NonnullGCPtr<Layout::Node>);
void detach_layout_node(Badge<Layout::TreeBuilder>);

View file

@ -521,6 +521,7 @@ class PaintableWithLines;
class StackingContext;
class TextPaintable;
class VideoPaintable;
class ViewportPaintable;
enum class PaintPhase;

View file

@ -44,7 +44,7 @@ void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase pha
auto* hosted_document = layout_box().dom_node().content_document_without_origin_check();
if (!hosted_document)
return;
auto* hosted_paint_tree = hosted_document->paintable_box();
auto* hosted_paint_tree = hosted_document->paintable();
if (!hosted_paint_tree)
return;
@ -57,7 +57,7 @@ void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase pha
context.painter().translate(absolute_device_rect.x().value(), absolute_device_rect.y().value());
context.set_device_viewport_rect({ {}, context.enclosing_device_size(layout_box().dom_node().nested_browsing_context()->size()) });
const_cast<ViewportPaintable&>(verify_cast<ViewportPaintable>(*hosted_paint_tree)).paint_all_phases(context);
const_cast<ViewportPaintable*>(hosted_paint_tree)->paint_all_phases(context);
context.set_device_viewport_rect(old_viewport_rect);
context.painter().restore();

View file

@ -100,7 +100,7 @@ void SVGDecodedImageData::render(Gfx::IntSize size) const
Gfx::Painter painter(*m_bitmap);
PaintContext context(painter, m_page_client->palette(), m_page_client->device_pixels_per_css_pixel());
verify_cast<Painting::ViewportPaintable>(*m_document->paintable_box()).paint_all_phases(context);
m_document->paintable()->paint_all_phases(context);
}
RefPtr<Gfx::Bitmap const> SVGDecodedImageData::bitmap(size_t, Gfx::IntSize size) const

View file

@ -31,8 +31,8 @@
#include <LibWeb/Loader/ContentFilter.h>
#include <LibWeb/Loader/ProxyMappings.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/StackingContext.h>
#include <LibWeb/Painting/ViewportPaintable.h>
#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <WebContent/ConnectionFromClient.h>

View file

@ -122,8 +122,10 @@ void PageHost::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& targ
Gfx::Painter painter(target);
Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type<int>() };
if (auto* document = page().top_level_browsing_context().active_document())
auto document = page().top_level_browsing_context().active_document();
if (document) {
document->update_layout();
}
auto background_color = this->background_color();
@ -131,16 +133,14 @@ void PageHost::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& targ
painter.clear_rect(bitmap_rect, palette().base());
painter.fill_rect(bitmap_rect, background_color);
auto* layout_root = this->layout_root();
if (!layout_root) {
if (!document->paintable())
return;
}
Web::PaintContext context(painter, palette(), device_pixels_per_css_pixel());
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
context.set_device_viewport_rect(content_rect);
context.set_has_focus(m_has_focus);
verify_cast<Web::Painting::ViewportPaintable>(*layout_root->paintable_box()).paint_all_phases(context);
document->paintable()->paint_all_phases(context);
}
void PageHost::set_viewport_rect(Web::DevicePixelRect const& rect)