mirror of
https://github.com/servo/servo.git
synced 2025-08-16 10:55:34 +01:00
Replace Au with CSSPixelLength in CalcLengthOrPercentage.
We replace Au with CSSPixelLength for the length part of computed::CalcLengthOrPercentage. Therefore, it would be easier to use CSSPixelLength for all other LengthOrPercentage{*} types.
This commit is contained in:
parent
a949e2a057
commit
535c1e3c6f
13 changed files with 99 additions and 117 deletions
|
@ -11,7 +11,7 @@ use parser::ParserContext;
|
|||
use std::ascii::AsciiExt;
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use style_traits::values::specified::AllowedLengthType;
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use values::{CSSInteger, CSSFloat};
|
||||
use values::computed;
|
||||
use values::specified::{Angle, Time};
|
||||
|
@ -67,7 +67,7 @@ pub enum CalcUnit {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub struct CalcLengthOrPercentage {
|
||||
pub clamping_mode: AllowedLengthType,
|
||||
pub clamping_mode: AllowedNumericType,
|
||||
pub absolute: Option<AbsoluteLength>,
|
||||
pub vw: Option<CSSFloat>,
|
||||
pub vh: Option<CSSFloat>,
|
||||
|
@ -291,7 +291,7 @@ impl CalcNode {
|
|||
|
||||
/// Tries to simplify this expression into a `<length>` or `<percentage`>
|
||||
/// value.
|
||||
fn to_length_or_percentage(&self, clamping_mode: AllowedLengthType)
|
||||
fn to_length_or_percentage(&self, clamping_mode: AllowedNumericType)
|
||||
-> Result<CalcLengthOrPercentage, ()> {
|
||||
let mut ret = CalcLengthOrPercentage {
|
||||
clamping_mode: clamping_mode,
|
||||
|
@ -565,7 +565,7 @@ impl CalcNode {
|
|||
pub fn parse_length_or_percentage<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedLengthType
|
||||
clamping_mode: AllowedNumericType
|
||||
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
|
||||
Self::parse(context, input, CalcUnit::LengthOrPercentage)?
|
||||
.to_length_or_percentage(clamping_mode)
|
||||
|
@ -586,7 +586,7 @@ impl CalcNode {
|
|||
pub fn parse_length<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedLengthType
|
||||
clamping_mode: AllowedNumericType
|
||||
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
|
||||
Self::parse(context, input, CalcUnit::Length)?
|
||||
.to_length_or_percentage(clamping_mode)
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::{cmp, fmt, mem};
|
|||
use std::ascii::AsciiExt;
|
||||
use std::ops::{Add, Mul};
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use style_traits::values::specified::AllowedLengthType;
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use stylesheets::CssRuleType;
|
||||
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
||||
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, None_, Normal};
|
||||
|
@ -642,7 +642,7 @@ impl Length {
|
|||
#[inline]
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedLengthType,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Length, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
|
@ -683,7 +683,7 @@ impl Length {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Length, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
}
|
||||
|
||||
/// Get an absolute length from a px value.
|
||||
|
@ -713,7 +713,7 @@ impl Length {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,7 +725,7 @@ impl<T: Parse> Either<Length, T> {
|
|||
if let Ok(v) = input.try(|input| T::parse(context, input)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No).map(Either::First)
|
||||
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,7 +752,7 @@ impl<T: Parse> Parse for Either<NonNegativeLength, T> {
|
|||
if let Ok(v) = input.try(|input| T::parse(context, input)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No)
|
||||
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No)
|
||||
.map(NonNegative::<Length>).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
@ -836,7 +836,7 @@ impl LengthOrPercentage {
|
|||
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedLengthType,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentage, ParseError<'i>>
|
||||
{
|
||||
|
@ -885,7 +885,7 @@ impl LengthOrPercentage {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentage, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
}
|
||||
|
||||
/// Parse a length, treating dimensionless numbers as pixels
|
||||
|
@ -946,7 +946,7 @@ impl LengthOrPercentage {
|
|||
pub fn parse_quirky<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -978,7 +978,7 @@ impl From<computed::Percentage> for LengthOrPercentageOrAuto {
|
|||
impl LengthOrPercentageOrAuto {
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedLengthType,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
|
@ -1030,7 +1030,7 @@ impl LengthOrPercentageOrAuto {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
}
|
||||
|
||||
/// Returns the `auto` value.
|
||||
|
@ -1063,7 +1063,7 @@ impl LengthOrPercentageOrAuto {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1081,7 +1081,7 @@ pub enum LengthOrPercentageOrNone {
|
|||
impl LengthOrPercentageOrNone {
|
||||
fn parse_internal<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedLengthType,
|
||||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentageOrNone, ParseError<'i>>
|
||||
{
|
||||
|
@ -1133,14 +1133,14 @@ impl LengthOrPercentageOrNone {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentageOrNone {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedLengthType::All, AllowQuirks::No)
|
||||
Self::parse_internal(context, input, AllowedNumericType::All, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -203,14 +203,15 @@ impl<S: Side> ToComputedValue for PositionComponent<S> {
|
|||
match length.to_computed_value(context) {
|
||||
ComputedLengthOrPercentage::Length(length) => {
|
||||
ComputedLengthOrPercentage::Calc(
|
||||
CalcLengthOrPercentage::new(-length, Some(Percentage::hundred())))
|
||||
CalcLengthOrPercentage::new((-length).into(), Some(Percentage::hundred())))
|
||||
},
|
||||
ComputedLengthOrPercentage::Percentage(p) => {
|
||||
ComputedLengthOrPercentage::Percentage(Percentage(1.0 - p.0))
|
||||
},
|
||||
ComputedLengthOrPercentage::Calc(calc) => {
|
||||
let p = Percentage(1. - calc.percentage.map_or(0., |p| p.0));
|
||||
ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(-calc.unclamped_length(), Some(p)))
|
||||
let l = -calc.unclamped_length();
|
||||
ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(l, Some(p)))
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
|
@ -84,7 +84,7 @@ impl ToComputedValue for LineHeight {
|
|||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
use app_units::Au;
|
||||
use values::computed::NonNegativeLength;
|
||||
use values::specified::length::FontBaseSize;
|
||||
match *self {
|
||||
GenericLineHeight::Normal => {
|
||||
|
@ -119,13 +119,13 @@ impl ToComputedValue for LineHeight {
|
|||
.to_computed_value(
|
||||
context,
|
||||
FontBaseSize::CurrentStyle,
|
||||
);
|
||||
).px();
|
||||
|
||||
let absolute_length = computed_calc.unclamped_length();
|
||||
computed_calc
|
||||
let absolute_length = computed_calc.unclamped_length().px();
|
||||
let pixel = computed_calc
|
||||
.clamping_mode
|
||||
.clamp(absolute_length + Au::from(font_relative_length))
|
||||
.into()
|
||||
.clamp(absolute_length + font_relative_length);
|
||||
NonNegativeLength::new(pixel)
|
||||
}
|
||||
};
|
||||
GenericLineHeight::Length(result)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue