зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1484146 - Use AspectRatio directly for RangeOrOperator::evaluate. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D3587 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
def24933ef
Коммит
f2d834dde8
|
@ -118,11 +118,8 @@ where
|
|||
};
|
||||
|
||||
let size = get_size(device);
|
||||
RangeOrOperator::evaluate(
|
||||
range_or_operator,
|
||||
Some(size.height.0 as u64 * query_value.0 as u64),
|
||||
size.width.0 as u64 * query_value.1 as u64,
|
||||
)
|
||||
let value = AspectRatio(size.width.0 as u32, size.height.0 as u32);
|
||||
RangeOrOperator::evaluate_with_query_value(range_or_operator, query_value, value)
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/mediaqueries-4/#aspect-ratio
|
||||
|
|
|
@ -14,6 +14,7 @@ use cssparser::{Parser, Token};
|
|||
use context::QuirksMode;
|
||||
use num_traits::Zero;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::cmp::{PartialOrd, Ordering};
|
||||
use std::fmt::{self, Write};
|
||||
use str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
|
@ -45,6 +46,15 @@ impl ToCss for AspectRatio {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for AspectRatio {
|
||||
fn partial_cmp(&self, other: &AspectRatio) -> Option<Ordering> {
|
||||
u64::partial_cmp(
|
||||
&(self.0 as u64 * other.1 as u64),
|
||||
&(self.1 as u64 * other.0 as u64),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of matching that should be performed on a media feature value.
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq)]
|
||||
pub enum Range {
|
||||
|
@ -97,7 +107,8 @@ pub enum RangeOrOperator {
|
|||
}
|
||||
|
||||
impl RangeOrOperator {
|
||||
/// Evaluate a given range given a query value and a value from the browser.
|
||||
/// Evaluate a given range given an optional query value and a value from
|
||||
/// the browser.
|
||||
pub fn evaluate<T>(
|
||||
range_or_op: Option<Self>,
|
||||
query_value: Option<T>,
|
||||
|
@ -106,13 +117,22 @@ impl RangeOrOperator {
|
|||
where
|
||||
T: PartialOrd + Zero
|
||||
{
|
||||
use std::cmp::Ordering;
|
||||
|
||||
let query_value = match query_value {
|
||||
Some(v) => v,
|
||||
None => return value != Zero::zero(),
|
||||
};
|
||||
match query_value {
|
||||
Some(v) => Self::evaluate_with_query_value(range_or_op, v, value),
|
||||
None => !value.is_zero(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate a given range given a non-optional query value and a value from
|
||||
/// the browser.
|
||||
pub fn evaluate_with_query_value<T>(
|
||||
range_or_op: Option<Self>,
|
||||
query_value: T,
|
||||
value: T,
|
||||
) -> bool
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
let cmp = match value.partial_cmp(&query_value) {
|
||||
Some(c) => c,
|
||||
None => return false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче