diff options
author | Adam Hodgen <ant1441@gmail.com> | 2021-02-21 17:41:00 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-28 18:19:52 +0100 |
commit | e169e241046f70fb9edda29fab42818d7d2bfb22 (patch) | |
tree | 766a734847a054b89fc945d427bbdaf801a18448 /Userland | |
parent | a375133cc5de6130860285bf8224801e7613ad4e (diff) | |
download | serenity-e169e241046f70fb9edda29fab42818d7d2bfb22.zip |
LibWeb: Parese the CSS "cursor" property
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ComputedValues.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Identifiers.json | 36 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 83 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 39 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 4 |
6 files changed, 166 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 9710ba96f3..4765507429 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -36,6 +36,7 @@ class InitialValues { public: static CSS::Float float_() { return CSS::Float::None; } static CSS::Clear clear() { return CSS::Clear::None; } + static CSS::Cursor cursor() { return CSS::Cursor::Auto; } 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; } @@ -60,6 +61,7 @@ class ComputedValues { public: CSS::Float float_() const { return m_noninherited.float_; } CSS::Clear clear() const { return m_noninherited.clear; } + CSS::Cursor cursor() const { return m_inherited.cursor; } CSS::Display display() const { return m_noninherited.display; } Optional<int> z_index() const { return m_noninherited.z_index; } CSS::TextAlign text_align() const { return m_inherited.text_align; } @@ -102,6 +104,7 @@ public: protected: struct { Color color { InitialValues::color() }; + CSS::Cursor cursor { InitialValues::cursor() }; CSS::TextAlign text_align { InitialValues::text_align() }; CSS::TextTransform text_transform { InitialValues::text_transform() }; CSS::WhiteSpace white_space { InitialValues::white_space() }; @@ -141,6 +144,7 @@ class ImmutableComputedValues final : public ComputedValues { class MutableComputedValues final : public ComputedValues { public: void set_color(const Color& color) { m_inherited.color = color; } + void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; } void set_background_color(const Color& color) { m_noninherited.background_color = color; } void set_float(CSS::Float value) { m_noninherited.float_ = value; } void set_clear(CSS::Clear value) { m_noninherited.clear = value; } diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json index 143905cf75..9a2380545e 100644 --- a/Userland/Libraries/LibWeb/CSS/Identifiers.json +++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json @@ -56,6 +56,8 @@ "-libweb-palette-window", "-libweb-palette-window-text", "absolute", + "alias", + "all-scroll", "auto", "blink", "block", @@ -63,21 +65,32 @@ "bolder", "both", "capitalize", + "cell", "center", "circle", "clip", + "col-resize", "column", "column-reverse", + "context-menu", + "copy", + "crosshair", "dashed", "decimal", + "default", "disc", "dotted", "double", + "e-resize", + "ew-resize", "fixed", "flex", "full-size-kana", "full-width", + "grab", + "grabbing", "groove", + "help", "hidden", "inline", "inline-block", @@ -91,26 +104,41 @@ "list-item", "lowercase", "medium", + "move", + "ne-resize", + "nesw-resize", + "no-drop", "none", "normal", + "not-allowed", "nowrap", + "n-resize", + "ns-resize", + "nw-resize", + "nwse-resize", "outset", "overline", + "pointer", "pre", "pre-line", "pre-wrap", + "progress", "relative", "ridge", "right", "row", + "row-resize", "row-reverse", "scroll", + "se-resize", "small", "smaller", "solid", "square", + "s-resize", "static", "sticky", + "sw-resize", "table", "table-caption", "table-cell", @@ -120,12 +148,18 @@ "table-header-group", "table-row", "table-row-group", + "text", "underline", "uppercase", "visible", + "vertical-text", + "wait", + "w-resize", "x-large", "x-small", "xx-large", "xx-small", - "xxx-large" + "xxx-large", + "zoom-in", + "zoom-out" ] diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index bcf79e9ae6..b3ce140060 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -390,6 +390,89 @@ Optional<CSS::Clear> StyleProperties::clear() const } } +Optional<CSS::Cursor> StyleProperties::cursor() const +{ + auto value = property(CSS::PropertyID::Cursor); + if (!value.has_value() || !value.value()->is_identifier()) + return {}; + switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) { + case CSS::ValueID::Auto: + return CSS::Cursor::Auto; + case CSS::ValueID::Default: + return CSS::Cursor::Default; + case CSS::ValueID::None: + return CSS::Cursor::None; + case CSS::ValueID::ContextMenu: + return CSS::Cursor::ContextMenu; + case CSS::ValueID::Help: + return CSS::Cursor::Help; + case CSS::ValueID::Pointer: + return CSS::Cursor::Pointer; + case CSS::ValueID::Progress: + return CSS::Cursor::Progress; + case CSS::ValueID::Wait: + return CSS::Cursor::Wait; + case CSS::ValueID::Cell: + return CSS::Cursor::Cell; + case CSS::ValueID::Crosshair: + return CSS::Cursor::Crosshair; + case CSS::ValueID::Text: + return CSS::Cursor::Text; + case CSS::ValueID::VerticalText: + return CSS::Cursor::VerticalText; + case CSS::ValueID::Alias: + return CSS::Cursor::Alias; + case CSS::ValueID::Copy: + return CSS::Cursor::Copy; + case CSS::ValueID::Move: + return CSS::Cursor::Move; + case CSS::ValueID::NoDrop: + return CSS::Cursor::NoDrop; + case CSS::ValueID::NotAllowed: + return CSS::Cursor::NotAllowed; + case CSS::ValueID::Grab: + return CSS::Cursor::Grab; + case CSS::ValueID::Grabbing: + return CSS::Cursor::Grabbing; + case CSS::ValueID::EResize: + return CSS::Cursor::EResize; + case CSS::ValueID::NResize: + return CSS::Cursor::NResize; + case CSS::ValueID::NeResize: + return CSS::Cursor::NeResize; + case CSS::ValueID::NwResize: + return CSS::Cursor::NwResize; + case CSS::ValueID::SResize: + return CSS::Cursor::SResize; + case CSS::ValueID::SeResize: + return CSS::Cursor::SeResize; + case CSS::ValueID::SwResize: + return CSS::Cursor::SwResize; + case CSS::ValueID::WResize: + return CSS::Cursor::WResize; + case CSS::ValueID::EwResize: + return CSS::Cursor::EwResize; + case CSS::ValueID::NsResize: + return CSS::Cursor::NsResize; + case CSS::ValueID::NeswResize: + return CSS::Cursor::NeswResize; + case CSS::ValueID::NwseResize: + return CSS::Cursor::NwseResize; + case CSS::ValueID::ColResize: + return CSS::Cursor::ColResize; + case CSS::ValueID::RowResize: + return CSS::Cursor::RowResize; + case CSS::ValueID::AllScroll: + return CSS::Cursor::AllScroll; + case CSS::ValueID::ZoomIn: + return CSS::Cursor::ZoomIn; + case CSS::ValueID::ZoomOut: + return CSS::Cursor::ZoomOut; + default: + return {}; + } +} + CSS::Display StyleProperties::display() const { auto value = property(CSS::PropertyID::Display); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 9777162850..4f25e378c4 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -64,6 +64,7 @@ public: CSS::Display display() const; Optional<CSS::Float> float_() const; Optional<CSS::Clear> clear() const; + Optional<CSS::Cursor> cursor() const; Optional<CSS::WhiteSpace> white_space() const; Optional<CSS::LineStyle> line_style(CSS::PropertyID) const; Optional<CSS::TextDecorationLine> text_decoration_line() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index bd41ce925a..7bacdcb810 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -121,6 +121,45 @@ enum class Clear { Both, }; +enum class Cursor { + Auto, + Default, + None, + ContextMenu, + Help, + Pointer, + Progress, + Wait, + Cell, + Crosshair, + Text, + VerticalText, + Alias, + Copy, + Move, + NoDrop, + NotAllowed, + Grab, + Grabbing, + EResize, + NResize, + NeResize, + NwResize, + SResize, + SeResize, + SwResize, + WResize, + EwResize, + NsResize, + NeswResize, + NwseResize, + ColResize, + RowResize, + AllScroll, + ZoomIn, + ZoomOut, +}; + enum class LineStyle { None, Hidden, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 5c708f42eb..7a72dfbca5 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -268,6 +268,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) if (overflow_y.has_value()) computed_values.set_overflow_y(overflow_y.value()); + auto cursor = specified_style.cursor(); + if (cursor.has_value()) + computed_values.set_cursor(cursor.value()); + auto text_decoration_line = specified_style.text_decoration_line(); if (text_decoration_line.has_value()) computed_values.set_text_decoration_line(text_decoration_line.value()); |