CTTE: Teach CompositeEditCommand that link Nodes are always Elements.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Oct 2013 08:37:29 +0000 (08:37 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Oct 2013 08:37:29 +0000 (08:37 +0000)
<https://webkit.org/b/122400>

Reviewed by Sam Weinig.

Make pushAnchorElementDown() take an Element& instead of a Node* and
tweak the surrounding code a tiny bit.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156987 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/CreateLinkCommand.cpp
Source/WebCore/editing/htmlediting.cpp

index 3fe554f..b038720 100644 (file)
@@ -1,5 +1,15 @@
 2013-10-06  Andreas Kling  <akling@apple.com>
 
+        CTTE: Teach CompositeEditCommand that link Nodes are always Elements.
+        <https://webkit.org/b/122400>
+
+        Reviewed by Sam Weinig.
+
+        Make pushAnchorElementDown() take an Element& instead of a Node* and
+        tweak the surrounding code a tiny bit.
+
+2013-10-06  Andreas Kling  <akling@apple.com>
+
         CTTE: Node::enclosingLinkEventParentOrSelf() should return an Element.
         <https://webkit.org/b/122401>
 
index 687c741..9f50cd6 100644 (file)
@@ -971,18 +971,15 @@ PassRefPtr<Node> CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessar
     return newBlock.release();
 }
 
-void CompositeEditCommand::pushAnchorElementDown(Node* anchorNode)
+void CompositeEditCommand::pushAnchorElementDown(Element& anchorElement)
 {
-    if (!anchorNode)
-        return;
-    
-    ASSERT(anchorNode->isLink());
+    ASSERT(anchorElement.isLink());
     
-    setEndingSelection(VisibleSelection::selectionFromContentsOfNode(anchorNode));
-    applyStyledElement(toElement(anchorNode));
-    // Clones of anchorNode have been pushed down, now remove it.
-    if (anchorNode->inDocument())
-        removeNodePreservingChildren(anchorNode);
+    setEndingSelection(VisibleSelection::selectionFromContentsOfNode(&anchorElement));
+    applyStyledElement(&anchorElement);
+    // Clones of anchorElement have been pushed down, now remove it.
+    if (anchorElement.inDocument())
+        removeNodePreservingChildren(&anchorElement);
 }
 
 // Clone the paragraph between start and end under blockElement,
@@ -1397,7 +1394,7 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
         return original;
         
     VisiblePosition visiblePos(original);
-    Node* enclosingAnchor = enclosingAnchorElement(original);
+    Element* enclosingAnchor = enclosingAnchorElement(original);
     Position result = original;
 
     if (!enclosingAnchor)
@@ -1413,7 +1410,7 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
             // Make sure anchors are pushed down before avoiding them so that we don't
             // also avoid structural elements like lists and blocks (5142012).
             if (original.deprecatedNode() != enclosingAnchor && original.deprecatedNode()->parentNode() != enclosingAnchor) {
-                pushAnchorElementDown(enclosingAnchor);
+                pushAnchorElementDown(*enclosingAnchor);
                 enclosingAnchor = enclosingAnchorElement(original);
                 if (!enclosingAnchor)
                     return original;
@@ -1432,7 +1429,7 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
             // Make sure anchors are pushed down before avoiding them so that we don't
             // also avoid structural elements like lists and blocks (5142012).
             if (original.deprecatedNode() != enclosingAnchor && original.deprecatedNode()->parentNode() != enclosingAnchor) {
-                pushAnchorElementDown(enclosingAnchor);
+                pushAnchorElementDown(*enclosingAnchor);
                 enclosingAnchor = enclosingAnchorElement(original);
             }
             if (!enclosingAnchor)
index b15d987..d414f22 100644 (file)
@@ -152,7 +152,7 @@ protected:
 
     PassRefPtr<Node> moveParagraphContentsToNewBlockIfNecessary(const Position&);
     
-    void pushAnchorElementDown(Node*);
+    void pushAnchorElementDown(Element&);
     
     void moveParagraph(const VisiblePosition&, const VisiblePosition&, const VisiblePosition&, bool preserveSelection = false, bool preserveStyle = true);
     void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const VisiblePosition&, bool preserveSelection = false, bool preserveStyle = true);
index 579a882..e8d02ca 100644 (file)
@@ -47,11 +47,11 @@ void CreateLinkCommand::doApply()
     anchorElement->setHref(m_url);
     
     if (endingSelection().isRange())
-        applyStyledElement(anchorElement.get());
+        applyStyledElement(anchorElement.release());
     else {
         insertNodeAt(anchorElement.get(), endingSelection().start());
         RefPtr<Text> textNode = Text::create(document(), m_url);
-        appendNode(textNode.get(), anchorElement.get());
+        appendNode(textNode.release(), anchorElement.get());
         setEndingSelection(VisibleSelection(positionInParentBeforeNode(anchorElement.get()), positionInParentAfterNode(anchorElement.get()), DOWNSTREAM, endingSelection().isDirectional()));
     }
 }
index 2ff8d91..660381e 100644 (file)
@@ -679,13 +679,13 @@ Node* enclosingTableCell(const Position& p)
 Element* enclosingAnchorElement(const Position& p)
 {
     if (p.isNull())
-        return 0;
+        return nullptr;
 
     for (Node* node = p.deprecatedNode(); node; node = node->parentNode()) {
         if (node->isElementNode() && node->isLink())
             return toElement(node);
     }
-    return 0;
+    return nullptr;
 }
 
 HTMLElement* enclosingList(Node* node)