Using individual rules naturally has pluses and minuses. In this case in which one wants to add rules on mass it's not appropriate thus appending new css to a particular stylesheet is more appropriate....read on for my views and some developer benefits.
Take the stylesheet included by one of the theme modules such as "chrome"... Imagine your not happy with the "default" font set by one of the rule which targets "body". It is a pain to override this and other similar rules in one of your own stylesheets because there is no way to control the order of any injected stylesheets. Let's argue I want my customisations in my own module I can't definitely guarantee The ordering. In the end the easiest way to override stuff like this is to take a copy of the Css file and modify which shouldn't be necessary. I should be able to inject my own css file and have it appear in head "after" the "chrome" css so my "modified" rules apply. Is there another simpler less messy to override "chrome" rules ? Perhaps another important issue is the fact that ie6 only reads the first 30 odd style tags. Do a google for "ie stylesheet tag limit" and read the ms article ( it's the top / first match). I ran into this in the past and can't recall if the problem also applies to ie7... Ms says the prob only applied to <= ie6. Does gwt care about ie6 - dunno it's not my call ??? Ultimately I believe users should be able to control the order of any stylesheet's as the are injected. The only practical way to achieve this is to create stylesheet's dynamically. Another benefit for the developer is that rules from different modules are in separate stylesheets rather than in one big stylesheet. This helps when one wants to make adjustments with stuff like firebug... I personally don't like the idea of having my Dom "polluted" with scattered style tags. This is the equivalent of loading js via many script tags - it's just ugly compared to the provided "standard". I believe it's nicer to do the stylesheet create etc thing. If it's too late so be it for now - but it's the better way. Do you agree with the benefits ? Hth On 04/04/2009, at 3:12 PM, Ray Cromwell <[email protected]> wrote: > > The current solution of allowing you to inject as the first child of > <head> works just fine, at the loss of user defined stylesheets > needing to use !important, but it is also extremely simple to > implement, and the low hanging fruit. Iimposing that StyleInjector > would have to use addRule()/insertRule() would result in a > performance hit for large injections, while simultaneously reducing > the coding efficiency of ImmutableResourceBundle/ClientBundle, since > it would have to break up the cssText into an array of strings. I > don't think the GWT team wants to make large sweeping changes to > StyleInjector/ClientBundle at this point. I'm also skeptical that it > would yield much practical benefit to most developers. Can you give > a practical example of how this would even be used and how the end > user (not generally aware of CSS and cascade rules) would even > decide what to do? > > > On Fri, Apr 3, 2009 at 8:52 PM, Miroslav Pokorny <[email protected] > > wrote: > That's correct because they cascade. The benefit of specifying which > stylesheet to inject into is that the gwt stylesheet can contain > defaults which are in turn overridden at will in user defined > stylesheets. > > Currently it's a free for all with ordering being undpecified which > makes it messy to start overriding some rules. > > > > On 04/04/2009,d at 2:33 PM, Ray Cromwell <[email protected]> > wrote: > >> >> You can get the CssRule/CSSStyleDeclaration as text via the cssText >> property, but AFAIK, there is no property on >> document.styleSheets[n] that allows setting the whole stylesheet at >> once using text. If there is, it's certainly not part of the W3C >> DOM CSS OM. >> >> -Ray >> >> On Fri, Apr 3, 2009 at 8:21 PM, Miroslav Pokorny <[email protected] >> > wrote: >> One does not have to add the rules one by one. If I recall it is >> possible to get the entire content of a stylesheet using the "css" >> property append your new rules and update that property. I'm pretty >> sure you can do basically the same thing in all browsers. >> >> Ti >> >> On 04/04/2009, at 10:56 AM, Ray Cromwell <[email protected]> >> wrote: >> >>> It seems to me that calling addRule/insertRule a hundred times >>> would be pretty slow (just look how many rules are in the GWT >>> Theme CSS), not to mention there are cross-browser issues to deal >>> with, when a simple, well-tested, mechanism exists already. >>> Sometimes doing the 'proper' thing is not an improvement (e.g. not >>> using tables for layout because it's "wrong") >>> >>> -Ray >>> >>> >>> On Fri, Apr 3, 2009 at 4:47 PM, Miroslav Pokorny >>> <[email protected] >>> > wrote: >>> This is probably the wrong time to ask -but updating styles via >>> the addition of style tags seems very limiting. >>> >>> If I recall IE (cant recall which vetsion was probably 7) chokes >>> when a page has more than thirty odd style elements. >>> >>> Why not add new rules using StyleSheet.addRule/insertRule or >>> appending the new CSS to a particular stylesheet's CSS ? Using >>> style elements to "append" to a stylesheet seems a hack when >>> proper mechanisms exist. >>> >>> If the StyleInjector bundle included a mechanism to say which >>> stylesheet to modify. >>> >>> On 04/04/2009, at 8:49 AM, Ray Cromwell <[email protected]> >>> wrote: >>> >>>> >>>> I believe so. I don't see any harm. Personally, I think if you >>>> don't have a <head>, your page is broken, since you don't even >>>> get a <title>, but it would be nice to either throw an >>>> informative exception, or inject a head in this circumstance. >>>> >>>> -Ray >>>> >>>> >>>> On Fri, Apr 3, 2009 at 2:46 PM, Ray Ryan <[email protected]> wrote: >>>> Can we add safely add head if we don't find it? >>>> >>>> >>>> On Fri, Apr 3, 2009 at 2:43 PM, <[email protected]> wrote: >>>> >>>> http://gwt-code-reviews.appspot.com/15803/diff/4001/4004 >>>> File user/src/com/google/gwt/dom/client/StyleInjector.java (right): >>>> >>>> http://gwt-code-reviews.appspot.com/15803/diff/4001/4004#newcode35 >>>> Line 35: "head").getItem(0)); >>>> I mentioned this in another review, but this common idiom can >>>> fail if >>>> the user doesn't have a <head> element, which is certainly legal. >>>> Some >>>> browsers automatically insert a <head> if it's missing, but some >>>> don't. >>>> I guess we could simply declare we don't support leaving out head. >>>> >>>> Might be good to assert head != null >>>> >>>> >>>> http://gwt-code-reviews.appspot.com/15803 >>>> >>>> >>>> >>>> >>> >>> >>> >>> >>> >> >> >> >> >> > > > > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
