static HTMLElement* highestAncestorToWrapMarkup(const Range* range, EAnnotateForInterchange shouldAnnotate, Node* constrainingAncestor) { Node* commonAncestor = range->commonAncestorContainer(); ASSERT(commonAncestor); HTMLElement* specialCommonAncestor = 0; Node* checkAncestor = specialCommonAncestor ? specialCommonAncestor : commonAncestor; if (checkAncestor->renderer()) { HTMLElement* newSpecialCommonAncestor = toHTMLElement(highestEnclosingNodeOfType(firstPositionInNode(checkAncestor), &isPresentationalHTMLElement, CanCrossEditingBoundary, constrainingAncestor)); if (newSpecialCommonAncestor) specialCommonAncestor = newSpecialCommonAncestor; } if (HTMLAnchorElement* enclosingAnchor = toHTMLAnchorElement(enclosingElementWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : commonAncestor), HTMLNames::aTag))) specialCommonAncestor = enclosingAnchor; return specialCommonAncestor; }
static HTMLElement* highestAncestorToWrapMarkup( const PositionTemplate<Strategy>& startPosition, const PositionTemplate<Strategy>& endPosition, EAnnotateForInterchange shouldAnnotate, Node* constrainingAncestor) { Node* firstNode = startPosition.nodeAsRangeFirstNode(); // For compatibility reason, we use container node of start and end // positions rather than first node and last node in selection. Node* commonAncestor = Strategy::commonAncestor(*startPosition.computeContainerNode(), *endPosition.computeContainerNode()); DCHECK(commonAncestor); HTMLElement* specialCommonAncestor = nullptr; if (shouldAnnotate == AnnotateForInterchange) { // Include ancestors that aren't completely inside the range but are // required to retain the structure and appearance of the copied markup. specialCommonAncestor = ancestorToRetainStructureAndAppearance(commonAncestor); if (Node* parentListNode = enclosingNodeOfType( firstPositionInOrBeforeNode(firstNode), isListItem)) { EphemeralRangeTemplate<Strategy> markupRange = EphemeralRangeTemplate<Strategy>(startPosition, endPosition); EphemeralRangeTemplate<Strategy> nodeRange = normalizeRange( EphemeralRangeTemplate<Strategy>::rangeOfContents(*parentListNode)); if (nodeRange == markupRange) { ContainerNode* ancestor = parentListNode->parentNode(); while (ancestor && !isHTMLListElement(ancestor)) ancestor = ancestor->parentNode(); specialCommonAncestor = toHTMLElement(ancestor); } } // Retain the Mail quote level by including all ancestor mail block quotes. if (HTMLQuoteElement* highestMailBlockquote = toHTMLQuoteElement(highestEnclosingNodeOfType( firstPositionInOrBeforeNode(firstNode), isMailHTMLBlockquoteElement, CanCrossEditingBoundary))) specialCommonAncestor = highestMailBlockquote; } Node* checkAncestor = specialCommonAncestor ? specialCommonAncestor : commonAncestor; if (checkAncestor->layoutObject()) { HTMLElement* newSpecialCommonAncestor = toHTMLElement(highestEnclosingNodeOfType( Position::firstPositionInNode(checkAncestor), &isPresentationalHTMLElement, CanCrossEditingBoundary, constrainingAncestor)); if (newSpecialCommonAncestor) specialCommonAncestor = newSpecialCommonAncestor; } // If a single tab is selected, commonAncestor will be a text node inside a // tab span. If two or more tabs are selected, commonAncestor will be the tab // span. In either case, if there is a specialCommonAncestor already, it will // necessarily be above any tab span that needs to be included. if (!specialCommonAncestor && isTabHTMLSpanElementTextNode(commonAncestor)) specialCommonAncestor = toHTMLSpanElement(Strategy::parent(*commonAncestor)); if (!specialCommonAncestor && isTabHTMLSpanElement(commonAncestor)) specialCommonAncestor = toHTMLSpanElement(commonAncestor); if (HTMLAnchorElement* enclosingAnchor = toHTMLAnchorElement(enclosingElementWithTag( Position::firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : commonAncestor), aTag))) specialCommonAncestor = enclosingAnchor; return specialCommonAncestor; }