Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
498 changes: 388 additions & 110 deletions src/compute/block.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ impl Rect<f32> {
pub const fn new(start: f32, end: f32, top: f32, bottom: f32) -> Self {
Self { left: start, right: end, top, bottom }
}

/// Creates a new Rect from a horizontal and vertical line.
#[must_use]
pub const fn from_lines(horizontal: Line<f32>, vertical: Line<f32>) -> Self {
Self { left: horizontal.start, right: horizontal.end, top: vertical.start, bottom: vertical.end }
}
}

/// An abstract "line". Represents any type that has a start and an end
Expand Down
18 changes: 18 additions & 0 deletions test_fixtures/block/block_absolute_auto_margin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Absolute positioning: Horizontal centering with vertical margin interference
</title>
</head>
<body>

<div id="test-root" style="display: block; width: 200px; height: 200px; position: relative; background: red;">
<div style="position: absolute; left: 50px; right: 0; width: 100px; top: 0; height: 100px; margin-top: 100px; margin-left: auto; margin-right: auto; background: green;">
</div>
</div>

</body>
</html>
19 changes: 19 additions & 0 deletions test_fixtures/block/block_absolute_auto_margins_and_insets.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Absolute positioning: Border/Padding interference with Auto-Margins and Insets
</title>
</head>
<body>

<div id="test-root" style="display: block; width: 120px; height: 120px; padding: 20px; border: 20px solid black; position: relative; background: red;">

<div style="position: absolute; left: 0; right: 0; width: 60px; height: 60px; margin-left: auto; margin-right: auto; border: 10px solid black; background: green;">
</div>
</div>

</body>
</html>
15 changes: 15 additions & 0 deletions tests/xml/block/block_absolute_auto_margin__border_box_ltr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margin__border_box_ltr" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" direction="ltr" width="200px" height="200px">
<text direction="ltr" position="absolute" width="100px" height="100px" margin-top="100px" margin-left="auto" margin-right="auto" top="0px" left="50px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="200" height="200">
<node x="75" y="100" width="100" height="100"/>
</node>
</expectations>
</test>
15 changes: 15 additions & 0 deletions tests/xml/block/block_absolute_auto_margin__border_box_rtl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margin__border_box_rtl" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" direction="rtl" width="200px" height="200px">
<text direction="rtl" position="absolute" width="100px" height="100px" margin-top="100px" margin-left="auto" margin-right="auto" top="0px" left="50px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="200" height="200">
<node x="75" y="100" width="100" height="100"/>
</node>
</expectations>
</test>
15 changes: 15 additions & 0 deletions tests/xml/block/block_absolute_auto_margin__content_box_ltr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margin__content_box_ltr" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" box-sizing="content-box" direction="ltr" width="200px" height="200px">
<text box-sizing="content-box" direction="ltr" position="absolute" width="100px" height="100px" margin-top="100px" margin-left="auto" margin-right="auto" top="0px" left="50px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="200" height="200">
<node x="75" y="100" width="100" height="100"/>
</node>
</expectations>
</test>
15 changes: 15 additions & 0 deletions tests/xml/block/block_absolute_auto_margin__content_box_rtl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margin__content_box_rtl" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" box-sizing="content-box" direction="rtl" width="200px" height="200px">
<text box-sizing="content-box" direction="rtl" position="absolute" width="100px" height="100px" margin-top="100px" margin-left="auto" margin-right="auto" top="0px" left="50px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="200" height="200">
<node x="75" y="100" width="100" height="100"/>
</node>
</expectations>
</test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margins_and_insets__border_box_ltr" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" direction="ltr" width="120px" height="120px" padding-top="20px" padding-left="20px" padding-bottom="20px" padding-right="20px" border-top="20px" border-left="20px" border-bottom="20px" border-right="20px">
<text direction="ltr" position="absolute" width="60px" height="60px" margin-left="auto" margin-right="auto" border-top="10px" border-left="10px" border-bottom="10px" border-right="10px" left="0px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="120" height="120">
<node x="30" y="40" width="60" height="60"/>
</node>
</expectations>
</test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margins_and_insets__border_box_rtl" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" direction="rtl" width="120px" height="120px" padding-top="20px" padding-left="20px" padding-bottom="20px" padding-right="20px" border-top="20px" border-left="20px" border-bottom="20px" border-right="20px">
<text direction="rtl" position="absolute" width="60px" height="60px" margin-left="auto" margin-right="auto" border-top="10px" border-left="10px" border-bottom="10px" border-right="10px" left="0px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="120" height="120">
<node x="30" y="40" width="60" height="60"/>
</node>
</expectations>
</test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margins_and_insets__content_box_ltr" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" box-sizing="content-box" direction="ltr" width="120px" height="120px" padding-top="20px" padding-left="20px" padding-bottom="20px" padding-right="20px" border-top="20px" border-left="20px" border-bottom="20px" border-right="20px">
<text box-sizing="content-box" direction="ltr" position="absolute" width="60px" height="60px" margin-left="auto" margin-right="auto" border-top="10px" border-left="10px" border-bottom="10px" border-right="10px" left="0px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="200" height="200">
<node x="60" y="40" width="80" height="80"/>
</node>
</expectations>
</test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<test name="block_absolute_auto_margins_and_insets__content_box_rtl" use-rounding="true">
<viewport width="max-content" height="max-content"/>
<input>
<div display="block" box-sizing="content-box" direction="rtl" width="120px" height="120px" padding-top="20px" padding-left="20px" padding-bottom="20px" padding-right="20px" border-top="20px" border-left="20px" border-bottom="20px" border-right="20px">
<text box-sizing="content-box" direction="rtl" position="absolute" width="60px" height="60px" margin-left="auto" margin-right="auto" border-top="10px" border-left="10px" border-bottom="10px" border-right="10px" left="0px" right="0px">

