style: Fix servo build.

This also fixes a bunch of calc handling issues and such.

Also remove tests that no longer compile and are covered by WPT.
This commit is contained in:
Emilio Cobos Álvarez 2019-01-07 16:43:10 +01:00
parent ca503b4908
commit 4a31509215
17 changed files with 199 additions and 436 deletions

View file

@ -66,8 +66,7 @@ use style::context::SharedStyleContext;
use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrNone};
/// Information specific to floated blocks. /// Information specific to floated blocks.
#[derive(Clone, Serialize)] #[derive(Clone, Serialize)]
@ -418,42 +417,23 @@ impl CandidateBSizeIterator {
// If that is not determined yet by the time we need to resolve // If that is not determined yet by the time we need to resolve
// `min-height` and `max-height`, percentage values are ignored. // `min-height` and `max-height`, percentage values are ignored.
let block_size = match ( let block_size = match fragment.style.content_block_size() {
fragment.style.content_block_size(), LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto,
block_container_block_size, LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
) { MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size))
(LengthOrPercentageOrAuto::Percentage(percent), Some(block_container_block_size)) => {
MaybeAuto::Specified(block_container_block_size.scale_by(percent.0))
}, },
(LengthOrPercentageOrAuto::Calc(calc), _) => {
MaybeAuto::from_option(calc.to_used_value(block_container_block_size))
},
(LengthOrPercentageOrAuto::Percentage(_), None) |
(LengthOrPercentageOrAuto::Auto, _) => MaybeAuto::Auto,
(LengthOrPercentageOrAuto::Length(length), _) => MaybeAuto::Specified(Au::from(length)),
}; };
let max_block_size = match (fragment.style.max_block_size(), block_container_block_size) {
(LengthOrPercentageOrNone::Percentage(percent), Some(block_container_block_size)) => { let max_block_size = match fragment.style.max_block_size() {
Some(block_container_block_size.scale_by(percent.0)) LengthOrPercentageOrNone::None => None,
LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => {
lp.maybe_to_used_value(block_container_block_size)
}, },
(LengthOrPercentageOrNone::Calc(calc), _) => {
calc.to_used_value(block_container_block_size)
},
(LengthOrPercentageOrNone::Percentage(_), None) |
(LengthOrPercentageOrNone::None, _) => None,
(LengthOrPercentageOrNone::Length(length), _) => Some(Au::from(length)),
};
let min_block_size = match (fragment.style.min_block_size(), block_container_block_size) {
(LengthOrPercentage::Percentage(percent), Some(block_container_block_size)) => {
block_container_block_size.scale_by(percent.0)
},
(LengthOrPercentage::Calc(calc), _) => calc
.to_used_value(block_container_block_size)
.unwrap_or(Au(0)),
(LengthOrPercentage::Percentage(_), None) => Au(0),
(LengthOrPercentage::Length(length), _) => Au::from(length),
}; };
let min_block_size =
fragment.style.min_block_size().maybe_to_used_value(block_container_block_size).unwrap_or(Au(0));
// If the style includes `box-sizing: border-box`, subtract the border and padding. // If the style includes `box-sizing: border-box`, subtract the border and padding.
let adjustment_for_box_sizing = match fragment.style.get_position().box_sizing { let adjustment_for_box_sizing = match fragment.style.get_position().box_sizing {
BoxSizing::BorderBox => fragment.border_padding.block_start_end(), BoxSizing::BorderBox => fragment.border_padding.block_start_end(),
@ -1415,15 +1395,9 @@ impl BlockFlow {
pub fn explicit_block_size(&self, containing_block_size: Option<Au>) -> Option<Au> { pub fn explicit_block_size(&self, containing_block_size: Option<Au>) -> Option<Au> {
let content_block_size = self.fragment.style().content_block_size(); let content_block_size = self.fragment.style().content_block_size();
match (content_block_size, containing_block_size) { match content_block_size {
(LengthOrPercentageOrAuto::Calc(calc), _) => calc.to_used_value(containing_block_size), LengthOrPercentageOrAuto::Auto => {
(LengthOrPercentageOrAuto::Length(length), _) => Some(Au::from(length)), let container_size = containing_block_size?;
(LengthOrPercentageOrAuto::Percentage(percent), Some(container_size)) => {
Some(container_size.scale_by(percent.0))
},
(LengthOrPercentageOrAuto::Percentage(_), None) |
(LengthOrPercentageOrAuto::Auto, None) => None,
(LengthOrPercentageOrAuto::Auto, Some(container_size)) => {
let (block_start, block_end) = { let (block_start, block_end) = {
let position = self.fragment.style().logical_position(); let position = self.fragment.style().logical_position();
( (
@ -1454,10 +1428,12 @@ impl BlockFlow {
let sum = block_start + block_end + margin_block_start + margin_block_end; let sum = block_start + block_end + margin_block_start + margin_block_end;
Some(available_block_size - sum) Some(available_block_size - sum)
}, },
(_, _) => None, (_, _) => None,
} }
}, },
LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
lp.maybe_to_used_value(containing_block_size)
},
} }
} }
@ -2177,8 +2153,8 @@ impl Flow for BlockFlow {
// If this block has a fixed width, just use that for the minimum and preferred width, // If this block has a fixed width, just use that for the minimum and preferred width,
// rather than bubbling up children inline width. // rather than bubbling up children inline width.
let consult_children = match self.fragment.style().get_position().width { let consult_children = match self.fragment.style().get_position().width {
LengthOrPercentageOrAuto::Length(_) => false, LengthOrPercentageOrAuto::Auto => true,
_ => true, LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => lp.maybe_to_used_value(None).is_none(),
}; };
self.bubble_inline_sizes_for_block(consult_children); self.bubble_inline_sizes_for_block(consult_children);
self.fragment self.fragment

View file

@ -107,14 +107,14 @@ fn convert_gradient_stops(
{ {
let first = stop_items.first_mut().unwrap(); let first = stop_items.first_mut().unwrap();
if first.position.is_none() { if first.position.is_none() {
first.position = Some(LengthOrPercentage::Percentage(Percentage(0.0))); first.position = Some(LengthOrPercentage::new_percent(Percentage(0.)));
} }
} }
// If the last color stop does not have a position, set its position to 100%. // If the last color stop does not have a position, set its position to 100%.
{ {
let last = stop_items.last_mut().unwrap(); let last = stop_items.last_mut().unwrap();
if last.position.is_none() { if last.position.is_none() {
last.position = Some(LengthOrPercentage::Percentage(Percentage(1.0))); last.position = Some(LengthOrPercentage::new_percent(Percentage(1.0)));
} }
} }
@ -214,13 +214,7 @@ fn position_to_offset(position: LengthOrPercentage, total_length: Au) -> f32 {
if total_length == Au(0) { if total_length == Au(0) {
return 0.0; return 0.0;
} }
match position { position.to_used_value(total_length).0 as f32 / total_length.0 as f32
LengthOrPercentage::Length(l) => l.to_i32_au() as f32 / total_length.0 as f32,
LengthOrPercentage::Percentage(percentage) => percentage.0 as f32,
LengthOrPercentage::Calc(calc) => {
calc.to_used_value(Some(total_length)).unwrap().0 as f32 / total_length.0 as f32
},
}
} }
pub fn linear( pub fn linear(

View file

@ -12,7 +12,7 @@ use crate::floats::FloatKind;
use crate::flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, ImmutableFlowUtils, OpaqueFlow}; use crate::flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, ImmutableFlowUtils, OpaqueFlow};
use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::layout_debug; use crate::layout_debug;
use crate::model::{AdjoiningMargins, CollapsibleMargins}; use crate::model::{self, AdjoiningMargins, CollapsibleMargins};
use crate::model::{IntrinsicISizes, MaybeAuto, SizeConstraint}; use crate::model::{IntrinsicISizes, MaybeAuto, SizeConstraint};
use crate::traversal::PreorderFlowTraversal; use crate::traversal::PreorderFlowTraversal;
use app_units::{Au, MAX_AU}; use app_units::{Au, MAX_AU};
@ -52,18 +52,15 @@ impl AxisSize {
max: LengthOrPercentageOrNone, max: LengthOrPercentageOrNone,
) -> AxisSize { ) -> AxisSize {
match size { match size {
LengthOrPercentageOrAuto::Length(length) => AxisSize::Definite(Au::from(length)),
LengthOrPercentageOrAuto::Percentage(percent) => match content_size {
Some(size) => AxisSize::Definite(size.scale_by(percent.0)),
None => AxisSize::Infinite,
},
LengthOrPercentageOrAuto::Calc(calc) => match calc.to_used_value(content_size) {
Some(length) => AxisSize::Definite(length),
None => AxisSize::Infinite,
},
LengthOrPercentageOrAuto::Auto => { LengthOrPercentageOrAuto::Auto => {
AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)) AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None))
}, }
LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
match lp.maybe_to_used_value(content_size) {
Some(length) => AxisSize::Definite(length),
None => AxisSize::Infinite,
}
}
} }
} }
} }
@ -461,10 +458,11 @@ impl FlexFlow {
// Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic
// stripped out, and max replaced with union_nonbreaking_inline. // stripped out, and max replaced with union_nonbreaking_inline.
fn inline_mode_bubble_inline_sizes(&mut self) { fn inline_mode_bubble_inline_sizes(&mut self) {
let fixed_width = match self.block_flow.fragment.style().get_position().width { // FIXME(emilio): This doesn't handle at all writing-modes.
LengthOrPercentageOrAuto::Length(_) => true, let fixed_width = !model::style_length(
_ => false, self.block_flow.fragment.style().get_position().width,
}; None,
).is_auto();
let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes();
if !fixed_width { if !fixed_width {
@ -488,10 +486,10 @@ impl FlexFlow {
// Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic
// stripped out. // stripped out.
fn block_mode_bubble_inline_sizes(&mut self) { fn block_mode_bubble_inline_sizes(&mut self) {
let fixed_width = match self.block_flow.fragment.style().get_position().width { let fixed_width = !model::style_length(
LengthOrPercentageOrAuto::Length(_) => true, self.block_flow.fragment.style().get_position().width,
_ => false, None,
}; ).is_auto();
let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes();
if !fixed_width { if !fixed_width {

View file

@ -542,16 +542,21 @@ impl SpeculatedFloatPlacement {
let mut float_inline_size = base_flow.intrinsic_inline_sizes.preferred_inline_size; let mut float_inline_size = base_flow.intrinsic_inline_sizes.preferred_inline_size;
if float_inline_size == Au(0) { if float_inline_size == Au(0) {
if flow.is_block_like() { if flow.is_block_like() {
// Hack: If the size of the float is a percentage, then there's no way we can guess // Hack: If the size of the float is not fixed, then there's no
// at its size now. So just pick an arbitrary nonzero value (in this case, 1px) so // way we can guess at its size now. So just pick an arbitrary
// that the layout traversal logic will know that objects later in the document // nonzero value (in this case, 1px) so that the layout
// traversal logic will know that objects later in the document
// might flow around this float. // might flow around this float.
if let LengthOrPercentageOrAuto::Percentage(percentage) = let inline_size =
flow.as_block().fragment.style.content_inline_size() flow.as_block().fragment.style.content_inline_size();
{ let fixed = match inline_size {
if percentage.0 > 0.0 { LengthOrPercentageOrAuto::Auto => false,
float_inline_size = Au::from_px(1) LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
lp.is_definitely_zero() || lp.maybe_to_used_value(None).is_some()
} }
};
if !fixed {
float_inline_size = Au::from_px(1)
} }
} }
} }

View file

@ -61,7 +61,7 @@ use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace; use style::str::char_is_whitespace;
use style::values::computed::counters::ContentItem; use style::values::computed::counters::ContentItem;
use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::generics::box_::{Perspective, VerticalAlign}; use style::values::generics::box_::{Perspective, VerticalAlign};
use style::values::generics::transform; use style::values::generics::transform;
use webrender_api::{self, LayoutTransform}; use webrender_api::{self, LayoutTransform};
@ -1610,33 +1610,32 @@ impl Fragment {
SpecificFragmentInfo::Canvas(_) | SpecificFragmentInfo::Canvas(_) |
SpecificFragmentInfo::Iframe(_) | SpecificFragmentInfo::Iframe(_) |
SpecificFragmentInfo::Svg(_) => { SpecificFragmentInfo::Svg(_) => {
let mut inline_size = match self.style.content_inline_size() { let inline_size = match self.style.content_inline_size() {
LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Percentage(_) => { LengthOrPercentageOrAuto::Auto => None,
// We have to initialize the `border_padding` field first to make LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
// the size constraints work properly. lp.maybe_to_used_value(None)
// TODO(stshine): Find a cleaner way to do this. }
let padding = self.style.logical_padding();
self.border_padding.inline_start =
padding.inline_start.to_used_value(Au(0));
self.border_padding.inline_end = padding.inline_end.to_used_value(Au(0));
self.border_padding.block_start = padding.block_start.to_used_value(Au(0));
self.border_padding.block_end = padding.block_end.to_used_value(Au(0));
let border = self.border_width();
self.border_padding.inline_start += border.inline_start;
self.border_padding.inline_end += border.inline_end;
self.border_padding.block_start += border.block_start;
self.border_padding.block_end += border.block_end;
let (result_inline, _) = self.calculate_replaced_sizes(None, None);
result_inline
},
LengthOrPercentageOrAuto::Length(length) => Au::from(length),
LengthOrPercentageOrAuto::Calc(calc) => {
// TODO(nox): This is probably wrong, because it accounts neither for
// clamping (not sure if necessary here) nor percentage.
Au::from(calc.unclamped_length())
},
}; };
let mut inline_size = inline_size.unwrap_or_else(|| {
// We have to initialize the `border_padding` field first to make
// the size constraints work properly.
// TODO(stshine): Find a cleaner way to do this.
let padding = self.style.logical_padding();
self.border_padding.inline_start =
padding.inline_start.to_used_value(Au(0));
self.border_padding.inline_end = padding.inline_end.to_used_value(Au(0));
self.border_padding.block_start = padding.block_start.to_used_value(Au(0));
self.border_padding.block_end = padding.block_end.to_used_value(Au(0));
let border = self.border_width();
self.border_padding.inline_start += border.inline_start;
self.border_padding.inline_end += border.inline_end;
self.border_padding.block_start += border.block_start;
self.border_padding.block_end += border.block_end;
let (result_inline, _) = self.calculate_replaced_sizes(None, None);
result_inline
});
let size_constraint = self.size_constraint(None, Direction::Inline); let size_constraint = self.size_constraint(None, Direction::Inline);
inline_size = size_constraint.clamp(inline_size); inline_size = size_constraint.clamp(inline_size);
@ -2432,16 +2431,8 @@ impl Fragment {
content_inline_metrics.space_below_baseline content_inline_metrics.space_below_baseline
} }
}, },
VerticalAlign::Length(LengthOrPercentage::Length(length)) => { VerticalAlign::Length(ref lp) => {
offset -= Au::from(length) offset -= lp.to_used_value(minimum_line_metrics.space_needed());
},
VerticalAlign::Length(LengthOrPercentage::Percentage(percentage)) => {
offset -= minimum_line_metrics.space_needed().scale_by(percentage.0)
},
VerticalAlign::Length(LengthOrPercentage::Calc(formula)) => {
offset -= formula
.to_used_value(Some(minimum_line_metrics.space_needed()))
.unwrap()
}, },
} }
} }
@ -2519,12 +2510,12 @@ impl Fragment {
continue; continue;
} }
if inline_context_node.style.logical_margin().inline_end != if inline_context_node.style.logical_margin().inline_end !=
LengthOrPercentageOrAuto::Length(Length::new(0.)) LengthOrPercentageOrAuto::zero()
{ {
return false; return false;
} }
if inline_context_node.style.logical_padding().inline_end != if inline_context_node.style.logical_padding().inline_end !=
LengthOrPercentage::Length(Length::new(0.)) LengthOrPercentage::zero()
{ {
return false; return false;
} }
@ -2545,12 +2536,12 @@ impl Fragment {
continue; continue;
} }
if inline_context_node.style.logical_margin().inline_start != if inline_context_node.style.logical_margin().inline_start !=
LengthOrPercentageOrAuto::Length(Length::new(0.)) LengthOrPercentageOrAuto::zero()
{ {
return false; return false;
} }
if inline_context_node.style.logical_padding().inline_start != if inline_context_node.style.logical_padding().inline_start !=
LengthOrPercentage::Length(Length::new(0.)) LengthOrPercentage::zero()
{ {
return false; return false;
} }

View file

@ -136,26 +136,19 @@ impl MarginCollapseInfo {
may_collapse_through = may_collapse_through && may_collapse_through = may_collapse_through &&
match fragment.style().content_block_size() { match fragment.style().content_block_size() {
LengthOrPercentageOrAuto::Auto => true, LengthOrPercentageOrAuto::Auto => true,
LengthOrPercentageOrAuto::Length(l) => l.px() == 0., LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
LengthOrPercentageOrAuto::Percentage(v) => { lp.is_definitely_zero() ||
v.0 == 0. || containing_block_size.is_none() lp.maybe_to_used_value(containing_block_size).is_none()
}, },
LengthOrPercentageOrAuto::Calc(_) => false,
}; };
if may_collapse_through { if may_collapse_through {
match fragment.style().min_block_size() { if fragment.style().min_block_size().is_definitely_zero() {
LengthOrPercentage::Length(l) if l.px() == 0. => { FinalMarginState::MarginsCollapseThrough
FinalMarginState::MarginsCollapseThrough } else {
}, // If the fragment has non-zero min-block-size, margins may not
LengthOrPercentage::Percentage(v) if v.0 == 0. => { // collapse through it.
FinalMarginState::MarginsCollapseThrough FinalMarginState::BottomMarginCollapses
},
_ => {
// If the fragment has non-zero min-block-size, margins may not
// collapse through it.
FinalMarginState::BottomMarginCollapses
},
} }
} else { } else {
// If the fragment has an explicitly specified block-size, margins may not // If the fragment has an explicitly specified block-size, margins may not
@ -445,13 +438,9 @@ impl MaybeAuto {
pub fn from_style(length: LengthOrPercentageOrAuto, containing_length: Au) -> MaybeAuto { pub fn from_style(length: LengthOrPercentageOrAuto, containing_length: Au) -> MaybeAuto {
match length { match length {
LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto,
LengthOrPercentageOrAuto::Percentage(percent) => { LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
MaybeAuto::Specified(containing_length.scale_by(percent.0)) MaybeAuto::Specified(lp.to_used_value(containing_length))
}, },
LengthOrPercentageOrAuto::Calc(calc) => {
MaybeAuto::from_option(calc.to_used_value(Some(containing_length)))
},
LengthOrPercentageOrAuto::Length(length) => MaybeAuto::Specified(Au::from(length)),
} }
} }
@ -484,6 +473,15 @@ impl MaybeAuto {
self.specified_or_default(Au::new(0)) self.specified_or_default(Au::new(0))
} }
#[inline]
pub fn is_auto(&self) -> bool {
match *self {
MaybeAuto::Auto => true,
MaybeAuto::Specified(..) => false,
}
}
#[inline] #[inline]
pub fn map<F>(&self, mapper: F) -> MaybeAuto pub fn map<F>(&self, mapper: F) -> MaybeAuto
where where
@ -503,15 +501,11 @@ pub fn style_length(
style_length: LengthOrPercentageOrAuto, style_length: LengthOrPercentageOrAuto,
container_size: Option<Au>, container_size: Option<Au>,
) -> MaybeAuto { ) -> MaybeAuto {
match container_size { match style_length {
Some(length) => MaybeAuto::from_style(style_length, length), LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto,
None => { LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
if let LengthOrPercentageOrAuto::Length(length) = style_length { MaybeAuto::from_option(lp.maybe_to_used_value(container_size))
MaybeAuto::Specified(Au::from(length)) }
} else {
MaybeAuto::Auto
}
},
} }
} }
@ -580,27 +574,16 @@ impl SizeConstraint {
max_size: LengthOrPercentageOrNone, max_size: LengthOrPercentageOrNone,
border: Option<Au>, border: Option<Au>,
) -> SizeConstraint { ) -> SizeConstraint {
let mut min_size = match container_size { let mut min_size =
Some(container_size) => min_size.to_used_value(container_size), min_size.maybe_to_used_value(container_size).unwrap_or(Au(0));
None => {
if let LengthOrPercentage::Length(length) = min_size { let mut max_size = match max_size {
Au::from(length) LengthOrPercentageOrNone::None => None,
} else { LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => {
Au(0) lp.maybe_to_used_value(container_size)
}
}, },
}; };
let mut max_size = match container_size {
Some(container_size) => max_size.to_used_value(container_size),
None => {
if let LengthOrPercentageOrNone::Length(length) = max_size {
Some(Au::from(length))
} else {
None
}
},
};
// Make sure max size is not smaller than min size. // Make sure max size is not smaller than min size.
max_size = max_size.map(|x| max(x, min_size)); max_size = max_size.map(|x| max(x, min_size));
@ -609,10 +592,7 @@ impl SizeConstraint {
max_size = max_size.map(|x| max(x - border, Au(0))); max_size = max_size.map(|x| max(x - border, Au(0)));
} }
SizeConstraint { SizeConstraint { min_size, max_size }
min_size: min_size,
max_size: max_size,
}
} }
/// Clamp the given size by the given min size and max size constraint. /// Clamp the given size by the given min size and max size constraint.

View file

@ -154,11 +154,22 @@ impl Flow for MulticolFlow {
this_fragment_is_empty: true, this_fragment_is_empty: true,
available_block_size: { available_block_size: {
let style = &self.block_flow.fragment.style; let style = &self.block_flow.fragment.style;
if let LengthOrPercentageOrAuto::Length(length) = style.content_block_size() { let size = match style.content_block_size() {
Au::from(length) LengthOrPercentageOrAuto::Auto => None,
} else if let LengthOrPercentageOrNone::Length(length) = style.max_block_size() { LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
Au::from(length) lp.maybe_to_used_value(None)
} else { }
};
let size = size.or_else(|| {
match style.max_block_size() {
LengthOrPercentageOrNone::None => None,
LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => {
lp.maybe_to_used_value(None)
}
}
});
size.unwrap_or_else(|| {
// FIXME: do column balancing instead // FIXME: do column balancing instead
// FIXME: (until column balancing) substract margins/borders/padding // FIXME: (until column balancing) substract margins/borders/padding
LogicalSize::from_physical( LogicalSize::from_physical(
@ -166,7 +177,7 @@ impl Flow for MulticolFlow {
ctx.shared_context().viewport_size(), ctx.shared_context().viewport_size(),
) )
.block .block
} })
}, },
}); });

View file

@ -301,16 +301,16 @@ impl Flow for TableFlow {
self.column_intrinsic_inline_sizes self.column_intrinsic_inline_sizes
.push(ColumnIntrinsicInlineSize { .push(ColumnIntrinsicInlineSize {
minimum_length: match *specified_inline_size { minimum_length: match *specified_inline_size {
LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Auto => Au(0),
LengthOrPercentageOrAuto::Calc(_) | LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
LengthOrPercentageOrAuto::Percentage(_) => Au(0), lp.maybe_to_used_value(None).unwrap_or(Au(0))
LengthOrPercentageOrAuto::Length(length) => Au::from(length), },
}, },
percentage: match *specified_inline_size { percentage: match *specified_inline_size {
LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Auto => 0.0,
LengthOrPercentageOrAuto::Calc(_) | LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
LengthOrPercentageOrAuto::Length(_) => 0.0, lp.as_percentage().map_or(0.0, |p| p.0)
LengthOrPercentageOrAuto::Percentage(percentage) => percentage.0, },
}, },
preferred: Au(0), preferred: Au(0),
constrained: false, constrained: false,

View file

@ -430,25 +430,24 @@ impl Flow for TableRowFlow {
let child_base = kid.mut_base(); let child_base = kid.mut_base();
let child_column_inline_size = ColumnIntrinsicInlineSize { let child_column_inline_size = ColumnIntrinsicInlineSize {
minimum_length: match child_specified_inline_size { minimum_length: match child_specified_inline_size {
LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Auto => None,
LengthOrPercentageOrAuto::Calc(_) | LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
LengthOrPercentageOrAuto::Percentage(_) => { lp.maybe_to_used_value(None)
child_base.intrinsic_inline_sizes.minimum_inline_size
}, },
LengthOrPercentageOrAuto::Length(length) => Au::from(length), }
}, .unwrap_or(child_base.intrinsic_inline_sizes.minimum_inline_size),
percentage: match child_specified_inline_size { percentage: match child_specified_inline_size {
LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Auto => 0.0,
LengthOrPercentageOrAuto::Calc(_) | LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
LengthOrPercentageOrAuto::Length(_) => 0.0, lp.as_percentage().map_or(0.0, |p| p.0)
LengthOrPercentageOrAuto::Percentage(percentage) => percentage.0, },
}, },
preferred: child_base.intrinsic_inline_sizes.preferred_inline_size, preferred: child_base.intrinsic_inline_sizes.preferred_inline_size,
constrained: match child_specified_inline_size { constrained: match child_specified_inline_size {
LengthOrPercentageOrAuto::Length(_) => true, LengthOrPercentageOrAuto::Auto => false,
LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => {
LengthOrPercentageOrAuto::Calc(_) | lp.maybe_to_used_value(None).is_some()
LengthOrPercentageOrAuto::Percentage(_) => false, },
}, },
}; };
min_inline_size = min_inline_size + child_column_inline_size.minimum_length; min_inline_size = min_inline_size + child_column_inline_size.minimum_length;

View file

@ -718,7 +718,9 @@ impl LayoutElementHelpers for LayoutDom<Element> {
specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size)); specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::LengthOrPercentage(
specified::LengthOrPercentage::Length(value)
)),
)); ));
} }
@ -743,8 +745,10 @@ impl LayoutElementHelpers for LayoutDom<Element> {
match width { match width {
LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Auto => {},
LengthOrPercentageOrAuto::Percentage(percentage) => { LengthOrPercentageOrAuto::Percentage(percentage) => {
let width_value = specified::LengthOrPercentageOrAuto::Percentage( let width_value = specified::LengthOrPercentageOrAuto::LengthOrPercentage(
computed::Percentage(percentage), specified::LengthOrPercentage::Percentage(
computed::Percentage(percentage),
),
); );
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
@ -753,9 +757,13 @@ impl LayoutElementHelpers for LayoutDom<Element> {
}, },
LengthOrPercentageOrAuto::Length(length) => { LengthOrPercentageOrAuto::Length(length) => {
let width_value = let width_value =
specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( specified::LengthOrPercentageOrAuto::LengthOrPercentage(
specified::AbsoluteLength::Px(length.to_f32_px()), specified::LengthOrPercentage::Length(
)); specified::NoCalcLength::Absolute(
specified::AbsoluteLength::Px(length.to_f32_px()),
),
),
);
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width(width_value), PropertyDeclaration::Width(width_value),
@ -776,8 +784,10 @@ impl LayoutElementHelpers for LayoutDom<Element> {
match height { match height {
LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Auto => {},
LengthOrPercentageOrAuto::Percentage(percentage) => { LengthOrPercentageOrAuto::Percentage(percentage) => {
let height_value = specified::LengthOrPercentageOrAuto::Percentage( let height_value = specified::LengthOrPercentageOrAuto::LengthOrPercentage(
computed::Percentage(percentage), specified::LengthOrPercentage::Percentage(
computed::Percentage(percentage),
)
); );
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
@ -786,9 +796,13 @@ impl LayoutElementHelpers for LayoutDom<Element> {
}, },
LengthOrPercentageOrAuto::Length(length) => { LengthOrPercentageOrAuto::Length(length) => {
let height_value = let height_value =
specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( specified::LengthOrPercentageOrAuto::LengthOrPercentage(
specified::AbsoluteLength::Px(length.to_f32_px()), specified::LengthOrPercentage::Length(
)); specified::NoCalcLength::Absolute(
specified::AbsoluteLength::Px(length.to_f32_px()),
)
)
);
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Height(height_value), PropertyDeclaration::Height(height_value),
@ -815,7 +829,9 @@ impl LayoutElementHelpers for LayoutDom<Element> {
specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols)); specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::LengthOrPercentage(
specified::LengthOrPercentage::Length(value)
)),
)); ));
} }
@ -837,7 +853,9 @@ impl LayoutElementHelpers for LayoutDom<Element> {
)); ));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::Length(value)), PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::LengthOrPercentage(
specified::LengthOrPercentage::Length(value)
)),
)); ));
} }

View file

@ -297,7 +297,7 @@ ${helpers.predefined_type(
${helpers.predefined_type( ${helpers.predefined_type(
"min-%s" % size, "min-%s" % size,
"LengthOrPercentage", "LengthOrPercentage",
"computed::LengthOrPercentage::Length(computed::Length::new(0.))", "computed::LengthOrPercentage::zero()",
"parse_non_negative", "parse_non_negative",
spec=spec % ("min-%s" % size), spec=spec % ("min-%s" % size),
logical_group="min-size", logical_group="min-size",

View file

@ -4,7 +4,6 @@
use cssparser::RGBA; use cssparser::RGBA;
use style::values::animated::{Animate, Procedure, ToAnimatedValue}; use style::values::animated::{Animate, Procedure, ToAnimatedValue};
use style::values::computed::Percentage;
use style::values::generics::transform::{Transform, TransformOperation}; use style::values::generics::transform::{Transform, TransformOperation};
fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA { fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA {
@ -83,60 +82,6 @@ fn test_rgba_color_interepolation_out_of_range_clamped_2() {
); );
} }
// Transform
#[test]
fn test_transform_interpolation_on_translate() {
use style::values::computed::{CalcLengthOrPercentage, Length, LengthOrPercentage};
let from = Transform(vec![TransformOperation::Translate3D(
LengthOrPercentage::Length(Length::new(0.)),
LengthOrPercentage::Length(Length::new(100.)),
Length::new(25.),
)]);
let to = Transform(vec![TransformOperation::Translate3D(
LengthOrPercentage::Length(Length::new(100.)),
LengthOrPercentage::Length(Length::new(0.)),
Length::new(75.),
)]);
assert_eq!(
from.animate(&to, Procedure::Interpolate { progress: 0.5 })
.unwrap(),
Transform(vec![TransformOperation::Translate3D(
LengthOrPercentage::Length(Length::new(50.)),
LengthOrPercentage::Length(Length::new(50.)),
Length::new(50.),
)])
);
let from = Transform(vec![TransformOperation::Translate3D(
LengthOrPercentage::Percentage(Percentage(0.5)),
LengthOrPercentage::Percentage(Percentage(1.0)),
Length::new(25.),
)]);
let to = Transform(vec![TransformOperation::Translate3D(
LengthOrPercentage::Length(Length::new(100.)),
LengthOrPercentage::Length(Length::new(50.)),
Length::new(75.),
)]);
assert_eq!(
from.animate(&to, Procedure::Interpolate { progress: 0.5 })
.unwrap(),
Transform(vec![TransformOperation::Translate3D(
// calc(50px + 25%)
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(
Length::new(50.),
Some(Percentage(0.25))
)),
// calc(25px + 50%)
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(
Length::new(25.),
Some(Percentage(0.5))
)),
Length::new(50.),
)])
);
}
#[test] #[test]
fn test_transform_interpolation_on_scale() { fn test_transform_interpolation_on_scale() {
let from = Transform(vec![TransformOperation::Scale3D(1.0, 2.0, 1.0)]); let from = Transform(vec![TransformOperation::Scale3D(1.0, 2.0, 1.0)]);
@ -197,29 +142,3 @@ fn test_transform_interpolation_on_skew() {
)]) )])
); );
} }
#[test]
fn test_transform_interpolation_on_mismatched_lists() {
use style::values::computed::{Angle, Length, LengthOrPercentage};
let from = Transform(vec![TransformOperation::Rotate3D(
0.0,
0.0,
1.0,
Angle::from_radians(100.0),
)]);
let to = Transform(vec![TransformOperation::Translate3D(
LengthOrPercentage::Length(Length::new(100.)),
LengthOrPercentage::Length(Length::new(0.)),
Length::new(0.),
)]);
assert_eq!(
from.animate(&to, Procedure::Interpolate { progress: 0.5 })
.unwrap(),
Transform(vec![TransformOperation::InterpolateMatrix {
from_list: from.clone(),
to_list: to.clone(),
progress: Percentage(0.5),
}])
);
}

View file

@ -4,19 +4,6 @@
use app_units::Au; use app_units::Au;
use style::attr::{parse_length, AttrValue, LengthOrPercentageOrAuto}; use style::attr::{parse_length, AttrValue, LengthOrPercentageOrAuto};
use style::values::computed::{CalcLengthOrPercentage, Percentage};
#[test]
fn test_length_calc() {
let calc = CalcLengthOrPercentage::new(Au(10).into(), Some(Percentage(0.2)));
assert_eq!(calc.to_used_value(Some(Au(10))), Some(Au(12)));
assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_used_value(None), None);
let calc = CalcLengthOrPercentage::new(Au(10).into(), None);
assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_used_value(None), Some(Au(10)));
}
#[test] #[test]
fn test_parse_double() { fn test_parse_double() {

View file

@ -4,13 +4,11 @@
use crate::properties::{parse, parse_input}; use crate::properties::{parse, parse_input};
use crate::stylesheets::block_from; use crate::stylesheets::block_from;
use style::computed_values::display::T as Display;
use style::properties::declaration_block::PropertyDeclarationBlock; use style::properties::declaration_block::PropertyDeclarationBlock;
use style::properties::parse_property_declaration_list; use style::properties::parse_property_declaration_list;
use style::properties::{Importance, PropertyDeclaration}; use style::properties::{Importance, PropertyDeclaration};
use style::values::specified::url::SpecifiedUrl; use style::values::specified::url::SpecifiedUrl;
use style::values::specified::NoCalcLength; use style::values::specified::Length;
use style::values::specified::{Length, LengthOrPercentage, LengthOrPercentageOrAuto};
use style_traits::ToCss; use style_traits::ToCss;
trait ToCssString { trait ToCssString {
@ -25,53 +23,6 @@ impl ToCssString for PropertyDeclarationBlock {
} }
} }
#[test]
fn property_declaration_block_should_serialize_correctly() {
use style::properties::longhands::overflow_x::SpecifiedValue as OverflowValue;
let declarations = vec![
(
PropertyDeclaration::Width(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(
70f32,
))),
Importance::Normal,
),
(
PropertyDeclaration::MinHeight(LengthOrPercentage::Length(NoCalcLength::from_px(
20f32,
))),
Importance::Normal,
),
(
PropertyDeclaration::Height(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(
20f32,
))),
Importance::Important,
),
(
PropertyDeclaration::Display(Display::InlineBlock),
Importance::Normal,
),
(
PropertyDeclaration::OverflowX(OverflowValue::Auto),
Importance::Normal,
),
(
PropertyDeclaration::OverflowY(OverflowValue::Auto),
Importance::Normal,
),
];
let block = block_from(declarations);
let css_string = block.to_css_string();
assert_eq!(
css_string,
"width: 70px; min-height: 20px; height: 20px !important; display: inline-block; overflow: auto;"
);
}
mod shorthand_serialization { mod shorthand_serialization {
pub use super::*; pub use super::*;

View file

@ -17,20 +17,16 @@ use std::sync::atomic::AtomicBool;
use style::context::QuirksMode; use style::context::QuirksMode;
use style::error_reporting::{ContextualParseError, ParseErrorReporter}; use style::error_reporting::{ContextualParseError, ParseErrorReporter};
use style::media_queries::MediaList; use style::media_queries::MediaList;
use style::properties::longhands::{self, animation_timing_function}; use style::properties::longhands;
use style::properties::{CSSWideKeyword, CustomDeclaration}; use style::properties::{CSSWideKeyword, CustomDeclaration};
use style::properties::{CustomDeclarationValue, Importance}; use style::properties::{CustomDeclarationValue, Importance};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use style::shared_lock::SharedRwLock; use style::shared_lock::SharedRwLock;
use style::stylesheets::keyframes_rule::{Keyframe, KeyframePercentage, KeyframeSelector};
use style::stylesheets::{ use style::stylesheets::{
CssRule, CssRules, KeyframesRule, NamespaceRule, StyleRule, Stylesheet, StylesheetContents, CssRule, CssRules, NamespaceRule, StyleRule, Stylesheet, StylesheetContents,
}; };
use style::stylesheets::{Namespaces, Origin}; use style::stylesheets::{Namespaces, Origin};
use style::values::computed::Percentage; use style::values::specified::PositionComponent;
use style::values::specified::TimingFunction;
use style::values::specified::{LengthOrPercentageOrAuto, PositionComponent};
use style::values::{CustomIdent, KeyframesName};
pub fn block_from<I>(iterable: I) -> PropertyDeclarationBlock pub fn block_from<I>(iterable: I) -> PropertyDeclarationBlock
where where
@ -61,14 +57,6 @@ fn test_parse_stylesheet() {
display: block; display: block;
} }
#d1 > .ok { background: blue; } #d1 > .ok { background: blue; }
@keyframes foo {
from { width: 0% }
to {
width: 100%;
width: 50% !important; /* !important not allowed here */
animation-name: 'foo'; /* animation properties not allowed here */
animation-timing-function: ease; /* … except animation-timing-function */
}
}"; }";
let url = ServoUrl::parse("about::test").unwrap(); let url = ServoUrl::parse("about::test").unwrap();
let lock = SharedRwLock::new(); let lock = SharedRwLock::new();
@ -278,56 +266,6 @@ fn test_parse_stylesheet() {
column: 9, column: 9,
}, },
}))), }))),
CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule {
name: KeyframesName::Ident(CustomIdent("foo".into())),
keyframes: vec![
Arc::new(stylesheet.shared_lock.wrap(Keyframe {
selector: KeyframeSelector::new_for_unit_testing(vec![
KeyframePercentage::new(0.),
]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![(
PropertyDeclaration::Width(
LengthOrPercentageOrAuto::Percentage(Percentage(0.)),
),
Importance::Normal,
)]))),
source_location: SourceLocation {
line: 17,
column: 13,
},
})),
Arc::new(stylesheet.shared_lock.wrap(Keyframe {
selector: KeyframeSelector::new_for_unit_testing(vec![
KeyframePercentage::new(1.),
]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(
PropertyDeclaration::Width(
LengthOrPercentageOrAuto::Percentage(Percentage(1.)),
),
Importance::Normal,
),
(
PropertyDeclaration::AnimationTimingFunction(
animation_timing_function::SpecifiedValue(vec![
TimingFunction::ease(),
]),
),
Importance::Normal,
),
]))),
source_location: SourceLocation {
line: 18,
column: 13,
},
})),
],
vendor_prefix: None,
source_location: SourceLocation {
line: 16,
column: 19,
},
}))),
], ],
&stylesheet.shared_lock, &stylesheet.shared_lock,
), ),

View file

@ -17,6 +17,7 @@ use style::stylesheets::{CssRuleType, Origin, Stylesheet, StylesheetInDocument};
use style::values::specified::LengthOrPercentageOrAuto::{self, Auto}; use style::values::specified::LengthOrPercentageOrAuto::{self, Auto};
use style::values::specified::NoCalcLength::{self, ViewportPercentage}; use style::values::specified::NoCalcLength::{self, ViewportPercentage};
use style::values::specified::ViewportPercentageLength::Vw; use style::values::specified::ViewportPercentageLength::Vw;
use style::values::specified::LengthOrPercentage;
use style_traits::viewport::*; use style_traits::viewport::*;
use style_traits::{ParsingMode, PinchZoomFactor}; use style_traits::{ParsingMode, PinchZoomFactor};
@ -96,15 +97,15 @@ macro_rules! assert_decl_len {
macro_rules! viewport_length { macro_rules! viewport_length {
($value:expr, px) => { ($value:expr, px) => {
ViewportLength::Specified(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::Length(NoCalcLength::from_px(
$value,
)))
};
($value:expr, vw) => {
ViewportLength::Specified(LengthOrPercentageOrAuto::Length(ViewportPercentage(Vw(
$value, $value,
)))) ))))
}; };
($value:expr, vw) => {
ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::Length(ViewportPercentage(Vw(
$value,
)))))
};
} }
#[test] #[test]

View file

@ -1,6 +1,4 @@
[variable-substitution-replaced-size.html] [variable-substitution-replaced-size.html]
[height on IFRAME]
expected: FAIL
[width on INPUT] [width on INPUT]
expected: FAIL expected: FAIL
@ -8,6 +6,3 @@
[height on INPUT] [height on INPUT]
expected: FAIL expected: FAIL
[height on CANVAS]
expected: FAIL