Skip to content
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

Merged
merged 2 commits into from Jul 1, 2017

Conversation

mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Jun 30, 2017

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.



This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @bholley: components/style/servo/restyle_damage.rs
  • @KiChjang: components/script/dom/element.rs
  • @fitzgen: components/script/dom/element.rs
  • @emilio: components/layout/Cargo.toml, components/style/servo/restyle_damage.rs, components/layout/flow.rs

@highfive
Copy link

warning Warning warning

  • These commits include an empty title element (<title></title>). Consider adding appropriate metadata.

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 30, 2017
@mbrubeck
Copy link
Contributor Author

r? @pcwalton

@mbrubeck
Copy link
Contributor Author

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit 3ec643c with merge b6fb1aa...

bors-servo pushed a commit that referenced this pull request Jun 30, 2017
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 -->
@@ -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);
Copy link
Member

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.

Copy link
Contributor Author

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.

self.flags.set(BLOCK_POSITION_IS_STATIC,
logical_position.block_start == LengthOrPercentageOrAuto::Auto &&
logical_position.block_end == LengthOrPercentageOrAuto::Auto);
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@bors-servo
Copy link
Contributor

💔 Test failed - arm32

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jun 30, 2017
@emilio
Copy link
Member

emilio commented Jun 30, 2017

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 dirty(..) call.

@emilio
Copy link
Member

emilio commented Jun 30, 2017

The demo definitely works with this series but removing the first patch, so it should be dropped IMO.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jun 30, 2017
@mbrubeck
Copy link
Contributor Author

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit a57149a with merge 6a87c6e...

bors-servo pushed a commit that referenced this pull request Jun 30, 2017
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 -->
Copy link
Member

@emilio emilio left a 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.

}

// For absolutely-positioned flows, changes to top/bottom/left/right can cause these flags
// to get out of date:
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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);
Copy link
Member

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?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Jul 1, 2017

Removed the new RestyleDamage flag; we can just use REFLOW_OUT_OF_FLOW as @pcwalton suggested on IRC.

This is necessary because the CLEARS_LEFT and CLEARS_RIGHT flags are set
during flow construction.
@pcwalton
Copy link
Contributor

pcwalton commented Jul 1, 2017

Looks good. r=me if you like

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Jul 1, 2017

@bors-servo r=pcwalton

@bors-servo
Copy link
Contributor

📌 Commit 3981884 has been approved by pcwalton

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 1, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 3981884 with merge 496eb4c...

bors-servo pushed a commit that referenced this pull request Jul 1, 2017
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 -->
@bors-servo
Copy link
Contributor

💔 Test failed - mac-rel-css2

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jul 1, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Jul 1, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Jul 1, 2017

@bors-servo r=pcwalton

  • Updated test metadata

@bors-servo
Copy link
Contributor

📌 Commit 2aef2af has been approved by pcwalton

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 1, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 2aef2af with merge ece35f9...

bors-servo pushed a commit that referenced this pull request Jul 1, 2017
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 -->
@bors-servo
Copy link
Contributor

☀️ 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
Approved by: pcwalton
Pushing ece35f9 to master...

@bors-servo bors-servo merged commit 2aef2af into servo:master Jul 1, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incremental layout bug in matter.js demo.
6 participants