diff options
Diffstat (limited to 'Libraries')
-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 | 15 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutStyle.h | 49 | ||||
-rw-r--r-- | Libraries/LibWeb/Painting/StackingContext.cpp | 2 |
5 files changed, 76 insertions, 4 deletions
diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/LayoutBox.cpp index 9951221b0d..4269cbfb93 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/LayoutBox.cpp @@ -324,7 +324,7 @@ bool LayoutBox::establishes_stacking_context() const if (node() == document().root()) return true; auto position = this->position(); - auto z_index = specified_style().z_index(); + auto z_index = style().z_index(); if (position == CSS::Position::Absolute || position == CSS::Position::Relative) { if (z_index.has_value()) return true; diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp index e185991872..c2280827c7 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/LayoutNode.cpp @@ -216,8 +216,16 @@ LayoutNodeWithStyle::LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StylePr , m_specified_style(move(style)) { m_has_style = true; - m_position = m_specified_style->position(); - m_text_align = m_specified_style->text_align(); + apply_style(this->specified_style()); +} + +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_z_index(specified_style.z_index()); } } diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index dc002f180c..da723db51d 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -34,6 +34,7 @@ #include <LibWeb/Forward.h> #include <LibWeb/Layout/BoxModelMetrics.h> #include <LibWeb/Layout/LayoutPosition.h> +#include <LibWeb/Layout/LayoutStyle.h> #include <LibWeb/Painting/PaintContext.h> #include <LibWeb/TreeNode.h> @@ -190,6 +191,7 @@ public: virtual LayoutNode& inline_wrapper() { return *this; } const StyleProperties& specified_style() const; + const ImmutableLayoutStyle& style() const; CSS::Position position() const; CSS::TextAlign text_align() const; @@ -259,6 +261,8 @@ public: const StyleProperties& specified_style() const { return m_specified_style; } void set_specified_style(const StyleProperties& style) { m_specified_style = style; } + 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; } @@ -266,6 +270,10 @@ protected: explicit LayoutNodeWithStyle(const Node*, NonnullRefPtr<StyleProperties>); private: + void apply_style(const StyleProperties&); + + LayoutStyle m_style; + NonnullRefPtr<StyleProperties> m_specified_style; CSS::Position m_position; CSS::TextAlign m_text_align; @@ -293,6 +301,13 @@ inline const StyleProperties& LayoutNode::specified_style() const return parent()->specified_style(); } +inline const ImmutableLayoutStyle& LayoutNode::style() const +{ + if (m_has_style) + return static_cast<const LayoutNodeWithStyle*>(this)->style(); + return parent()->style(); +} + inline CSS::Position LayoutNode::position() const { if (m_has_style) diff --git a/Libraries/LibWeb/Layout/LayoutStyle.h b/Libraries/LibWeb/Layout/LayoutStyle.h new file mode 100644 index 0000000000..14f1e3dc22 --- /dev/null +++ b/Libraries/LibWeb/Layout/LayoutStyle.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include <AK/Optional.h> + +namespace Web { + +class LayoutStyle { +public: + Optional<int> z_index() const { return m_z_index; } + +protected: + Optional<int> m_z_index; +}; + +class ImmutableLayoutStyle final : public LayoutStyle { +}; + +class MutableLayoutStyle final : public LayoutStyle { +public: + void set_z_index(Optional<int> value) { m_z_index = value; } +}; + +} diff --git a/Libraries/LibWeb/Painting/StackingContext.cpp b/Libraries/LibWeb/Painting/StackingContext.cpp index 5134d0c3df..fffc584947 100644 --- a/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Libraries/LibWeb/Painting/StackingContext.cpp @@ -42,7 +42,7 @@ StackingContext::StackingContext(LayoutBox& box, StackingContext* parent) // FIXME: Don't sort on every append.. quick_sort(m_children, [](auto& a, auto& b) { - return a->m_box.specified_style().z_index().value_or(0) < b->m_box.specified_style().z_index().value_or(0); + return a->m_box.style().z_index().value_or(0) < b->m_box.style().z_index().value_or(0); }); } } |