Author: [EMAIL PROTECTED]
Date: Fri Sep 12 06:04:26 2008
New Revision: 3650

Modified:
    trunk/user/src/com/google/gwt/user/client/ui/TextArea.java
    trunk/user/test/com/google/gwt/user/client/ui/ElementWrappingTest.java

Log:
Adds TextArea.wrap() and updates TextArea to use dom.Element.

Patch by: Folke Behrens
Review by: jgw
Issue: 2874


Modified: trunk/user/src/com/google/gwt/user/client/ui/TextArea.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/TextArea.java  (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/TextArea.java  Fri Sep 12  
06:04:26 2008
@@ -15,7 +15,9 @@
   */
  package com.google.gwt.user.client.ui;

-import com.google.gwt.user.client.DOM;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.TextAreaElement;
  import com.google.gwt.i18n.client.HasDirection;
  import com.google.gwt.i18n.client.BidiUtils;

@@ -39,21 +41,55 @@
  public class TextArea extends TextBoxBase implements HasDirection {

    /**
+   * Creates a TextArea widget that wraps an existing <textarea>
+   * element.
+   *
+   * This element must already be attached to the document. If the element  
is
+   * removed from the document, you must call
+   * [EMAIL PROTECTED] RootPanel#detachNow(Widget)}.
+   *
+   * @param element the element to be wrapped
+   */
+  public static TextArea wrap(Element element) {
+    // Assert that the element is attached.
+    assert Document.get().getBody().isOrHasChild(element);
+
+    TextArea textArea = new TextArea(element);
+
+    // Mark it attached and remember it for cleanup.
+    textArea.onAttach();
+    RootPanel.detachOnWindowClose(textArea);
+
+    return textArea;
+  }
+
+  /**
     * Creates an empty text area.
     */
    public TextArea() {
-    super(DOM.createTextArea());
+    super(Document.get().createTextAreaElement());
      setStyleName("gwt-TextArea");
    }

    /**
+   * This constructor may be used by subclasses to explicitly use an  
existing
+   * element. This element must be a <textarea> element.
+   *
+   * @param element the element to be used
+   */
+  protected TextArea(Element element) {
+    super(element.<Element>cast());
+    TextAreaElement.as(element);
+  }
+
+  /**
     * Gets the requested width of the text box (this is not an exact value,  
as
     * not all characters are created equal).
     *
     * @return the requested width, in characters
     */
    public int getCharacterWidth() {
-    return DOM.getElementPropertyInt(getElement(), "cols");
+    return getTextAreaElement().getCols();
    }

    @Override
@@ -64,7 +100,7 @@
    public Direction getDirection() {
      return BidiUtils.getDirectionOnElement(getElement());
    }
-
+
    @Override
    public int getSelectionLength() {
      return getImpl().getSelectionLength(getElement());
@@ -76,7 +112,7 @@
     * @return the number of visible lines
     */
    public int getVisibleLines() {
-    return DOM.getElementPropertyInt(getElement(), "rows");
+    return getTextAreaElement().getRows();
    }

    /**
@@ -86,7 +122,7 @@
     * @param width the requested width, in characters
     */
    public void setCharacterWidth(int width) {
-    DOM.setElementPropertyInt(getElement(), "cols", width);
+    getTextAreaElement().setCols(width);
    }

    public void setDirection(Direction direction) {
@@ -99,6 +135,10 @@
     * @param lines the number of visible lines
     */
    public void setVisibleLines(int lines) {
-    DOM.setElementPropertyInt(getElement(), "rows", lines);
+    getTextAreaElement().setRows(lines);
+  }
+
+  private TextAreaElement getTextAreaElement() {
+    return getElement().cast();
    }
  }

Modified:  
trunk/user/test/com/google/gwt/user/client/ui/ElementWrappingTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/ElementWrappingTest.java      
 
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/ElementWrappingTest.java      
 
Fri Sep 12 06:04:26 2008
@@ -150,6 +150,13 @@
      assertExistsAndAttached(radio);
    }

+  public void testTextArea() {
+    ensureDiv().setInnerHTML("<textarea rows='1' cols='1'  
id='foo'></textarea>");
+    TextArea textArea =  
TextArea.wrap(Document.get().getElementById("foo"));
+
+    assertExistsAndAttached(textArea);
+  }
+
    public void testTextBox() {
      ensureDiv().setInnerHTML("<input type='text' id='foo'></input>");
      TextBox textBox = TextBox.wrap(Document.get().getElementById("foo"));

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to