LibWeb: Expose type and raw values of basic CSS types

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.
This commit is contained in:
Sam Atkins 2023-04-11 12:57:32 +01:00 committed by Andreas Kling
parent 89e55c5297
commit 5f2f780662
Notes: sideshowbarker 2024-07-17 04:49:48 +09:00
5 changed files with 11 additions and 0 deletions

View file

@ -30,6 +30,9 @@ public:
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;

View file

@ -27,6 +27,9 @@ public:
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;

View file

@ -79,6 +79,7 @@ public:
|| m_type == Type::Rlh;
}
Type type() const { return m_type; }
float raw_value() const { return m_value; }
CSSPixels to_px(Layout::Node const&) const;

View file

@ -31,6 +31,7 @@ public:
{
}
Type type() const { return m_type; }
float value() const { return m_value; }
i64 integer_value() const
{

View file

@ -28,6 +28,9 @@ public:
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;