Goktug Gokdogan has submitted this change and it was merged.
Change subject: Add support for 'ImageResource' to @url substitution in
css. Only 'DataResource' used to be supported.
......................................................................
Add support for 'ImageResource' to @url substitution in css.
Only 'DataResource' used to be supported.
Change-Id: Ie6ae9fe0ace59eb682a77a761fe252bf46cafa9f
Review-Link: https://gwt-review.googlesource.com/#/c/3290/
---
M user/src/com/google/gwt/resources/css/SubstitutionReplacer.java
M user/test/com/google/gwt/resources/client/CSSResourceTest.java
M user/test/com/google/gwt/resources/client/test.css
3 files changed, 30 insertions(+), 4 deletions(-)
Approvals:
Leeroy Jenkins: Verified
Goktug Gokdogan: Looks good to me, approved
diff --git
a/user/src/com/google/gwt/resources/css/SubstitutionReplacer.java
b/user/src/com/google/gwt/resources/css/SubstitutionReplacer.java
index 885a2b4..0fe893f 100644
--- a/user/src/com/google/gwt/resources/css/SubstitutionReplacer.java
+++ b/user/src/com/google/gwt/resources/css/SubstitutionReplacer.java
@@ -17,8 +17,10 @@
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.resources.client.DataResource;
+import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.css.ast.Context;
import com.google.gwt.resources.css.ast.CssCompilerException;
import com.google.gwt.resources.css.ast.CssDef;
@@ -44,6 +46,7 @@
public class SubstitutionReplacer extends CssVisitor {
private final ResourceContext context;
private final JClassType dataResourceType;
+ private final JClassType imageResourceType;
private final TreeLogger logger;
private final Map<String, CssDef> substitutions;
@@ -52,6 +55,8 @@
this.context = context;
this.dataResourceType =
context.getGeneratorContext().getTypeOracle().findType(
DataResource.class.getCanonicalName());
+ this.imageResourceType =
context.getGeneratorContext().getTypeOracle().findType(
+ ImageResource.class.getCanonicalName());
this.logger = logger;
this.substitutions = substitutions;
}
@@ -95,21 +100,34 @@
assert def.getValues().get(0).isDotPathValue() != null;
DotPathValue functionName =
def.getValues().get(0).isDotPathValue();
+ JType methodType = null;
try {
-
ResourceGeneratorUtil.getMethodByPath(context.getClientBundleType(),
- functionName.getParts(), dataResourceType);
+ methodType =
ResourceGeneratorUtil.getMethodByPath(context.getClientBundleType(),
+ functionName.getParts(), null).getReturnType();
} catch (NotFoundException e) {
logger.log(TreeLogger.ERROR, e.getMessage());
throw new CssCompilerException("Cannot find data method");
}
- String instance = "((" + DataResource.class.getName() + ")("
+ if (!methodType.equals(dataResourceType) &&
+ !methodType.equals(imageResourceType)) {
+ String message = "Invalid method type for url substitution: " +
methodType + ". " +
+ "Only DataResource and ImageResource are supported.";
+ logger.log(TreeLogger.ERROR, message);
+ throw new CssCompilerException(message);
+ }
+
+ String instance = "((" + methodType.getQualifiedSourceName() + ")("
+ context.getImplementationSimpleSourceName() + ".this."
+ functionName.getExpression() + "))";
StringBuilder expression = new StringBuilder();
expression.append("\"url('\" + ");
- expression.append(instance).append(".getUrl()");
+ if (methodType.equals(dataResourceType)) {
+ expression.append(instance).append(".getUrl()");
+ } else if (methodType.equals(imageResourceType)) {
+ expression.append(instance).append(".getURL()");
+ }
expression.append(" + \"')\"");
result.add(new ExpressionValue(expression.toString()));
} else {
diff --git a/user/test/com/google/gwt/resources/client/CSSResourceTest.java
b/user/test/com/google/gwt/resources/client/CSSResourceTest.java
index ab91748..be907ae 100644
--- a/user/test/com/google/gwt/resources/client/CSSResourceTest.java
+++ b/user/test/com/google/gwt/resources/client/CSSResourceTest.java
@@ -313,6 +313,10 @@
+ Resources.INSTANCE.dataMethod().getUrl() + "')"));
assertTrue(text.contains("backgroundNested:url('"
+ Resources.INSTANCE.nested().dataMethod().getUrl() + "')"));
+ assertTrue(text.contains("backgroundImage:url('"
+ + Resources.INSTANCE.spriteMethod().getURL() + "')"));
+ assertTrue(text.contains("backgroundImageNested:url('"
+ + Resources.INSTANCE.nested().spriteMethod().getURL() + "')"));
// Check @eval expansion
assertTrue(text.contains(red() + ";"));
diff --git a/user/test/com/google/gwt/resources/client/test.css
b/user/test/com/google/gwt/resources/client/test.css
index 6317916..f93d24c 100644
--- a/user/test/com/google/gwt/resources/client/test.css
+++ b/user/test/com/google/gwt/resources/client/test.css
@@ -18,6 +18,8 @@
@eval RED com.google.gwt.resources.client.CSSResourceTest.red();
@url BACKGROUND dataMethod;
@url NESTEDBACKGROUND nested.dataMethod;
+@url BACKGROUNDIMAGE spriteMethod;
+@url NESTEDBACKGROUNDIMAGE nested.spriteMethod;
/* Check @def expansion */
@def SPRITEWIDTH value("spriteMethod.getWidth", "px");
@@ -57,6 +59,8 @@
direction: DIRECTION;
backgroundTopLevel: BACKGROUND;
backgroundNested: NESTEDBACKGROUND;
+ backgroundImage: BACKGROUNDIMAGE;
+ backgroundImageNested: NESTEDBACKGROUNDIMAGE;
}
div[foo="bar"] {
--
To view, visit https://gwt-review.googlesource.com/3290
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie6ae9fe0ace59eb682a77a761fe252bf46cafa9f
Gerrit-PatchSet: 2
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Emmanuel Pellereau <[email protected]>
Gerrit-Reviewer: Daniel Kurka <[email protected]>
Gerrit-Reviewer: Emmanuel Pellereau <[email protected]>
Gerrit-Reviewer: Goktug Gokdogan <[email protected]>
Gerrit-Reviewer: Leeroy Jenkins <[email protected]>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.