Implement `direction` property (#906)
1//! Generic CSS content size code that is shared between all CSS algorithms.
2use crate::geometry::{Point, Size};
3use crate::style::Overflow;
4use crate::util::sys::{f32_max, f32_min};
5
6#[inline(always)]
7/// Determine how much width/height a given node contributes to it's parent's content size
8pub(crate) fn compute_content_size_contribution(
9 location: Point<f32>,
10 size: Size<f32>,
11 content_size: Size<f32>,
12 overflow: Point<Overflow>,
13) -> Size<f32> {
14 let size_content_size_contribution = Size {
15 width: match overflow.x {
16 Overflow::Visible => f32_max(size.width, content_size.width),
17 _ => size.width,
18 },
19 height: match overflow.y {
20 Overflow::Visible => f32_max(size.height, content_size.height),
21 _ => size.height,
22 },
23 };
24 if size_content_size_contribution.width > 0.0 && size_content_size_contribution.height > 0.0 {
25 let max_x = f32_max(location.x + size_content_size_contribution.width, 0.0);
26 let min_x = f32_min(location.x, 0.0);
27 let max_y = f32_max(location.y + size_content_size_contribution.height, 0.0);
28 let min_y = f32_min(location.y, 0.0);
29
30 Size { width: max_x - min_x, height: max_y - min_y }
31 } else {
32 Size::ZERO
33 }
34}