1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

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.
This commit is contained in:
Sam Atkins 2023-03-30 14:22:39 +01:00 committed by Andreas Kling
parent b3a7a00ccf
commit bcebca62d3
9 changed files with 69 additions and 38 deletions

View file

@ -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

View file

@ -5,7 +5,6 @@
*/
#include "Clip.h"
#include <LibWeb/CSS/StyleValue.h>
namespace Web::CSS {

View file

@ -6,7 +6,7 @@
#pragma once
#include <LibWeb/CSS/StyleValue.h>
#include <LibWeb/CSS/EdgeRect.h>
namespace Web::CSS {

View file

@ -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
};
}
}

View file

@ -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;
};
}

View file

@ -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>

View file

@ -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();

View file

@ -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; }

View file

@ -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; }