Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdding sync method to update atrr from inline style updates #9410
Conversation
highfive
commented
Jan 23, 2016
|
r? @nox |
|
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:
Does it make sense? |
|
As stated before, you need to set the attribute value from the serialisation of the CSSStyleDeclaration instance. |
|
I think I understand what you are looking for. When I have time (hopefully tonight) to make the change, I will push it here. |
|
Just some comments:
|
|
You want to implement this algorithm. |
|
Thanks for comments, I will make the changes and implement algorithm as well. I should have done it beforehand. |
74d7e75
to
f0d522d
|
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 Please let me know what you think. |
f0d522d
to
cf67f01
|
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. |
Don't worry about that. Fixing this was important for #9378, but we landed a temporary fix. So no hurry. |
|
That's good to hear, thanks. |
|
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 Thank you for the help and patience. |
| @@ -5724,6 +5724,97 @@ pub struct PropertyDeclarationBlock { | |||
| pub normal: Arc<Vec<PropertyDeclaration>>, | |||
| } | |||
|
|
|||
| impl PropertyDeclarationBlock { | |||
| // https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block | |||
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 3, 2016
Member
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.
This comment has been minimized.
This comment has been minimized.
| shorthands.sort_by(|a,b| a.longhands().len().cmp(&b.longhands().len())); | ||
|
|
||
| // TODO: Help - I do not want to do iter cloned, is there a way to | ||
| // somehow collection into a list or Vec of references? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
craftytrickster
Feb 3, 2016
Author
Contributor
How can you turn an iterator result (for example, after performing a filter) into a slice? I do not see any documentation that demonstrates that.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
craftytrickster
Feb 3, 2016
Author
Contributor
If I try .collect::<&[PropertyDeclaration]>(), I get the following message:
error: expected `<`, found `&`
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28520
.collect::&[PropertyDeclaration]>();
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 3, 2016
Member
Yeah, sorry, you're not supposed to add a & there. Also, you're missing a <.
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 3, 2016
Member
Hmm... this means that PropertyDeclaration doesn't have a compile-time known size... is it possible to #[derive(Sized)] for PropertyDeclaration? Otherwise, we'd have to do .collect::<Vec<PropertyDeclaration>>() and then form a slice from the vector afterwards.
This comment has been minimized.
This comment has been minimized.
craftytrickster
Feb 4, 2016
Author
Contributor
It still complains that the trait is not implemented for the type, even with the derive.
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 4, 2016
Member
Oh, it's complaining about the [PropertyDeclaration] type in particular (note the square brackets). Are there any hints/notes that get printed after the error?
This comment has been minimized.
This comment has been minimized.
craftytrickster
Feb 4, 2016
Author
Contributor
These are all the errors. The Array remove one makes sense, since you cannot remove from a fixed array:
18:22: 28518:29 error: the trait `core::marker::Sized` is not implemented for the type `[properties::PropertyDeclaration]` [E0277]
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518 .collect::<[PropertyDeclaration]>();
^~~~~~~
/home/divad/Rust/servo/components/style/lib.rs:75:5: 75:58 note: in this expansion of include!
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518:22: 28518:29 help: run `rustc --explain E0277` to see a detailed explanation
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518:22: 28518:29 note: `[properties::PropertyDeclaration]` does not have a constant size known at compile-time
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518:22: 28518:29 error: the trait `core::iter::FromIterator<properties::PropertyDeclaration>` is not implemented for the type `[properties::PropertyDeclaration]` [E0277]
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518 .collect::<[PropertyDeclaration]>();
^~~~~~~
/home/divad/Rust/servo/components/style/lib.rs:75:5: 75:58 note: in this expansion of include!
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518:22: 28518:29 help: run `rustc --explain E0277` to see a detailed explanation
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28518:22: 28518:29 note: a collection of type `[properties::PropertyDeclaration]` cannot be built from an iterator over elements of type `properties::PropertyDeclaration`
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28516:21: 28516:34 error: the trait `core::marker::Sized` is not implemented for the type `[properties::PropertyDeclaration]` [E0277]
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28516 let mut longhands = self.normal.iter().chain(self.important.iter()).cloned()
^~~~~~~~~~~~~
/home/divad/Rust/servo/components/style/lib.rs:75:5: 75:58 note: in this expansion of include!
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28516:21: 28516:34 help: run `rustc --explain E0277` to see a detailed explanation
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28516:21: 28516:34 note: `[properties::PropertyDeclaration]` does not have a constant size known at compile-time
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28516:21: 28516:34 note: all local variables must have a statically known size
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28578:39: 28578:45 error: no method named `remove` found for type `[properties::PropertyDeclaration]` in the current scope
/home/divad/Rust/servo/target/debug/build/style-f9fb073aea07cada/out/properties.rs:28578 longhands.remove(index);
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 4, 2016
Member
Yeah, we'll have to make a Vec<PropertyDeclaration>, which you already did in your latest commit.
dafbeef
to
2a01887
|
|
2a01887
to
e8f86c7
15407da
to
c82f1da
|
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. |
|
|
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
…essary calls to document.content_changed
… when inline style is changed
…g to string buffers to save string allocations for every result
…portant
… argument
… to handle shorthand serialization better
… writing to string buffers to save string allocations for every result
…order to avoid reparsing serialized output
c82f1da
to
870c47f
|
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? |
|
|
|
I think this is good to go. I’ve rebased it and sent it to CI in #11377. |
Update style attributes on CSSStyleDeclaration changes Rebase of #9410. Fixes #9410, fixes #9307. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11377) <!-- Reviewable:end -->
|
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). |
|
Thank you for keeping at it all this time! |
…g to string buffers to save string allocations for every result
craftytrickster commentedJan 23, 2016
#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:
new_styleinsync_property_with_attrs_stylefn 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.