Commit b7bf13ad authored by darin@apple.com's avatar darin@apple.com
Browse files

WebCore:

        Reviewed by Mitz.

        - make some Range improvements (preparation for Range support for DOM mutation)

        Made constructors private, added create functions.
        Made refcount start at 1 rather than starting at 0 and being incremented.
        Made Range use two Position objects for the start/end container/offset pairs.

        * WebCore.base.exp: Updated.

        * dom/Document.cpp:
        (WebCore::Document::createRange): Changed to use Range::create.
        (WebCore::Document::removeMarkers): Updated for Range::first/pastLastNode name change.

        * dom/Position.cpp:
        (WebCore::Position::formatForDebugger): Updated for member variable name change.
        (WebCore::Position::showTreeForThis): Ditto.
        (WebCore::startPosition): Changed to use Range::startPosition.
        (WebCore::endPosition): Changed to use Range::endPosition.

        * dom/Position.h: Made the data members public and renamed them to container
        and offset. But since offset() is already a function, temporarily used posOffset
        for the data member. Later we'll get rid of offset(). Made more functions inline.
        Removed the constructor that takes a PositionIterator.

        * dom/PositionIterator.cpp:
        (WebCore::PositionIterator::operator Position): Added. Replaces the constructor
        that used to be in Position.
        * dom/PositionIterator.h: Added conversion operator to produce a Position.
        Removed friend declaration for Position.

        * dom/Range.cpp:
        (WebCore::Range::Range): Updated constructors for data member changes and made
        them use a refcount of 1.
        (WebCore::Range::create): Added.
        (WebCore::Range::startContainer): Updated to eliminate use of m_detached; detached
        is now indicated by m_start.container of 0. Also updated to use m_start instead
        of the old m_startContainer.
        (WebCore::Range::startOffset): Ditto.
        (WebCore::Range::endContainer): Ditto.
        (WebCore::Range::endOffset): Ditto.
        (WebCore::Range::commonAncestorContainer): Ditto.
        (WebCore::Range::collapsed): Ditto.
        (WebCore::Range::setStart): Ditto.
        (WebCore::Range::setEnd): Ditto.
        (WebCore::Range::collapse): Ditto.
        (WebCore::Range::isPointInRange): Ditto.
        (WebCore::Range::comparePoint): Ditto.
        (WebCore::Range::compareNode): Ditto.
        (WebCore::Range::compareBoundaryPoints): Ditto.
        (WebCore::Range::boundaryPointsValid): Ditto.
        (WebCore::Range::deleteContents): Ditto.
        (WebCore::Range::intersectsNode): Ditto.
        (WebCore::Range::processContents): Ditto.
        (WebCore::Range::extractContents): Ditto.
        (WebCore::Range::cloneContents): Ditto.
        (WebCore::Range::insertNode): Ditto.
        (WebCore::Range::toString): Ditto.
        (WebCore::Range::text): Ditto.
        (WebCore::Range::createContextualFragment): Ditto.
        (WebCore::Range::detach): Ditto.
        (WebCore::Range::checkNodeBA): Changed to use switch statements instead of
        multiple calls to the virtual nodeType() function.
        (WebCore::Range::cloneRange): Ditto.
        (WebCore::Range::setStartAfter): Ditto.
        (WebCore::Range::setEndBefore): Ditto.
        (WebCore::Range::setEndAfter): Ditto.
        (WebCore::Range::selectNode): Ditto.
        (WebCore::Range::selectNodeContents): Ditto.
        (WebCore::Range::surroundContents): Ditto.
        (WebCore::Range::setStartBefore): Ditto.
        (WebCore::Range::checkDeleteExtract): Ditto.
        (WebCore::Range::containedByReadOnly): Ditto.
        (WebCore::Range::firstNode): Ditto.
        (WebCore::Range::editingStartPosition): Ditto.
        (WebCore::Range::pastLastNode): Ditto.
        (WebCore::Range::addLineBoxRects): Ditto.
        (WebCore::Range::formatForDebugger): Ditto.
        (WebCore::operator==): Ditto.
        (WebCore::rangeOfContents): Ditto.
        (WebCore::Range::maxStartOffset): Ditto.
        (WebCore::Range::maxEndOffset): Ditto.

        * dom/Range.h: Made constructors private. Added create functions.
        Added getters for startContainer/Offset and endContainer/Offset that
        return 0 instead of an exception for detached ranges that are inline
        and don't require an ExceptionCode out parameter. Changed the parameters
        to setStart and setEnd to PassRefPtr. Removed isDetached function.
        Made ActionType and processContents private. Made startPosition and
        endPosition inlines and have then return const&. Renamed startNode and
        pastEndNode to firstNode and pastLastNode to reduce the chance of
        confusion with startContainer/endContainer. Used Position for m_start
        and m_end instead of separate container and offset members. Changed
        maxStartOffset and maxEndOffset into int to match other offsets.

        * editing/ApplyStyleCommand.cpp:
        (WebCore::ApplyStyleCommand::applyBlockStyle): Changed to use Range::create.
        (WebCore::ApplyStyleCommand::applyInlineStyle): Ditto.
        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::inputText): Ditto.
        (WebCore::CompositeEditCommand::moveParagraphs): Ditto.
        * editing/DeleteSelectionCommand.cpp:
        (WebCore::DeleteSelectionCommand::mergeParagraphs): Ditto.
        * editing/Editor.cpp:
        (WebCore::Editor::fontForSelection): Changed for pastLastNode name change.
        (WebCore::Editor::setComposition): Changed to use Range::create.
        (WebCore::paragraphAlignedRangeForRange): Ditto.
        (WebCore::markMisspellingsOrBadGrammar): Changed to get rid of check for
        isDetached and check for 0 from startContainer instead.
        (WebCore::Editor::compositionRange): Changed to use Range::create.
        * editing/EditorCommand.cpp:
        (WebCore::unionDOMRanges): Ditto.
        * editing/Selection.cpp:
        (WebCore::Selection::toRange): Ditto.
        * editing/TextIterator.cpp:
        (WebCore::TextIterator::TextIterator): Changed for firstNode and pastLastNode
        name change.
        (WebCore::TextIterator::range): Changed to use Range::create.
        (WebCore::SimplifiedBackwardsTextIterator::range): Ditto.
        (WebCore::TextIterator::subrange): Ditto.
        * editing/VisiblePosition.cpp:
        (WebCore::makeRange): Ditto.
        * editing/VisiblePosition.h: Added now-needed include.
        * editing/htmlediting.cpp:
        (WebCore::indexForVisiblePosition): Changed to use Range::create.
        (WebCore::avoidIntersectionWithNode): Changed to get rid of check for
        isDetached and check for 0 instead and to use Range::create.
        * editing/markup.cpp:
        (WebCore::renderedText): Changed to use Range::create.
        (WebCore::createMarkup): Changed to no longer use isDetached and also
        for new firstNode/pastEndNode names.
        (WebCore::createFragmentFromText): Ditto.
        * editing/visible_units.cpp:
        (WebCore::previousBoundary): Changed to use Range::create.
        * page/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge convertToNSRange:]): Changed to no longer use
        isDetached().
        * rendering/RenderTextControl.cpp:
        (WebCore::RenderTextControl::visiblePositionForIndex): Changed to use Range::create.
        (WebCore::RenderTextControl::indexForVisiblePosition): Ditto.

WebKit/mac:

        Reviewed by Mitz.

        - update code affected by Range changes

        * Misc/WebNSAttributedStringExtras.mm:
        (+[NSAttributedString _web_attributedStringFromRange:]): Update for name changes.
        * WebView/WebHTMLRepresentation.mm:
        (-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):
        Use Range::create.
        * WebView/WebHTMLView.mm:
        (-[WebHTMLView attributedString]): Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30973 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 95f8b099
2008-03-11 Darin Adler <darin@apple.com>
Reviewed by Mitz.
- make some Range improvements (preparation for Range support for DOM mutation)
Made constructors private, added create functions.
Made refcount start at 1 rather than starting at 0 and being incremented.
Made Range use two Position objects for the start/end container/offset pairs.
* WebCore.base.exp: Updated.
* dom/Document.cpp:
(WebCore::Document::createRange): Changed to use Range::create.
(WebCore::Document::removeMarkers): Updated for Range::first/pastLastNode name change.
* dom/Position.cpp:
(WebCore::Position::formatForDebugger): Updated for member variable name change.
(WebCore::Position::showTreeForThis): Ditto.
(WebCore::startPosition): Changed to use Range::startPosition.
(WebCore::endPosition): Changed to use Range::endPosition.
* dom/Position.h: Made the data members public and renamed them to container
and offset. But since offset() is already a function, temporarily used posOffset
for the data member. Later we'll get rid of offset(). Made more functions inline.
Removed the constructor that takes a PositionIterator.
* dom/PositionIterator.cpp:
(WebCore::PositionIterator::operator Position): Added. Replaces the constructor
that used to be in Position.
* dom/PositionIterator.h: Added conversion operator to produce a Position.
Removed friend declaration for Position.
* dom/Range.cpp:
(WebCore::Range::Range): Updated constructors for data member changes and made
them use a refcount of 1.
(WebCore::Range::create): Added.
(WebCore::Range::startContainer): Updated to eliminate use of m_detached; detached
is now indicated by m_start.container of 0. Also updated to use m_start instead
of the old m_startContainer.
(WebCore::Range::startOffset): Ditto.
(WebCore::Range::endContainer): Ditto.
(WebCore::Range::endOffset): Ditto.
(WebCore::Range::commonAncestorContainer): Ditto.
(WebCore::Range::collapsed): Ditto.
(WebCore::Range::setStart): Ditto.
(WebCore::Range::setEnd): Ditto.
(WebCore::Range::collapse): Ditto.
(WebCore::Range::isPointInRange): Ditto.
(WebCore::Range::comparePoint): Ditto.
(WebCore::Range::compareNode): Ditto.
(WebCore::Range::compareBoundaryPoints): Ditto.
(WebCore::Range::boundaryPointsValid): Ditto.
(WebCore::Range::deleteContents): Ditto.
(WebCore::Range::intersectsNode): Ditto.
(WebCore::Range::processContents): Ditto.
(WebCore::Range::extractContents): Ditto.
(WebCore::Range::cloneContents): Ditto.
(WebCore::Range::insertNode): Ditto.
(WebCore::Range::toString): Ditto.
(WebCore::Range::text): Ditto.
(WebCore::Range::createContextualFragment): Ditto.
(WebCore::Range::detach): Ditto.
(WebCore::Range::checkNodeBA): Changed to use switch statements instead of
multiple calls to the virtual nodeType() function.
(WebCore::Range::cloneRange): Ditto.
(WebCore::Range::setStartAfter): Ditto.
(WebCore::Range::setEndBefore): Ditto.
(WebCore::Range::setEndAfter): Ditto.
(WebCore::Range::selectNode): Ditto.
(WebCore::Range::selectNodeContents): Ditto.
(WebCore::Range::surroundContents): Ditto.
(WebCore::Range::setStartBefore): Ditto.
(WebCore::Range::checkDeleteExtract): Ditto.
(WebCore::Range::containedByReadOnly): Ditto.
(WebCore::Range::firstNode): Ditto.
(WebCore::Range::editingStartPosition): Ditto.
(WebCore::Range::pastLastNode): Ditto.
(WebCore::Range::addLineBoxRects): Ditto.
(WebCore::Range::formatForDebugger): Ditto.
(WebCore::operator==): Ditto.
(WebCore::rangeOfContents): Ditto.
(WebCore::Range::maxStartOffset): Ditto.
(WebCore::Range::maxEndOffset): Ditto.
* dom/Range.h: Made constructors private. Added create functions.
Added getters for startContainer/Offset and endContainer/Offset that
return 0 instead of an exception for detached ranges that are inline
and don't require an ExceptionCode out parameter. Changed the parameters
to setStart and setEnd to PassRefPtr. Removed isDetached function.
Made ActionType and processContents private. Made startPosition and
endPosition inlines and have then return const&. Renamed startNode and
pastEndNode to firstNode and pastLastNode to reduce the chance of
confusion with startContainer/endContainer. Used Position for m_start
and m_end instead of separate container and offset members. Changed
maxStartOffset and maxEndOffset into int to match other offsets.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyBlockStyle): Changed to use Range::create.
(WebCore::ApplyStyleCommand::applyInlineStyle): Ditto.
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::inputText): Ditto.
(WebCore::CompositeEditCommand::moveParagraphs): Ditto.
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::mergeParagraphs): Ditto.
* editing/Editor.cpp:
(WebCore::Editor::fontForSelection): Changed for pastLastNode name change.
(WebCore::Editor::setComposition): Changed to use Range::create.
(WebCore::paragraphAlignedRangeForRange): Ditto.
(WebCore::markMisspellingsOrBadGrammar): Changed to get rid of check for
isDetached and check for 0 from startContainer instead.
(WebCore::Editor::compositionRange): Changed to use Range::create.
* editing/EditorCommand.cpp:
(WebCore::unionDOMRanges): Ditto.
* editing/Selection.cpp:
(WebCore::Selection::toRange): Ditto.
* editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator): Changed for firstNode and pastLastNode
name change.
(WebCore::TextIterator::range): Changed to use Range::create.
(WebCore::SimplifiedBackwardsTextIterator::range): Ditto.
(WebCore::TextIterator::subrange): Ditto.
* editing/VisiblePosition.cpp:
(WebCore::makeRange): Ditto.
* editing/VisiblePosition.h: Added now-needed include.
* editing/htmlediting.cpp:
(WebCore::indexForVisiblePosition): Changed to use Range::create.
(WebCore::avoidIntersectionWithNode): Changed to get rid of check for
isDetached and check for 0 instead and to use Range::create.
* editing/markup.cpp:
(WebCore::renderedText): Changed to use Range::create.
(WebCore::createMarkup): Changed to no longer use isDetached and also
for new firstNode/pastEndNode names.
(WebCore::createFragmentFromText): Ditto.
* editing/visible_units.cpp:
(WebCore::previousBoundary): Changed to use Range::create.
* page/mac/WebCoreFrameBridge.mm:
(-[WebCoreFrameBridge convertToNSRange:]): Changed to no longer use
isDetached().
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::visiblePositionForIndex): Changed to use Range::create.
(WebCore::RenderTextControl::indexForVisiblePosition): Ditto.
2008-03-11 Daniel Zucker <zucker@wake3.com>
 
