Skip to content

Commit

Permalink
LibWeb: Expose type and raw values of basic CSS types
Browse files Browse the repository at this point in the history
This makes it possible to do arithmetic on them without having to
resolve to their canonical unit, which often requires context
information that is not available until the last minute. For example, a
Length cannot be resolved to px without knowing the font size, parent
element's size, etc.

Only Length currently requires such context, but treating all these
types the same means that code that manipulates them does not need to
know or care if a new unit gets added that does require contextual
information.
  • Loading branch information
AtkinsSJ authored and awesomekling committed Apr 13, 2023
1 parent 89e55c5 commit 5f2f780
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Angle {
ErrorOr<String> to_string() const;
float to_degrees() const;

Type type() const { return m_type; }
float raw_value() const { return m_value; }

bool operator==(Angle const& other) const
{
return m_type == other.m_type && m_value == other.m_value;
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Frequency.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Frequency {
ErrorOr<String> to_string() const;
float to_hertz() const;

Type type() const { return m_type; }
float raw_value() const { return m_value; }

bool operator==(Frequency const& other) const
{
return m_type == other.m_type && m_value == other.m_value;
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/CSS/Length.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Length {
|| m_type == Type::Rlh;
}

Type type() const { return m_type; }
float raw_value() const { return m_value; }

CSSPixels to_px(Layout::Node const&) const;
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/CSS/Number.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Number {
{
}

Type type() const { return m_type; }
float value() const { return m_value; }
i64 integer_value() const
{
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Time {
ErrorOr<String> to_string() const;
float to_seconds() const;

Type type() const { return m_type; }
float raw_value() const { return m_value; }

bool operator==(Time const& other) const
{
return m_type == other.m_type && m_value == other.m_value;
Expand Down

0 comments on commit 5f2f780

Please sign in to comment.