mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibWeb: Use IdentifierStyleValue for CSS 'position'
This commit is contained in:
parent
3247ea3581
commit
dd2e8b7dd0
6 changed files with 38 additions and 15 deletions
|
@ -386,6 +386,16 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
|
|||
return CSS::ValueID::VendorSpecificCenter;
|
||||
if (string.equals_ignoring_case("-libweb-link"))
|
||||
return CSS::ValueID::VendorSpecificLink;
|
||||
if (string.equals_ignoring_case("static"))
|
||||
return CSS::ValueID::Static;
|
||||
if (string.equals_ignoring_case("relative"))
|
||||
return CSS::ValueID::Relative;
|
||||
if (string.equals_ignoring_case("absolute"))
|
||||
return CSS::ValueID::Absolute;
|
||||
if (string.equals_ignoring_case("fixed"))
|
||||
return CSS::ValueID::Fixed;
|
||||
if (string.equals_ignoring_case("sticky"))
|
||||
return CSS::ValueID::Sticky;
|
||||
if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive))
|
||||
return value_id_for_palette_string(string.substring_view(16, string.length() - 16));
|
||||
return {};
|
||||
|
|
|
@ -225,20 +225,25 @@ Optional<int> StyleProperties::z_index() const
|
|||
return static_cast<int>(value.value()->to_length().raw_value());
|
||||
}
|
||||
|
||||
CSS::Position StyleProperties::position() const
|
||||
Optional<CSS::Position> StyleProperties::position() const
|
||||
{
|
||||
if (property(CSS::PropertyID::Position).has_value()) {
|
||||
String position_string = string_or_fallback(CSS::PropertyID::Position, "static");
|
||||
if (position_string == "relative")
|
||||
return CSS::Position::Relative;
|
||||
if (position_string == "absolute")
|
||||
return CSS::Position::Absolute;
|
||||
if (position_string == "sticky")
|
||||
return CSS::Position::Sticky;
|
||||
if (position_string == "fixed")
|
||||
return CSS::Position::Fixed;
|
||||
auto value = property(CSS::PropertyID::Position);
|
||||
if (!value.has_value() || !value.value()->is_identifier())
|
||||
return {};
|
||||
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
|
||||
case CSS::ValueID::Static:
|
||||
return CSS::Position::Static;
|
||||
case CSS::ValueID::Relative:
|
||||
return CSS::Position::Relative;
|
||||
case CSS::ValueID::Absolute:
|
||||
return CSS::Position::Absolute;
|
||||
case CSS::ValueID::Fixed:
|
||||
return CSS::Position::Fixed;
|
||||
case CSS::ValueID::Sticky:
|
||||
return CSS::Position::Sticky;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
return CSS::Position::Static;
|
||||
}
|
||||
|
||||
bool StyleProperties::operator==(const StyleProperties& other) const
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
bool operator==(const StyleProperties&) const;
|
||||
bool operator!=(const StyleProperties& other) const { return !(*this == other); }
|
||||
|
||||
CSS::Position position() const;
|
||||
Optional<CSS::Position> position() const;
|
||||
Optional<int> z_index() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -117,6 +117,11 @@ enum class ValueID {
|
|||
XxLarge,
|
||||
XxSmall,
|
||||
XxxLarge,
|
||||
Static,
|
||||
Relative,
|
||||
Absolute,
|
||||
Fixed,
|
||||
Sticky,
|
||||
};
|
||||
|
||||
enum class Position {
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
static CSS::Clear clear() { return CSS::Clear::None; }
|
||||
static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
|
||||
static CSS::TextAlign text_align() { return CSS::TextAlign::Left; }
|
||||
static CSS::Position position() { return CSS::Position::Static; }
|
||||
};
|
||||
|
||||
struct BorderData {
|
||||
|
@ -76,7 +77,7 @@ protected:
|
|||
CSS::Clear m_clear { InitialValues::clear() };
|
||||
Optional<int> m_z_index;
|
||||
CSS::TextAlign m_text_align { InitialValues::text_align() };
|
||||
CSS::Position m_position;
|
||||
CSS::Position m_position { InitialValues::position() };
|
||||
CSS::WhiteSpace m_white_space { InitialValues::white_space() };
|
||||
CSS::Length m_width;
|
||||
CSS::Length m_min_width;
|
||||
|
|
|
@ -219,7 +219,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
|||
{
|
||||
auto& style = static_cast<MutableLayoutStyle&>(m_style);
|
||||
|
||||
style.set_position(specified_style.position());
|
||||
auto position = specified_style.position();
|
||||
if (position.has_value())
|
||||
style.set_position(position.value());
|
||||
|
||||
auto text_align = specified_style.text_align();
|
||||
if (text_align.has_value())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue