| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (!m_anchorNode) | 207 if (!m_anchorNode) |
| 208 return Position(); | 208 return Position(); |
| 209 | 209 |
| 210 // FIXME: This should only be necessary for legacy positions, but is also ne
eded for positions before and after Tables | 210 // FIXME: This should only be necessary for legacy positions, but is also ne
eded for positions before and after Tables |
| 211 if (m_offset <= 0 && (m_anchorType != PositionIsAfterAnchor && m_anchorType
!= PositionIsAfterChildren)) { | 211 if (m_offset <= 0 && (m_anchorType != PositionIsAfterAnchor && m_anchorType
!= PositionIsAfterChildren)) { |
| 212 if (m_anchorNode->parentNode() && (editingIgnoresContent(m_anchorNode.ge
t()) || isRenderedTableElement(m_anchorNode.get()))) | 212 if (m_anchorNode->parentNode() && (editingIgnoresContent(m_anchorNode.ge
t()) || isRenderedTableElement(m_anchorNode.get()))) |
| 213 return positionInParentBeforeNode(m_anchorNode.get()); | 213 return positionInParentBeforeNode(m_anchorNode.get()); |
| 214 return Position(m_anchorNode.get(), 0, PositionIsOffsetInAnchor); | 214 return Position(m_anchorNode.get(), 0, PositionIsOffsetInAnchor); |
| 215 } | 215 } |
| 216 if (!m_anchorNode->offsetInCharacters() | 216 if (!m_anchorNode->offsetInCharacters() |
| 217 && (m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsA
fterChildren || static_cast<unsigned>(m_offset) == m_anchorNode->childNodeCount(
)) | 217 && (m_anchorType == PositionIsAfterAnchor || m_anchorType == PositionIsA
fterChildren || static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()
) |
| 218 && (editingIgnoresContent(m_anchorNode.get()) || isRenderedTableElement(
m_anchorNode.get())) | 218 && (editingIgnoresContent(m_anchorNode.get()) || isRenderedTableElement(
m_anchorNode.get())) |
| 219 && containerNode()) { | 219 && containerNode()) { |
| 220 return positionInParentAfterNode(m_anchorNode.get()); | 220 return positionInParentAfterNode(m_anchorNode.get()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 return Position(containerNode(), computeOffsetInContainerNode(), PositionIsO
ffsetInAnchor); | 223 return Position(containerNode(), computeOffsetInContainerNode(), PositionIsO
ffsetInAnchor); |
| 224 } | 224 } |
| 225 | 225 |
| 226 Node* Position::computeNodeBeforePosition() const | 226 Node* Position::computeNodeBeforePosition() const |
| 227 { | 227 { |
| 228 if (!m_anchorNode) | 228 if (!m_anchorNode) |
| 229 return 0; | 229 return 0; |
| 230 | 230 |
| 231 switch (anchorType()) { | 231 switch (anchorType()) { |
| 232 case PositionIsBeforeChildren: | 232 case PositionIsBeforeChildren: |
| 233 return 0; | 233 return 0; |
| 234 case PositionIsAfterChildren: | 234 case PositionIsAfterChildren: |
| 235 return m_anchorNode->lastChild(); | 235 return m_anchorNode->lastChild(); |
| 236 case PositionIsOffsetInAnchor: | 236 case PositionIsOffsetInAnchor: |
| 237 return m_anchorNode->childNode(m_offset - 1); // -1 converts to childNod
e((unsigned)-1) and returns null. | 237 return m_anchorNode->traverseToChildAt(m_offset - 1); // -1 converts to
traverseToChildAt((unsigned)-1) and returns null. |
| 238 case PositionIsBeforeAnchor: | 238 case PositionIsBeforeAnchor: |
| 239 return m_anchorNode->previousSibling(); | 239 return m_anchorNode->previousSibling(); |
| 240 case PositionIsAfterAnchor: | 240 case PositionIsAfterAnchor: |
| 241 return m_anchorNode.get(); | 241 return m_anchorNode.get(); |
| 242 } | 242 } |
| 243 ASSERT_NOT_REACHED(); | 243 ASSERT_NOT_REACHED(); |
| 244 return 0; | 244 return 0; |
| 245 } | 245 } |
| 246 | 246 |
| 247 Node* Position::computeNodeAfterPosition() const | 247 Node* Position::computeNodeAfterPosition() const |
| 248 { | 248 { |
| 249 if (!m_anchorNode) | 249 if (!m_anchorNode) |
| 250 return 0; | 250 return 0; |
| 251 | 251 |
| 252 switch (anchorType()) { | 252 switch (anchorType()) { |
| 253 case PositionIsBeforeChildren: | 253 case PositionIsBeforeChildren: |
| 254 return m_anchorNode->firstChild(); | 254 return m_anchorNode->firstChild(); |
| 255 case PositionIsAfterChildren: | 255 case PositionIsAfterChildren: |
| 256 return 0; | 256 return 0; |
| 257 case PositionIsOffsetInAnchor: | 257 case PositionIsOffsetInAnchor: |
| 258 return m_anchorNode->childNode(m_offset); | 258 return m_anchorNode->traverseToChildAt(m_offset); |
| 259 case PositionIsBeforeAnchor: | 259 case PositionIsBeforeAnchor: |
| 260 return m_anchorNode.get(); | 260 return m_anchorNode.get(); |
| 261 case PositionIsAfterAnchor: | 261 case PositionIsAfterAnchor: |
| 262 return m_anchorNode->nextSibling(); | 262 return m_anchorNode->nextSibling(); |
| 263 } | 263 } |
| 264 ASSERT_NOT_REACHED(); | 264 ASSERT_NOT_REACHED(); |
| 265 return 0; | 265 return 0; |
| 266 } | 266 } |
| 267 | 267 |
| 268 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo
de, int offset) | 268 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo
de, int offset) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 296 { | 296 { |
| 297 Node* node = deprecatedNode(); | 297 Node* node = deprecatedNode(); |
| 298 if (!node) | 298 if (!node) |
| 299 return *this; | 299 return *this; |
| 300 | 300 |
| 301 int offset = deprecatedEditingOffset(); | 301 int offset = deprecatedEditingOffset(); |
| 302 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie
r. | 302 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie
r. |
| 303 ASSERT(offset >= 0); | 303 ASSERT(offset >= 0); |
| 304 | 304 |
| 305 if (offset > 0) { | 305 if (offset > 0) { |
| 306 if (Node* child = node->childNode(offset - 1)) | 306 if (Node* child = node->traverseToChildAt(offset - 1)) |
| 307 return lastPositionInOrAfterNode(child); | 307 return lastPositionInOrAfterNode(child); |
| 308 | 308 |
| 309 // There are two reasons child might be 0: | 309 // There are two reasons child might be 0: |
| 310 // 1) The node is node like a text node that is not an element, and th
erefore has no children. | 310 // 1) The node is node like a text node that is not an element, and th
erefore has no children. |
| 311 // Going backward one character at a time is correct. | 311 // Going backward one character at a time is correct. |
| 312 // 2) The old offset was a bogus offset like (<br>, 1), and there is n
o child. | 312 // 2) The old offset was a bogus offset like (<br>, 1), and there is n
o child. |
| 313 // Going from 1 to 0 is correct. | 313 // Going from 1 to 0 is correct. |
| 314 switch (moveType) { | 314 switch (moveType) { |
| 315 case CodePoint: | 315 case CodePoint: |
| 316 return createLegacyEditingPosition(node, offset - 1); | 316 return createLegacyEditingPosition(node, offset - 1); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 331 ASSERT(moveType != BackwardDeletion); | 331 ASSERT(moveType != BackwardDeletion); |
| 332 | 332 |
| 333 Node* node = deprecatedNode(); | 333 Node* node = deprecatedNode(); |
| 334 if (!node) | 334 if (!node) |
| 335 return *this; | 335 return *this; |
| 336 | 336 |
| 337 int offset = deprecatedEditingOffset(); | 337 int offset = deprecatedEditingOffset(); |
| 338 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie
r. | 338 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie
r. |
| 339 ASSERT(offset >= 0); | 339 ASSERT(offset >= 0); |
| 340 | 340 |
| 341 if (Node* child = node->childNode(offset)) | 341 if (Node* child = node->traverseToChildAt(offset)) |
| 342 return firstPositionInOrBeforeNode(child); | 342 return firstPositionInOrBeforeNode(child); |
| 343 | 343 |
| 344 if (!node->hasChildNodes() && offset < lastOffsetForEditing(node)) { | 344 if (!node->hasChildren() && offset < lastOffsetForEditing(node)) { |
| 345 // There are two reasons child might be 0: | 345 // There are two reasons child might be 0: |
| 346 // 1) The node is node like a text node that is not an element, and th
erefore has no children. | 346 // 1) The node is node like a text node that is not an element, and th
erefore has no children. |
| 347 // Going forward one character at a time is correct. | 347 // Going forward one character at a time is correct. |
| 348 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
child. | 348 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
child. |
| 349 // Going from 0 to 1 is correct. | 349 // Going from 0 to 1 is correct. |
| 350 return createLegacyEditingPosition(node, (moveType == Character) ? unche
ckedNextOffset(node, offset) : offset + 1); | 350 return createLegacyEditingPosition(node, (moveType == Character) ? unche
ckedNextOffset(node, offset) : offset + 1); |
| 351 } | 351 } |
| 352 | 352 |
| 353 if (ContainerNode* parent = node->parentNode()) | 353 if (ContainerNode* parent = node->parentNode()) |
| 354 return createLegacyEditingPosition(parent, node->nodeIndex() + 1); | 354 return createLegacyEditingPosition(parent, node->nodeIndex() + 1); |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 pos.showTreeForThis(); | 1382 pos.showTreeForThis(); |
| 1383 } | 1383 } |
| 1384 | 1384 |
| 1385 void showTree(const WebCore::Position* pos) | 1385 void showTree(const WebCore::Position* pos) |
| 1386 { | 1386 { |
| 1387 if (pos) | 1387 if (pos) |
| 1388 pos->showTreeForThis(); | 1388 pos->showTreeForThis(); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 #endif | 1391 #endif |
| OLD | NEW |