diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-30 14:22:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-30 21:29:50 +0200 |
commit | bcebca62d37e6acc740eda3715fd525c9c230cbf (patch) | |
tree | 56a94a754d07fb1fd837fcd8cd52757490baeb1b | |
parent | b3a7a00ccfd448e473d740685d3cd6c5e0b04bc1 (diff) | |
download | serenity-bcebca62d37e6acc740eda3715fd525c9c230cbf.zip |
LibWeb: Move CSS::EdgeRect into its own files
Also remove the unused StyleValue::to_rect() because an EdgeRect is only
ever held by a RectStyleValue.
-rw-r--r-- | Userland/Libraries/LibWeb/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Clip.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Clip.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/EdgeRect.cpp | 39 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/EdgeRect.h | 26 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 25 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h | 2 |
9 files changed, 69 insertions, 38 deletions
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 <LibWeb/CSS/StyleValue.h> 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 <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/EdgeRect.h> 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 <kling@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> + * + * 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 <shape> value is: rect(<top>, <right>, <bottom>, <left>) where + // <top> and <bottom> specify offsets from the top border edge of the box, and <right>, and + // <left> 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 <top> and + // <left>, the same as the used value of the height plus the sum of vertical padding and border + // widths for <bottom>, and the same as the used value of the width plus the sum of the + // horizontal padding and border widths for <right>, 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 <kling@serenityos.org> + * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibGfx/Rect.h> +#include <LibWeb/CSS/Length.h> + +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 <LibWeb/CSS/CSSStyleSheet.h> #include <LibWeb/CSS/CSSSupportsRule.h> #include <LibWeb/CSS/CalculatedOr.h> +#include <LibWeb/CSS/EdgeRect.h> #include <LibWeb/CSS/MediaList.h> #include <LibWeb/CSS/Parser/Block.h> #include <LibWeb/CSS/Parser/ComponentValue.h> 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::ResolvedType> 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 <shape> value is: rect(<top>, <right>, <bottom>, <left>) where - // <top> and <bottom> specify offsets from the top border edge of the box, and <right>, and - // <left> 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 <top> and - // <left>, the same as the used value of the height plus the sum of vertical padding and border - // widths for <bottom>, and the same as the used value of the width plus the sum of the - // horizontal padding and border widths for <right>, 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::ResolvedType> 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<StyleValue const> 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 <LibWeb/CSS/EdgeRect.h> #include <LibWeb/CSS/StyleValue.h> namespace Web::CSS { @@ -21,7 +22,6 @@ public: EdgeRect rect() const { return m_rect; } virtual ErrorOr<String> 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; } |