Changeset 89952 in webkit
- Timestamp:
- Jun 28, 2011 1:07:31 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r89951 r89952 1 2011-06-28 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Stop instantiating Position with PositionIsOffsetInAnchor in various files 6 https://bugs.webkit.org/show_bug.cgi?id=63384 7 8 Refactoring. 9 10 Removed many if conditions that compared the anchor type to Position::PositionIsOffsetInAnchor 11 because there were also checking that containerNode is a text node. 12 13 Also added Position::containerText() to avoid manually casting containerNode(). 14 15 * dom/Position.cpp: 16 (WebCore::Position::Position): Added an assertion to ensure BeforeChildren/AfterChildren 17 anchor type won't be used for a node whose contents is ignored by editing. 18 (WebCore::Position::containerText): Added. 19 * dom/Position.h: 20 * editing/ApplyBlockElementCommand.cpp: 21 (WebCore::isNewLineAtPosition): Removed a redundant comparison of anchor type. 22 (WebCore::ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded): Since containerNode 23 is always a text node when renderStyleOfEnclosingTextNode returns a render style, use new Position 24 constructor that takes Text* and offset. 25 (WebCore::ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfNeeded): Removed redundant 26 comparison of anchor type and use new Position constructor that takes Text* and offset. 27 * editing/ApplyStyleCommand.cpp: 28 (WebCore::ApplyStyleCommand::splitTextAtStart): Replaced an assertion that compared anchor type by 29 an assertion that the container node is a text node; use new constructor. 30 (WebCore::ApplyStyleCommand::splitTextAtEnd): Ditto; also added early exits in the case script 31 modified DOM. 32 (WebCore::ApplyStyleCommand::splitTextElementAtStart): Ditto. 33 (WebCore::ApplyStyleCommand::splitTextElementAtEnd): Ditto. 34 (WebCore::ApplyStyleCommand::joinChildTextNodes): Use new constructor. 35 * editing/CompositeEditCommand.cpp: 36 (WebCore::Editor::replaceSelectedTextInNode): Calls containerText instead of manually casting containerNode. 37 * editing/Editor.cpp: 38 (WebCore::Editor::canDeleteRange): Call Range::startPosition instead of manually instantiating Position 39 by calling startContainer and startOffset. 40 * editing/FrameSelection.cpp: 41 (WebCore::FrameSelection::setSelectedRange): Ditto. 42 * editing/InsertTextCommand.cpp: 43 (WebCore::InsertTextCommand::input): Calls containerText instead of manually casting containerNode. 44 * editing/ReplaceSelectionCommand.cpp: 45 (WebCore::ReplaceSelectionCommand::doApply): Calls containerText instead of manually casting containerNode. 46 * editing/VisiblePosition.cpp: 47 (WebCore::VisiblePosition::characterAfter): Removed a redundant anchor type comparison. 48 (WebCore::startVisiblePosition): Call Range::startPosition instead of startContainer and startOffset. 49 (WebCore::endVisiblePosition): Call Range::endPosition instead of endContainer and endOffset. 50 * editing/htmlediting.cpp: 51 (WebCore::firstInSpecialElement): Call containerNode() to address <rdar://problem/5027702>. 52 (WebCore::lastInSpecialElement): Ditto; use new constructor. 53 * editing/visible_units.cpp: 54 (WebCore::endPositionForLine): Use new constructor. 55 (WebCore::startOfParagraph): Ditto. 56 (WebCore::endOfParagraph): Ditto. 57 1 58 2011-06-28 Rob Buis <rbuis@rim.com> 2 59 -
trunk/Source/WebCore/dom/Position.cpp
r89683 r89952 92 92 ASSERT(!m_anchorNode || !m_anchorNode->isShadowRoot()); 93 93 ASSERT(anchorType != PositionIsOffsetInAnchor); 94 ASSERT(!((anchorType == PositionIsBeforeChildren || anchorType == PositionIsAfterChildren) && m_anchorNode->isTextNode())); 94 ASSERT(!((anchorType == PositionIsBeforeChildren || anchorType == PositionIsAfterChildren) 95 && (m_anchorNode->isTextNode() || editingIgnoresContent(m_anchorNode.get())))); 95 96 } 96 97 … … 144 145 case PositionIsAfterAnchor: 145 146 return m_anchorNode->nonShadowBoundaryParentNode(); 147 } 148 ASSERT_NOT_REACHED(); 149 return 0; 150 } 151 152 Text* Position::containerText() const 153 { 154 switch (anchorType()) { 155 case PositionIsOffsetInAnchor: 156 return m_anchorNode && m_anchorNode->isTextNode() ? static_cast<Text*>(m_anchorNode.get()) : 0; 157 case PositionIsBeforeAnchor: 158 case PositionIsAfterAnchor: 159 return 0; 160 case PositionIsBeforeChildren: 161 case PositionIsAfterChildren: 162 ASSERT(!m_anchorNode || !m_anchorNode->isTextNode()); 163 return 0; 146 164 } 147 165 ASSERT_NOT_REACHED(); -
trunk/Source/WebCore/dom/Position.h
r89683 r89952 97 97 // will return img->parentNode() and img->nodeIndex() from these functions. 98 98 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent 99 Text* containerText() const; 100 99 101 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions 100 102 Position parentAnchoredEquivalent() const; // Convenience method for DOM positions that also fixes up some positions for editing -
trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp
r86325 r89952 151 151 static bool isNewLineAtPosition(const Position& position) 152 152 { 153 if (position.anchorType() != Position::PositionIsOffsetInAnchor)154 return false;155 156 153 Node* textNode = position.containerNode(); 157 154 int offset = position.offsetInContainerNode(); … … 182 179 end = endOfCurrentParagraph.deepEquivalent(); 183 180 184 RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start);185 181 bool isStartAndEndOnSameNode = false; 186 if ( startStyle) {187 isStartAndEndOnSameNode = renderStyleOfEnclosingTextNode(end) && start. deprecatedNode() == end.deprecatedNode();188 bool isStartAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && start. deprecatedNode() == m_endOfLastParagraph.deprecatedNode();182 if (RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start)) { 183 isStartAndEndOnSameNode = renderStyleOfEnclosingTextNode(end) && start.containerNode() == end.containerNode(); 184 bool isStartAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.containerNode(); 189 185 190 186 // Avoid obtanining the start of next paragraph for start … … 195 191 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) { 196 192 int startOffset = start.offsetInContainerNode(); 197 splitTextNode(static_cast<Text*>(start.deprecatedNode()), startOffset); 198 start = firstPositionInOrBeforeNode(start.deprecatedNode()); 193 Text* startText = start.containerText(); 194 splitTextNode(startText, startOffset); 195 start = firstPositionInNode(startText); 199 196 if (isStartAndEndOnSameNode) { 200 197 ASSERT(end.offsetInContainerNode() >= startOffset); 201 end = Position( end.deprecatedNode(), end.offsetInContainerNode() - startOffset, Position::PositionIsOffsetInAnchor);198 end = Position(startText, end.offsetInContainerNode() - startOffset); 202 199 } 203 200 if (isStartAndEndOfLastParagraphOnSameNode) { 204 201 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffset); 205 m_endOfLastParagraph = Position(m_endOfLastParagraph.deprecatedNode(), m_endOfLastParagraph.offsetInContainerNode() - startOffset, 206 Position::PositionIsOffsetInAnchor); 202 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph.offsetInContainerNode() - startOffset); 207 203 } 208 204 } 209 205 } 210 206 211 RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end); 212 if (endStyle) { 207 if (RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end)) { 213 208 bool isEndAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.deprecatedNode(); 214 209 // Include \n at the end of line if we're at an empty paragraph 215 if (endStyle->preserveNewline() && start == end 216 && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) { 210 if (endStyle->preserveNewline() && start == end && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) { 217 211 int endOffset = end.offsetInContainerNode(); 218 212 if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end)) 219 end = Position(end. deprecatedNode(), endOffset + 1, Position::PositionIsOffsetInAnchor);213 end = Position(end.containerText(), endOffset + 1); 220 214 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNode() >= m_endOfLastParagraph.offsetInContainerNode()) 221 215 m_endOfLastParagraph = end; … … 223 217 224 218 // If end is in the middle of a text node, split. 225 if (!endStyle->collapseWhiteSpace() && end.offsetInContainerNode() 226 && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) {227 splitTextNode( static_cast<Text*>(end.deprecatedNode()), end.offsetInContainerNode());219 if (!endStyle->collapseWhiteSpace() && end.offsetInContainerNode() && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) { 220 RefPtr<Text> endContainer = end.containerText(); 221 splitTextNode(endContainer, end.offsetInContainerNode()); 228 222 if (isStartAndEndOnSameNode) 229 start = firstPositionInOrBeforeNode(end .deprecatedNode()->previousSibling());223 start = firstPositionInOrBeforeNode(endContainer->previousSibling()); 230 224 if (isEndAndEndOfLastParagraphOnSameNode) { 231 225 if (m_endOfLastParagraph.offsetInContainerNode() == end.offsetInContainerNode()) 232 m_endOfLastParagraph = lastPositionIn Node(end.deprecatedNode()->previousSibling());226 m_endOfLastParagraph = lastPositionInOrAfterNode(endContainer->previousSibling()); 233 227 else 234 m_endOfLastParagraph = Position(end.deprecatedNode(), m_endOfLastParagraph.offsetInContainerNode() - end.offsetInContainerNode(), 235 Position::PositionIsOffsetInAnchor); 228 m_endOfLastParagraph = Position(endContainer, m_endOfLastParagraph.offsetInContainerNode() - end.offsetInContainerNode()); 236 229 } 237 end = lastPositionInNode(end .deprecatedNode()->previousSibling());230 end = lastPositionInNode(endContainer->previousSibling()); 238 231 } 239 232 } … … 248 241 return endOfNextParagraph; 249 242 250 RefPtr<Node> containerNode = position.containerNode(); 251 if (!style->preserveNewline() || !position.offsetInContainerNode() 252 || !isNewLineAtPosition(Position(containerNode.get(), 0, Position::PositionIsOffsetInAnchor))) 243 RefPtr<Text> text = position.containerText(); 244 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNewLineAtPosition(firstPositionInNode(text.get()))) 253 245 return endOfNextParagraph; 254 246 … … 256 248 // If endOfNextParagraph was pointing at this same text node, endOfNextParagraph will be shifted by one paragraph. 257 249 // Avoid this by splitting "\n" 258 splitTextNode( static_cast<Text*>(containerNode.get()), 1);259 260 if ( start.anchorType() == Position::PositionIsOffsetInAnchor && containerNode.get() == start.containerNode()) {250 splitTextNode(text, 1); 251 252 if (text == start.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) { 261 253 ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode()); 262 start = Position( containerNode->previousSibling(), start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);263 } 264 if ( end.anchorType() == Position::PositionIsOffsetInAnchor && containerNode.get() == end.containerNode()) {254 start = Position(static_cast<Text*>(text->previousSibling()), start.offsetInContainerNode()); 255 } 256 if (text == end.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) { 265 257 ASSERT(end.offsetInContainerNode() < position.offsetInContainerNode()); 266 end = Position(containerNode->previousSibling(), end.offsetInContainerNode(), Position::PositionIsOffsetInAnchor); 267 } 268 if (m_endOfLastParagraph.anchorType() == Position::PositionIsOffsetInAnchor && containerNode.get() == m_endOfLastParagraph.containerNode()) { 269 if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInContainerNode()) 270 m_endOfLastParagraph = Position(containerNode->previousSibling(), m_endOfLastParagraph.offsetInContainerNode(), Position::PositionIsOffsetInAnchor); 271 else 272 m_endOfLastParagraph = Position(containerNode, m_endOfLastParagraph.offsetInContainerNode() - 1, Position::PositionIsOffsetInAnchor); 273 } 274 275 return Position(containerNode.get(), position.offsetInContainerNode() - 1, Position::PositionIsOffsetInAnchor); 258 end = Position(static_cast<Text*>(text->previousSibling()), end.offsetInContainerNode()); 259 } 260 if (text == m_endOfLastParagraph.containerNode()) { 261 if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInContainerNode()) { 262 // We can only fix endOfLastParagraph if the previous node was still text and hasn't been modified by script. 263 if (text->previousSibling()->isTextNode() 264 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= static_cast<Text*>(text->previousSibling())->length()) 265 m_endOfLastParagraph = Position(static_cast<Text*>(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode()); 266 } else 267 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.offsetInContainerNode() - 1); 268 } 269 270 return Position(text.get(), position.offsetInContainerNode() - 1); 276 271 } 277 272 -
trunk/Source/WebCore/editing/ApplyStyleCommand.cpp
r89283 r89952 1118 1118 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position& end) 1119 1119 { 1120 ASSERT(start. anchorType() == Position::PositionIsOffsetInAnchor);1120 ASSERT(start.containerNode()->isTextNode()); 1121 1121 1122 1122 Position newEnd; 1123 1123 if (end.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode()) 1124 newEnd = Position(end.container Node(), end.offsetInContainerNode() - start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);1124 newEnd = Position(end.containerText(), end.offsetInContainerNode() - start.offsetInContainerNode()); 1125 1125 else 1126 1126 newEnd = end; 1127 1127 1128 Text* text = static_cast<Text*>(start.deprecatedNode());1128 RefPtr<Text> text = start.containerText(); 1129 1129 splitTextNode(text, start.offsetInContainerNode()); 1130 updateStartEnd(firstPositionInNode( start.deprecatedNode()), newEnd);1130 updateStartEnd(firstPositionInNode(text.get()), newEnd); 1131 1131 } 1132 1132 1133 1133 void ApplyStyleCommand::splitTextAtEnd(const Position& start, const Position& end) 1134 1134 { 1135 ASSERT(end. anchorType() == Position::PositionIsOffsetInAnchor);1135 ASSERT(end.containerNode()->isTextNode()); 1136 1136 1137 1137 bool shouldUpdateStart = start.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode(); … … 1140 1140 1141 1141 Node* prevNode = text->previousSibling(); 1142 ASSERT(prevNode); 1143 Position newStart = shouldUpdateStart ? Position(prevNode, start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor) : start; 1142 if (!prevNode || !prevNode->isTextNode()) 1143 return; 1144 1145 Position newStart = shouldUpdateStart ? Position(static_cast<Text*>(prevNode), start.offsetInContainerNode()) : start; 1144 1146 updateStartEnd(newStart, lastPositionInNode(prevNode)); 1145 1147 } … … 1147 1149 void ApplyStyleCommand::splitTextElementAtStart(const Position& start, const Position& end) 1148 1150 { 1149 ASSERT(start. anchorType() == Position::PositionIsOffsetInAnchor);1151 ASSERT(start.containerNode()->isTextNode()); 1150 1152 1151 1153 Position newEnd; 1152 if ( end.anchorType() == Position::PositionIsOffsetInAnchor &&start.containerNode() == end.containerNode())1153 newEnd = Position(end.container Node(), end.offsetInContainerNode() - start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);1154 if (start.containerNode() == end.containerNode()) 1155 newEnd = Position(end.containerText(), end.offsetInContainerNode() - start.offsetInContainerNode()); 1154 1156 else 1155 1157 newEnd = end; 1156 1158 1157 Text* text = static_cast<Text*>(start.deprecatedNode()); 1158 splitTextNodeContainingElement(text, start.deprecatedEditingOffset()); 1159 updateStartEnd(Position(start.deprecatedNode()->parentNode(), start.deprecatedNode()->nodeIndex(), Position::PositionIsOffsetInAnchor), newEnd); 1159 splitTextNodeContainingElement(start.containerText(), start.offsetInContainerNode()); 1160 updateStartEnd(positionBeforeNode(start.containerNode()), newEnd); 1160 1161 } 1161 1162 1162 1163 void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Position& end) 1163 1164 { 1164 ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor); 1165 1166 bool shouldUpdateStart = start.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode(); 1167 Text* text = static_cast<Text*>(end.deprecatedNode()); 1168 splitTextNodeContainingElement(text, end.deprecatedEditingOffset()); 1169 1170 Node* prevNode = text->parentNode()->previousSibling()->lastChild(); 1171 ASSERT(prevNode); 1172 Position newStart = shouldUpdateStart ? Position(prevNode, start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor) : start; 1173 updateStartEnd(newStart, Position(prevNode->parentNode(), prevNode->nodeIndex() + 1, Position::PositionIsOffsetInAnchor)); 1165 ASSERT(end.containerNode()->isTextNode()); 1166 1167 bool shouldUpdateStart = start.containerNode() == end.containerNode(); 1168 splitTextNodeContainingElement(end.containerText(), end.offsetInContainerNode()); 1169 1170 Node* parentElement = end.containerNode()->parentNode(); 1171 if (!parentElement || !parentElement->previousSibling()) 1172 return; 1173 Node* firstTextNode = parentElement->previousSibling()->lastChild(); 1174 if (!firstTextNode || !firstTextNode->isTextNode()) 1175 return; 1176 1177 Position newStart = shouldUpdateStart ? Position(static_cast<Text*>(firstTextNode), start.offsetInContainerNode()) : start; 1178 updateStartEnd(newStart, positionAfterNode(firstTextNode)); 1174 1179 } 1175 1180 … … 1481 1486 Text* nextText = static_cast<Text *>(next); 1482 1487 if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode()) 1483 newStart = Position(childText, childText->length() + start.offsetInContainerNode() , Position::PositionIsOffsetInAnchor);1488 newStart = Position(childText, childText->length() + start.offsetInContainerNode()); 1484 1489 if (end.anchorType() == Position::PositionIsOffsetInAnchor && next == end.containerNode()) 1485 newEnd = Position(childText, childText->length() + end.offsetInContainerNode() , Position::PositionIsOffsetInAnchor);1490 newEnd = Position(childText, childText->length() + end.offsetInContainerNode()); 1486 1491 String textToMove = nextText->data(); 1487 1492 insertTextIntoNode(childText, childText->length(), textToMove); -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r89844 r89952 321 321 return Position(); 322 322 323 RefPtr<Text> textNode = sta tic_cast<Text*>(start.containerNode());323 RefPtr<Text> textNode = start.containerText(); 324 324 replaceTextInNode(textNode, start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text); 325 325 -
trunk/Source/WebCore/editing/Editor.cpp
r88211 r89952 267 267 268 268 if (range->collapsed(ec)) { 269 VisiblePosition start( Position(startContainer, range->startOffset(ec), Position::PositionIsOffsetInAnchor), DOWNSTREAM);269 VisiblePosition start(range->startPosition(), DOWNSTREAM); 270 270 VisiblePosition previous = start.previous(); 271 271 // FIXME: We sometimes allow deletions at the start of editable roots, like when the caret is in an empty list item. -
trunk/Source/WebCore/editing/FrameSelection.cpp
r89318 r89952 1463 1463 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool closeTyping) 1464 1464 { 1465 if (!range) 1466 return false; 1467 1468 ExceptionCode ec = 0; 1469 Node* startContainer = range->startContainer(ec); 1470 if (ec) 1471 return false; 1472 1473 Node* endContainer = range->endContainer(ec); 1474 if (ec) 1475 return false; 1476 1477 ASSERT(startContainer); 1478 ASSERT(endContainer); 1479 ASSERT(startContainer->document() == endContainer->document()); 1480 1465 if (!range || !range->startContainer() || !range->endContainer()) 1466 return false; 1467 ASSERT(range->startContainer()->document() == range->endContainer()->document()); 1468 1481 1469 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1482 1470 1483 1471 // Non-collapsed ranges are not allowed to start at the end of a line that is wrapped, 1484 1472 // they start at the beginning of the next line instead 1473 ExceptionCode ec = 0; 1485 1474 bool collapsed = range->collapsed(ec); 1486 1475 if (ec) 1487 1476 return false; 1488 1489 int startOffset = range->startOffset(ec); 1490 if (ec) 1491 return false; 1492 1493 int endOffset = range->endOffset(ec); 1494 if (ec) 1495 return false; 1496 1477 1497 1478 // FIXME: Can we provide extentAffinity? 1498 VisiblePosition visibleStart(Position(startContainer, startOffset, Position::PositionIsOffsetInAnchor), collapsed ? affinity : DOWNSTREAM); 1499 VisiblePosition visibleEnd(Position(endContainer, endOffset, Position::PositionIsOffsetInAnchor), SEL_DEFAULT_AFFINITY); 1500 SetSelectionOptions options = ClearTypingStyle; 1501 if (closeTyping) 1502 options |= CloseTyping; 1503 setSelection(VisibleSelection(visibleStart, visibleEnd), options); 1479 VisiblePosition visibleStart(range->startPosition(), collapsed ? affinity : DOWNSTREAM); 1480 VisiblePosition visibleEnd(range->endPosition(), SEL_DEFAULT_AFFINITY); 1481 setSelection(VisibleSelection(visibleStart, visibleEnd), ClearTypingStyle | (closeTyping ? CloseTyping : 0)); 1504 1482 return true; 1505 1483 } -
trunk/Source/WebCore/editing/InsertTextCommand.cpp
r89844 r89952 158 158 if (placeholder.isNotNull()) 159 159 removePlaceholderAt(placeholder); 160 RefPtr<Text> textNode = sta tic_cast<Text*>(startPosition.containerNode());160 RefPtr<Text> textNode = startPosition.containerText(); 161 161 const unsigned offset = startPosition.offsetInContainerNode(); 162 162 -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r89505 r89952 940 940 if (!m_matchStyle && !enclosingList(insertionPos.containerNode()) && isStyleSpan(fragment.firstChild())) { 941 941 if (insertionPos.containerNode()->isTextNode() && insertionPos.offsetInContainerNode() && !insertionPos.atLastEditingPositionForNode()) { 942 splitTextNodeContainingElement( static_cast<Text*>(insertionPos.containerNode()), insertionPos.offsetInContainerNode());942 splitTextNodeContainingElement(insertionPos.containerText(), insertionPos.offsetInContainerNode()); 943 943 insertionPos = firstPositionInNode(insertionPos.containerNode()); 944 944 } -
trunk/Source/WebCore/editing/VisiblePosition.cpp
r89683 r89952 553 553 break; 554 554 } 555 Text* textNode = static_cast<Text*>(pos.containerNode());556 unsigned offset = pos.anchorType() == Position::PositionIsOffsetInAnchor ? pos.offsetInContainerNode() : 0;555 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode()); 556 Text* textNode = pos.containerText(); 557 557 unsigned length = textNode->length(); 558 558 if (offset >= length) … … 650 650 VisiblePosition startVisiblePosition(const Range *r, EAffinity affinity) 651 651 { 652 int exception = 0; 653 return VisiblePosition(Position(r->startContainer(exception), r->startOffset(exception), Position::PositionIsOffsetInAnchor), affinity); 652 return VisiblePosition(r->startPosition(), affinity); 654 653 } 655 654 656 655 VisiblePosition endVisiblePosition(const Range *r, EAffinity affinity) 657 656 { 658 int exception = 0; 659 return VisiblePosition(Position(r->endContainer(exception), r->endOffset(exception), Position::PositionIsOffsetInAnchor), affinity); 657 return VisiblePosition(r->endPosition(), affinity); 660 658 } 661 659 -
trunk/Source/WebCore/editing/htmlediting.cpp
r89283 r89952 403 403 static Node* firstInSpecialElement(const Position& pos) 404 404 { 405 // FIXME: This begins at pos.deprecatedNode(), which doesn't necessarily contain pos (suppose pos was [img, 0]). See <rdar://problem/5027702>. 406 Node* rootEditableElement = pos.deprecatedNode()->rootEditableElement(); 405 Node* rootEditableElement = pos.containerNode()->rootEditableElement(); 407 406 for (Node* n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode()) 408 407 if (isSpecialElement(n)) { … … 419 418 static Node* lastInSpecialElement(const Position& pos) 420 419 { 421 // FIXME: This begins at pos.deprecatedNode(), which doesn't necessarily contain pos (suppose pos was [img, 0]). See <rdar://problem/5027702>. 422 Node* rootEditableElement = pos.deprecatedNode()->rootEditableElement(); 420 Node* rootEditableElement = pos.containerNode()->rootEditableElement(); 423 421 for (Node* n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode()) 424 422 if (isSpecialElement(n)) { 425 423 VisiblePosition vPos = VisiblePosition(pos, DOWNSTREAM); 426 VisiblePosition lastInElement = VisiblePosition( Position(n, n->childNodeCount(), Position::PositionIsOffsetInAnchor), DOWNSTREAM);424 VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfterNode(n), DOWNSTREAM); 427 425 if (isTableElement(n) && vPos == lastInElement.previous()) 428 426 return n; -
trunk/Source/WebCore/editing/visible_units.cpp
r89505 r89952 438 438 if (endNode->hasTagName(brTag)) { 439 439 pos = positionBeforeNode(endNode); 440 } else if (endBox->isInlineTextBox() ) {441 InlineTextBox *endTextBox = static_cast<InlineTextBox *>(endBox);440 } else if (endBox->isInlineTextBox() && endNode->isTextNode()) { 441 InlineTextBox* endTextBox = static_cast<InlineTextBox *>(endBox); 442 442 int endOffset = endTextBox->start(); 443 443 if (!endTextBox->isLineBreak()) 444 444 endOffset += endTextBox->len(); 445 pos = Position( endNode, endOffset, Position::PositionIsOffsetInAnchor);445 pos = Position(static_cast<Text*>(endNode), endOffset); 446 446 } else 447 447 pos = positionAfterNode(endNode); … … 794 794 795 795 if (r->isText() && r->caretMaxRenderedOffset() > 0) { 796 ASSERT(n->isTextNode()); 796 797 type = Position::PositionIsOffsetInAnchor; 797 798 if (style->preserveNewline()) { … … 801 802 if (n == startNode && o < i) 802 803 i = max(0, o); 803 while (--i >= 0) 804 while (--i >= 0) { 804 805 if (chars[i] == '\n') 805 return VisiblePosition(Position(n, i + 1, Position::PositionIsOffsetInAnchor), DOWNSTREAM); 806 return VisiblePosition(Position(static_cast<Text*>(n), i + 1), DOWNSTREAM); 807 } 806 808 } 807 809 node = n; … … 816 818 } 817 819 818 if (type == Position::PositionIsOffsetInAnchor) 820 if (type == Position::PositionIsOffsetInAnchor) { 821 ASSERT(type != Position::PositionIsOffsetInAnchor || !offset); 819 822 return VisiblePosition(Position(node, offset, type), DOWNSTREAM); 820 823 } 824 821 825 return VisiblePosition(Position(node, type), DOWNSTREAM); 822 826 } … … 868 872 // FIXME: We avoid returning a position where the renderer can't accept the caret. 869 873 if (r->isText() && r->caretMaxRenderedOffset() > 0) { 874 ASSERT(n->isTextNode()); 870 875 int length = toRenderText(r)->textLength(); 871 876 type = Position::PositionIsOffsetInAnchor; … … 873 878 const UChar* chars = toRenderText(r)->characters(); 874 879 int o = n == startNode ? offset : 0; 875 for (int i = o; i < length; ++i) 880 for (int i = o; i < length; ++i) { 876 881 if (chars[i] == '\n') 877 return VisiblePosition(Position(n, i, Position::PositionIsOffsetInAnchor), DOWNSTREAM); 882 return VisiblePosition(Position(static_cast<Text*>(n), i), DOWNSTREAM); 883 } 878 884 } 879 885 node = n;
Note: See TracChangeset
for help on using the changeset viewer.