List of usage examples for com.google.gwt.dom.client Node getFirstChild
@Override
public Node getFirstChild()
From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java
License:Apache License
public static Element getElementForPositioning0(Element from) { assert tempPositioningText == null; if (!isVisibleAncestorChain(from)) { return null; }// w w w.j a v a 2 s. co m boolean hidden = isZeroOffsetDims(from); int kidCount = from.getChildCount(); if (kidCount != 0 && !hidden) { return from; } Node parent = from.getParentNode(); if (parent != null && parent.getFirstChild() == from && parent.getNodeType() == Node.ELEMENT_NODE && !isZeroOffsetDims((Element) parent)) { return (Element) parent; } ClientNodeIterator itr = new ClientNodeIterator(from, ClientNodeIterator.SHOW_ALL); Element fromContainingBlock = DomUtils.getContainingBlock(from); Node node = from; int insertTextIfOffsetMoreThanXChars = 100; while ((node = node.getPreviousSibling()) != null) { if (node.getNodeType() == Node.TEXT_NODE) { insertTextIfOffsetMoreThanXChars -= TextUtils.normalizeWhitespaceAndTrim(node.getNodeValue()) .length(); if (insertTextIfOffsetMoreThanXChars < 0) { // this causes a relayout - so we try and avoid. most of the // time, positioning elements will contain text (or be from // a friendly browser), or be at the start of a block elt) tempPositioningText = Document.get().createTextNode("---"); from.appendChild(tempPositioningText); return from; } } } // give up after 50 node iterations (big tables maybe) int max = 50; while ((node = itr.nextNode()) != null && max-- > 0) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (!isZeroOffsetDims(node.getParentElement()) && node.getNodeName().equalsIgnoreCase("img")) { return (Element) node; } if (!UIObject.isVisible((Element) node)) { itr.skipChildren(); } } else { // text if (!isZeroOffsetDims(node.getParentElement()) // we don't want the combined ancestor of everyone... && (!node.getParentElement().isOrHasChild(from) || // but we do want <p><a><b>*some-text*</b></p> DomUtils.getContainingBlock(node) == fromContainingBlock)) { return node.getParentElement(); } } } return from.getParentElement(); }
From source file:com.bfr.client.selection.Range.java
License:Apache License
/** * Returns the next adjacent text node in the given direction. Will move * down the hierarchy (if traversingUp is not set), then through siblings, * then up (but not past topMostNode), looking for the first node * <p/>//from w w w . j a va 2 s . c o m * This could be non-statically included in the Node class * * @param current An element to start the search from, can be any type * of node. * @param topMostNode A node that this will traverse no higher than * @param forward whether to search forward or backward * @param traversingUp if true, will not look at the children of this element * @return the next (previous) text node, or null if no more */ public static Text getAdjacentTextElement(Node current, Node topMostNode, boolean forward, boolean traversingUp) { Text res = null; Node node; // If traversingUp, then the children have already been processed if (!traversingUp) { if (current.getChildCount() > 0) { node = forward ? current.getFirstChild() : current.getLastChild(); if (node.getNodeType() == Node.TEXT_NODE) { res = (Text) node; } else { // Depth first traversal, the recursive call deals with // siblings res = getAdjacentTextElement(node, topMostNode, forward, false); } } } if (res == null) { node = forward ? current.getNextSibling() : current.getPreviousSibling(); // Traverse siblings if (node != null) { if (node.getNodeType() == Node.TEXT_NODE) { res = (Text) node; } else { // Depth first traversal, the recursive call deals with // siblings res = getAdjacentTextElement(node, topMostNode, forward, false); } } } // Go up and over if still not found if ((res == null) && (current != topMostNode)) { node = current.getParentNode(); // Stop at document (technically could stop at "html" tag) if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE)) { res = getAdjacentTextElement(node, topMostNode, forward, true); } } return res; }
From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java
License:Apache License
private JsNodeArray getNthChildPseudo(JsNodeArray previousMatch, String pseudoValue, JsNodeArray prevParents, JsNodeArray matchingElms) {/*from w ww. j a v a 2 s. c o m*/ Node previous; if (JsUtils.eq(pseudoValue, "n")) { matchingElms = previousMatch; } else { Sequence sequence = getSequence(pseudoValue); if (sequence != null) { for (int l = 0, llen = previousMatch.size(); l < llen; l++) { previous = previousMatch.getNode(l); Node prevParent = previous.getParentNode(); if (!hasChildElms(prevParent)) { int iteratorNext = sequence.start; int childCount = 0; Node childElm = prevParent.getFirstChild(); while (childElm != null && (sequence.max < 0 || iteratorNext <= sequence.max)) { if (childElm.getNodeType() == Node.ELEMENT_NODE) { if (++childCount == iteratorNext) { if (JsUtils.eq(childElm.getNodeName(), previous.getNodeName())) { matchingElms.addNode(childElm); } iteratorNext += sequence.add; } } childElm = SelectorEngine.getNextSibling(childElm); } setHasChildElms(prevParent, true); prevParents.addNode(prevParent); } } clearChildElms(prevParents); } } return matchingElms; }
From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java
License:Apache License
private JsNodeArray getNthOfTypePseudo(JsNodeArray previousMatch, String pseudoValue, JsNodeArray prevParents, JsNodeArray matchingElms) {/* ww w .j ava2 s .co m*/ Node previous; if (pseudoValue.startsWith("n")) { matchingElms = previousMatch; } else { Sequence sequence = getSequence(pseudoValue); if (sequence != null) { for (int p = 0, plen = previousMatch.size(); p < plen; p++) { previous = previousMatch.getNode(p); Node prevParent = previous.getParentNode(); if (!hasChildElms(prevParent)) { int iteratorNext = sequence.start; int childCount = 0; Node childElm = prevParent.getFirstChild(); while (JsUtils.truth(childElm) && (sequence.max < 0 || iteratorNext <= sequence.max)) { if (JsUtils.eq(childElm.getNodeName(), previous.getNodeName())) { if (++childCount == iteratorNext) { matchingElms.addNode(childElm); iteratorNext += sequence.add; } } childElm = SelectorEngine.getNextSibling(childElm); } setHasChildElms(prevParent, true); prevParents.addNode(prevParent); } } clearChildElms(prevParents); } } return matchingElms; }
From source file:com.dom_distiller.client.DomWalker.java
License:Open Source License
/** * Walk the subtree rooted at n.//from w w w . j a v a 2s . c o m */ public void walk(Node top) { // Conceptually, this maintains a pointer to the currently "walked" node. When first seeing // the node, it calls visit() on it. The next node to visit is then (1) the first child, (2) // the next sibling, or (3) the next sibling of the first ancestor w/ a next sibling. // // Every time the walk "crosses" the "exit" of a node (i.e. when the pointer goes from // somewhere in the node's subtree to somewhere outside of that subtree), exit() is called // for that node (unless visit() for that node returned false). if (!visitor.visit(top)) return; Node n = top.getFirstChild(); if (n != null) { while (n != top) { // shouldExit is used to suppress the exit call for the current node when visit() // returns false. boolean shouldExit = false; if (visitor.visit(n)) { Node c = n.getFirstChild(); if (c != null) { n = c; continue; } shouldExit = true; } while (n != top) { if (shouldExit) visitor.exit(n); Node s = n.getNextSibling(); if (s != null) { n = s; break; } n = n.getParentNode(); shouldExit = true; } } } visitor.exit(top); }
From source file:com.extjs.gxt.ui.client.widget.ListView.java
License:sencha.com license
protected void onAdd(List<M> models, int index) { if (rendered) { if (all.getCount() == 0) { refresh();// w w w .j av a2 s . com return; } NodeList<Element> nodes = bufferRender(models); Element[] elements = Util.toElementArray(nodes); all.insert(elements, index); Element ref = index == 0 ? all.getElement(elements.length) : all.getElement(index - 1); for (int i = elements.length - 1; i >= 0; i--) { Node n = ref.getParentNode(); if (index == 0) { n.insertBefore(elements[i], n.getFirstChild()); } else { Node next = ref == null ? null : ref.getNextSibling(); if (next == null) { n.appendChild(elements[i]); } else { n.insertBefore(elements[i], next); } } if (GXT.isAriaEnabled()) { elements[i].setId(XDOM.getUniqueId()); } } updateIndexes(index, -1); } }
From source file:com.google.livingstories.client.lsp.views.contentitems.QuoteContentItemView.java
License:Apache License
public Node getFirstTextNode(Node node) { if (node == null) { return null; }//w w w . jav a 2 s . co m if (node.getNodeType() == Node.TEXT_NODE && !node.getNodeValue().trim().isEmpty()) { return node; } Node childResult = getFirstTextNode(node.getFirstChild()); return (childResult == null) ? getFirstTextNode(node.getNextSibling()) : childResult; }
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 w w . j av a 2 s . co 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:de.catma.ui.client.ui.tagger.editor.LeafFinder.java
License:Open Source License
public static Node getFirstTextLeaf(Node root) { VConsole.log("looking for first text leaf for root: " + DebugUtil.getNodeInfo(root)); if (root.hasChildNodes()) { Node candidate = root.getFirstChild(); while (candidate.hasChildNodes()) { candidate = candidate.getFirstChild(); }//from w ww. j a v a2 s . com VConsole.log("outer left child node: " + DebugUtil.getNodeInfo(candidate)); if (Element.is(candidate) || (candidate.getNodeValue().isEmpty())) { VConsole.log("outer left node is not a text leaf, we start searching to the right now"); LeafFinder leafFinder = new LeafFinder(candidate); // return leafFinder.getNextRightTextLeaf(); return leafFinder.getNextNonEmptyRightTextLeaf(); } else { return candidate; } } return null; }
From source file:de.catma.ui.client.ui.tagger.LeafFinder.java
License:Open Source License
public static Node getFirstTextLeaf(Node root) { if (root.hasChildNodes()) { Node candidate = root.getFirstChild(); while (candidate.hasChildNodes()) { candidate = candidate.getFirstChild(); }/*from w w w.j a va2 s . com*/ if (Element.is(candidate)) { LeafFinder leafFinder = new LeafFinder(candidate); return leafFinder.getNextRightTextLeaf(); } else { return candidate; } } return null; }