Reviewed by Adam Roben.
......@@ -411,7 +411,7 @@ __ZN7WebCore5FrameC1EPNS_4PageEPNS_21HTMLFrameOwnerElementEPNS_17FrameLoaderClie
__ZN7WebCore5Image10getNSImageEv
__ZN7WebCore5Image20loadPlatformResourceEPKc
__ZN7WebCore5Image21getTIFFRepresentationEv
__ZN7WebCore5RangeC1EPNS_8DocumentEPNS_4NodeEiS4_i
__ZN7WebCore5Range6createEN3WTF10PassRefPtrINS_8DocumentEEENS2_INS_4NodeEEEiS6_i
__ZN7WebCore5RangeD1Ev
__ZN7WebCore5cacheEv
__ZN7WebCore5equalEPNS_10StringImplEPKc
......@@ -673,12 +673,12 @@ __ZNK7WebCore5Frame6editorEv
__ZNK7WebCore5Frame6loaderEv
__ZNK7WebCore5Frame8documentEv
__ZNK7WebCore5Frame8settingsEv
__ZNK7WebCore5Range11pastEndNodeEv
__ZNK7WebCore5Range11startOffsetERi
__ZNK7WebCore5Range12endContainerERi
__ZNK7WebCore5Range12pastLastNodeEv
__ZNK7WebCore5Range19boundaryPointsValidEv
__ZNK7WebCore5Range9endOffsetERi
__ZNK7WebCore5Range9startNodeEv
__ZNK7WebCore5Range9firstNodeEv
__ZNK7WebCore6Editor13canEditRichlyEv
__ZNK7WebCore6Editor17selectionHasStyleEPNS_19CSSStyleDeclarationE
__ZNK7WebCore6Editor17shouldDeleteRangeEPNS_5RangeE
......
......@@ -1008,7 +1008,7 @@ Settings* Document::settings() const
PassRefPtr<Range> Document::createRange()
{
return new Range(this);
return Range::create(this);
}
PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow,
......@@ -2934,8 +2934,8 @@ void Document::removeMarkers(Range* range, DocumentMarker::MarkerType markerType
Node* startContainer = range->startContainer(ec);
Node* endContainer = range->endContainer(ec);
Node* pastEndNode = range->pastEndNode();
for (Node* node = range->startNode(); node != pastEndNode; node = node->traverseNextNode()) {
Node* pastLastNode = range->pastLastNode();
for (Node* node = range->firstNode(); node != pastLastNode; node = node->traverseNextNode()) {
int startOffset = node == startContainer ? range->startOffset(ec) : 0;
int endOffset = node == endContainer ? range->endOffset(ec) : INT_MAX;
int length = endOffset - startOffset;
......
......@@ -73,24 +73,6 @@ static Node *previousRenderedEditable(Node *node)
return 0;
}
Position::Position(Node* node, int offset)
: m_node(node)
, m_offset(offset)
{
}
Position::Position(const PositionIterator& it)
: m_node(it.m_parent)
, m_offset(it.m_child ? it.m_child->nodeIndex() : (it.m_parent->hasChildNodes() ? maxDeepOffset(it.m_parent) : it.m_offset))
{
}
void Position::clear()
{
m_node = 0;
m_offset = 0;
}
Element* Position::documentElement() const
{
if (Node* n = node())
......@@ -712,9 +694,9 @@ void Position::formatForDebugger(char* buffer, unsigned length) const
else {
char s[1024];
result += "offset ";
result += String::number(m_offset);
result += String::number(offset());
result += " of ";
m_node->formatForDebugger(s, sizeof(s));
node()->formatForDebugger(s, sizeof(s));
result += s;
}
......@@ -723,26 +705,20 @@ void Position::formatForDebugger(char* buffer, unsigned length) const
void Position::showTreeForThis() const
{
if (m_node)
m_node->showTreeForThis();
if (node())
node()->showTreeForThis();
}
#endif
Position startPosition(const Range *r)
Position startPosition(const Range* r)
{
if (!r || r->isDetached())
return Position();
ExceptionCode ec;
return Position(r->startContainer(ec), r->startOffset(ec));
return r ? r->startPosition() : Position();
}
Position endPosition(const Range *r)
Position endPosition(const Range* r)
{
if (!r || r->isDetached())
return Position();
ExceptionCode ec;
return Position(r->endContainer(ec), r->endOffset(ec));
return r ? r->endPosition() : Position();
}
} // namespace WebCore
......
/*
* Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,33 +26,40 @@
#ifndef Position_h
#define Position_h
#include "Node.h"
#include "TextAffinity.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class CSSComputedStyleDeclaration;
class Element;
class PositionIterator;
class Node;
class Range;
class RenderObject;
enum EUsingComposedCharacters { NotUsingComposedCharacters = false, UsingComposedCharacters = true };
class Position
{
// FIXME: Reduce the number of operations we have on a Position.
// This should be more like a humble struct, without so many different
// member functions. We should find better homes for these functions.
class Position {
public:
Position() : m_node(0), m_offset(0) { }
Position(Node*, int offset);
Position(const PositionIterator&);
RefPtr<Node> container;
int posOffset; // to be renamed to offset when we get rid of offset()
Position() : posOffset(0) { }
Position(PassRefPtr<Node> c, int o) : container(c), posOffset(o) { }
void clear();
void clear() { container.clear(); posOffset = 0; }
Node *node() const { return m_node.get(); }
Node* node() const { return container.get(); }
int offset() const { return posOffset; }
Element* documentElement() const;
int offset() const { return m_offset; }
bool isNull() const { return m_node == 0; }
bool isNotNull() const { return m_node != 0; }
bool isNull() const { return !container; }
bool isNotNull() const { return container; }
Element* element() const;
PassRefPtr<CSSComputedStyleDeclaration> computedStyle() const;
......@@ -80,7 +87,7 @@ public:
bool isCandidate() const;
bool inRenderedText() const;
bool isRenderedCharacter() const;
bool rendersInDifferentPosition(const Position &pos) const;
bool rendersInDifferentPosition(const Position&) const;
static bool hasRenderedNonAnonymousDescendantsWithHeight(RenderObject*);
static bool nodeIsUserSelectNone(Node*);
......@@ -97,16 +104,14 @@ private:
Position previousCharacterPosition(EAffinity) const;
Position nextCharacterPosition(EAffinity) const;
RefPtr<Node> m_node;
int m_offset;
};
inline bool operator==(const Position &a, const Position &b)
inline bool operator==(const Position& a, const Position& b)
{
return a.node() == b.node() && a.offset() == b.offset();
return a.container == b.container && a.posOffset == b.posOffset;
}
inline bool operator!=(const Position &a, const Position &b)
inline bool operator!=(const Position& a, const Position& b)
{
return !(a == b);
}
......
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -34,6 +34,11 @@ namespace WebCore {
using namespace HTMLNames;
PositionIterator::operator Position() const
{
return Position(m_parent, m_child ? m_child->nodeIndex() : (m_parent->hasChildNodes() ? maxDeepOffset(m_parent) : m_offset));
}
void PositionIterator::increment()
{
if (!m_parent)
......
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,6 +26,7 @@
#ifndef PositionIterator_h
#define PositionIterator_h
#include "Node.h"
#include "Position.h"
namespace WebCore {
......@@ -48,6 +49,7 @@ public:
, m_offset(m_child ? 0 : pos.offset())
{
}
operator Position() const;
void increment();
void decrement();
......@@ -62,7 +64,6 @@ public:
bool isCandidate() const;
private:
friend class Position;
Node* m_parent;
Node* m_child;
int m_offset;
......
This diff is collapsed.
/*
* This file is part of the DOM implementation for KDE.
*
* (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
* (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
* (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -27,9 +25,8 @@
#ifndef Range_h
#define Range_h
#include "Position.h"
#include <wtf/RefCounted.h>
#include <wtf/Forward.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
......@@ -43,15 +40,18 @@ class Node;
class Position;
class String;
class Range : public RefCounted<Range>
{
class Range : public RefCounted<Range> {
public:
Range(Document*);
Range(Document*, Node* startContainer, int startOffset, Node* endContainer, int endOffset);
Range(Document*, const Position&, const Position&);
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&);
~Range();
Document* ownerDocument() const { return m_ownerDocument.get(); }
Node* startContainer() const { return m_start.container.get(); }
int startOffset() const { return m_start.posOffset; }
Node* endContainer() const { return m_end.container.get(); }
int endOffset() const { return m_end.posOffset; }
Node* startContainer(ExceptionCode&) const;
int startOffset(ExceptionCode&) const;
......@@ -61,8 +61,8 @@ public:
Node* commonAncestorContainer(ExceptionCode&) const;
static Node* commonAncestorContainer(Node* containerA, Node* containerB);
void setStart(Node* container, int offset, ExceptionCode&);
void setEnd(Node* container, int offset, ExceptionCode&);
void setStart(PassRefPtr<Node> container, int offset, ExceptionCode&);
void setEnd(PassRefPtr<Node> container, int offset, ExceptionCode&);
void collapse(bool toStart, ExceptionCode&);
bool isPointInRange(Node* refNode, int offset, ExceptionCode& ec);
short comparePoint(Node* refNode, int offset, ExceptionCode& ec);
......@@ -86,7 +86,6 @@ public:
PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&) const;
void detach(ExceptionCode&);
bool isDetached() const;
PassRefPtr<Range> cloneRange(ExceptionCode&) const;
void setStartAfter(Node*, ExceptionCode&);
......@@ -97,18 +96,11 @@ public:
void surroundContents(PassRefPtr<Node>, ExceptionCode&);
void setStartBefore(Node*, ExceptionCode&);
enum ActionType {
DELETE_CONTENTS,
EXTRACT_CONTENTS,
CLONE_CONTENTS
};
PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
Position startPosition() const;
Position endPosition() const;
const Position& startPosition() const { return m_start; }
const Position& endPosition() const { return m_end; }
Node* startNode() const;
Node* pastEndNode() const;
Node* firstNode() const;
Node* pastLastNode() const;
Position editingStartPosition() const;
......@@ -120,19 +112,22 @@ public:
#endif
private:
RefPtr<Document> m_ownerDocument;
RefPtr<Node> m_startContainer;
unsigned m_startOffset;
RefPtr<Node> m_endContainer;
unsigned m_endOffset;
bool m_detached;
Range(PassRefPtr<Document>);
Range(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
void checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
void checkNodeBA(Node*, ExceptionCode&) const;
void checkDeleteExtract(ExceptionCode&);
bool containedByReadOnly() const;
unsigned maxStartOffset() const;
unsigned maxEndOffset() const;
int maxStartOffset() const;
int maxEndOffset() const;
enum ActionType { DELETE_CONTENTS, EXTRACT_CONTENTS, CLONE_CONTENTS };
PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
RefPtr<Document> m_ownerDocument;
Position m_start;
Position m_end;
};
PassRefPtr<Range> rangeOfContents(Node*);
......
......@@ -387,8 +387,8 @@ void ApplyStyleCommand::applyBlockStyle(CSSMutableStyleDeclaration *style)
// Calculate start and end indices from the start of the tree that they're in.
Node* scope = highestAncestor(visibleStart.deepEquivalent().node());
Position rangeStart(scope, 0);
RefPtr<Range> startRange = new Range(document(), rangeStart, rangeCompliantEquivalent(visibleStart.deepEquivalent()));
RefPtr<Range> endRange = new Range(document(), rangeStart, rangeCompliantEquivalent(visibleEnd.deepEquivalent()));
RefPtr<Range> startRange = Range::create(document(), rangeStart, rangeCompliantEquivalent(visibleStart.deepEquivalent()));
RefPtr<Range> endRange = Range::create(document(), rangeStart, rangeCompliantEquivalent(visibleEnd.deepEquivalent()));
int startIndex = TextIterator::rangeLength(startRange.get(), true);
int endIndex = TextIterator::rangeLength(endRange.get(), true);
......@@ -656,7 +656,7 @@ void ApplyStyleCommand::applyInlineStyle(CSSMutableStyleDeclaration *style)
if (start == end && start.node()->hasTagName(brTag))
end = positionAfterNode(start.node());
// Add the style to selected inline runs.
Node* pastEnd = Range(document(), rangeCompliantEquivalent(start), rangeCompliantEquivalent(end)).pastEndNode();
Node* pastEnd = Range::create(document(), rangeCompliantEquivalent(start), rangeCompliantEquivalent(end))->pastLastNode();
for (Node* next; node && node != pastEnd; node = next) {
next = node->traverseNextNode();
......
......@@ -270,7 +270,7 @@ void CompositeEditCommand::inputText(const String &text, bool selectInsertedText
{
int offset = 0;
int length = text.length();
RefPtr<Range> startRange = new Range(document(), Position(document()->documentElement(), 0), endingSelection().start());
RefPtr<Range> startRange = Range::create(document(), Position(document()->documentElement(), 0), endingSelection().start());
int startIndex = TextIterator::rangeLength(startRange.get());
int newline;
do {
......@@ -729,13 +729,13 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
startIndex = 0;
if (startInParagraph) {
RefPtr<Range> startRange = new Range(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleStart.deepEquivalent()));
RefPtr<Range> startRange = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleStart.deepEquivalent()));
startIndex = TextIterator::rangeLength(startRange.get(), true);
}
endIndex = 0;
if (endInParagraph) {
RefPtr<Range> endRange = new Range(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleEnd.deepEquivalent()));
RefPtr<Range> endRange = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleEnd.deepEquivalent()));
endIndex = TextIterator::rangeLength(endRange.get(), true);
}
}
......@@ -752,7 +752,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 = rangeCompliantEquivalent(start);
Position endRangeCompliant = rangeCompliantEquivalent(end);
RefPtr<Range> range = new Range(document(), startRangeCompliant.node(), startRangeCompliant.offset(), endRangeCompliant.node(), endRangeCompliant.offset());
RefPtr<Range> range = Range::create(document(), startRangeCompliant.node(), startRangeCompliant.offset(), endRangeCompliant.node(), endRangeCompliant.offset());
// 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.
......@@ -805,7 +805,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
updateLayout();
}
RefPtr<Range> startToDestinationRange(new Range(document(), Position(document(), 0), rangeCompliantEquivalent(destination.deepEquivalent())));
RefPtr<Range> startToDestinationRange(Range::create(document(), Position(document(), 0), rangeCompliantEquivalent(destination.deepEquivalent())));
destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true);
setEndingSelection(destination);
......
......@@ -560,8 +560,8 @@ void DeleteSelectionCommand::mergeParagraphs()
return;
}
RefPtr<Range> range = new Range(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(endOfParagraphToMove.deepEquivalent()));
RefPtr<Range> rangeToBeReplaced = new Range(document(), rangeCompliantEquivalent(mergeDestination.deepEquivalent()), rangeCompliantEquivalent(mergeDestination.deepEquivalent()));
RefPtr<Range> range = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(endOfParagraphToMove.deepEquivalent()));
RefPtr<Range> rangeToBeReplaced = Range::create(document(), rangeCompliantEquivalent(mergeDestination.deepEquivalent()), rangeCompliantEquivalent(mergeDestination.deepEquivalent()));
if (!document()->frame()->editor()->client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
return;
......
......@@ -435,7 +435,7 @@ const SimpleFontData* Editor::fontForSelection(bool& hasMultipleFonts) const
RefPtr<Range> range = m_frame->selectionController()->toRange();
Node* startNode = range->editingStartPosition().node();
if (startNode) {
Node* pastEnd = range->pastEndNode();
Node* pastEnd = range->pastLastNode();
// In the loop below, n should eventually match pastEnd and not become nil, but we've seen at least one
// unreproducible case where this didn't happen, so check for nil also.
for (Node* n = startNode; n && n != pastEnd; n = n->traverseNextNode()) {
......@@ -1208,7 +1208,7 @@ void Editor::setComposition(const String& text, const Vector<CompositionUnderlin
unsigned start = min(baseOffset + selectionStart, extentOffset);
unsigned end = min(max(start, baseOffset + selectionEnd), extentOffset);