From c690fb9df382b2d503ff57eaf6b3d813056f6359 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 16 Oct 2024 15:19:32 +0200 Subject: [PATCH] LibWeb: Rename Layout::Node::paintable() to first_paintable() Layout node is allowed to have multiple corresponding paintables, so first_paintable() is more explicit name for getter that returns first paintable. --- .../Libraries/LibWeb/CSS/Interpolation.cpp | 2 +- .../CSS/ResolvedCSSStyleDeclaration.cpp | 18 ++++++++--------- Userland/Libraries/LibWeb/DOM/Document.cpp | 8 ++++---- Userland/Libraries/LibWeb/DOM/Element.cpp | 4 ++-- Userland/Libraries/LibWeb/Dump.cpp | 4 ++-- Userland/Libraries/LibWeb/Layout/Box.cpp | 4 ++-- .../Libraries/LibWeb/Layout/LabelableNode.cpp | 4 ++-- .../Libraries/LibWeb/Layout/LayoutState.cpp | 20 +++++++++---------- Userland/Libraries/LibWeb/Layout/Node.h | 4 ++-- Userland/Libraries/LibWeb/Layout/Viewport.cpp | 2 +- .../Libraries/LibWeb/Page/EventHandler.cpp | 2 +- .../LibWeb/Painting/BackgroundPainting.cpp | 2 +- .../LibWeb/Painting/PaintableFragment.h | 2 +- .../Libraries/LibWeb/Painting/SVGMaskable.cpp | 4 ++-- .../WebContent/ConnectionFromClient.cpp | 4 ++-- 15 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Interpolation.cpp b/Userland/Libraries/LibWeb/CSS/Interpolation.cpp index 7ccf1932720..7c836a263e1 100644 --- a/Userland/Libraries/LibWeb/CSS/Interpolation.cpp +++ b/Userland/Libraries/LibWeb/CSS/Interpolation.cpp @@ -127,7 +127,7 @@ RefPtr interpolate_transform(DOM::Element& element, CSSStyl return {}; Optional paintable_box; if (auto layout_node = element.layout_node()) { - if (auto paintable = layout_node->paintable(); paintable && is(paintable)) + if (auto paintable = layout_node->first_paintable(); paintable && is(paintable)) paintable_box = *static_cast(paintable); } if (auto matrix = transformation->to_matrix(paintable_box); !matrix.is_error()) diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 236ed881fda..fa3eb60b533 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -198,9 +198,9 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert { auto used_value_for_property = [&layout_node, property_id](Function&& used_value_getter) -> Optional { auto const& display = layout_node.computed_values().display(); - if (!display.is_none() && !display.is_contents() && layout_node.paintable()) { - if (layout_node.paintable()->is_paintable_box()) { - auto const& paintable_box = static_cast(*layout_node.paintable()); + if (!display.is_none() && !display.is_contents() && layout_node.first_paintable()) { + if (layout_node.first_paintable()->is_paintable_box()) { + auto const& paintable_box = static_cast(*layout_node.first_paintable()); return used_value_getter(paintable_box); } dbgln("FIXME: Support getting used value for property `{}` on {}", string_from_property_id(property_id), layout_node.debug_description()); @@ -379,8 +379,8 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert auto transform = FloatMatrix4x4::identity(); // 2. Post-multiply all s in to transform. - VERIFY(layout_node.paintable()); - auto const& paintable_box = verify_cast(*layout_node.paintable()); + VERIFY(layout_node.first_paintable()); + auto const& paintable_box = verify_cast(*layout_node.first_paintable()); for (auto transformation : transformations) { transform = transform * transformation.to_matrix(paintable_box).release_value(); } @@ -523,15 +523,15 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert // For grid-template-columns and grid-template-rows the resolved value is the used value. // https://www.w3.org/TR/css-grid-2/#resolved-track-list-standalone if (property_id == PropertyID::GridTemplateColumns) { - if (layout_node.paintable() && layout_node.paintable()->is_paintable_box()) { - auto const& paintable_box = verify_cast(*layout_node.paintable()); + if (layout_node.first_paintable() && layout_node.first_paintable()->is_paintable_box()) { + auto const& paintable_box = verify_cast(*layout_node.first_paintable()); if (auto used_values_for_grid_template_columns = paintable_box.used_values_for_grid_template_columns()) { return used_values_for_grid_template_columns; } } } else if (property_id == PropertyID::GridTemplateRows) { - if (layout_node.paintable() && layout_node.paintable()->is_paintable_box()) { - auto const& paintable_box = verify_cast(*layout_node.paintable()); + if (layout_node.first_paintable() && layout_node.first_paintable()->is_paintable_box()) { + auto const& paintable_box = verify_cast(*layout_node.first_paintable()); if (auto used_values_for_grid_template_rows = paintable_box.used_values_for_grid_template_rows()) { return used_values_for_grid_template_rows; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f7aa3684b1b..4242a0f7b3e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1389,14 +1389,14 @@ void Document::set_inspected_node(Node* node, Optionalpaintable()) - layout_node->paintable()->set_needs_display(); + if (auto layout_node = inspected_layout_node(); layout_node && layout_node->first_paintable()) + layout_node->first_paintable()->set_needs_display(); m_inspected_node = node; m_inspected_pseudo_element = pseudo_element; - if (auto layout_node = inspected_layout_node(); layout_node && layout_node->paintable()) - layout_node->paintable()->set_needs_display(); + if (auto layout_node = inspected_layout_node(); layout_node && layout_node->first_paintable()) + layout_node->first_paintable()->set_needs_display(); } Layout::Node* Document::inspected_layout_node() diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 120f831b542..e70a44db215 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -601,8 +601,8 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style() if (auto* node_with_style = dynamic_cast(pseudo_element->layout_node.ptr())) { node_with_style->apply_style(*pseudo_element_style); - if (invalidation.repaint && node_with_style->paintable()) - node_with_style->paintable()->set_needs_display(); + if (invalidation.repaint && node_with_style->first_paintable()) + node_with_style->first_paintable()->set_needs_display(); } } } diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 17dda86cc87..cb8fb27c8a2 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -381,9 +381,9 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho } } - if (is(layout_node) && layout_node.paintable()) { + if (is(layout_node) && layout_node.first_paintable()) { auto const& inline_node = static_cast(layout_node); - auto const& inline_paintable = static_cast(*inline_node.paintable()); + auto const& inline_paintable = static_cast(*inline_node.first_paintable()); auto const& fragments = inline_paintable.fragments(); for (size_t fragment_index = 0; fragment_index < fragments.size(); ++fragment_index) { auto const& fragment = fragments[fragment_index]; diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index feea12ea8b9..a9ceda87448 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -72,12 +72,12 @@ JS::GCPtr Box::create_paintable() const Painting::PaintableBox* Box::paintable_box() { - return static_cast(Node::paintable()); + return static_cast(Node::first_paintable()); } Painting::PaintableBox const* Box::paintable_box() const { - return static_cast(Node::paintable()); + return static_cast(Node::first_paintable()); } Optional Box::preferred_aspect_ratio() const diff --git a/Userland/Libraries/LibWeb/Layout/LabelableNode.cpp b/Userland/Libraries/LibWeb/Layout/LabelableNode.cpp index 74762955465..401f6ed5340 100644 --- a/Userland/Libraries/LibWeb/Layout/LabelableNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/LabelableNode.cpp @@ -11,12 +11,12 @@ namespace Web::Layout { Painting::LabelablePaintable* LabelableNode::paintable() { - return static_cast(ReplacedBox::paintable()); + return static_cast(ReplacedBox::first_paintable()); } Painting::LabelablePaintable const* LabelableNode::paintable() const { - return static_cast(ReplacedBox::paintable()); + return static_cast(ReplacedBox::first_paintable()); } } diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index 139532460c6..3b4ecc478a7 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -88,8 +88,8 @@ static CSSPixelRect measure_scrollable_overflow(Box const& box) auto scrollable_overflow_rect = paintable_box.absolute_padding_box_rect(); // - All line boxes directly contained by the scroll container. - if (is(box.paintable())) { - for (auto const& fragment : static_cast(*box.paintable()).fragments()) { + if (is(box.first_paintable())) { + for (auto const& fragment : static_cast(*box.first_paintable()).fragments()) { scrollable_overflow_rect = scrollable_overflow_rect.united(fragment.absolute_rect()); } } @@ -129,8 +129,8 @@ static CSSPixelRect measure_scrollable_overflow(Box const& box) }); } else { box.for_each_child([&scrollable_overflow_rect, &content_overflow_rect](Node const& child) { - if (child.paintable() && child.paintable()->is_inline_paintable()) { - for (auto const& fragment : static_cast(*child.paintable()).fragments()) { + if (child.first_paintable() && child.first_paintable()->is_inline_paintable()) { + for (auto const& fragment : static_cast(*child.first_paintable()).fragments()) { scrollable_overflow_rect = scrollable_overflow_rect.united(fragment.absolute_rect()); content_overflow_rect = content_overflow_rect.united(fragment.absolute_rect()); } @@ -165,7 +165,7 @@ void LayoutState::resolve_relative_positions() auto& used_values = *it.value; auto& node = const_cast(used_values.node()); - auto* paintable = node.paintable(); + auto* paintable = node.first_paintable(); if (!paintable) continue; if (!is(*paintable)) @@ -197,8 +197,8 @@ void LayoutState::resolve_relative_positions() static void build_paint_tree(Node& node, Painting::Paintable* parent_paintable = nullptr) { Painting::Paintable* paintable = nullptr; - if (node.paintable()) { - paintable = const_cast(node.paintable()); + if (node.first_paintable()) { + paintable = const_cast(node.first_paintable()); if (parent_paintable && !paintable->forms_unconnected_subtree()) { VERIFY(!paintable->parent()); parent_paintable->append_child(*paintable); @@ -298,7 +298,7 @@ void LayoutState::commit(Box& root) if (!node.is_box()) continue; - auto& paintable = static_cast(*node.paintable()); + auto& paintable = static_cast(*node.first_paintable()); CSSPixelPoint offset; if (used_values.containing_line_box_fragment.has_value()) { @@ -336,7 +336,7 @@ void LayoutState::commit(Box& root) auto find_closest_inline_paintable = [&](auto& fragment) -> Painting::InlinePaintable const* { for (auto const* parent = fragment.layout_node().parent(); parent; parent = parent->parent()) { if (is(*parent)) - return static_cast(parent->paintable()); + return static_cast(parent->first_paintable()); } return nullptr; }; @@ -352,7 +352,7 @@ void LayoutState::commit(Box& root) for (auto* text_node : text_nodes) { text_node->add_paintable(text_node->create_paintable()); - auto* paintable = text_node->paintable(); + auto* paintable = text_node->first_paintable(); auto const& font = text_node->first_available_font(); auto const glyph_height = CSSPixels::nearest_value_for(font.pixel_size()); auto const css_line_thickness = [&] { diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 1b488224da9..505f0d811de 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -67,8 +67,8 @@ public: using PaintableList = IntrusiveList<&Painting::Paintable::m_list_node>; - Painting::Paintable* paintable() { return m_paintable.first(); } - Painting::Paintable const* paintable() const { return m_paintable.first(); } + Painting::Paintable* first_paintable() { return m_paintable.first(); } + Painting::Paintable const* first_paintable() const { return m_paintable.first(); } void add_paintable(JS::GCPtr); void clear_paintables(); diff --git a/Userland/Libraries/LibWeb/Layout/Viewport.cpp b/Userland/Libraries/LibWeb/Layout/Viewport.cpp index 533d6e81500..d77b7cd5ee2 100644 --- a/Userland/Libraries/LibWeb/Layout/Viewport.cpp +++ b/Userland/Libraries/LibWeb/Layout/Viewport.cpp @@ -55,7 +55,7 @@ void Viewport::update_text_blocks() Vector text_positions; Vector text_blocks; for_each_in_inclusive_subtree([&](auto const& layout_node) { - if (layout_node.display().is_none() || !layout_node.paintable() || !layout_node.paintable()->is_visible()) + if (layout_node.display().is_none() || !layout_node.first_paintable() || !layout_node.first_paintable()->is_visible()) return TraversalDecision::Continue; if (layout_node.is_box() || layout_node.is_generated()) { diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 67a7442e01a..6e53ad918fa 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -136,7 +136,7 @@ static Gfx::StandardCursor cursor_css_to_gfx(Optional cursor) static CSSPixelPoint compute_mouse_event_offset(CSSPixelPoint position, Layout::Node const& layout_node) { - auto top_left_of_layout_node = layout_node.paintable()->box_type_agnostic_position(); + auto top_left_of_layout_node = layout_node.first_paintable()->box_type_agnostic_position(); return { position.x() - top_left_of_layout_node.x(), position.y() - top_left_of_layout_node.y() diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 121e5fba973..89bbf6de488 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -82,7 +82,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet DisplayListRecorderStateSaver state { display_list_recorder }; if (resolved_background.needs_text_clip) { - auto display_list = compute_text_clip_paths(context, *layout_node.paintable(), resolved_background.background_rect.location()); + auto display_list = compute_text_clip_paths(context, *layout_node.first_paintable(), resolved_background.background_rect.location()); auto rect = context.rounded_device_rect(resolved_background.background_rect); display_list_recorder.add_mask(move(display_list), rect.to_type()); } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableFragment.h b/Userland/Libraries/LibWeb/Painting/PaintableFragment.h index d340fefcd44..c4f47509ac3 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableFragment.h +++ b/Userland/Libraries/LibWeb/Painting/PaintableFragment.h @@ -22,7 +22,7 @@ public: explicit PaintableFragment(Layout::LineBoxFragment const&); Layout::Node const& layout_node() const { return m_layout_node; } - Paintable const& paintable() const { return *m_layout_node->paintable(); } + Paintable const& paintable() const { return *m_layout_node->first_paintable(); } int start() const { return m_start; } int length() const { return m_length; } diff --git a/Userland/Libraries/LibWeb/Painting/SVGMaskable.cpp b/Userland/Libraries/LibWeb/Painting/SVGMaskable.cpp index f52b8daf4ae..e53ddd28a31 100644 --- a/Userland/Libraries/LibWeb/Painting/SVGMaskable.cpp +++ b/Userland/Libraries/LibWeb/Painting/SVGMaskable.cpp @@ -96,11 +96,11 @@ RefPtr SVGMaskable::calculate_mask_of_svg(PaintContext& context, CS }; RefPtr mask_bitmap = {}; if (auto* mask_box = get_mask_box(graphics_element)) { - auto& mask_paintable = static_cast(*mask_box->paintable()); + auto& mask_paintable = static_cast(*mask_box->first_paintable()); mask_bitmap = paint_mask_or_clip(mask_paintable); } if (auto* clip_box = get_clip_box(graphics_element)) { - auto& clip_paintable = static_cast(*clip_box->paintable()); + auto& clip_paintable = static_cast(*clip_box->first_paintable()); auto clip_bitmap = paint_mask_or_clip(clip_paintable); // Combine the clip-path with the mask (if present). if (mask_bitmap && clip_bitmap) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index a9d550af543..061e94de0d8 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -890,12 +890,12 @@ static void append_paint_tree(Web::Page& page, StringBuilder& builder) builder.append("(no layout tree)"sv); return; } - if (!layout_root->paintable()) { + if (!layout_root->first_paintable()) { builder.append("(no paint tree)"sv); return; } - Web::dump_tree(builder, *layout_root->paintable()); + Web::dump_tree(builder, *layout_root->first_paintable()); } static void append_gc_graph(StringBuilder& builder)