mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
LibWeb: Implement gathering and broadcasting of resize observations
Extends event loop processing steps to include gathering and broadcasting resize observations. Moves layout updates from Navigable::paint() to event loop processing steps. This ensures resize observation processing occurs between layout updates and painting.
This commit is contained in:
parent
8ba18dfd40
commit
fcf293a8df
8 changed files with 287 additions and 1 deletions
52
Tests/LibWeb/Text/input/ResizeObserver/observe.html
Normal file
52
Tests/LibWeb/Text/input/ResizeObserver/observe.html
Normal file
|
@ -0,0 +1,52 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
#box {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background-color: lightblue;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="box"></div>
|
||||
</body>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
const box = document.getElementById("box");
|
||||
|
||||
let resolve = null;
|
||||
function createResizeObserverPromise() {
|
||||
return new Promise(r => {
|
||||
resolve = r;
|
||||
});
|
||||
}
|
||||
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
for (let entry of entries) {
|
||||
const { width, height } = entry.contentRect;
|
||||
println(`Size changed: ${width}px x ${height}px`);
|
||||
}
|
||||
|
||||
if (resolve) resolve();
|
||||
});
|
||||
|
||||
let observerCallbackInvocation = createResizeObserverPromise();
|
||||
resizeObserver.observe(box);
|
||||
await observerCallbackInvocation;
|
||||
|
||||
// Change size of box multiple times.
|
||||
// Observer callback is expected to be invoked only once.
|
||||
box.style.width = "300px";
|
||||
box.style.height = "300px";
|
||||
|
||||
box.style.width = "400px";
|
||||
box.style.height = "400px";
|
||||
|
||||
observerCallbackInvocation = createResizeObserverPromise();
|
||||
await observerCallbackInvocation;
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue