Reviewers: jlabanca, pdr,
Description:
Adds support for the CSS_ATTRIBUTE_START parse context to
HtmlTemplateParser.
Please review this at http://gwt-code-reviews.appspot.com/1392801/
Affected files:
M user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java
M user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java
M user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java
Index: user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java
===================================================================
--- user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java
(revision 9880)
+++ user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java
(working copy)
@@ -74,10 +74,14 @@
* <dd>This context corresponds to a parameter that appears at the very
start of
* a URL-valued HTML attribute's value; in the above example this applies
to
* parameter #1.
+ * <dt>{@link HtmlContext.Type#CSS_ATTRIBUTE_START}
+ * <dd>This context corresponds to a parameter that appears at the very
+ * beginning of a {@code style} attribute's value; in the above example
this
+ * applies to parameter #0.
* <dt>{@link HtmlContext.Type#CSS_ATTRIBUTE}
* <dd>This context corresponds to a parameter that appears in the context
of a
- * {@code style} attribute; in the above example this applies to
- * parameter #0.
+ * {@code style} attribute, except at the very beginning of the attribute's
+ * value.
* <dt>{@link HtmlContext.Type#ATTRIBUTE_VALUE}
* <dd>This context corresponds to a parameter that appears within an
attribute
* and is not in one of the more specific in-attribute contexts above. In
@@ -250,7 +254,11 @@
if (streamHtmlParser.isUrlStart()) {
return new HtmlContext(HtmlContext.Type.URL_START, tag, attribute);
} else if (streamHtmlParser.inCss()) {
- return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE, tag,
attribute);
+ if (streamHtmlParser.getValueIndex() == 0) {
+ return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE_START,
tag, attribute);
+ } else {
+ return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE, tag,
attribute);
+ }
} else {
return new HtmlContext(
HtmlContext.Type.ATTRIBUTE_VALUE, tag, attribute);
Index: user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java
===================================================================
--- user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java
(revision 9880)
+++ user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java
(working copy)
@@ -64,7 +64,11 @@
/**
* CSS (style) attribute context.
*/
- CSS_ATTRIBUTE
+ CSS_ATTRIBUTE,
+ /**
+ * At the very start of a CSS (style) attribute context.
+ */
+ CSS_ATTRIBUTE_START
}
private final Type type;
Index: user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java
===================================================================
--- user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java
(revision 9880)
+++ user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java
(working copy)
@@ -134,9 +134,14 @@
// Test correct detection of CSS context.
assertParseTemplateResult(
"[L(<div class=\"), P((ATTRIBUTE_VALUE,div,class),0), L(\"
style=\"), "
+ + "P((CSS_ATTRIBUTE_START,div,style),2), L(\">Hello ), "
+ + "P((TEXT,null,null),1)]",
+ "<div class=\"{0}\" style=\"{2}\">Hello {1}");
+ assertParseTemplateResult(
+ "[L(<div class=\"), P((ATTRIBUTE_VALUE,div,class),0), L(\"
style=\"color:green; ), "
+ "P((CSS_ATTRIBUTE,div,style),2), L(\">Hello ), "
+ "P((TEXT,null,null),1)]",
- "<div class=\"{0}\" style=\"{2}\">Hello {1}");
+ "<div class=\"{0}\" style=\"color:green; {2}\">Hello {1}");
assertParseTemplateResult(
"[L(<div>), P((TEXT,null,null),0), L(<style>foo ), "
+ "P((CSS,null,null),1), L(</style>)]",
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors