mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 09:52:31 +00:00
LibWeb/CSS: Parse media-feature values forgivingly
Instead of rejecting invalid media-feature values at parse time, we are expected to parse them, and then treat them as Unknown when evaluating their media query. To implement this, we first try to parse a valid value as before. If that fails, or we have any trailing tokens that could be part of a value, we then scoop up all the possible ComponentValues and treat that as an "unknown"-type MediaFeatureValue. This gets us 66 WPT passes.
This commit is contained in:
parent
72f50217b0
commit
9b8dc6b8d0
Notes:
github-actions[bot]
2025-05-23 09:19:18 +00:00
Author: https://github.com/AtkinsSJ
Commit: 9b8dc6b8d0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4817
15 changed files with 228 additions and 146 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <LibWeb/CSS/BooleanExpression.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/MediaFeatureID.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Ratio.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -51,6 +52,11 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
explicit MediaFeatureValue(Vector<Parser::ComponentValue> unknown_tokens)
|
||||
: m_value(move(unknown_tokens))
|
||||
{
|
||||
}
|
||||
|
||||
String to_string() const;
|
||||
|
||||
bool is_ident() const { return m_value.has<Keyword>(); }
|
||||
|
@ -58,6 +64,7 @@ public:
|
|||
bool is_integer() const { return m_value.has<IntegerOrCalculated>(); }
|
||||
bool is_ratio() const { return m_value.has<Ratio>(); }
|
||||
bool is_resolution() const { return m_value.has<ResolutionOrCalculated>(); }
|
||||
bool is_unknown() const { return m_value.has<Vector<Parser::ComponentValue>>(); }
|
||||
bool is_same_type(MediaFeatureValue const& other) const;
|
||||
|
||||
Keyword const& ident() const
|
||||
|
@ -91,7 +98,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Variant<Keyword, LengthOrCalculated, Ratio, ResolutionOrCalculated, IntegerOrCalculated> m_value;
|
||||
Variant<Keyword, LengthOrCalculated, Ratio, ResolutionOrCalculated, IntegerOrCalculated, Vector<Parser::ComponentValue>> m_value;
|
||||
};
|
||||
|
||||
// https://www.w3.org/TR/mediaqueries-4/#mq-features
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue