PositionTemplate<Strategy> PositionTemplate<Strategy>::toOffsetInAnchor() const { if (isNull()) return PositionTemplate<Strategy>(); return PositionTemplate<Strategy>(computeContainerNode(), computeOffsetInContainerNode()); }
// Neighbor-anchored positions are invalid DOM positions, so they need to be // fixed up before handing them off to the Range object. Position Position::parentAnchoredEquivalent() const { if (!m_anchorNode) return Position(); // FIXME: This should only be necessary for legacy positions, but is also needed for positions before and after Tables if (m_offset <= 0 && m_anchorType != PositionIsAfterAnchor) { if (m_anchorNode->parentNode() && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get()))) return positionInParentBeforeNode(m_anchorNode.get()); return firstPositionInOrBeforeNode(m_anchorNode.get()); } if (!m_anchorNode->offsetInCharacters() && (m_anchorType == PositionIsAfterAnchor || static_cast<unsigned>(m_offset) == m_anchorNode->childNodeCount()) && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get())) && containerNode()) { return positionInParentAfterNode(m_anchorNode.get()); } return Position(containerNode(), computeOffsetInContainerNode(), PositionIsOffsetInAnchor); }
PositionTemplate<Strategy> PositionTemplate<Strategy>::parentAnchoredEquivalent() const { if (!m_anchorNode) return PositionTemplate<Strategy>(); // FIXME: This should only be necessary for legacy positions, but is also needed for positions before and after Tables if (m_offset == 0 && !isAfterAnchorOrAfterChildren()) { if (Strategy::parent(*m_anchorNode) && (Strategy::editingIgnoresContent(m_anchorNode.get()) || isDisplayInsideTable(m_anchorNode.get()))) return inParentBeforeNode(*m_anchorNode); return PositionTemplate<Strategy>(m_anchorNode.get(), 0); } if (!m_anchorNode->offsetInCharacters() && (isAfterAnchorOrAfterChildren() || static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()) && (Strategy::editingIgnoresContent(m_anchorNode.get()) || isDisplayInsideTable(m_anchorNode.get())) && computeContainerNode()) { return inParentAfterNode(*m_anchorNode); } return PositionTemplate<Strategy>(computeContainerNode(), computeOffsetInContainerNode()); }