Reduce PassRefPtr uses in editing
authorgyuyoung.kim@webkit.org <gyuyoung.kim@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Mar 2016 14:05:54 +0000 (14:05 +0000)
committergyuyoung.kim@webkit.org <gyuyoung.kim@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Mar 2016 14:05:54 +0000 (14:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155743

Reviewed by Darin Adler.

Use RefPtr<>&&, raw pointer, or reference in arugments instead of PassRefPtr.
Besides RefPtr is used if function may be able to return nullptr.

* dom/Element.cpp:
(WebCore::Element::setOuterHTML):
(WebCore::Element::setInnerHTML):
* dom/Range.cpp:
(WebCore::Range::createContextualFragment):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::setInnerHTML):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::wrapContentsInDummySpan):
* editing/CompositeEditCommand.h:
* editing/DictationCommand.cpp:
(WebCore::DictationCommand::insertText):
* editing/SplitTextNodeContainingElementCommand.cpp:
(WebCore::SplitTextNodeContainingElementCommand::doApply):
* editing/TextInsertionBaseCommand.cpp:
(WebCore::TextInsertionBaseCommand::applyTextInsertionCommand):
* editing/TextInsertionBaseCommand.h:
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::deleteSelection):
(WebCore::TypingCommand::deleteKeyPressed):
(WebCore::TypingCommand::forwardDeleteKeyPressed):
(WebCore::TypingCommand::insertText):
(WebCore::TypingCommand::insertLineBreak):
(WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent):
(WebCore::TypingCommand::insertParagraphSeparator):
(WebCore::TypingCommand::lastTypingCommandIfStillOpenForTyping):
(WebCore::TypingCommand::closeTyping):
(WebCore::TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping):
* editing/TypingCommand.h:
* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::firstRange):
(WebCore::makeSearchRange):
* editing/VisibleSelection.h:
* editing/WrapContentsInDummySpanCommand.cpp:
(WebCore::WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand):
* editing/WrapContentsInDummySpanCommand.h:
(WebCore::WrapContentsInDummySpanCommand::create):
* editing/atk/FrameSelectionAtk.cpp:
(WebCore::maybeEmitTextFocusChange):
(WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
* editing/htmlediting.cpp:
(WebCore::createOrderedListElement):
(WebCore::createUnorderedListElement):
(WebCore::createListItemElement):
(WebCore::createTabSpanElement):
* editing/htmlediting.h:
* editing/markup.cpp:
(WebCore::AttributeChange::AttributeChange):
(WebCore::ancestorToRetainStructureAndAppearanceForBlock):
(WebCore::styleFromMatchedRulesAndInlineDecl):
(WebCore::createFragmentForInnerOuterHTML):
(WebCore::createFragmentForTransformToFragment):
(WebCore::createContextualFragment):
* editing/markup.h:
* html/HTMLElement.cpp:
(WebCore::HTMLElement::insertAdjacentHTML):
* xml/XSLTProcessor.cpp:
(WebCore::XSLTProcessor::transformToFragment):

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

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/DictationCommand.cpp
Source/WebCore/editing/SplitTextNodeContainingElementCommand.cpp
Source/WebCore/editing/TextInsertionBaseCommand.cpp
Source/WebCore/editing/TextInsertionBaseCommand.h
Source/WebCore/editing/TypingCommand.cpp
Source/WebCore/editing/TypingCommand.h
Source/WebCore/editing/VisibleSelection.cpp
Source/WebCore/editing/VisibleSelection.h
Source/WebCore/editing/WrapContentsInDummySpanCommand.cpp
Source/WebCore/editing/WrapContentsInDummySpanCommand.h
Source/WebCore/editing/atk/FrameSelectionAtk.cpp
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/editing/htmlediting.h
Source/WebCore/editing/markup.cpp
Source/WebCore/editing/markup.h
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/xml/XSLTProcessor.cpp

index ef35f51..8fe8e40 100644 (file)
@@ -1,3 +1,72 @@
+2016-03-23  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
+
+        Reduce PassRefPtr uses in editing
+        https://bugs.webkit.org/show_bug.cgi?id=155743
+
+        Reviewed by Darin Adler.
+
+        Use RefPtr<>&&, raw pointer, or reference in arugments instead of PassRefPtr.
+        Besides RefPtr is used if function may be able to return nullptr.
+
+        * dom/Element.cpp:
+        (WebCore::Element::setOuterHTML):
+        (WebCore::Element::setInnerHTML):
+        * dom/Range.cpp:
+        (WebCore::Range::createContextualFragment):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::setInnerHTML):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::wrapContentsInDummySpan):
+        * editing/CompositeEditCommand.h:
+        * editing/DictationCommand.cpp:
+        (WebCore::DictationCommand::insertText):
+        * editing/SplitTextNodeContainingElementCommand.cpp:
+        (WebCore::SplitTextNodeContainingElementCommand::doApply):
+        * editing/TextInsertionBaseCommand.cpp:
+        (WebCore::TextInsertionBaseCommand::applyTextInsertionCommand):
+        * editing/TextInsertionBaseCommand.h:
+        * editing/TypingCommand.cpp:
+        (WebCore::TypingCommand::deleteSelection):
+        (WebCore::TypingCommand::deleteKeyPressed):
+        (WebCore::TypingCommand::forwardDeleteKeyPressed):
+        (WebCore::TypingCommand::insertText):
+        (WebCore::TypingCommand::insertLineBreak):
+        (WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent):
+        (WebCore::TypingCommand::insertParagraphSeparator):
+        (WebCore::TypingCommand::lastTypingCommandIfStillOpenForTyping):
+        (WebCore::TypingCommand::closeTyping):
+        (WebCore::TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping):
+        * editing/TypingCommand.h:
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::firstRange):
+        (WebCore::makeSearchRange):
+        * editing/VisibleSelection.h:
+        * editing/WrapContentsInDummySpanCommand.cpp:
+        (WebCore::WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand):
+        * editing/WrapContentsInDummySpanCommand.h:
+        (WebCore::WrapContentsInDummySpanCommand::create):
+        * editing/atk/FrameSelectionAtk.cpp:
+        (WebCore::maybeEmitTextFocusChange):
+        (WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
+        * editing/htmlediting.cpp:
+        (WebCore::createOrderedListElement):
+        (WebCore::createUnorderedListElement):
+        (WebCore::createListItemElement):
+        (WebCore::createTabSpanElement):
+        * editing/htmlediting.h:
+        * editing/markup.cpp:
+        (WebCore::AttributeChange::AttributeChange):
+        (WebCore::ancestorToRetainStructureAndAppearanceForBlock):
+        (WebCore::styleFromMatchedRulesAndInlineDecl):
+        (WebCore::createFragmentForInnerOuterHTML):
+        (WebCore::createFragmentForTransformToFragment):
+        (WebCore::createContextualFragment):
+        * editing/markup.h:
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::insertAdjacentHTML):
+        * xml/XSLTProcessor.cpp:
+        (WebCore::XSLTProcessor::transformToFragment):
+
 2016-03-23  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Use Region instead of IntRect in PageClient and WebPageProxy setViewNeedsDisplay method
index f9399d8..75fe8f8 100644 (file)
@@ -2368,7 +2368,7 @@ void Element::setOuterHTML(const String& html, ExceptionCode& ec)
     RefPtr<Node> prev = previousSibling();
     RefPtr<Node> next = nextSibling();
 
-    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, ec);
+    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*parent, html, AllowScriptingContent, ec);
     if (ec)
         return;
     
@@ -2383,7 +2383,7 @@ void Element::setOuterHTML(const String& html, ExceptionCode& ec)
 
 void Element::setInnerHTML(const String& html, ExceptionCode& ec)
 {
-    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, ec)) {
+    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*this, html, AllowScriptingContent, ec)) {
         ContainerNode* container = this;
 
 #if ENABLE(TEMPLATE_ELEMENT)
index 94fa4e1..7f8b761 100644 (file)
@@ -941,7 +941,7 @@ RefPtr<DocumentFragment> Range::createContextualFragment(const String& markup, E
         return nullptr;
     }
 
-    return WebCore::createContextualFragment(markup, downcast<HTMLElement>(element.get()), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
+    return WebCore::createContextualFragment(downcast<HTMLElement>(*element), markup, AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
 }
 
 
index b7758b8..5ddada1 100644 (file)
@@ -135,7 +135,7 @@ void ShadowRoot::setInnerHTML(const String& markup, ExceptionCode& ec)
         return;
     }
 
-    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, ec))
+    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*host(), markup, AllowScriptingContent, ec))
         replaceChildrenWithFragment(*this, fragment.releaseNonNull(), ec);
 }
 
index ed41756..6d6095d 100644 (file)
@@ -493,7 +493,7 @@ void CompositeEditCommand::mergeIdenticalElements(PassRefPtr<Element> prpFirst,
     applyCommandToComposite(MergeIdenticalElementsCommand::create(first, second));
 }
 
-void CompositeEditCommand::wrapContentsInDummySpan(PassRefPtr<Element> element)
+void CompositeEditCommand::wrapContentsInDummySpan(Element& element)
 {
     applyCommandToComposite(WrapContentsInDummySpanCommand::create(element));
 }
index 465b601..df59307 100644 (file)
@@ -140,7 +140,7 @@ protected:
     void splitElement(PassRefPtr<Element>, PassRefPtr<Node> atChild);
     void splitTextNode(PassRefPtr<Text>, unsigned offset);
     void splitTextNodeContainingElement(PassRefPtr<Text>, unsigned offset);
-    void wrapContentsInDummySpan(PassRefPtr<Element>);
+    void wrapContentsInDummySpan(Element&);
 
     void deleteInsignificantText(PassRefPtr<Text>, unsigned start, unsigned end);
     void deleteInsignificantText(const Position& start, const Position& end);
index 99295c6..4a96156 100644 (file)
@@ -101,7 +101,7 @@ void DictationCommand::insertText(Document& document, const String& text, const
         // If the text was modified before insertion, the location of dictation alternatives
         // will not be valid anymore. We will just drop the alternatives.
         cmd = DictationCommand::create(document, newText, Vector<DictationAlternative>());
-    applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSelection);
+    applyTextInsertionCommand(frame.get(), *cmd, selectionForInsertion, currentSelection);
 }
 
 void DictationCommand::doApply()
index 5175e3a..ce88874 100644 (file)
@@ -55,7 +55,7 @@ void SplitTextNodeContainingElementCommand::doApply()
 
     RenderElement* parentRenderer = parent->renderer();
     if (!parentRenderer || !parentRenderer->isInline()) {
-        wrapContentsInDummySpan(parent);
+        wrapContentsInDummySpan(*parent);
         Node* firstChild = parent->firstChild();
         if (!is<Element>(firstChild))
             return;
index ccc3dde..c5bdbbe 100644 (file)
@@ -40,16 +40,16 @@ TextInsertionBaseCommand::TextInsertionBaseCommand(Document& document)
 {
 }
 
-void TextInsertionBaseCommand::applyTextInsertionCommand(Frame* frame, PassRefPtr<TextInsertionBaseCommand> command, const VisibleSelection& selectionForInsertion, const VisibleSelection& endingSelection)
+void TextInsertionBaseCommand::applyTextInsertionCommand(Frame* frame, TextInsertionBaseCommand& command, const VisibleSelection& selectionForInsertion, const VisibleSelection& endingSelection)
 {
     bool changeSelection = selectionForInsertion != endingSelection;
     if (changeSelection) {
-        command->setStartingSelection(selectionForInsertion);
-        command->setEndingSelection(selectionForInsertion);
+        command.setStartingSelection(selectionForInsertion);
+        command.setEndingSelection(selectionForInsertion);
     }
-    applyCommand(command);
+    applyCommand(&command);
     if (changeSelection) {
-        command->setEndingSelection(endingSelection);
+        command.setEndingSelection(endingSelection);
         frame->selection().setSelection(endingSelection);
     }
 }
index e549b5c..875c587 100644 (file)
@@ -40,7 +40,7 @@ public:
 
 protected:
     explicit TextInsertionBaseCommand(Document&);
-    static void applyTextInsertionCommand(Frame*, PassRefPtr<TextInsertionBaseCommand>, const VisibleSelection& selectionForInsertion, const VisibleSelection& endingSelection);
+    static void applyTextInsertionCommand(Frame*, TextInsertionBaseCommand&, const VisibleSelection& selectionForInsertion, const VisibleSelection& endingSelection);
 };
 
 String dispatchBeforeTextInsertedEvent(const String& text, const VisibleSelection& selectionForInsertion, bool insertionIsForUpdatingComposition);
index a0f912a..15b4f85 100644 (file)
@@ -99,7 +99,7 @@ void TypingCommand::deleteSelection(Document& document, Options options)
     if (!frame->selection().isRange())
         return;
 
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
         lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
         lastTypingCommand->deleteSelection(options & SmartDelete);
         return;
@@ -111,7 +111,7 @@ void TypingCommand::deleteSelection(Document& document, Options options)
 void TypingCommand::deleteKeyPressed(Document& document, Options options, TextGranularity granularity)
 {
     if (granularity == CharacterGranularity) {
-        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
             updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document.frame());
             lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
             lastTypingCommand->deleteKeyPressed(granularity, options & AddsToKillRing);
@@ -127,7 +127,7 @@ void TypingCommand::forwardDeleteKeyPressed(Document& document, Options options,
     // FIXME: Forward delete in TextEdit appears to open and close a new typing command.
     Frame* frame = document.frame();
     if (granularity == CharacterGranularity) {
-        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
+        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
             updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), frame);
             lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
             lastTypingCommand->forwardDeleteKeyPressed(granularity, options & AddsToKillRing);
@@ -173,7 +173,7 @@ void TypingCommand::insertText(Document& document, const String& text, const Vis
     // Set the starting and ending selection appropriately if we are using a selection
     // that is different from the current selection.  In the future, we should change EditCommand
     // to deal with custom selections in a general way that can be used by all of the commands.
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame.get())) {
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
         if (lastTypingCommand->endingSelection() != selectionForInsertion) {
             lastTypingCommand->setStartingSelection(selectionForInsertion);
             lastTypingCommand->setEndingSelection(selectionForInsertion);
@@ -187,12 +187,12 @@ void TypingCommand::insertText(Document& document, const String& text, const Vis
     }
 
     RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
-    applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSelection);
+    applyTextInsertionCommand(frame.get(), *cmd, selectionForInsertion, currentSelection);
 }
 
 void TypingCommand::insertLineBreak(Document& document, Options options)
 {
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
         lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
         lastTypingCommand->insertLineBreak();
         return;
@@ -203,7 +203,7 @@ void TypingCommand::insertLineBreak(Document& document, Options options)
 
 void TypingCommand::insertParagraphSeparatorInQuotedContent(Document& document)
 {
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
         lastTypingCommand->insertParagraphSeparatorInQuotedContent();
         return;
     }
@@ -213,7 +213,7 @@ void TypingCommand::insertParagraphSeparatorInQuotedContent(Document& document)
 
 void TypingCommand::insertParagraphSeparator(Document& document, Options options)
 {
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
         lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
         lastTypingCommand->insertParagraphSeparator();
         return;
@@ -222,27 +222,25 @@ void TypingCommand::insertParagraphSeparator(Document& document, Options options
     applyCommand(TypingCommand::create(document, InsertParagraphSeparator, "", options));
 }
 
-PassRefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(Frame* frame)
+RefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(Frame& frame)
 {
-    ASSERT(frame);
-
-    RefPtr<CompositeEditCommand> lastEditCommand = frame->editor().lastEditCommand();
+    RefPtr<CompositeEditCommand> lastEditCommand = frame.editor().lastEditCommand();
     if (!lastEditCommand || !lastEditCommand->isTypingCommand() || !static_cast<TypingCommand*>(lastEditCommand.get())->isOpenForMoreTyping())
-        return 0;
+        return nullptr;
 
     return static_cast<TypingCommand*>(lastEditCommand.get());
 }
 
 void TypingCommand::closeTyping(Frame* frame)
 {
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame))
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame))
         lastTypingCommand->closeTyping();
 }
 
 #if PLATFORM(IOS)
 void TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(Frame* frame, const VisibleSelection& newSelection)
 {
-    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
+    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
         lastTypingCommand->setEndingSelection(newSelection);
         lastTypingCommand->setEndingSelectionOnLastInsertCommand(newSelection);
     }
index 7f3492f..b43e1eb 100644 (file)
@@ -102,7 +102,7 @@ private:
     bool isOpenForMoreTyping() const { return m_openForMoreTyping; }
     void closeTyping() { m_openForMoreTyping = false; }
 
-    static PassRefPtr<TypingCommand> lastTypingCommandIfStillOpenForTyping(Frame*);
+    static RefPtr<TypingCommand> lastTypingCommandIfStillOpenForTyping(Frame&);
 
     virtual void doApply();
     virtual EditAction editingAction() const;
index b794506..d3e1cb2 100644 (file)
@@ -123,10 +123,10 @@ void VisibleSelection::setExtent(const VisiblePosition& visiblePosition)
     validate();
 }
 
-PassRefPtr<Range> VisibleSelection::firstRange() const
+RefPtr<Range> VisibleSelection::firstRange() const
 {
     if (isNone())
-        return 0;
+        return nullptr;
     Position start = m_start.parentAnchoredEquivalent();
     Position end = m_end.parentAnchoredEquivalent();
     return Range::create(start.anchorNode()->document(), start, end);
@@ -197,17 +197,17 @@ bool VisibleSelection::expandUsingGranularity(TextGranularity granularity)
     return true;
 }
 
-static PassRefPtr<Range> makeSearchRange(const Position& pos)
+static RefPtr<Range> makeSearchRange(const Position& pos)
 {
     Node* n = pos.deprecatedNode();
     if (!n)
-        return 0;
+        return nullptr;
     Node* de = n->document().documentElement();
     if (!de)
-        return 0;
+        return nullptr;
     Element* boundary = deprecatedEnclosingBlockFlowElement(n);
     if (!boundary)
-        return 0;
+        return nullptr;
 
     RefPtr<Range> searchRange(Range::create(n->document()));
     ExceptionCode ec = 0;
@@ -218,9 +218,9 @@ static PassRefPtr<Range> makeSearchRange(const Position& pos)
 
     ASSERT(!ec);
     if (ec)
-        return 0;
+        return nullptr;
 
-    return searchRange.release();
+    return WTFMove(searchRange);
 }
 
 bool VisibleSelection::isAll(EditingBoundaryCrossingRule rule) const
index fcce1e9..e8cfea2 100644 (file)
@@ -90,7 +90,7 @@ public:
     WEBCORE_EXPORT bool expandUsingGranularity(TextGranularity granularity);
     
     // We don't yet support multi-range selections, so we only ever have one range to return.
-    WEBCORE_EXPORT PassRefPtr<Range> firstRange() const;
+    WEBCORE_EXPORT RefPtr<Range> firstRange() const;
 
     // FIXME: Most callers probably don't want this function, but are using it
     // for historical reasons.  toNormalizedRange contracts the range around
index 88c07b9..768f33f 100644 (file)
 
 namespace WebCore {
 
-WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand(PassRefPtr<Element> element)
-    : SimpleEditCommand(element->document())
+WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand(Element& element)
+    : SimpleEditCommand(element.document())
     , m_element(element)
 {
-    ASSERT(m_element);
 }
 
 void WrapContentsInDummySpanCommand::executeApply()
@@ -59,8 +58,6 @@ void WrapContentsInDummySpanCommand::doApply()
     
 void WrapContentsInDummySpanCommand::doUnapply()
 {
-    ASSERT(m_element);
-
     if (!m_dummySpan || !m_element->hasEditableStyle())
         return;
 
@@ -75,9 +72,7 @@ void WrapContentsInDummySpanCommand::doUnapply()
 }
 
 void WrapContentsInDummySpanCommand::doReapply()
-{
-    ASSERT(m_element);
-    
+{    
     if (!m_dummySpan || !m_element->hasEditableStyle())
         return;
 
@@ -87,7 +82,7 @@ void WrapContentsInDummySpanCommand::doReapply()
 #ifndef NDEBUG
 void WrapContentsInDummySpanCommand::getNodesInCommand(HashSet<Node*>& nodes)
 {
-    addNodeAndDescendants(m_element.get(), nodes);
+    addNodeAndDescendants(m_element.ptr(), nodes);
     addNodeAndDescendants(m_dummySpan.get(), nodes);
 }
 #endif
index 4beb9cc..89899ad 100644 (file)
@@ -34,13 +34,13 @@ class HTMLElement;
 
 class WrapContentsInDummySpanCommand : public SimpleEditCommand {
 public:
-    static Ref<WrapContentsInDummySpanCommand> create(PassRefPtr<Element> element)
+    static Ref<WrapContentsInDummySpanCommand> create(Element& element)
     {
         return adoptRef(*new WrapContentsInDummySpanCommand(element));
     }
 
 private:
-    explicit WrapContentsInDummySpanCommand(PassRefPtr<Element>);
+    explicit WrapContentsInDummySpanCommand(Element&);
 
     void doApply() override;
     void doUnapply() override;
@@ -51,7 +51,7 @@ private:
     void getNodesInCommand(HashSet<Node*>&) override;
 #endif
 
-    RefPtr<Element> m_element;
+    Ref<Element> m_element;
     RefPtr<HTMLElement> m_dummySpan;
 };
 
index 0ffc325..4ecd63c 100644 (file)
@@ -43,15 +43,13 @@ static void emitTextSelectionChange(AccessibilityObject* object, VisibleSelectio
         g_signal_emit_by_name(axObject, "text-selection-changed");
 }
 
-static void maybeEmitTextFocusChange(PassRefPtr<AccessibilityObject> prpObject)
+static void maybeEmitTextFocusChange(RefPtr<AccessibilityObject>&& object)
 {
     // This static variable is needed to keep track of the old object
     // as per previous calls to this function, in order to properly
     // decide whether to emit some signals or not.
     static NeverDestroyed<RefPtr<AccessibilityObject>> oldObject;
 
-    RefPtr<AccessibilityObject> object = prpObject;
-
     // Ensure the oldObject belongs to the same document that the
     // current object so further comparisons make sense. Otherwise,
     // just reset oldObject to 0 so it won't be taken into account in
@@ -74,7 +72,7 @@ static void maybeEmitTextFocusChange(PassRefPtr<AccessibilityObject> prpObject)
     }
 
     // Update pointer to last focused object.
-    oldObject.get() = object;
+    oldObject.get() = WTFMove(object);
 }
 
 
@@ -101,7 +99,7 @@ void FrameSelection::notifyAccessibilityForSelectionChange(const AXTextStateChan
         return;
 
     emitTextSelectionChange(object.get(), m_selection, offset);
-    maybeEmitTextFocusChange(object.release());
+    maybeEmitTextFocusChange(WTFMove(object));
 }
 
 } // namespace WebCore
index 607dc7a..29c9af8 100644 (file)
@@ -912,17 +912,17 @@ Ref<HTMLElement> createBreakElement(Document& document)
     return HTMLBRElement::create(document);
 }
 
-PassRefPtr<HTMLElement> createOrderedListElement(Document& document)
+Ref<HTMLElement> createOrderedListElement(Document& document)
 {
     return HTMLOListElement::create(document);
 }
 
-PassRefPtr<HTMLElement> createUnorderedListElement(Document& document)
+Ref<HTMLElement> createUnorderedListElement(Document& document)
 {
     return HTMLUListElement::create(document);
 }
 
-PassRefPtr<HTMLElement> createListItemElement(Document& document)
+Ref<HTMLElement> createListItemElement(Document& document)
 {
     return HTMLLIElement::create(document);
 }
@@ -966,12 +966,10 @@ Position positionOutsideTabSpan(const Position& pos)
     return positionInParentBeforeNode(node);
 }
 
-Ref<Element> createTabSpanElement(Document& document, PassRefPtr<Node> prpTabTextNode)
+Ref<Element> createTabSpanElement(Document& document, RefPtr<Node>&& tabTextNode)
 {
-    RefPtr<Node> tabTextNode = prpTabTextNode;
-
     // Make the span to hold the tab.
-    RefPtr<Element> spanElement = document.createElement(spanTag, false);
+    Ref<Element> spanElement = document.createElement(spanTag, false);
     spanElement->setAttribute(classAttr, AppleTabSpanClass);
     spanElement->setAttribute(styleAttr, "white-space:pre");
 
@@ -981,7 +979,7 @@ Ref<Element> createTabSpanElement(Document& document, PassRefPtr<Node> prpTabTex
 
     spanElement->appendChild(tabTextNode.releaseNonNull(), ASSERT_NO_EXCEPTION);
 
-    return spanElement.releaseNonNull();
+    return spanElement;
 }
 
 Ref<Element> createTabSpanElement(Document& document, const String& tabText)
@@ -991,7 +989,7 @@ Ref<Element> createTabSpanElement(Document& document, const String& tabText)
 
 Ref<Element> createTabSpanElement(Document& document)
 {
-    return createTabSpanElement(document, PassRefPtr<Node>());
+    return createTabSpanElement(document, RefPtr<Node>());
 }
 
 bool isNodeRendered(const Node* node)
index 6349efc..c15479c 100644 (file)
@@ -208,9 +208,9 @@ VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node*, int index);
     
 WEBCORE_EXPORT Ref<HTMLElement> createDefaultParagraphElement(Document&);
 Ref<HTMLElement> createBreakElement(Document&);
-PassRefPtr<HTMLElement> createOrderedListElement(Document&);
-PassRefPtr<HTMLElement> createUnorderedListElement(Document&);
-PassRefPtr<HTMLElement> createListItemElement(Document&);
+Ref<HTMLElement> createOrderedListElement(Document&);
+Ref<HTMLElement> createUnorderedListElement(Document&);
+Ref<HTMLElement> createListItemElement(Document&);
 Ref<HTMLElement> createHTMLElement(Document&, const QualifiedName&);
 Ref<HTMLElement> createHTMLElement(Document&, const AtomicString&);
 
@@ -223,7 +223,7 @@ Node* enclosingListChild(Node*);
 // -------------------------------------------------------------------------
 
 Ref<Element> createTabSpanElement(Document&);
-Ref<Element> createTabSpanElement(Document&, PassRefPtr<Node> tabTextNode);
+Ref<Element> createTabSpanElement(Document&, RefPtr<Node>&& tabTextNode);
 Ref<Element> createTabSpanElement(Document&, const String& tabText);
 Ref<Element> createBlockPlaceholderElement(Document&);
 
index d907526..6f6bd58 100644 (file)
@@ -79,7 +79,7 @@ public:
     {
     }
 
-    AttributeChange(PassRefPtr<Element> element, const QualifiedName& name, const String& value)
+    AttributeChange(Element* element, const QualifiedName& name, const String& value)
         : m_element(element), m_name(name), m_value(value)
     {
     }
@@ -466,7 +466,7 @@ Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No
 static Node* ancestorToRetainStructureAndAppearanceForBlock(Node* commonAncestorBlock)
 {
     if (!commonAncestorBlock)
-        return 0;
+        return nullptr;
 
     if (commonAncestorBlock->hasTagName(tbodyTag) || commonAncestorBlock->hasTagName(trTag)) {
         ContainerNode* table = commonAncestorBlock->parentNode();
@@ -479,7 +479,7 @@ static Node* ancestorToRetainStructureAndAppearanceForBlock(Node* commonAncestor
     if (isNonTableCellHTMLBlockElement(commonAncestorBlock))
         return commonAncestorBlock;
 
-    return 0;
+    return nullptr;
 }
 
 static inline Node* ancestorToRetainStructureAndAppearance(Node* commonAncestor)
@@ -508,17 +508,17 @@ static bool needInterchangeNewlineAfter(const VisiblePosition& v)
     return isEndOfParagraph(v) && isStartOfParagraph(next) && !(upstreamNode->hasTagName(brTag) && upstreamNode == downstreamNode);
 }
 
-static PassRefPtr<EditingStyle> styleFromMatchedRulesAndInlineDecl(const Node* node)
+static RefPtr<EditingStyle> styleFromMatchedRulesAndInlineDecl(const Node* node)
 {
     if (!node->isHTMLElement())
-        return 0;
+        return nullptr;
 
     // FIXME: Having to const_cast here is ugly, but it is quite a bit of work to untangle
     // the non-const-ness of styleFromMatchedRulesForElement.
     HTMLElement* element = const_cast<HTMLElement*>(static_cast<const HTMLElement*>(node));
     RefPtr<EditingStyle> style = EditingStyle::create(element->inlineStyle());
     style->mergeStyleFromRules(element);
-    return style.release();
+    return style;
 }
 
 static bool isElementPresentational(const Node* node)
@@ -878,50 +878,50 @@ String urlToMarkup(const URL& url, const String& title)
     return markup.toString();
 }
 
-PassRefPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String& markup, Element* contextElement, ParserContentPolicy parserContentPolicy, ExceptionCode& ec)
+RefPtr<DocumentFragment> createFragmentForInnerOuterHTML(Element& contextElement, const String& markup, ParserContentPolicy parserContentPolicy, ExceptionCode& ec)
 {
-    Document* document = &contextElement->document();
+    Document* document = &contextElement.document();
 #if ENABLE(TEMPLATE_ELEMENT)
-    if (contextElement->hasTagName(templateTag))
+    if (contextElement.hasTagName(templateTag))
         document = &document->ensureTemplateDocument();
 #endif
     RefPtr<DocumentFragment> fragment = DocumentFragment::create(*document);
 
     if (document->isHTMLDocument()) {
-        fragment->parseHTML(markup, contextElement, parserContentPolicy);
+        fragment->parseHTML(markup, &contextElement, parserContentPolicy);
         return fragment;
     }
 
-    bool wasValid = fragment->parseXML(markup, contextElement, parserContentPolicy);
+    bool wasValid = fragment->parseXML(markup, &contextElement, parserContentPolicy);
     if (!wasValid) {
         ec = SYNTAX_ERR;
-        return 0;
+        return nullptr;
     }
-    return fragment.release();
+    return fragment;
 }
 
