From 88ca932fac84e7e349a4f64f57e4d303df9e8397 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 4 Dec 2020 15:46:58 +0100 Subject: [PATCH] LibWeb: Make LineBoxFragment store non-const Layout::Node& This is more honest, since we actually const_cast these layout nodes during inline layout anyway. --- Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 4 ++-- Libraries/LibWeb/Layout/LineBox.cpp | 4 ++-- Libraries/LibWeb/Layout/LineBox.h | 2 +- Libraries/LibWeb/Layout/LineBoxFragment.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 029ade00a0..105dffa119 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -135,8 +135,8 @@ void InlineFormattingContext::run(LayoutMode layout_mode) } } - if (fragment.layout_node().is_box()) - dimension_box_on_line(const_cast(downcast(fragment.layout_node())), layout_mode); + if (is(fragment.layout_node())) + dimension_box_on_line(downcast(fragment.layout_node()), layout_mode); float final_line_box_width = 0; for (auto& fragment : line_box.fragments()) diff --git a/Libraries/LibWeb/Layout/LineBox.cpp b/Libraries/LibWeb/Layout/LineBox.cpp index 6ef3efbfa5..8d2c3d63da 100644 --- a/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Libraries/LibWeb/Layout/LineBox.cpp @@ -33,7 +33,7 @@ namespace Web::Layout { -void LineBox::add_fragment(const Node& layout_node, int start, int length, int width, int height, LineBoxFragment::Type fragment_type) +void LineBox::add_fragment(Node& layout_node, int start, int length, int width, int height, LineBoxFragment::Type fragment_type) { bool text_align_is_justify = layout_node.style().text_align() == CSS::TextAlign::Justify; if (!text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node) { @@ -47,7 +47,7 @@ void LineBox::add_fragment(const Node& layout_node, int start, int length, int w m_width += width; if (is(layout_node)) - const_cast(downcast(layout_node)).set_containing_line_box_fragment(m_fragments.last()); + downcast(layout_node).set_containing_line_box_fragment(m_fragments.last()); } void LineBox::trim_trailing_whitespace() diff --git a/Libraries/LibWeb/Layout/LineBox.h b/Libraries/LibWeb/Layout/LineBox.h index 4198f34ddc..5bfb71abec 100644 --- a/Libraries/LibWeb/Layout/LineBox.h +++ b/Libraries/LibWeb/Layout/LineBox.h @@ -38,7 +38,7 @@ public: float width() const { return m_width; } - void add_fragment(const Node& layout_node, int start, int length, int width, int height, LineBoxFragment::Type = LineBoxFragment::Type::Normal); + void add_fragment(Node& layout_node, int start, int length, int width, int height, LineBoxFragment::Type = LineBoxFragment::Type::Normal); const NonnullOwnPtrVector& fragments() const { return m_fragments; } NonnullOwnPtrVector& fragments() { return m_fragments; } diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.h b/Libraries/LibWeb/Layout/LineBoxFragment.h index 39fc97972e..03819f0fb3 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.h +++ b/Libraries/LibWeb/Layout/LineBoxFragment.h @@ -43,7 +43,7 @@ public: Trailing, }; - LineBoxFragment(const Node& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size, Type type) + LineBoxFragment(Node& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size, Type type) : m_layout_node(layout_node) , m_start(start) , m_length(length) @@ -53,7 +53,7 @@ public: { } - const Node& layout_node() const { return m_layout_node; } + Node& layout_node() const { return m_layout_node; } int start() const { return m_start; } int length() const { return m_length; } const Gfx::FloatRect absolute_rect() const; @@ -81,7 +81,7 @@ public: Gfx::FloatRect selection_rect(const Gfx::Font&) const; private: - const Node& m_layout_node; + Node& m_layout_node; int m_start { 0 }; int m_length { 0 }; Gfx::FloatPoint m_offset;