1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::css::{ComputedStyle, ElementSignature, PercentageBasis, Stylesheets};
use crate::dom::Element;
use crate::layout::{IntrinsicBlockBasis, LayoutBuilder, element_signature};
impl<'a> LayoutBuilder<'a> {
/// Estimate a direct inline row for flex intrinsic sizing.
///
/// CSS Flexbox asks each item for intrinsic size contributions before flex
/// line placement, while CSS Inline and CSS Text define the line fragments
/// and atomic inline boxes that determine row height:
/// <https://www.w3.org/TR/css-flexbox-1/#intrinsic-sizes>,
/// <https://www.w3.org/TR/css-inline-3/#line-box>, and
/// <https://www.w3.org/TR/css-text-3/#line-breaking>.
pub(super) fn measure_direct_inline_row(
&mut self,
element: &Element,
style: &ComputedStyle,
stylesheets: &Stylesheets<'_>,
block_basis: IntrinsicBlockBasis,
) -> (f32, f32) {
self.with_flex_item_percentage_height_basis(block_basis, |layout| {
let measurement =
layout.with_ancestor_signature(element_signature(element), |layout| {
layout.with_intrinsic_inline_percentage_basis(
PercentageBasis::indefinite(),
|layout| {
layout.intrinsic_inline_measurement_for_element(
element,
style,
stylesheets,
None,
f32::MAX,
)
},
)
});
(
measurement.contribution.max_content.points(),
measurement.height(),
)
})
}
pub(super) fn push_ancestor_signature(&mut self, signature: ElementSignature) {
self.ancestors.push(signature);
}
/// Run a layout query with one descendant signature on the selector ancestor stack.
///
/// CSS selector matching for descendant layout estimates depends on the
/// same ancestor chain used by normal box construction. This helper keeps
/// recursive intrinsic estimates from leaking temporary ancestry into
/// sibling estimates:
/// <https://www.w3.org/TR/selectors-4/#overview> and
/// <https://www.w3.org/TR/css-flexbox-1/#intrinsic-sizes>.
pub(super) fn with_ancestor_signature<R>(
&mut self,
signature: ElementSignature,
estimate: impl FnOnce(&mut Self) -> R,
) -> R {
self.ancestors.push(signature);
let result = estimate(self);
self.ancestors.pop();
result
}
}