Revision: 8667
Author: [email protected]
Date: Mon Aug 30 02:46:06 2010
Log: Introducing a new interface, HasDirectionalText
Review at http://gwt-code-reviews.appspot.com/738803
http://code.google.com/p/google-web-toolkit/source/detail?r=8667
Added:
/trunk/user/src/com/google/gwt/user/client/ui/HasDirectionalHtml.java
/trunk/user/src/com/google/gwt/user/client/ui/HasDirectionalText.java
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/HTML.java
/trunk/user/src/com/google/gwt/user/client/ui/Label.java
/trunk/user/test/com/google/gwt/user/client/ui/HTMLTest.java
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/client/ui/HasDirectionalHtml.java
Mon Aug 30 02:46:06 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.user.client.ui;
+
+import com.google.gwt.i18n.client.HasDirection.Direction;
+
+/**
+ * An object that implements this interface contains html that has a
direction.
+ */
+public interface HasDirectionalHtml extends HasDirectionalText, HasHTML {
+ /**
+ * Sets this object's html, also declaring its direction.
+ *
+ * @param html the object's new html
+ * @param dir the html's direction
+ */
+ void setHTML(String html, Direction dir);
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/client/ui/HasDirectionalText.java
Mon Aug 30 02:46:06 2010
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.user.client.ui;
+
+import com.google.gwt.i18n.client.HasDirection.Direction;
+
+/**
+ * An object that implements this interface contains text that has a
direction.
+ */
+public interface HasDirectionalText extends HasText {
+
+ /**
+ * Gets the direction of this object's text.
+ *
+ * @return the direction of this object's text
+ */
+ Direction getTextDirection();
+
+ /**
+ * Sets this object's text, also declaring its direction.
+ *
+ * @param text the object's new text
+ * @param dir the text's direction
+ */
+ void setText(String text, Direction dir);
+}
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/HTML.java Mon Aug 2
09:47:24 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/HTML.java Mon Aug 30
02:46:06 2010
@@ -42,7 +42,7 @@
* {...@example com.google.gwt.examples.HTMLExample}
* </p>
*/
-public class HTML extends Label implements HasHTML {
+public class HTML extends Label implements HasDirectionalHtml {
/**
* Creates an HTML widget that wraps an existing <div> or
<span>
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Label.java Fri Aug 13
16:13:23 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/Label.java Mon Aug 30
02:46:06 2010
@@ -61,8 +61,8 @@
* </p>
*/
@SuppressWarnings("deprecation")
-public class Label extends Widget implements HasText, HasWordWrap,
HasDirection,
- HasClickHandlers, HasDoubleClickHandlers, SourcesClickEvents,
+public class Label extends Widget implements HasDirectionalText,
HasWordWrap,
+ HasDirection, HasClickHandlers, HasDoubleClickHandlers,
SourcesClickEvents,
SourcesMouseEvents, HasAllMouseHandlers, HasDirectionEstimator,
HasAutoHorizontalAlignment {
@@ -101,7 +101,7 @@
* ({...@code getElement()}).
* See {...@link #setTextOrHtml(String, Direction, boolean)} for details.
*/
- private Direction contentDir;
+ private Direction textDir;
/**
* The widget's DirectionEstimator object.
@@ -150,7 +150,7 @@
setStyleName("gwt-Label");
isElementInline = false;
isSpanWrapped = false;
- contentDir = Direction.DEFAULT;
+ textDir = Direction.DEFAULT;
initialElementDir = Direction.DEFAULT;
}
@@ -200,7 +200,7 @@
assert isElementInline || tagName.equalsIgnoreCase("div");
isSpanWrapped = false;
initialElementDir = BidiUtils.getDirectionOnElement(element);
- contentDir = initialElementDir;
+ textDir = initialElementDir;
}
public HandlerRegistration addClickHandler(ClickHandler handler) {
@@ -267,14 +267,10 @@
public AutoHorizontalAlignmentConstant getAutoHorizontalAlignment() {
return autoHorizontalAlignment;
}
-
- public Direction getContentDirection() {
- return contentDir;
- }
/**
* Gets the widget element's direction.
- * @deprecated Use {...@link #getContentDirection} instead
+ * @deprecated Use {...@link #getTextDirection} instead
*/
@Deprecated
public Direction getDirection() {
@@ -295,6 +291,10 @@
public String getText() {
return getTextOrHtml(false);
}
+
+ public Direction getTextDirection() {
+ return textDir;
+ }
public boolean getWordWrap() {
return !getElement().getStyle().getProperty("whiteSpace").equals("nowrap");
@@ -350,7 +350,7 @@
// content direction.
setInnerTextOrHtml(getTextOrHtml(true), true);
isSpanWrapped = false;
- contentDir = initialElementDir;
+ textDir = initialElementDir;
updateHorizontalAlignment();
}
@@ -456,8 +456,8 @@
// Preserves the initial direction of the widget. This is different
from
// passing the direction parameter explicitly as DEFAULT, which
forces the
// widget to inherit the direction from its parent.
- if (contentDir != initialElementDir) {
- contentDir = initialElementDir;
+ if (textDir != initialElementDir) {
+ textDir = initialElementDir;
BidiUtils.setDirectionOnElement(getElement(), initialElementDir);
updateHorizontalAlignment();
}
@@ -491,7 +491,7 @@
* @param isHtml whether the content is HTML
*/
protected void setTextOrHtml(String content, Direction dir, boolean
isHtml) {
- contentDir = dir;
+ textDir = dir;
// Set the text and the direction.
if (isElementInline) {
@@ -530,8 +530,8 @@
/* autoHorizontalAlignment is a truly automatic policy, i.e. either
ALIGN_CONTENT_START or ALIGN_CONTENT_END */
align = autoHorizontalAlignment == ALIGN_CONTENT_START ?
- HorizontalAlignmentConstant.startOf(contentDir) :
- HorizontalAlignmentConstant.endOf(contentDir);
+ HorizontalAlignmentConstant.startOf(textDir) :
+ HorizontalAlignmentConstant.endOf(textDir);
}
if (align != horzAlign) {
@@ -541,3 +541,4 @@
}
}
}
+
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/HTMLTest.java Mon Aug 2
14:09:21 2010
+++ /trunk/user/test/com/google/gwt/user/client/ui/HTMLTest.java Mon Aug 30
02:46:06 2010
@@ -73,8 +73,8 @@
}
/**
- * Asserts that both the {...@link Label#getContentDirection} and the
physical
- * dir attribute match the expected direction.
+ * Asserts that both the {...@link Label#getTextDirection} and the physical
dir
+ * attribute match the expected direction.
*
* @param message Assertion message
* @param expected Expected direction
@@ -87,8 +87,8 @@
isSpanWrapped() && getLabelDirection() == Direction.DEFAULT &&
expected == Direction.LTR
&& !LocaleInfo.getCurrentLocale().isRTL());
- assertEquals("contentDir mismatch: " + message, expected,
- label.getContentDirection());
+ assertEquals("textDir mismatch: " + message, expected,
+ label.getTextDirection());
}
private Direction getLabelDirection() {
@@ -167,3 +167,4 @@
}
}
}
+
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors