Example usage for com.google.gwt.dom.client Text getParentElement

List of usage examples for com.google.gwt.dom.client Text getParentElement

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Text getParentElement.

Prototype

@Override
    public Element getParentElement() 

Source Link

Usage

From source file:com.bfr.client.selection.impl.RangeImplIE6.java

License:Apache License

/**
 * For IE, do this by copying the contents, then creating a dummy element
 * and replacing it with this element./*from  w ww  . ja  v  a  2s  . c o m*/
 *
 * @see com.bfr.client.selection.impl.RangeImpl#surroundContents(com.bfr.client.selection.impl.RangeImpl.JSRange, com.google.gwt.dom.client.Element)
 */
@Override
public void surroundContents(JSRange range, Element copyInto) {
    copyContents(range, copyInto);
    Text txt = placeholdRange(range);
    if (txt != null) {
        txt.getParentElement().replaceChild(copyInto, txt);
    }
}

From source file:com.bfr.client.selection.impl.RangeImplIE6.java

License:Apache License

/**
 * Create a new range with a range that has its start and end point within
 * the given text and at the given offset.  This emulates capabilities of
 * the W3C standard..//from w  ww. j  a v  a  2  s.  c  o  m
 *
 * @param setText
 * @param offset
 * @return
 */
private JSRange createRangeOnText(Text setText, int offset) {
    Element parent = setText.getParentElement();
    JSRange res = createRangeOnFirst(parent);
    Element testElement = getTestElement(parent.getOwnerDocument());

    // Can't directly select the text, but we can select a fake element
    // before it, then move the selection...
    try {
        parent.insertBefore(testElement, setText);
        moveToElementText(res, testElement);
        moveCharacter(res, offset);
    } finally {
        // Ensure the test element gets removed from the document
        testElement.removeFromParent();
    }

    return res;
}

From source file:com.bfr.client.selection.RangeEndPoint.java

License:Apache License

private static FindLocRes findLocation(Document doc, Text text, int relX, int relY) {
    FindLocRes res = null;/*from  w  ww .ja  v a2s .c  o  m*/

    String str = text.getData();
    if ((str == null) || str.isEmpty()) {
        // Theoretically it could be in here still..
    } else {
        // Insert 2 spans and do a binary search to find the single
        // character that fits
        Element span1 = doc.createSpanElement();
        Element span2 = doc.createSpanElement();
        Element span3 = doc.createSpanElement();
        Element span4 = doc.createSpanElement();

        Element parent = text.getParentElement();
        parent.insertBefore(span1, text);
        parent.insertBefore(span2, text);
        parent.insertBefore(span3, text);
        parent.insertBefore(span4, text);
        parent.removeChild(text);

        try {
            int len = str.length() / 2;
            span2.setInnerText(str.substring(0, len));
            span3.setInnerText(str.substring(len));

            res = findLocation(text, span1, span2, span3, span4, relX, relY);
        } catch (Exception ex) {
        } finally {
            parent.insertAfter(text, span4);
            parent.removeChild(span1);
            parent.removeChild(span2);
            parent.removeChild(span3);
            parent.removeChild(span4);
        }
    }

    return res;
}

From source file:org.vectomatic.svg.edit.client.model.XPathMetadata.java

License:Open Source License

@Override
public T remove(SVGElement element) {
    T oldValue = null;//  w  ww  .  j  ava  2 s  .  com
    Node node = DOMHelper.evaluateNodeXPath(element, xpath, SVGPrefixResolver.INSTANCE);
    if (node != null) {
        switch (node.getNodeType()) {
        case Node.TEXT_NODE: {
            Text text = node.cast();
            oldValue = (T) text.getData();
            text.getParentElement().removeChild(text);
        }
            break;
        case 2: {
            Attr attr = node.cast();
            oldValue = (T) attr.getValue();
            attr.getOwnerElement().removeAttribute(attr.getName());
        }
            break;
        default:
            assert (false);
        }
    }
    return oldValue;
}

From source file:org.waveprotocol.wave.client.editor.impl.NodeManager.java

License:Apache License

private Point<ContentNode> textNodeToWrapperPoint(Text text, int offset) throws HtmlInserted, HtmlMissing {

    if (getTransparency(text.getParentElement()) == Skip.DEEP) {
        Element e = text.getParentElement();
        return elementNodeToWrapperPoint(e.getParentElement(), e);
    } else {// w ww  .ja v a 2s  .c  om
        ContentTextNode textNode = findTextWrapper(text, true);
        return Point.<ContentNode>inText(textNode, offset + textNode.getOffset(text));
    }
}

From source file:org.waveprotocol.wave.client.editor.impl.NodeManager.java

License:Apache License

/**
 * Converts the given point to a parent-nodeAfter point, splitting a
 * text node if necessary./*from w  w w  .j  ava 2 s  .  co m*/
 *
 * @param point
 * @return a point at the same location, between node boundaries
 */
public static Point.El<Node> forceElementPoint(Point<Node> point) {
    Point.El<Node> elementPoint = point.asElementPoint();
    if (elementPoint != null) {
        return elementPoint;
    }
    Element parent;
    Node nodeAfter;
    Text text = point.getContainer().cast();
    parent = text.getParentElement();
    int offset = point.getTextOffset();
    if (offset == 0) {
        nodeAfter = text;
    } else if (offset == text.getLength()) {
        nodeAfter = text.getNextSibling();
    } else {
        nodeAfter = text.splitText(offset);
    }
    return Point.inElement(parent, nodeAfter);
}

From source file:rocket.selection.client.support.InternetExplorerSelectionSupport.java

License:Apache License

@Override
protected void surround0(final Selection selection, final Element element) {
    // get child index of selection start textNode from its parent.
    final SelectionEndPoint selectionStart = this.getStart(selection);
    final Text textNode = selectionStart.getTextNode();
    final Element parentOfTextNode = textNode.getParentElement().cast();
    int insertIndex = 0;
    if (selectionStart.getOffset() > 0) {
        insertIndex = this.getChildIndexOfTextNode(textNode) + 1;
    }/*from w w w .  j av a  2  s . com*/
    // extract selection to become a child of element.
    this.extract0(selection, element);
    // delete the
    this.delete(selection);
    // insert $element just after the original start of selection textNode
    this.insertChild(parentOfTextNode, element, insertIndex);
}