Ref-ify Range::create().
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Dec 2014 03:06:00 +0000 (03:06 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Dec 2014 03:06:00 +0000 (03:06 +0000)
<https://webkit.org/b/139755>

Reviewed by Anders Carlsson.

Source/WebCore:

* dom/Document.cpp:
(WebCore::acceptsEditingFocus):
* dom/Element.cpp:
(WebCore::Element::innerText):
* dom/Range.cpp:
(WebCore::Range::create):
(WebCore::Range::cloneRange):
(WebCore::rangeOfContents):
* dom/Range.h:
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyAlternativeTextToRange):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers):
* editing/VisibleUnits.cpp:
(WebCore::charactersAroundPosition):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::renderedText):
* page/FocusController.cpp:
(WebCore::relinquishesEditingFocus):

Source/WebKit/mac:

* WebView/WebHTMLRepresentation.mm:
(-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):
* WebView/WebHTMLView.mm:
(-[WebHTMLView attributedString]):

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/page/FocusController.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebHTMLRepresentation.mm
Source/WebKit/mac/WebView/WebHTMLView.mm

index ba9795d..a52e874 100644 (file)
@@ -1,3 +1,30 @@
+2014-12-17  Andreas Kling  <akling@apple.com>
+
+        Ref-ify Range::create().
+        <https://webkit.org/b/139755>
+
+        Reviewed by Anders Carlsson.
+
+        * dom/Document.cpp:
+        (WebCore::acceptsEditingFocus):
+        * dom/Element.cpp:
+        (WebCore::Element::innerText):
+        * dom/Range.cpp:
+        (WebCore::Range::create):
+        (WebCore::Range::cloneRange):
+        (WebCore::rangeOfContents):
+        * dom/Range.h:
+        * editing/AlternativeTextController.cpp:
+        (WebCore::AlternativeTextController::applyAlternativeTextToRange):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers):
+        * editing/VisibleUnits.cpp:
+        (WebCore::charactersAroundPosition):
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::renderedText):
+        * page/FocusController.cpp:
+        (WebCore::relinquishesEditingFocus):
+
 2014-12-17  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/19282508> WebKitLegacy is unusable due to bad dylib identifier
index c3a6f37..bfe1c5c 100644 (file)
@@ -343,7 +343,7 @@ static bool acceptsEditingFocus(Node* node)
     if (!frame || !root)
         return false;
 
-    return frame->editor().shouldBeginEditing(rangeOfContents(*root).get());
+    return frame->editor().shouldBeginEditing(rangeOfContents(*root).ptr());
 }
 
 static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* targetFrame)
index 8e22f88..b260d19 100644 (file)
@@ -2100,7 +2100,7 @@ String Element::innerText()
     if (!renderer())
         return textContent(true);
 
-    return plainText(rangeOfContents(*this).get());
+    return plainText(rangeOfContents(*this).ptr());
 }
 
 String Element::outerText()
index 412a7a0..cd565c5 100644 (file)
@@ -72,9 +72,9 @@ inline Range::Range(Document& ownerDocument)
     m_ownerDocument->attachRange(this);
 }
 
-PassRefPtr<Range> Range::create(Document& ownerDocument)
+Ref<Range> Range::create(Document& ownerDocument)
 {
-    return adoptRef(new Range(ownerDocument));
+    return adoptRef(*new Range(ownerDocument));
 }
 
 inline Range::Range(Document& ownerDocument, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset)
@@ -94,26 +94,26 @@ inline Range::Range(Document& ownerDocument, PassRefPtr<Node> startContainer, in
     setEnd(endContainer, endOffset);
 }
 
-PassRefPtr<Range> Range::create(Document& ownerDocument, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset)
+Ref<Range> Range::create(Document& ownerDocument, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset)
 {
-    return adoptRef(new Range(ownerDocument, startContainer, startOffset, endContainer, endOffset));
+    return adoptRef(*new Range(ownerDocument, startContainer, startOffset, endContainer, endOffset));
 }
 
-PassRefPtr<Range> Range::create(Document& ownerDocument, const Position& start, const Position& end)
+Ref<Range> Range::create(Document& ownerDocument, const Position& start, const Position& end)
 {
-    return adoptRef(new Range(ownerDocument, start.containerNode(), start.computeOffsetInContainerNode(), end.containerNode(), end.computeOffsetInContainerNode()));
+    return adoptRef(*new Range(ownerDocument, start.containerNode(), start.computeOffsetInContainerNode(), end.containerNode(), end.computeOffsetInContainerNode()));
 }
 
-PassRefPtr<Range> Range::create(ScriptExecutionContext& context)
+Ref<Range> Range::create(ScriptExecutionContext& context)
 {
-    return adoptRef(new Range(downcast<Document>(context)));
+    return adoptRef(*new Range(downcast<Document>(context)));
 }
 
-PassRefPtr<Range> Range::create(Document& ownerDocument, const VisiblePosition& visibleStart, const VisiblePosition& visibleEnd)
+Ref<Range> Range::create(Document& ownerDocument, const VisiblePosition& visibleStart, const VisiblePosition& visibleEnd)
 {
     Position start = visibleStart.deepEquivalent().parentAnchoredEquivalent();
     Position end = visibleEnd.deepEquivalent().parentAnchoredEquivalent();
-    return adoptRef(new Range(ownerDocument, start.anchorNode(), start.deprecatedEditingOffset(), end.anchorNode(), end.deprecatedEditingOffset()));
+    return adoptRef(*new Range(ownerDocument, start.anchorNode(), start.deprecatedEditingOffset(), end.anchorNode(), end.deprecatedEditingOffset()));
 }
 
 Range::~Range()
@@ -1220,11 +1220,11 @@ void Range::checkNodeBA(Node* n, ExceptionCode& ec) const
     }
 }
 
-PassRefPtr<Range> Range::cloneRange(ExceptionCode& ec) const
+RefPtr<Range> Range::cloneRange(ExceptionCode& ec) const
 {
     if (!m_start.container()) {
         ec = INVALID_STATE_ERR;
-        return 0;
+        return nullptr;
     }
 
     return Range::create(ownerDocument(), m_start.container(), m_start.offset(), m_end.container(), m_end.offset());
@@ -2002,12 +2002,12 @@ bool rangesOverlap(const Range* a, const Range* b)
     return false;
 }
 
-PassRefPtr<Range> rangeOfContents(Node& node)
+Ref<Range> rangeOfContents(Node& node)
 {
-    RefPtr<Range> range = Range::create(node.document());
+    Ref<Range> range = Range::create(node.document());
     int exception = 0;
     range->selectNodeContents(&node, exception);
-    return range.release();
+    return range;
 }
 
 static inline void boundaryNodeChildrenChanged(RangeBoundaryPoint& boundary, ContainerNode& container)
index f58ea29..adaa9d5 100644 (file)
@@ -52,11 +52,11 @@ class SelectionRect;
 
 class Range : public RefCounted<Range> {
 public:
-    WEBCORE_EXPORT static PassRefPtr<Range> create(Document&);
-    WEBCORE_EXPORT static PassRefPtr<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
-    WEBCORE_EXPORT static PassRefPtr<Range> create(Document&, const Position&, const Position&);
-    WEBCORE_EXPORT static PassRefPtr<Range> create(ScriptExecutionContext&);
-    WEBCORE_EXPORT static PassRefPtr<Range> create(Document&, const VisiblePosition&, const VisiblePosition&);
+    WEBCORE_EXPORT static Ref<Range> create(Document&);
+    WEBCORE_EXPORT static Ref<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
+    WEBCORE_EXPORT static Ref<Range> create(Document&, const Position&, const Position&);
+    WEBCORE_EXPORT static Ref<Range> create(ScriptExecutionContext&);
+    WEBCORE_EXPORT static Ref<Range> create(Document&, const VisiblePosition&, const VisiblePosition&);
     WEBCORE_EXPORT ~Range();
 
     Document& ownerDocument() const { return const_cast<Document&>(m_ownerDocument.get()); }
@@ -99,7 +99,7 @@ public:
     PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&);
 
     void detach(ExceptionCode&);
-    WEBCORE_EXPORT PassRefPtr<Range> cloneRange(ExceptionCode&) const;
+    WEBCORE_EXPORT RefPtr<Range> cloneRange(ExceptionCode&) const;
 
     WEBCORE_EXPORT void setStartAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
     WEBCORE_EXPORT void setEndBefore(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION);
@@ -183,7 +183,7 @@ private:
     RangeBoundaryPoint m_end;
 };
 
-PassRefPtr<Range> rangeOfContents(Node&);
+Ref<Range> rangeOfContents(Node&);
 
 WEBCORE_EXPORT bool areRangesEqual(const Range*, const Range*);
 bool rangesOverlap(const Range*, const Range*);
index 0ef7bda..6d73cae 100644 (file)
@@ -273,7 +273,7 @@ void AlternativeTextController::applyAlternativeTextToRange(const Range* range,
     RefPtr<Range> rangeWithAlternative = range->cloneRange(ec);
 
     ContainerNode& rootNode = paragraphRangeContainingCorrection.get()->startContainer()->treeScope().rootNode();
-    int paragraphStartIndex = TextIterator::rangeLength(Range::create(rootNode.document(), &rootNode, 0, paragraphRangeContainingCorrection.get()->startContainer(), paragraphRangeContainingCorrection.get()->startOffset()).get());
+    int paragraphStartIndex = TextIterator::rangeLength(Range::create(rootNode.document(), &rootNode, 0, paragraphRangeContainingCorrection->startContainer(), paragraphRangeContainingCorrection->startOffset()).ptr());
     applyCommand(SpellingCorrectionCommand::create(rangeWithAlternative, alternative));
     // Recalculate pragraphRangeContainingCorrection, since SpellingCorrectionCommand modified the DOM, such that the original paragraphRangeContainingCorrection is no longer valid. Radar: 10305315 Bugzilla: 89526
     paragraphRangeContainingCorrection = TextIterator::rangeFromLocationAndLength(&rootNode, paragraphStartIndex, correctionStartOffsetInParagraph + alternative.length());
index 416a001..372b557 100644 (file)
@@ -569,7 +569,7 @@ void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> p
     RefPtr<Text> node(prpNode);
     DocumentMarkerController& markerController = document().markers();
     Vector<RenderedDocumentMarker> markers;
-    copyMarkers(markerController.markersInRange(Range::create(document(), node, offset, node, offset + count).get(), DocumentMarker::AllMarkers()), markers);
+    copyMarkers(markerController.markersInRange(Range::create(document(), node, offset, node, offset + count).ptr(), DocumentMarker::AllMarkers()), markers);
     replaceTextInNode(node, offset, count, replacementText);
     RefPtr<Range> newRange = Range::create(document(), node, offset, node, offset + replacementText.length());
     for (const auto& marker : markers)
index 04c1395..e5984d9 100644 (file)
@@ -1830,7 +1830,7 @@ void charactersAroundPosition(const VisiblePosition& position, UChar32& oneAfter
     }
 
     if (startPosition != endPosition) {
-        String characterString = plainText(Range::create(position.deepEquivalent().anchorNode()->document(), startPosition, endPosition).get()).replace(noBreakSpace, ' ');
+        String characterString = plainText(Range::create(position.deepEquivalent().anchorNode()->document(), startPosition, endPosition).ptr()).replace(noBreakSpace, ' ');
         for (int i = characterString.length() - 1, index = 0; i >= 0 && index < maxCharacters; --i) {
             if (!index && nextPosition.isNull())
                 index++;
index e8dd860..dc31166 100644 (file)
@@ -276,7 +276,7 @@ String StyledMarkupAccumulator::renderedText(const Node& node, const Range* rang
 
     Position start = createLegacyEditingPosition(const_cast<Node*>(&node), startOffset);
     Position end = createLegacyEditingPosition(const_cast<Node*>(&node), endOffset);
-    return plainText(Range::create(node.document(), start, end).get(), behavior);
+    return plainText(Range::create(node.document(), start, end).ptr(), behavior);
 }
 
 String StyledMarkupAccumulator::stringValueForRange(const Node& node, const Range* range)
index 14364ac..644420d 100644 (file)
@@ -544,7 +544,7 @@ static bool relinquishesEditingFocus(Node *node)
     if (!frame || !root)
         return false;
 
-    return frame->editor().shouldEndEditing(rangeOfContents(*root).get());
+    return frame->editor().shouldEndEditing(rangeOfContents(*root).ptr());
 }
 
 static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFrame, Node* newFocusedNode)
index 5058a37..3331e9b 100644 (file)
@@ -1,3 +1,15 @@
+2014-12-17  Andreas Kling  <akling@apple.com>
+
+        Ref-ify Range::create().
+        <https://webkit.org/b/139755>
+
+        Reviewed by Anders Carlsson.
+
+        * WebView/WebHTMLRepresentation.mm:
+        (-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView attributedString]):
+
 2014-12-17  Anders Carlsson  <andersca@apple.com>
 
         Unify -[WebResource description]
index 6e40ae5..c4506e8 100644 (file)
@@ -277,7 +277,7 @@ static NSMutableArray *newArrayByConcatenatingArrays(NSArray *first, NSArray *se
 
 - (NSAttributedString *)attributedStringFrom:(DOMNode *)startNode startOffset:(int)startOffset to:(DOMNode *)endNode endOffset:(int)endOffset
 {
-    return editingAttributedStringFromRange(*Range::create(core(startNode)->document(), core(startNode), startOffset, core(endNode), endOffset));
+    return editingAttributedStringFromRange(Range::create(core(startNode)->document(), core(startNode), startOffset, core(endNode), endOffset));
 }
 #endif
 
index 44669bc..ca9b835 100644 (file)
@@ -6717,7 +6717,7 @@ static CGImageRef selectionImage(Frame* frame, bool forceBlackText)
     NSAttributedString *attributedString = [self _attributeStringFromDOMRange:[document _documentRange]];
     if (!attributedString) {
         Document* coreDocument = core(document);
-        attributedString = editingAttributedStringFromRange(*Range::create(*coreDocument, coreDocument, 0, coreDocument, coreDocument->countChildNodes()));
+        attributedString = editingAttributedStringFromRange(Range::create(*coreDocument, coreDocument, 0, coreDocument, coreDocument->countChildNodes()));
     }
     return attributedString;
 }