</text>
</div>
</input>
<expectations>
<node x="0" y="0" width="200" height="200">
<node x="60" y="40" width="80" height="80"/>
</node>
</expectations>
</test>
40 changes: 40 additions & 0 deletions tests/xml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,46 @@ mod block {
crate::run_xml_test("block", "block_absolute_aspect_ratio_width_overrides_inset__content_box_rtl");
}

#[test]
fn block_absolute_auto_margin__border_box_ltr() {
crate::run_xml_test("block", "block_absolute_auto_margin__border_box_ltr");
}

#[test]
fn block_absolute_auto_margin__content_box_ltr() {
crate::run_xml_test("block", "block_absolute_auto_margin__content_box_ltr");
}

#[test]
fn block_absolute_auto_margin__border_box_rtl() {
crate::run_xml_test("block", "block_absolute_auto_margin__border_box_rtl");
}

#[test]
fn block_absolute_auto_margin__content_box_rtl() {
crate::run_xml_test("block", "block_absolute_auto_margin__content_box_rtl");
}

#[test]
fn block_absolute_auto_margins_and_insets__border_box_ltr() {
crate::run_xml_test("block", "block_absolute_auto_margins_and_insets__border_box_ltr");
}

#[test]
fn block_absolute_auto_margins_and_insets__content_box_ltr() {
crate::run_xml_test("block", "block_absolute_auto_margins_and_insets__content_box_ltr");
}

#[test]
fn block_absolute_auto_margins_and_insets__border_box_rtl() {
crate::run_xml_test("block", "block_absolute_auto_margins_and_insets__border_box_rtl");
}

#[test]
fn block_absolute_auto_margins_and_insets__content_box_rtl() {
crate::run_xml_test("block", "block_absolute_auto_margins_and_insets__content_box_rtl");
}

#[test]
fn block_absolute_child_with_margin_x__border_box_ltr() {
crate::run_xml_test("block", "block_absolute_child_with_margin_x__border_box_ltr");
Expand Down