Complete text-* support for Style
Reposting of 1736803
Thanks Patrick!
Review at http://gwt-code-reviews.appspot.com/1737804
Review by: rdayal@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11033 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/dom/builder/client/DomStylesBuilder.java b/user/src/com/google/gwt/dom/builder/client/DomStylesBuilder.java
index f5aae1e..8bbf729 100644
--- a/user/src/com/google/gwt/dom/builder/client/DomStylesBuilder.java
+++ b/user/src/com/google/gwt/dom/builder/client/DomStylesBuilder.java
@@ -28,7 +28,11 @@
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.TableLayout;
+import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.dom.client.Style.Visibility;
@@ -350,12 +354,42 @@
}
@Override
+ public StylesBuilder textAlign(TextAlign value) {
+ delegate.assertCanAddStyleProperty().setTextAlign(value);
+ return this;
+ }
+
+ @Override
public StylesBuilder textDecoration(TextDecoration value) {
delegate.assertCanAddStyleProperty().setTextDecoration(value);
return this;
}
@Override
+ public StylesBuilder textIndent(double value, Unit unit) {
+ delegate.assertCanAddStyleProperty().setTextIndent(value, unit);
+ return this;
+ }
+
+ @Override
+ public StylesBuilder textJustify(TextJustify value) {
+ delegate.assertCanAddStyleProperty().setTextJustify(value);
+ return this;
+ }
+
+ @Override
+ public StylesBuilder textOverflow(TextOverflow value) {
+ delegate.assertCanAddStyleProperty().setTextOverflow(value);
+ return this;
+ }
+
+ @Override
+ public StylesBuilder textTransform(TextTransform value) {
+ delegate.assertCanAddStyleProperty().setTextTransform(value);
+ return this;
+ }
+
+ @Override
public StylesBuilder top(double value, Unit unit) {
delegate.assertCanAddStyleProperty().setTop(value, unit);
return this;
diff --git a/user/src/com/google/gwt/dom/builder/shared/HtmlStylesBuilder.java b/user/src/com/google/gwt/dom/builder/shared/HtmlStylesBuilder.java
index 678a300..2c12769 100644
--- a/user/src/com/google/gwt/dom/builder/shared/HtmlStylesBuilder.java
+++ b/user/src/com/google/gwt/dom/builder/shared/HtmlStylesBuilder.java
@@ -28,7 +28,11 @@
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.TableLayout;
+import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.dom.client.Style.Visibility;
@@ -364,11 +368,36 @@
}
@Override
+ public StylesBuilder textAlign(TextAlign value) {
+ return delegate.styleProperty(SafeStylesUtils.forTextAlign(value));
+ }
+
+ @Override
public StylesBuilder textDecoration(TextDecoration value) {
return delegate.styleProperty(SafeStylesUtils.forTextDecoration(value));
}
@Override
+ public StylesBuilder textIndent(double value, Unit unit) {
+ return delegate.styleProperty(SafeStylesUtils.forTextIndent(value, unit));
+ }
+
+ @Override
+ public StylesBuilder textJustify(TextJustify value) {
+ return delegate.styleProperty(SafeStylesUtils.forTextJustify(value));
+ }
+
+ @Override
+ public StylesBuilder textOverflow(TextOverflow value) {
+ return delegate.styleProperty(SafeStylesUtils.forTextOverflow(value));
+ }
+
+ @Override
+ public StylesBuilder textTransform(TextTransform value) {
+ return delegate.styleProperty(SafeStylesUtils.forTextTransform(value));
+ }
+
+ @Override
public StylesBuilder top(double value, Unit unit) {
return delegate.styleProperty(SafeStylesUtils.forTop(value, unit));
}
diff --git a/user/src/com/google/gwt/dom/builder/shared/StylesBuilder.java b/user/src/com/google/gwt/dom/builder/shared/StylesBuilder.java
index e265005..7f63003 100644
--- a/user/src/com/google/gwt/dom/builder/shared/StylesBuilder.java
+++ b/user/src/com/google/gwt/dom/builder/shared/StylesBuilder.java
@@ -26,7 +26,11 @@
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.TableLayout;
+import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.dom.client.Style.Visibility;
@@ -220,11 +224,36 @@
StylesBuilder tableLayout(TableLayout value);
/**
- * Sets the text-decoration CSS property.
+ * Set the text-align CSS property.
+ */
+ StylesBuilder textAlign(TextAlign value);
+
+ /**
+ * Set the text-decoration CSS property.
*/
StylesBuilder textDecoration(TextDecoration value);
/**
+ * Set the text-indent CSS property.
+ */
+ StylesBuilder textIndent(double value, Unit unit);
+
+ /**
+ * Set the text-justify CSS3 property.
+ */
+ StylesBuilder textJustify(TextJustify value);
+
+ /**
+ * Set the text-overflow CSS3 property.
+ */
+ StylesBuilder textOverflow(TextOverflow value);
+
+ /**
+ * Set the text-transform CSS property.
+ */
+ StylesBuilder textTransform(TextTransform value);
+
+ /**
* Set the top css property.
*/
StylesBuilder top(double value, Unit unit);
diff --git a/user/src/com/google/gwt/dom/client/Style.java b/user/src/com/google/gwt/dom/client/Style.java
index b936a9d..29cbc81 100644
--- a/user/src/com/google/gwt/dom/client/Style.java
+++ b/user/src/com/google/gwt/dom/client/Style.java
@@ -638,31 +638,141 @@
}
/**
- * Enum for the text-decoration property.
+ * Enum for the 'text-decoration' CSS property.
*/
public enum TextDecoration implements HasCssName {
+ BLINK {
+ @Override
+ public String getCssName() {
+ return TEXT_DECORATION_BLINK;
+ }
+ },
+ LINE_THROUGH {
+ @Override
+ public String getCssName() {
+ return TEXT_DECORATION_LINE_THROUGH;
+ }
+ },
NONE {
@Override
public String getCssName() {
return TEXT_DECORATION_NONE;
}
},
- UNDERLINE {
- @Override
- public String getCssName() {
- return TEXT_DECORATION_UNDERLINE;
- }
- },
OVERLINE {
@Override
public String getCssName() {
return TEXT_DECORATION_OVERLINE;
}
},
- LINE_THROUGH {
+ UNDERLINE {
@Override
public String getCssName() {
- return TEXT_DECORATION_LINE_THROUGH;
+ return TEXT_DECORATION_UNDERLINE;
+ }
+ };
+ @Override
+ public abstract String getCssName();
+ }
+
+
+
+ /**
+ * Enum for the 'text-justify' CSS3 property.
+ */
+ public enum TextJustify implements HasCssName {
+ AUTO {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_AUTO;
+ }
+ },
+ DISTRIBUTE {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_DISTRIBUTE;
+ }
+ },
+ INTER_CLUSTER {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_INTER_CLUSTER;
+ }
+ },
+ INTER_IDEOGRAPH {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_INTER_IDEOGRAPH;
+ }
+ },
+ INTER_WORD {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_INTER_WORD;
+ }
+ },
+ KASHIDA {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_KASHIDA;
+ }
+ },
+ NONE {
+ @Override
+ public String getCssName() {
+ return TEXT_JUSTIFY_NONE;
+ }
+ };
+ @Override
+ public abstract String getCssName();
+ }
+
+ /**
+ * Enum for the 'text-overflow' CSS3 property.
+ */
+ public enum TextOverflow implements HasCssName {
+ CLIP {
+ @Override
+ public String getCssName() {
+ return TEXT_OVERFLOW_CLIP;
+ }
+ },
+ ELLIPSIS {
+ @Override
+ public String getCssName() {
+ return TEXT_OVERFLOW_ELLIPSIS;
+ }
+ };
+ @Override
+ public abstract String getCssName();
+ }
+
+ /**
+ * Enum for the 'text-transform' CSS property.
+ */
+ public enum TextTransform implements HasCssName {
+ CAPITALIZE {
+ @Override
+ public String getCssName() {
+ return TEXT_TRANSFORM_CAPITALIZE;
+ }
+ },
+ NONE {
+ @Override
+ public String getCssName() {
+ return TEXT_TRANSFORM_NONE;
+ }
+ },
+ LOWERCASE {
+ @Override
+ public String getCssName() {
+ return TEXT_TRANSFORM_LOWERCASE;
+ }
+ },
+ UPPERCASE {
+ @Override
+ public String getCssName() {
+ return TEXT_TRANSFORM_UPPERCASE;
}
};
@Override
@@ -901,6 +1011,10 @@
private static final String STYLE_VERTICAL_ALIGN = "verticalAlign";
private static final String STYLE_TABLE_LAYOUT = "tableLayout";
private static final String STYLE_TEXT_ALIGN = "textAlign";
+ private static final String STYLE_TEXT_INDENT = "textIndent";
+ private static final String STYLE_TEXT_JUSTIFY = "textJustify";
+ private static final String STYLE_TEXT_OVERFLOW = "textOverflow";
+ private static final String STYLE_TEXT_TRANSFORM = "textTransform";
private static final String STYLE_OUTLINE_WIDTH = "outlineWidth";
private static final String STYLE_OUTLINE_STYLE = "outlineStyle";
private static final String STYLE_OUTLINE_COLOR = "outlineColor";
@@ -915,10 +1029,27 @@
private static final String TEXT_ALIGN_LEFT = "left";
private static final String TEXT_ALIGN_RIGHT = "right";
+ private static final String TEXT_DECORATION_BLINK = "blink";
private static final String TEXT_DECORATION_LINE_THROUGH = "line-through";
+ private static final String TEXT_DECORATION_NONE = "none";
private static final String TEXT_DECORATION_OVERLINE = "overline";
private static final String TEXT_DECORATION_UNDERLINE = "underline";
- private static final String TEXT_DECORATION_NONE = "none";
+
+ private static final String TEXT_JUSTIFY_AUTO = "auto";
+ private static final String TEXT_JUSTIFY_DISTRIBUTE = "distribute";
+ private static final String TEXT_JUSTIFY_INTER_CLUSTER = "inter-cluster";
+ private static final String TEXT_JUSTIFY_INTER_IDEOGRAPH = "inter-ideograph";
+ private static final String TEXT_JUSTIFY_INTER_WORD = "inter-word";
+ private static final String TEXT_JUSTIFY_KASHIDA = "kashida";
+ private static final String TEXT_JUSTIFY_NONE = "none";
+
+ private static final String TEXT_OVERFLOW_CLIP = "clip";
+ private static final String TEXT_OVERFLOW_ELLIPSIS = "ellipsis";
+
+ private static final String TEXT_TRANSFORM_CAPITALIZE = "capitalize";
+ private static final String TEXT_TRANSFORM_NONE = "none";
+ private static final String TEXT_TRANSFORM_LOWERCASE = "lowercase";
+ private static final String TEXT_TRANSFORM_UPPERCASE = "uppercase";
private static final String UNIT_MM = "mm";
private static final String UNIT_CM = "cm";
@@ -1237,6 +1368,34 @@
public final void clearTextDecoration() {
clearProperty(STYLE_TEXT_DECORATION);
}
+
+ /**
+ * Clear the 'text-indent' CSS property.
+ */
+ public final void clearTextIndent() {
+ clearProperty(STYLE_TEXT_INDENT);
+ }
+
+ /**
+ * Clear the 'text-justify' CSS3 property.
+ */
+ public final void clearTextJustify() {
+ clearProperty(STYLE_TEXT_JUSTIFY);
+ }
+
+ /**
+ * Clear the 'text-overflow' CSS3 property.
+ */
+ public final void clearTextOverflow() {
+ clearProperty(STYLE_TEXT_OVERFLOW);
+ }
+
+ /**
+ * Clear the 'text-transform' CSS property.
+ */
+ public final void clearTextTransform() {
+ clearProperty(STYLE_TEXT_TRANSFORM);
+ }
/**
* Clear the top css property.
@@ -1532,6 +1691,34 @@
public final String getTextDecoration() {
return getProperty(STYLE_TEXT_DECORATION);
}
+
+ /**
+ * Get the 'text-indent' CSS property.
+ */
+ public final String getTextIndent() {
+ return getProperty(STYLE_TEXT_INDENT);
+ }
+
+ /**
+ * Get the 'text-justify' CSS3 property.
+ */
+ public final String getTextJustify() {
+ return getProperty(STYLE_TEXT_JUSTIFY);
+ }
+
+ /**
+ * Get the 'text-overflow' CSS3 property.
+ */
+ public final String getTextOverflow() {
+ return getProperty(STYLE_TEXT_OVERFLOW);
+ }
+
+ /**
+ * Get the 'text-transform' CSS property.
+ */
+ public final String getTextTransform() {
+ return getProperty(STYLE_TEXT_TRANSFORM);
+ }
/**
* Get the top css property.
@@ -1879,6 +2066,34 @@
public final void setTextDecoration(TextDecoration value) {
setProperty(STYLE_TEXT_DECORATION, value.getCssName());
}
+
+ /**
+ * Set the 'text-indent' CSS property.
+ */
+ public final void setTextIndent(double value, Unit unit) {
+ setProperty(STYLE_TEXT_INDENT, value, unit);
+ }
+
+ /**
+ * Set the 'text-justify' CSS3 property.
+ */
+ public final void setTextJustify(TextJustify value) {
+ setProperty(STYLE_TEXT_JUSTIFY, value.getCssName());
+ }
+
+ /**
+ * Set the 'text-overflow' CSS3 property.
+ */
+ public final void setTextOverflow(TextOverflow value) {
+ setProperty(STYLE_TEXT_OVERFLOW, value.getCssName());
+ }
+
+ /**
+ * Set the 'text-transform' CSS property.
+ */
+ public final void setTextTransform(TextTransform value) {
+ setProperty(STYLE_TEXT_TRANSFORM, value.getCssName());
+ }
/**
* Set the top css property.
diff --git a/user/src/com/google/gwt/safecss/shared/SafeStylesBuilder.java b/user/src/com/google/gwt/safecss/shared/SafeStylesBuilder.java
index 40fb551..5c3f41b 100644
--- a/user/src/com/google/gwt/safecss/shared/SafeStylesBuilder.java
+++ b/user/src/com/google/gwt/safecss/shared/SafeStylesBuilder.java
@@ -28,6 +28,9 @@
import com.google.gwt.dom.client.Style.TableLayout;
import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.dom.client.Style.Visibility;
@@ -359,6 +362,34 @@
}
/**
+ * Append the 'text-indent' CSS property.
+ */
+ public SafeStylesBuilder textIndent(double value, Unit unit) {
+ return append(SafeStylesUtils.forTextIndent(value, unit));
+ }
+
+ /**
+ * Append the 'text-justify' CSS3 property.
+ */
+ public SafeStylesBuilder textJustify(TextJustify value) {
+ return append(SafeStylesUtils.forTextJustify(value));
+ }
+
+ /**
+ * Append the 'text-overflow' CSS3 property.
+ */
+ public SafeStylesBuilder textOverflow(TextOverflow value) {
+ return append(SafeStylesUtils.forTextOverflow(value));
+ }
+
+ /**
+ * Append the 'text-transform' CSS property.
+ */
+ public SafeStylesBuilder textTransform(TextTransform value) {
+ return append(SafeStylesUtils.forTextTransform(value));
+ }
+
+ /**
* Append the top css property.
*/
public SafeStylesBuilder top(double value, Unit unit) {
diff --git a/user/src/com/google/gwt/safecss/shared/SafeStylesUtils.java b/user/src/com/google/gwt/safecss/shared/SafeStylesUtils.java
index 11ef99b..652fb48 100644
--- a/user/src/com/google/gwt/safecss/shared/SafeStylesUtils.java
+++ b/user/src/com/google/gwt/safecss/shared/SafeStylesUtils.java
@@ -30,6 +30,9 @@
import com.google.gwt.dom.client.Style.TableLayout;
import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.dom.client.Style.Visibility;
@@ -334,13 +337,41 @@
}
/**
- * Sets the text-decoration CSS property.
+ * Sets the 'text-decoration' CSS property.
*/
public static SafeStyles forTextDecoration(TextDecoration value) {
return fromTrustedNameAndValue("text-decoration", value.getCssName());
}
/**
+ * Set the 'text-indent' CSS property.
+ */
+ public static SafeStyles forTextIndent(double value, Unit unit) {
+ return fromTrustedNameAndValue("text-indent", value + unit.getType());
+ }
+
+ /**
+ * Set the 'text-justify' CSS3 property.
+ */
+ public static SafeStyles forTextJustify(TextJustify value) {
+ return fromTrustedNameAndValue("text-justify", value.getCssName());
+ }
+
+ /**
+ * Set the 'text-overflow' CSS3 property.
+ */
+ public static SafeStyles forTextOverflow(TextOverflow value) {
+ return fromTrustedNameAndValue("text-overflow", value.getCssName());
+ }
+
+ /**
+ * Set the 'text-transform' CSS property.
+ */
+ public static SafeStyles forTextTransform(TextTransform value) {
+ return fromTrustedNameAndValue("text-transform", value.getCssName());
+ }
+
+ /**
* Set the top css property.
*/
public static SafeStyles forTop(double value, Unit unit) {
diff --git a/user/test/com/google/gwt/dom/client/StyleTest.java b/user/test/com/google/gwt/dom/client/StyleTest.java
index 3f2007d..33dfb21 100644
--- a/user/test/com/google/gwt/dom/client/StyleTest.java
+++ b/user/test/com/google/gwt/dom/client/StyleTest.java
@@ -37,6 +37,9 @@
import com.google.gwt.dom.client.Style.TableLayout;
import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.dom.client.Style.WhiteSpace;
@@ -277,6 +280,8 @@
DivElement div = Document.get().createDivElement();
Style style = div.getStyle();
+ style.setTextDecoration(TextDecoration.BLINK);
+ assertEquals(TextDecoration.BLINK, style.getTextDecoration());
style.setTextDecoration(TextDecoration.NONE);
assertEquals(TextDecoration.NONE, style.getTextDecoration());
style.setTextDecoration(TextDecoration.UNDERLINE);
@@ -287,6 +292,68 @@
assertEquals(TextDecoration.LINE_THROUGH, style.getTextDecoration());
}
+ public void testTextIndent() {
+ DivElement div = Document.get().createDivElement();
+ Style style = div.getStyle();
+
+ style.setTextIndent(1, PX);
+ assertEquals("1px", style.getTextIndent());
+ style.setTextIndent(1, PCT);
+ assertEquals("1%", style.getTextIndent());
+ style.clearTextIndent();
+ assertEmpty(style.getTextIndent());
+ }
+
+ public void testTextJustify() {
+ DivElement div = Document.get().createDivElement();
+ Style style = div.getStyle();
+
+ style.setTextJustify(TextJustify.AUTO);
+ assertEquals(TextJustify.AUTO, style.getTextOverflow());
+ style.setTextJustify(TextJustify.DISTRIBUTE);
+ assertEquals(TextJustify.DISTRIBUTE, style.getTextOverflow());
+ style.setTextJustify(TextJustify.INTER_CLUSTER);
+ assertEquals(TextJustify.INTER_CLUSTER, style.getTextOverflow());
+ style.setTextJustify(TextJustify.INTER_IDEOGRAPH);
+ assertEquals(TextJustify.INTER_IDEOGRAPH, style.getTextOverflow());
+ style.setTextJustify(TextJustify.INTER_WORD);
+ assertEquals(TextJustify.INTER_WORD, style.getTextOverflow());
+ style.setTextJustify(TextJustify.KASHIDA);
+ assertEquals(TextJustify.KASHIDA, style.getTextOverflow());
+ style.setTextJustify(TextJustify.NONE);
+ assertEquals(TextJustify.NONE, style.getTextOverflow());
+ style.clearTextJustify();
+ assertEmpty(style.getTextJustify());
+ }
+
+ public void testTextOverflow() {
+ DivElement div = Document.get().createDivElement();
+ Style style = div.getStyle();
+
+ style.setTextOverflow(TextOverflow.CLIP);
+ assertEquals(TextOverflow.CLIP, style.getTextOverflow());
+ style.setTextOverflow(TextOverflow.ELLIPSIS);
+ assertEquals(TextOverflow.ELLIPSIS, style.getTextOverflow());
+ style.clearTextOverflow();
+ assertEmpty(style.getTextOverflow());
+ }
+
+ public void testTextTransform() {
+ DivElement div = Document.get().createDivElement();
+ Style style = div.getStyle();
+
+ style.setTextTransform(TextTransform.CAPITALIZE);
+ assertEquals(TextTransform.CAPITALIZE, style.getTextTransform());
+ style.setTextTransform(TextTransform.LOWERCASE);
+ assertEquals(TextTransform.LOWERCASE, style.getTextTransform());
+ style.setTextTransform(TextTransform.NONE);
+ assertEquals(TextTransform.NONE, style.getTextTransform());
+ style.setTextTransform(TextTransform.UPPERCASE);
+ assertEquals(TextTransform.UPPERCASE, style.getTextTransform());
+ style.clearTextTransform();
+ assertEmpty(style.getTextTransform());
+ }
+
public void testVerticalAlign() {
DivElement div = Document.get().createDivElement();
Style style = div.getStyle();
diff --git a/user/test/com/google/gwt/safecss/shared/GwtSafeStylesUtilsTest.java b/user/test/com/google/gwt/safecss/shared/GwtSafeStylesUtilsTest.java
index ffc7d63..569cd78 100644
--- a/user/test/com/google/gwt/safecss/shared/GwtSafeStylesUtilsTest.java
+++ b/user/test/com/google/gwt/safecss/shared/GwtSafeStylesUtilsTest.java
@@ -19,6 +19,10 @@
import com.google.gwt.dom.client.Style.Clear;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.TextAlign;
+import com.google.gwt.dom.client.Style.TextDecoration;
+import com.google.gwt.dom.client.Style.TextJustify;
+import com.google.gwt.dom.client.Style.TextOverflow;
+import com.google.gwt.dom.client.Style.TextTransform;
import com.google.gwt.dom.client.Style.WhiteSpace;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.safehtml.shared.SafeUri;
@@ -102,10 +106,40 @@
}
public void testForTextAlign() {
- assertEquals("text-align:center;", SafeStylesUtils.forTextAlign(TextAlign.CENTER).asString());
- assertEquals("text-align:justify;", SafeStylesUtils.forTextAlign(TextAlign.JUSTIFY).asString());
- assertEquals("text-align:left;", SafeStylesUtils.forTextAlign(TextAlign.LEFT).asString());
- assertEquals("text-align:right;", SafeStylesUtils.forTextAlign(TextAlign.RIGHT).asString());
+ assertEquals("text-align:center;", SafeStylesUtils.forTextAlign(TextAlign.CENTER));
+ assertEquals("text-align:justify;", SafeStylesUtils.forTextAlign(TextAlign.JUSTIFY));
+ assertEquals("text-align:left;", SafeStylesUtils.forTextAlign(TextAlign.LEFT));
+ assertEquals("text-align:right;", SafeStylesUtils.forTextAlign(TextAlign.RIGHT));
+ }
+
+ public void testForTextDecoration() {
+ assertEquals("text-decoration:blink;", SafeStylesUtils.forTextDecoration(TextDecoration.BLINK));
+ assertEquals("text-decoration:line-through;", SafeStylesUtils.forTextDecoration(TextDecoration.LINE_THROUGH));
+ assertEquals("text-decoration:none;", SafeStylesUtils.forTextDecoration(TextDecoration.NONE));
+ assertEquals("text-decoration:overline;", SafeStylesUtils.forTextDecoration(TextDecoration.OVERLINE));
+ assertEquals("text-decoration:underline;", SafeStylesUtils.forTextDecoration(TextDecoration.UNDERLINE));
+ }
+
+ public void testForTextJustify() {
+ assertEquals("text-justify:auto;", SafeStylesUtils.forTextJustify(TextJustify.AUTO));
+ assertEquals("text-justify:distribute;", SafeStylesUtils.forTextJustify(TextJustify.DISTRIBUTE));
+ assertEquals("text-justify:inter-cluster;", SafeStylesUtils.forTextJustify(TextJustify.INTER_CLUSTER));
+ assertEquals("text-justify:inter-ideograph;", SafeStylesUtils.forTextJustify(TextJustify.INTER_IDEOGRAPH));
+ assertEquals("text-justify:inter-word;", SafeStylesUtils.forTextJustify(TextJustify.INTER_WORD));
+ assertEquals("text-justify:kashida;", SafeStylesUtils.forTextJustify(TextJustify.KASHIDA));
+ assertEquals("text-justify:none;", SafeStylesUtils.forTextJustify(TextJustify.NONE));
+ }
+
+ public void testForTextOverflow() {
+ assertEquals("text-overflow:clip;", SafeStylesUtils.forTextOverflow(TextOverflow.CLIP));
+ assertEquals("text-overflow:ellipsis;", SafeStylesUtils.forTextOverflow(TextOverflow.ELLIPSIS));
+ }
+
+ public void testForTextTransform() {
+ assertEquals("text-transform:capitalize;", SafeStylesUtils.forTextTransform(TextTransform.CAPITALIZE));
+ assertEquals("text-transform:lowercase;", SafeStylesUtils.forTextTransform(TextTransform.LOWERCASE));
+ assertEquals("text-transform:none;", SafeStylesUtils.forTextTransform(TextTransform.NONE));
+ assertEquals("text-transform:uppercase;", SafeStylesUtils.forTextTransform(TextTransform.UPPERCASE));
}
public void testForWhiteSpace() {
@@ -196,7 +230,7 @@
for (String s : VALID_STYLE_NAMES) {
try {
SafeStyles styles = SafeStylesUtils.fromTrustedNameAndValue(s, "value");
- assertEquals(s + ":value;", styles.asString());
+ assertEquals(s + ":value;", styles);
} catch (Exception e) {
fail("Unexpected exception thrown for valid style name: '" + s + "'.\n" + e.getMessage());
}
@@ -212,7 +246,7 @@
for (String s : VALID_STYLE_VALUES) {
try {
SafeStyles styles = SafeStylesUtils.fromTrustedNameAndValue("name", s);
- assertEquals("name" + ":" + s + ";", styles.asString());
+ assertEquals("name" + ":" + s + ";", styles);
} catch (Exception e) {
fail("Unexpected exception thrown for valid style value: '" + s + "'.\n" + e.getMessage());
}
@@ -220,6 +254,10 @@
}
public void testFromTrustedString() {
- assertEquals("name:value;", SafeStylesUtils.fromTrustedString("name:value;").asString());
+ assertEquals("name:value;", SafeStylesUtils.fromTrustedString("name:value;"));
+ }
+
+ private void assertEquals(String cssValue, SafeStyles safeStyles) {
+ assertEquals(cssValue, safeStyles.asString());
}
}