1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

LibWeb: Use IdentifierStyleValue for CSS 'position'

This commit is contained in:
Andreas Kling 2020-12-14 18:47:00 +01:00
parent 3247ea3581
commit dd2e8b7dd0
6 changed files with 38 additions and 15 deletions

View file

@ -386,6 +386,16 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
return CSS::ValueID::VendorSpecificCenter; return CSS::ValueID::VendorSpecificCenter;
if (string.equals_ignoring_case("-libweb-link")) if (string.equals_ignoring_case("-libweb-link"))
return CSS::ValueID::VendorSpecificLink; 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)) if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive))
return value_id_for_palette_string(string.substring_view(16, string.length() - 16)); return value_id_for_palette_string(string.substring_view(16, string.length() - 16));
return {}; return {};

View file

@ -225,20 +225,25 @@ Optional<int> StyleProperties::z_index() const
return static_cast<int>(value.value()->to_length().raw_value()); 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()) { auto value = property(CSS::PropertyID::Position);
String position_string = string_or_fallback(CSS::PropertyID::Position, "static"); if (!value.has_value() || !value.value()->is_identifier())
if (position_string == "relative") return {};
return CSS::Position::Relative; switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
if (position_string == "absolute") case CSS::ValueID::Static:
return CSS::Position::Absolute; return CSS::Position::Static;
if (position_string == "sticky") case CSS::ValueID::Relative:
return CSS::Position::Sticky; return CSS::Position::Relative;
if (position_string == "fixed") case CSS::ValueID::Absolute:
return CSS::Position::Fixed; 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 bool StyleProperties::operator==(const StyleProperties& other) const

View file

@ -79,7 +79,7 @@ public:
bool operator==(const StyleProperties&) const; bool operator==(const StyleProperties&) const;
bool operator!=(const StyleProperties& other) const { return !(*this == other); } bool operator!=(const StyleProperties& other) const { return !(*this == other); }
CSS::Position position() const; Optional<CSS::Position> position() const;
Optional<int> z_index() const; Optional<int> z_index() const;
private: private:

View file

@ -117,6 +117,11 @@ enum class ValueID {
XxLarge, XxLarge,
XxSmall, XxSmall,
XxxLarge, XxxLarge,
Static,
Relative,
Absolute,
Fixed,
Sticky,
}; };
enum class Position { enum class Position {

View file

@ -38,6 +38,7 @@ public:
static CSS::Clear clear() { return CSS::Clear::None; } static CSS::Clear clear() { return CSS::Clear::None; }
static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; } static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
static CSS::TextAlign text_align() { return CSS::TextAlign::Left; } static CSS::TextAlign text_align() { return CSS::TextAlign::Left; }
static CSS::Position position() { return CSS::Position::Static; }
}; };
struct BorderData { struct BorderData {
@ -76,7 +77,7 @@ protected:
CSS::Clear m_clear { InitialValues::clear() }; CSS::Clear m_clear { InitialValues::clear() };
Optional<int> m_z_index; Optional<int> m_z_index;
CSS::TextAlign m_text_align { InitialValues::text_align() }; 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::WhiteSpace m_white_space { InitialValues::white_space() };
CSS::Length m_width; CSS::Length m_width;
CSS::Length m_min_width; CSS::Length m_min_width;

View file

@ -219,7 +219,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
{ {
auto& style = static_cast<MutableLayoutStyle&>(m_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(); auto text_align = specified_style.text_align();
if (text_align.has_value()) if (text_align.has_value())