Commit 98ac4575 authored by darin@apple.com's avatar darin@apple.com

2008-04-01 Darin Adler <darin@apple.com>

        Reviewed by Sam and Antti.

        - fix <rdar://problem/5829565> paste performance slowed down with the Range Acid3 changes

        Added a new class, RangeBoundaryPoint, to use for range boundary points. The "truth" of
        the offset is now stored as a node pointer, and the offset is computed as and when needed.
        This allows us to efficiently update when the DOM tree is changed -- computation of the
        node offsets is deferred until the Range is used later.

        * WebCore.base.exp: Export nodeIndex().

        * WebCore.xcodeproj/project.pbxproj: Added RangeBoundaryPoint.h, removed NodeWithIndexBefore.h
        and NodeWIthIndexAfter.h. Also let Xcode tweak the file formatting.

        * dom/ContainerNode.cpp:
        (WebCore::ContainerNode::childrenChanged): Pass fewer arguments to Document.

        * dom/Document.cpp:
        (WebCore::Document::nodeChildrenChanged): Pass fewer arguments to Range.
        (WebCore::Document::nodeWillBeRemoved): Pass node to range as a raw node pointer; no need for
        the index.
        * dom/Document.h: Take fewer arguments.

        * dom/NodeWithIndexAfter.h: Removed.
        * dom/NodeWithIndexBefore.h: Removed.

        * dom/Range.cpp:
        (WebCore::Range::Range): Changed to use the new RangeBoundaryPoint constructor.
        (WebCore::Range::create): Updated to use RangeBoundaryPoint instead of Position.
        (WebCore::Range::~Range): Ditto.
        (WebCore::Range::startContainer): Ditto.
        (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::intersectsNode): Ditto.
        (WebCore::Range::processContents): Ditto.
        (WebCore::Range::cloneContents): Ditto.
        (WebCore::Range::insertNode): Updated to use RangeBoundaryPoint. Also simplified the code
        at the end that updates the range -- not all of it is needed now since most of the fixup
        is done automatically by the range document mutation machinery. The one bit that remains
        is arguably a bug, but we need to keep it to keep passing Acid3 until we get clarification
        that it is indeed a bug (and then Acid3 will probably have to change).
        (WebCore::Range::toString): Update to use RangeBoundaryPoint instead of Position.
        (WebCore::Range::text): Ditto.
        (WebCore::Range::createContextualFragment): Ditto.
        (WebCore::Range::detach): Ditto.
        (WebCore::Range::checkNodeWOffset): Changed case where the offset is a node offset to
        be more efficient by using childNode instead of childNodeCount, and also return the node
        before which is needed to set the value of a RangeBoundaryPoint.
        (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::Range::maxStartOffset): Ditto.
        (WebCore::Range::maxEndOffset): Ditto.
        (WebCore::boundaryNodeChildrenChanged): Updated to use RangeBoundaryPoint instead of
        Position. Also changed name and changed to just call invalidateOffset.
        (WebCore::Range::nodeChildrenChanged): Changed to take just a container node.
        (WebCore::boundaryNodeWillBeRemoved): Updated to use RangeBoundaryPoint instead of
        Position. Also changed name and changed to update childBefore.
        (WebCore::Range::nodeWillBeRemoved): Changed to just take a Node*.
        (WebCore::boundaryTextInserted): Updated to use RangeBoundaryPoint instead of
        Position. Also changed name.
        (WebCore::Range::textInserted): Ditto.
        (WebCore::boundaryTextRemoved): Ditto.
        (WebCore::Range::textRemoved): Ditto.
        (WebCore::boundaryTextNodesMerged): Ditto.
        (WebCore::Range::textNodesMerged): Ditto.
        (WebCore::boundaryTextNodesSplit): Ditto.
        (WebCore::Range::textNodeSplit): Ditto.

        * dom/Range.h: Updated to use RangeBoundaryPoint instead of Position.

        * dom/RangeBoundaryPoint.h: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31549 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f178dc5e
