Skip to content

Commit

Permalink
Implement calc expressions for more value types
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbarsky committed Nov 2, 2015
1 parent 35b4526 commit 00980ea
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 312 deletions.
4 changes: 4 additions & 0 deletions components/layout/block.rs
Expand Up @@ -340,6 +340,10 @@ impl CandidateBSizeIterator {
(LengthOrPercentageOrNone::Percentage(percent), Some(block_container_block_size)) => {
Some(block_container_block_size.scale_by(percent))
}
(LengthOrPercentageOrNone::Calc(calc), Some(block_container_block_size)) => {
Some(block_container_block_size.scale_by(calc.percentage()) + calc.length())
}
(LengthOrPercentageOrNone::Calc(_), _) |
(LengthOrPercentageOrNone::Percentage(_), None) |
(LengthOrPercentageOrNone::None, _) => None,
(LengthOrPercentageOrNone::Length(length), _) => Some(length),
Expand Down
7 changes: 4 additions & 3 deletions components/layout/inline.rs
Expand Up @@ -27,6 +27,7 @@ use std::{fmt, isize, mem};
use style::computed_values::{display, overflow_x, position, text_align, text_justify};
use style::computed_values::{text_overflow, vertical_align, white_space};
use style::properties::ComputedValues;
use style::values::computed::LengthOrPercentage;
use text;
use unicode_bidi;
use util;
Expand Down Expand Up @@ -953,15 +954,15 @@ impl InlineFlow {
offset_from_baseline = offset_from_baseline - *depth_below_baseline
}
},
vertical_align::T::Length(length) => {
vertical_align::T::LengthOrPercentage(LengthOrPercentage::Length(length)) => {
offset_from_baseline = offset_from_baseline - length
}
vertical_align::T::Percentage(p) => {
vertical_align::T::LengthOrPercentage(LengthOrPercentage::Percentage(p)) => {
let line_height = fragment.calculate_line_height(layout_context);
let percent_offset = line_height.scale_by(p);
offset_from_baseline = offset_from_baseline - percent_offset
}
vertical_align::T::Calc(calc) => {
vertical_align::T::LengthOrPercentage(LengthOrPercentage::Calc(calc)) => {
let line_height = fragment.calculate_line_height(layout_context);
let percent_offset = line_height.scale_by(calc.percentage());
offset_from_baseline = offset_from_baseline - percent_offset - calc.length()
Expand Down
2 changes: 2 additions & 0 deletions components/layout/model.rs
Expand Up @@ -411,6 +411,8 @@ pub fn specified_or_none(length: LengthOrPercentageOrNone, containing_length: Au
match length {
LengthOrPercentageOrNone::None => None,
LengthOrPercentageOrNone::Percentage(percent) => Some(containing_length.scale_by(percent)),
LengthOrPercentageOrNone::Calc(calc) =>
Some(containing_length.scale_by(calc.percentage()) + calc.length()),
LengthOrPercentageOrNone::Length(length) => Some(length),
}
}
Expand Down
5 changes: 3 additions & 2 deletions components/script/dom/element.rs
Expand Up @@ -80,7 +80,7 @@ use style::properties::DeclaredValue;
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA};
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
use url::UrlParser;
use util::mem::HeapSizeOf;
use util::str::{DOMString, LengthOrPercentageOrAuto};
Expand Down Expand Up @@ -347,7 +347,8 @@ impl LayoutElementHelpers for LayoutJS<Element> {
hints.push(from_declaration(
PropertyDeclaration::FontSize(
DeclaredValue::Value(
font_size::SpecifiedValue(font_size)))))
font_size::SpecifiedValue(
LengthOrPercentage::Length(font_size))))))
}

let cellspacing = if let Some(this) = self.downcast::<HTMLTableElement>() {
Expand Down
24 changes: 12 additions & 12 deletions components/style/animation.rs
Expand Up @@ -28,7 +28,7 @@ use std::iter::repeat;
use util::bezier::Bezier;
use values::CSSFloat;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{Calc, Length, LengthOrPercentage, Time};
use values::computed::{CalcLengthOrPercentage, Length, LengthOrPercentage, Time};

#[derive(Clone, Debug)]
pub struct PropertyAnimation {
Expand Down Expand Up @@ -461,10 +461,10 @@ impl Interpolate for VerticalAlign {
fn interpolate(&self, other: &VerticalAlign, time: f64)
-> Option<VerticalAlign> {
match (*self, *other) {
(VerticalAlign::Length(ref this),
VerticalAlign::Length(ref other)) => {
(VerticalAlign::LengthOrPercentage(LengthOrPercentage::Length(ref this)),
VerticalAlign::LengthOrPercentage(LengthOrPercentage::Length(ref other))) => {
this.interpolate(other, time).and_then(|value| {
Some(VerticalAlign::Length(value))
Some(VerticalAlign::LengthOrPercentage(LengthOrPercentage::Length(value)))
})
}
(_, _) => None,
Expand Down Expand Up @@ -513,11 +513,11 @@ impl Interpolate for Color {
}
}

impl Interpolate for Calc {
impl Interpolate for CalcLengthOrPercentage {
#[inline]
fn interpolate(&self, other: &Calc, time: f64)
-> Option<Calc> {
Some(Calc {
fn interpolate(&self, other: &CalcLengthOrPercentage, time: f64)
-> Option<CalcLengthOrPercentage> {
Some(CalcLengthOrPercentage {
length: self.length().interpolate(&other.length(), time),
percentage: self.percentage().interpolate(&other.percentage(), time),
})
Expand All @@ -542,8 +542,8 @@ impl Interpolate for LengthOrPercentage {
})
}
(this, other) => {
let this: Calc = From::from(this);
let other: Calc = From::from(other);
let this: CalcLengthOrPercentage = From::from(this);
let other: CalcLengthOrPercentage = From::from(other);
this.interpolate(&other, time).and_then(|value| {
Some(LengthOrPercentage::Calc(value))
})
Expand Down Expand Up @@ -573,8 +573,8 @@ impl Interpolate for LengthOrPercentageOrAuto {
Some(LengthOrPercentageOrAuto::Auto)
}
(this, other) => {
let this: Option<Calc> = From::from(this);
let other: Option<Calc> = From::from(other);
let this: Option<CalcLengthOrPercentage> = From::from(this);
let other: Option<CalcLengthOrPercentage> = From::from(other);
this.interpolate(&other, time).unwrap_or(None).and_then(|value| {
Some(LengthOrPercentageOrAuto::Calc(value))
})
Expand Down

0 comments on commit 00980ea

Please sign in to comment.