Skip to content

Adding sync method to update atrr from inline style updates - #9410

Closed
craftytrickster wants to merge 15 commits into
servo:masterfrom
craftytrickster:9307/style-update
Closed

craftytrickster wants to merge 15 commits into
servo:masterfrom
craftytrickster:9307/style-update

Conversation

@craftytrickster

Copy link
Copy Markdown
Contributor

#9307

I am not terribly confident in this PR, but getAttribute("style") does update correctly now. If the implementation here is more or less "correct", I will add unit tests to confirm that the attr for style is updated correctly. If it is completely off, I will gladly keep trying, but I also understand if someone else with more experience with Rust and this area of the application wants to do it.

There are a few things I do not like here, such as:

  • Manually forming the string new_style in sync_property_with_attrs_style
  • In the fn update_inline_style, I needed to coerce the value to a string slice, so I did &format!("{}", &property_decl.name(), but I am sure there is a better way to do this.

Review on Reviewable

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 23, 2016
@jdm

jdm commented Jan 25, 2016

Copy link
Copy Markdown
Member

r? @nox

@paulrouget

Copy link
Copy Markdown
Contributor

You're trying to update the attribute, keeping the previous value. This won't work.

For example, this is valid:

elt.setAttribute("style", "meh:42");
console.log(elt.getAttribute("style")); // prints "meh:42"
elt.style.color = "red"; //
console.log(elt.getAttribute("style")); // prints "color:red"

With your code, i'd expect it to print: meh:42; color: red.

sync_property_with_attrs_style should not take a property and a value, but just empty the DOM style attribute, and replace it with the content of self.style_attribute().

Does it make sense?

@nox

nox commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

As stated before, you need to set the attribute value from the serialisation of the CSSStyleDeclaration instance.

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 25, 2016
@craftytrickster

Copy link
Copy Markdown
Contributor Author

I think I understand what you are looking for. When I have time (hopefully tonight) to make the change, I will push it here.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jan 26, 2016
@paulrouget

Copy link
Copy Markdown
Contributor

Just some comments:

  • Don't forget to remove the calls to document.content_changed in cssstyledeclaration.rs. Now that the style attribute mutates, content_changed should be called automatically.
  • In https://github.com/servo/servo/pull/9378/files (PR that is not necessary anymore, thanks to your work), there's a test that I think should be added to this PR
  • This doesn't use shorthands (border:2px solid red is expanded into border-left-style: solid; border-left-color: red; border-bottom-width: 2px;...)
  • !important is missing

@nox

nox commented Jan 26, 2016

Copy link
Copy Markdown
Contributor

You want to implement this algorithm.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

Thanks for comments, I will make the changes and implement algorithm as well. I should have done it beforehand.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

I know that @paulrouget mentioned that having issue #9307 solved would help in debugging. I have been extremely busy the past few weeks, it has been hard to find time and I feel bad that I am holding up this issue.

I am looking into serializing this correctly, but I have not solved it yet. In the meantime, it might provide value to integrate the current changes. Then someone (perhaps me if I am able to complete it on time) can simple replace the implementation of serialize in a different PR perhaps (without closing the current issue). This is a good reference for the implementation - https://github.com/AngleSharp/AngleSharp/blob/36e94f9492a1ee309af8a8bf0be50333d107b914/AngleSharp/Dom/Css/CssStyleDeclaration.cs#L2315

Please let me know what you think.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

I found some time to look at this tonight, I have a better idea of what to do now with the serialize piece, maybe I can finish this weekend.

@paulrouget

Copy link
Copy Markdown
Contributor

I know that @paulrouget mentioned that having issue #9307 solved would help in debugging. I have been extremely busy the past few weeks, it has been hard to find time and I feel bad that I am holding up this issue.

Don't worry about that. Fixing this was important for #9378, but we landed a temporary fix.

So no hurry.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

That's good to hear, thanks.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

I would like some assistance looking at my latest commits if possible. During the serialize method, I do a lot of iter().cloned() that intuitively seems wrong. However, I am not sure of another way to do it.

Also, it seems that the pre-existing method serialize_shorthand (whose location I moved) is serializing incorrectly, with the following input: margin: 10px; margin-bottom: 13px it outputs - margin: 10px 10px 10px 13px;. It also does not take into account whether or not the attribute is important.

Thank you for the help and patience.

Comment thread components/style/properties.mako.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'd be nice if you can put in some annotations about which step of the algorithm that the code is following. Just a // Step 1. above step 1 would be enough, for example. // Substep 1. for substeps, and so on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will add that now.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #9510) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm

jdm commented Apr 30, 2016

Copy link
Copy Markdown
Member

The failing reftests include x.style.border = "solid" and x.style.border = "solid lime", and it looks like the calls to node.dirty were removed from the code that updates the inline element style - this would cause the rendering to change.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

I tested adding back the node.dirty calls on a different branch craftytrickster@847265c, but the rendering problem is still there.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

It seems that the root of the may be the use of sync_property_with_attrs_style, specifically when it calls push_new_attribute .

The sync_property_with_attrs_style occurs after the element's style_attribute has been modified. However, this causes the attribute_mutated method to be called, which seems to perform an unnecessary parse here, which is most likely causing this problem. I will try to look into this further, time permitting.

@craftytrickster

craftytrickster commented May 13, 2016 •

Copy link
Copy Markdown
Contributor Author

The wpt test for tests/wpt/mozilla/tests/css/removeproperty.html was failing due to the fact that node.dirty was not called during property removals. After my latest commit, this is now passing. I still see some wpt-test failures locally (such as viewport_percentage_vmin_vmax_a.html), but they seem intermittent/unrelated to the changes I made here.

Please let me know if anything else is missing here.

@jdm jdm removed the S-needs-rebase There are merge conflict errors. label May 13, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #11192) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label May 15, 2016
craftytrickster and others added 15 commits May 18, 2016 20:22
from cssstyledeclaration.rs file

For PropertyDeclaration impl, added shorthands method to get the shorthands associated
with the current longhand

For PropertyDeclarationBlock impl, added serialize algorithm
…g to string buffers to save string allocations for every result
… writing to string buffers to save string allocations for every result
@craftytrickster

Copy link
Copy Markdown
Contributor Author

With the latest rebase and changes, the unit test and wpt-test results in this branch are the same as the results from master branch.

@SimonSapin Is this able to be merged, or is there still something I am missing?

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #11326) made this pull request unmergeable. Please resolve the merge conflicts.

@SimonSapin

Copy link
Copy Markdown
Member

I think this is good to go. I’ve rebased it and sent it to CI in #11377.

@craftytrickster

Copy link
Copy Markdown
Contributor Author

Thank you everyone for your help and patience on this issue. I learned a quite a bit about Rust from doing this one (although it did take a little longer than expected).

@SimonSapin

Copy link
Copy Markdown
Member

Thank you for keeping at it all this time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants