Example usage for com.google.gwt.dom.client Node isOrHasChild

List of usage examples for com.google.gwt.dom.client Node isOrHasChild

Introduction

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

Prototype

@Override
    public boolean isOrHasChild(Node child) 

Source Link

Usage

From source file:com.vaadin.client.LayoutManagerIE8.java

License:Apache License

@Override
public void cleanMeasuredSizes() {
    Profiler.enter("LayoutManager.cleanMeasuredSizes");

    // #12688: IE8 was leaking memory when adding&removing components.
    // Uses IE specific logic to figure if an element has been removed from
    // DOM or not. For removed elements the measured size is stored within
    // the element in case the element gets re-attached.
    Node rootNode = Document.get().getBody();

    Iterator<Element> i = measuredSizes.keySet().iterator();
    while (i.hasNext()) {
        Element e = i.next();/*  w  w  w.j a v  a  2s  .  c  o m*/
        if (!rootNode.isOrHasChild(e)) {
            // Store in element in case is still needed.
            // Not attached, so reflow isn't a problem.
            super.setMeasuredSize(e, measuredSizes.get(e));
            i.remove();
        }
    }

    Profiler.leave("LayoutManager.cleanMeasuredSizes");
}

From source file:com.vaadin.client.widgets.JsniWorkaround.java

License:Apache License

/**
 * Returns the widget from a cell node or <code>null</code> if there is no
 * widget in the cell//from w  ww  .  j a  v  a2  s.  c o  m
 * 
 * @param cellNode
 *            The cell node
 */
static Widget getWidgetFromCell(Node cellNode) {
    Node possibleWidgetNode = cellNode.getFirstChild();
    if (possibleWidgetNode != null && possibleWidgetNode.getNodeType() == Node.ELEMENT_NODE) {
        @SuppressWarnings("deprecation")
        com.google.gwt.user.client.Element castElement = (com.google.gwt.user.client.Element) possibleWidgetNode
                .cast();
        Widget w = WidgetUtil.findWidget(castElement, null);

        // Ensure findWidget did not traverse past the cell element in the
        // DOM hierarchy
        if (cellNode.isOrHasChild(w.getElement())) {
            return w;
        }
    }
    return null;
}

From source file:org.waveprotocol.wave.client.clipboard.Clipboard.java

License:Apache License

/**
 * Fill the PasteBuffer with the given content.
 *
 * This fills the PasteBuffer and sets the selection over the corresponding
 * html on the buffer. To fill the clipboard, this needs to be called inside a
 * copy event handler, or follow this with an execCommand(copy)
 *
 * @param htmlFragment//from  w  w w.j  a  v a 2 s  .c  o m
 * @param selection
 * @param waveXml
 * @param normalizedAnnotation
 */
public void fillBufferAndSetSelection(Node htmlFragment, PointRange<Node> selection, XmlStringBuilder waveXml,
        Iterable<RangedAnnotation<String>> normalizedAnnotation, boolean restoreSelection) {
    final FocusedPointRange<Node> oldSelection = restoreSelection ? NativeSelectionUtil.get() : null;

    // Clear this node and append the cloned fragment.
    pasteBuffer.setContent(htmlFragment);

    assert htmlFragment.isOrHasChild(selection.getFirst().getContainer()) : "first not attached before hijack";
    assert htmlFragment
            .isOrHasChild(selection.getSecond().getContainer()) : "second not attached before hijack";

    if (waveXml != null && normalizedAnnotation != null) {
        selection = hijackFragment(waveXml.toString(),
                AnnotationSerializer.serializeAnnotation(normalizedAnnotation), selection);
    }
    assert htmlFragment.isOrHasChild(selection.getFirst().getContainer()) : "first not attached after hijack";
    assert htmlFragment.isOrHasChild(selection.getSecond().getContainer()) : "second not attached after hijack";
    NativeSelectionUtil.set(selection.getFirst(), selection.getSecond());

    if (restoreSelection && oldSelection != null) {
        DeferredCommand.addCommand(new Command() {
            @Override
            public void execute() {
                NativeSelectionUtil.set(oldSelection);
            }
        });
    }
}

From source file:org.waveprotocol.wave.client.editor.extract.PasteExtractor.java

License:Apache License

protected void performCopyOrCut(HtmlSelectionHelper selectionHelper, Element srcContainer,
        ContentRange contentSelection, boolean isCut) {
    if (contentSelection.isCollapsed()) {
        // Nothing to do.
        return;//  www . j  a v  a2  s  .  c  om
    }

    Point<ContentNode> first = contentSelection.getFirst();
    Point<ContentNode> second = contentSelection.getSecond();
    SelectionMatcher selectionMatcher = new SelectionMatcher(first, second);

    ContentNode commonAncestor = DocHelper.nearestCommonAncestor(renderedContent, first.getContainer(),
            second.getContainer());

    Node fragment = PASTE_FORMAT_RENDERER.renderTree(renderedContent, commonAncestor, selectionMatcher);

    Preconditions.checkNotNull(selectionMatcher.getHtmlStart(), "html start is null, first: " + first);
    Preconditions.checkNotNull(selectionMatcher.getHtmlEnd(), "html end is null second: " + second);

    assert fragment.isOrHasChild(
            selectionMatcher.getHtmlStart().getContainer()) : "SelectionMatcher start not attached";
    assert fragment
            .isOrHasChild(selectionMatcher.getHtmlEnd().getContainer()) : "SelectionMatcher end not attached";

    PointRange<Node> newRange = new PointRange<Node>(selectionMatcher.getHtmlStart(),
            selectionMatcher.getHtmlEnd());

    Point<ContentNode> normalizedStart = normalize(contentSelection.getFirst());
    Point<ContentNode> normalizedEnd = normalize(contentSelection.getSecond());

    final XmlStringBuilder xmlInRange;
    final List<RangedAnnotation<String>> normalizedAnnotations;
    if (useSemanticCopyPaste) {
        String debugString = "Start: " + contentSelection.getFirst() + " End: " + contentSelection.getSecond()
                + " docDebug: " + mutableDocument.toDebugString();
        try {
            xmlInRange = subtreeRenderer.renderRange(normalizedStart, normalizedEnd);
            normalizedAnnotations = annotationLogic.extractNormalizedAnnotation(normalizedStart, normalizedEnd);
        } catch (Exception e) {
            LOG.error().logPlainText(debugString);
            throw new RuntimeException(e);
        }
    } else {
        xmlInRange = null;
        normalizedAnnotations = null;
    }

    if (isCut) {
        // Delete the originally selected content.
        mutableDocument.deleteRange(normalizedStart, normalizedEnd).getFirst();
    }

    // Set the browser's selection to the hidden div for the copy/cut.
    clipboard.fillBufferAndSetSelection(fragment, newRange, xmlInRange, normalizedAnnotations, false);
}

From source file:org.waveprotocol.wave.client.editor.HtmlSelectionHelperImpl.java

License:Apache License

/**
 * Tests if the given selection is fully inside the given node.
 *
 * @param selection/*from ww  w  . jav a 2  s .  c om*/
 * @param node
 * @return true if the given selection is fully inside the given node.
 */
private boolean isFullyInside(FocusedPointRange<Node> selection, Node node) {
    return node.isOrHasChild(selection.getAnchor().getContainer())
            && node.isOrHasChild(selection.getFocus().getContainer());
}

From source file:org.waveprotocol.wave.client.editor.util.EditorDocFormatter.java

License:Apache License

/** @return a String version of the HTML dom inside an editor. */
public static String formatImplDomString(Editor editor) {
    if (EditorTestingUtil.isConsistent(editor)) {
        // Get editor, null selection if outside the editor:
        PointRange<Node> selection = NativeSelectionUtil.getOrdered();
        if (selection != null) {
            Node editorHtml = editor.getWidget().getElement();
            if (!editorHtml.isOrHasChild(selection.getFirst().getContainer())
                    || editorHtml.isOrHasChild(selection.getSecond().getContainer())) {
                selection = null; // outside!
            }//from w  ww. ja  v  a  2  s . c o m
        }
        HtmlView view = editor.getContent().getRawHtmlView();
        Point<Node> selStart = (selection != null) ? selection.getFirst() : null;
        Point<Node> selEnd = (selection != null) ? selection.getSecond() : null;
        return new Pretty<Node>().select(selStart, selEnd).print(view);
    } else {
        EditorStaticDeps.logger.error().logPlainText("EditorDocFormatter called with inconsistent Doc");
        return null;
    }
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.readonly.ReadOnlyKeyboardHandler.java

License:Open Source License

/**
 * @param container a DOM node/*ww  w.j  a  va 2  s .  co  m*/
 * @param caret specifies a position within the given container, <strong>between</strong> DOM nodes
 * @return {@code true} if the given container has visible content before the caret position, {@code false}
 *         otherwise
 */
private boolean hasVisibleContentBefore(Node container, Range caret) {
    Node leaf = domUtils.getPreviousLeaf(caret);
    if (leaf == null || !container.isOrHasChild(leaf)) {
        // We jumped outside of the container without finding any leaf.
        return false;
    }
    // Move backward looking for a visible leaf, taking care not to jump over the first leaf.
    Node firstLeaf = domUtils.getFirstLeaf(container);
    while (!isVisible(leaf)) {
        if (leaf == firstLeaf) {
            return false;
        }
        leaf = domUtils.getPreviousLeaf(leaf);
    }
    return true;
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.readonly.ReadOnlyKeyboardHandler.java

License:Open Source License

/**
 * @param container a DOM node//ww  w. j a v  a  2 s . c o  m
 * @param caret specifies a position within the given container, <strong>between</strong> DOM nodes
 * @return {@code true} if the given container has visible content after the caret position, {@code false} otherwise
 */
private boolean hasVisibleContentAfter(Node container, Range caret) {
    Node leaf = domUtils.getNextLeaf(caret);
    if (leaf == null || !container.isOrHasChild(leaf)) {
        // We jumped outside of the container without finding any leaf.
        return false;
    }
    // Move forward looking for a visible leaf, taking care not to jump over the last leaf.
    Node lastLeaf = domUtils.getLastLeaf(container);
    while (!isVisible(leaf)) {
        if (leaf == lastLeaf) {
            return false;
        }
        leaf = domUtils.getNextLeaf(leaf);
    }
    return true;
}