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 all commits
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

@@ -17,7 +17,6 @@ use std::sync::Arc;
use style::dom::TNode;
use style::properties::ComputedValues;
use style::selector_parser::PseudoElement;
use style::values::computed::Length;

#[derive(Clone, Copy)]
pub enum WhichPseudoElement {
@@ -299,7 +298,10 @@ impl Drop for BoxSlot<'_> {
pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode + Send + Sync {
fn is_element(self) -> bool;
fn as_text(self) -> Option<String>;
fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<Length>)>;

/// Returns the image if it’s loaded, and its size in image pixels
/// adjusted for `image_density`.
fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<f64>)>;

This comment has been minimized.

Copy link
@nox

nox Dec 9, 2019

Member

Why the type change, and why not CSSFloat?

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Dec 9, 2019

Author Member

It’s not Length because it is measured in image pixels rather than CSS px.

I wanted to make it u32 but it’s already divided by script::dom::htmlimageelement::ImageRequest::current_pixel_density. I’m not sure what that density means exactly or if diving there is correct.

It could be CSSFloat. It probably wouldn’t affect much since it’s not kept in memory for a long time.

fn first_child(self) -> Option<Self>;
fn next_sibling(self) -> Option<Self>;
fn parent_node(self) -> Option<Self>;
@@ -328,22 +330,22 @@ where
}
}

fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<Length>)> {
fn as_image(self) -> Option<(Option<Arc<NetImage>>, Vec2<f64>)> {
let node = self.to_threadsafe();
let (resource, metadata) = node.image_data()?;
let (width, height) = resource
.as_ref()
.map(|image| (image.width, image.height))
.or_else(|| metadata.map(|metadata| (metadata.width, metadata.height)))
.unwrap_or((0, 0));
let (mut width, mut height) = (width as f32, height as f32);
let (mut width, mut height) = (width as f64, height as f64);
if let Some(density) = node.image_density().filter(|density| *density != 1.) {
width = (width as f64 / density) as f32;
height = (height as f64 / density) as f32;
width = width / density;
height = height / density;
}
let size = Vec2 {
x: Length::new(width),
y: Length::new(height),
x: width,
y: height,
};
Some((resource, size))
}
@@ -393,7 +393,7 @@ where
style.clone(),
display_inside,
contents,
ContentSizesRequest::inline_if(style.inline_size_is_auto()),
ContentSizesRequest::inline_if(!style.inline_size_is_length()),
),
))
};
@@ -590,7 +590,7 @@ where
&style,
ContentSizesRequest::inline_if(
max_assign_in_flow_outer_content_sizes_to.is_some() &&
style.inline_size_is_auto(),
!style.inline_size_is_length(),
),
);
if let Some(to) = max_assign_in_flow_outer_content_sizes_to {
@@ -607,7 +607,7 @@ where
} => {
let content_sizes = ContentSizesRequest::inline_if(
max_assign_in_flow_outer_content_sizes_to.is_some() &&
style.inline_size_is_auto(),
!style.inline_size_is_length(),
);
let contents = IndependentFormattingContext::construct(
context,
@@ -33,7 +33,7 @@ impl FloatBox {
display_inside: DisplayInside,
contents: Contents<impl NodeExt<'dom>>,
) -> Self {
let content_sizes = ContentSizesRequest::inline_if(style.inline_size_is_auto());
let content_sizes = ContentSizesRequest::inline_if(!style.inline_size_is_length());
Self {
contents: IndependentFormattingContext::construct(
context,
@@ -465,9 +465,7 @@ fn layout_atomic<'box_tree>(

let fragment = match atomic.as_replaced() {
Ok(replaced) => {
// FIXME: implement https://drafts.csswg.org/css2/visudet.html#inline-replaced-width
// and https://drafts.csswg.org/css2/visudet.html#inline-replaced-height
let size = Vec2::zero();
let size = replaced.used_size_as_if_inline_element(ifc.containing_block, &atomic.style);
let fragments = replaced.make_fragments(&atomic.style, size.clone());
let content_rect = Rect { start_corner, size };
BoxFragment {
@@ -482,10 +480,29 @@ fn layout_atomic<'box_tree>(
},
Err(non_replaced) => {
let box_size = atomic.style.box_size();
let inline_size = box_size.inline.percentage_relative_to(cbis).auto_is(|| {
let available_size = cbis - pbm.inline_sum();
atomic.content_sizes.shrink_to_fit(available_size)
});
let max_box_size = atomic
.style
.max_box_size()
.percentages_relative_to(ifc.containing_block);
let min_box_size = atomic
.style
.min_box_size()
.percentages_relative_to(ifc.containing_block)
.auto_is(Length::zero);

// https://drafts.csswg.org/css2/visudet.html#inlineblock-width
let tentative_inline_size =
box_size.inline.percentage_relative_to(cbis).auto_is(|| {
let available_size = cbis - pbm.inline_sum();
atomic.content_sizes.shrink_to_fit(available_size)
});

// https://drafts.csswg.org/css2/visudet.html#min-max-widths
// In this case “applying the rules above again” with a non-auto inline-size
// always results in that size.
let inline_size = tentative_inline_size
.clamp_between_extremums(min_box_size.inline, max_box_size.inline);

let block_size = box_size
.block
.maybe_percentage_relative_to(ifc.containing_block.block_size.non_auto());
@@ -508,7 +525,16 @@ fn layout_atomic<'box_tree>(
dummy_tree_rank,
ifc.absolutely_positioned_fragments,
);
let block_size = block_size.auto_is(|| independent_layout.content_block_size);

// https://drafts.csswg.org/css2/visudet.html#block-root-margin
let tentative_block_size = block_size.auto_is(|| independent_layout.content_block_size);

// https://drafts.csswg.org/css2/visudet.html#min-max-heights
// In this case “applying the rules above again” with a non-auto block-size
// always results in that size.
let block_size = tentative_block_size
.clamp_between_extremums(min_box_size.block, max_box_size.block);

let content_rect = Rect {
start_corner,
size: Vec2 {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.