mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 04:13:11 +00:00
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:
parent
89e55c5297
commit
5f2f780662
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
float value() const { return m_value; }
|
||||
i64 integer_value() const
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue