Permalink
Browse files

Auto merge of #22864 - emilio:gecko-sync, r=emilio

style: Rename MozLength to Size, and MaxLength to MaxSize.

MozLength is not a very descriptive name. If we're going to use it in both Gecko
and Servo we may as well name it something more accurate.

I would've chosen `ContentSize` per CSS2[1][2] if it wasn't a lie in presence
of box-sizing. I don't have better ideas than `Size`, given that.

[1]: https://drafts.csswg.org/css2/visudet.html#propdef-width
[2]: https://drafts.csswg.org/css2/box.html#content-width

Differential Revision: https://phabricator.services.mozilla.com/D19280

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22864)
<!-- Reviewable:end -->
  • Loading branch information...
bors-servo committed Feb 11, 2019
2 parents 7ed6b9d + 6b4fe0b commit de5f87571d18599b6b4a0b6450d1885706353394
@@ -67,9 +67,7 @@ use style::context::SharedStyleContext;
use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::{
LengthPercentageOrAuto, MaxLength, NonNegativeLengthPercentageOrAuto,
};
use style::values::computed::{LengthPercentageOrAuto, MaxSize, Size};

/// Information specific to floated blocks.
#[derive(Clone, Serialize)]
@@ -421,24 +419,24 @@ impl CandidateBSizeIterator {
// `min-height` and `max-height`, percentage values are ignored.

let block_size = match fragment.style.content_block_size() {
NonNegativeLengthPercentageOrAuto::Auto => MaybeAuto::Auto,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
Size::Auto => MaybeAuto::Auto,
Size::LengthPercentage(ref lp) => {
MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size))
},
};

let max_block_size = match fragment.style.max_block_size() {
MaxLength::None => None,
MaxLength::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(block_container_block_size)
},
MaxSize::None => None,
MaxSize::LengthPercentage(ref lp) => lp.maybe_to_used_value(block_container_block_size),
};

let min_block_size = fragment
.style
.min_block_size()
.maybe_to_used_value(block_container_block_size)
.unwrap_or(Au(0));
let min_block_size = match fragment.style.min_block_size() {
Size::Auto => MaybeAuto::Auto,
Size::LengthPercentage(ref lp) => {
MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size))
},
}
.specified_or_zero();

// 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 {
@@ -1402,7 +1400,7 @@ impl BlockFlow {
let content_block_size = self.fragment.style().content_block_size();

match content_block_size {
NonNegativeLengthPercentageOrAuto::Auto => {
Size::Auto => {
let container_size = containing_block_size?;
let (block_start, block_end) = {
let position = self.fragment.style().logical_position();
@@ -1437,9 +1435,7 @@ impl BlockFlow {
(_, _) => None,
}
},
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(containing_block_size)
},
Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(containing_block_size),
}
}

@@ -1796,7 +1792,8 @@ impl BlockFlow {
.fragment
.style()
.min_inline_size()
.to_used_value(self.base.block_container_inline_size);
.to_used_value(self.base.block_container_inline_size)
.unwrap_or(Au(0));
let specified_inline_size = self.fragment.style().content_inline_size();
let container_size = self.base.block_container_inline_size;
let inline_size = match specified_inline_size.to_used_value(container_size) {
@@ -2025,7 +2022,7 @@ impl BlockFlow {
// If `max-width` is set, then don't perform this speculation. We guess that the
// page set `max-width` in order to avoid hitting floats. The search box on Google
// SERPs falls into this category.
if self.fragment.style.max_inline_size() != MaxLength::None {
if self.fragment.style.max_inline_size() != MaxSize::None {
return;
}

@@ -2157,10 +2154,8 @@ impl Flow for BlockFlow {
// rather than bubbling up children inline width.
// FIXME(emilio): This should probably be writing-mode-aware.
let consult_children = match self.fragment.style().get_position().width {
NonNegativeLengthPercentageOrAuto::Auto => true,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(None).is_none()
},
Size::Auto => true,
Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(None).is_none(),
};
self.bubble_inline_sizes_for_block(consult_children);
self.fragment
@@ -2911,7 +2906,8 @@ pub trait ISizeAndMarginsComputer {
.fragment()
.style()
.min_inline_size()
.to_used_value(containing_block_inline_size);
.to_used_value(containing_block_inline_size)
.unwrap_or(Au(0));
if computed_min_inline_size > solution.inline_size {
input.computed_inline_size = MaybeAuto::Specified(computed_min_inline_size);
solution = self.solve_inline_size_constraints(block, &input);
@@ -29,9 +29,7 @@ use style::logical_geometry::{Direction, LogicalSize};
use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::flex::FlexBasis;
use style::values::computed::{
MaxLength, NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto,
};
use style::values::computed::{MaxSize, Size};
use style::values::generics::flex::FlexBasis as GenericFlexBasis;

/// The size of an axis. May be a specified size, a min/max
@@ -46,21 +44,12 @@ enum AxisSize {
impl AxisSize {
/// Generate a new available cross or main axis size from the specified size of the container,
/// containing block size, min constraint, and max constraint
pub fn new(
size: NonNegativeLengthPercentageOrAuto,
content_size: Option<Au>,
min: NonNegativeLengthPercentage,
max: MaxLength,
) -> AxisSize {
pub fn new(size: Size, content_size: Option<Au>, min: Size, max: MaxSize) -> AxisSize {
match size {
NonNegativeLengthPercentageOrAuto::Auto => {
AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None))
},
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
match lp.maybe_to_used_value(content_size) {
Some(length) => AxisSize::Definite(length),
None => AxisSize::Infinite,
}
Size::Auto => AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)),
Size::LengthPercentage(ref lp) => match lp.maybe_to_used_value(content_size) {
Some(length) => AxisSize::Definite(length),
None => AxisSize::Infinite,
},
}
}
@@ -70,26 +59,20 @@ impl AxisSize {
/// and the container size, then return the used value of flex basis. it can be used to help
/// determining the flex base size and to indicate whether the main size of the item
/// is definite after flex size resolving.
fn from_flex_basis(
flex_basis: FlexBasis,
main_length: NonNegativeLengthPercentageOrAuto,
containing_length: Au,
) -> MaybeAuto {
fn from_flex_basis(flex_basis: FlexBasis, main_length: Size, containing_length: Au) -> MaybeAuto {
let width = match flex_basis {
GenericFlexBasis::Content => return MaybeAuto::Auto,
GenericFlexBasis::Width(width) => width,
};

let width = match width {
NonNegativeLengthPercentageOrAuto::Auto => main_length,
Size::Auto => main_length,
_ => width,
};

match width {
NonNegativeLengthPercentageOrAuto::Auto => MaybeAuto::Auto,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
MaybeAuto::Specified(lp.to_used_value(containing_length))
},
Size::Auto => MaybeAuto::Auto,
Size::LengthPercentage(ref lp) => MaybeAuto::Specified(lp.to_used_value(containing_length)),
}
}

@@ -183,7 +166,8 @@ impl FlexItem {
.fragment
.style
.min_inline_size()
.to_used_value(containing_length);
.to_used_value(containing_length)
.unwrap_or(Au(0));
},
Direction::Block => {
let basis = from_flex_basis(
@@ -205,7 +189,8 @@ impl FlexItem {
.fragment
.style
.min_block_size()
.to_used_value(containing_length);
.to_used_value(containing_length)
.unwrap_or(Au(0));
},
}
}
@@ -10,7 +10,7 @@ use std::cmp::{max, min};
use std::fmt;
use style::computed_values::float::T as StyleFloat;
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::values::computed::NonNegativeLengthPercentageOrAuto;
use style::values::computed::Size;

/// The kind of float: left or right.
#[derive(Clone, Copy, Debug, Serialize)]
@@ -549,8 +549,8 @@ impl SpeculatedFloatPlacement {
// might flow around this float.
let inline_size = flow.as_block().fragment.style.content_inline_size();
let fixed = match inline_size {
NonNegativeLengthPercentageOrAuto::Auto => false,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
Size::Auto => false,
Size::LengthPercentage(ref lp) => {
lp.0.is_definitely_zero() || lp.0.maybe_to_used_value(None).is_some()
},
};
@@ -61,9 +61,7 @@ use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace;
use style::values::computed::counters::ContentItem;
use style::values::computed::{
LengthPercentage, LengthPercentageOrAuto, NonNegativeLengthPercentageOrAuto,
};
use style::values::computed::{LengthPercentage, LengthPercentageOrAuto, Size};
use style::values::generics::box_::{Perspective, VerticalAlign};
use style::values::generics::transform;
use webrender_api::{self, LayoutTransform};
@@ -991,7 +989,13 @@ impl Fragment {
.content_inline_size()
.to_used_value(Au(0))
.unwrap_or(Au(0));
specified = max(style.min_inline_size().to_used_value(Au(0)), specified);
specified = max(
style
.min_inline_size()
.to_used_value(Au(0))
.unwrap_or(Au(0)),
specified,
);
if let Some(max) = style.max_inline_size().to_used_value(Au(0)) {
specified = min(specified, max)
}
@@ -1615,10 +1619,8 @@ impl Fragment {
SpecificFragmentInfo::Iframe(_) |
SpecificFragmentInfo::Svg(_) => {
let inline_size = match self.style.content_inline_size() {
NonNegativeLengthPercentageOrAuto::Auto => None,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(None)
},
Size::Auto => None,
Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
};

let mut inline_size = inline_size.unwrap_or_else(|| {
@@ -11,10 +11,8 @@ use std::cmp::{max, min};
use std::fmt;
use style::logical_geometry::{LogicalMargin, WritingMode};
use style::properties::ComputedValues;
use style::values::computed::MaxLength;
use style::values::computed::{
LengthPercentageOrAuto, NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto,
};
use style::values::computed::MaxSize;
use style::values::computed::{LengthPercentageOrAuto, Size};

/// A collapsible margin. See CSS 2.1 § 8.3.1.
#[derive(Clone, Copy, Debug)]
@@ -137,8 +135,8 @@ impl MarginCollapseInfo {
MarginCollapseState::AccumulatingCollapsibleTopMargin => {
may_collapse_through = may_collapse_through &&
match fragment.style().content_block_size() {
NonNegativeLengthPercentageOrAuto::Auto => true,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
Size::Auto => true,
Size::LengthPercentage(ref lp) => {
lp.is_definitely_zero() ||
lp.maybe_to_used_value(containing_block_size).is_none()
},
@@ -498,13 +496,10 @@ impl MaybeAuto {
/// Receive an optional container size and return used value for width or height.
///
/// `style_length`: content size as given in the CSS.
pub fn style_length(
style_length: NonNegativeLengthPercentageOrAuto,
container_size: Option<Au>,
) -> MaybeAuto {
pub fn style_length(style_length: Size, container_size: Option<Au>) -> MaybeAuto {
match style_length {
NonNegativeLengthPercentageOrAuto::Auto => MaybeAuto::Auto,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
Size::Auto => MaybeAuto::Auto,
Size::LengthPercentage(ref lp) => {
MaybeAuto::from_option(lp.0.maybe_to_used_value(container_size))
},
}
@@ -571,17 +566,20 @@ impl SizeConstraint {
/// Create a `SizeConstraint` for an axis.
pub fn new(
container_size: Option<Au>,
min_size: NonNegativeLengthPercentage,
max_size: MaxLength,
min_size: Size,
max_size: MaxSize,
border: Option<Au>,
) -> SizeConstraint {
let mut min_size = min_size
.maybe_to_used_value(container_size)
.unwrap_or(Au(0));
let mut min_size = match min_size {
Size::Auto => Au(0),
Size::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(container_size).unwrap_or(Au(0))
},
};

let mut max_size = match max_size {
MaxLength::None => None,
MaxLength::LengthPercentage(ref lp) => lp.maybe_to_used_value(container_size),
MaxSize::None => None,
MaxSize::LengthPercentage(ref lp) => lp.maybe_to_used_value(container_size),
};

// Make sure max size is not smaller than min size.
@@ -19,7 +19,7 @@ use std::fmt;
use std::sync::Arc;
use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues;
use style::values::computed::{MaxLength, NonNegativeLengthPercentageOrAuto};
use style::values::computed::{MaxSize, Size};
use style::values::generics::column::ColumnCount;
use style::values::Either;

@@ -155,14 +155,12 @@ impl Flow for MulticolFlow {
available_block_size: {
let style = &self.block_flow.fragment.style;
let size = match style.content_block_size() {
NonNegativeLengthPercentageOrAuto::Auto => None,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(None)
},
Size::Auto => None,
Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
};
let size = size.or_else(|| match style.max_block_size() {
MaxLength::None => None,
MaxLength::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
MaxSize::None => None,
MaxSize::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
});

size.unwrap_or_else(|| {
@@ -33,7 +33,7 @@ use style::logical_geometry::LogicalSize;
use style::properties::style_structs::Background;
use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::NonNegativeLengthPercentageOrAuto;
use style::values::computed::Size;
use style::values::CSSFloat;

#[allow(unsafe_code)]
@@ -301,14 +301,14 @@ impl Flow for TableFlow {
self.column_intrinsic_inline_sizes
.push(ColumnIntrinsicInlineSize {
minimum_length: match *specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => Au(0),
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
Size::Auto => Au(0),
Size::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(None).unwrap_or(Au(0))
},
},
percentage: match *specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => 0.0,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => {
Size::Auto => 0.0,
Size::LengthPercentage(ref lp) => {
lp.0.as_percentage().map_or(0.0, |p| p.0)
},
},
Oops, something went wrong.

0 comments on commit de5f875

Please sign in to comment.