My favorites | Sign in
Google
                
New issue | Search
for
| Advanced search | Search tips
Issue 1079: Clarify and enhance setStyleName(), getStyleName(), addStyleName(), and removeStyleName()
2 people starred this issue and may be notified of changes. Back to list
 
Reported by gwt.team.bruce, May 22, 2007
Found in GWT Release:
trunk, r1050

Detailed description:
The semantics of setStyleName(), getStyleName(), addStyleName(), and
removeStyleName() were not clearly defined in GWT 1.3. When widgets use
addStyleName() to indicate state changes, the interaction with
setStyleName() gets confusing. Does setStyleName() clobber the effect of
addStyleName()? Does the string returned by getStyleName() include the
additional style names addded by addStyleName()? And so on...

Solution:
Introduce the following concepts:
1) Primary style name - the style name that is set by setStyleName() and
returned by getStyleName()
2) Secondary style names - the style names that are added by addStyleName()
and removeStyleName()
3) Dependent style names - dependent style names are secondary style names
that are prefixed with the primary style name

Modify the GWT 1.3 behavior as follows:
- setStyleName() and getStyleName() always accept/return exactly one token:
the primary style name
- The primary style is always the first token in the root element's className
- A primary style name can never be null, so UIObject.setElement() sets a
default primary style name of "gwt-nostyle"
- Each time setStyleName() is called, it updates both the first className
token (the primary style name) as well as all dependent style names using a
search/replace based on the new/old prefixes; secondary style names that
are not dependent style names are not modified when setStyleName() is called
Comment 1 by gwt.team.bruce, May 22, 2007
Committed as r1063
Status: FixedNotReleased
Comment 2 by gwt.team.bruce, May 29, 2007
Changing to Fixed status with GWT 1.4 RC release
Status: Fixed
Comment 3 by oliver.zahorka, Jul 02, 2007
Unfortunately, this new behavior breaks our application at many places. We used setStyleName("") and 
removeStyleName(style) often to completely remove styles from elements. Although it is totally legal to have no 
class defined and an empty className property, this situation now leads to an Exception.

Please be aware that IE6 does not properly process multiple style names, thus the whole concept of adding and 
removing styles to a base style should not be forced.
Comment 4 by gwt.team.bruce, Jul 02, 2007
We are reviewing this issue after having seeing some growing feedback that this
change is too inconvenient in its current form. We'll update this issue after a bit
more discussion on the contributors list.

@knorton: Could you clarify about IE not supporting multiple styles? My understanding
is that the IE limitation prevents you from writing single CSS selectors based on an
element having multiple types (i.e. the selector would have class names separated
with dots and no spaces). If that is true, then this is an opportunity to explain the
GWT recommended formulation of dependent style names (i.e. to make it easy to work
around the very IE bug in question).
Status: Accepted
Cc: gwt.team.knorton
Labels: -Milestone-1_4_RC Milestone-1_4_RC2
Comment 5 by oliver.zahorka, Jul 03, 2007
I think here is a good explanation of the IE6 bug

<a href="http://www.ryanbrill.com/archives/multiple-classes-in-ie/">Multiple Classes in IE</a>
Comment 6 by gwt.team.jgw, Jul 03, 2007
@rajeev: I've assigned this bug to you, because I believe you said you needed this
change as well. It should be a pretty simple change, as we discussed. Here's the last
thread I posted on the subject:

http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/6329f8f175590ce1
Owner: gwt.team.rdayal
Comment 7 by gwt.team.bruce, Jul 03, 2007
Thanks for the hyperlink. The lack of CSS selector support for multiple style names
was the behavior I was referring to. So, to clarify, IE will support multiple CSS
class names, but it won't properly apply a CSS selector that depends on two or more
class names being present simultaneously. I don't know if there's a term of this kind
of selector, but a good name might be an "intersection selector".

This bug was in fact a motivator for the best practice we wanted to encourage with
the introduction of dependent style names in GWT 1.4. By prefixing each dependent
style name with the common widget style name prefix, you can create families of
independent selectors that are clearly intended to be used together in concert.
Comment 8 by gwt.team.knorton, Jul 03, 2007
IE6 does support multiple CSS classes on an element. What it doesn't support is multiple classes in a single 
CSS selector. Specifically, this is the situation it does not support:

<div class="foo bar"></div>

I can't select that with:
div.foo.bar {}

I can select it with both:
div.foo { }
div.bar { }

I don't see why this poses a problem to setStyleName, et. al. Those methods add/remove class names to the 
element, they do not do css selection and those elements are perfectly selectable by other CSS selectors. I 
don't find working around this particular selector to be any worse than working around any of the other 
selectors IE is missing.

Comment 9 by oliver.zahorka, Jul 04, 2007
Thanks for the clarification. I re-read your comments after some reading on the multiple class problems and 
doing some small experiments myself. There are so many bugs in IE CSS handling, that I seem to have mixed up 
something about the multiple class issues.

However, as already commented in the Group thread mentioned above, the main problem with the changes you 
did to the style related methods is that removeStyleName() throws an IllegalArgumentException if it is called to 
remove the last (base) style -- although that operation is absolutely legal from a CSS point of view.
Comment 10 by gwt.team.rdayal, Jul 05, 2007
@jgw: Assigning this one back to you. Based on the discussion today, it looks like
you'll be taking the lead on this one.
Owner: gwt.team.jgw
Comment 11 by gwt.team.jgw, Jul 09, 2007
(No comment was entered for this change.)
Status: Started
Comment 12 by gwt.team.jgw, Jul 11, 2007
(No comment was entered for this change.)
Status: ReviewPending
Labels: -Type-Enhancement Type-Defect
Comment 13 by david.nouls, Jul 19, 2007
I noticed that when I use a Grid cellformatter , that the setStyleName/getStyleName 
is implemented differently than in Widget setStyleName... now that is completely 
confusing!
Comment 14 by gwt.team.knorton, Jul 22, 2007
(No comment was entered for this change.)
Labels: ReviewBy-knorton
Comment 15 by gwt.team.knorton, Jul 25, 2007


Cc: -gwt.team.bruce -gwt.team.jgw -gwt.team.rdayal gwt.team.scottb
Labels: -ReviewBy-bruce -ReviewBy-jgw ReviewBy-scottb
Comment 16 by gwt.team.knorton, Jul 29, 2007
Committed as r1277.
Status: FixedNotReleased
Comment 17 by gwt.team.scottb, Aug 20, 2007
1.4 RC2 now released.
Status: Fixed
Comment 18 by sumitcha...@google.com, Apr 28, 2008
 
Owner: jgw
Comment 19 by knorton@google.com, Apr 29, 2008
 
Comment 20 by knorton@google.com, Apr 29, 2008
 
Comment 21 by scottb@google.com, Apr 29, 2008
 
Comment 22 by scottb@google.com, Apr 29, 2008
 
Cc: -gwt.team.scottb sco...@google.com
Comment 23 by knorton@google.com, Apr 29, 2008
 
Cc: -gwt.team.knorton knor...@google.com
Sign in to add a comment