Skip to content

Commit

Permalink
[css-layout-api] Populate children, and pass into layout() function
Browse files Browse the repository at this point in the history
This introduces the LayoutChild API surface, (which only has a styleMap
accessor currently).

Each LayoutBox which is a child of a LayoutCustom will hold onto a
LayoutChild object, acting as the script interface for the web
developer.

Bug: 726125
Change-Id: Iecdb01a38c0712dcda063b485c4207bde59f3995
Reviewed-on: https://chromium-review.googlesource.com/933092
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Morten Stenshorne <mstensho@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539928}
  • Loading branch information
bfgeek authored and chromium-wpt-export-bot committed Feb 28, 2018
1 parent 3370b65 commit 7ccdd1e
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 9 deletions.
16 changes: 16 additions & 0 deletions common/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Returns true if the given arrays are equal. Optionally can pass an equality function.
export function areArraysEqual(a, b, equalityFunction = (c, d) => { return c === d; }) {
try {
if (a.length !== b.length)
return false;

for (let i = 0; i < a.length; i++) {
if (!equalityFunction(a[i], b[i]))
return false;
}
} catch (ex) {
return false;
}

return true;
}
23 changes: 15 additions & 8 deletions common/worklet-reftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@
// requestAnimationFrame. In the second frame, we take a screenshot, that makes
// sure that we already have a full frame.
function importWorkletAndTerminateTestAfterAsyncPaint(worklet, code) {
if (typeof worklet == "undefined") {
if (typeof worklet === 'undefined') {
takeScreenshot();
return;
}

let url;
if (typeof code === 'object') {
url = code.url;
} else {
var blob = new Blob([code], {type: 'text/javascript'});
worklet.addModule(URL.createObjectURL(blob)).then(function() {
const blob = new Blob([code], {type: 'text/javascript'});
url = URL.createObjectURL(blob);
}

worklet.addModule(url).then(function() {
requestAnimationFrame(function() {
requestAnimationFrame(function() {
requestAnimationFrame(function() {
takeScreenshot();
});
takeScreenshot();
});
});
}
});
}

2 changes: 1 addition & 1 deletion css/css-layout-api/box-tree-registered.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<script id="code" type="text/worklet">
registerLayout('registered', class {
*intrinsicSizes() {}
*layout() {}
*layout() { throw Error(); }
});
</script>

Expand Down
44 changes: 44 additions & 0 deletions css/css-layout-api/layout-child-absolute.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#layout-children">
<link rel="match" href="layout-child-ref.html">
<meta name="assert" content="This test checks that absolute children don't appear in the children array." />

<style>
.test {
--child-expected: ["2"];

background: red;
margin: 10px;
width: 100px;
}

.absolute {
position: absolute;
visibility: hidden;
--child: 1;
}

.inflow {
visibility: hidden;
--child: 2;
}

@supports (display: layout(test)) {
.test {
background: green;
display: layout(test);
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>

<div class="test">
<div class="absolute"></div>
<div class="inflow"></div>
</div>

<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.layoutWorklet, {url: 'support/layout-child-worklet.js'});
</script>
49 changes: 49 additions & 0 deletions css/css-layout-api/layout-child-before-after.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#layout-children">
<link rel="match" href="layout-child-ref.html">
<meta name="assert" content="This test checks that boxes created by ::before/::after appear as children." />

<style>
.test {
--child-expected: ["1", "2", "3"];

background: red;
margin: 10px;
width: 100px;
}

.test::before {
visibility: hidden;
content: 'before';
--child: 1;
}

.inflow {
visibility: hidden;
--child: 2;
}

.test::after {
visibility: hidden;
content: 'after';
--child: 3;
}

@supports (display: layout(test)) {
.test {
background: green;
display: layout(test);
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>

<div class="test">
<div class="inflow"></div>
</div>

<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.layoutWorklet, {url: 'support/layout-child-worklet.js'});
</script>
44 changes: 44 additions & 0 deletions css/css-layout-api/layout-child-fixed.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#layout-children">
<link rel="match" href="layout-child-ref.html">
<meta name="assert" content="This test checks that fixed children don't appear in the children array." />

<style>
.test {
--child-expected: ["2"];

background: red;
margin: 10px;
width: 100px;
}

.fixed {
position: fixed;
visibility: hidden;
--child: 1;
}

.inflow {
visibility: hidden;
--child: 2;
}

@supports (display: layout(test)) {
.test {
background: green;
display: layout(test);
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>

<div class="test">
<div class="fixed"></div>
<div class="inflow"></div>
</div>

<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.layoutWorklet, {url: 'support/layout-child-worklet.js'});
</script>
44 changes: 44 additions & 0 deletions css/css-layout-api/layout-child-float.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#layout-children">
<link rel="match" href="layout-child-ref.html">
<meta name="assert" content="This test checks that float children appear in the children array." />

<style>
.test {
--child-expected: ["1", "2"];

background: red;
margin: 10px;
width: 100px;
}

.float {
float: right;
visibility: hidden;
--child: 1;
}

.inflow {
visibility: hidden;
--child: 2;
}

@supports (display: layout(test)) {
.test {
background: green;
display: layout(test);
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>

<div class="test">
<div class="float"></div>
<div class="inflow"></div>
</div>

<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.layoutWorklet, {url: 'support/layout-child-worklet.js'});
</script>
43 changes: 43 additions & 0 deletions css/css-layout-api/layout-child-inflow.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#layout-children">
<link rel="match" href="layout-child-ref.html">
<meta name="assert" content="This test checks that regular inflow children appear as children." />

<style>
.test {
--child-expected: ["1", "2"];

background: red;
margin: 10px;
width: 100px;
}

.inflow-1 {
visibility: hidden;
--child: 1;
}

.inflow-2 {
visibility: hidden;
--child: 2;
}

@supports (display: layout(test)) {
.test {
background: green;
display: layout(test);
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>

<div class="test">
<div class="inflow-1"></div>
<div class="inflow-2"></div>
</div>

<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.layoutWorklet, {url: 'support/layout-child-worklet.js'});
</script>
55 changes: 55 additions & 0 deletions css/css-layout-api/layout-child-inlines.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#layout-children">
<link rel="match" href="layout-child-ref.html">
<meta name="assert" content="This test checks that inline children are correctly blockified or wrapped in anonymous boxes." />

<style>
/* We have a wrapper in this test to ensure that any text that is positioned
* slightly outside the "test" box doesn't affect the rendering.
* This wrapper has a 10px inline padding which does the trick. */
.wrapper {
background: green;
padding: 0 10px;
margin: 10px;
width: 80px;
}

.test {
--child-expected: ["1", "default", "3", "4", "5"];

background: red;
color: green;
width: 80px;
--child: default;
}

.inflow {
visibility: hidden;
--child: 3;
}

@supports (display: layout(test)) {
.test {
background: green;
display: layout(test);
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>

<div class="wrapper">
<div class="test">
<span style="--child: 1;">Text,</span> more text
<div class="inflow"></div>
<span style="--child: 4;">Text,
<div>block!</div>
</span>
<span style="--child: 5;">Other text</span>
</div>
</div>

<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.layoutWorklet, {url: 'support/layout-child-worklet.js'});
</script>
10 changes: 10 additions & 0 deletions css/css-layout-api/layout-child-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<style>
.result {
background: green;
margin: 10px;
height: 100px;
width: 100px;
}
</style>
<div class="result"></div>
Loading

0 comments on commit 7ccdd1e

Please sign in to comment.