Commit dbc78b57 authored by akling@apple.com's avatar akling@apple.com

Range constructors should take a Document&.

<https://webkit.org/b/122435>

Reviewed by Sam Weinig.

Source/WebCore:

Make all Range constructors take Document& instead of a PassRefPtr.
This removes one null check at every call site.

Also use a Ref<Document> for storage in Range.

Source/WTF:

Give Ref an assignment operator.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157018 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d40ca2ec
2013-10-06 Andreas Kling <akling@apple.com>
Range constructors should take a Document&.
<https://webkit.org/b/122435>
Reviewed by Sam Weinig.
Give Ref an assignment operator.
2013-10-05 Anders Carlsson <andersca@apple.com>
Clean up MessageQueue.h
......
......@@ -33,6 +33,13 @@ namespace WTF {
template<typename T> class Ref {
public:
Ref(T& object) : m_ptr(&object) { m_ptr->ref(); }
Ref& operator=(T& object)
{
object.ref();
m_ptr->deref();
m_ptr = &object;
return *this;
}
~Ref() { m_ptr->deref(); }
......
2013-10-06 Andreas Kling <akling@apple.com>
Range constructors should take a Document&.
<https://webkit.org/b/122435>
Reviewed by Sam Weinig.
Make all Range constructors take Document& instead of a PassRefPtr.
This removes one null check at every call site.
Also use a Ref<Document> for storage in Range.
2013-10-06 Antti Koivisto <antti@apple.com>
Factor text paint style computation out from InlineTextBox
......@@ -929,8 +929,8 @@ __ZN7WebCore5Range13setStartAfterEPNS_4NodeERi
__ZN7WebCore5Range14isPointInRangeEPNS_4NodeEiRi
__ZN7WebCore5Range14setStartBeforeEPNS_4NodeERi
__ZN7WebCore5Range18selectNodeContentsEPNS_4NodeERi
__ZN7WebCore5Range6createEN3WTF10PassRefPtrINS_8DocumentEEE
__ZN7WebCore5Range6createEN3WTF10PassRefPtrINS_8DocumentEEENS2_INS_4NodeEEEiS6_i
__ZN7WebCore5Range6createERNS_8DocumentE
__ZN7WebCore5Range6createERNS_8DocumentEN3WTF10PassRefPtrINS_4NodeEEEiS6_i
__ZN7WebCore5Range6setEndEN3WTF10PassRefPtrINS_4NodeEEEiRi
__ZN7WebCore5Range8collapseEbRi
__ZN7WebCore5Range8setStartEN3WTF10PassRefPtrINS_4NodeEEEiRi
......
......@@ -214,7 +214,7 @@ void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject* obje
// Consider previous text objects that might be present for
// the current accessibility object to ensure we emit the
// right offset (e.g. multiline text areas).
RefPtr<Range> range = Range::create(&document, node->parentNode(), 0, node, 0);
RefPtr<Range> range = Range::create(document, node->parentNode(), 0, node, 0);
offsetToEmit = offset + TextIterator::rangeLength(range.get());
}
......
......@@ -260,7 +260,7 @@ static gint webkitAccessibleHyperlinkGetStartIndex(AtkHyperlink* link)
if (!parentNode)
return 0;
RefPtr<Range> range = Range::create(&node->document(), firstPositionInOrBeforeNode(parentNode), firstPositionInOrBeforeNode(node));
RefPtr<Range> range = Range::create(node->document(), firstPositionInOrBeforeNode(parentNode), firstPositionInOrBeforeNode(node));
return getRangeLengthForObject(coreObject, range.get());
}
......@@ -286,7 +286,7 @@ static gint webkitAccessibleHyperlinkGetEndIndex(AtkHyperlink* link)
if (!parentNode)
return 0;
RefPtr<Range> range = Range::create(&node->document(), firstPositionInOrBeforeNode(parentNode), lastPositionInOrAfterNode(node));
RefPtr<Range> range = Range::create(node->document(), firstPositionInOrBeforeNode(parentNode), lastPositionInOrAfterNode(node));
return getRangeLengthForObject(coreObject, range.get());
}
......
......@@ -532,12 +532,12 @@ static void getSelectionOffsetsForObject(AccessibilityObject* coreObject, Visibl
// Calculate position of the selected range inside the object.
Position parentFirstPosition = firstPositionInOrBeforeNode(node);
RefPtr<Range> rangeInParent = Range::create(&node->document(), parentFirstPosition, nodeRangeStart);
RefPtr<Range> rangeInParent = Range::create(node->document(), parentFirstPosition, nodeRangeStart);
// Set values for start offsets and calculate initial range length.
// These values might be adjusted later to cover special cases.
startOffset = webCoreOffsetToAtkOffset(coreObject, TextIterator::rangeLength(rangeInParent.get(), true));
RefPtr<Range> nodeRange = Range::create(&node->document(), nodeRangeStart, nodeRangeEnd);
RefPtr<Range> nodeRange = Range::create(node->document(), nodeRangeStart, nodeRangeEnd);
int rangeLength = TextIterator::rangeLength(nodeRange.get(), true);
// Special cases that are only relevant when working with *_END boundaries.
......
......@@ -1651,7 +1651,7 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope))
return NSMakeRange(NSNotFound, 0);
RefPtr<Range> testRange = Range::create(&scope->document(), scope, 0, range->startContainer(), range->startOffset());
RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
ASSERT(testRange->startContainer() == scope);
int startPosition = TextIterator::rangeLength(testRange.get());
......
......@@ -1461,7 +1461,7 @@ PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
if (shadowAncestorNode != node) {
unsigned offset = shadowAncestorNode->nodeIndex();
ContainerNode* container = shadowAncestorNode->parentNode();
return Range::create(this, container, offset, container, offset);
return Range::create(*this, container, offset, container, offset);
}
RenderObject* renderer = node->renderer();
......@@ -1472,7 +1472,7 @@ PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
return 0;
Position rangeCompliantPosition = visiblePosition.deepEquivalent().parentAnchoredEquivalent();
return Range::create(this, rangeCompliantPosition, rangeCompliantPosition);
return Range::create(*this, rangeCompliantPosition, rangeCompliantPosition);
}
/*
......@@ -1688,7 +1688,7 @@ Settings* Document::settings() const
PassRefPtr<Range> Document::createRange()
{
return Range::create(this);
return Range::create(*this);
}
PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow,
......
......@@ -2277,7 +2277,7 @@ void Node::removedLastRef()
void Node::textRects(Vector<IntRect>& rects) const
{
RefPtr<Range> range = Range::create(&document());
RefPtr<Range> range = Range::create(document());
range->selectNodeContents(const_cast<Node*>(this), IGNORE_EXCEPTION);
range->textRects(rects);
}
......
This diff is collapsed.
......@@ -48,12 +48,13 @@ class Text;
class Range : public RefCounted<Range> {
public:
static PassRefPtr<Range> create(PassRefPtr<Document>);
static PassRefPtr<Range> create(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
static PassRefPtr<Range> create(PassRefPtr<Document>, const Position&, const Position&);
static PassRefPtr<Range> create(Document&);
static PassRefPtr<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
static PassRefPtr<Range> create(Document&, const Position&, const Position&);
~Range();
Document& ownerDocument() const { return *m_ownerDocument; }
Document& ownerDocument() const { return const_cast<Document&>(m_ownerDocument.get()); }
Node* startContainer() const { return m_start.container(); }
int startOffset() const { return m_start.offset(); }
Node* endContainer() const { return m_end.container(); }
......@@ -149,8 +150,8 @@ public:
#endif
private:
explicit Range(PassRefPtr<Document>);
Range(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
explicit Range(Document&);
Range(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
void setDocument(Document&);
......@@ -168,7 +169,7 @@ private:
enum ContentsProcessDirection { ProcessContentsForward, ProcessContentsBackward };
static PassRefPtr<Node> processAncestorsAndTheirSiblings(ActionType, Node* container, ContentsProcessDirection, PassRefPtr<Node> clonedContainer, Node* commonRoot, ExceptionCode&);
RefPtr<Document> m_ownerDocument;
Ref<Document> m_ownerDocument;
RangeBoundaryPoint m_start;
RangeBoundaryPoint m_end;
};
......
......@@ -262,7 +262,7 @@ void AlternativeTextController::applyAlternativeTextToRange(const Range* range,
// relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph
// to store this value. In order to obtain this offset, we need to first create a range
// which spans from the start of paragraph to the start position of rangeWithAlternative.
RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(&paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition());
RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition());
if (ec)
return;
......@@ -277,7 +277,7 @@ void AlternativeTextController::applyAlternativeTextToRange(const Range* range,
// Clone the range, since the caller of this method may want to keep the original range around.
RefPtr<Range> rangeWithAlternative = range->cloneRange(ec);
int paragraphStartIndex = TextIterator::rangeLength(Range::create(m_frame.document(), m_frame.document(), 0, paragraphRangeContainingCorrection.get()->startContainer(), paragraphRangeContainingCorrection.get()->startOffset()).get());
int paragraphStartIndex = TextIterator::rangeLength(Range::create(*m_frame.document(), m_frame.document(), 0, paragraphRangeContainingCorrection.get()->startContainer(), paragraphRangeContainingCorrection.get()->startOffset()).get());
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(m_frame.document(), paragraphStartIndex, correctionStartOffsetInParagraph + alternative.length());
......@@ -323,7 +323,7 @@ void AlternativeTextController::respondToUnappliedSpellCorrection(const VisibleS
client->recordAutocorrectionResponse(AutocorrectionReverted, corrected, correction);
m_frame.document()->updateLayout();
m_frame.selection().setSelection(selectionOfCorrected, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::SpellCorrectionTriggered);
RefPtr<Range> range = Range::create(m_frame.document(), m_frame.selection().selection().start(), m_frame.selection().selection().end());
RefPtr<Range> range = Range::create(*m_frame.document(), m_frame.selection().selection().start(), m_frame.selection().selection().end());
DocumentMarkerController& markers = m_frame.document()->markers();
markers.removeMarkers(range.get(), DocumentMarker::Spelling | DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker);
......@@ -499,7 +499,7 @@ void AlternativeTextController::respondToUnappliedEditing(EditCommandComposition
{
if (!command->wasCreateLinkCommand())
return;
RefPtr<Range> range = Range::create(m_frame.document(), command->startingSelection().start(), command->startingSelection().end());
RefPtr<Range> range = Range::create(*m_frame.document(), command->startingSelection().start(), command->startingSelection().end());
if (!range)
return;
DocumentMarkerController& markers = m_frame.document()->markers();
......@@ -591,7 +591,7 @@ void AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionA
if (endOfSelection == precedingCharacterPosition)
return;
RefPtr<Range> precedingCharacterRange = Range::create(m_frame.document(), precedingCharacterPosition, endOfSelection);
RefPtr<Range> precedingCharacterRange = Range::create(*m_frame.document(), precedingCharacterPosition, endOfSelection);
String string = plainText(precedingCharacterRange.get());
if (string.isEmpty() || !isWhitespace(string[string.length() - 1]))
return;
......@@ -616,7 +616,7 @@ bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const T
Position beginningOfRange = rangeWithAlternative->startPosition();
Position precedingCharacterPosition = beginningOfRange.previous();
RefPtr<Range> precedingCharacterRange = Range::create(m_frame.document(), precedingCharacterPosition, beginningOfRange);
RefPtr<Range> precedingCharacterRange = Range::create(*m_frame.document(), precedingCharacterPosition, beginningOfRange);
Vector<DocumentMarker*> markers = markerController.markersInRange(precedingCharacterRange.get(), DocumentMarker::DeletedAutocorrection);
......@@ -640,7 +640,7 @@ bool AlternativeTextController::respondToMarkerAtEndOfWord(const DocumentMarker&
if (!shouldStartTimerFor(marker, endOfWordPosition.offsetInContainerNode()))
return false;
Node* node = endOfWordPosition.containerNode();
RefPtr<Range> wordRange = Range::create(m_frame.document(), node, marker.startOffset(), node, marker.endOffset());
RefPtr<Range> wordRange = Range::create(*m_frame.document(), node, marker.startOffset(), node, marker.endOffset());
if (!wordRange)
return false;
String currentWord = plainText(wordRange.get());
......
......@@ -264,8 +264,8 @@ void ApplyStyleCommand::applyBlockStyle(EditingStyle *style)
// addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoints.
// Calculate start and end indices from the start of the tree that they're in.
Node* scope = highestAncestor(visibleStart.deepEquivalent().deprecatedNode());
RefPtr<Range> startRange = Range::create(&document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> endRange = Range::create(&document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
int startIndex = TextIterator::rangeLength(startRange.get(), true);
int endIndex = TextIterator::rangeLength(endRange.get(), true);
......@@ -704,7 +704,7 @@ void ApplyStyleCommand::fixRangeAndApplyInlineStyle(EditingStyle* style, const P
// Start from the highest fully selected ancestor so that we can modify the fully selected node.
// e.g. When applying font-size: large on <font color="blue">hello</font>, we need to include the font element in our run
// to generate <font color="blue" size="4">hello</font> instead of <font color="blue"><font size="4">hello</font></font>
RefPtr<Range> range = Range::create(&startNode->document(), start, end);
RefPtr<Range> range = Range::create(startNode->document(), start, end);
Element* editableRoot = startNode->rootEditableElement();
if (startNode != editableRoot) {
while (editableRoot && startNode->parentNode() != editableRoot && isNodeVisiblyContainedWithin(startNode->parentNode(), range.get()))
......
......@@ -533,9 +533,9 @@ void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> p
RefPtr<Text> node(prpNode);
DocumentMarkerController& markerController = document().markers();
Vector<DocumentMarker> 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).get(), DocumentMarker::AllMarkers()), markers);
replaceTextInNode(node, offset, count, replacementText);
RefPtr<Range> newRange = Range::create(&document(), node, offset, node, offset + replacementText.length());
RefPtr<Range> newRange = Range::create(document(), node, offset, node, offset + replacementText.length());
for (size_t i = 0; i < markers.size(); ++i)
markerController.addMarker(newRange.get(), markers[i].type(), markers[i].description());
}
......@@ -1165,13 +1165,13 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
startIndex = 0;
if (startInParagraph) {
RefPtr<Range> startRange = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent());
startIndex = TextIterator::rangeLength(startRange.get(), true);
}
endIndex = 0;
if (endInParagraph) {
RefPtr<Range> endRange = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> endRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
endIndex = TextIterator::rangeLength(endRange.get(), true);
}
}
......@@ -1188,7 +1188,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
// start and end can't be used directly to create a Range; they are "editing positions"
Position startRangeCompliant = start.parentAnchoredEquivalent();
Position endRangeCompliant = end.parentAnchoredEquivalent();
RefPtr<Range> range = Range::create(&document(), startRangeCompliant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset());
RefPtr<Range> range = Range::create(document(), startRangeCompliant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset());
// FIXME: This is an inefficient way to preserve style on nodes in the paragraph to move. It
// shouldn't matter though, since moved paragraphs will usually be quite small.
......@@ -1234,7 +1234,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
document().updateLayoutIgnorePendingStylesheets();
}
RefPtr<Range> startToDestinationRange(Range::create(&document(), firstPositionInNode(document().documentElement()), destination.deepEquivalent().parentAnchoredEquivalent()));
RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document().documentElement()), destination.deepEquivalent().parentAnchoredEquivalent()));
destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true);
setEndingSelection(VisibleSelection(destination, originalIsDirectional));
......
......@@ -657,8 +657,8 @@ void DeleteSelectionCommand::mergeParagraphs()
return;
}
RefPtr<Range> range = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> rangeToBeReplaced = Range::create(&document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> range = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> rangeToBeReplaced = Range::create(document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
if (!frame().editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
return;
......@@ -760,7 +760,7 @@ String DeleteSelectionCommand::originalStringForAutocorrectionAtBeginningOfSelec
if (nextPosition.isNull())
return String();
RefPtr<Range> rangeOfFirstCharacter = Range::create(&document(), startOfSelection.deepEquivalent(), nextPosition.deepEquivalent());
RefPtr<Range> rangeOfFirstCharacter = Range::create(document(), startOfSelection.deepEquivalent(), nextPosition.deepEquivalent());
Vector<DocumentMarker*> markers = document().markers().markersInRange(rangeOfFirstCharacter.get(), DocumentMarker::Autocorrected);
for (size_t i = 0; i < markers.size(); ++i) {
const DocumentMarker* marker = markers[i];
......
......@@ -1277,7 +1277,7 @@ WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection&
if (selection.isRange()) {
end = selection.end().upstream();
Node* pastLast = Range::create(end.document(), position.parentAnchoredEquivalent(), end.parentAnchoredEquivalent())->pastLastNode();
Node* pastLast = Range::create(*end.document(), position.parentAnchoredEquivalent(), end.parentAnchoredEquivalent())->pastLastNode();
for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(n)) {
if (!n->isStyledElement())
continue;
......
......@@ -131,7 +131,7 @@ PassRefPtr<Range> Editor::avoidIntersectionWithDeleteButtonController(const Rang
endOffset = element->nodeIndex();
}
return Range::create(&range->ownerDocument(), startContainer, startOffset, endContainer, endOffset);
return Range::create(range->ownerDocument(), startContainer, startOffset, endContainer, endOffset);
}
VisibleSelection Editor::avoidIntersectionWithDeleteButtonController(const VisibleSelection& selection) const
......@@ -487,7 +487,7 @@ void Editor::replaceSelectionWithFragment(PassRefPtr<DocumentFragment> fragment,
if (!nodeToCheck)
return;
RefPtr<Range> rangeToCheck = Range::create(&document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck));
RefPtr<Range> rangeToCheck = Range::create(document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck));
m_spellChecker->requestCheckingFor(SpellCheckRequest::create(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextCheckingProcessBatch, rangeToCheck, rangeToCheck));
}
......@@ -1630,7 +1630,7 @@ void Editor::setComposition(const String& text, const Vector<CompositionUnderlin
unsigned start = min(baseOffset + selectionStart, extentOffset);
unsigned end = min(max(start, baseOffset + selectionEnd), extentOffset);
RefPtr<Range> selectedRange = Range::create(&baseNode->document(), baseNode, start, baseNode, end);
RefPtr<Range> selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end);
m_frame.selection().setSelectedRange(selectedRange.get(), DOWNSTREAM, false);
}
}
......@@ -2481,7 +2481,7 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA
// garde", we will have CorrectionIndicator marker on both words and on the whitespace between them. If we then edit garde,
// we would like to remove the marker from word "avant" and whitespace as well. So we need to get the continous range of
// of marker that contains the word in question, and remove marker on that whole range.
RefPtr<Range> wordRange = Range::create(&document(), startOfFirstWord.deepEquivalent(), endOfLastWord.deepEquivalent());
RefPtr<Range> wordRange = Range::create(document(), startOfFirstWord.deepEquivalent(), endOfLastWord.deepEquivalent());
Vector<DocumentMarker*> markers = document().markers().markersInRange(wordRange.get(), DocumentMarker::DictationAlternatives);
for (size_t i = 0; i < markers.size(); ++i)
......@@ -2540,7 +2540,7 @@ PassRefPtr<Range> Editor::compositionRange() const
unsigned end = min(max(start, m_compositionEnd), length);
if (start >= end)
return 0;
return Range::create(&m_compositionNode->document(), m_compositionNode.get(), start, m_compositionNode.get(), end);
return Range::create(m_compositionNode->document(), m_compositionNode.get(), start, m_compositionNode.get(), end);
}
bool Editor::getCompositionSelection(unsigned& selectionStart, unsigned& selectionEnd) const
......
......@@ -270,7 +270,7 @@ static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION) <= 0 ? a : b;
Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION) <= 0 ? b : a;
return Range::create(&a->ownerDocument(), start->startContainer(), start->startOffset(), end->endContainer(), end->endOffset());
return Range::create(a->ownerDocument(), start->startContainer(), start->startOffset(), end->endContainer(), end->endOffset());
}
// Execute command functions
......
......@@ -65,7 +65,7 @@ void FormatBlockCommand::formatRange(const Position& start, const Position& end,
RefPtr<Node> outerBlock = (start.deprecatedNode() == nodeToSplitTo) ? start.deprecatedNode() : splitTreeToNode(start.deprecatedNode(), nodeToSplitTo);
RefPtr<Node> nodeAfterInsertionPosition = outerBlock;
RefPtr<Range> range = Range::create(&document(), start, endOfSelection);
RefPtr<Range> range = Range::create(document(), start, endOfSelection);
Element* refNode = enclosingBlockFlowElement(end);
Element* root = editableRootForPosition(start);
// Root is null for elements with contenteditable=false.
......
......@@ -184,7 +184,7 @@ PassRefPtr<Range> TextCheckingParagraph::offsetAsRange() const
{
ASSERT(m_checkingRange);
if (!m_offsetAsRange)
m_offsetAsRange = Range::create(&paragraphRange()->startContainer()->document(), paragraphRange()->startPosition(), checkingRange()->startPosition());
m_offsetAsRange = Range::create(paragraphRange()->startContainer()->document(), paragraphRange()->startPosition(), checkingRange()->startPosition());
return m_offsetAsRange;
}
......@@ -315,7 +315,7 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b
int totalRangeLength = TextIterator::rangeLength(paragraphRange.get());
setEnd(paragraphRange.get(), endOfParagraph(m_range->startPosition()));
RefPtr<Range> offsetAsRange = Range::create(&paragraphRange->startContainer()->document(), paragraphRange->startPosition(), m_range->startPosition());
RefPtr<Range> offsetAsRange = Range::create(paragraphRange->startContainer()->document(), paragraphRange->startPosition(), m_range->startPosition());
int rangeStartOffset = TextIterator::rangeLength(offsetAsRange.get());
int totalLengthProcessed = 0;
......@@ -329,7 +329,7 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b
if (inSameParagraph(paragraphRange->startPosition(), m_range->endPosition())) {
// Determine the character offset from the end of the original search range to the end of the paragraph,
// since we will want to ignore results in this area.
RefPtr<Range> endOffsetAsRange = Range::create(&paragraphRange->startContainer()->document(), paragraphRange->startPosition(), m_range->endPosition());
RefPtr<Range> endOffsetAsRange = Range::create(paragraphRange->startContainer()->document(), paragraphRange->startPosition(), m_range->endPosition());
currentEndOffset = TextIterator::rangeLength(endOffsetAsRange.get());
lastIteration = true;
}
......@@ -382,7 +382,7 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b
if (!misspelledWord.isEmpty() && (!checkGrammar || badGrammarPhrase.isEmpty() || spellingLocation <= grammarDetailLocation)) {
int spellingOffset = spellingLocation - currentStartOffset;
if (!firstIteration) {
RefPtr<Range> paragraphOffsetAsRange = Range::create(&paragraphRange->startContainer()->document(), m_range->startPosition(), paragraphRange->startPosition());
RefPtr<Range> paragraphOffsetAsRange = Range::create(paragraphRange->startContainer()->document(), m_range->startPosition(), paragraphRange->startPosition());
spellingOffset += TextIterator::rangeLength(paragraphOffsetAsRange.get());
}
outIsSpelling = true;
......@@ -393,7 +393,7 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b
if (checkGrammar && !badGrammarPhrase.isEmpty()) {
int grammarPhraseOffset = grammarPhraseLocation - currentStartOffset;
if (!firstIteration) {
RefPtr<Range> paragraphOffsetAsRange = Range::create(&paragraphRange->startContainer()->document(), m_range->startPosition(), paragraphRange->startPosition());
RefPtr<Range> paragraphOffsetAsRange = Range::create(paragraphRange->startContainer()->document(), m_range->startPosition(), paragraphRange->startPosition());
grammarPhraseOffset += TextIterator::rangeLength(paragraphOffsetAsRange.get());
}
outIsSpelling = false;
......
......@@ -1065,12 +1065,12 @@ PassRefPtr<Range> TextIterator::range() const
m_positionEndOffset += index;
m_positionOffsetBaseNode = 0;
}
return Range::create(&m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
return Range::create(m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
}
// otherwise, return the end of the overall range we were given
if (m_endContainer)
return Range::create(&m_endContainer->document(), m_endContainer, m_endOffset, m_endContainer, m_endOffset);
return Range::create(m_endContainer->document(), m_endContainer, m_endOffset, m_endContainer, m_endOffset);
return 0;
}
......@@ -1367,9 +1367,9 @@ bool SimplifiedBackwardsTextIterator::advanceRespectingRange(Node* next)
PassRefPtr<Range> SimplifiedBackwardsTextIterator::range() const
{
if (m_positionNode)
return Range::create(&m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
return Range::create(m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
return Range::create(&m_startNode->document(), m_startNode, m_startOffset, m_startNode, m_startOffset);
return Range::create(m_startNode->document(), m_startNode, m_startOffset, m_startNode, m_startOffset);
}
// --------
......@@ -1468,7 +1468,7 @@ static PassRefPtr<Range> characterSubrange(CharacterIterator& it, int offset, in
it.advance(length - 1);
RefPtr<Range> end = it.range();
return Range::create(&start->startContainer()->document(),
return Range::create(start->startContainer()->document(),
start->startContainer(), start->startOffset(),
end->endContainer(), end->endOffset());
}
......@@ -2504,7 +2504,7 @@ bool TextIterator::getLocationAndLengthFromRange(Node* scope, const Range* range
if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope))
return false;
RefPtr<Range> testRange = Range::create(&scope->document(), scope, 0, range->startContainer(), range->startOffset());
RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
ASSERT(testRange->startContainer() == scope);
location = TextIterator::rangeLength(testRange.get());
......
......@@ -678,7 +678,7 @@ PassRefPtr<Range> makeRange(const VisiblePosition &start, const VisiblePosition
if (s.isNull() || e.isNull())
return 0;
return Range::create(&s.containerNode()->document(), s.containerNode(), s.offsetInContainerNode(), e.containerNode(), e.offsetInContainerNode());
return Range::create(s.containerNode()->document(), s.containerNode(), s.offsetInContainerNode(), e.containerNode(), e.offsetInContainerNode());
}
VisiblePosition startVisiblePosition(const Range *r, EAffinity affinity)
......
......@@ -130,7 +130,7 @@ PassRefPtr<Range> VisibleSelection::firstRange() const
return 0;
Position start = m_start.parentAnchoredEquivalent();
Position end = m_end.parentAnchoredEquivalent();
return Range::create(&start.anchorNode()->document(), start, end);
return Range::create(start.anchorNode()->document(), start, end);
}
PassRefPtr<Range> VisibleSelection::toNormalizedRange() const
......@@ -186,7 +186,7 @@ PassRefPtr<Range> VisibleSelection::toNormalizedRange() const
// VisibleSelections are supposed to always be valid. This constructor will ASSERT
// if a valid range could not be created, which is fine for this callsite.
return Range::create(&s.anchorNode()->document(), s, e);
return Range::create(s.anchorNode()->document(), s, e);
}
bool VisibleSelection::expandUsingGranularity(TextGranularity granularity)
......@@ -210,7 +210,7 @@ static PassRefPtr<Range> makeSearchRange(const Position& pos)
if (!boundary)
return 0;
RefPtr<Range> searchRange(Range::create(&n->document()));
RefPtr<Range> searchRange(Range::create(n->document()));
ExceptionCode ec = 0;
Position start(pos.parentAnchoredEquivalent());
......
......@@ -457,7 +457,7 @@ static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
Document& boundaryDocument = boundary->document();
Position start = createLegacyEditingPosition(boundary, 0).parentAnchoredEquivalent();
Position end = pos.parentAnchoredEquivalent();
RefPtr<Range> searchRange = Range::create(&boundaryDocument);
RefPtr<Range> searchRange = Range::create(boundaryDocument);
Vector<UChar, 1024> string;
unsigned suffixLength = 0;
......
......@@ -537,46 +537,6 @@ VisiblePosition visiblePositionAfterNode(Node* node)
return positionInParentAfterNode(node);
}
// Create a range object with two visible positions, start and end.
// create(PassRefPtr<Document>, const Position&, const Position&); will use deprecatedEditingOffset
// Use this function instead of create a regular range object (avoiding editing offset).
PassRefPtr<Range> createRange(PassRefPtr<Document> document, const VisiblePosition& start, const VisiblePosition& end, ExceptionCode& ec)
{
ec = 0;
RefPtr<Range> selectedRange = Range::create(document);
selectedRange->setStart(start.deepEquivalent().containerNode(), start.deepEquivalent().computeOffsetInContainerNode(), ec);
if (!ec)
selectedRange->setEnd(end.deepEquivalent().containerNode(), end.deepEquivalent().computeOffsetInContainerNode(), ec);
return selectedRange.release();
}
// Extend rangeToExtend to include nodes that wraps range and visibly starts and ends inside or at the boudnaries of maximumRange
// e.g. if the original range spaned "hello" in <div>hello</div>, then this function extends the range to contain div's around it.
// 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.
PassRefPtr<Range> extendRangeToWrappingNodes(PassRefPtr<Range> range, const Range* maximumRange, const Node* rootNode)
{
ASSERT(range);
ASSERT(maximumRange);
Node* ancestor = range->commonAncestorContainer(IGNORE_EXCEPTION); // Find the closest common ancestor.
Node* highestNode = 0;
// 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, maximumRange) && ancestor != rootNode) {
highestNode = ancestor;
ancestor = ancestor->parentNode();
}
if (!highestNode)
return range;
// Create new range with the highest editable node contained within the range
RefPtr<Range> extendedRange = Range::create(&range->ownerDocument());
extendedRange->selectNode(highestNode, IGNORE_EXCEPTION);
return extendedRange.release();
}
bool isListElement(Node *n)
{
return (n && (n->hasTagName(ulTag) || n->hasTagName(olTag) || n->hasTagName(dlTag)));
......@@ -1155,8 +1115,7 @@ int indexForVisiblePosition(const VisiblePosition& visiblePosition, RefPtr<Conta
else
scope = document.documentElement();
RefPtr<Range> range = Range::create(&document, firstPositionInNode(scope.get()), p.parentAnchoredEquivalent());
RefPtr<Range> range = Range::create(document, firstPositionInNode(scope.get()), p.parentAnchoredEquivalent());
return TextIterator::rangeLength(range.get(), true);
}
......@@ -1164,7 +1123,7 @@ int indexForVisiblePosition(const VisiblePosition& visiblePosition, RefPtr<Conta
int indexForVisiblePosition(Node* node, const VisiblePosition& visiblePosition, bool forSelectionPreservation)
{
ASSERT(node);
RefPtr<Range> range = Range::create(&node->document(), firstPositionInNode(node), visiblePosition.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> range = Range::create(node->document(), firstPositionInNode(node), visiblePosition.deepEquivalent().parentAnchoredEquivalent());
return TextIterator::rangeLength(range.get(), forSelectionPreservation);
}
......@@ -1184,7 +1143,7 @@ VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node* node, int in
if (index <= 0)
return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
RefPtr<Range> range = Range::create(&node->document());
RefPtr<Range> range = Range::create(node->document());
range->selectNodeContents(node, IGNORE_EXCEPTION);
CharacterIterator it(range.get());
it.advance(index - 1);
......
......@@ -193,15 +193,6 @@ int indexForVisiblePosition(Node*, const VisiblePosition&, bool forSelectionPres
VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope);