LibWeb: Split BorderRadiusShorthandStyleValue out of StyleValue.{h,cpp}

This commit is contained in:
Sam Atkins 2023-03-25 00:29:33 +00:00 committed by Linus Groh
parent 1c03bc7a6f
commit 25114c159d
Notes: sideshowbarker 2024-07-17 05:23:40 +09:00
8 changed files with 81 additions and 46 deletions

View file

@ -68,6 +68,7 @@ set(SOURCES
CSS/StyleValues/BackgroundRepeatStyleValue.cpp
CSS/StyleValues/BackgroundSizeStyleValue.cpp
CSS/StyleValues/BackgroundStyleValue.cpp
CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp
CSS/StyleValues/BorderStyleValue.cpp
CSS/Supports.cpp
CSS/SyntaxHighlighter/SyntaxHighlighter.cpp

View file

@ -33,6 +33,7 @@
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h>

View file

@ -14,6 +14,7 @@
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>

View file

@ -26,6 +26,7 @@
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleSheet.h>
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>

View file

@ -15,6 +15,7 @@
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
@ -302,11 +303,6 @@ ErrorOr<String> BorderRadiusStyleValue::to_string() const
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
}
ErrorOr<String> BorderRadiusShorthandStyleValue::to_string() const
{
return String::formatted("{} {} {} {} / {} {} {} {}", TRY(m_properties.top_left->horizontal_radius().to_string()), TRY(m_properties.top_right->horizontal_radius().to_string()), TRY(m_properties.bottom_right->horizontal_radius().to_string()), TRY(m_properties.bottom_left->horizontal_radius().to_string()), TRY(m_properties.top_left->vertical_radius().to_string()), TRY(m_properties.top_right->vertical_radius().to_string()), TRY(m_properties.bottom_right->vertical_radius().to_string()), TRY(m_properties.bottom_left->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);

View file

@ -535,47 +535,6 @@ private:
} m_properties;
};
class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<BorderRadiusShorthandStyleValue> create(
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
{
return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left)));
}
virtual ~BorderRadiusShorthandStyleValue() override = default;
auto top_left() const { return m_properties.top_left; }
auto top_right() const { return m_properties.top_right; }
auto bottom_right() const { return m_properties.bottom_right; }
auto bottom_left() const { return m_properties.bottom_left; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
BorderRadiusShorthandStyleValue(
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
: StyleValueWithDefaultOperators(Type::BorderRadiusShorthand)
, m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left;
bool operator==(Properties const&) const = default;
} m_properties;
};
class CalculatedStyleValue : public StyleValue {
public:
enum class ResolvedType {

View file

@ -0,0 +1,19 @@
/*
* 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 "BorderRadiusShorthandStyleValue.h"
namespace Web::CSS {
ErrorOr<String> BorderRadiusShorthandStyleValue::to_string() const
{
return String::formatted("{} {} {} {} / {} {} {} {}", TRY(m_properties.top_left->horizontal_radius().to_string()), TRY(m_properties.top_right->horizontal_radius().to_string()), TRY(m_properties.bottom_right->horizontal_radius().to_string()), TRY(m_properties.bottom_left->horizontal_radius().to_string()), TRY(m_properties.top_left->vertical_radius().to_string()), TRY(m_properties.top_right->vertical_radius().to_string()), TRY(m_properties.bottom_right->vertical_radius().to_string()), TRY(m_properties.bottom_left->vertical_radius().to_string()));
}
}

View file

@ -0,0 +1,57 @@
/*
* 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/StyleValue.h>
namespace Web::CSS {
class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<BorderRadiusShorthandStyleValue> create(
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
{
return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left)));
}
virtual ~BorderRadiusShorthandStyleValue() override = default;
auto top_left() const { return m_properties.top_left; }
auto top_right() const { return m_properties.top_right; }
auto bottom_right() const { return m_properties.bottom_right; }
auto bottom_left() const { return m_properties.bottom_left; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
BorderRadiusShorthandStyleValue(
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
: StyleValueWithDefaultOperators(Type::BorderRadiusShorthand)
, m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left;
bool operator==(Properties const&) const = default;
} m_properties;
};
}