1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:27:45 +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:
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; }

View file

@ -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"
]

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

View file

@ -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;

View file

@ -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,

View file

@ -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());