| Index: Source/core/editing/htmlediting.cpp
|
| diff --git a/Source/core/editing/htmlediting.cpp b/Source/core/editing/htmlediting.cpp
|
| index 9448c574ac74c878882680e8bf7881b3c6b3c3aa..3b20fb9f3f26040d3e399de4f6b848619793c87d 100644
|
| --- a/Source/core/editing/htmlediting.cpp
|
| +++ b/Source/core/editing/htmlediting.cpp
|
| @@ -65,7 +65,7 @@ using namespace HTMLNames;
|
|
|
| // Atomic means that the node has no children, or has children which are ignored for the
|
| // purposes of editing.
|
| -bool isAtomicNode(const Node *node)
|
| +bool isAtomicNode(const Handle<const Node>& node)
|
| {
|
| return node && (!node->hasChildNodes() || editingIgnoresContent(node));
|
| }
|
| @@ -107,15 +107,15 @@ int comparePositions(const VisiblePosition& a, const VisiblePosition& b)
|
| return comparePositions(a.deepEquivalent(), b.deepEquivalent());
|
| }
|
|
|
| -Node* highestEditableRoot(const Position& position, EditableType editableType)
|
| +Result<Node> highestEditableRoot(const Position& position, EditableType editableType)
|
| {
|
| Handle<Node> node = position.deprecatedNode();
|
| if (!node)
|
| - return 0;
|
| + return nullptr;
|
|
|
| Handle<Node> highestRoot = editableRootForPosition(position, editableType);
|
| if (!highestRoot)
|
| - return 0;
|
| + return nullptr;
|
|
|
| node = highestRoot;
|
| while (node) {
|
| @@ -127,20 +127,20 @@ Node* highestEditableRoot(const Position& position, EditableType editableType)
|
| node = node->parentNode();
|
| }
|
|
|
| - return highestRoot.raw();
|
| + return highestRoot;
|
| }
|
|
|
| -Node* lowestEditableAncestor(Node* node)
|
| +Result<Node> lowestEditableAncestor(const Handle<Node>& node)
|
| {
|
| if (!node)
|
| - return 0;
|
| + return nullptr;
|
|
|
| - Node* lowestRoot = 0;
|
| - Handle<Node> current = adoptRawResult(node);
|
| + Handle<Node> lowestRoot;
|
| + Handle<Node> current = node;
|
| while (current) {
|
| HandleScope scope;
|
| if (current->rendererIsEditable())
|
| - return current->rootEditableElement().handle().raw();
|
| + return current->rootEditableElement();
|
| if (current->hasTagName(bodyTag))
|
| break;
|
| current = current->parentNode();
|
| @@ -203,7 +203,7 @@ Result<Element> unsplittableElementForPosition(const Position& p)
|
| {
|
| // Since enclosingNodeOfType won't search beyond the highest root editable node,
|
| // this code works even if the closest table cell was outside of the root editable node.
|
| - Handle<Element> enclosingCell = adoptRawResult(toElement(enclosingNodeOfType(p, &isTableCell)));
|
| + Handle<Element> enclosingCell = toElement(enclosingNodeOfType(p, &isTableCell));
|
| if (enclosingCell)
|
| return enclosingCell;
|
|
|
| @@ -260,11 +260,11 @@ Position previousVisuallyDistinctCandidate(const Position& position)
|
| return Position();
|
| }
|
|
|
| -VisiblePosition firstEditablePositionAfterPositionInRoot(const Position& position, Node* highestRoot)
|
| +VisiblePosition firstEditablePositionAfterPositionInRoot(const Position& position, const Handle<Node>& highestRoot)
|
| {
|
| // position falls before highestRoot.
|
| - if (comparePositions(position, firstPositionInNode(adoptRawResult(highestRoot))) == -1 && highestRoot->rendererIsEditable())
|
| - return firstPositionInNode(adoptRawResult(highestRoot));
|
| + if (comparePositions(position, firstPositionInNode(highestRoot)) == -1 && highestRoot->rendererIsEditable())
|
| + return firstPositionInNode(highestRoot);
|
|
|
| Position p = position;
|
|
|
| @@ -276,39 +276,39 @@ VisiblePosition firstEditablePositionAfterPositionInRoot(const Position& positio
|
| p = positionAfterNode(shadowAncestor);
|
| }
|
|
|
| - while (p.deprecatedNode() && !isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot)) {
|
| + while (p.deprecatedNode() && !isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot.raw())) {
|
| HandleScope scope;
|
| - p = isAtomicNode(p.deprecatedNode().handle().raw()) ? positionInParentAfterNode(p.deprecatedNode()) : nextVisuallyDistinctCandidate(p);
|
| + p = isAtomicNode(p.deprecatedNode()) ? positionInParentAfterNode(p.deprecatedNode()) : nextVisuallyDistinctCandidate(p);
|
| }
|
|
|
| - if (p.deprecatedNode() && p.deprecatedNode() != highestRoot && !p.deprecatedNode()->isDescendantOf(highestRoot))
|
| + if (p.deprecatedNode() && p.deprecatedNode() != highestRoot && !p.deprecatedNode()->isDescendantOf(highestRoot.raw()))
|
| return VisiblePosition();
|
|
|
| return VisiblePosition(p);
|
| }
|
|
|
| -VisiblePosition lastEditablePositionBeforePositionInRoot(const Position& position, Node* highestRoot)
|
| +VisiblePosition lastEditablePositionBeforePositionInRoot(const Position& position, const Handle<Node>& highestRoot)
|
| {
|
| // When position falls after highestRoot, the result is easy to compute.
|
| - if (comparePositions(position, lastPositionInNode(adoptRawResult(highestRoot))) == 1)
|
| - return lastPositionInNode(adoptRawResult(highestRoot));
|
| + if (comparePositions(position, lastPositionInNode(highestRoot)) == 1)
|
| + return lastPositionInNode(highestRoot);
|
|
|
| Position p = position;
|
|
|
| if (position.deprecatedNode()->treeScope() != highestRoot->treeScope()) {
|
| - Node* shadowAncestor = highestRoot->treeScope()->ancestorInThisScope(p.deprecatedNode().handle().raw());
|
| + Handle<Node> shadowAncestor = adoptRawResult(highestRoot->treeScope()->ancestorInThisScope(p.deprecatedNode().handle().raw()));
|
| if (!shadowAncestor)
|
| return VisiblePosition();
|
|
|
| p = firstPositionInOrBeforeNode(shadowAncestor);
|
| }
|
|
|
| - while (p.deprecatedNode() && !isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot)) {
|
| + while (p.deprecatedNode() && !isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot.raw())) {
|
| HandleScope scope;
|
| - p = isAtomicNode(p.deprecatedNode().handle().raw()) ? positionInParentBeforeNode(p.deprecatedNode()) : previousVisuallyDistinctCandidate(p);
|
| + p = isAtomicNode(p.deprecatedNode()) ? positionInParentBeforeNode(p.deprecatedNode()) : previousVisuallyDistinctCandidate(p);
|
| }
|
|
|
| - if (p.deprecatedNode() && p.deprecatedNode() != highestRoot && !p.deprecatedNode()->isDescendantOf(highestRoot))
|
| + if (p.deprecatedNode() && p.deprecatedNode() != highestRoot && !p.deprecatedNode()->isDescendantOf(highestRoot.raw()))
|
| return VisiblePosition();
|
|
|
| return VisiblePosition(p);
|
| @@ -316,12 +316,12 @@ VisiblePosition lastEditablePositionBeforePositionInRoot(const Position& positio
|
|
|
| // FIXME: The method name, comment, and code say three different things here!
|
| // Whether or not content before and after this node will collapse onto the same line as it.
|
| -bool isBlock(const Node* node)
|
| +bool isBlock(const Handle<const Node>& node)
|
| {
|
| return node && node->renderer() && !node->renderer()->isInline() && !node->renderer()->isRubyText();
|
| }
|
|
|
| -bool isInline(const Node* node)
|
| +bool isInline(const Handle<const Node>& node)
|
| {
|
| return node && node->renderer() && node->renderer()->isInline();
|
| }
|
| @@ -330,15 +330,15 @@ bool isInline(const Node* node)
|
| // FIXME: Pass a position to this function. The enclosing block of [table, x] for example, should be the
|
| // block that contains the table and not the table, and this function should be the only one responsible for
|
| // knowing about these kinds of special cases.
|
| -Result<Element> enclosingBlock(Node* node, EditingBoundaryCrossingRule rule)
|
| +Result<Element> enclosingBlock(const Handle<Node>& node, EditingBoundaryCrossingRule rule)
|
| {
|
| - Handle<Node> enclosingNode = adoptRawResult(enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule));
|
| + Handle<Node> enclosingNode = enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule);
|
| return enclosingNode && enclosingNode->isElementNode() ? toElement(enclosingNode) : nullptr;
|
| }
|
|
|
| TextDirection directionOfEnclosingBlock(const Position& position)
|
| {
|
| - Handle<Node> enclosingBlockNode = enclosingBlock(position.containerNode().handle().raw());
|
| + Handle<Node> enclosingBlockNode = enclosingBlock(position.containerNode());
|
| if (!enclosingBlockNode)
|
| return LTR;
|
| RenderObject* renderer = enclosingBlockNode->renderer();
|
| @@ -349,7 +349,7 @@ TextDirection directionOfEnclosingBlock(const Position& position)
|
| // in a node. It returns 1 for some elements even though they do not have children, which
|
| // creates technically invalid DOM Positions. Be sure to call parentAnchoredEquivalent
|
| // on a Position before using it to create a DOM Range, or an exception will be thrown.
|
| -int lastOffsetForEditing(const Node* node)
|
| +int lastOffsetForEditing(const Handle<const Node>& node)
|
| {
|
| ASSERT(node);
|
| if (!node)
|
| @@ -392,7 +392,7 @@ String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
|
| return String::adopt(rebalancedString);
|
| }
|
|
|
| -bool isTableStructureNode(const Node *node)
|
| +bool isTableStructureNode(const Handle<const Node>& node)
|
| {
|
| RenderObject* renderer = node->renderer();
|
| return (renderer && (renderer->isTableCell() || renderer->isTableRow() || renderer->isTableSection() || renderer->isRenderTableCol()));
|
| @@ -405,7 +405,7 @@ const String& nonBreakingSpaceString()
|
| }
|
|
|
| // FIXME: need to dump this
|
| -bool isSpecialElement(const Node *n)
|
| +bool isSpecialElement(const Handle<const Node>& n)
|
| {
|
| if (!n)
|
| return false;
|
| @@ -432,38 +432,40 @@ bool isSpecialElement(const Node *n)
|
| return false;
|
| }
|
|
|
| -static Node* firstInSpecialElement(const Position& pos)
|
| +static Result<Node> firstInSpecialElement(const Position& pos)
|
| {
|
| HandleScope scope;
|
| Handle<Node> rootEditableElement = pos.containerNode()->rootEditableElement();
|
| for (Handle<Node> n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode()) {
|
| HandleScope scope;
|
| - if (isSpecialElement(n.raw())) {
|
| + if (isSpecialElement(n)) {
|
| VisiblePosition vPos = VisiblePosition(pos, DOWNSTREAM);
|
| - VisiblePosition firstInElement = VisiblePosition(firstPositionInOrBeforeNode(n.raw()), DOWNSTREAM);
|
| - if (isTableElement(n.raw()) && vPos == firstInElement.next())
|
| - return n.raw();
|
| + VisiblePosition firstInElement = VisiblePosition(firstPositionInOrBeforeNode(n), DOWNSTREAM);
|
| + if (isTableElement(n) && vPos == firstInElement.next())
|
| + return n;
|
| if (vPos == firstInElement)
|
| - return n.raw();
|
| + return n;
|
| }
|
| }
|
| - return 0;
|
| + return nullptr;
|
| }
|
|
|
| -static Node* lastInSpecialElement(const Position& pos)
|
| +static Result<Node> lastInSpecialElement(const Position& pos)
|
| {
|
| HandleScope scope;
|
| Handle<Node> rootEditableElement = pos.containerNode()->rootEditableElement();
|
| - for (Handle<Node> n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode())
|
| - if (isSpecialElement(n.raw())) {
|
| + for (Handle<Node> n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode()) {
|
| + HandleScope scope;
|
| + if (isSpecialElement(n)) {
|
| VisiblePosition vPos = VisiblePosition(pos, DOWNSTREAM);
|
| - VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfterNode(n.raw()), DOWNSTREAM);
|
| - if (isTableElement(n.raw()) && vPos == lastInElement.previous())
|
| - return n.raw();
|
| + VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfterNode(n), DOWNSTREAM);
|
| + if (isTableElement(n) && vPos == lastInElement.previous())
|
| + return n;
|
| if (vPos == lastInElement)
|
| - return n.raw();
|
| + return n;
|
| }
|
| - return 0;
|
| + }
|
| + return nullptr;
|
| }
|
|
|
| bool isFirstVisiblePositionInSpecialElement(const Position& pos)
|
| @@ -471,12 +473,12 @@ bool isFirstVisiblePositionInSpecialElement(const Position& pos)
|
| return firstInSpecialElement(pos);
|
| }
|
|
|
| -Position positionBeforeContainingSpecialElement(const Position& pos, Node** containingSpecialElement)
|
| +Position positionBeforeContainingSpecialElement(const Position& pos, Handle<Node>* containingSpecialElement)
|
| {
|
| - Node* n = firstInSpecialElement(pos);
|
| + Handle<Node> n = firstInSpecialElement(pos);
|
| if (!n)
|
| return pos;
|
| - Position result = positionInParentBeforeNode(adoptRawResult(n));
|
| + Position result = positionInParentBeforeNode(n);
|
| if (result.isNull() || result.deprecatedNode()->rootEditableElement() != pos.deprecatedNode()->rootEditableElement())
|
| return pos;
|
| if (containingSpecialElement)
|
| @@ -489,12 +491,12 @@ bool isLastVisiblePositionInSpecialElement(const Position& pos)
|
| return lastInSpecialElement(pos);
|
| }
|
|
|
| -Position positionAfterContainingSpecialElement(const Position& pos, Node **containingSpecialElement)
|
| +Position positionAfterContainingSpecialElement(const Position& pos, Handle<Node>* containingSpecialElement)
|
| {
|
| - Node* n = lastInSpecialElement(pos);
|
| + Handle<Node> n = lastInSpecialElement(pos);
|
| if (!n)
|
| return pos;
|
| - Position result = positionInParentAfterNode(adoptRawResult(n));
|
| + Position result = positionInParentAfterNode(n);
|
| if (result.isNull() || result.deprecatedNode()->rootEditableElement() != pos.deprecatedNode()->rootEditableElement())
|
| return pos;
|
| if (containingSpecialElement)
|
| @@ -502,7 +504,7 @@ Position positionAfterContainingSpecialElement(const Position& pos, Node **conta
|
| return result;
|
| }
|
|
|
| -Position positionOutsideContainingSpecialElement(const Position &pos, Node **containingSpecialElement)
|
| +Position positionOutsideContainingSpecialElement(const Position &pos, Handle<Node>* containingSpecialElement)
|
| {
|
| if (isFirstVisiblePositionInSpecialElement(pos))
|
| return positionBeforeContainingSpecialElement(pos, containingSpecialElement);
|
| @@ -511,44 +513,44 @@ Position positionOutsideContainingSpecialElement(const Position &pos, Node **con
|
| return pos;
|
| }
|
|
|
| -Node* isFirstPositionAfterTable(const VisiblePosition& visiblePosition)
|
| +Result<Node> isFirstPositionAfterTable(const VisiblePosition& visiblePosition)
|
| {
|
| Position upstream(visiblePosition.deepEquivalent().upstream());
|
| if (upstream.deprecatedNode() && upstream.deprecatedNode()->renderer() && upstream.deprecatedNode()->renderer()->isTable() && upstream.atLastEditingPositionForNode())
|
| - return upstream.deprecatedNode().handle().raw();
|
| -
|
| - return 0;
|
| + return upstream.deprecatedNode();
|
| +
|
| + return nullptr;
|
| }
|
|
|
| -Node* isLastPositionBeforeTable(const VisiblePosition& visiblePosition)
|
| +Result<Node> isLastPositionBeforeTable(const VisiblePosition& visiblePosition)
|
| {
|
| Position downstream(visiblePosition.deepEquivalent().downstream());
|
| if (downstream.deprecatedNode() && downstream.deprecatedNode()->renderer() && downstream.deprecatedNode()->renderer()->isTable() && downstream.atFirstEditingPositionForNode())
|
| - return downstream.deprecatedNode().handle().raw();
|
| -
|
| - return 0;
|
| + return downstream.deprecatedNode();
|
| +
|
| + return nullptr;
|
| }
|
|
|
| // Returns the visible position at the beginning of a node
|
| -VisiblePosition visiblePositionBeforeNode(Node* node)
|
| +VisiblePosition visiblePositionBeforeNode(const Handle<Node>& node)
|
| {
|
| ASSERT(node);
|
| if (node->childNodeCount())
|
| return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
|
| ASSERT(node->parentNode());
|
| ASSERT(!node->parentNode()->isShadowRoot());
|
| - return positionInParentBeforeNode(adoptRawResult(node));
|
| + return positionInParentBeforeNode(node);
|
| }
|
|
|
| // Returns the visible position at the ending of a node
|
| -VisiblePosition visiblePositionAfterNode(Node* node)
|
| +VisiblePosition visiblePositionAfterNode(const Handle<Node>& node)
|
| {
|
| ASSERT(node);
|
| if (node->childNodeCount())
|
| return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM);
|
| ASSERT(node->parentNode());
|
| ASSERT(!node->parentNode()->isShadowRoot());
|
| - return positionInParentAfterNode(adoptRawResult(node));
|
| + return positionInParentAfterNode(node);
|
| }
|
|
|
| // Create a range object with two visible positions, start and end.
|
| @@ -569,17 +571,17 @@ Result<Range> createRange(const Handle<Document>& document, const VisiblePositio
|
| // Call this function before copying / moving paragraphs to contain all wrapping nodes.
|
| // This function stops extending the range immediately below rootNode; i.e. the extended range can contain a child node of rootNode
|
| // but it can never contain rootNode itself.
|
| -Result<Range> extendRangeToWrappingNodes(const Handle<Range>& range, const Handle<const Range>& maximumRange, const Node* rootNode)
|
| +Result<Range> extendRangeToWrappingNodes(const Handle<Range>& range, const Handle<const Range>& maximumRange, const Handle<const Node>& rootNode)
|
| {
|
| ASSERT(range);
|
| ASSERT(maximumRange);
|
|
|
| Handle<Node> ancestor = range->commonAncestorContainer(IGNORE_EXCEPTION); // Find the closest common ancestor.
|
| - Node* highestNode = 0;
|
| + Handle<Node> highestNode;
|
| // traverse through ancestors as long as they are contained within the range, content-editable, and below rootNode (could be =0).
|
| - while (ancestor && ancestor->rendererIsEditable() && isNodeVisiblyContainedWithin(ancestor.raw(), maximumRange) && ancestor != rootNode) {
|
| + while (ancestor && ancestor->rendererIsEditable() && isNodeVisiblyContainedWithin(ancestor, maximumRange) && ancestor != rootNode) {
|
| HandleScope scope;
|
| - highestNode = ancestor.raw();
|
| + highestNode = ancestor;
|
| ancestor = ancestor->parentNode();
|
| }
|
|
|
| @@ -588,142 +590,142 @@ Result<Range> extendRangeToWrappingNodes(const Handle<Range>& range, const Handl
|
|
|
| // Create new range with the highest editable node contained within the range
|
| Handle<Range> extendedRange = Range::create(range->ownerDocument());
|
| - extendedRange->selectNode(adoptRawResult(highestNode), IGNORE_EXCEPTION);
|
| + extendedRange->selectNode(highestNode, IGNORE_EXCEPTION);
|
| return extendedRange;
|
| }
|
|
|
| -bool isListElement(Node *n)
|
| +bool isListElement(const Handle<Node>& n)
|
| {
|
| return (n && (n->hasTagName(ulTag) || n->hasTagName(olTag) || n->hasTagName(dlTag)));
|
| }
|
|
|
| -bool isListItem(const Node *n)
|
| +bool isListItem(const Handle<const Node>& n)
|
| {
|
| return n && n->renderer() && n->renderer()->isListItem();
|
| }
|
|
|
| -Node* enclosingNodeWithTag(const Position& p, const QualifiedName& tagName)
|
| +Result<Node> enclosingNodeWithTag(const Position& p, const QualifiedName& tagName)
|
| {
|
| HandleScope scope;
|
|
|
| if (p.isNull())
|
| - return 0;
|
| -
|
| - Node* root = highestEditableRoot(p);
|
| + return nullptr;
|
| +
|
| + Handle<Node> root = highestEditableRoot(p);
|
| for (Handle<Node> n = p.deprecatedNode(); n; n = n->parentNode()) {
|
| HandleScope scope;
|
| if (root && !n->rendererIsEditable())
|
| continue;
|
| if (n->hasTagName(tagName))
|
| - return n.raw();
|
| + return n;
|
| if (n == root)
|
| - return 0;
|
| + return nullptr;
|
| }
|
|
|
| - return 0;
|
| + return nullptr;
|
| }
|
|
|
| -Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule rule)
|
| +Result<Node> enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Handle<const Node>&), EditingBoundaryCrossingRule rule)
|
| {
|
| HandleScope scope;
|
|
|
| // FIXME: support CanSkipCrossEditingBoundary
|
| ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary);
|
| if (p.isNull())
|
| - return 0;
|
| + return nullptr;
|
|
|
| - Node* root = rule == CannotCrossEditingBoundary ? highestEditableRoot(p) : 0;
|
| + Handle<Node> root = rule == CannotCrossEditingBoundary ? highestEditableRoot(p) : nullptr;
|
| for (Handle<Node> n = p.deprecatedNode(); n; n = n->parentNode()) {
|
| HandleScope scope;
|
| // Don't return a non-editable node if the input position was editable, since
|
| // the callers from editing will no doubt want to perform editing inside the returned node.
|
| if (root && !n->rendererIsEditable())
|
| continue;
|
| - if (nodeIsOfType(n.raw()))
|
| - return n.raw();
|
| - if (n.raw() == root)
|
| - return 0;
|
| + if (nodeIsOfType(n))
|
| + return n;
|
| + if (n == root)
|
| + return nullptr;
|
| }
|
| -
|
| - return 0;
|
| +
|
| + return nullptr;
|
| }
|
|
|
| -Node* highestEnclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule rule, Node* stayWithin)
|
| +Result<Node> highestEnclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Handle<const Node>&), EditingBoundaryCrossingRule rule, const Handle<Node>& stayWithin)
|
| {
|
| HandleScope scope;
|
|
|
| - Node* highest = 0;
|
| - Node* root = rule == CannotCrossEditingBoundary ? highestEditableRoot(p) : 0;
|
| - for (Handle<Node> n = p.containerNode(); n && n.raw() != stayWithin; n = n->parentNode()) {
|
| + Handle<Node> highest;
|
| + Handle<Node> root = rule == CannotCrossEditingBoundary ? highestEditableRoot(p) : nullptr;
|
| + for (Handle<Node> n = p.containerNode(); n && n != stayWithin; n = n->parentNode()) {
|
| HandleScope scope;
|
| if (root && !n->rendererIsEditable())
|
| continue;
|
| - if (nodeIsOfType(n.raw()))
|
| - highest = n.raw();
|
| + if (nodeIsOfType(n))
|
| + highest = n;
|
| if (n == root)
|
| break;
|
| }
|
| -
|
| +
|
| return highest;
|
| }
|
|
|
| -static bool hasARenderedDescendant(Node* node, Node* excludedNode)
|
| +static bool hasARenderedDescendant(const Handle<Node>& node, const Handle<Node>& excludedNode)
|
| {
|
| for (Handle<Node> n = node->firstChild(); n;) {
|
| HandleScope scope;
|
| if (n == excludedNode) {
|
| - n = NodeTraversal::nextSkippingChildren(n, adoptRawResult(node));
|
| + n = NodeTraversal::nextSkippingChildren(n, node);
|
| continue;
|
| }
|
| if (n->renderer())
|
| return true;
|
| - n = NodeTraversal::next(n, adoptRawResult(node));
|
| + n = NodeTraversal::next(n, node);
|
| }
|
| return false;
|
| }
|
|
|
| -Node* highestNodeToRemoveInPruning(Node* node)
|
| +Result<Node> highestNodeToRemoveInPruning(const Handle<Node>& node)
|
| {
|
| HandleScope scope;
|
| Handle<Node> previousNode;
|
| Handle<Node> rootEditableElement = node ? node->rootEditableElement() : nullptr;
|
| - Handle<Node> current = adoptRawResult(node);
|
| + Handle<Node> current = node;
|
| for (; current; current = current->parentNode()) {
|
| HandleScope scope;
|
| if (RenderObject* renderer = current->renderer()) {
|
| - if (!renderer->canHaveChildren() || hasARenderedDescendant(current.raw(), previousNode.raw()) || rootEditableElement == current)
|
| - return previousNode.raw();
|
| + if (!renderer->canHaveChildren() || hasARenderedDescendant(current, previousNode) || rootEditableElement == current)
|
| + return previousNode;
|
| }
|
| previousNode = current;
|
| }
|
| - return 0;
|
| + return nullptr;
|
| }
|
|
|
| -Node* enclosingTableCell(const Position& p)
|
| +Result<Node> enclosingTableCell(const Position& p)
|
| {
|
| return toElement(enclosingNodeOfType(p, isTableCell));
|
| }
|
|
|
| -Node* enclosingAnchorElement(const Position& p)
|
| +Result<Node> enclosingAnchorElement(const Position& p)
|
| {
|
| if (p.isNull())
|
| - return 0;
|
| + return nullptr;
|
|
|
| Handle<Node> node = p.deprecatedNode();
|
| while (node && !(node->isElementNode() && node->isLink())) {
|
| NoHandleScope scope;
|
| node = node->parentNode();
|
| }
|
| - return node.raw();
|
| + return node;
|
| }
|
|
|
| -Result<HTMLElement> enclosingList(Node* node)
|
| +Result<HTMLElement> enclosingList(const Handle<Node>& node)
|
| {
|
| HandleScope scope;
|
| if (!node)
|
| return nullptr;
|
|
|
| - Node* root = highestEditableRoot(firstPositionInOrBeforeNode(node));
|
| + Handle<Node> root = highestEditableRoot(firstPositionInOrBeforeNode(node));
|
|
|
| for (Handle<ContainerNode> n = node->parentNode(); n; n = n->parentNode()) {
|
| HandleScope scope;
|
| @@ -736,86 +738,88 @@ Result<HTMLElement> enclosingList(Node* node)
|
| return nullptr;
|
| }
|
|
|
| -Node* enclosingListChild(Node *node)
|
| +Result<Node> enclosingListChild(const Handle<Node>& node)
|
| {
|
| if (!node)
|
| - return 0;
|
| + return nullptr;
|
|
|
| HandleScope scope;
|
|
|
| // Check for a list item element, or for a node whose parent is a list element. Such a node
|
| // will appear visually as a list item (but without a list marker)
|
| - Node* root = highestEditableRoot(firstPositionInOrBeforeNode(node));
|
| + Handle<Node> root = highestEditableRoot(firstPositionInOrBeforeNode(node));
|
|
|
| // FIXME: This function is inappropriately named if it starts with node instead of node->parentNode()
|
| - for (Node* n = node; n && n->parentNode(); n = n->parentNode().handle().raw()) {
|
| + for (Handle<Node> n = node; n && n->parentNode(); n = n->parentNode()) {
|
| HandleScope scope;
|
| - if (n->hasTagName(liTag) || (isListElement(n->parentNode().handle().raw()) && n != root))
|
| + if (n->hasTagName(liTag) || (isListElement(n->parentNode()) && n != root))
|
| return n;
|
| if (n == root || isTableCell(n))
|
| - return 0;
|
| + return nullptr;
|
| }
|
| -
|
| - return 0;
|
| +
|
| + return nullptr;
|
| }
|
|
|
| -static Result<HTMLElement> embeddedSublist(Node* listItem)
|
| +static Result<HTMLElement> embeddedSublist(const Handle<Node>& listItem)
|
| {
|
| // Check the DOM so that we'll find collapsed sublists without renderers.
|
| for (Handle<Node> n = listItem->firstChild(); n; n = n->nextSibling()) {
|
| - if (isListElement(n.raw()))
|
| + HandleScope scope;
|
| + if (isListElement(n))
|
| return toHTMLElement(n);
|
| }
|
| -
|
| +
|
| return nullptr;
|
| }
|
|
|
| -static Node* appendedSublist(Node* listItem)
|
| +static Result<Node> appendedSublist(const Handle<Node>& listItem)
|
| {
|
| // Check the DOM so that we'll find collapsed sublists without renderers.
|
| for (Handle<Node> n = listItem->nextSibling(); n; n = n->nextSibling()) {
|
| - if (isListElement(n.raw()))
|
| - return toHTMLElement(n).handle().raw();
|
| + HandleScope scope;
|
| + if (isListElement(n))
|
| + return toHTMLElement(n);
|
| if (isListItem(listItem))
|
| - return 0;
|
| + return nullptr;
|
| }
|
| -
|
| - return 0;
|
| +
|
| + return nullptr;
|
| }
|
|
|
| // FIXME: This method should not need to call isStartOfParagraph/isEndOfParagraph
|
| -Node* enclosingEmptyListItem(const VisiblePosition& visiblePos)
|
| +Result<Node> enclosingEmptyListItem(const VisiblePosition& visiblePos)
|
| {
|
| // Check that position is on a line by itself inside a list item
|
| - Node* listChildNode = enclosingListChild(visiblePos.deepEquivalent().deprecatedNode().handle().raw());
|
| + Handle<Node> listChildNode = enclosingListChild(visiblePos.deepEquivalent().deprecatedNode());
|
| if (!listChildNode || !isStartOfParagraph(visiblePos) || !isEndOfParagraph(visiblePos))
|
| - return 0;
|
| + return nullptr;
|
|
|
| VisiblePosition firstInListChild(firstPositionInOrBeforeNode(listChildNode));
|
| VisiblePosition lastInListChild(lastPositionInOrAfterNode(listChildNode));
|
|
|
| if (firstInListChild != visiblePos || lastInListChild != visiblePos)
|
| - return 0;
|
| -
|
| + return nullptr;
|
| +
|
| if (embeddedSublist(listChildNode) || appendedSublist(listChildNode))
|
| - return 0;
|
| -
|
| + return nullptr;
|
| +
|
| return listChildNode;
|
| }
|
|
|
| -Result<HTMLElement> outermostEnclosingList(Node* node, Node* rootList)
|
| +Result<HTMLElement> outermostEnclosingList(const Handle<Node>& node, const Handle<Node>& rootList)
|
| {
|
| Handle<HTMLElement> list = enclosingList(node);
|
| if (!list)
|
| return nullptr;
|
|
|
| - Handle<HTMLElement> nextList = enclosingList(list.raw());
|
| + Handle<HTMLElement> nextList = enclosingList(list);
|
| while (nextList) {
|
| HandleScope scope;
|
| if (nextList == rootList)
|
| break;
|
| list = nextList;
|
| - nextList = enclosingList(list.raw());
|
| + nextList = enclosingList(list);
|
| }
|
|
|
| return list;
|
| @@ -841,7 +845,7 @@ Result<Node> highestAncestor(const Handle<Node>& node)
|
| }
|
|
|
| // FIXME: do not require renderer, so that this can be used within fragments, or rename to isRenderedTable()
|
| -bool isTableElement(Node* n)
|
| +bool isTableElement(const Handle<Node>& n)
|
| {
|
| if (!n || !n->isElementNode())
|
| return false;
|
| @@ -850,7 +854,7 @@ bool isTableElement(Node* n)
|
| return (renderer && (renderer->style()->display() == TABLE || renderer->style()->display() == INLINE_TABLE));
|
| }
|
|
|
| -bool isTableCell(const Node* node)
|
| +bool isTableCell(const Handle<const Node>& node)
|
| {
|
| RenderObject* r = node->renderer();
|
| if (!r)
|
| @@ -859,7 +863,7 @@ bool isTableCell(const Node* node)
|
| return r->isTableCell();
|
| }
|
|
|
| -bool isEmptyTableCell(const Node* node)
|
| +bool isEmptyTableCell(const Handle<const Node>& node)
|
| {
|
| // Returns true IFF the passed in node is one of:
|
| // .) a table cell with no children,
|
| @@ -867,16 +871,17 @@ bool isEmptyTableCell(const Node* node)
|
| // .) the BR child of such a table cell
|
|
|
| // Find rendered node
|
| - while (node && !node->renderer()) {
|
| + Handle<const Node> current = node;
|
| + while (current && !current->renderer()) {
|
| HandleScope scope;
|
| - node = node->parentNode().handle().raw();
|
| + current = current->parentNode();
|
| }
|
| - if (!node)
|
| + if (!current)
|
| return false;
|
|
|
| // Make sure the rendered node is a table cell or <br>.
|
| // If it's a <br>, then the parent node has to be a table cell.
|
| - RenderObject* renderer = node->renderer();
|
| + RenderObject* renderer = current->renderer();
|
| if (renderer->isBR()) {
|
| renderer = renderer->parent();
|
| if (!renderer)
|
| @@ -937,27 +942,27 @@ Result<HTMLElement> createHTMLElement(const Handle<Document>& document, const At
|
| return createHTMLElement(document, QualifiedName(nullAtom, tagName, xhtmlNamespaceURI));
|
| }
|
|
|
| -bool isTabSpanNode(const Node *node)
|
| +bool isTabSpanNode(const Handle<const Node>& node)
|
| {
|
| - return node && node->hasTagName(spanTag) && node->isElementNode() && static_cast<const Element *>(node)->getAttribute(classAttr) == AppleTabSpanClass;
|
| + return node && node->hasTagName(spanTag) && node->isElementNode() && Handle<const Element>::cast(node)->getAttribute(classAttr) == AppleTabSpanClass;
|
| }
|
|
|
| -bool isTabSpanTextNode(const Node *node)
|
| +bool isTabSpanTextNode(const Handle<const Node>& node)
|
| {
|
| - return node && node->isTextNode() && node->parentNode() && isTabSpanNode(node->parentNode().handle().raw());
|
| + return node && node->isTextNode() && node->parentNode() && isTabSpanNode(node->parentNode());
|
| }
|
|
|
| -Node* tabSpanNode(const Node *node)
|
| +Result<Node> tabSpanNode(const Handle<const Node>& node)
|
| {
|
| - return isTabSpanTextNode(node) ? node->parentNode().handle().raw() : 0;
|
| + return isTabSpanTextNode(node) ? node->parentNode() : nullptr;
|
| }
|
|
|
| Position positionOutsideTabSpan(const Position& pos)
|
| {
|
| Handle<Node> node = pos.containerNode();
|
| - if (isTabSpanTextNode(node.raw()))
|
| - node = adoptRawResult(tabSpanNode(node.raw()));
|
| - else if (!isTabSpanNode(node.raw()))
|
| + if (isTabSpanTextNode(node))
|
| + node = tabSpanNode(node);
|
| + else if (!isTabSpanNode(node))
|
| return pos;
|
|
|
| if (node && VisiblePosition(pos) == lastPositionInNode(node))
|
| @@ -994,7 +999,7 @@ Result<Element> createTabSpanElement(const Handle<Document>& document)
|
| return createTabSpanElement(document, PassRefPtr<Node>());
|
| }
|
|
|
| -bool isNodeRendered(const Node *node)
|
| +bool isNodeRendered(const Handle<const Node>& node)
|
| {
|
| if (!node)
|
| return false;
|
| @@ -1012,52 +1017,52 @@ unsigned numEnclosingMailBlockquotes(const Position& p)
|
| unsigned num = 0;
|
| for (Handle<Node> n = p.deprecatedNode(); n; n = n->parentNode()) {
|
| HandleScope scope;
|
| - if (isMailBlockquote(n.raw()))
|
| + if (isMailBlockquote(n))
|
| num++;
|
| }
|
|
|
| return num;
|
| }
|
|
|
| -void updatePositionForNodeRemoval(Position& position, Node* node)
|
| +void updatePositionForNodeRemoval(Position& position, const Handle<Node>& node)
|
| {
|
| if (position.isNull())
|
| return;
|
| switch (position.anchorType()) {
|
| case Position::PositionIsBeforeChildren:
|
| if (position.containerNode() == node)
|
| - position = positionInParentBeforeNode(adoptRawResult(node));
|
| + position = positionInParentBeforeNode(node);
|
| break;
|
| case Position::PositionIsAfterChildren:
|
| if (position.containerNode() == node)
|
| - position = positionInParentAfterNode(adoptRawResult(node));
|
| + position = positionInParentAfterNode(node);
|
| break;
|
| case Position::PositionIsOffsetInAnchor:
|
| if (position.containerNode() == node->parentNode() && static_cast<unsigned>(position.offsetInContainerNode()) > node->nodeIndex())
|
| position.moveToOffset(position.offsetInContainerNode() - 1);
|
| else if (node->containsIncludingShadowDOM(position.containerNode()))
|
| - position = positionInParentBeforeNode(adoptRawResult(node));
|
| + position = positionInParentBeforeNode(node);
|
| break;
|
| case Position::PositionIsAfterAnchor:
|
| if (node->containsIncludingShadowDOM(position.anchorNode()))
|
| - position = positionInParentAfterNode(adoptRawResult(node));
|
| + position = positionInParentAfterNode(node);
|
| break;
|
| case Position::PositionIsBeforeAnchor:
|
| if (node->containsIncludingShadowDOM(position.anchorNode()))
|
| - position = positionInParentBeforeNode(adoptRawResult(node));
|
| + position = positionInParentBeforeNode(node);
|
| break;
|
| }
|
| }
|
|
|
| -bool isMailBlockquote(const Node *node)
|
| +bool isMailBlockquote(const Handle<const Node>& node)
|
| {
|
| if (!node || !node->hasTagName(blockquoteTag))
|
| return false;
|
| -
|
| - return static_cast<const Element *>(node)->getAttribute("type") == "cite";
|
| +
|
| + return Handle<const Element>::cast(node)->getAttribute("type") == "cite";
|
| }
|
|
|
| -int caretMinOffset(const Node* n)
|
| +int caretMinOffset(const Handle<const Node>& n)
|
| {
|
| RenderObject* r = n->renderer();
|
| ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a runtime check that seemingly couldn't fail; changed it to an assertion for now.
|
| @@ -1066,7 +1071,7 @@ int caretMinOffset(const Node* n)
|
|
|
| // If a node can contain candidates for VisiblePositions, return the offset of the last candidate, otherwise
|
| // return the number of children for container nodes and the length for unrendered text nodes.
|
| -int caretMaxOffset(const Node* n)
|
| +int caretMaxOffset(const Handle<const Node>& n)
|
| {
|
| // For rendered text nodes, return the last position that a caret could occupy.
|
| if (n->isTextNode() && n->renderer())
|
| @@ -1112,16 +1117,16 @@ VisibleSelection selectionForParagraphIteration(const VisibleSelection& original
|
| // if the start of the selection is inside that table, then the last paragraph
|
| // that we'll want modify is the last one inside the table, not the table itself
|
| // (a table is itself a paragraph).
|
| - if (Node* table = isFirstPositionAfterTable(endOfSelection))
|
| - if (startOfSelection.deepEquivalent().deprecatedNode()->isDescendantOf(table))
|
| + if (Handle<Node> table = isFirstPositionAfterTable(endOfSelection))
|
| + if (startOfSelection.deepEquivalent().deprecatedNode()->isDescendantOf(table.raw()))
|
| newSelection = VisibleSelection(startOfSelection, endOfSelection.previous(CannotCrossEditingBoundary));
|
|
|
| // If the start of the selection to modify is just before a table,
|
| // and if the end of the selection is inside that table, then the first paragraph
|
| // we'll want to modify is the first one inside the table, not the paragraph
|
| // containing the table itself.
|
| - if (Node* table = isLastPositionBeforeTable(startOfSelection))
|
| - if (endOfSelection.deepEquivalent().deprecatedNode()->isDescendantOf(table))
|
| + if (Handle<Node> table = isLastPositionBeforeTable(startOfSelection))
|
| + if (endOfSelection.deepEquivalent().deprecatedNode()->isDescendantOf(table.raw()))
|
| newSelection = VisibleSelection(startOfSelection.next(CannotCrossEditingBoundary), endOfSelection);
|
|
|
| return newSelection;
|
| @@ -1171,26 +1176,26 @@ bool isVisiblyAdjacent(const Position& first, const Position& second)
|
|
|
| // Determines whether a node is inside a range or visibly starts and ends at the boundaries of the range.
|
| // Call this function to determine whether a node is visibly fit inside selectedRange
|
| -bool isNodeVisiblyContainedWithin(Node* node, const Handle<const Range>& selectedRange)
|
| +bool isNodeVisiblyContainedWithin(const Handle<Node>& node, const Handle<const Range>& selectedRange)
|
| {
|
| ASSERT(node);
|
| ASSERT(selectedRange);
|
| // If the node is inside the range, then it surely is contained within
|
| - if (selectedRange->compareNode(adoptRawResult(node), IGNORE_EXCEPTION) == Range::NODE_INSIDE)
|
| + if (selectedRange->compareNode(node, IGNORE_EXCEPTION) == Range::NODE_INSIDE)
|
| return true;
|
|
|
| bool startIsVisuallySame = visiblePositionBeforeNode(node) == selectedRange->startPosition();
|
| - if (startIsVisuallySame && comparePositions(positionInParentAfterNode(adoptRawResult(node)), selectedRange->endPosition()) < 0)
|
| + if (startIsVisuallySame && comparePositions(positionInParentAfterNode(node), selectedRange->endPosition()) < 0)
|
| return true;
|
|
|
| bool endIsVisuallySame = visiblePositionAfterNode(node) == selectedRange->endPosition();
|
| - if (endIsVisuallySame && comparePositions(selectedRange->startPosition(), positionInParentBeforeNode(adoptRawResult(node))) < 0)
|
| + if (endIsVisuallySame && comparePositions(selectedRange->startPosition(), positionInParentBeforeNode(node)) < 0)
|
| return true;
|
|
|
| return startIsVisuallySame && endIsVisuallySame;
|
| }
|
|
|
| -bool isRenderedAsNonInlineTableImageOrHR(const Node* node)
|
| +bool isRenderedAsNonInlineTableImageOrHR(const Handle<const Node>& node)
|
| {
|
| if (!node)
|
| return false;
|
| @@ -1198,20 +1203,20 @@ bool isRenderedAsNonInlineTableImageOrHR(const Node* node)
|
| return renderer && ((renderer->isTable() && !renderer->isInline()) || (renderer->isImage() && !renderer->isInline()) || renderer->isHR());
|
| }
|
|
|
| -bool areIdenticalElements(const Node* first, const Node* second)
|
| +bool areIdenticalElements(const Handle<const Node>& first, const Handle<const Node>& second)
|
| {
|
| if (!first->isElementNode() || !second->isElementNode())
|
| return false;
|
|
|
| - Handle<const Element> firstElement = adoptRawResult(toElement(first));
|
| - Handle<const Element> secondElement = adoptRawResult(toElement(second));
|
| + Handle<const Element> firstElement = toConstElement(first);
|
| + Handle<const Element> secondElement = toConstElement(second);
|
| if (!firstElement->hasTagName(secondElement->tagQName()))
|
| return false;
|
|
|
| return firstElement->hasEquivalentAttributes(secondElement);
|
| }
|
|
|
| -bool isNonTableCellHTMLBlockElement(const Node* node)
|
| +bool isNonTableCellHTMLBlockElement(const Handle<const Node>& node)
|
| {
|
| return node->hasTagName(listingTag)
|
| || node->hasTagName(olTag)
|
|
|