mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Add GridTrackSizeStyleValue
Add GridTrackSizeStyleValue for the use of CSS properties grid-template-columns, grid-template-rows.
This commit is contained in:
parent
ca286fc220
commit
0148260b5f
Notes:
sideshowbarker
2024-07-17 11:34:34 +09:00
Author: https://github.com/martinfalisse Commit: https://github.com/SerenityOS/serenity/commit/0148260b5f Pull-request: https://github.com/SerenityOS/serenity/pull/14996
3 changed files with 55 additions and 0 deletions
|
@ -150,6 +150,12 @@ LengthStyleValue const& StyleValue::as_length() const
|
|||
return static_cast<LengthStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
GridTrackSizeStyleValue const& StyleValue::as_grid_track_size() const
|
||||
{
|
||||
VERIFY(is_grid_track_size());
|
||||
return static_cast<GridTrackSizeStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
LinearGradientStyleValue const& StyleValue::as_linear_gradient() const
|
||||
{
|
||||
VERIFY(is_linear_gradient());
|
||||
|
@ -1198,6 +1204,25 @@ bool FrequencyStyleValue::equals(StyleValue const& other) const
|
|||
return m_frequency == other.as_frequency().m_frequency;
|
||||
}
|
||||
|
||||
String GridTrackSizeStyleValue::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < m_grid_track.size(); i++) {
|
||||
builder.append(m_grid_track[i].to_string());
|
||||
if (i != m_grid_track.size() - 1)
|
||||
builder.append(" "sv);
|
||||
}
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
bool GridTrackSizeStyleValue::equals(StyleValue const& other) const
|
||||
{
|
||||
if (type() != other.type())
|
||||
return false;
|
||||
auto const& typed_other = other.as_grid_track_size();
|
||||
return m_grid_track == typed_other.grid_track_size();
|
||||
}
|
||||
|
||||
String IdentifierStyleValue::to_string() const
|
||||
{
|
||||
return CSS::string_from_value_id(m_id);
|
||||
|
@ -1906,6 +1931,11 @@ NonnullRefPtr<ColorStyleValue> ColorStyleValue::create(Color color)
|
|||
return adopt_ref(*new ColorStyleValue(color));
|
||||
}
|
||||
|
||||
NonnullRefPtr<GridTrackSizeStyleValue> GridTrackSizeStyleValue::create(Vector<CSS::GridTrackSize> grid_track_size)
|
||||
{
|
||||
return adopt_ref(*new GridTrackSizeStyleValue(grid_track_size));
|
||||
}
|
||||
|
||||
NonnullRefPtr<RectStyleValue> RectStyleValue::create(EdgeRect rect)
|
||||
{
|
||||
return adopt_ref(*new RectStyleValue(rect));
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <LibWeb/CSS/Display.h>
|
||||
#include <LibWeb/CSS/Enums.h>
|
||||
#include <LibWeb/CSS/Frequency.h>
|
||||
#include <LibWeb/CSS/GridTrackSize.h>
|
||||
#include <LibWeb/CSS/Length.h>
|
||||
#include <LibWeb/CSS/Number.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
|
@ -130,6 +131,7 @@ public:
|
|||
FlexFlow,
|
||||
Font,
|
||||
Frequency,
|
||||
GridTrackSize,
|
||||
Identifier,
|
||||
Image,
|
||||
Inherit,
|
||||
|
@ -171,6 +173,7 @@ public:
|
|||
bool is_flex_flow() const { return type() == Type::FlexFlow; }
|
||||
bool is_font() const { return type() == Type::Font; }
|
||||
bool is_frequency() const { return type() == Type::Frequency; }
|
||||
bool is_grid_track_size() const { return type() == Type::GridTrackSize; }
|
||||
bool is_identifier() const { return type() == Type::Identifier; }
|
||||
bool is_image() const { return type() == Type::Image; }
|
||||
bool is_inherit() const { return type() == Type::Inherit; }
|
||||
|
@ -210,6 +213,7 @@ public:
|
|||
FlexStyleValue const& as_flex() const;
|
||||
FontStyleValue const& as_font() const;
|
||||
FrequencyStyleValue const& as_frequency() const;
|
||||
GridTrackSizeStyleValue const& as_grid_track_size() const;
|
||||
IdentifierStyleValue const& as_identifier() const;
|
||||
ImageStyleValue const& as_image() const;
|
||||
InheritStyleValue const& as_inherit() const;
|
||||
|
@ -247,6 +251,7 @@ public:
|
|||
FlexStyleValue& as_flex() { return const_cast<FlexStyleValue&>(const_cast<StyleValue const&>(*this).as_flex()); }
|
||||
FontStyleValue& as_font() { return const_cast<FontStyleValue&>(const_cast<StyleValue const&>(*this).as_font()); }
|
||||
FrequencyStyleValue& as_frequency() { return const_cast<FrequencyStyleValue&>(const_cast<StyleValue const&>(*this).as_frequency()); }
|
||||
GridTrackSizeStyleValue& as_grid_track_size() { return const_cast<GridTrackSizeStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_track_size()); }
|
||||
IdentifierStyleValue& as_identifier() { return const_cast<IdentifierStyleValue&>(const_cast<StyleValue const&>(*this).as_identifier()); }
|
||||
ImageStyleValue& as_image() { return const_cast<ImageStyleValue&>(const_cast<StyleValue const&>(*this).as_image()); }
|
||||
InheritStyleValue& as_inherit() { return const_cast<InheritStyleValue&>(const_cast<StyleValue const&>(*this).as_inherit()); }
|
||||
|
@ -897,6 +902,25 @@ private:
|
|||
Frequency m_frequency;
|
||||
};
|
||||
|
||||
class GridTrackSizeStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<GridTrackSizeStyleValue> create(Vector<CSS::GridTrackSize> grid_track_size);
|
||||
virtual ~GridTrackSizeStyleValue() override = default;
|
||||
|
||||
Vector<CSS::GridTrackSize> grid_track_size() const { return m_grid_track; }
|
||||
virtual String to_string() const override;
|
||||
virtual bool equals(StyleValue const& other) const override;
|
||||
|
||||
private:
|
||||
explicit GridTrackSizeStyleValue(Vector<CSS::GridTrackSize> grid_track_size)
|
||||
: StyleValue(Type::GridTrackSize)
|
||||
, m_grid_track(grid_track_size)
|
||||
{
|
||||
}
|
||||
|
||||
Vector<CSS::GridTrackSize> m_grid_track;
|
||||
};
|
||||
|
||||
class IdentifierStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<IdentifierStyleValue> create(CSS::ValueID id)
|
||||
|
|
|
@ -59,6 +59,7 @@ class FrequencyPercentage;
|
|||
class FrequencyStyleValue;
|
||||
class GridTrackPlacement;
|
||||
class GridTrackSize;
|
||||
class GridTrackSizeStyleValue;
|
||||
class IdentifierStyleValue;
|
||||
class ImageStyleValue;
|
||||
class InheritStyleValue;
|
||||
|
|
Loading…
Reference in a new issue