You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The setting of the styles appears to occur in the servo/components/script/dom/element.rs file.
The initial setting of the width <div style="width:10px"> appears to occur in the set_attribute_from_parser method, and the second setting div.style.backgroundColor = "red"; appears to occur in the update_inline_style method.
On the element struct, why is there style_attribute field in addition to the attrs field? Is a style_attribute not just a type of attr?
I am not sure if this is "robust", but could this be solved by adding a check in the get_attribute_by_name method, by making a special check for name === style, and then appending the inline style attributes to the result as well?
I have noticed further incorrect results with the implementation of console.log(div.getAttribute("style"));.
If you change the original code to include the background declaration twice:
<divstyle="width:10px; width: 10px;">
In Firefox it will print out the width with only one instance of width. However, in servo, it will actually print out width:100px; width: 100px; for the console.log style.
I suspect that this is due to the fact that push_new_attribute is blindly called from set_attribute_from_parser. It seems to me that there should be a check to see if the attribute exists, and if it does, it should simply be updated. If there is any recommended way of doing so, it would be good to know.
As for the original problem:
If I comment out the following code - self.attrs.borrow_mut().push(JS::from_rooted(&attr)); the style changes on the screen seem to be fine, but the style string returned by div.getAttribute("style") is null instead of width: 10px;.
In update_inline_style (which is called by div.style.backgroundColor = "red";), there is no code that appends the self.attrs. It seems that this is why the string is not being updated in OP's example. But, given the problem of blindingly appending the string above, I feel reluctant to append self.attrs, every time this is called. If the same inline style is updated multiple times, doing so would needless bloat self.atrrs. That is why I suggested doing my special check of name === style on get_attribute_by_name, in order to avoid the inline update.
In Firefox it will print out the width with only one instance of width. However, in servo, it will actually print out width:100px; width: 100px; for the console.log style
Servo just doesn't update the attribute. Ever. So it just doesn't change the original string.
Firefox applies the property, and pretty print it as width: 100px.
In Firefox it will print out the width with only one instance of width. However, in servo, it will actually print out width:100px; width: 100px; for the console.log style.
Oh, I just now understood thanks to @paulrouget that you were still referring to the original snippet where we change properties on CSSStyleDeclaration. Never mind me.
The method set_attribute_from_parser is still irrelevant to the problem we have here, though.
I would like to work on a PR, maybe tonight if I have some time. I am not sure what the correct thing to do here is, my initial guess would be to edit the update_inline_style method, perhaps converting the PropertyDeclaration field to an Attr, and then do something like self.attrs.push(convertedPropertyDeclaration). As mentioned in my example above where I commented out code, the self.attrs seems to be what drives the result string from console.log(div.getAttribute("style")).
The complication here is that I do not see any easy way to do the PropertyDeclaration -> Attr conversion offhand, but I am definitely open to suggestions.
@craftytrickster Of course self.attrs is what drives the result of getAttribute. The attribute should be appropriately updated when the corresponding CSSStyleDeclaration value is changed, as the spec mandates.
I've taken an initial pass (WIP) at this in my branch here, and superficially it seems to work, as it is able to append the style names as expected. However, the else branch of my if statement always causes a panic (reachable if you delete the style attribute in the html directly,
div style="width:10px").
I have included the text of the panic as a comment on the branch. I have so far been unable to determine the cause, if I eventually do, I can clean up the code and also take into account remove_inline_style_property. In the meantime, if someone sees a clear reason for the panic, it would be helpful to know.
@craftytrickster Your code panics because you try to mutably-borrow self.attrs while you have already borrowed it.
On another note, as stated earlier, you should not append anything to the style attribute, you should instead set it to the serialised CSSStyleDeclaration instance.
I was able to achieve the results of this issue using regex to modify the existing attrs style instance, but it is was just a temporary approach to see if it would work. @nox, as suggested, I will try to replace the unstructured regex approach with using the CSSStyleDeclaration methods.
@nox, after taking a look, I do not see anything on the cssstyledeclaration.rs file that would help with this issue, which is to synchronize element.style_attribute with the style-attr fromelement.attrs. Nevertheless, I will post a PR this weekend, and we can go from there.
Activity
paulrouget commentedon Jan 14, 2016
Supporting this would help a lot debugging browser.html.
Ms2ger commentedon Jan 14, 2016
https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface
craftytrickster commentedon Jan 17, 2016
Some observations:
The setting of the styles appears to occur in the
servo/components/script/dom/element.rsfile.The initial setting of the width
<div style="width:10px">appears to occur in theset_attribute_from_parsermethod, and the second settingdiv.style.backgroundColor = "red";appears to occur in theupdate_inline_stylemethod.craftytrickster commentedon Jan 17, 2016
On the element struct, why is there
style_attributefield in addition to theattrsfield? Is astyle_attributenot just a type of attr?I am not sure if this is "robust", but could this be solved by adding a check in the
get_attribute_by_namemethod, by making a special check for name === style, and then appending the inline style attributes to the result as well?Ms2ger commentedon Jan 17, 2016
I think we'll probably want to update the string any time the style is changed.
craftytrickster commentedon Jan 19, 2016
I have noticed further incorrect results with the implementation of
console.log(div.getAttribute("style"));.If you change the original code to include the background declaration twice:
In Firefox it will print out the width with only one instance of width. However, in servo, it will actually print out
width:100px; width: 100px;for the console.log style.I suspect that this is due to the fact that
push_new_attributeis blindly called fromset_attribute_from_parser. It seems to me that there should be a check to see if the attribute exists, and if it does, it should simply be updated. If there is any recommended way of doing so, it would be good to know.As for the original problem:
If I comment out the following code -
self.attrs.borrow_mut().push(JS::from_rooted(&attr));the style changes on the screen seem to be fine, but the style string returned bydiv.getAttribute("style")is null instead ofwidth: 10px;.In
update_inline_style(which is called bydiv.style.backgroundColor = "red";), there is no code that appends the self.attrs. It seems that this is why the string is not being updated in OP's example. But, given the problem of blindingly appending the string above, I feel reluctant to append self.attrs, every time this is called. If the same inline style is updated multiple times, doing so would needless bloat self.atrrs. That is why I suggested doing my special check ofname === styleon get_attribute_by_name, in order to avoid the inline update.@Ms2ger Please let me know what you think.
nox commentedon Jan 19, 2016
I'm 99% sure the spec requires the actual attribute value to be preserved when getting it, with duplicate entries and whatnot.
paulrouget commentedon Jan 19, 2016
Servo just doesn't update the attribute. Ever. So it just doesn't change the original string.
Firefox applies the property, and pretty print it as
width: 100px.paulrouget commentedon Jan 19, 2016
This is needed to fix #9377. @craftytrickster, are you planning to work on a PR?
nox commentedon Jan 19, 2016
I think you are wrong.
nox commentedon Jan 19, 2016
Oh, I just now understood thanks to @paulrouget that you were still referring to the original snippet where we change properties on CSSStyleDeclaration. Never mind me.
The method
set_attribute_from_parseris still irrelevant to the problem we have here, though.craftytrickster commentedon Jan 19, 2016
I would like to work on a PR, maybe tonight if I have some time. I am not sure what the correct thing to do here is, my initial guess would be to edit the update_inline_style method, perhaps converting the PropertyDeclaration field to an Attr, and then do something like
self.attrs.push(convertedPropertyDeclaration). As mentioned in my example above where I commented out code, the self.attrs seems to be what drives the result string fromconsole.log(div.getAttribute("style")).The complication here is that I do not see any easy way to do the PropertyDeclaration -> Attr conversion offhand, but I am definitely open to suggestions.
nox commentedon Jan 19, 2016
@craftytrickster Of course self.attrs is what drives the result of getAttribute. The attribute should be appropriately updated when the corresponding CSSStyleDeclaration value is changed, as the spec mandates.
7 remaining items
paulrouget commentedon Jan 21, 2016
Yes.
craftytrickster commentedon Jan 22, 2016
I've taken an initial pass (WIP) at this in my branch here, and superficially it seems to work, as it is able to append the style names as expected. However, the else branch of my if statement always causes a panic (reachable if you delete the style attribute in the html directly,
div style="width:10px").
I have included the text of the panic as a comment on the branch. I have so far been unable to determine the cause, if I eventually do, I can clean up the code and also take into account
remove_inline_style_property. In the meantime, if someone sees a clear reason for the panic, it would be helpful to know.nox commentedon Jan 23, 2016
@craftytrickster Your code panics because you try to mutably-borrow
self.attrswhile you have already borrowed it.On another note, as stated earlier, you should not append anything to the style attribute, you should instead set it to the serialised CSSStyleDeclaration instance.
craftytrickster commentedon Jan 23, 2016
I was able to achieve the results of this issue using regex to modify the existing attrs style instance, but it is was just a temporary approach to see if it would work. @nox, as suggested, I will try to replace the unstructured regex approach with using the CSSStyleDeclaration methods.
craftytrickster commentedon Jan 23, 2016
@nox, after taking a look, I do not see anything on the cssstyledeclaration.rs file that would help with this issue, which is to synchronize
element.style_attributewith the style-attr fromelement.attrs. Nevertheless, I will post a PR this weekend, and we can go from there.Auto merge of #9410 - craftytrickster:9307/style-update, r=<try>
Auto merge of #11377 - servo:style-attr-ser-rebase, r=SimonSapin