2008-04-01 Darin Adler <darin@apple.com>
Reviewed by Sam and Antti.
- fix <rdar://problem/5829565> paste performance slowed down with the Range Acid3 changes
Added a new class, RangeBoundaryPoint, to use for range boundary points. The "truth" of
the offset is now stored as a node pointer, and the offset is computed as and when needed.
This allows us to efficiently update when the DOM tree is changed -- computation of the
node offsets is deferred until the Range is used later.
* WebCore.base.exp: Export nodeIndex().
* WebCore.xcodeproj/project.pbxproj: Added RangeBoundaryPoint.h, removed NodeWithIndexBefore.h
and NodeWIthIndexAfter.h. Also let Xcode tweak the file formatting.
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::childrenChanged): Pass fewer arguments to Document.
* dom/Document.cpp:
(WebCore::Document::nodeChildrenChanged): Pass fewer arguments to Range.
(WebCore::Document::nodeWillBeRemoved): Pass node to range as a raw node pointer; no need for
the index.
* dom/Document.h: Take fewer arguments.
* dom/NodeWithIndexAfter.h: Removed.
* dom/NodeWithIndexBefore.h: Removed.
* dom/Range.cpp:
(WebCore::Range::Range): Changed to use the new RangeBoundaryPoint constructor.
(WebCore::Range::create): Updated to use RangeBoundaryPoint instead of Position.
(WebCore::Range::~Range): Ditto.
(WebCore::Range::startContainer): Ditto.
(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::intersectsNode): Ditto.
(WebCore::Range::processContents): Ditto.
(WebCore::Range::cloneContents): Ditto.
(WebCore::Range::insertNode): Updated to use RangeBoundaryPoint. Also simplified the code
at the end that updates the range -- not all of it is needed now since most of the fixup
is done automatically by the range document mutation machinery. The one bit that remains
is arguably a bug, but we need to keep it to keep passing Acid3 until we get clarification
that it is indeed a bug (and then Acid3 will probably have to change).
(WebCore::Range::toString): Update to use RangeBoundaryPoint instead of Position.
(WebCore::Range::text): Ditto.
(WebCore::Range::createContextualFragment): Ditto.
(WebCore::Range::detach): Ditto.
(WebCore::Range::checkNodeWOffset): Changed case where the offset is a node offset to
be more efficient by using childNode instead of childNodeCount, and also return the node
before which is needed to set the value of a RangeBoundaryPoint.
(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::Range::maxStartOffset): Ditto.
(WebCore::Range::maxEndOffset): Ditto.
(WebCore::boundaryNodeChildrenChanged): Updated to use RangeBoundaryPoint instead of
Position. Also changed name and changed to just call invalidateOffset.
(WebCore::Range::nodeChildrenChanged): Changed to take just a container node.
(WebCore::boundaryNodeWillBeRemoved): Updated to use RangeBoundaryPoint instead of
Position. Also changed name and changed to update childBefore.
(WebCore::Range::nodeWillBeRemoved): Changed to just take a Node*.
(WebCore::boundaryTextInserted): Updated to use RangeBoundaryPoint instead of
Position. Also changed name.
(WebCore::Range::textInserted): Ditto.
(WebCore::boundaryTextRemoved): Ditto.
(WebCore::Range::textRemoved): Ditto.
(WebCore::boundaryTextNodesMerged): Ditto.
(WebCore::Range::textNodesMerged): Ditto.
(WebCore::boundaryTextNodesSplit): Ditto.
(WebCore::Range::textNodeSplit): Ditto.
* dom/Range.h: Updated to use RangeBoundaryPoint instead of Position.
* dom/RangeBoundaryPoint.h: Added.
2008-04-01 Anders Carlsson <andersca@apple.com>
Reviewed by Sam.
......@@ -721,6 +721,7 @@ __ZNK7WebCore4KURL4pathEv
__ZNK7WebCore4KURLcvP5NSURLEv
__ZNK7WebCore4Node14isDescendantOfEPKS0_
__ZNK7WebCore4Node18getSubresourceURLsERN3WTF6VectorINS_4KURLELm0EEE
__ZNK7WebCore4Node9nodeIndexEv
__ZNK7WebCore4Page10pluginDataEv
__ZNK7WebCore4Page34inLowQualityImageInterpolationModeEv
__ZNK7WebCore5Frame10isFrameSetEv
......
......@@ -364,7 +364,7 @@
371F53EA0D2704F900ECE0D5 /* CSSUnicodeRangeValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 371F53E80D2704F900ECE0D5 /* CSSUnicodeRangeValue.cpp */; };
37919C230B7D188600A56998 /* PositionIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37919C210B7D188600A56998 /* PositionIterator.cpp */; };
37919C240B7D188600A56998 /* PositionIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 37919C220B7D188600A56998 /* PositionIterator.h */; settings = {ATTRIBUTES = (); }; };
37ACCE420DA2980F0089E602 /* FontRenderingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 37ACCE410DA2980F0089E602 /* FontRenderingMode.h */;settings = {ATTRIBUTES = (Private, ); }; };
37ACCE420DA2980F0089E602 /* FontRenderingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 37ACCE410DA2980F0089E602 /* FontRenderingMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
37F818FD0D657606005E1F05 /* WebCoreURLResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
37F818FE0D657606005E1F05 /* WebCoreURLResponse.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */; };
441B05560CD779B6007C1F18 /* DOMCSSStyleSheetPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 4429AAEA0CB84DC7007647C5 /* DOMCSSStyleSheetPrivate.h */; };
......@@ -1639,8 +1639,6 @@
9380F47409A11AB4001FDB34 /* Widget.h in Headers */ = {isa = PBXBuildFile; fileRef = 9380F47209A11AB4001FDB34 /* Widget.h */; settings = {ATTRIBUTES = (Private, ); }; };
9380F47809A11ACC001FDB34 /* WidgetMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47709A11ACC001FDB34 /* WidgetMac.mm */; };
9382AAB40D8C386100F357A6 /* NodeWithIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB10D8C386100F357A6 /* NodeWithIndex.h */; };
9382AAB50D8C386100F357A6 /* NodeWithIndexBefore.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB20D8C386100F357A6 /* NodeWithIndexBefore.h */; };
9382AAB60D8C386100F357A6 /* NodeWithIndexAfter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB30D8C386100F357A6 /* NodeWithIndexAfter.h */; };
93831B570D087D6000E5C984 /* ExceptionCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93831B560D087D6000E5C984 /* ExceptionCode.cpp */; };
938E65F109F09840008A48EC /* JSHTMLElementWrapperFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */; };
938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */; };
......@@ -1679,6 +1677,7 @@
93C841FF09CE858300DFF5E5 /* DOMImplementationFront.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93C841FE09CE858300DFF5E5 /* DOMImplementationFront.cpp */; };
93CCF0270AF6C52900018E89 /* NavigationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CCF0260AF6C52900018E89 /* NavigationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
93CCF0600AF6CA7600018E89 /* NavigationAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93CCF05F0AF6CA7600018E89 /* NavigationAction.cpp */; };
93D9D53C0DA27E180077216C /* RangeBoundaryPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
93E227E00AF589AD00D48324 /* DocumentLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DB0AF589AD00D48324 /* DocumentLoader.cpp */; };
93E227E10AF589AD00D48324 /* MainResourceLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DC0AF589AD00D48324 /* MainResourceLoader.cpp */; };
93E227E30AF589AD00D48324 /* ResourceLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DE0AF589AD00D48324 /* ResourceLoader.cpp */; };
......@@ -5987,8 +5986,6 @@
9380F47209A11AB4001FDB34 /* Widget.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Widget.h; sourceTree = "<group>"; };
9380F47709A11ACC001FDB34 /* WidgetMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WidgetMac.mm; sourceTree = "<group>"; };
9382AAB10D8C386100F357A6 /* NodeWithIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWithIndex.h; sourceTree = "<group>"; };
9382AAB20D8C386100F357A6 /* NodeWithIndexBefore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWithIndexBefore.h; sourceTree = "<group>"; };
9382AAB30D8C386100F357A6 /* NodeWithIndexAfter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWithIndexAfter.h; sourceTree = "<group>"; };
93831B560D087D6000E5C984 /* ExceptionCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExceptionCode.cpp; sourceTree = "<group>"; };
938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLElementWrapperFactory.h; sourceTree = "<group>"; };
938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLElementWrapperFactory.cpp; sourceTree = "<group>"; };
......@@ -6038,6 +6035,7 @@
93CA4CA309DF93FA00DF8677 /* tokenizer.flex */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tokenizer.flex; sourceTree = "<group>"; };
93CCF0260AF6C52900018E89 /* NavigationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationAction.h; sourceTree = "<group>"; };
93CCF05F0AF6CA7600018E89 /* NavigationAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NavigationAction.cpp; sourceTree = "<group>"; };
93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RangeBoundaryPoint.h; sourceTree = "<group>"; };
93E227DB0AF589AD00D48324 /* DocumentLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentLoader.cpp; sourceTree = "<group>"; };
93E227DC0AF589AD00D48324 /* MainResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MainResourceLoader.cpp; sourceTree = "<group>"; };
93E227DD0AF589AD00D48324 /* NetscapePlugInStreamLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePlugInStreamLoader.cpp; sourceTree = "<group>"; };
......@@ -12697,8 +12695,6 @@
A81872100977D3C0005826D9 /* NodeList.h */,
85ACA9FA0A9B631000671E90 /* NodeList.idl */,
9382AAB10D8C386100F357A6 /* NodeWithIndex.h */,
9382AAB20D8C386100F357A6 /* NodeWithIndexBefore.h */,
9382AAB30D8C386100F357A6 /* NodeWithIndexAfter.h */,
A8EA7EB70A1945D000A8EF5F /* Notation.cpp */,
A8EA7EB60A1945D000A8EF5F /* Notation.h */,
93EEC1F409C2877700C515D1 /* Notation.idl */,
......@@ -12720,6 +12716,7 @@
F523D30302DE4476018635CA /* Range.cpp */,
F523D30402DE4476018635CA /* Range.h */,
936DD03A09CEAC270056AE8C /* Range.idl */,
93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */,
D23CA56B0AB0EB8D005108A5 /* RangeException.h */,
D23CA5480AB0E983005108A5 /* RangeException.idl */,
85031B350A44EFC700F992E0 /* RegisteredEventListener.cpp */,
......@@ -14147,6 +14144,7 @@
550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */,
B22279720D00BF220071B782 /* RadialGradientAttributes.h in Headers */,
93F1991808245E59001E9ABC /* Range.h in Headers */,
93D9D53C0DA27E180077216C /* RangeBoundaryPoint.h in Headers */,
D23CA56C0AB0EB8D005108A5 /* RangeException.h in Headers */,
BC4368E80C226E32005EFB5F /* Rect.h in Headers */,
85031B4C0A44EFC700F992E0 /* RegisteredEventListener.h in Headers */,
......@@ -14670,8 +14668,6 @@
A9D248070D757E7D00FDF959 /* JSMimeType.h in Headers */,
A9D248090D757E7D00FDF959 /* JSMimeTypeArray.h in Headers */,
9382AAB40D8C386100F357A6 /* NodeWithIndex.h in Headers */,
9382AAB50D8C386100F357A6 /* NodeWithIndexBefore.h in Headers */,
9382AAB60D8C386100F357A6 /* NodeWithIndexAfter.h in Headers */,
4B17CBC90D945B370053F183 /* AccessibilityObject.h in Headers */,
4B17CBCD0D945B910053F183 /* AccessibilityObjectWrapper.h in Headers */,
512DD8F50D91E6AF000F89EE /* LegacyWebArchive.h in Headers */,
......@@ -694,7 +694,7 @@ void ContainerNode::childrenChanged(bool changedByParser, Node* beforeChange, No
{
Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (!changedByParser && childCountDelta)
document()->nodeChildrenChanged(this, beforeChange, afterChange, childCountDelta);
document()->nodeChildrenChanged(this);
if (document()->hasNodeListCaches())
notifyNodeListsChildrenChanged();
}
......
......@@ -80,8 +80,6 @@
#include "NodeFilter.h"
#include "NodeIterator.h"
#include "NodeWithIndex.h"
#include "NodeWithIndexAfter.h"
#include "NodeWithIndexBefore.h"
#include "OverflowEvent.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
......@@ -2466,13 +2464,11 @@ void Document::detachNodeIterator(NodeIterator *ni)
m_nodeIterators.remove(ni);
}
void Document::nodeChildrenChanged(ContainerNode* container, Node* beforeChange, Node* afterChange, int childCountDelta)
void Document::nodeChildrenChanged(ContainerNode* container)
{
NodeWithIndexAfter beforeChangeWithIndex(beforeChange);
NodeWithIndexBefore afterChangeWithIndex(container, afterChange);
HashSet<Range*>::const_iterator end = m_ranges.end();
for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it)
(*it)->nodeChildrenChanged(beforeChangeWithIndex, afterChangeWithIndex, childCountDelta);
(*it)->nodeChildrenChanged(container);
}
void Document::nodeWillBeRemoved(Node* n)
......@@ -2481,10 +2477,9 @@ void Document::nodeWillBeRemoved(Node* n)
for (HashSet<NodeIterator*>::const_iterator it = m_nodeIterators.begin(); it != nodeIteratorsEnd; ++it)
(*it)->nodeWillBeRemoved(n);
NodeWithIndex nodeWithIndex(n);
HashSet<Range*>::const_iterator rangesEnd = m_ranges.end();
for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != rangesEnd; ++it)
(*it)->nodeWillBeRemoved(nodeWithIndex);
(*it)->nodeWillBeRemoved(n);
if (Frame* frame = this->frame()) {
frame->selectionController()->nodeWillBeRemoved(n);
......
......@@ -479,7 +479,7 @@ public:
void attachRange(Range*);
void detachRange(Range*);
void nodeChildrenChanged(ContainerNode* container, Node* beforeChange, Node* afterChange, int childCountDelta);
void nodeChildrenChanged(ContainerNode*);
void nodeWillBeRemoved(Node*);
void textInserted(Node*, unsigned offset, unsigned length);
......
/*
* Copyright (C) 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
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NodeWithIndexAfter_h
#define NodeWithIndexAfter_h
#include "Node.h"
namespace WebCore {
// Like NodeWithIndex, but treats a node pointer of 0 as meaning
// "before the last node in the container" and returns the index
// value after the node rather than the value of the node.
class NodeWithIndexAfter {
public:
NodeWithIndexAfter(Node* node)
: m_node(node)
, m_haveIndex(false)
{
}
int indexAfter() const
{
if (!m_haveIndex) {
m_indexAfter = m_node ? m_node->nodeIndex() + 1 : 0;
m_haveIndex = true;
}
ASSERT(m_indexAfter == (m_node ? static_cast<int>(m_node->nodeIndex()) + 1 : 0));
return m_indexAfter;
}
private:
Node* m_node;
mutable bool m_haveIndex;
mutable int m_indexAfter;
};
}
#endif
/*
* Copyright (C) 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
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NodeWithIndexBefore_h
#define NodeWithIndexBefore_h
#include "ContainerNode.h"
namespace WebCore {
// Same as NodeWithIndex, but treats a node pointer of 0 as meaning
// "after the last node in the container".
class NodeWithIndexBefore {
public:
NodeWithIndexBefore(ContainerNode* parent, Node* node)
: m_parent(parent)
, m_node(node)
, m_haveIndex(false)
{
ASSERT(parent);
ASSERT(!node || node->parentNode() == parent);
}
ContainerNode* parent() const { return m_parent; }
int indexBefore() const
{
if (!m_haveIndex) {
m_indexBefore = m_node ? m_node->nodeIndex() : m_parent->childNodeCount();
m_haveIndex = true;
}
ASSERT(m_indexBefore == static_cast<int>(m_node ? m_node->nodeIndex() : m_parent->childNodeCount()));
return m_indexBefore;
}
private:
ContainerNode* m_parent;
Node* m_node;
mutable bool m_haveIndex;
mutable int m_indexBefore;
};
}
#endif
This diff is collapsed.
......@@ -25,21 +25,14 @@
#ifndef Range_h
#define Range_h
#include "Position.h"
#include "RangeBoundaryPoint.h"
#include <wtf/RefCounted.h>
#include <wtf/Vector.h>
namespace WebCore {
typedef int ExceptionCode;
class DocumentFragment;
class Document;
class NodeWithIndex;
class NodeWithIndexAfter;
class NodeWithIndexBefore;
class IntRect;
class String;
class Text;
class Range : public RefCounted<Range> {
......@@ -50,10 +43,10 @@ public:
~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() const { return m_start.container(); }
int startOffset() const { return m_start.offset(); }
Node* endContainer() const { return m_end.container(); }
int endOffset() const { return m_end.offset(); }
Node* startContainer(ExceptionCode&) const;
int startOffset(ExceptionCode&) const;
......@@ -98,8 +91,8 @@ public:
void surroundContents(PassRefPtr<Node>, ExceptionCode&);
void setStartBefore(Node*, ExceptionCode&);
const Position& startPosition() const { return m_start; }
const Position& endPosition() const { return m_end; }
const Position& startPosition() const { return m_start.position(); }
const Position& endPosition() const { return m_end.position(); }
Node* firstNode() const;
Node* pastLastNode() const;
......@@ -109,8 +102,8 @@ public:
IntRect boundingBox();
void addLineBoxRects(Vector<IntRect>&, bool useSelectionHeight = false);
void nodeChildrenChanged(NodeWithIndexAfter& beforeChange, NodeWithIndexBefore& afterChange, int childCountDelta);
void nodeWillBeRemoved(NodeWithIndex&);
void nodeChildrenChanged(ContainerNode*);
void nodeWillBeRemoved(Node*);
void textInserted(Node*, unsigned offset, unsigned length);
void textRemoved(Node*, unsigned offset, unsigned length);
......@@ -125,7 +118,7 @@ private:
Range(PassRefPtr<Document>);
Range(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
void checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
void checkNodeBA(Node*, ExceptionCode&) const;
void checkDeleteExtract(ExceptionCode&);
bool containedByReadOnly() const;
......@@ -136,8 +129,8 @@ private:
PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
RefPtr<Document> m_ownerDocument;
Position m_start;
Position m_end;
RangeBoundaryPoint m_start;
RangeBoundaryPoint m_end;
};
PassRefPtr<Range> rangeOfContents(Node*);
......
/*
* Copyright (C) 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
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RangeBoundaryPoint_h
#define RangeBoundaryPoint_h
#include "Node.h"
#include "Position.h"
namespace WebCore {
class RangeBoundaryPoint {
public:
RangeBoundaryPoint();
explicit RangeBoundaryPoint(PassRefPtr<Node> container);
const Position& position() const;
Node* container() const;
int offset() const;
Node* childBefore() const;
void clear();
void set(PassRefPtr<Node> container, int offset, Node* childBefore);
void setOffset(int offset);
void setToChild(Node* child);
void setToStart(PassRefPtr<Node> container);
void setToEnd(PassRefPtr<Node> container);
void childBeforeWillBeRemoved();
void invalidateOffset() const;
private:
static const int invalidOffset = -1;
mutable Position m_position;
Node* m_childBefore;
};
inline RangeBoundaryPoint::RangeBoundaryPoint()
: m_childBefore(0)
{
}
inline RangeBoundaryPoint::RangeBoundaryPoint(PassRefPtr<Node> container)
: m_position(container, 0)
, m_childBefore(0)
{
}
inline Node* RangeBoundaryPoint::container() const
{
return m_position.container.get();
}
inline Node* RangeBoundaryPoint::childBefore() const
{
return m_childBefore;
}
inline const Position& RangeBoundaryPoint::position() const
{
if (m_position.posOffset >= 0)
return m_position;
ASSERT(m_childBefore);
m_position.posOffset = m_childBefore->nodeIndex() + 1;
return m_position;
}
inline int RangeBoundaryPoint::offset() const
{
return position().posOffset;
}
inline void RangeBoundaryPoint::clear()
{
m_position.clear();
m_childBefore = 0;
}
inline void RangeBoundaryPoint::set(PassRefPtr<Node> container, int offset, Node* childBefore)
{
ASSERT(offset >= 0);
ASSERT(childBefore == (offset ? container->childNode(offset - 1) : 0));
m_position.container = container;
m_position.posOffset = offset;
m_childBefore = childBefore;
}
inline void RangeBoundaryPoint::setOffset(int offset)
{
ASSERT(m_position.container);
ASSERT(m_position.container->offsetInCharacters());
ASSERT(m_position.posOffset >= 0);
ASSERT(!m_childBefore);
m_position.posOffset = offset;
}
inline void RangeBoundaryPoint::setToChild(Node* child)
{
ASSERT(child);
ASSERT(child->parentNode());
m_position.container = child->parentNode();
m_childBefore = child->previousSibling();
m_position.posOffset = m_childBefore ? invalidOffset : 0;
}
inline void RangeBoundaryPoint::setToStart(PassRefPtr<Node> container)
{
ASSERT(container);
m_position.container = container;
m_position.posOffset = 0;
m_childBefore = 0;
}
inline void RangeBoundaryPoint::setToEnd(PassRefPtr<Node> container)
{
ASSERT(container);
m_position.container = container;
if (m_position.container->offsetInCharacters()) {
m_position.posOffset = m_position.container->maxCharacterOffset();
m_childBefore = 0;
} else {
m_childBefore = m_position.container->lastChild();
m_position.posOffset = m_childBefore ? invalidOffset : 0;
}
}
inline void RangeBoundaryPoint::childBeforeWillBeRemoved()
{
ASSERT(m_position.posOffset);
m_childBefore = m_childBefore->previousSibling();
if (!m_childBefore)
m_position.posOffset = 0;
else if (m_position.posOffset > 0)
--m_position.posOffset;
}
inline void RangeBoundaryPoint::invalidateOffset() const
{
m_position.posOffset = invalidOffset;
}
inline bool operator==(const RangeBoundaryPoint& a, const RangeBoundaryPoint& b)
{
if (a.container() != b.container())
return false;
if (a.childBefore() || b.childBefore()) {
if (a.childBefore() != b.childBefore())
return false;
} else {
if (a.offset() != b.offset())
return false;
}
return true;
}
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment