This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 19276 - [Shadow]: Consider simplifying addStyleSheet parameters
Summary: [Shadow]: Consider simplifying addStyleSheet parameters
Status: RESOLVED DUPLICATE of bug 22539
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 15480
  Show dependency treegraph
 
Reported: 2012-10-04 17:21 UTC by Dimitri Glazkov
Modified: 2013-07-17 16:48 UTC (History)
2 users (show)

See Also:


Attachments

Description Dimitri Glazkov 2012-10-04 17:21:30 UTC
Both HTMLLinkElement and HTMLStyleElement are used here as the glorified dictionaries, and that seems like abuse of their intended purpose.

We should do something simpler.

a) use actual dictionaries
b) use two calls, one to add a stylesheet by URL, one to add a stylesheet as string.
Comment 1 Takashi Sakamoto 2012-10-12 05:58:10 UTC
(In reply to comment #0)
> Both HTMLLinkElement and HTMLStyleElement are used here as the glorified
> dictionaries, and that seems like abuse of their intended purpose.
> 
> We should do something simpler.
> 
> a) use actual dictionaries
> b) use two calls, one to add a stylesheet by URL, one to add a stylesheet as
> string.

Talking about b),  I'm not sure whether it is ok to create any hash key from css text or not...

If we cannot quickly check whether the given css text (string) is the same as the one which has been already parsed or not, we have to parse the same css text many and many times.

I mean, from the view of implementation, is it possible to do (1)->(2)->(3) in WebKit?

Suppose that we have some css text as WTF::String.
(1) we generate some hash key from the css text.
(2) we look up some hash table, mapping from some hash key (integer?) to an instance of class StyleSheet.
(3) if some StyleSheet is found, we use the found one. Otherwise, we parse the css text by using CSSParser and create a new StyleSheet (and register it with the hash table).

If we run CSSParser every time we invoke addStyleSheet, it might cause performance problem...

Best regards,
Takashi Sakamoto
Comment 2 Takashi Sakamoto 2012-10-15 10:40:00 UTC
I'm sorry. I missed the way to obtain css text from <style>(and also URL from <link>).

So, if <style> is not in DOM tree,
(1) obtain css text from <style> (in the same way as StyleElement class does).
(2) parse the obtained css text (in the same way as StyleElement class does).
(3) create CSSStyleSheet.

(2) and (3) are the same task as addStyleSheet(DOMString cssText) does.

I think, which is better to use Element or DOMString depends on Web developers...
We have to ask developers about which their favorite way.

Best regards,
Takashi Sakamoto

(In reply to comment #1)
> (In reply to comment #0)
> > Both HTMLLinkElement and HTMLStyleElement are used here as the glorified
> > dictionaries, and that seems like abuse of their intended purpose.
> > 
> > We should do something simpler.
> > 
> > a) use actual dictionaries
> > b) use two calls, one to add a stylesheet by URL, one to add a stylesheet as
> > string.
> 
> Talking about b),  I'm not sure whether it is ok to create any hash key from
> css text or not...
> 
> If we cannot quickly check whether the given css text (string) is the same
> as the one which has been already parsed or not, we have to parse the same
> css text many and many times.
> 
> I mean, from the view of implementation, is it possible to do (1)->(2)->(3)
> in WebKit?
> 
> Suppose that we have some css text as WTF::String.
> (1) we generate some hash key from the css text.
> (2) we look up some hash table, mapping from some hash key (integer?) to an
> instance of class StyleSheet.
> (3) if some StyleSheet is found, we use the found one. Otherwise, we parse
> the css text by using CSSParser and create a new StyleSheet (and register it
> with the hash table).
> 
> If we run CSSParser every time we invoke addStyleSheet, it might cause
> performance problem...
> 
> Best regards,
> Takashi Sakamoto
Comment 3 Dimitri Glazkov 2013-07-17 16:48:48 UTC
This API got yanked out of the latest draft. The closest bug is 22539. Duping.

*** This bug has been marked as a duplicate of bug 22539 ***