Changeset 89505 in webkit
- Timestamp:
- Jun 22, 2011, 5:45:26 PM (14 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r89504 r89505 1 2011-06-22 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Add a Position constructor that takes (Text*, unsigned offset) 6 https://bugs.webkit.org/show_bug.cgi?id=63181 7 8 Added Position::Position(PassRefPtr<Text*>, unsigned offset) and deployed in a couple of places 9 by replacing the calls to the old constructor. 10 11 * dom/Position.cpp: 12 (WebCore::Position::Position): Added. 13 * dom/Position.h: 14 * editing/CompositeEditCommand.cpp: 15 (WebCore::CompositeEditCommand::replaceSelectedTextInNode): Calls new constructor; extracted 16 from InsertTextCommand::performTrivialReplace and ReplaceSelectionCommand::performTrivialReplace. 17 (WebCore::CompositeEditCommand::rebalanceWhitespaceOnTextSubstring): Calls new constructor 18 * editing/CompositeEditCommand.h: 19 * editing/InsertTextCommand.cpp: 20 (WebCore::InsertTextCommand::performTrivialReplace): Calls replaceSelectedTextInNode. 21 (WebCore::InsertTextCommand::input): Calls new constructor. 22 (WebCore::InsertTextCommand::insertTab): Use RefPtr instead of a raw pointer. 23 * editing/ReplaceSelectionCommand.cpp: 24 (WebCore::ReplaceSelectionCommand::performTrivialReplace): Calls replaceSelectedTextInNode. 25 * editing/visible_units.cpp: 26 (WebCore::startPositionForLine): Calls new constructor. 27 * rendering/RenderTextControl.cpp: 28 (WebCore::RenderTextControl::visiblePositionForIndex): Calls new constructor; calls endPosition 29 on Range instead of avoid manually constructing a VisiblePosition out of endContainer and endOffset. 30 1 31 2011-06-22 Adam Barth <abarth@webkit.org> 2 32 -
trunk/Source/WebCore/dom/Position.cpp
r89440 r89505 104 104 } 105 105 106 Position::Position(PassRefPtr<Text> textNode, unsigned offset) 107 : m_anchorNode(textNode) 108 , m_offset(static_cast<int>(offset)) 109 , m_anchorType(PositionIsOffsetInAnchor) 110 , m_isLegacyEditingPosition(false) 111 { 112 ASSERT(m_anchorNode); 113 } 114 106 115 void Position::moveToPosition(PassRefPtr<Node> node, int offset) 107 116 { -
trunk/Source/WebCore/dom/Position.h
r89440 r89505 43 43 class Range; 44 44 class RenderObject; 45 class Text; 45 46 46 47 enum PositionMoveType { … … 81 82 // For creating before/after positions: 82 83 Position(PassRefPtr<Node> anchorNode, AnchorType); 84 Position(PassRefPtr<Text> textNode, unsigned offset); 85 83 86 // For creating offset positions: 87 // FIXME: This constructor should eventually go away. See bug 63040. 84 88 Position(PassRefPtr<Node> anchorNode, int offset, AnchorType); 85 89 -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r89420 r89505 341 341 } 342 342 343 Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) 344 { 345 Position start = endingSelection().start(); 346 Position end = endingSelection().end(); 347 if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode() || isTabSpanTextNode(start.containerNode())) 348 return Position(); 349 350 RefPtr<Text> textNode = static_cast<Text*>(start.containerNode()); 351 replaceTextInNode(textNode, start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text); 352 353 return Position(textNode.release(), start.offsetInContainerNode() + text.length()); 354 } 355 343 356 void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> prpNode, unsigned offset, unsigned count, const String& replacementText) 344 357 { … … 480 493 return; 481 494 482 VisiblePosition visibleUpstreamPos(Position(textNode, upstream , Position::PositionIsOffsetInAnchor));483 VisiblePosition visibleDownstreamPos(Position(textNode, downstream , Position::PositionIsOffsetInAnchor));495 VisiblePosition visibleUpstreamPos(Position(textNode, upstream)); 496 VisiblePosition visibleDownstreamPos(Position(textNode, downstream)); 484 497 485 498 String string = text.substring(upstream, length); -
trunk/Source/WebCore/editing/CompositeEditCommand.h
r89420 r89505 83 83 void prune(PassRefPtr<Node>); 84 84 void replaceTextInNode(PassRefPtr<Text>, unsigned offset, unsigned count, const String& replacementText); 85 Position replaceSelectedTextInNode(const String&); 85 86 void replaceTextInNodePreservingMarkers(PassRefPtr<Text>, unsigned offset, unsigned count, const String& replacementText); 86 87 Position positionOutsideTabSpan(const Position&); -
trunk/Source/WebCore/editing/InsertTextCommand.cpp
r89440 r89505 77 77 if (text.contains('\t') || text.contains(' ') || text.contains('\n')) 78 78 return false; 79 80 Position start = endingSelection().start().parentAnchoredEquivalent(); 81 Position end = endingSelection().end().parentAnchoredEquivalent(); 82 ASSERT(start.anchorType() == Position::PositionIsOffsetInAnchor); 83 ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor); 84 85 if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode() || isTabSpanTextNode(start.containerNode())) 79 80 Position start = endingSelection().start(); 81 Position endPosition = replaceSelectedTextInNode(text); 82 if (endPosition.isNull()) 86 83 return false; 87 88 replaceTextInNode(static_cast<Text*>(start.containerNode()), start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text);89 90 Position endPosition(start.containerNode(), start.offsetInContainerNode() + text.length(), Position::PositionIsOffsetInAnchor);91 84 92 85 // We could have inserted a part of composed character sequence, … … 166 159 if (placeholder.isNotNull()) 167 160 removePlaceholderAt(placeholder); 168 Text*textNode = static_cast<Text*>(startPosition.containerNode());161 RefPtr<Text> textNode = static_cast<Text*>(startPosition.containerNode()); 169 162 const unsigned offset = startPosition.offsetInContainerNode(); 170 163 171 164 insertTextIntoNode(textNode, offset, text); 172 endPosition = Position(textNode, offset + text.length() , Position::PositionIsOffsetInAnchor);165 endPosition = Position(textNode, offset + text.length()); 173 166 174 167 if (whitespaceRebalance == RebalanceLeadingAndTrailingWhitespaces) { … … 212 205 // keep tabs coalesced in tab span 213 206 if (isTabSpanTextNode(node)) { 214 insertTextIntoNode(static_cast<Text *>(node), offset, "\t"); 215 return Position(node, offset + 1, Position::PositionIsOffsetInAnchor); 207 RefPtr<Text> textNode = static_cast<Text*>(node); 208 insertTextIntoNode(textNode, offset, "\t"); 209 return Position(textNode.release(), offset + 1); 216 210 } 217 211 … … 223 217 insertNodeAt(spanNode.get(), insertPos); 224 218 } else { 225 Text *textNode = static_cast<Text*>(node);226 if (offset >= textNode->length()) {227 insertNodeAfter(spanNode .get(), textNode);228 }else {219 RefPtr<Text> textNode = static_cast<Text*>(node); 220 if (offset >= textNode->length()) 221 insertNodeAfter(spanNode, textNode.release()); 222 else { 229 223 // split node to make room for the span 230 224 // NOTE: splitTextNode uses textNode for the … … 233 227 if (offset > 0) 234 228 splitTextNode(textNode, offset); 235 insertNodeBefore(spanNode, textNode );229 insertNodeBefore(spanNode, textNode.release()); 236 230 } 237 231 } -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r89283 r89505 1306 1306 Text* textNode = static_cast<Text*>(fragment.firstChild()); 1307 1307 // Our fragment creation code handles tabs, spaces, and newlines, so we don't have to worry about those here. 1308 String text(textNode->data()); 1309 1310 Position start = endingSelection().start().parentAnchoredEquivalent(); 1311 Position end = endingSelection().end().parentAnchoredEquivalent(); 1312 ASSERT(start.anchorType() == Position::PositionIsOffsetInAnchor); 1313 ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor); 1314 1315 if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode()) 1316 return false; 1317 1318 replaceTextInNode(static_cast<Text*>(start.containerNode()), start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text); 1319 1320 end = Position(start.containerNode(), start.offsetInContainerNode() + text.length(), Position::PositionIsOffsetInAnchor); 1308 1309 Position start = endingSelection().start(); 1310 Position end = replaceSelectedTextInNode(textNode->data()); 1311 if (end.isNull()) 1312 return false; 1321 1313 1322 1314 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, end); -
trunk/Source/WebCore/editing/visible_units.cpp
r89440 r89505 35 35 #include "RenderLayer.h" 36 36 #include "RenderObject.h" 37 #include "Text.h" 37 38 #include "TextBoundaries.h" 38 39 #include "TextBreakIterator.h" … … 387 388 } 388 389 389 VisiblePosition visPos = startNode->isTextNode() ? VisiblePosition(Position(sta rtNode, static_cast<InlineTextBox *>(startBox)->start(), Position::PositionIsOffsetInAnchor), DOWNSTREAM)390 VisiblePosition visPos = startNode->isTextNode() ? VisiblePosition(Position(static_cast<Text*>(startNode), static_cast<InlineTextBox*>(startBox)->start()), DOWNSTREAM) 390 391 : VisiblePosition(positionBeforeNode(startNode), DOWNSTREAM); 391 392 return positionAvoidingFirstPositionInTable(visPos); -
trunk/Source/WebCore/rendering/RenderTextControl.cpp
r88456 r89505 305 305 { 306 306 if (index <= 0) 307 return VisiblePosition( Position(innerTextElement(), 0, Position::PositionIsOffsetInAnchor), DOWNSTREAM);307 return VisiblePosition(firstPositionInNode(innerTextElement()), DOWNSTREAM); 308 308 ExceptionCode ec = 0; 309 309 RefPtr<Range> range = Range::create(document()); … … 312 312 CharacterIterator it(range.get()); 313 313 it.advance(index - 1); 314 Node* endContainer = it.range()->endContainer(ec); 315 ASSERT(!ec); 316 int endOffset = it.range()->endOffset(ec); 317 ASSERT(!ec); 318 return VisiblePosition(Position(endContainer, endOffset, Position::PositionIsOffsetInAnchor), UPSTREAM); 314 return VisiblePosition(it.range()->endPosition(), UPSTREAM); 319 315 } 320 316
Note:
See TracChangeset
for help on using the changeset viewer.