-PassRefPtr<DocumentFragment> createFragmentForTransformToFragment(const String& sourceString, const String& sourceMIMEType, Document* outputDoc)
+RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document& outputDoc, const String& sourceString, const String& sourceMIMEType)
 {
-    RefPtr<DocumentFragment> fragment = outputDoc->createDocumentFragment();
+    RefPtr<DocumentFragment> fragment = outputDoc.createDocumentFragment();
     
     if (sourceMIMEType == "text/html") {
         // As far as I can tell, there isn't a spec for how transformToFragment is supposed to work.
         // Based on the documentation I can find, it looks like we want to start parsing the fragment in the InBody insertion mode.
         // Unfortunately, that's an implementation detail of the parser.
         // We achieve that effect here by passing in a fake body element as context for the fragment.
-        RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(*outputDoc);
+        RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(outputDoc);
         fragment->parseHTML(sourceString, fakeBody.get());
     } else if (sourceMIMEType == "text/plain")
-        fragment->parserAppendChild(Text::create(*outputDoc, sourceString));
+        fragment->parserAppendChild(Text::create(outputDoc, sourceString));
     else {
         bool successfulParse = fragment->parseXML(sourceString, 0);
         if (!successfulParse)
-            return 0;
+            return nullptr;
     }
     
     // FIXME: Do we need to mess with URLs here?
     
-    return fragment.release();
+    return fragment;
 }
 
 static Vector<Ref<HTMLElement>> collectElementsToRemoveFromFragment(ContainerNode& container)
@@ -950,21 +950,20 @@ static void removeElementFromFragmentPreservingChildren(DocumentFragment& fragme
     fragment.removeChild(element, ASSERT_NO_EXCEPTION);
 }
 
-PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTMLElement* element, ParserContentPolicy parserContentPolicy, ExceptionCode& ec)
+RefPtr<DocumentFragment> createContextualFragment(HTMLElement& element, const String& markup, ParserContentPolicy parserContentPolicy, ExceptionCode& ec)
 {
-    ASSERT(element);
-    if (element->ieForbidsInsertHTML()) {
+    if (element.ieForbidsInsertHTML()) {
         ec = NOT_SUPPORTED_ERR;
         return nullptr;
     }
 
-    if (element->hasTagName(colTag) || element->hasTagName(colgroupTag) || element->hasTagName(framesetTag)
-        || element->hasTagName(headTag) || element->hasTagName(styleTag) || element->hasTagName(titleTag)) {
+    if (element.hasTagName(colTag) || element.hasTagName(colgroupTag) || element.hasTagName(framesetTag)
+        || element.hasTagName(headTag) || element.hasTagName(styleTag) || element.hasTagName(titleTag)) {
         ec = NOT_SUPPORTED_ERR;
         return nullptr;
     }
 
-    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, element, parserContentPolicy, ec);
+    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(element, markup, parserContentPolicy, ec);
     if (!fragment)
         return nullptr;
 
@@ -975,7 +974,7 @@ PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTML
     for (auto& element : toRemove)
         removeElementFromFragmentPreservingChildren(*fragment, element);
 
-    return fragment.release();
+    return fragment;
 }
 
 static inline bool hasOneChild(ContainerNode& node)
index 47a4ed9..3a12163 100644 (file)
@@ -51,9 +51,9 @@ enum EFragmentSerialization { HTMLFragmentSerialization, XMLFragmentSerializatio
 
 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(Range& context, const String& text);
 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent);
-PassRefPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String&, Element*, ParserContentPolicy, ExceptionCode&);
-PassRefPtr<DocumentFragment> createFragmentForTransformToFragment(const String&, const String& sourceMIMEType, Document* outputDoc);
-PassRefPtr<DocumentFragment> createContextualFragment(const String&, HTMLElement*, ParserContentPolicy, ExceptionCode&);
+RefPtr<DocumentFragment> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy, ExceptionCode&);
+RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document&, const String& sourceString, const String& sourceMIMEType);
+RefPtr<DocumentFragment> createContextualFragment(HTMLElement&, const String& markup, ParserContentPolicy, ExceptionCode&);
 
 bool isPlainTextMarkup(Node*);
 
index 39435a1..18bd1c7 100644 (file)
@@ -696,7 +696,7 @@ void HTMLElement::insertAdjacentHTML(const String& where, const String& markup,
     Element* contextElement = contextElementForInsertion(where, this, ec);
     if (!contextElement)
         return;
-    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement, AllowScriptingContent, ec);
+    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*contextElement, markup, AllowScriptingContent, ec);
     if (!fragment)
         return;
     insertAdjacent(where, fragment.releaseNonNull(), ec);
index db6f9ac..a6457a9 100644 (file)
@@ -138,7 +138,7 @@ RefPtr<DocumentFragment> XSLTProcessor::transformToFragment(Node* sourceNode, Do
 
     if (!transformToString(*sourceNode, resultMIMEType, resultString, resultEncoding))
         return nullptr;
-    return createFragmentForTransformToFragment(resultString, resultMIMEType, outputDoc);
+    return createFragmentForTransformToFragment(*outputDoc, resultString, resultMIMEType);
 }
 
 void XSLTProcessor::setParameter(const String& /*namespaceURI*/, const String& localName, const String& value)