mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +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
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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue