mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Change LengthOrPercentageOrAuto to make use of NoCalcLength
This commit is contained in:
parent
590c9579f0
commit
bdb08b9a82
5 changed files with 35 additions and 42 deletions
|
@ -503,14 +503,12 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
};
|
||||
|
||||
if let Some(size) = size {
|
||||
let value = specified::Length::NoCalc(
|
||||
specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size)));
|
||||
let value = specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Width(DeclaredValue::Value(
|
||||
specified::LengthOrPercentageOrAuto::Length(value)))));
|
||||
}
|
||||
|
||||
|
||||
let width = if let Some(this) = self.downcast::<HTMLIFrameElement>() {
|
||||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLImageElement>() {
|
||||
|
@ -536,7 +534,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => {
|
||||
let width_value = specified::LengthOrPercentageOrAuto::Length(
|
||||
specified::Length::NoCalc(specified::NoCalcLength::Absolute(length)));
|
||||
specified::NoCalcLength::Absolute(length));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Width(DeclaredValue::Value(width_value))));
|
||||
}
|
||||
|
@ -561,7 +559,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => {
|
||||
let height_value = specified::LengthOrPercentageOrAuto::Length(
|
||||
specified::Length::NoCalc(specified::NoCalcLength::Absolute(length)));
|
||||
specified::NoCalcLength::Absolute(length));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Height(DeclaredValue::Value(height_value))));
|
||||
}
|
||||
|
@ -583,14 +581,12 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
// scrollbar size into consideration (but we don't have a scrollbar yet!)
|
||||
//
|
||||
// https://html.spec.whatwg.org/multipage/#textarea-effective-width
|
||||
let value = specified::Length::NoCalc(
|
||||
specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols)));
|
||||
let value = specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Width(DeclaredValue::Value(
|
||||
specified::LengthOrPercentageOrAuto::Length(value)))));
|
||||
}
|
||||
|
||||
|
||||
let rows = if let Some(this) = self.downcast::<HTMLTextAreaElement>() {
|
||||
match this.get_rows() {
|
||||
0 => None,
|
||||
|
@ -604,8 +600,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
// TODO(mttr) This should take scrollbar size into consideration.
|
||||
//
|
||||
// https://html.spec.whatwg.org/multipage/#textarea-effective-height
|
||||
let value = specified::Length::NoCalc(
|
||||
specified::NoCalcLength::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat)));
|
||||
let value = specified::NoCalcLength::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Height(DeclaredValue::Value(
|
||||
specified::LengthOrPercentageOrAuto::Length(value)))));
|
||||
|
|
|
@ -989,7 +989,7 @@ impl Parse for LengthOrPercentage {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum LengthOrPercentageOrAuto {
|
||||
Length(Length),
|
||||
Length(NoCalcLength),
|
||||
Percentage(Percentage),
|
||||
Auto,
|
||||
Calc(Box<CalcLengthOrPercentage>),
|
||||
|
@ -1022,11 +1022,11 @@ impl LengthOrPercentageOrAuto {
|
|||
{
|
||||
match try!(input.next()) {
|
||||
Token::Dimension(ref value, ref unit) if context.is_ok(value.value) =>
|
||||
Length::parse_dimension(value.value, unit).map(LengthOrPercentageOrAuto::Length),
|
||||
NoCalcLength::parse_dimension(value.value, unit).map(LengthOrPercentageOrAuto::Length),
|
||||
Token::Percentage(ref value) if context.is_ok(value.unit_value) =>
|
||||
Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))),
|
||||
Token::Number(ref value) if value.value == 0. =>
|
||||
Ok(LengthOrPercentageOrAuto::Length(Length::zero())),
|
||||
Ok(LengthOrPercentageOrAuto::Length(NoCalcLength::zero())),
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") =>
|
||||
Ok(LengthOrPercentageOrAuto::Auto),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
|
|
|
@ -25,7 +25,7 @@ use style_traits::ToCss;
|
|||
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
|
||||
use stylesheets::{Stylesheet, Origin};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::specified::{Length, NoCalcLength, LengthOrPercentageOrAuto, ViewportPercentageLength};
|
||||
use values::specified::{NoCalcLength, LengthOrPercentageOrAuto, ViewportPercentageLength};
|
||||
|
||||
macro_rules! declare_viewport_descriptor {
|
||||
( $( $variant_name: expr => $variant: ident($data: ident), )+ ) => {
|
||||
|
@ -150,16 +150,14 @@ impl FromMeta for ViewportLength {
|
|||
|
||||
Some(match value {
|
||||
v if v.eq_ignore_ascii_case("device-width") =>
|
||||
specified!(Length::NoCalc(
|
||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.)))),
|
||||
specified!(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.))),
|
||||
v if v.eq_ignore_ascii_case("device-height") =>
|
||||
specified!(Length::NoCalc(
|
||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(100.)))),
|
||||
specified!(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(100.))),
|
||||
_ => {
|
||||
match value.parse::<f32>() {
|
||||
Ok(n) if n >= 0. => specified!(Length::from_px(n.max(1.).min(10000.))),
|
||||
Ok(n) if n >= 0. => specified!(NoCalcLength::from_px(n.max(1.).min(10000.))),
|
||||
Ok(_) => return None,
|
||||
Err(_) => specified!(Length::from_px(1.))
|
||||
Err(_) => specified!(NoCalcLength::from_px(1.))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue