Overview | Package | Class | Tree | Deprecated | Index | Help
| GWT 2.0.3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.resources.client
Interface CssResource

All Superinterfaces:
  ResourcePrototype

    public interface CssResource

extends ResourcePrototype

Aggregates and minifies CSS stylesheets. A CssResource represents a regular CSS file with GWT-specific at-rules.

Currently-supported accessor functions:

- `String someClassName();` will allow the css class `.someClassName` to be obfuscated at runtime. The function will return the obfuscated class name.
- `<primitive numeric type or String> someDefName();` will allow access to the values defined by @def rules within the CSS file. The defined value must be a raw number, a CSS length, or a percentage value if it is to be returned as a numeric type.

Currently-supported rules:

- `@def NAME replacement-expression; .myClass background: NAME;` Define a static constant. The replacement expression may be any CSS that would be valid in a property value context. A `@def` may refer to previously-defined rules, but no forward-references will be honored.
- `@eval NAME Java-expression; .myClass background: NAME;` Define a constant based on a Java expression.
- `@external class-name, class-name, ...;` Disable obfuscation for specific class selectors and exclude those class selectors from strictness requirements.
- `@if [!]property list of values {ruleBlock}` Include or exclude CSS rules based on the value of a deferred-binding property. Also `@elif` and `@else` follow the same pattern.
  This might look like `@if user.agent ie6 safari ...`.
- `@if (Java-expression) {ruleBlock}` Include or exclude CSS rules based on a boolean Java expression.
- `@noflip { rules }` will suppress the automatic right-to-left transformation applied to the CSS when the module is compiled for an RTL language.
- `@sprite .any .selector {gwt-image: "imageResourceFunction";}` . The appearance, size, and height of the sprite will be affected by any `ImageResource.ImageOptions` annotations present on the related `ImageResource` accessor function. Additional properties may be specified in the rule block.
- `@url NAME siblingDataResource; .myClass background: NAME repeat-x;` Use a `DataResource` to generate a `url('...'}` value.

Currently-supported CSS functions:

- `literal("expression")` substitutes a property value that does not conform to CSS2 parsing rules. The escape sequences `\"` and `\\` will be replaced with `"` and `\` respectively.
- `value("bundleFunction.someFunction[.other[...]]" [, "suffix"])` substitute the value of a sequence of named zero-arg function invocations. An optional suffix will be appended to the return value of the function. The first name is resolved relative to the bundle interface passed to `GWT.create(Class)`. An example:

       .bordersTheSizeOfAnImage {
         border-left: value('leftBorderImageResource.getWidth', 'px') solid blue;
       }

Any class selectors that do not correspond with a String accessor method in the return type will trigger a compilation error. This ensures that the CssResource does not contribute any unobfuscated class selectors into the global CSS namespace. Strict mode can be disabled by annotating the ClientBundle method declaration with `CssResource.NotStrict`, however this is only recommended for interacting with legacy CSS.

Given these interfaces:

     interface MyCss extends CssResource {
       String someClass();
     }

     interface MyBundle extends ClientBundle {
      @Source("my.css")
       MyCss css();
     }

the source CSS will fail to compile if it does not contain exactly the one class selector defined in the MyCss type.

The `@external` at-rule can be used in strict mode to indicate that certain class selectors are exempt from the strict semantics. Class selectors marked as external will not be obfuscated and are not required to have string accessor functions. Consider the following example in conjunction with the above `MyCss` interface:

     @external .foo, .bar;
     .foo .someClass .bar { .... }

The resulting CSS would look like:

     .foo .A1234 .bar { .... }

If a `String foo()` method were defined in `MyCss`, it would return the string value "`foo`".

The utility tool `com.google.gwt.resources.css.InterfaceGenerator` can be used to automatically generate a Java interface from a CssResource-compatible CSS file.

See Also:
  CssResource design doc

Nested Class Summary
`static interface` | `CssResource.ClassName` The original CSS class name specified in the resource.
`static interface` | `CssResource.Import` Makes class selectors from other CssResource types available in the raw source of a CssResource.
`static interface` | `CssResource.ImportedWithPrefix` Specifies the string prefix to use when one CssResource is imported into the scope of another CssResource.
`static interface` | `CssResource.NotStrict` The presence of this annotation on a CssResource accessor method indicates that any class selectors that do not correspond with a String accessor method in the return type or an `@external` declaration should not trigger a compilation error.
`static interface` | `CssResource.Shared` Indicates that the String accessor methods defined in a CssResource will return the same values across all implementations of that type.
`static interface` | `CssResource.Strict` Deprecated. Strict mode is now the default behavior for CssResource

Method Summary
`boolean` | `ensureInjected()` Calls `StyleInjector.injectStylesheet(String)` to inject the contents of the CssResource into the DOM.
`java.lang.String` | `getText()` Provides the contents of the CssResource.

Methods inherited from interface com.google.gwt.resources.client.ResourcePrototype
`getName`

Method Detail

### ensureInjected

    boolean ensureInjected()

  Calls `StyleInjector.injectStylesheet(String)` to inject the contents of the CssResource into the DOM. Repeated calls to this method on an instance of a CssResources will have no effect.

  Returns:
    `true` if this method mutated the DOM.

### getText

    java.lang.String getText()

  Provides the contents of the CssResource.

Overview | Package | Class | Tree | Deprecated | Index | Help
| GWT 2.0.3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD