mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 09:20:36 +00:00
LibWeb: Split BorderRadiusStyleValue out of StyleValue.{h,cpp}
This commit is contained in:
parent
25114c159d
commit
66bc816284
Notes:
sideshowbarker
2024-07-16 22:51:10 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/66bc816284 Pull-request: https://github.com/SerenityOS/serenity/pull/18040
10 changed files with 95 additions and 54 deletions
|
@ -69,6 +69,7 @@ set(SOURCES
|
|||
CSS/StyleValues/BackgroundSizeStyleValue.cpp
|
||||
CSS/StyleValues/BackgroundStyleValue.cpp
|
||||
CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp
|
||||
CSS/StyleValues/BorderRadiusStyleValue.cpp
|
||||
CSS/StyleValues/BorderStyleValue.cpp
|
||||
CSS/Supports.cpp
|
||||
CSS/SyntaxHighlighter/SyntaxHighlighter.cpp
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <LibWeb/CSS/StyleSheet.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
|
@ -296,13 +297,6 @@ StyleValueList const& StyleValue::as_value_list() const
|
|||
return static_cast<StyleValueList const&>(*this);
|
||||
}
|
||||
|
||||
ErrorOr<String> BorderRadiusStyleValue::to_string() const
|
||||
{
|
||||
if (m_properties.horizontal_radius == m_properties.vertical_radius)
|
||||
return m_properties.horizontal_radius.to_string();
|
||||
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
|
||||
}
|
||||
|
||||
void CalculatedStyleValue::CalculationResult::add(CalculationResult const& other, Layout::Node const* layout_node, PercentageBasis const& percentage_basis)
|
||||
{
|
||||
add_or_subtract_internal(SumOperation::Add, other, layout_node, percentage_basis);
|
||||
|
@ -2158,7 +2152,7 @@ ValueComparingNonnullRefPtr<LengthStyleValue> LengthStyleValue::create(Length co
|
|||
return adopt_ref(*new LengthStyleValue(length));
|
||||
}
|
||||
|
||||
static Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height)
|
||||
Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height)
|
||||
{
|
||||
if (length.is_px())
|
||||
return {};
|
||||
|
@ -2190,19 +2184,6 @@ ValueComparingNonnullRefPtr<StyleValue const> ShadowStyleValue::absolutized(CSSP
|
|||
return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement);
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::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
|
||||
{
|
||||
if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage())
|
||||
return *this;
|
||||
auto absolutized_horizontal_radius = m_properties.horizontal_radius;
|
||||
auto absolutized_vertical_radius = m_properties.vertical_radius;
|
||||
if (!m_properties.horizontal_radius.is_percentage())
|
||||
absolutized_horizontal_radius = absolutized_length(m_properties.horizontal_radius.length(), viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(m_properties.horizontal_radius.length());
|
||||
if (!m_properties.vertical_radius.is_percentage())
|
||||
absolutized_vertical_radius = absolutized_length(m_properties.vertical_radius.length(), viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(m_properties.vertical_radius.length());
|
||||
return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius);
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::contains_percentage() const
|
||||
{
|
||||
return m_expression->contains_percentage();
|
||||
|
|
|
@ -267,6 +267,8 @@ private:
|
|||
|
||||
using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
||||
|
||||
Optional<CSS::Length> absolutized_length(CSS::Length const&, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const&, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height);
|
||||
|
||||
class StyleValue : public RefCounted<StyleValue> {
|
||||
public:
|
||||
virtual ~StyleValue() = default;
|
||||
|
@ -502,39 +504,6 @@ struct StyleValueWithDefaultOperators : public StyleValue {
|
|||
}
|
||||
};
|
||||
|
||||
class BorderRadiusStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<BorderRadiusStyleValue> create(LengthPercentage const& horizontal_radius, LengthPercentage const& vertical_radius)
|
||||
{
|
||||
return adopt_ref(*new BorderRadiusStyleValue(horizontal_radius, vertical_radius));
|
||||
}
|
||||
virtual ~BorderRadiusStyleValue() override = default;
|
||||
|
||||
LengthPercentage const& horizontal_radius() const { return m_properties.horizontal_radius; }
|
||||
LengthPercentage const& vertical_radius() const { return m_properties.vertical_radius; }
|
||||
bool is_elliptical() const { return m_properties.is_elliptical; }
|
||||
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
|
||||
bool properties_equal(BorderRadiusStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
BorderRadiusStyleValue(LengthPercentage const& horizontal_radius, LengthPercentage const& vertical_radius)
|
||||
: StyleValueWithDefaultOperators(Type::BorderRadius)
|
||||
, m_properties { .is_elliptical = horizontal_radius != vertical_radius, .horizontal_radius = horizontal_radius, .vertical_radius = vertical_radius }
|
||||
{
|
||||
}
|
||||
|
||||
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 override;
|
||||
|
||||
struct Properties {
|
||||
bool is_elliptical;
|
||||
LengthPercentage horizontal_radius;
|
||||
LengthPercentage vertical_radius;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
class CalculatedStyleValue : public StyleValue {
|
||||
public:
|
||||
enum class ResolvedType {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "BorderRadiusStyleValue.h"
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ErrorOr<String> BorderRadiusStyleValue::to_string() const
|
||||
{
|
||||
if (m_properties.horizontal_radius == m_properties.vertical_radius)
|
||||
return m_properties.horizontal_radius.to_string();
|
||||
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::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
|
||||
{
|
||||
if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage())
|
||||
return *this;
|
||||
auto absolutized_horizontal_radius = m_properties.horizontal_radius;
|
||||
auto absolutized_vertical_radius = m_properties.vertical_radius;
|
||||
if (!m_properties.horizontal_radius.is_percentage())
|
||||
absolutized_horizontal_radius = absolutized_length(m_properties.horizontal_radius.length(), viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(m_properties.horizontal_radius.length());
|
||||
if (!m_properties.vertical_radius.is_percentage())
|
||||
absolutized_vertical_radius = absolutized_length(m_properties.vertical_radius.length(), viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(m_properties.vertical_radius.length());
|
||||
return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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 <LibWeb/CSS/Length.h>
|
||||
#include <LibWeb/CSS/Percentage.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class BorderRadiusStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<BorderRadiusStyleValue> create(LengthPercentage const& horizontal_radius, LengthPercentage const& vertical_radius)
|
||||
{
|
||||
return adopt_ref(*new BorderRadiusStyleValue(horizontal_radius, vertical_radius));
|
||||
}
|
||||
virtual ~BorderRadiusStyleValue() override = default;
|
||||
|
||||
LengthPercentage const& horizontal_radius() const { return m_properties.horizontal_radius; }
|
||||
LengthPercentage const& vertical_radius() const { return m_properties.vertical_radius; }
|
||||
bool is_elliptical() const { return m_properties.is_elliptical; }
|
||||
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
|
||||
bool properties_equal(BorderRadiusStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
BorderRadiusStyleValue(LengthPercentage const& horizontal_radius, LengthPercentage const& vertical_radius)
|
||||
: StyleValueWithDefaultOperators(Type::BorderRadius)
|
||||
, m_properties { .is_elliptical = horizontal_radius != vertical_radius, .horizontal_radius = horizontal_radius, .vertical_radius = vertical_radius }
|
||||
{
|
||||
}
|
||||
|
||||
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 override;
|
||||
|
||||
struct Properties {
|
||||
bool is_elliptical;
|
||||
LengthPercentage horizontal_radius;
|
||||
LengthPercentage vertical_radius;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include <AK/Demangle.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
|
|
Loading…
Reference in a new issue