зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #20064 - style: Trivially cleanup length parsing (from emilio:cleanup-length-parsing); r=nox
Mostly formatting signatures properly, but also removing useless functions and stuff. Source-Repo: https://github.com/servo/servo Source-Revision: d092c2e877fdbae241d6f4b53d61701d7d50e346 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : c39ea1e8984d9d43feb9e515379bd0ea3bf625a9
This commit is contained in:
Родитель
7166c3c714
Коммит
37ad4728ac
|
@ -113,6 +113,12 @@ impl<'a> ParserContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether we're in a @page rule.
|
||||
#[inline]
|
||||
pub fn in_page_rule(&self) -> bool {
|
||||
self.rule_type.map_or(false, |rule_type| rule_type == CssRuleType::Page)
|
||||
}
|
||||
|
||||
/// Get the rule type, which assumes that one is available.
|
||||
pub fn rule_type(&self) -> CssRuleType {
|
||||
self.rule_type.expect("Rule type expected, but none was found.")
|
||||
|
|
|
@ -16,7 +16,6 @@ use std::cmp;
|
|||
use std::ops::{Add, Mul};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use stylesheets::CssRuleType;
|
||||
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
||||
use values::{Auto, CSSFloat, Either, None_, Normal};
|
||||
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
|
||||
|
@ -422,9 +421,11 @@ impl Mul<CSSFloat> for NoCalcLength {
|
|||
|
||||
impl NoCalcLength {
|
||||
/// Parse a given absolute or relative dimension.
|
||||
pub fn parse_dimension(context: &ParserContext, value: CSSFloat, unit: &str)
|
||||
-> Result<NoCalcLength, ()> {
|
||||
let in_page_rule = context.rule_type.map_or(false, |rule_type| rule_type == CssRuleType::Page);
|
||||
pub fn parse_dimension(
|
||||
context: &ParserContext,
|
||||
value: CSSFloat,
|
||||
unit: &str,
|
||||
) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { unit,
|
||||
"px" => Ok(NoCalcLength::Absolute(AbsoluteLength::Px(value))),
|
||||
"in" => Ok(NoCalcLength::Absolute(AbsoluteLength::In(value))),
|
||||
|
@ -440,25 +441,25 @@ impl NoCalcLength {
|
|||
"rem" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Rem(value))),
|
||||
// viewport percentages
|
||||
"vw" => {
|
||||
if in_page_rule {
|
||||
if context.in_page_rule() {
|
||||
return Err(())
|
||||
}
|
||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value)))
|
||||
},
|
||||
"vh" => {
|
||||
if in_page_rule {
|
||||
if context.in_page_rule() {
|
||||
return Err(())
|
||||
}
|
||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value)))
|
||||
},
|
||||
"vmin" => {
|
||||
if in_page_rule {
|
||||
if context.in_page_rule() {
|
||||
return Err(())
|
||||
}
|
||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value)))
|
||||
},
|
||||
"vmax" => {
|
||||
if in_page_rule {
|
||||
if context.in_page_rule() {
|
||||
return Err(())
|
||||
}
|
||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value)))
|
||||
|
@ -566,25 +567,21 @@ impl Length {
|
|||
Length::NoCalc(NoCalcLength::zero())
|
||||
}
|
||||
|
||||
/// Parse a given absolute or relative dimension.
|
||||
pub fn parse_dimension(context: &ParserContext, value: CSSFloat, unit: &str)
|
||||
-> Result<Length, ()> {
|
||||
NoCalcLength::parse_dimension(context, value, unit).map(Length::NoCalc)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Length, ParseError<'i>> {
|
||||
fn parse_internal<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
return Length::parse_dimension(context, value, unit)
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(Length::NoCalc)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
|
@ -759,12 +756,12 @@ impl LengthOrPercentage {
|
|||
LengthOrPercentage::Length(NoCalcLength::zero())
|
||||
}
|
||||
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentage, ParseError<'i>>
|
||||
{
|
||||
fn parse_internal<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
|
@ -861,11 +858,12 @@ impl From<computed::Percentage> for LengthOrPercentageOrAuto {
|
|||
}
|
||||
|
||||
impl LengthOrPercentageOrAuto {
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
fn parse_internal<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
|
@ -968,12 +966,12 @@ pub enum LengthOrPercentageOrNone {
|
|||
}
|
||||
|
||||
impl LengthOrPercentageOrNone {
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentageOrNone, ParseError<'i>>
|
||||
{
|
||||
fn parse_internal<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
|
|
|
@ -213,11 +213,13 @@ bitflags! {
|
|||
|
||||
impl ParsingMode {
|
||||
/// Whether the parsing mode allows unitless lengths for non-zero values to be intpreted as px.
|
||||
#[inline]
|
||||
pub fn allows_unitless_lengths(&self) -> bool {
|
||||
self.intersects(ParsingMode::ALLOW_UNITLESS_LENGTH)
|
||||
}
|
||||
|
||||
/// Whether the parsing mode allows all numeric values.
|
||||
#[inline]
|
||||
pub fn allows_all_numeric_values(&self) -> bool {
|
||||
self.intersects(ParsingMode::ALLOW_ALL_NUMERIC_VALUES)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче