1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibWeb: Add Ratio type to MediaFeatureValue

As noted, the Parser can't handle the `<number>` syntax for this - it
gets parsed instead by the `<number>` branch. We can't actually resolve
the ambiguity without making the Parser aware of what type each
media-feature is, but I will get to that soon. :^)
This commit is contained in:
Sam Atkins 2022-03-06 17:50:56 +00:00 committed by Andreas Kling
parent 5f93f1c161
commit deea129b8c
4 changed files with 50 additions and 7 deletions

View file

@ -13,6 +13,7 @@
#include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <LibWeb/CSS/GeneralEnclosed.h>
#include <LibWeb/CSS/Ratio.h>
#include <LibWeb/CSS/StyleValue.h>
namespace Web::CSS {
@ -30,6 +31,11 @@ public:
{
}
explicit MediaFeatureValue(Ratio ratio)
: m_value(move(ratio))
{
}
explicit MediaFeatureValue(Resolution resolution)
: m_value(move(resolution))
{
@ -45,6 +51,7 @@ public:
bool is_ident() const { return m_value.has<String>(); }
bool is_length() const { return m_value.has<Length>(); }
bool is_number() const { return m_value.has<double>(); }
bool is_ratio() const { return m_value.has<Ratio>(); }
bool is_resolution() const { return m_value.has<Resolution>(); }
bool is_same_type(MediaFeatureValue const& other) const;
@ -60,6 +67,12 @@ public:
return m_value.get<Length>();
}
Ratio const& ratio() const
{
VERIFY(is_ratio());
return m_value.get<Ratio>();
}
Resolution const& resolution() const
{
VERIFY(is_resolution());
@ -73,8 +86,7 @@ public:
}
private:
// TODO: Support <ratio> once we have that.
Variant<String, Length, Resolution, double> m_value;
Variant<String, Length, Ratio, Resolution, double> m_value;
};
// https://www.w3.org/TR/mediaqueries-4/#mq-features