layout: Speculate that the inline sizes of floats with percentage

inline sizes are nonzero.

This is a bit of a hack.
This commit is contained in:
Patrick Walton 2016-04-27 12:38:30 -07:00
parent b4f573db1a
commit 94306cd183

View file

@ -11,6 +11,7 @@ use std::fmt;
use std::i32; use std::i32;
use style::computed_values::float; use style::computed_values::float;
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::values::computed::LengthOrPercentageOrAuto;
/// The kind of float: left or right. /// The kind of float: left or right.
#[derive(Clone, RustcEncodable, Debug, Copy)] #[derive(Clone, RustcEncodable, Debug, Copy)]
@ -490,14 +491,30 @@ impl SpeculatedFloatPlacement {
} }
let base_flow = flow::base(flow); let base_flow = flow::base(flow);
if !base_flow.flags.is_float() {
return
}
let mut float_inline_size = base_flow.intrinsic_inline_sizes.preferred_inline_size;
if float_inline_size == Au(0) {
if flow.is_block_like() {
// Hack: If the size of the float is a percentage, then there's no way we can guess
// at its size now. So just pick an arbitrary 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.
if let LengthOrPercentageOrAuto::Percentage(percentage) =
flow.as_block().fragment.style.content_inline_size() {
if percentage > 0.0 {
float_inline_size = Au::from_px(1)
}
}
}
}
match base_flow.flags.float_kind() { match base_flow.flags.float_kind() {
float::T::none => {} float::T::none => {}
float::T::left => { float::T::left => self.left = self.left + float_inline_size,
self.left = self.left + base_flow.intrinsic_inline_sizes.preferred_inline_size float::T::right => self.right = self.right + float_inline_size,
}
float::T::right => {
self.right = self.right + base_flow.intrinsic_inline_sizes.preferred_inline_size
}
} }
} }