Search in sources :

Example 1 with Text

use of com.google.gwt.dom.client.Text in project rstudio by rstudio.

the class NodeRelativePosition method toPositionHelper.

private static NodeRelativePosition toPositionHelper(Node here, int[] counter) {
    switch(here.getNodeType()) {
        case Node.TEXT_NODE:
            Text text = (Text) here;
            if (counter[0] <= text.getLength())
                return new NodeRelativePosition(here, counter[0]);
            counter[0] -= text.getLength();
            return null;
        case Node.ELEMENT_NODE:
            Element el = (Element) here;
            String tagName = el.getTagName().toLowerCase();
            if (tagName.equals("br")) {
                if (counter[0] <= 0)
                    return new NodeRelativePosition(here, 0);
                counter[0] -= 1;
                return null;
            } else if (tagName.equals("script") || tagName.equals("style"))
                return null;
            break;
    }
    NodeList<Node> children = here.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        NodeRelativePosition result = toPositionHelper(children.getItem(i), counter);
        if (result != null)
            return result;
    }
    return null;
}
Also used : Element(com.google.gwt.dom.client.Element) Node(com.google.gwt.dom.client.Node) Text(com.google.gwt.dom.client.Text)

Example 2 with Text

use of com.google.gwt.dom.client.Text in project gwt-test-utils by gwt-test-utils.

the class TextTest method checkToString.

@Test
public void checkToString() {
    // Given
    Text text = Document.get().createTextNode("some text");
    // When
    String toString = text.toString();
    // Then
    assertThat(toString).isEqualTo("'some text'");
}
Also used : Text(com.google.gwt.dom.client.Text) GwtTestTest(com.googlecode.gwt.test.GwtTestTest) Test(org.junit.Test)

Example 3 with Text

use of com.google.gwt.dom.client.Text in project rstudio by rstudio.

the class DomUtilsStandardImpl method replaceSelection.

public String replaceSelection(Document document, String text) {
    if (!isSelectionInElement(document.getBody()))
        throw new IllegalStateException("Selection is not active");
    Range rng = getSelectionRange(NativeWindow.get(document), true);
    String orig = rng.toStringJs();
    rng.deleteContents();
    Text textNode = document.createTextNode(text);
    rng.insertNode(textNode);
    rng.selectNode(textNode);
    Selection.get(NativeWindow.get(document)).setRange(rng);
    return orig;
}
Also used : Text(com.google.gwt.dom.client.Text)

Example 4 with Text

use of com.google.gwt.dom.client.Text in project gwt-test-utils by gwt-test-utils.

the class UiObjectTag method appendText.

/**
 * Append text to this uiObject. This implementation calls {@link HasText#setText(String)} if the
 * current uiObject is implementing the {@link HasText} interface, or append a new {@link Text}
 * node wrapping the data value to the Widget's element.
 *
 * @param wrapped The wrapped uiObject of this tag.
 * @param data    The string value.
 */
protected void appendText(T wrapped, String data) {
    if (HasText.class.isInstance(wrapped)) {
        ((HasText) wrapped).setText(data);
    } else {
        Element element = getElement(wrapped);
        Text text = JsoUtils.newText(data, element.getOwnerDocument());
        element.appendChild(text);
    }
}
Also used : Element(com.google.gwt.dom.client.Element) Text(com.google.gwt.dom.client.Text)

Example 5 with Text

use of com.google.gwt.dom.client.Text in project gwt-test-utils by gwt-test-utils.

the class UiElementTag method appendText.

protected void appendText(Element wrapped, String data) {
    Text text = JsoUtils.newText(data, wrapped.getOwnerDocument());
    wrapped.appendChild(text);
}
Also used : Text(com.google.gwt.dom.client.Text)

Aggregations

Text (com.google.gwt.dom.client.Text)5 Element (com.google.gwt.dom.client.Element)2 Node (com.google.gwt.dom.client.Node)1 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)1 Test (org.junit.Test)1