1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:07:36 +00:00

LibWeb: Parese the CSS "cursor" property

This commit is contained in:
Adam Hodgen 2021-02-21 17:41:00 +00:00 committed by Andreas Kling
parent a375133cc5
commit e169e24104
6 changed files with 166 additions and 1 deletions

View file

@ -36,6 +36,7 @@ class InitialValues {
public: public:
static CSS::Float float_() { return CSS::Float::None; } static CSS::Float float_() { return CSS::Float::None; }
static CSS::Clear clear() { return CSS::Clear::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::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; } static CSS::Position position() { return CSS::Position::Static; }
@ -60,6 +61,7 @@ class ComputedValues {
public: public:
CSS::Float float_() const { return m_noninherited.float_; } CSS::Float float_() const { return m_noninherited.float_; }
CSS::Clear clear() const { return m_noninherited.clear; } CSS::Clear clear() const { return m_noninherited.clear; }
CSS::Cursor cursor() const { return m_inherited.cursor; }
CSS::Display display() const { return m_noninherited.display; } CSS::Display display() const { return m_noninherited.display; }
Optional<int> z_index() const { return m_noninherited.z_index; } Optional<int> z_index() const { return m_noninherited.z_index; }
CSS::TextAlign text_align() const { return m_inherited.text_align; } CSS::TextAlign text_align() const { return m_inherited.text_align; }
@ -102,6 +104,7 @@ public:
protected: protected:
struct { struct {
Color color { InitialValues::color() }; Color color { InitialValues::color() };
CSS::Cursor cursor { InitialValues::cursor() };
CSS::TextAlign text_align { InitialValues::text_align() }; CSS::TextAlign text_align { InitialValues::text_align() };
CSS::TextTransform text_transform { InitialValues::text_transform() }; CSS::TextTransform text_transform { InitialValues::text_transform() };
CSS::WhiteSpace white_space { InitialValues::white_space() }; CSS::WhiteSpace white_space { InitialValues::white_space() };
@ -141,6 +144,7 @@ class ImmutableComputedValues final : public ComputedValues {
class MutableComputedValues final : public ComputedValues { class MutableComputedValues final : public ComputedValues {
public: public:
void set_color(const Color& color) { m_inherited.color = color; } 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_background_color(const Color& color) { m_noninherited.background_color = color; }
void set_float(CSS::Float value) { m_noninherited.float_ = value; } void set_float(CSS::Float value) { m_noninherited.float_ = value; }
void set_clear(CSS::Clear value) { m_noninherited.clear = value; } void set_clear(CSS::Clear value) { m_noninherited.clear = value; }

View file

@ -56,6 +56,8 @@
"-libweb-palette-window", "-libweb-palette-window",
"-libweb-palette-window-text", "-libweb-palette-window-text",
"absolute", "absolute",
"alias",
"all-scroll",
"auto", "auto",
"blink", "blink",
"block", "block",
@ -63,21 +65,32 @@
"bolder", "bolder",
"both", "both",
"capitalize", "capitalize",
"cell",
"center", "center",
"circle", "circle",
"clip", "clip",
"col-resize",
"column", "column",
"column-reverse", "column-reverse",
"context-menu",
"copy",
"crosshair",
"dashed", "dashed",
"decimal", "decimal",
"default",
"disc", "disc",
"dotted", "dotted",
"double", "double",
"e-resize",
"ew-resize",
"fixed", "fixed",
"flex", "flex",
"full-size-kana", "full-size-kana",
"full-width", "full-width",
"grab",
"grabbing",
"groove", "groove",
"help",
"hidden", "hidden",
"inline", "inline",
"inline-block", "inline-block",
@ -91,26 +104,41 @@
"list-item", "list-item",
"lowercase", "lowercase",
"medium", "medium",
"move",
"ne-resize",
"nesw-resize",
"no-drop",
"none", "none",
"normal", "normal",
"not-allowed",
"nowrap", "nowrap",
"n-resize",
"ns-resize",
"nw-resize",
"nwse-resize",
"outset", "outset",
"overline", "overline",
"pointer",
"pre", "pre",
"pre-line", "pre-line",
"pre-wrap", "pre-wrap",
"progress",
"relative", "relative",
"ridge", "ridge",
"right", "right",
"row", "row",
"row-resize",
"row-reverse", "row-reverse",
"scroll", "scroll",
"se-resize",
"small", "small",
"smaller", "smaller",
"solid", "solid",
"square", "square",
"s-resize",
"static", "static",
"sticky", "sticky",
"sw-resize",
"table", "table",
"table-caption", "table-caption",
"table-cell", "table-cell",
@ -120,12 +148,18 @@
"table-header-group", "table-header-group",
"table-row", "table-row",
"table-row-group", "table-row-group",
"text",
"underline", "underline",
"uppercase", "uppercase",
"visible", "visible",
"vertical-text",
"wait",
"w-resize",
"x-large", "x-large",
"x-small", "x-small",
"xx-large", "xx-large",
"xx-small", "xx-small",
"xxx-large" "xxx-large",
"zoom-in",
"zoom-out"
] ]

View file

@ -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 CSS::Display StyleProperties::display() const
{ {
auto value = property(CSS::PropertyID::Display); auto value = property(CSS::PropertyID::Display);

View file

@ -64,6 +64,7 @@ public:
CSS::Display display() const; CSS::Display display() const;
Optional<CSS::Float> float_() const; Optional<CSS::Float> float_() const;
Optional<CSS::Clear> clear() const; Optional<CSS::Clear> clear() const;
Optional<CSS::Cursor> cursor() const;
Optional<CSS::WhiteSpace> white_space() const; Optional<CSS::WhiteSpace> white_space() const;
Optional<CSS::LineStyle> line_style(CSS::PropertyID) const; Optional<CSS::LineStyle> line_style(CSS::PropertyID) const;
Optional<CSS::TextDecorationLine> text_decoration_line() const; Optional<CSS::TextDecorationLine> text_decoration_line() const;

View file

@ -121,6 +121,45 @@ enum class Clear {
Both, 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 { enum class LineStyle {
None, None,
Hidden, Hidden,

View file

@ -268,6 +268,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
if (overflow_y.has_value()) if (overflow_y.has_value())
computed_values.set_overflow_y(overflow_y.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(); auto text_decoration_line = specified_style.text_decoration_line();
if (text_decoration_line.has_value()) if (text_decoration_line.has_value())
computed_values.set_text_decoration_line(text_decoration_line.value()); computed_values.set_text_decoration_line(text_decoration_line.value());