Re: [cssom] CSSNamespaceRule

On Wed, 19 Mar 2014 14:55:40 +0100, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 3/19/14 4:35 AM, Simon Pieters wrote:
>> OK. I don't mind that, personally, but I can imagine that it can affect
>> performance. Does anyone object to implementing this?
>
> I'd like to understand the proposed behavior a bit better.

Me too. :-)

> It seems like in an editing context you fundamentally want to re-parse  
> the stylesheet from scratch when inserting a namespace rule.  Or  
> something.
>
> Concretely, consider a stylesheet author who first inserts this rule:
>
>    foo|bar { color: green; }
>
> and then inserts this rule:
>
>    @namespace bar url("something");
>
> During the first step, parsing of the rule fails, since the namespace  
> prefix is unknown; in at least some current browser implementations, and  
> per the spec draft at http://dev.w3.org/csswg/cssom/#insert-a-css-rule  
> the insertRule call will throw.  So doing these operations via CSSOM is  
> probably not the right way to implement this editing behavior.

I'm not Daniel but I think the scenario is more like: you start out with a  
stylesheet that has a bunch of rules and no @namespace and no rules using  
namespace prefixes. Then you want to insert @namespace svg "..."; at the  
top and svg|foo { ... } somewhere else.

You are right that in that scenario it would not actually affect the  
existing rules, but if we allow insertion and changing of @namespace  
rules, I think it seems sane to have the other rules change.

> So are we only talking about inserting @namespace rules that define the  
> default namespace for the sheet?

No, also ones that define prefixes, and not only inserting but also  
changing existing ones.

> Because it seems to me that inserting one that defines the namespace for  
> a prefix that wasn't defined before can't actually affect the OM, since  
> there should be no rules using that prefix.

Right.

> Of course you could insert a rule that _redefines_ a prefix that was  
> already defined by another @namespace rule in the sheet, but I'm not  
> sure how useful it is in practice to support that....

More interesting is maybe editing of an existing @namespace rule, e.g. if  
there was a typo in the value.

What if you want to change the prefix? Changing it would render rules  
using the old prefix invalid. Should they be dropped? Or magically also  
change their prefixes? Or be kept in in an invalid state? Or should the  
setter throw?

What should happen when an @namespace rule is removed?

> If we _do_ have to support it, that requires storing the prefix when  
> it's present with the selectors in the sheet, which is not required  
> right now, as far as I can tell.

You have to store the unparsed selector already since it's exposed in  
CSSOM, so you could parse it again if you don't want to store the prefix.  
But yeah.

-- 
Simon Pieters
Opera Software

Received on Wednesday, 19 March 2014 14:25:34 UTC