public static class CssResource extends Object
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.@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 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.
Copyright © 2018. All rights reserved.