Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 324436 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rwt/internal/theme/QxColor.java (-17 / +87 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2007, 2011 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 *     EclipseSource - ongoing development
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.rwt.internal.theme;
13
package org.eclipse.rwt.internal.theme;
Lines 24-32 Link Here
24
25
25
  private static final Map NAMED_COLORS = new HashMap();
26
  private static final Map NAMED_COLORS = new HashMap();
26
27
27
  public static final QxColor BLACK = new QxColor( 0, 0, 0 );
28
  public static final QxColor BLACK = new QxColor( 0, 0, 0, 1f );
28
29
29
  public static final QxColor WHITE = new QxColor( 255, 255, 255 );
30
  public static final QxColor WHITE = new QxColor( 255, 255, 255, 1f );
30
31
31
  public static final QxColor TRANSPARENT = new QxColor();
32
  public static final QxColor TRANSPARENT = new QxColor();
32
33
Lines 35-42 Link Here
35
  public final int green;
36
  public final int green;
36
37
37
  public final int blue;
38
  public final int blue;
38
39
  
39
  public final boolean transparent;
40
  public final float alpha;
40
41
41
  static {
42
  static {
42
    // register 16 standard HTML colors
43
    // register 16 standard HTML colors
Lines 62-75 Link Here
62
    this.red = 0;
63
    this.red = 0;
63
    this.green = 0;
64
    this.green = 0;
64
    this.blue = 0;
65
    this.blue = 0;
65
    this.transparent = true;
66
    this.alpha = 0f;
66
  }
67
  }
67
68
68
  private QxColor( final int red, final int green, final int blue ) {
69
  private QxColor( final int red,
70
                   final int green,
71
                   final int blue,
72
                   final float alpha )
73
  {
69
    this.red = red;
74
    this.red = red;
70
    this.green = green;
75
    this.green = green;
71
    this.blue = blue;
76
    this.blue = blue;
72
    this.transparent = false;
77
    this.alpha = alpha;
73
  }
78
  }
74
79
75
  public static QxColor create( final int red, final int green, final int blue )
80
  public static QxColor create( final int red, final int green, final int blue )
Lines 80-89 Link Here
80
    } else if( red == 255 && green == 255 && blue == 255 ) {
85
    } else if( red == 255 && green == 255 && blue == 255 ) {
81
      result = WHITE;
86
      result = WHITE;
82
    } else {
87
    } else {
83
      result = new QxColor( red, green, blue );
88
      result = new QxColor( red, green, blue, 1f );
84
    }
89
    }
85
    return result;
90
    return result;
86
  }
91
  }
92
  
93
  public static QxColor create( final int red,
94
                                final int green,
95
                                final int blue,
96
                                final float alpha )
97
  {
98
    checkAlpha( alpha );
99
    QxColor result;
100
    if( alpha == 1f ) {
101
      result = create( red, green, blue );
102
    } else {
103
      result = new QxColor( red, green, blue, alpha );
104
    }
105
    return result;
106
  }
107
108
  private static void checkAlpha( final float alpha ) {
109
    if( alpha < 0 || alpha > 1 ) {
110
      String msg = "Alpha out of range [ 0, 1 ]: " + alpha;
111
      throw new IllegalArgumentException( msg );
112
    }
113
  }
87
114
88
  public static QxColor valueOf( final String input ) {
115
  public static QxColor valueOf( final String input ) {
89
    QxColor result;
116
    QxColor result;
Lines 94-99 Link Here
94
      result = TRANSPARENT;
121
      result = TRANSPARENT;
95
    } else {
122
    } else {
96
      int red, green, blue;
123
      int red, green, blue;
124
      float alpha = 1f;
97
      String lowerCaseInput = input.toLowerCase( Locale.ENGLISH );
125
      String lowerCaseInput = input.toLowerCase( Locale.ENGLISH );
98
      if( input.startsWith( "#" ) ) {
126
      if( input.startsWith( "#" ) ) {
99
        try {
127
        try {
Lines 124-134 Link Here
124
        blue = values[ 2 ];
152
        blue = values[ 2 ];
125
      } else {
153
      } else {
126
        String[] parts = input.split( "\\s*,\\s*" );
154
        String[] parts = input.split( "\\s*,\\s*" );
127
        if( parts.length == 3 ) {
155
        if( parts.length >= 3 && parts.length <= 4 ) {
128
          try {
156
          try {
129
            red = Integer.parseInt( parts[ 0 ] );
157
            red = Integer.parseInt( parts[ 0 ] );
130
            green = Integer.parseInt( parts[ 1 ] );
158
            green = Integer.parseInt( parts[ 1 ] );
131
            blue = Integer.parseInt( parts[ 2 ] );
159
            blue = Integer.parseInt( parts[ 2 ] );
160
            if( parts.length == 4 ) {
161
              alpha = Float.parseFloat( parts[ 3 ] );
162
            }
132
          } catch( final NumberFormatException e ) {
163
          } catch( final NumberFormatException e ) {
133
            String pattern = "Illegal number format in color definition ''{0}''";
164
            String pattern = "Illegal number format in color definition ''{0}''";
134
            Object[] arguments = new Object[] { input };
165
            Object[] arguments = new Object[] { input };
Lines 142-154 Link Here
142
          throw new IllegalArgumentException( message );
173
          throw new IllegalArgumentException( message );
143
        }
174
        }
144
      }
175
      }
145
      result = create( red, green, blue );
176
      result = create( red, green, blue, alpha );
146
    }
177
    }
147
    return result;
178
    return result;
148
  }
179
  }
149
180
181
  public boolean isTransparent() {
182
    return alpha == 0f;
183
  }
184
150
  public String toDefaultString() {
185
  public String toDefaultString() {
151
    return transparent ? TRANSPARENT_STR : toHtmlString( red, green, blue );
186
    String result;
187
    if( isTransparent() ) {
188
      result = TRANSPARENT_STR;
189
    } else if( alpha == 1f ) {
190
      result = toHtmlString( red, green, blue );
191
    } else {
192
      result = toRgbaString( red, green, blue, alpha );
193
    }
194
    return result;
152
  }
195
  }
153
196
154
  public boolean equals( final Object obj ) {
197
  public boolean equals( final Object obj ) {
Lines 159-176 Link Here
159
      QxColor other = ( QxColor )obj;
202
      QxColor other = ( QxColor )obj;
160
      result =  other.red == red
203
      result =  other.red == red
161
             && other.green == green
204
             && other.green == green
162
             && other.blue == blue;
205
             && other.blue == blue
206
             && other.alpha == alpha;
163
    }
207
    }
164
    return result;
208
    return result;
165
  }
209
  }
166
210
167
  public int hashCode() {
211
  public int hashCode() {
168
    return transparent ? -1 : red + green * 256 + blue * 65536;
212
    int result = -1;
213
    if( !isTransparent() ) {
214
      result = 41;
215
      result += 19 * result + red;
216
      result += 19 * result + green;
217
      result += 19 * result + blue;
218
      result += 19 * result + Float.floatToIntBits( alpha );
219
    }
220
    return result;
169
  }
221
  }
170
222
171
  public String toString() {
223
  public String toString() {
172
    String colors = red + ", " + green + ", " + blue;
224
    String colors = red + ", " + green + ", " + blue + ", " + alpha;
173
    return "QxColor{ " + ( transparent ? TRANSPARENT_STR : colors ) + " }";
225
    return "QxColor{ " + ( isTransparent() ? TRANSPARENT_STR : colors ) + " }";
174
  }
226
  }
175
227
176
  public static String toHtmlString( final int red,
228
  public static String toHtmlString( final int red,
Lines 187-193 Link Here
187
239
188
  public static Color createColor( final QxColor color ) {
240
  public static Color createColor( final QxColor color ) {
189
    Color result = null;
241
    Color result = null;
190
    if( !color.transparent ) {
242
    if( color.alpha == 1f ) {
191
      result = Graphics.getColor( color.red, color.green, color.blue );
243
      result = Graphics.getColor( color.red, color.green, color.blue );
192
    }
244
    }
193
    return result;
245
    return result;
Lines 197-200 Link Here
197
    String hex = Integer.toHexString( value );
249
    String hex = Integer.toHexString( value );
198
    return hex.length() == 1 ? "0" + hex : hex;
250
    return hex.length() == 1 ? "0" + hex : hex;
199
  }
251
  }
252
253
  private static String toRgbaString( final int red,
254
                                      final int green,
255
                                      final int blue,
256
                                      final float alpha )
257
  {
258
    StringBuffer sb = new StringBuffer();
259
    sb.append( "rgba(" );
260
    sb.append( red );
261
    sb.append( "," );
262
    sb.append( green );
263
    sb.append( "," );
264
    sb.append( blue );
265
    sb.append( "," );
266
    sb.append( alpha );
267
    sb.append( ")" );
268
    return sb.toString();
269
  }
200
}
270
}
(-)src/org/eclipse/rwt/internal/theme/QxShadow.java (+158 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 EclipseSource and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution, 
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
6
 *
7
 * Contributors:
8
 *   EclipseSource - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.rwt.internal.theme;
11
12
13
public class QxShadow implements QxType {
14
  
15
  public static final QxShadow NONE
16
    = new QxShadow( false, 0 , 0, 0, 0, null, 0 );
17
  
18
  public final boolean inset;
19
  public final int offsetX;
20
  public final int offsetY;
21
  public final int blur;
22
  public final int spread;
23
  public final String color;
24
  public final float opacity;
25
  
26
  private QxShadow( final boolean inset,
27
                    final int offsetX,
28
                    final int offsetY,
29
                    final int blur,
30
                    final int spread,
31
                    final String color,
32
                    final float opacity )
33
  {
34
    this.inset = inset;
35
    this.offsetX = offsetX;
36
    this.offsetY = offsetY;
37
    this.blur = blur;
38
    this.spread = spread;
39
    this.color = color;
40
    this.opacity = opacity;
41
  }
42
  
43
  public static QxShadow create( final boolean inset,
44
                                 final int offsetX,
45
                                 final int offsetY,
46
                                 final int blur,
47
                                 final int spread,
48
                                 final QxColor color )
49
  {
50
    String msg;
51
    if( inset ) {
52
      msg = "Shadow \"inset\" keyword is not supported";
53
      throw new IllegalArgumentException( msg );
54
    }
55
    if( blur < 0 ) {
56
      msg = "Shadow blur distance can't be negative";
57
      throw new IllegalArgumentException( msg );
58
    }
59
    if( spread != 0 ) {
60
      msg = "Shadow spread distance is not supported";
61
      throw new IllegalArgumentException( msg );
62
    }
63
    if( color == null ) {
64
      throw new NullPointerException( "null argument" );
65
    }
66
    String htmlColor = QxColor.toHtmlString( color.red,
67
                                             color.green,
68
                                             color.blue );
69
    return new QxShadow( inset,
70
                         offsetX,
71
                         offsetY,
72
                         blur,
73
                         spread,
74
                         htmlColor,
75
                         color.alpha );
76
  }
77
78
  public boolean equals( final Object obj ) {
79
    boolean result = false;
80
    if( obj == this ) {
81
      result = true;
82
    } else if( obj instanceof QxShadow ) {
83
      QxShadow other = ( QxShadow )obj;
84
      result =  other.inset == inset
85
             && other.offsetX == offsetX
86
             && other.offsetY == offsetY
87
             && other.blur == blur
88
             && other.spread == spread
89
             && ( color == null
90
                  ? other.color == null
91
                  : color.equals( other.color ) )
92
             && other.opacity == opacity;
93
    }
94
    return result;
95
  }
96
  
97
  public int hashCode() {
98
    int result = 17;
99
    result += 11 * result + offsetX;
100
    result += 11 * result + offsetY;
101
    result += 11 * result + blur;
102
    result += 11 * result + spread;
103
    if( color != null ) {
104
      result += 11 * result + color.hashCode();
105
    }
106
    result += 11 * result + Float.floatToIntBits( opacity );
107
    result += inset ? 0 : 11 * result + 13;
108
    return result;
109
  }
110
111
  public String toDefaultString() {
112
    StringBuffer buffer = new StringBuffer();
113
    if( color == null ) {
114
      buffer.append( "none" );
115
    } else {
116
      if( inset ) {
117
        buffer.append( "inset " );
118
      }
119
      buffer.append( offsetX );
120
      buffer.append( "px " );
121
      buffer.append( offsetY );
122
      buffer.append( "px " );
123
      buffer.append( blur );
124
      buffer.append( "px " );
125
      buffer.append( spread );
126
      buffer.append( "px " );
127
      buffer.append( "rgba( " );
128
      QxColor qxColor = QxColor.valueOf( color );
129
      buffer.append( qxColor.red );
130
      buffer.append( ", " );
131
      buffer.append( qxColor.green );
132
      buffer.append( ", " );
133
      buffer.append( qxColor.blue );
134
      buffer.append( ", " );
135
      buffer.append( opacity );
136
      buffer.append( " )" );
137
    }
138
    return buffer.toString();
139
  }
140
  
141
  public String toString() {
142
    StringBuffer buffer = new StringBuffer();
143
    buffer.append( inset );
144
    buffer.append( ", " );
145
    buffer.append( offsetX );
146
    buffer.append( ", " );
147
    buffer.append( offsetY );
148
    buffer.append( ", " );
149
    buffer.append( blur );
150
    buffer.append( ", " );
151
    buffer.append( spread );
152
    buffer.append( ", " );    
153
    buffer.append( color );
154
    buffer.append( ", " );
155
    buffer.append( opacity );
156
    return "QxShadow{ " + buffer.toString() + " }";
157
  }
158
}
(-)src/org/eclipse/rwt/internal/theme/ThemeStoreWriter.java (-2 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 EclipseSource and others. All rights reserved.
2
 * Copyright (c) 2009, 2011 EclipseSource and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
Lines 54-59 Link Here
54
    JsonObject borderMap = new JsonObject();
54
    JsonObject borderMap = new JsonObject();
55
    JsonObject cursorMap = new JsonObject();
55
    JsonObject cursorMap = new JsonObject();
56
    JsonObject animationMap = new JsonObject();
56
    JsonObject animationMap = new JsonObject();
57
    JsonObject shadowMap = new JsonObject();
57
    QxType[] values = new QxType[ valueSet.size() ];
58
    QxType[] values = new QxType[ valueSet.size() ];
58
    valueSet.toArray( values );
59
    valueSet.toArray( values );
59
    for( int i = 0; i < values.length; i++ ) {
60
    for( int i = 0; i < values.length; i++ ) {
Lines 94-100 Link Here
94
        }
95
        }
95
      } else if( value instanceof QxColor ) {
96
      } else if( value instanceof QxColor ) {
96
        QxColor color = ( QxColor )value;
97
        QxColor color = ( QxColor )value;
97
        if( color.transparent ) {
98
        if( color.isTransparent() ) {
98
          colorMap.append( key, "undefined" );
99
          colorMap.append( key, "undefined" );
99
        } else {
100
        } else {
100
          colorMap.append( key, QxColor.toHtmlString( color.red,
101
          colorMap.append( key, QxColor.toHtmlString( color.red,
Lines 137-142 Link Here
137
                                  currentAnimationArray );
138
                                  currentAnimationArray );
138
        }
139
        }
139
        animationMap.append( key, animationObject );
140
        animationMap.append( key, animationObject );
141
      } else if( value instanceof QxShadow ) {
142
        QxShadow shadow = ( QxShadow )value;        
143
        if( shadow.equals( QxShadow.NONE ) ) {
144
          shadowMap.append( key, JsonValue.NULL );
145
        } else {
146
          JsonArray shadowArray = new JsonArray();
147
          shadowArray.append( shadow.inset );
148
          shadowArray.append( shadow.offsetX );
149
          shadowArray.append( shadow.offsetY );
150
          shadowArray.append( shadow.blur );
151
          shadowArray.append( shadow.spread );
152
          shadowArray.append( shadow.color );
153
          shadowArray.append( shadow.opacity );
154
          shadowMap.append( key, shadowArray );
155
        }
140
      }
156
      }
141
    }
157
    }
142
    JsonObject valuesMap = new JsonObject();
158
    JsonObject valuesMap = new JsonObject();
Lines 149-154 Link Here
149
    valuesMap.append( "borders", borderMap );
165
    valuesMap.append( "borders", borderMap );
150
    valuesMap.append( "cursors", cursorMap );
166
    valuesMap.append( "cursors", cursorMap );
151
    valuesMap.append( "animations", animationMap );
167
    valuesMap.append( "animations", animationMap );
168
    valuesMap.append( "shadows", shadowMap );
152
    return valuesMap;
169
    return valuesMap;
153
  }
170
  }
154
171
(-)src/org/eclipse/rwt/internal/theme/css/PropertyResolver.java (-1 / +137 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2008, 2011 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 119-124 Link Here
119
      result = readFloat( unit );
119
      result = readFloat( unit );
120
    } else if( isAnimationProperty( name ) ) {
120
    } else if( isAnimationProperty( name ) ) {
121
      result = readAnimation( unit );
121
      result = readAnimation( unit );
122
    } else if( isShadowProperty( name ) ) {
123
      result = readShadow( unit );
122
    } else {
124
    } else {
123
      throw new IllegalArgumentException( "Unknown property " + name );
125
      throw new IllegalArgumentException( "Unknown property " + name );
124
    }
126
    }
Lines 183-188 Link Here
183
    return result;
185
    return result;
184
  }
186
  }
185
187
188
  static QxColor readColorWithAlpha( final LexicalUnit unit ) {
189
    QxColor result = null;
190
    int[] values = new int[ 3 ];
191
    float alpha = 1f;
192
    short type = unit.getLexicalUnitType();
193
    if(    type == LexicalUnit.SAC_FUNCTION
194
        && "rgba".equals( unit.getFunctionName() )  )
195
    {
196
      LexicalUnit nextUnit = unit.getParameters();
197
      boolean ok = nextUnit != null;
198
      boolean mixedTypes = false;
199
      short previousType = -1;
200
      int pos = 0;
201
      while( ok ) {
202
        type = nextUnit.getLexicalUnitType();
203
        if( pos == 0 || pos == 2 || pos == 4 ) {
204
          // color number
205
          if( type == LexicalUnit.SAC_INTEGER ) {
206
            values[ pos / 2 ] = normalizeRGBValue( nextUnit.getIntegerValue() );
207
          } else if( type == LexicalUnit.SAC_PERCENTAGE ) {
208
            float percentValue
209
              = normalizePercentValue( nextUnit.getFloatValue() );
210
            values[ pos / 2 ] = ( int )( 255 * percentValue / 100 );
211
          } else {
212
            ok = false;
213
          }
214
          mixedTypes = previousType != -1 && previousType != type;
215
          previousType = type;
216
        } else if( pos == 1 || pos == 3 || pos == 5 ) {
217
          // comma
218
          if( type != LexicalUnit.SAC_OPERATOR_COMMA ) {
219
            ok = false;
220
          }
221
        } else if( pos == 6 ) {
222
          // alpha number
223
          if( type == LexicalUnit.SAC_REAL ) {
224
            alpha = normalizeAlphaValue( nextUnit.getFloatValue() );
225
          } else {
226
            ok = false;
227
          }
228
        }
229
        pos++;
230
        nextUnit = nextUnit.getNextLexicalUnit();
231
        ok &= nextUnit != null && pos < 7 && !mixedTypes;
232
      }
233
      if( pos == 7 ) {
234
        result = QxColor.create( values[ 0 ], values[ 1 ], values[ 2 ], alpha );
235
      }
236
    }
237
    if( result == null ) {
238
      throw new IllegalArgumentException( "Failed to parse rgba color" );
239
    }
240
    return result;
241
  }
242
186
  static boolean isDimensionProperty( final String property ) {
243
  static boolean isDimensionProperty( final String property ) {
187
    return    "spacing".equals( property )
244
    return    "spacing".equals( property )
188
           || "width".equals( property )
245
           || "width".equals( property )
Lines 771-776 Link Here
771
    return result;
828
    return result;
772
  }
829
  }
773
830
831
  static boolean isShadowProperty( final String property ) {
832
    return "box-shadow".equals( property );
833
  }
834
835
  static QxShadow readShadow( final LexicalUnit unit ) {
836
    QxShadow result = null;
837
    boolean inset = false;
838
    Integer offsetX = null;
839
    Integer offsetY = null;
840
    int blur = 0;
841
    int spread = 0;
842
    QxColor color = QxColor.BLACK;
843
    LexicalUnit nextUnit = unit;
844
    short type = nextUnit.getLexicalUnitType();
845
    if( type == LexicalUnit.SAC_IDENT ) {
846
      String value = nextUnit.getStringValue();
847
      if( NONE.equals( value ) ) {
848
        result = QxShadow.NONE;
849
      } else if( INSET.equals( value ) ) {
850
        inset = true;
851
      }
852
      nextUnit = nextUnit.getNextLexicalUnit();
853
    }
854
    if( result == null ) {
855
      boolean ok = true;
856
      int pos = 0;
857
      while( nextUnit != null && ok ) {
858
        pos++;
859
        Integer nextValue = readSingleLengthUnit( nextUnit );
860
        ok &= nextValue != null && pos <= 4; 
861
        if( ok ) {
862
          if( pos == 1 ) {
863
            offsetX = nextValue;
864
          } else if( pos == 2 ) {
865
            offsetY = nextValue;
866
          } else if( pos == 3 ) {
867
            blur = nextValue.intValue();
868
          } else if( pos == 4 ) {
869
            spread = nextValue.intValue();
870
          }
871
          nextUnit = nextUnit.getNextLexicalUnit();
872
        }
873
      }
874
      if( nextUnit != null ) {
875
        type = nextUnit.getLexicalUnitType();
876
        if(    type == LexicalUnit.SAC_FUNCTION
877
            && "rgba".equals( nextUnit.getFunctionName() )  )
878
        {
879
          color = readColorWithAlpha( nextUnit );
880
        } else {
881
          color = readColor( nextUnit );
882
        }
883
      }
884
    }
885
    if( offsetX != null && offsetY != null ) {
886
      result = QxShadow.create( inset,
887
                                offsetX.intValue(),
888
                                offsetY.intValue(),
889
                                blur,
890
                                spread,
891
                                color );
892
    }
893
    if( result == null ) {
894
      throw new IllegalArgumentException( "Failed to parse shadow "
895
                                          + toString( unit ) );
896
    }
897
    return result;
898
  }
899
774
  private static Integer readSingleLengthUnit( final LexicalUnit unit ) {
900
  private static Integer readSingleLengthUnit( final LexicalUnit unit ) {
775
    Integer result = null;
901
    Integer result = null;
776
    short type = unit.getLexicalUnitType();
902
    short type = unit.getLexicalUnitType();
Lines 795-800 Link Here
795
    return result;
921
    return result;
796
  }
922
  }
797
923
924
  private static float normalizeAlphaValue( final float input ) {
925
    float result = input;
926
    if( input < 0 ) {
927
      result = 0f;
928
    } else if( input > 1 ) {
929
      result = 1f;
930
    }
931
    return result;
932
  }
933
798
  private static float normalizePercentValue( final float input ) {
934
  private static float normalizePercentValue( final float input ) {
799
    float result = input;
935
    float result = input;
800
    if( input < 0f ) {
936
    if( input < 0f ) {
(-)src/org/eclipse/swt/internal/widgets/shellkit/Shell.default.css (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2008, 2011 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
  padding: 0px;
18
  padding: 0px;
19
  background-image: none;
19
  background-image: none;
20
  opacity: 1;
20
  opacity: 1;
21
  box-shadow: none;
21
}
22
}
22
23
23
Shell[TITLE], Shell[BORDER] {
24
Shell[TITLE], Shell[BORDER] {
(-)src/org/eclipse/swt/internal/widgets/shellkit/Shell.theme.xml (-3 / +6 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
2
<!--
3
 Copyright (c) 2008, 2009 Innoopract Informationssysteme GmbH.
3
 Copyright (c) 2008, 2011 Innoopract Informationssysteme GmbH.
4
 All rights reserved. This program and the accompanying materials
4
 All rights reserved. This program and the accompanying materials
5
 are made available under the terms of the Eclipse Public License v1.0
5
 are made available under the terms of the Eclipse Public License v1.0
6
 which accompanies this distribution, and is available at
6
 which accompanies this distribution, and is available at
Lines 35-42 Link Here
35
    <property name="background-color"
35
    <property name="background-color"
36
        description="Background color for shells." />
36
        description="Background color for shells." />
37
37
38
	<property name="opacity" 
38
    <property name="opacity" 
39
	    description="The opacity of the shell. A value between 0 and 1." />
39
        description="The opacity of the shell. A value between 0 and 1." />
40
        
41
    <property name="box-shadow" 
42
        description="The shadow behind the shell." />
40
43
41
    <style name="BORDER"
44
    <style name="BORDER"
42
        description="Indicates that the shell should have a border." />
45
        description="Indicates that the shell should have a border." />
(-)js/org/eclipse/swt/theme/ThemeStore.js (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2007, 2011 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 31-37 Link Here
31
      colors : {},
31
      colors : {},
32
      borders : {},
32
      borders : {},
33
      cursors : {},
33
      cursors : {},
34
      animations : {}
34
      animations : {},
35
      shadows : {}
35
    };
36
    };
36
    this._cssValues = {};
37
    this._cssValues = {};
37
    this._statesMap = {
38
    this._statesMap = {
(-)js/org/eclipse/swt/theme/ThemeValues.js (-1 / +8 lines)
Lines 168-174 Link Here
168
    getCssAnimation : function( element, key ) {
168
    getCssAnimation : function( element, key ) {
169
      var vkey = this._store.getCssValue( element, this._states, key );
169
      var vkey = this._store.getCssValue( element, this._states, key );
170
      var values = this._store.getThemeValues();
170
      var values = this._store.getThemeValues();
171
      var result = values.animations[ vkey ];      
171
      var result = values.animations[ vkey ];
172
      return result;
173
    },
174
175
    getCssShadow : function( element, key ) {
176
      var vkey = this._store.getCssValue( element, this._states, key );
177
      var values = this._store.getThemeValues();
178
      var result = values.shadows[ vkey ];
172
      return result;
179
      return result;
173
    }
180
    }
174
181
(-)src/org/eclipse/rwt/internal/theme/QxColor_Test.java (-7 / +48 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2007, 2011 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 39-50 Link Here
39
    }
39
    }
40
  }
40
  }
41
41
42
  public void testIllegalArguments_OutOfRangeAlpha() {
43
    try {
44
      QxColor.valueOf( "1, 2, 3, 1.01" );
45
      fail( "Exception expected" );
46
    } catch( IllegalArgumentException e ) {
47
      // expected
48
    }
49
  }
50
51
  public void testIllegalArguments_NegativeAlpha() {
52
    try {
53
      QxColor.valueOf( "1, 2, 3, -0.01" );
54
      fail( "Exception expected" );
55
    } catch( IllegalArgumentException e ) {
56
      // expected
57
    }
58
  }
59
42
  public void test6HexNotation() {
60
  public void test6HexNotation() {
43
    QxColor color1 = QxColor.valueOf( "#0023ff" );
61
    QxColor color1 = QxColor.valueOf( "#0023ff" );
44
    assertEquals( 0, color1.red );
62
    assertEquals( 0, color1.red );
45
    assertEquals( 35, color1.green );
63
    assertEquals( 35, color1.green );
46
    assertEquals( 255, color1.blue );
64
    assertEquals( 255, color1.blue );
47
    assertFalse( color1.transparent );
65
    assertEquals( 1f, color1.alpha, 0 );
48
    QxColor color2 = QxColor.valueOf( "#efeFEF" );
66
    QxColor color2 = QxColor.valueOf( "#efeFEF" );
49
    assertEquals( 239, color2.red );
67
    assertEquals( 239, color2.red );
50
    assertEquals( 239, color2.green );
68
    assertEquals( 239, color2.green );
Lines 56-62 Link Here
56
    assertEquals( 0, color1.red );
74
    assertEquals( 0, color1.red );
57
    assertEquals( 51, color1.green );
75
    assertEquals( 51, color1.green );
58
    assertEquals( 255, color1.blue );
76
    assertEquals( 255, color1.blue );
59
    assertFalse( color1.transparent );
77
    assertEquals( 1f, color1.alpha, 0 );
60
    QxColor color2 = QxColor.valueOf( "#ccc" );
78
    QxColor color2 = QxColor.valueOf( "#ccc" );
61
    assertEquals( 204, color2.red );
79
    assertEquals( 204, color2.red );
62
    assertEquals( 204, color2.green );
80
    assertEquals( 204, color2.green );
Lines 69-75 Link Here
69
    assertEquals( 255, color1.red );
87
    assertEquals( 255, color1.red );
70
    assertEquals( 0, color1.green );
88
    assertEquals( 0, color1.green );
71
    assertEquals( 0, color1.blue );
89
    assertEquals( 0, color1.blue );
72
    assertFalse( color1.transparent );
90
    assertEquals( 1f, color1.alpha, 0 );
73
    QxColor color2 = QxColor.valueOf( "blue" );
91
    QxColor color2 = QxColor.valueOf( "blue" );
74
    assertEquals( 0, color2.red );
92
    assertEquals( 0, color2.red );
75
    assertEquals( 0, color2.green );
93
    assertEquals( 0, color2.green );
Lines 81-91 Link Here
81
    assertEquals( 100, color.red );
99
    assertEquals( 100, color.red );
82
    assertEquals( 23, color.green );
100
    assertEquals( 23, color.green );
83
    assertEquals( 42, color.blue );
101
    assertEquals( 42, color.blue );
84
    assertFalse( color.transparent );
102
    assertEquals( 1f, color.alpha, 0 );
103
  }
104
105
  public void testCommaSeparatedValues_WithAlpha() {
106
    QxColor color = QxColor.valueOf( "100, 23, 42, 0.5" );
107
    assertEquals( 100, color.red );
108
    assertEquals( 23, color.green );
109
    assertEquals( 42, color.blue );
110
    assertEquals( 0.5, color.alpha, 0 );
85
  }
111
  }
86
112
87
  public void testTransparent() {
113
  public void testTransparent() {
88
    assertTrue( QxColor.TRANSPARENT.transparent );
114
    assertTrue( QxColor.TRANSPARENT.isTransparent() );
89
  }
115
  }
90
116
91
  public void testShared() {
117
  public void testShared() {
Lines 100-112 Link Here
100
126
101
  public void testToString() {
127
  public void testToString() {
102
    QxColor color = QxColor.valueOf( "100, 23, 42" );
128
    QxColor color = QxColor.valueOf( "100, 23, 42" );
103
    assertEquals( "QxColor{ 100, 23, 42 }", color.toString() );
129
    assertEquals( "QxColor{ 100, 23, 42, 1.0 }", color.toString() );
130
  }
131
132
  public void testToString_WithAlpha() {
133
    QxColor color = QxColor.valueOf( "100, 23, 42, 0.5" );
134
    assertEquals( "QxColor{ 100, 23, 42, 0.5 }", color.toString() );
104
  }
135
  }
105
136
106
  public void testDefaultString() {
137
  public void testDefaultString() {
107
    QxColor color = QxColor.valueOf( "100, 23, 42" );
138
    QxColor color = QxColor.valueOf( "100, 23, 42" );
108
    assertEquals( "#64172a", color.toDefaultString() );
139
    assertEquals( "#64172a", color.toDefaultString() );
109
  }
140
  }
141
  
142
  public void testDefaultString_Transparent() {
143
    QxColor color = QxColor.valueOf( "100, 23, 42, 0" );
144
    assertEquals( "transparent", color.toDefaultString() );
145
  }
146
147
  public void testDefaultString_WithAlpha() {
148
    QxColor color = QxColor.valueOf( "100, 23, 42, 0.5" );
149
    assertEquals( "rgba(100,23,42,0.5)", color.toDefaultString() );
150
  }
110
151
111
  public void testWithTurkishLocale() {
152
  public void testWithTurkishLocale() {
112
    Locale originalLocale = Locale.getDefault();
153
    Locale originalLocale = Locale.getDefault();
(-)src/org/eclipse/rwt/internal/theme/QxShadow_Test.java (+113 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 EclipseSource and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution, 
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
6
 *
7
 * Contributors:
8
 *   EclipseSource - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.rwt.internal.theme;
11
12
import junit.framework.TestCase;
13
14
15
public class QxShadow_Test extends TestCase {
16
  
17
  public void testIllegalArguments_Inset() {
18
    try {
19
      QxShadow.create( true, 10, 10, 0, 0, QxColor.BLACK );
20
      fail( "Exception expected" );
21
    } catch( IllegalArgumentException e ) {
22
      // expected
23
    }
24
  }
25
26
  public void testIllegalArguments_NegativeBlur() {
27
    try {
28
      QxShadow.create( false, 10, 10, -10, 0, QxColor.BLACK );
29
      fail( "Exception expected" );
30
    } catch( IllegalArgumentException e ) {
31
      // expected
32
    }
33
  }
34
  
35
  public void testIllegalArguments_SpreadNotZero() {
36
    try {
37
      QxShadow.create( false, 10, 10, 0, 10, QxColor.BLACK );
38
      fail( "Exception expected" );
39
    } catch( IllegalArgumentException e ) {
40
      // expected
41
    }
42
  }
43
  
44
  public void testIllegalArguments_NullColor() {
45
    try {
46
      QxShadow.create( false, 10, 10, 0, 0, null );
47
      fail( "Exception expected" );
48
    } catch( NullPointerException e ) {
49
      // expected
50
    }
51
  }
52
53
  public void testCreate_WithoutOpacity() {
54
    QxShadow shadow = QxShadow.create( false, 10, 10, 0, 0, QxColor.BLACK );
55
    assertNotNull( shadow );
56
    assertFalse( shadow.inset );
57
    assertEquals( 10, shadow.offsetX );
58
    assertEquals( 10, shadow.offsetY );
59
    assertEquals( 0, shadow.blur );
60
    assertEquals( 0, shadow.spread );
61
    assertEquals( QxColor.BLACK.toDefaultString(), shadow.color );
62
    assertEquals( 1f, shadow.opacity, 0 );
63
  }
64
65
  public void testCreate_WithOpacity() {
66
    QxColor color = QxColor.valueOf( "0, 0, 0, 0.5" );
67
    QxShadow shadow = QxShadow.create( false, 10, 10, 0, 0, color );
68
    assertNotNull( shadow );
69
    assertFalse( shadow.inset );
70
    assertEquals( 10, shadow.offsetX );
71
    assertEquals( 10, shadow.offsetY );
72
    assertEquals( 0, shadow.blur );
73
    assertEquals( 0, shadow.spread );
74
    assertEquals( QxColor.BLACK.toDefaultString(), shadow.color );
75
    assertEquals( 0.5, shadow.opacity, 0 );
76
  }
77
78
  public void testNoneShadow() {
79
    QxShadow shadow = QxShadow.NONE;
80
    assertFalse( shadow.inset );
81
    assertEquals( 0, shadow.offsetX );
82
    assertEquals( 0, shadow.offsetY );
83
    assertEquals( 0, shadow.blur );
84
    assertEquals( 0, shadow.spread );
85
    assertNull( shadow.color );
86
    assertEquals( 0, shadow.opacity, 0 );
87
  }
88
89
  public void testToString() {
90
    QxShadow shadow = QxShadow.create( false, 10, 10, 0, 0, QxColor.BLACK );
91
    String expected = "QxShadow{ false, 10, 10, 0, 0, #000000, 1.0 }";
92
    assertEquals( expected, shadow.toString() );
93
  }
94
95
  public void testToDefaultString() {
96
    QxColor color = QxColor.valueOf( "0, 0, 0, 0.5" );
97
    QxShadow shadow = QxShadow.create( false, 10, 10, 0, 0, color );
98
    String expected = "10px 10px 0px 0px rgba( 0, 0, 0, 0.5 )";
99
    assertEquals( expected, shadow.toDefaultString() );
100
  }
101
102
  public void testToDefaultString_NoneShadow() {
103
    QxShadow shadow = QxShadow.NONE;
104
    String expected = "none";
105
    assertEquals( expected, shadow.toDefaultString() );
106
  }
107
108
  public void testEquals() {
109
    QxShadow shadow1 = QxShadow.create( false, 10, 10, 0, 0, QxColor.BLACK );
110
    QxShadow shadow2 = QxShadow.create( false, 10, 10, 0, 0, QxColor.BLACK );
111
    assertTrue( shadow1.equals( shadow2 ) );
112
  } 
113
}
(-)src/org/eclipse/rwt/internal/theme/ThemeStoreWriter_Test.java (-3 / +28 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 EclipseSource and others. All rights reserved.
2
 * Copyright (c) 2009, 2011 EclipseSource and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
Lines 45-51 Link Here
45
    expected = "\"cd56ce7d\": [ \"cd56ce7d\", 50, 100 ]";
45
    expected = "\"cd56ce7d\": [ \"cd56ce7d\", 50, 100 ]";
46
    assertTrue( output.indexOf( expected ) != -1 );
46
    assertTrue( output.indexOf( expected ) != -1 );
47
    // conditional colors
47
    // conditional colors
48
    expected = "\"color\": [ [ [ \"[BORDER\" ], \"ff\" ], [ [], \"0\" ] ]";
48
    expected = "\"color\": [ [ [ \"[BORDER\" ], "
49
             + "\"400339c0\" ], [ [], \"3fe41900\" ] ]";
49
    assertTrue( output.indexOf( expected ) != -1 );
50
    assertTrue( output.indexOf( expected ) != -1 );
50
    // conditional background-images
51
    // conditional background-images
51
    expected = "\"background-image\": "
52
    expected = "\"background-image\": "
Lines 72-78 Link Here
72
                      + "\"slideIn\": [ 2000, \"easeIn\" ],\n"
73
                      + "\"slideIn\": [ 2000, \"easeIn\" ],\n"
73
                      + "\"slideOut\": [ 2000, \"easeOut\" ]\n"
74
                      + "\"slideOut\": [ 2000, \"easeOut\" ]\n"
74
                      + "}\n"
75
                      + "}\n"
75
                      + "}\n";
76
                      + "},\n";
76
    assertTrue( output.indexOf( expected ) != -1 );
77
    assertTrue( output.indexOf( expected ) != -1 );
77
    expected = "\"Menu\": {\n"
78
    expected = "\"Menu\": {\n"
78
               + "\"animation\": [ [ [], \"2e5f3d63\" ] ]\n"
79
               + "\"animation\": [ [ [], \"2e5f3d63\" ] ]\n"
Lines 146-151 Link Here
146
    assertTrue( output.indexOf( expected ) != -1 );
147
    assertTrue( output.indexOf( expected ) != -1 );
147
  }
148
  }
148
149
150
  public void testWriteShadow() throws Exception {
151
    ThemeCssElement element = new ThemeCssElement( "Shell" );
152
    element.addProperty( "box-shadow" );
153
    IThemeCssElement[] elements = new IThemeCssElement[] { element };
154
    ThemeStoreWriter storeWriter = new ThemeStoreWriter( elements );
155
    String themeId = "myTheme";
156
    String cssCode
157
      = "Shell { box-shadow: 10px 10px 3px 0 rgba( 0, 0, 0, 0.5 ); }\n";
158
    ResourceLoader loader
159
      = ThemeTestUtil.createResourceLoader( Fixture.class );
160
    ThemeTestUtil.registerCustomTheme( themeId, cssCode, loader );
161
    Theme theme = ThemeManager.getInstance().getTheme( themeId );
162
    storeWriter.addTheme( theme, true );
163
    String output = storeWriter.createJs();
164
    String expected = "\"shadows\": {\n"
165
      + "\"2aedfabd\": [ false, 10, 10, 3, 0, \"#000000\", 0.5 ]\n"
166
      + "}\n";
167
    assertTrue( output.indexOf( expected ) != -1 );
168
    expected = "\"Shell\": {\n"
169
               + "\"box-shadow\": [ [ [], \"2aedfabd\" ] ]\n"
170
               + "}";
171
    assertTrue( output.indexOf( expected ) != -1 );
172
  }
173
149
  protected void setUp() throws Exception {
174
  protected void setUp() throws Exception {
150
    Fixture.setUp();
175
    Fixture.setUp();
151
    Fixture.fakeNewRequest();
176
    Fixture.fakeNewRequest();
(-)src/org/eclipse/rwt/internal/theme/css/PropertyResolver_Test.java (-1 / +190 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2008, 2011 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 77-82 Link Here
77
    }
77
    }
78
  }
78
  }
79
79
80
  public void testColorWithAlpha() throws Exception {
81
    String input = "rgba( 1, 2, 3, 0.25 )";
82
    QxColor result
83
      = PropertyResolver.readColorWithAlpha( parseProperty( input ) );
84
    assertNotNull( result );
85
    assertEquals( 1, result.red );
86
    assertEquals( 2, result.green );
87
    assertEquals( 3, result.blue );
88
    assertEquals( 0.25, result.alpha, 0 );
89
  }
90
91
  public void testColorWithAlpha_Percents() throws Exception {
92
    String input = "rgba( 0%, 50%, 100%, 0.25 )";
93
    QxColor result
94
      = PropertyResolver.readColorWithAlpha( parseProperty( input ) );
95
    assertNotNull( result );
96
    assertEquals( 0, result.red );
97
    assertEquals( 127, result.green );
98
    assertEquals( 255, result.blue );
99
    assertEquals( 0.25, result.alpha, 0 );
100
  }
101
  
102
  public void testColorWithAlpha_NoTransparency() throws Exception {
103
    String input = "rgba( 0, 0, 0, 1 )";
104
    QxColor result
105
      = PropertyResolver.readColorWithAlpha( parseProperty( input ) );
106
    assertSame( QxColor.BLACK, result );
107
  }
108
109
  public void testColorWithAlpha_NormalizeNegativeAlpha() throws Exception {
110
    String input = "rgba( 1, 2, 3, -0.1 )";
111
    QxColor result
112
      = PropertyResolver.readColorWithAlpha( parseProperty( input ) );
113
    assertNotNull( result );
114
    assertEquals( 1, result.red );
115
    assertEquals( 2, result.green );
116
    assertEquals( 3, result.blue );
117
    assertEquals( 0f, result.alpha, 0 );
118
  }
119
120
  public void testColorWithAlpha_NormalizePositiveAlpha() throws Exception {
121
    String input = "rgba( 1, 2, 3, 1.1 )";
122
    QxColor result
123
      = PropertyResolver.readColorWithAlpha( parseProperty( input ) );
124
    assertNotNull( result );
125
    assertEquals( 1, result.red );
126
    assertEquals( 2, result.green );
127
    assertEquals( 3, result.blue );
128
    assertEquals( 1f, result.alpha, 0 );
129
  }
130
131
  public void testColorWithAlpha_NormalizeColorValue() throws Exception {
132
    String input = "rgba( -10, 127, 300, 0.25 )";
133
    QxColor result
134
      = PropertyResolver.readColorWithAlpha( parseProperty( input ) );
135
    assertNotNull( result );
136
    assertEquals( 0, result.red );
137
    assertEquals( 127, result.green );
138
    assertEquals( 255, result.blue );
139
    assertEquals( 0.25, result.alpha, 0 );
140
  }
141
142
  public void testColorWithAlpha_MixedValues() throws Exception {
143
    String input = "rgba( 0%, 50, 100, 0.25 )";
144
    try {
145
      PropertyResolver.readColorWithAlpha( parseProperty( input ) );
146
      fail();
147
    } catch( IllegalArgumentException e ) {
148
      // expected
149
    }
150
  }
151
80
  public void testDimension() throws Exception {
152
  public void testDimension() throws Exception {
81
    QxDimension zero = PropertyResolver.readDimension( parseProperty( "0px" ) );
153
    QxDimension zero = PropertyResolver.readDimension( parseProperty( "0px" ) );
82
    assertNotNull( zero );
154
    assertNotNull( zero );
Lines 652-657 Link Here
652
    }
724
    }
653
  }
725
  }
654
726
727
  public void testShadow_XYOffsetOnlyNotation() throws Exception {
728
    String input = "1px 2px";
729
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
730
    assertNotNull( result );
731
    assertEquals( 1, result.offsetX );
732
    assertEquals( 2, result.offsetY );
733
    assertEquals( 0, result.blur );
734
    assertEquals( 0, result.spread );
735
    assertEquals( "#000000", result.color );
736
    assertEquals( 1f, result.opacity, 0 );
737
  }
738
739
  public void testShadow_OffsetXYBlurNotation() throws Exception {
740
    String input = "1px 2px 3px";
741
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
742
    assertNotNull( result );
743
    assertEquals( 1, result.offsetX );
744
    assertEquals( 2, result.offsetY );
745
    assertEquals( 3, result.blur );
746
    assertEquals( 0, result.spread );
747
    assertEquals( "#000000", result.color );
748
    assertEquals( 1f, result.opacity, 0 );
749
  }
750
751
  public void testShadow_XYOffsetBlurSpreadNotation() throws Exception {
752
    String input = "1px 2px 0 0";
753
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
754
    assertNotNull( result );
755
    assertEquals( 1, result.offsetX );
756
    assertEquals( 2, result.offsetY );
757
    assertEquals( 0, result.blur );
758
    assertEquals( 0, result.spread );
759
    assertEquals( "#000000", result.color );
760
    assertEquals( 1f, result.opacity, 0 );
761
  }
762
763
  public void testShadow_FullNotation_NamedColor() throws Exception {
764
    String input = "1px 2px 0px 0 red";
765
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
766
    assertNotNull( result );
767
    assertEquals( 1, result.offsetX );
768
    assertEquals( 2, result.offsetY );
769
    assertEquals( 0, result.blur );
770
    assertEquals( 0, result.spread );
771
    assertEquals( "#ff0000", result.color );
772
    assertEquals( 1f, result.opacity, 0 );
773
  }
774
775
  public void testShadow_FullNotation_HexColor() throws Exception {
776
    String input = "1px 2px 0px 0 #FF0000";
777
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
778
    assertNotNull( result );
779
    assertEquals( 1, result.offsetX );
780
    assertEquals( 2, result.offsetY );
781
    assertEquals( 0, result.blur );
782
    assertEquals( 0, result.spread );
783
    assertEquals( "#ff0000", result.color );
784
    assertEquals( 1f, result.opacity, 0 );
785
  }
786
787
  public void testShadow_FullNotation_RgbColor() throws Exception {
788
    String input = "1px 2px 3px 0 rgb( 1, 2, 3 )";
789
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
790
    assertNotNull( result );
791
    assertEquals( 1, result.offsetX );
792
    assertEquals( 2, result.offsetY );
793
    assertEquals( 3, result.blur );
794
    assertEquals( 0, result.spread );
795
    assertEquals( "#010203", result.color );
796
    assertEquals( 1f, result.opacity, 0 );
797
  }
798
799
  public void testShadow_FullNotation_RgbaColor() throws Exception {
800
    String input = "1px 2px 0px 0 rgba( 1, 2, 3, 0.25 )";
801
    QxShadow result = PropertyResolver.readShadow( parseProperty( input ) );
802
    assertNotNull( result );
803
    assertEquals( 1, result.offsetX );
804
    assertEquals( 2, result.offsetY );
805
    assertEquals( 0, result.blur );
806
    assertEquals( 0, result.spread );
807
    assertEquals( "#010203", result.color );
808
    assertEquals( 0.25, result.opacity, 0 );
809
  }
810
811
  public void testShadow_WithoutOffsetY() throws Exception {
812
    try {
813
      PropertyResolver.readShadow( parseProperty( "1px" ) );
814
      fail();
815
    } catch( IllegalArgumentException e ) {
816
      // expected
817
    }
818
  }
819
820
  public void testShadow_MissingRgbaParameters() throws Exception {
821
    String input = "1px 2px 0px 0 rgba( 1, 2, 0.25 )";
822
    try {
823
      PropertyResolver.readShadow( parseProperty( input ) );
824
      fail();
825
    } catch( IllegalArgumentException e ) {
826
      // expected
827
    }
828
  }
829
830
  public void testShadow_NonZeroSpread() throws Exception {
831
    String input = "1px 2px 3px 3px rgba( 1, 2, 3, 0.25 )";
832
    try {
833
      PropertyResolver.readShadow( parseProperty( input ) );
834
      fail();
835
    } catch( IllegalArgumentException e ) {
836
      // expected
837
    }
838
  }
839
655
  public void testIsColorProperty() {
840
  public void testIsColorProperty() {
656
    assertFalse( PropertyResolver.isColorProperty( "border" ) );
841
    assertFalse( PropertyResolver.isColorProperty( "border" ) );
657
    assertTrue( PropertyResolver.isColorProperty( "color" ) );
842
    assertTrue( PropertyResolver.isColorProperty( "color" ) );
Lines 685-690 Link Here
685
    assertTrue( PropertyResolver.isAnimationProperty( "animation" ) );
870
    assertTrue( PropertyResolver.isAnimationProperty( "animation" ) );
686
  }
871
  }
687
872
873
  public void testIsShadowProperty() {
874
    assertTrue( PropertyResolver.isShadowProperty( "box-shadow" ) );
875
  }
876
688
  public void testResolveProperty() throws Exception {
877
  public void testResolveProperty() throws Exception {
689
    LexicalUnit unit = parseProperty( "white" );
878
    LexicalUnit unit = parseProperty( "white" );
690
    QxType value = PropertyResolver.resolveProperty( "color", unit, null );
879
    QxType value = PropertyResolver.resolveProperty( "color", unit, null );

Return to bug 324436