New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incremental layout bugs for absolute and cleared elements #17581
Conversation
r? @pcwalton |
@bors-servo try |
Fix incremental layout bugs for absolute and cleared elements Fixes #17307. There were two underlying bugs: * Nodes were not marked dirty when their style attribute changed. * BaseFlow flags set during flow construction could get out of sync with the element's style if repair_style was called. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #17307 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17581) <!-- Reviewable:end -->
components/script/dom/element.rs
Outdated
@@ -2214,6 +2214,7 @@ impl VirtualMethods for Element { | |||
match attr.local_name() { | |||
&local_name!("style") => { | |||
// Modifying the `style` attribute might change style. | |||
node.dirty(NodeDamage::NodeStyleDamaged); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed. We handle that already here: https://github.com/servo/servo/blob/master/components/script/dom/document.rs#L2418.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. I'll drop this change.
components/layout/flow.rs
Outdated
self.flags.set(BLOCK_POSITION_IS_STATIC, | ||
logical_position.block_start == LengthOrPercentageOrAuto::Auto && | ||
logical_position.block_end == LengthOrPercentageOrAuto::Auto); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about making this a new incremental reflow flag, along the lines of RECONSTRUCT_FLOW
or REFLOW_OUT_OF_FLOW
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. This increases the size of RestyleDamage from u8
to u16
and adds a bit more code. Let me know if you think it's worth the slight complexity cost.
💔 Test failed - arm32 |
So with this patch: diff --git a/components/layout/query.rs b/components/layout/query.rs
index ae7a506124..f1a5747419 100644
--- a/components/layout/query.rs
+++ b/components/layout/query.rs
@@ -824,11 +824,13 @@ fn process_resolved_style_request_internal<'a, N>(requested_node: N,
iterator.result.map(|r| r.to_css_string()).unwrap_or(String::new())
},
+ /*
LonghandId::Bottom | LonghandId::Top | LonghandId::Right | LonghandId::Left
if applies && positioned && style.get_box().display !=
display::computed_value::T::none => {
used_value_for_position_property(layout_el, layout_root, requested_node, longhand_id)
}
+ */
LonghandId::Width | LonghandId::Height
if applies && style.get_box().display !=
display::computed_value::T::none => { And printing the computed style: <!DOCTYPE html>
<style>
#rect {
position: absolute;
border: 1px solid red;
width: 40px;
height: 40px;
}
</style>
<div id="rect"></div>
<script>
var x = 10;
var tick = function() {
x += 4;
var e = document.getElementById("rect");
e.style.left = x + "px";
console.log(getComputedStyle(e).left)
window.requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
</script> I see the computed value updated properly, so now the thing is why the flow tree isn't getting properly updated without the |
The demo definitely works with this series but removing the first patch, so it should be dropped IMO. |
@bors-servo try |
Fix incremental layout bugs for absolute and cleared elements Fixes #17307. <del>There were two underlying bugs:</del> * <del>Nodes were not marked dirty when their style attribute changed.</del> * BaseFlow flags set during flow construction could get out of sync with the element's style if repair_style was called. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #17307 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17581) <!-- Reviewable:end -->
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments on my side were addressed, looks good to me assuming @pcwalton is fine with UPDATE_FLOW_FLAGS
.
components/layout/flow.rs
Outdated
} | ||
|
||
// For absolutely-positioned flows, changes to top/bottom/left/right can cause these flags | ||
// to get out of date: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps note that we don't need to update the IS_ABSOLUTELY_POSITIONED
flag because we reconstruct on position changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
components/layout/flow.rs
Outdated
@@ -1361,6 +1386,7 @@ impl<'a> MutableFlowUtils for &'a mut Flow { | |||
/// calling them individually, since there is no reason not to perform both operations. | |||
fn repair_style_and_bubble_inline_sizes(self, style: &::StyleArc<ServoComputedValues>) { | |||
self.repair_style(style); | |||
mut_base(self).update_flags(style); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And maybe call the function update_flags_if_needed
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Removed the new RestyleDamage flag; we can just use |
This is necessary because the CLEARS_LEFT and CLEARS_RIGHT flags are set during flow construction.
Looks good. r=me if you like |
@bors-servo r=pcwalton |
📌 Commit 3981884 has been approved by |
Fix incremental layout bugs for absolute and cleared elements Fixes #17307. <del>There were two underlying bugs:</del> * <del>Nodes were not marked dirty when their style attribute changed.</del> * BaseFlow flags set during flow construction could get out of sync with the element's style if repair_style was called. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #17307 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17581) <!-- Reviewable:end -->
💔 Test failed - mac-rel-css2 |
@bors-servo r=pcwalton
|
📌 Commit 2aef2af has been approved by |
Fix incremental layout bugs for absolute and cleared elements Fixes #17307. <del>There were two underlying bugs:</del> * <del>Nodes were not marked dirty when their style attribute changed.</del> * BaseFlow flags set during flow construction could get out of sync with the element's style if repair_style was called. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #17307 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17581) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
Fixes #17307.
There were two underlying bugs:Nodes were not marked dirty when their style attribute changed.BaseFlow flags set during flow construction could get out of sync with the element's style if repair_style was called.
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is