diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-24 14:34:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-24 16:49:51 +0200 |
commit | 959464fce404f53a8af4ce0b38ec7426f3eb8a05 (patch) | |
tree | aee7ddc63c172478e4224ef1859b50f0d8d45023 /Libraries | |
parent | 6f28f080969191e4a966d226739ad48cf43dac72 (diff) | |
download | serenity-959464fce404f53a8af4ce0b38ec7426f3eb8a05.zip |
LibWeb: Move position and text-align to LayoutStyle
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutBlock.cpp | 20 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutBox.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutNode.cpp | 12 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutNode.h | 19 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutStyle.h | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LineBox.cpp | 2 |
6 files changed, 25 insertions, 37 deletions
diff --git a/Libraries/LibWeb/Layout/LayoutBlock.cpp b/Libraries/LibWeb/Layout/LayoutBlock.cpp index bc85269c87..168c13c5bf 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.cpp +++ b/Libraries/LibWeb/Layout/LayoutBlock.cpp @@ -187,7 +187,7 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode) line_box.trim_trailing_whitespace(); } - auto text_align = this->text_align(); + auto text_align = style().text_align(); float min_line_height = specified_style().line_height(*this); float line_spacing = min_line_height - specified_style().font().glyph_height(); float content_height = 0; @@ -616,24 +616,24 @@ LayoutBlock::ShrinkToFitResult LayoutBlock::calculate_shrink_to_fit_width() void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBlock& block) { - auto& style = block.specified_style(); + auto& specified_style = block.specified_style(); auto zero_value = Length::make_px(0); auto& containing_block = *this; auto& box = block.box_model(); - box.margin.top = style.length_or_fallback(CSS::PropertyID::MarginTop, zero_value, containing_block.width()); - box.margin.bottom = style.length_or_fallback(CSS::PropertyID::MarginBottom, zero_value, containing_block.width()); - box.border.top = style.length_or_fallback(CSS::PropertyID::BorderTopWidth, zero_value); - box.border.bottom = style.length_or_fallback(CSS::PropertyID::BorderBottomWidth, zero_value); - box.padding.top = style.length_or_fallback(CSS::PropertyID::PaddingTop, zero_value, containing_block.width()); - box.padding.bottom = style.length_or_fallback(CSS::PropertyID::PaddingBottom, zero_value, containing_block.width()); + box.margin.top = specified_style.length_or_fallback(CSS::PropertyID::MarginTop, zero_value, containing_block.width()); + box.margin.bottom = specified_style.length_or_fallback(CSS::PropertyID::MarginBottom, zero_value, containing_block.width()); + box.border.top = specified_style.length_or_fallback(CSS::PropertyID::BorderTopWidth, zero_value); + box.border.bottom = specified_style.length_or_fallback(CSS::PropertyID::BorderBottomWidth, zero_value); + box.padding.top = specified_style.length_or_fallback(CSS::PropertyID::PaddingTop, zero_value, containing_block.width()); + box.padding.bottom = specified_style.length_or_fallback(CSS::PropertyID::PaddingBottom, zero_value, containing_block.width()); float x = box.margin.left.to_px(*this) + box.border.left.to_px(*this) + box.padding.left.to_px(*this) + box.offset.left.to_px(*this); - if (text_align() == CSS::TextAlign::VendorSpecificCenter) { + if (this->style().text_align() == CSS::TextAlign::VendorSpecificCenter) { x = (containing_block.width() / 2) - block.width() / 2; } @@ -642,7 +642,7 @@ void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBl auto* relevant_sibling = block.previous_sibling(); while (relevant_sibling != nullptr) { - if (relevant_sibling->position() != CSS::Position::Absolute) + if (relevant_sibling->style().position() != CSS::Position::Absolute) break; relevant_sibling = relevant_sibling->previous_sibling(); } diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/LayoutBox.cpp index 4269cbfb93..194b9c841e 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/LayoutBox.cpp @@ -323,7 +323,7 @@ bool LayoutBox::establishes_stacking_context() const return false; if (node() == document().root()) return true; - auto position = this->position(); + auto position = style().position(); auto z_index = style().z_index(); if (position == CSS::Position::Absolute || position == CSS::Position::Relative) { if (z_index.has_value()) diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp index c2280827c7..eeb7dc036e 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/LayoutNode.cpp @@ -57,7 +57,7 @@ void LayoutNode::layout(LayoutMode layout_mode) bool LayoutNode::can_contain_boxes_with_position_absolute() const { - return position() != CSS::Position::Static || is_root(); + return style().position() != CSS::Position::Static || is_root(); } const LayoutBlock* LayoutNode::containing_block() const @@ -72,7 +72,7 @@ const LayoutBlock* LayoutNode::containing_block() const if (is_text()) return nearest_block_ancestor(); - auto position = this->position(); + auto position = style().position(); if (position == CSS::Position::Absolute) { auto* ancestor = parent(); @@ -199,7 +199,7 @@ bool LayoutNode::is_absolutely_positioned() const { if (!has_style()) return false; - auto position = this->position(); + auto position = style().position(); return position == CSS::Position::Absolute || position == CSS::Position::Fixed; } @@ -207,7 +207,7 @@ bool LayoutNode::is_fixed_position() const { if (!has_style()) return false; - auto position = this->position(); + auto position = style().position(); return position == CSS::Position::Fixed; } @@ -223,8 +223,8 @@ void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style) { auto& style = static_cast<MutableLayoutStyle&>(m_style); - m_position = specified_style.position(); - m_text_align = specified_style.text_align(); + style.set_position(specified_style.position()); + style.set_text_align(specified_style.text_align()); style.set_z_index(specified_style.z_index()); } diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index da723db51d..5425583a02 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -192,8 +192,6 @@ public: const StyleProperties& specified_style() const; const ImmutableLayoutStyle& style() const; - CSS::Position position() const; - CSS::TextAlign text_align() const; LayoutNodeWithStyle* parent(); const LayoutNodeWithStyle* parent() const; @@ -263,9 +261,6 @@ public: const ImmutableLayoutStyle& style() const { return static_cast<const ImmutableLayoutStyle&>(m_style); } - CSS::Position position() const { return m_position; } - CSS::TextAlign text_align() const { return m_text_align; } - protected: explicit LayoutNodeWithStyle(const Node*, NonnullRefPtr<StyleProperties>); @@ -308,20 +303,6 @@ inline const ImmutableLayoutStyle& LayoutNode::style() const return parent()->style(); } -inline CSS::Position LayoutNode::position() const -{ - if (m_has_style) - return static_cast<const LayoutNodeWithStyle*>(this)->position(); - return parent()->position(); -} - -inline CSS::TextAlign LayoutNode::text_align() const -{ - if (m_has_style) - return static_cast<const LayoutNodeWithStyle*>(this)->text_align(); - return parent()->text_align(); -} - inline const LayoutNodeWithStyle* LayoutNode::parent() const { return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent()); diff --git a/Libraries/LibWeb/Layout/LayoutStyle.h b/Libraries/LibWeb/Layout/LayoutStyle.h index 14f1e3dc22..120d54f28e 100644 --- a/Libraries/LibWeb/Layout/LayoutStyle.h +++ b/Libraries/LibWeb/Layout/LayoutStyle.h @@ -27,15 +27,20 @@ #pragma once #include <AK/Optional.h> +#include <LibWeb/CSS/StyleValue.h> namespace Web { class LayoutStyle { public: Optional<int> z_index() const { return m_z_index; } + CSS::TextAlign text_align() const { return m_text_align; } + CSS::Position position() const { return m_position; } protected: Optional<int> m_z_index; + CSS::TextAlign m_text_align; + CSS::Position m_position; }; class ImmutableLayoutStyle final : public LayoutStyle { @@ -44,6 +49,8 @@ class ImmutableLayoutStyle final : public LayoutStyle { class MutableLayoutStyle final : public LayoutStyle { public: void set_z_index(Optional<int> value) { m_z_index = value; } + void set_text_align(CSS::TextAlign text_align) { m_text_align = text_align; } + void set_position(CSS::Position position) { m_position = position; } }; } diff --git a/Libraries/LibWeb/Layout/LineBox.cpp b/Libraries/LibWeb/Layout/LineBox.cpp index aac8862dd2..fe6da58712 100644 --- a/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Libraries/LibWeb/Layout/LineBox.cpp @@ -35,7 +35,7 @@ namespace Web { void LineBox::add_fragment(const LayoutNode& layout_node, int start, int length, int width, int height) { - bool text_align_is_justify = layout_node.text_align() == CSS::TextAlign::Justify; + 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) { // The fragment we're adding is from the last LayoutNode on the line. // Expand the last fragment instead of adding a new one with the same LayoutNode. |