|
@@ -25,6 +25,7 @@ String MediaFeatureValue::to_string() const
|
|
|
return m_value.visit(
|
|
|
[](String const& ident) { return serialize_an_identifier(ident); },
|
|
|
[](Length const& length) { return length.to_string(); },
|
|
|
+ [](Ratio const& ratio) { return ratio.to_string(); },
|
|
|
[](Resolution const& resolution) { return resolution.to_string(); },
|
|
|
[](double number) { return String::number(number); });
|
|
|
}
|
|
@@ -34,6 +35,7 @@ bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const
|
|
|
return m_value.visit(
|
|
|
[&](String const&) { return other.is_ident(); },
|
|
|
[&](Length const&) { return other.is_length(); },
|
|
|
+ [&](Ratio const&) { return other.is_ratio(); },
|
|
|
[&](Resolution const&) { return other.is_resolution(); },
|
|
|
[&](double) { return other.is_number(); });
|
|
|
}
|
|
@@ -88,6 +90,9 @@ bool MediaFeature::evaluate(DOM::Window const& window) const
|
|
|
return queried_value.number() != 0;
|
|
|
if (queried_value.is_length())
|
|
|
return queried_value.length().raw_value() != 0;
|
|
|
+ // FIXME: I couldn't figure out from the spec how ratios should be evaluated in a boolean context.
|
|
|
+ if (queried_value.is_ratio())
|
|
|
+ return !queried_value.ratio().is_degenerate();
|
|
|
if (queried_value.is_resolution())
|
|
|
return queried_value.resolution().to_dots_per_pixel() != 0;
|
|
|
if (queried_value.is_ident())
|
|
@@ -181,6 +186,25 @@ bool MediaFeature::compare(DOM::Window const& window, MediaFeatureValue left, Co
|
|
|
VERIFY_NOT_REACHED();
|
|
|
}
|
|
|
|
|
|
+ if (left.is_ratio()) {
|
|
|
+ auto left_decimal = left.ratio().value();
|
|
|
+ auto right_decimal = right.ratio().value();
|
|
|
+
|
|
|
+ switch (comparison) {
|
|
|
+ case Comparison::Equal:
|
|
|
+ return left_decimal == right_decimal;
|
|
|
+ case Comparison::LessThan:
|
|
|
+ return left_decimal < right_decimal;
|
|
|
+ case Comparison::LessThanOrEqual:
|
|
|
+ return left_decimal <= right_decimal;
|
|
|
+ case Comparison::GreaterThan:
|
|
|
+ return left_decimal > right_decimal;
|
|
|
+ case Comparison::GreaterThanOrEqual:
|
|
|
+ return left_decimal >= right_decimal;
|
|
|
+ }
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
+ }
|
|
|
+
|
|
|
if (left.is_resolution()) {
|
|
|
auto left_dppx = left.resolution().to_dots_per_pixel();
|
|
|
auto right_dppx = right.resolution().to_dots_per_pixel();
|