mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibWeb: Add EdgeStyleValue
This represents a single edge and offset, this will be needed for the values of background-position-x/y.
This commit is contained in:
parent
d5e61168b2
commit
2a659693bc
6 changed files with 87 additions and 0 deletions
|
@ -78,6 +78,7 @@ set(SOURCES
|
|||
CSS/StyleValues/ColorStyleValue.cpp
|
||||
CSS/StyleValues/ConicGradientStyleValue.cpp
|
||||
CSS/StyleValues/ContentStyleValue.cpp
|
||||
CSS/StyleValues/EdgeStyleValue.cpp
|
||||
CSS/StyleValues/FilterValueListStyleValue.cpp
|
||||
CSS/StyleValues/FlexFlowStyleValue.cpp
|
||||
CSS/StyleValues/FlexStyleValue.cpp
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexFlowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
|
@ -138,6 +139,12 @@ ContentStyleValue const& StyleValue::as_content() const
|
|||
return static_cast<ContentStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
EdgeStyleValue const& StyleValue::as_edge() const
|
||||
{
|
||||
VERIFY(is_edge());
|
||||
return static_cast<EdgeStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
FilterValueListStyleValue const& StyleValue::as_filter_value_list() const
|
||||
{
|
||||
VERIFY(is_filter_value_list());
|
||||
|
|
|
@ -99,6 +99,7 @@ public:
|
|||
Color,
|
||||
ConicGradient,
|
||||
Content,
|
||||
Edge,
|
||||
FilterValueList,
|
||||
Flex,
|
||||
FlexFlow,
|
||||
|
@ -148,6 +149,7 @@ public:
|
|||
bool is_color() const { return type() == Type::Color; }
|
||||
bool is_conic_gradient() const { return type() == Type::ConicGradient; }
|
||||
bool is_content() const { return type() == Type::Content; }
|
||||
bool is_edge() const { return type() == Type::Edge; }
|
||||
bool is_filter_value_list() const { return type() == Type::FilterValueList; }
|
||||
bool is_flex() const { return type() == Type::Flex; }
|
||||
bool is_flex_flow() const { return type() == Type::FlexFlow; }
|
||||
|
@ -195,6 +197,7 @@ public:
|
|||
ColorStyleValue const& as_color() const;
|
||||
ConicGradientStyleValue const& as_conic_gradient() const;
|
||||
ContentStyleValue const& as_content() const;
|
||||
EdgeStyleValue const& as_edge() const;
|
||||
FilterValueListStyleValue const& as_filter_value_list() const;
|
||||
FlexFlowStyleValue const& as_flex_flow() const;
|
||||
FlexStyleValue const& as_flex() const;
|
||||
|
@ -240,6 +243,7 @@ public:
|
|||
ColorStyleValue& as_color() { return const_cast<ColorStyleValue&>(const_cast<StyleValue const&>(*this).as_color()); }
|
||||
ConicGradientStyleValue& as_conic_gradient() { return const_cast<ConicGradientStyleValue&>(const_cast<StyleValue const&>(*this).as_conic_gradient()); }
|
||||
ContentStyleValue& as_content() { return const_cast<ContentStyleValue&>(const_cast<StyleValue const&>(*this).as_content()); }
|
||||
EdgeStyleValue& as_edge() { return const_cast<EdgeStyleValue&>(const_cast<StyleValue const&>(*this).as_edge()); }
|
||||
FilterValueListStyleValue& as_filter_value_list() { return const_cast<FilterValueListStyleValue&>(const_cast<StyleValue const&>(*this).as_filter_value_list()); }
|
||||
FlexFlowStyleValue& as_flex_flow() { return const_cast<FlexFlowStyleValue&>(const_cast<StyleValue const&>(*this).as_flex_flow()); }
|
||||
FlexStyleValue& as_flex() { return const_cast<FlexStyleValue&>(const_cast<StyleValue const&>(*this).as_flex()); }
|
||||
|
|
30
Userland/Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
Normal file
30
Userland/Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "EdgeStyleValue.h"
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ErrorOr<String> EdgeStyleValue::to_string() const
|
||||
{
|
||||
auto to_string = [](PositionEdge edge) {
|
||||
switch (edge) {
|
||||
case PositionEdge::Left:
|
||||
return "left";
|
||||
case PositionEdge::Right:
|
||||
return "right";
|
||||
case PositionEdge::Top:
|
||||
return "top";
|
||||
case PositionEdge::Bottom:
|
||||
return "bottom";
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
};
|
||||
|
||||
return String::formatted("{} {}", to_string(m_properties.edge), TRY(m_properties.offset.to_string()));
|
||||
}
|
||||
|
||||
}
|
44
Userland/Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
Normal file
44
Userland/Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/Enums.h>
|
||||
#include <LibWeb/CSS/PercentageOr.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class EdgeStyleValue final : public StyleValueWithDefaultOperators<EdgeStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<EdgeStyleValue> create(PositionEdge edge, LengthPercentage const& offset)
|
||||
{
|
||||
return adopt_ref(*new EdgeStyleValue(edge, offset));
|
||||
}
|
||||
virtual ~EdgeStyleValue() override = default;
|
||||
|
||||
PositionEdge edge() const { return m_properties.edge; }
|
||||
LengthPercentage const& offset() const { return m_properties.offset; }
|
||||
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
|
||||
bool properties_equal(EdgeStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
EdgeStyleValue(PositionEdge edge, LengthPercentage const& offset)
|
||||
: StyleValueWithDefaultOperators(Type::Edge)
|
||||
, m_properties { .edge = edge, .offset = offset }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
PositionEdge edge;
|
||||
LengthPercentage offset;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
|
@ -53,6 +53,7 @@ class CSSStyleRule;
|
|||
class CSSStyleSheet;
|
||||
class CSSSupportsRule;
|
||||
class Display;
|
||||
class EdgeStyleValue;
|
||||
class ElementInlineCSSStyleDeclaration;
|
||||
class ExplicitGridTrack;
|
||||
class FilterValueListStyleValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue