diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 2cd4effbcf..66d63ce502 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -31,6 +31,7 @@ set(SOURCES CSS/CSSStyleSheet.cpp CSS/CSSSupportsRule.cpp CSS/Display.cpp + CSS/EdgeRect.cpp CSS/FontFace.cpp CSS/Frequency.cpp CSS/GridTrackPlacement.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Clip.cpp b/Userland/Libraries/LibWeb/CSS/Clip.cpp index bf73c238fc..92e136714c 100644 --- a/Userland/Libraries/LibWeb/CSS/Clip.cpp +++ b/Userland/Libraries/LibWeb/CSS/Clip.cpp @@ -5,7 +5,6 @@ */ #include "Clip.h" -#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/Clip.h b/Userland/Libraries/LibWeb/CSS/Clip.h index 1f19d370f2..7d4a72fd7a 100644 --- a/Userland/Libraries/LibWeb/CSS/Clip.h +++ b/Userland/Libraries/LibWeb/CSS/Clip.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp b/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp new file mode 100644 index 0000000000..df862baca9 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/EdgeRect.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "EdgeRect.h" + +namespace Web::CSS { + +// https://www.w3.org/TR/CSS2/visufx.html#value-def-shape +Gfx::FloatRect EdgeRect::resolved(Layout::Node const& layout_node, Gfx::FloatRect border_box) const +{ + // In CSS 2.1, the only valid value is: rect(, , , ) where + // and specify offsets from the top border edge of the box, and , and + // specify offsets from the left border edge of the box. + + // The value 'auto' means that a given edge of the clipping region will be the same as the edge + // of the element's generated border box (i.e., 'auto' means the same as '0' for and + // , the same as the used value of the height plus the sum of vertical padding and border + // widths for , and the same as the used value of the width plus the sum of the + // horizontal padding and border widths for , such that four 'auto' values result in the + // clipping region being the same as the element's border box). + auto left = border_box.left() + (left_edge.is_auto() ? 0 : left_edge.to_px(layout_node)).value(); + auto top = border_box.top() + (top_edge.is_auto() ? 0 : top_edge.to_px(layout_node)).value(); + auto right = border_box.left() + (right_edge.is_auto() ? border_box.width() : right_edge.to_px(layout_node)).value(); + auto bottom = border_box.top() + (bottom_edge.is_auto() ? border_box.height() : bottom_edge.to_px(layout_node)).value(); + return Gfx::FloatRect { + left, + top, + right - left, + bottom - top + }; +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/EdgeRect.h b/Userland/Libraries/LibWeb/CSS/EdgeRect.h new file mode 100644 index 0000000000..97196dcd43 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/EdgeRect.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +struct EdgeRect { + Length top_edge; + Length right_edge; + Length bottom_edge; + Length left_edge; + Gfx::FloatRect resolved(Layout::Node const&, Gfx::FloatRect) const; + bool operator==(EdgeRect const&) const = default; +}; + +} diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 95fd6c6bd0..afde36f313 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 6578a2518c..9b75dee93d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -777,31 +777,6 @@ Optional CalculatedStyleValue::CalcSum::reso return resolve_sum_type(type, zero_or_more_additional_calc_products); } -// https://www.w3.org/TR/CSS2/visufx.html#value-def-shape -Gfx::FloatRect EdgeRect::resolved(Layout::Node const& layout_node, Gfx::FloatRect border_box) const -{ - // In CSS 2.1, the only valid value is: rect(, , , ) where - // and specify offsets from the top border edge of the box, and , and - // specify offsets from the left border edge of the box. - - // The value 'auto' means that a given edge of the clipping region will be the same as the edge - // of the element's generated border box (i.e., 'auto' means the same as '0' for and - // , the same as the used value of the height plus the sum of vertical padding and border - // widths for , and the same as the used value of the width plus the sum of the - // horizontal padding and border widths for , such that four 'auto' values result in the - // clipping region being the same as the element's border box). - auto left = border_box.left() + (left_edge.is_auto() ? 0 : left_edge.to_px(layout_node)).value(); - auto top = border_box.top() + (top_edge.is_auto() ? 0 : top_edge.to_px(layout_node)).value(); - auto right = border_box.left() + (right_edge.is_auto() ? border_box.width() : right_edge.to_px(layout_node)).value(); - auto bottom = border_box.top() + (bottom_edge.is_auto() ? border_box.height() : bottom_edge.to_px(layout_node)).value(); - return Gfx::FloatRect { - left, - top, - right - left, - bottom - top - }; -} - Optional CalculatedStyleValue::CalcNumberSum::resolved_type() const { auto maybe_type = first_calc_number_product->resolved_type(); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 7d4d09ef4b..a1e8ea9548 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -75,15 +75,6 @@ struct PositionValue { bool operator==(PositionValue const&) const = default; }; -struct EdgeRect { - Length top_edge; - Length right_edge; - Length bottom_edge; - Length left_edge; - Gfx::FloatRect resolved(Layout::Node const&, Gfx::FloatRect) const; - bool operator==(EdgeRect const&) const = default; -}; - // FIXME: Find a better place for this helper. inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_value) { @@ -357,7 +348,6 @@ public: virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const; virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; } - virtual EdgeRect to_rect() const { VERIFY_NOT_REACHED(); } virtual CSS::ValueID to_identifier() const { return ValueID::Invalid; } virtual Length to_length() const { VERIFY_NOT_REACHED(); } virtual float to_number() const { return 0; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h index cd1b9cf07c..645013079c 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h @@ -9,6 +9,7 @@ #pragma once +#include #include namespace Web::CSS { @@ -21,7 +22,6 @@ public: EdgeRect rect() const { return m_rect; } virtual ErrorOr to_string() const override; virtual bool has_rect() const override { return true; } - virtual EdgeRect to_rect() const override { return m_rect; } bool properties_equal(RectStyleValue const& other) const { return m_rect == other.m_rect; }