This method locates the position set element in the child list of the passed in plfParent or
if not found it will create one automatically and return it if the passed in create flag is
true.
163767
private static Element getPositionSet(Element plfParent, IPerson person, boolean create)
            throws PortalException {
        Node child = plfParent.getFirstChild();

        while (child != null) {
            if (child.getNodeName().equals(Constants.ELM_POSITION_SET)) return (Element) child;
            child = child.getNextSibling();
        }
        if (create == false) return null;

        String ID = null;

        try {
            ID = getDLS().getNextStructDirectiveId(person);
        } catch (Exception e) {
            throw new PortalException(
                    "Exception encountered while "
                            + "generating new position set node "
                            + "Id for userId="
                            + person.getID(),
                    e);
        }
        Document plf = plfParent.getOwnerDocument();
        Element positions = plf.createElement(Constants.ELM_POSITION_SET);
        positions.setAttribute(Constants.ATT_TYPE, Constants.ELM_POSITION_SET);
        positions.setAttribute(Constants.ATT_ID, ID);
        plfParent.appendChild(positions);
        return positions;
    }
848673
function( elem ) {

		// No argument, return index in parent
		if ( !elem ) {
			return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
		}

		// index in selector
		if ( typeof elem === "string" ) {
			return indexOf.call( jQuery( elem ), this[ 0 ] );
		}

		// Locate the position of the desired element
		return indexOf.call( this,

			// If it receives a jQuery object, the first element is used
			elem.jquery ? elem[ 0 ] : elem
		);
	}
1081338
private static TreeElement recursiveFindSelected(TreeElement elem)
    {
        assert(elem != null);

        if (elem.isSelected())
            return elem;

        TreeElement children[] = elem.getChildren();
        assert(children != null);
        for (int i = 0; i < children.length; i++) {
            TreeElement e = recursiveFindSelected(children[i]);
            if (e != null)
                return e;
        }
        return null;
    }
849784
function position() {
    /**
     * Find our nearest block level parent and access its lines property.
     * @var Block_Frame_Decorator
     */ 
    $p = $this->_frame->find_block_parent();

    // Debugging code:

//     pre_r("\nPositioning:");
//     pre_r("Me: " . $this->_frame->get_node()->nodeName . " (" . spl_object_hash($this->_frame->get_node()) . ")");
//     pre_r("Parent: " . $p->get_node()->nodeName . " (" . spl_object_hash($p->get_node()) . ")");

    // End debugging

    if ( !$p )
      throw new DOMPDF_Exception("No block-level parent found.  Not good.");

    $f = $this->_frame;
    
    $cb = $f->get_containing_block();
    $line = $p->get_current_line_box();

    // Skip the page break if in a fixed position element
    $is_fixed = false;
    while($f = $f->get_parent()) {
      if($f->get_style()->position === "fixed") {
        $is_fixed = true;
        break;
      }
    }

    $f = $this->_frame;

    if ( !$is_fixed && $f->get_parent() &&
         $f->get_parent() instanceof Inline_Frame_Decorator &&
         $f->is_text_node() ) {
      
      $min_max = $f->get_reflower()->get_min_max_width();
      
      // If the frame doesn't fit in the current line, a line break occurs
      if ( $min_max["min"] > ($cb["w"] - $line->left - $line->w - $line->right) ) {
        $p->add_line();
      }
    }
    
    $f->set_position($cb["x"] + $line->w, $line->y);

  }
16498
function getPositionFromOffset(el, of) {
  var offsetParent = getOffsetParent(el);
  var parentOf = getOffset(offsetParent);
  return {
    x: of.x - parentOf.x,
    y: of.y - parentOf.y
  };
}
431470
void findInsertPointInLeft(
    Object           new1,
    NodeInsertPoint  point)
  {
    int endp = endPoint();
    findIndex(0, endp, new1, point);
  }
835363
private static boolean isNotReparentable(
            NodeInfo ni, Element compViewParent, Element positionSet) {

        // This one is easy -- can't re-parent a node with dlm:moveAllowed=false
        if (ni.getNode().getAttribute(Constants.ATT_MOVE_ALLOWED).equals("false")) {
            return true;
        }

        try {
            /*
             *  Annoying to do in Java, but we need to find our own placeholder
             *  element in the positionSet
             */
            final XPathFactory xpathFactory = XPathFactory.newInstance();
            final XPath xpath = xpathFactory.newXPath();
            final String findPlaceholderXpath =
                    ".//*[local-name()='position' and @name='" + ni.getId() + "']";
            final XPathExpression findPlaceholder = xpath.compile(findPlaceholderXpath);
            final NodeList findPlaceholderList =
                    (NodeList) findPlaceholder.evaluate(positionSet, XPathConstants.NODESET);
            switch (findPlaceholderList.getLength()) {
                case 0:
                    LOG.warn(
                            "Node not found for XPathExpression=\""
                                    + findPlaceholderXpath
                                    + "\" in positionSet="
                                    + XmlUtilitiesImpl.toString(positionSet));
                    return true;
                case 1:
                    // This is healthy
                    break;
                default:
                    LOG.warn(
                            "More than one node found for XPathExpression=\""
                                    + findPlaceholderXpath
                                    + "\" in positionSet="
                                    + XmlUtilitiesImpl.toString(positionSet));
                    return true;
            }
            final Element placeholder = (Element) findPlaceholderList.item(0); // At last

            for (Element nextPlaceholder =
                            (Element)
                                    placeholder
                                            .getNextSibling(); // Start with the next dlm:position
                    // element after placeholder
                    nextPlaceholder != null; // As long as we have a placeholder to look at
                    nextPlaceholder =
                            (Element)
                                    nextPlaceholder
                                            .getNextSibling()) { // Advance to the next placeholder

                if (LOG.isDebugEnabled()) {
                    LOG.debug(
                            "Considering whether node ''"
                                    + ni.getId()
                                    + "' is Reparentable;  subsequent sibling is:  "
                                    + nextPlaceholder.getAttribute("name"));
                }

                /*
                 * Next task:  we have to find the non-placeholder representation of
                 * the nextSiblingPlaceholder within the compViewParent
                 */
                final String unmaskPlaceholderXpath =
                        ".//*[@ID='" + nextPlaceholder.getAttribute("name") + "']";
                final XPathExpression unmaskPlaceholder = xpath.compile(unmaskPlaceholderXpath);
                final NodeList unmaskPlaceholderList =
                        (NodeList)
                                unmaskPlaceholder.evaluate(compViewParent, XPathConstants.NODESET);
                switch (unmaskPlaceholderList.getLength()) {
                    case 0:
                        // Not a problem;  the nextSiblingPlaceholder also refers
                        // to a node that has been moved to this context (afaik)
                        continue;
                    case 1:
                        final Element nextSibling = (Element) unmaskPlaceholderList.item(0);
                        if (LOG.isDebugEnabled()) {
                            LOG.debug(
                                    "Considering whether node ''"
                                            + ni.getId()
                                            + "' is Reparentable;  subsequent sibling '"
                                            + nextSibling.getAttribute("ID")
                                            + "' has dlm:moveAllowed="
                                            + !nextSibling
                                                    .getAttribute(Constants.ATT_MOVE_ALLOWED)
                                                    .equals("false"));
                        }

                        // Need to perform some checks...
                        if (nextSibling.getAttribute(Constants.ATT_MOVE_ALLOWED).equals("false")) {

                            /*
                             *  The following check is a bit strange;  it seems to verify
                             *  that the current NodeInfo and the nextSibling come from the
                             *  same fragment.  If they don't, the re-parenting is allowable.
                             *  I believe this check could only be unsatisfied in the case
                             *  of tabs.
                             */
                            Precedence p =
                                    Precedence.newInstance(
                                            nextSibling.getAttribute(Constants.ATT_FRAGMENT));
                            if (ni.getPrecedence().isEqualTo(p)) {
                                return true;
                            }
                        }
                        break;
                    default:
                        LOG.warn(
                                "More than one node found for XPathExpression=\""
                                        + unmaskPlaceholderXpath
                                        + "\" in compViewParent");
                        return true;
                }
            }
        } catch (XPathExpressionException xpe) {
            throw new RuntimeException("Failed to evaluate XPATH", xpe);
        }

        return false; // Re-parenting is "not disallowed" (double-negative less readable)
    }
527385
public void setParent( IParseTree l )
  {
    if( l != null && !l.contains( this ) && getLength() > 0 )
    {
      throw new IllegalArgumentException( "Attempted set the parent location, but the parent location's area is not a superset of this location's area." );
    }
    if( _pe != null )
    {
      ParsedElement parentElement = (ParsedElement)_pe.getParent();
      if( parentElement != null )
      {
        ParseTree oldParent = parentElement.getLocation();
        if( oldParent != null )
        {
          oldParent._children.remove( this );
        }
      }
      _pe.setParent( l == null ? null : ((ParseTree)l)._pe );
    }
  }
1248450
private static Element createAndAppendPosition(
            String elementID, Element positions, IPerson person) throws PortalException {
        if (LOG.isDebugEnabled()) LOG.debug("Adding Position Set entry " + elementID + ".");

        String ID = null;

        try {
            ID = getDLS().getNextStructDirectiveId(person);
        } catch (Exception e) {
            throw new PortalException(
                    "Exception encountered while "
                            + "generating new position node "
                            + "Id for userId="
                            + person.getID(),
                    e);
        }
        Document plf = positions.getOwnerDocument();
        Element position = plf.createElement(Constants.ELM_POSITION);
        position.setAttribute(Constants.ATT_TYPE, Constants.ELM_POSITION);
        position.setAttribute(Constants.ATT_ID, ID);
        position.setAttributeNS(Constants.NS_URI, Constants.ATT_NAME, elementID);
        positions.appendChild(position);
        return position;
    }
539551
private int internalRepositionPlaceholder(int x, int y) {

        int indexCorrection = 0;
        int previousTop = 0;
        int documentScrollTop = getElement().getOwnerDocument().getScrollTop();
        int documentScrollLeft = getElement().getOwnerDocument().getScrollLeft();
        for (int index = 0; index < m_elementPositions.size(); index++) {
            ElementPositionInfo info = m_elementPositions.get(index);
            if (info.getElement() == m_placeholder) {
                indexCorrection = 1;
            }
            if (info.isAbsolute() || !info.isVisible()) {
                continue;
            }

            int top = info.getRelativeTop(y, documentScrollTop);

            if ((top <= 0) || (top >= info.getElementPosition().getHeight())) {
                previousTop = top;
                continue;
            }
            int left = info.getRelativeLeft(x, documentScrollLeft);
            if ((left <= 0) || (left >= info.getElementPosition().getWidth())) {
                previousTop = top;
                continue;
            }
            boolean floatSort = info.isFloating() && (top != 0) && (top == previousTop);
            previousTop = top;
            if (info.getElement() != m_placeholder) {
                if (floatSort) {
                    boolean insertBefore = false;
                    if (left < (info.getElementPosition().getWidth() / 2)) {
                        if (info.isFloatLeft()) {
                            insertBefore = true;
                        }
                    } else if (info.isFloatRight()) {
                        insertBefore = true;
                    }
                    if (insertBefore) {
                        getElement().insertBefore(m_placeholder, info.getElement());
                        return index - indexCorrection;
                    } else {
                        getElement().insertAfter(m_placeholder, info.getElement());
                        return (index + 1) - indexCorrection;
                    }
                } else {
                    if (top < (info.getElementPosition().getHeight() / 2)) {
                        getElement().insertBefore(m_placeholder, info.getElement());
                        return index - indexCorrection;
                    } else {
                        getElement().insertAfter(m_placeholder, info.getElement());
                        return (index + 1) - indexCorrection;
                    }
                }
            } else {
                return index;
            }
        }

        // not over any child position
        if ((m_placeholderIndex >= 0) && (m_placeholder.getParentElement() == getElement())) {
            // element is already attached to this parent and no new position available
            // don't do anything
            return m_placeholderIndex;
        }
        int top = CmsDomUtil.getRelativeY(y, getElement());
        int offsetHeight = getElement().getOffsetHeight();
        if ((top >= (offsetHeight / 2))) {
            // over top half, insert as first child
            getElement().insertFirst(m_placeholder);
            return 0;
        }
        // over bottom half, insert as last child
        getElement().appendChild(m_placeholder);
        return getElement().getChildCount() - 1;
    }
326811
def ipostorder(self):
        ''''''
        children = [self, ]
        seen = set()
        while children:
            cur_node = children[-1]
            if cur_node not in seen:
                seen.add(cur_node)
                children.extend(reversed(cur_node.children))
            else:
                children.pop()
                yield cur_node
305231
function () {

            // This check looks a little strange, but it suits what we're trying
            // to do: as we're walking through the children, a child node that has moved
            // from one parent to another will be found but would look like some kind
            // of insert. The check that we're doing here is looking up the current
            // child's ID in the *old* map and seeing if this child used to have a
            // different parent.
            var possiblyMovedElement = oldNodeMap[newChild.tagID];
            if (possiblyMovedElement &&
                    newParent.tagID !== getParentID(possiblyMovedElement)) {
                newEdit = {
                    type: "elementMove",
                    tagID: newChild.tagID,
                    parentID: newChild.parent.tagID
                };
                moves.push(newEdit.tagID);
                newEdits.push(newEdit);

                // this element in the new tree was a move to this spot, so we can move
                // on to the next child in the new tree.
                newIndex++;
                return true;
            }
            return false;
        }
500231
private Box locateBox(Box root, int x, int y)
    {
        if (root.isVisible())
        {
            Box found = null;
            //Rectangle bounds = root.getAbsoluteContentBounds().intersection(root.getClipBlock().getAbsoluteContentBounds());
            Rectangle bounds = root.getAbsoluteBounds();
            if (bounds.contains(x, y))
            {
                found = root;
                System.out.println("Fnd: " + found);
                found.drawExtent(((BrowserCanvas)cssbox).getImageGraphics());
            }
            
            //find if there is something smallest that fits among the child boxes
            if (root instanceof ElementBox)
            {
                ElementBox eb = (ElementBox) root;
                for (int i = eb.getStartChild(); i < eb.getEndChild(); i++)
                {
                    Box inside = locateBox(((ElementBox) root).getSubBox(i), x, y);
                    if (inside != null)
                    {
                        if (found == null)
                            found = inside;
                        else
                        {
                            if (inside.getAbsoluteBounds().width * inside.getAbsoluteBounds().height < found.getAbsoluteBounds().width * found.getAbsoluteBounds().height)
                                found = inside;
                        }
                    }
                }
            }
            return found;
        }
        else
            return null;
    }
586391
private static Element getFirstChildElement(Node parent) {
		NodeList nodeList = parent.getChildNodes();
		for (int i = 0; i < nodeList.getLength(); i++) {
			Node node = nodeList.item(i);
			if (node instanceof Element) {
				return (Element) node;
			}
		}
		return null;
	}
287567
@UiThread
    int getChildPosition(int flatPosition) {
        if (flatPosition == 0) {
            return 0;
        }

        int childCount = 0;
        for (int i = 0; i < flatPosition; i++) {
            ExpandableWrapper<P, C> listItem = mFlatItemList.get(i);
            if (listItem.isParent()) {
                childCount = 0;
            } else {
                childCount++;
            }
        }
        return childCount;
    }
735902
function (collection, settings, elements, element, index) {
            if (index !== 0 && trueOrUndefined(settings.before_up(collection, element))) {
                elements = swapElements(collection, elements, index, index - 1);
                if (!trueOrUndefined(settings.after_up(collection, element))) {
                    elements = swapElements(collection, elements, index - 1, index);
                }
            }

            if (settings.position_field_selector) {
                return doRewritePositions(settings, elements);
            }

            return elements;
        }
932265
void viewRangeUpdate(int positionStart, int itemCount) {
        final int childCount = getChildCount();
        final int positionEnd = positionStart + itemCount;

        for (int i = 0; i < childCount; i++) {
            final ViewHolder holder = getChildViewHolderInt(getChildAt(i));
            if (holder == null) {
                continue;
            }

            final int position = holder.getPosition();
            if (position >= positionStart && position < positionEnd) {
                holder.addFlags(ViewHolder.FLAG_UPDATE);
                // Binding an attached view will request a layout if needed.
                mAdapter.bindViewHolder(holder, holder.getPosition());
            }
        }
        mRecycler.viewRangeUpdate(positionStart, itemCount);
    }