Revision: 7528
Author: [email protected]
Date: Thu Feb 4 04:42:51 2010
Log: Fixes RichTextArea.isEnabled/setEnabled functionality so that it
actually enables/disables the text area.
Patch by: manolo.carrasco
Review by: jlabanca
Issue: 1488
http://code.google.com/p/google-web-toolkit/source/detail?r=7528
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/RichTextArea.java
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
/trunk/user/test/com/google/gwt/user/client/ui/RichTextAreaTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/RichTextArea.java Tue Jan
26 10:25:12 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/RichTextArea.java Thu
Feb 4 04:42:51 2010
@@ -633,6 +633,16 @@
public String getText() {
return impl.getText();
}
+
+ @Override
+ public boolean isEnabled() {
+ return impl.isEnabled();
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ impl.setEnabled(enabled);
+ }
@Override
public void setFocus(boolean focused) {
=======================================
---
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java
Wed Sep 16 10:40:29 2009
+++
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java
Thu Feb 4 04:42:51 2010
@@ -53,6 +53,14 @@
public void initElement() {
onElementInitialized();
}
+
+ public boolean isEnabled() {
+ return !elem.getPropertyBoolean("disabled");
+ }
+
+ public void setEnabled(boolean enabled) {
+ elem.setPropertyBoolean("disabled", !enabled);
+ }
public native void setFocus(boolean focused) /*-{
if (focused) {
=======================================
---
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java
Fri Oct 16 14:48:33 2009
+++
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java
Thu Feb 4 04:42:51 2010
@@ -114,6 +114,18 @@
elem.contentWindow.onblur = handler;
}-*/;
+ @Override
+ protected native boolean isEnabledImpl() /*-{
+ var elem =
[email protected]::elem;
+ return elem.contentWindow.document.body.contentEditable.toLowerCase()
== 'true';
+ }-*/;
+
+ @Override
+ protected native void setEnabledImpl(boolean enabled) /*-{
+ var elem =
[email protected]::elem;
+ elem.contentWindow.document.body.contentEditable = enabled;
+ }-*/;
+
@Override
protected native void setTextImpl(String text) /*-{
var elem =
[email protected]::elem;
=======================================
---
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
Fri Oct 16 14:48:33 2009
+++
/trunk/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
Thu Feb 4 04:42:51 2010
@@ -38,8 +38,9 @@
"cannot be used until the RichTextArea is attached and focused.";
/**
- * Holds a cached copy of any user setHTML/setText actions until the real
- * text area is fully initialized. Becomes <code>null</code> after init.
+ * Holds a cached copy of any user setHTML/setText/setEnabled actions
until
+ * the real text area is fully initialized. Becomes <code>null</code>
after
+ * init.
*/
private Element beforeInitPlaceholder = DOM.createDiv();
@@ -122,6 +123,12 @@
public boolean isBold() {
return queryCommandState("Bold");
}
+
+ @Override
+ public boolean isEnabled() {
+ return beforeInitPlaceholder == null ? isEnabledImpl()
+ : !beforeInitPlaceholder.getPropertyBoolean("disabled");
+ }
public boolean isItalic() {
return queryCommandState("Italic");
@@ -170,6 +177,15 @@
public void setBackColor(String color) {
execCommand("BackColor", color);
}
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ if (beforeInitPlaceholder == null) {
+ setEnabledImpl(enabled);
+ } else {
+ beforeInitPlaceholder.setPropertyBoolean("disabled", !enabled);
+ }
+ }
@Override
public native void setFocus(boolean focused) /*-{
@@ -265,12 +281,14 @@
// Unhook all custom event handlers when the element is detached.
unhookEvents();
- // Recreate the placeholder element and store the iframe's contents in
it.
- // This is necessary because some browsers will wipe the iframe's
contents
- // when it is removed from the DOM.
+ // Recreate the placeholder element and store the iframe's contents
and the
+ // enabled status in it. This is necessary because some browsers will
wipe
+ // the iframe's contents when it is removed from the DOM.
String html = getHTML();
+ boolean enabled = isEnabled();
beforeInitPlaceholder = DOM.createDiv();
DOM.setInnerHTML(beforeInitPlaceholder, html);
+ setEnabled(enabled);
}
protected native String getHTMLImpl() /*-{
@@ -324,6 +342,11 @@
wnd.addEventListener('blur', elem.__gwt_blurHandler, true);
}-*/;
+ protected native boolean isEnabledImpl() /*-{
+ var elem =
[email protected]::elem;
+ return elem.contentWindow.document.designMode.toUpperCase() == 'ON';
+ }-*/;
+
@Override
protected void onElementInitialized() {
// Issue 1897: This method is called after a timeout, during which
time the
@@ -337,12 +360,18 @@
// When the iframe is ready, ensure cached content is set.
if (beforeInitPlaceholder != null) {
setHTMLImpl(DOM.getInnerHTML(beforeInitPlaceholder));
+ setEnabledImpl(isEnabled());
beforeInitPlaceholder = null;
}
super.onElementInitialized();
}
+ protected native void setEnabledImpl(boolean enabled) /*-{
+ var elem =
[email protected]::elem;
+ elem.contentWindow.document.designMode = enabled ? 'On' : 'Off';
+ }-*/;
+
protected native void setHTMLImpl(String html) /*-{
[email protected]::elem.contentWindow.document.body.innerHTML
= html;
}-*/;
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/RichTextAreaTest.java
Mon Oct 26 18:35:41 2009
+++ /trunk/user/test/com/google/gwt/user/client/ui/RichTextAreaTest.java
Thu Feb 4 04:42:51 2010
@@ -159,6 +159,45 @@
});
RootPanel.get().add(richTextArea);
}
+
+ /**
+ * Test that a delayed call to setEnable is reflected.
+ */
+ @DoNotRunWith(Platform.HtmlUnit)
+ public void testSetEnabledAfterInit() {
+ final RichTextArea richTextArea = new RichTextArea();
+ delayTestFinish(RICH_TEXT_ASYNC_DELAY);
+ richTextArea.addInitializeHandler(new InitializeHandler() {
+ public void onInitialize(InitializeEvent event) {
+ richTextArea.setEnabled(false);
+ assertEquals(false, richTextArea.isEnabled());
+ richTextArea.setEnabled(true);
+ assertEquals(true, richTextArea.isEnabled());
+ finishTest();
+ }
+ });
+ RootPanel.get().add(richTextArea);
+ }
+
+ /**
+ * Test that a call to setEnable is reflected immediately, and after the
area
+ * loads.
+ */
+ @DoNotRunWith(Platform.HtmlUnit)
+ public void testSetEnabledBeforeInit() {
+ final RichTextArea richTextArea = new RichTextArea();
+ richTextArea.setEnabled(false);
+ assertEquals(false, richTextArea.isEnabled());
+ delayTestFinish(RICH_TEXT_ASYNC_DELAY);
+ richTextArea.addInitializeHandler(new InitializeHandler() {
+ public void onInitialize(InitializeEvent event) {
+ assertEquals(false, richTextArea.isEnabled());
+ finishTest();
+ }
+ });
+ RootPanel.get().add(richTextArea);
+ assertEquals(false, richTextArea.isEnabled());
+ }
/**
* Test that a delayed set of HTML is reflected. Some platforms have
timing
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors