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

This commit is contained in:
Sam Atkins 2023-03-24 17:20:16 +00:00 committed by Linus Groh
parent 7f6add1c6e
commit f98634586e
Notes: sideshowbarker 2024-07-17 07:11:12 +09:00
7 changed files with 68 additions and 34 deletions

View file

@ -89,6 +89,7 @@ set(SOURCES
CSS/StyleValues/LinearGradientStyleValue.cpp
CSS/StyleValues/ListStyleStyleValue.cpp
CSS/StyleValues/NumericStyleValue.cpp
CSS/StyleValues/OverflowStyleValue.cpp
CSS/StyleValues/RadialGradientStyleValue.cpp
CSS/Supports.cpp
CSS/SyntaxHighlighter/SyntaxHighlighter.cpp

View file

@ -57,6 +57,7 @@
#include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
#include <LibWeb/CSS/StyleValues/ListStyleStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h>

View file

@ -41,6 +41,7 @@
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
#include <LibWeb/CSS/StyleValues/ListStyleStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/FontCache.h>

View file

@ -40,6 +40,7 @@
#include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
#include <LibWeb/CSS/StyleValues/ListStyleStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
@ -1137,11 +1138,6 @@ ErrorOr<void> PositionValue::serialize(StringBuilder& builder) const
return {};
}
ErrorOr<String> OverflowStyleValue::to_string() const
{
return String::formatted("{} {}", TRY(m_properties.overflow_x->to_string()), TRY(m_properties.overflow_y->to_string()));
}
ErrorOr<String> PercentageStyleValue::to_string() const
{
return m_percentage.to_string();

View file

@ -627,35 +627,6 @@ private:
NonnullOwnPtr<CalcSum> m_expression;
};
class OverflowStyleValue final : public StyleValueWithDefaultOperators<OverflowStyleValue> {
public:
static ValueComparingNonnullRefPtr<OverflowStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> overflow_x, ValueComparingNonnullRefPtr<StyleValue> overflow_y)
{
return adopt_ref(*new OverflowStyleValue(move(overflow_x), move(overflow_y)));
}
virtual ~OverflowStyleValue() override = default;
ValueComparingNonnullRefPtr<StyleValue> overflow_x() const { return m_properties.overflow_x; }
ValueComparingNonnullRefPtr<StyleValue> overflow_y() const { return m_properties.overflow_y; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(OverflowStyleValue const& other) const { return m_properties == other.m_properties; }
private:
OverflowStyleValue(ValueComparingNonnullRefPtr<StyleValue> overflow_x, ValueComparingNonnullRefPtr<StyleValue> overflow_y)
: StyleValueWithDefaultOperators(Type::Overflow)
, m_properties { .overflow_x = move(overflow_x), .overflow_y = move(overflow_y) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<StyleValue> overflow_x;
ValueComparingNonnullRefPtr<StyleValue> overflow_y;
bool operator==(Properties const&) const = default;
} m_properties;
};
class PercentageStyleValue final : public StyleValueWithDefaultOperators<PercentageStyleValue> {
public:
static ValueComparingNonnullRefPtr<PercentageStyleValue> create(Percentage percentage)

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 "OverflowStyleValue.h"
namespace Web::CSS {
ErrorOr<String> OverflowStyleValue::to_string() const
{
return String::formatted("{} {}", TRY(m_properties.overflow_x->to_string()), TRY(m_properties.overflow_y->to_string()));
}
}

View file

@ -0,0 +1,45 @@
/*
* 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 OverflowStyleValue final : public StyleValueWithDefaultOperators<OverflowStyleValue> {
public:
static ValueComparingNonnullRefPtr<OverflowStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> overflow_x, ValueComparingNonnullRefPtr<StyleValue> overflow_y)
{
return adopt_ref(*new OverflowStyleValue(move(overflow_x), move(overflow_y)));
}
virtual ~OverflowStyleValue() override = default;
ValueComparingNonnullRefPtr<StyleValue> overflow_x() const { return m_properties.overflow_x; }
ValueComparingNonnullRefPtr<StyleValue> overflow_y() const { return m_properties.overflow_y; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(OverflowStyleValue const& other) const { return m_properties == other.m_properties; }
private:
OverflowStyleValue(ValueComparingNonnullRefPtr<StyleValue> overflow_x, ValueComparingNonnullRefPtr<StyleValue> overflow_y)
: StyleValueWithDefaultOperators(Type::Overflow)
, m_properties { .overflow_x = move(overflow_x), .overflow_y = move(overflow_y) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<StyleValue> overflow_x;
ValueComparingNonnullRefPtr<StyleValue> overflow_y;
bool operator==(Properties const&) const = default;
} m_properties;
};
}