Changeset 42264 in webkit
- Timestamp:
- Apr 7, 2009 7:25:57 AM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r42263 r42264 1 2009-04-07 Eric Seidel <eric@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Move RangeBoundaryPoint off of Position, per Darin's suggestion 6 https://bugs.webkit.org/show_bug.cgi?id=24966 7 8 Rename setToChild to setToBeforeChild (since that's what the method does) 9 10 * dom/Position.h: 11 (WebCore::Position::offsetInContainerNode): 12 * dom/Range.cpp: 13 (WebCore::Range::insertNode): 14 (WebCore::Range::selectNodeContents): 15 (WebCore::boundaryNodeWillBeRemoved): 16 * dom/Range.h: 17 (WebCore::Range::startPosition): 18 (WebCore::Range::endPosition): 19 * dom/RangeBoundaryPoint.h: 20 (WebCore::RangeBoundaryPoint::RangeBoundaryPoint): 21 (WebCore::RangeBoundaryPoint::container): 22 (WebCore::RangeBoundaryPoint::childBefore): 23 (WebCore::RangeBoundaryPoint::position): 24 (WebCore::RangeBoundaryPoint::offset): 25 (WebCore::RangeBoundaryPoint::clear): 26 (WebCore::RangeBoundaryPoint::set): 27 (WebCore::RangeBoundaryPoint::setOffset): 28 (WebCore::RangeBoundaryPoint::setToBeforeChild): 29 (WebCore::RangeBoundaryPoint::setToStartOfNode): 30 (WebCore::RangeBoundaryPoint::setToEndOfNode): 31 (WebCore::RangeBoundaryPoint::childBeforeWillBeRemoved): 32 (WebCore::RangeBoundaryPoint::invalidateOffset): 33 1 34 2009-04-07 Eric Seidel <eric@webkit.org> 2 35 -
trunk/WebCore/dom/Position.h
r42263 r42264 29 29 #include "TextAffinity.h" 30 30 #include "TextDirection.h" 31 #include <wtf/Assertions.h> 31 32 #include <wtf/PassRefPtr.h> 32 33 #include <wtf/RefPtr.h> … … 47 48 }; 48 49 49 // FIXME: Reduce the number of operations we have on a Position.50 // This should be more like a humble struct, without so many different51 // member functions. We should find better homes for these functions.52 53 50 class Position { 54 51 public: … … 65 62 // These are always DOM compliant values. Editing positions like [img, 0] (aka [img, before]) 66 63 // will return img->parentNode() and img->nodeIndex() from these functions. 67 Node* containerNode() const; 68 int computeOffsetInContainerNode() const; 64 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent 65 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions 66 67 // Inline O(1) access for Positions which callers know to be parent-anchored 68 int offsetInContainerNode() const 69 { 70 ASSERT(anchorType() == PositionIsOffsetInAnchor); 71 return m_offset; 72 } 69 73 70 74 // These are convenience methods which are smart about whether the position is neighbor anchored or parent anchored -
trunk/WebCore/dom/Range.cpp
r42084 r42264 992 992 // to pass Acid3. We might later decide to remove this. 993 993 if (collapsed) 994 m_end.setTo Child(newText.get());994 m_end.setToBeforeChild(newText.get()); 995 995 } else { 996 996 RefPtr<Node> lastChild; … … 1356 1356 } 1357 1357 1358 m_start.setToStart (refNode);1359 m_end.setToEnd (refNode);1358 m_start.setToStartOfNode(refNode); 1359 m_end.setToEndOfNode(refNode); 1360 1360 } 1361 1361 … … 1709 1709 for (Node* n = boundary.container(); n; n = n->parentNode()) { 1710 1710 if (n == nodeToBeRemoved) { 1711 boundary.setTo Child(nodeToBeRemoved);1711 boundary.setToBeforeChild(nodeToBeRemoved); 1712 1712 return; 1713 1713 } -
trunk/WebCore/dom/Range.h
r34900 r42264 92 92 void setStartBefore(Node*, ExceptionCode&); 93 93 94 const Position & startPosition() const { return m_start.position(); }95 const Position & endPosition() const { return m_end.position(); }94 const Position startPosition() const { return m_start.toPosition(); } 95 const Position endPosition() const { return m_end.toPosition(); } 96 96 97 97 Node* firstNode() const; -
trunk/WebCore/dom/RangeBoundaryPoint.h
r41933 r42264 37 37 explicit RangeBoundaryPoint(PassRefPtr<Node> container); 38 38 39 const Position& position() const; 39 const Position toPosition() const; 40 40 41 Node* container() const; 41 42 int offset() const; … … 46 47 void set(PassRefPtr<Node> container, int offset, Node* childBefore); 47 48 void setOffset(int offset); 48 void setToChild(Node* child); 49 void setToStart(PassRefPtr<Node> container); 50 void setToEnd(PassRefPtr<Node> container); 49 50 void setToBeforeChild(Node*); 51 void setToStartOfNode(PassRefPtr<Node>); 52 void setToEndOfNode(PassRefPtr<Node>); 51 53 52 54 void childBeforeWillBeRemoved(); 53 55 void invalidateOffset() const; 56 void ensureOffsetIsValid() const; 54 57 55 58 private: 56 59 static const int invalidOffset = -1; 57 58 // FIXME: RangeBoundaryPoint is the only file to ever use -1 as am expected offset for Position59 // RangeBoundaryPoint currently needs to store a Position object to make the60 // position() function be able to return a const& (and thus avoid ref-churn).61 60 62 mutable Position m_position; 63 Node* m_childBefore; 61 RefPtr<Node> m_containerNode; 62 mutable int m_offsetInContainer; 63 Node* m_childBeforeBoundary; 64 64 }; 65 65 66 66 inline RangeBoundaryPoint::RangeBoundaryPoint() 67 : m_childBefore(0) 67 : m_offsetInContainer(0) 68 , m_childBeforeBoundary(0) 68 69 { 69 70 } 70 71 71 72 inline RangeBoundaryPoint::RangeBoundaryPoint(PassRefPtr<Node> container) 72 : m_position(container, 0) 73 , m_childBefore(0) 73 : m_containerNode(container) 74 , m_offsetInContainer(0) 75 , m_childBeforeBoundary(0) 74 76 { 75 77 } … … 77 79 inline Node* RangeBoundaryPoint::container() const 78 80 { 79 return m_ position.node();81 return m_containerNode.get(); 80 82 } 81 83 82 84 inline Node* RangeBoundaryPoint::childBefore() const 83 85 { 84 return m_childBefore ;86 return m_childBeforeBoundary; 85 87 } 86 88 87 inline const Position& RangeBoundaryPoint::position() const89 inline void RangeBoundaryPoint::ensureOffsetIsValid() const 88 90 { 89 if (m_position.m_offset >= 0) 90 return m_position; 91 ASSERT(m_childBefore); 92 m_position.m_offset = m_childBefore->nodeIndex() + 1; 93 return m_position; 91 if (m_offsetInContainer >= 0) 92 return; 93 94 ASSERT(m_childBeforeBoundary); 95 m_offsetInContainer = m_childBeforeBoundary->nodeIndex() + 1; 96 } 97 98 inline const Position RangeBoundaryPoint::toPosition() const 99 { 100 ensureOffsetIsValid(); 101 return Position(m_containerNode.get(), m_offsetInContainer); 94 102 } 95 103 96 104 inline int RangeBoundaryPoint::offset() const 97 105 { 98 return position().m_offset; 106 ensureOffsetIsValid(); 107 return m_offsetInContainer; 99 108 } 100 109 101 110 inline void RangeBoundaryPoint::clear() 102 111 { 103 m_position.clear(); 104 m_childBefore = 0; 112 m_containerNode.clear(); 113 m_offsetInContainer = 0; 114 m_childBeforeBoundary = 0; 105 115 } 106 116 … … 109 119 ASSERT(offset >= 0); 110 120 ASSERT(childBefore == (offset ? container->childNode(offset - 1) : 0)); 111 m_position.moveToPosition(container, offset); 112 m_childBefore = childBefore; 121 m_containerNode = container; 122 m_offsetInContainer = offset; 123 m_childBeforeBoundary = childBefore; 113 124 } 114 125 115 126 inline void RangeBoundaryPoint::setOffset(int offset) 116 127 { 117 ASSERT(m_ position.node());118 ASSERT(m_ position.node()->offsetInCharacters());119 ASSERT(m_ position.m_offset>= 0);120 ASSERT(!m_childBefore );121 m_ position.moveToOffset(offset);128 ASSERT(m_containerNode); 129 ASSERT(m_containerNode->offsetInCharacters()); 130 ASSERT(m_offsetInContainer >= 0); 131 ASSERT(!m_childBeforeBoundary); 132 m_offsetInContainer = offset; 122 133 } 123 134 124 inline void RangeBoundaryPoint::setTo Child(Node* child)135 inline void RangeBoundaryPoint::setToBeforeChild(Node* child) 125 136 { 126 137 ASSERT(child); 127 138 ASSERT(child->parentNode()); 128 m_childBefore = child->previousSibling(); 129 m_position.moveToPosition(child->parentNode(), m_childBefore ? invalidOffset : 0); 139 m_childBeforeBoundary = child->previousSibling(); 140 m_containerNode = child->parentNode(); 141 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; 130 142 } 131 143 132 inline void RangeBoundaryPoint::setToStart (PassRefPtr<Node> container)144 inline void RangeBoundaryPoint::setToStartOfNode(PassRefPtr<Node> container) 133 145 { 134 146 ASSERT(container); 135 m_position.moveToPosition(container, 0); 136 m_childBefore = 0; 147 m_containerNode = container; 148 m_offsetInContainer = 0; 149 m_childBeforeBoundary = 0; 137 150 } 138 151 139 inline void RangeBoundaryPoint::setToEnd (PassRefPtr<Node> container)152 inline void RangeBoundaryPoint::setToEndOfNode(PassRefPtr<Node> container) 140 153 { 141 154 ASSERT(container); 142 if (container->offsetInCharacters()) { 143 m_position.moveToPosition(container, container->maxCharacterOffset()); 144 m_childBefore = 0; 155 m_containerNode = container; 156 if (m_containerNode->offsetInCharacters()) { 157 m_offsetInContainer = m_containerNode->maxCharacterOffset(); 158 m_childBeforeBoundary = 0; 145 159 } else { 146 m_childBefore = container->lastChild();147 m_ position.moveToPosition(container, m_childBefore ? invalidOffset : 0);160 m_childBeforeBoundary = m_containerNode->lastChild(); 161 m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0; 148 162 } 149 163 } … … 151 165 inline void RangeBoundaryPoint::childBeforeWillBeRemoved() 152 166 { 153 ASSERT(m_ position.m_offset);154 m_childBefore = m_childBefore->previousSibling();155 if (!m_childBefore )156 m_ position.m_offset= 0;157 else if (m_ position.m_offset> 0)158 --m_ position.m_offset;167 ASSERT(m_offsetInContainer); 168 m_childBeforeBoundary = m_childBeforeBoundary->previousSibling(); 169 if (!m_childBeforeBoundary) 170 m_offsetInContainer = 0; 171 else if (m_offsetInContainer > 0) 172 --m_offsetInContainer; 159 173 } 160 174 161 175 inline void RangeBoundaryPoint::invalidateOffset() const 162 176 { 163 m_ position.m_offset= invalidOffset;177 m_offsetInContainer = invalidOffset; 164 178 } 165 179
Note: See TracChangeset
for help on using the changeset viewer.