Re: [css-om] CSSStyleDeclaration.parentElement

On Tue, 06 Aug 2013 19:08:33 +0200, François REMY  
<francois.remy.dev@outlook.com> wrote:

>> Subject: [css-om] CSSStyleDeclaration.parentElement
>>> Returns the element that host the current style declaration, if any. {
>>> NOTE: This attribute is mutually exclusive with the parentRule
>>> attribute, in the sense at most one of the two can return a non-null
>>> value. }
>>>
>>> // would be great to add to the web platform, polyfilling
>>> "someNode.style.someProperty" is a huge pain right now...
>>
>> Can you elaborate on the use case?
>
> I want to fake support for some property. Let's say I want to support  
> "flow-from" from the CSS Regions Spec.
>
> The normal way to do this would be to extend CSSStyleDeclaration and  
> define some "flowFrom" property there. However, if you want to apply  
> this property, you need to have a reference to the element on which this  
> property applies and you have none in the CSSStyleDeclaration interface.  
> { NOTE: you may, for instance, want to update some HTML attribute in  
> response to a change in style. }
>
>
>
>
> My idea to work-around the lack of "parentElement" was then to override  
> HTMLElement.prototype.style and path the "parentElement" property when  
> the style declaration is created but... thank you Webkit for considering  
> "style" as a magic own value property of every element, that's so  
> helpful!

That's a bug in WebKit, WebIDL requires it on the prototype.

> Finally, I settled on a new "myStyle" property which would return the  
> "style" of the element but would add manually the "parentElement"  
> property so that I can access it in my "flowFrom" getter/setter. That's  
> a ugly hack but I can't do better for now...          

So this property would point to the element for element.style but be null  
for cssrule.style et al?

I'm having a bit of difficulty reasoning around your use case since it's  
about polyfilling. For instance, getting flow-from implemented in browsers  
would remove the need for parentElement in your case.

-- 
Simon Pieters
Opera Software

Received on Wednesday, 21 August 2013 14:05:47 UTC