// When inserting a new line, we want to avoid nesting empty divs if we can. Otherwise, when // pasting, it's easy to have each new line be a div deeper than the previous. E.g., in the case // below, we want to insert at ^ instead of |. // <div>foo<div>bar</div>|</div>^ static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock) { Element* curBlock = startBlock; // We don't want to return a root node (if it happens to be a div, e.g., in a document fragment) because there are no // siblings for us to append to. while (!curBlock->nextSibling() && curBlock->parentElement()->hasTagName(divTag) && curBlock->parentElement()->parentElement()) { NamedNodeMap* attributes = curBlock->parentElement()->attributes(true); if (attributes && !attributes->isEmpty()) break; curBlock = curBlock->parentElement(); } return curBlock; }