Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min/max-width/height, replaced elements #25207

Merged
merged 19 commits into from Dec 10, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a2c2b29
Move `clamp_*` functions to methods of `Length`
SimonSapin Dec 7, 2019
ce7e84b
Replace `percent_resolved_*` functions with methods
SimonSapin Dec 7, 2019
999dd72
Account for min/max-width in outer intrinsic sizing
SimonSapin Dec 7, 2019
bf96988
Add min/max-width/height support for `inline-block`
SimonSapin Dec 7, 2019
c40583b
Move replaced box used size computation to a method of `ReplacedConte…
SimonSapin Dec 7, 2019
b73eb49
Add sizing of inline replaced boxes
SimonSapin Dec 7, 2019
8996be3
Don’t assume replaced elements have an intrinsic size
SimonSapin Dec 7, 2019
80b2b5f
Fix min/max-content of replaced boxes
SimonSapin Dec 7, 2019
f43dc3a
Remove inline/block_size from AbsolutelyPositionedFragment
SimonSapin Dec 7, 2019
e86222d
Remove AbsoluteBoxOffsets’s type parameter
SimonSapin Dec 7, 2019
14ddf39
Rename ReplacedContent::used_size to used_size_as_if_inline_element
SimonSapin Dec 7, 2019
f09c14a
impl From<&'_ DefiniteContainingBlock> for ContainingBlock
SimonSapin Dec 7, 2019
1fcdde9
Move two AbsoluteBoxOffsets fields into a Vec2
SimonSapin Dec 7, 2019
1fa20e9
Implement replaced abspos
SimonSapin Dec 7, 2019
c07c980
Delayed initialization over mutation
SimonSapin Dec 8, 2019
2906722
Conditionsals over closures
SimonSapin Dec 8, 2019
be8df1d
Move `solve_axis` function to module level
SimonSapin Dec 8, 2019
a17db21
Struct with named fields over large tuple
SimonSapin Dec 8, 2019
53ce714
Fix a “Accessing content size that was not requested” panic
SimonSapin Dec 8, 2019
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Replace `percent_resolved_*` functions with methods

  • Loading branch information
SimonSapin committed Dec 10, 2019
commit ce7e84be72554ae8d5423fe6fd199bd4009134c8
@@ -21,8 +21,7 @@ use rayon_croissant::ParallelIteratorExt;
use servo_arc::Arc;
use style::computed_values::position::T as Position;
use style::properties::ComputedValues;
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
use style::values::generics::length::MaxSize;
use style::values::computed::{Length, LengthOrAuto};
use style::Zero;

mod construct;
@@ -365,10 +364,14 @@ fn layout_in_flow_non_replaced_block_level<'a>(
let pb = &padding + &border;
let pb_inline_sum = pb.inline_sum();

let box_size = percent_resolved_box_size(style.box_size(), containing_block);
let max_box_size = percent_resolved_max_box_size(style.max_box_size(), containing_block);
let min_box_size =
percent_resolved_box_size(style.min_box_size(), containing_block).auto_is(Length::zero);
let box_size = style.box_size().percentages_relative_to(containing_block);
let max_box_size = style
.max_box_size()
.percentages_relative_to(containing_block);
let min_box_size = style
.min_box_size()
.percentages_relative_to(containing_block)
.auto_is(Length::zero);

// https://drafts.csswg.org/css2/visudet.html#min-max-widths
let solve_inline_margins = |inline_size| {
@@ -529,10 +532,14 @@ fn layout_in_flow_replaced_block_level<'a>(
// FIXME(nox): This can divide by zero.
let intrinsic_ratio = intrinsic_size.inline.px() / intrinsic_size.block.px();

let box_size = percent_resolved_box_size(style.box_size(), containing_block);
let min_box_size =
percent_resolved_box_size(style.min_box_size(), containing_block).auto_is(Length::zero);
let max_box_size = percent_resolved_max_box_size(style.max_box_size(), containing_block);
let box_size = style.box_size().percentages_relative_to(containing_block);
let min_box_size = style
.min_box_size()
.percentages_relative_to(containing_block)
.auto_is(Length::zero);
let max_box_size = style
.max_box_size()
.percentages_relative_to(containing_block);

let clamp = |inline_size: Length, block_size: Length| {
(
@@ -701,37 +708,3 @@ fn solve_inline_margins_for_in_flow_block_level(
(LengthOrAuto::LengthPercentage(start), _) => (start, inline_margins - start),
}
}

fn percent_resolved_box_size(
box_size: Vec2<LengthPercentageOrAuto>,
containing_block: &ContainingBlock,
) -> Vec2<LengthOrAuto> {
Vec2 {
inline: box_size
.inline
.percentage_relative_to(containing_block.inline_size),
block: box_size
.block
.maybe_percentage_relative_to(containing_block.block_size.non_auto()),
}
}

fn percent_resolved_max_box_size(
max_box_size: Vec2<MaxSize<LengthPercentage>>,
containing_block: &ContainingBlock,
) -> Vec2<Option<Length>> {
Vec2 {
inline: match max_box_size.inline {
MaxSize::LengthPercentage(max_inline_size) => {
Some(max_inline_size.percentage_relative_to(containing_block.inline_size))
},
MaxSize::None => None,
},
block: match max_box_size.block {
MaxSize::LengthPercentage(max_block_size) => {
max_block_size.maybe_percentage_relative_to(containing_block.block_size.non_auto())
},
MaxSize::None => None,
},
}
}
@@ -2,11 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::ContainingBlock;
use std::fmt;
use std::ops::{Add, AddAssign, Sub};
use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection};
use style::logical_geometry::{PhysicalCorner, WritingMode};
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
use style::values::generics::length::MaxSize;
use style::Zero;
use style_traits::CSSPixel;

@@ -151,6 +153,39 @@ impl flow_relative::Vec2<LengthOrAuto> {
}
}

impl flow_relative::Vec2<LengthPercentageOrAuto> {
pub fn percentages_relative_to(
&self,
containing_block: &ContainingBlock,
) -> flow_relative::Vec2<LengthOrAuto> {
flow_relative::Vec2 {
inline: self
.inline
.percentage_relative_to(containing_block.inline_size),
block: self
.block
.maybe_percentage_relative_to(containing_block.block_size.non_auto()),
}
}
}

impl flow_relative::Vec2<MaxSize<LengthPercentage>> {
pub fn percentages_relative_to(
&self,
containing_block: &ContainingBlock,
) -> flow_relative::Vec2<Option<Length>> {
flow_relative::Vec2 {
inline: self
.inline
.to_option()
.map(|lp| lp.percentage_relative_to(containing_block.inline_size)),
block: self.block.to_option().and_then(|olp| {
olp.maybe_percentage_relative_to(containing_block.block_size.non_auto())
}),
}
}
}

impl flow_relative::Rect<Length> {
pub fn zero() -> Self {
Self {
@@ -207,6 +207,15 @@ impl<LengthPercentage> MaxSize<LengthPercentage> {
pub fn none() -> Self {
MaxSize::None
}

/// Convert
#[cfg(not(feature = "gecko"))]
pub fn to_option(self) -> Option<LengthPercentage> {

This comment has been minimized.

Copy link
@nox

nox Dec 9, 2019

Member

Nit: Just name that length, like Result::ok?

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Dec 9, 2019

Author Member

This is subtle but I mean this method not as "if this enum is the LengthPercentage variant, access its field" but rather "losslessly convert all the information in this enum". If/when we add support for e.g. min-width: min-content https://drafts.csswg.org/css-sizing/#min-size-properties this enum will have additional variants like it does today for Gecko, this method will need to be removed, and the callers should be modified to handle those variants separately.

match self {
Self::LengthPercentage(lp) => Some(lp),
Self::None => None,
}
}
}

/// A generic `<length>` | `<number>` value for the `-moz-tab-size` property.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.