| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 int m_offset; | 86 int m_offset; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 static const TreeScope* commonAncestorTreeScope(const PositionType&, const P
ositionType& b); | 89 static const TreeScope* commonAncestorTreeScope(const PositionType&, const P
ositionType& b); |
| 90 static PositionType createLegacyEditingPosition(PassRefPtrWillBeRawPtr<Node>
anchorNode, int offset); | 90 static PositionType createLegacyEditingPosition(PassRefPtrWillBeRawPtr<Node>
anchorNode, int offset); |
| 91 | 91 |
| 92 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, LegacyEditingOffs
et); | 92 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, LegacyEditingOffs
et); |
| 93 | 93 |
| 94 // For creating before/after positions: | 94 // For creating before/after positions: |
| 95 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, AnchorType); | 95 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, AnchorType); |
| 96 PositionAlgorithm(PassRefPtrWillBeRawPtr<Text> textNode, unsigned offset); | |
| 97 | 96 |
| 98 // For creating offset positions: | 97 // For creating offset positions: |
| 99 // FIXME: This constructor should eventually go away. See bug 63040. | 98 // FIXME: This constructor should eventually go away. See bug 63040. |
| 100 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, int offset, Ancho
rType); | 99 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, int offset); |
| 101 | 100 |
| 102 PositionAlgorithm(const PositionAlgorithm&); | 101 PositionAlgorithm(const PositionAlgorithm&); |
| 103 | 102 |
| 104 AnchorType anchorType() const { return m_anchorType; } | 103 AnchorType anchorType() const { return m_anchorType; } |
| 105 | 104 |
| 106 void clear() { m_anchorNode.clear(); m_offset = 0; m_anchorType = PositionIs
OffsetInAnchor; m_isLegacyEditingPosition = false; } | 105 void clear() { m_anchorNode.clear(); m_offset = 0; m_anchorType = PositionIs
OffsetInAnchor; m_isLegacyEditingPosition = false; } |
| 107 | 106 |
| 108 // These are always DOM compliant values. Editing positions like [img, 0] (
aka [img, before]) | 107 // These are always DOM compliant values. Editing positions like [img, 0] (
aka [img, before]) |
| 109 // will return img->parentNode() and img->nodeIndex() from these functions. | 108 // will return img->parentNode() and img->nodeIndex() from these functions. |
| 110 Node* containerNode() const; // NULL for a before/after position anchored to
a node with no parent | 109 Node* containerNode() const; // NULL for a before/after position anchored to
a node with no parent |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // These are inline to prevent ref-churn when returning a Position object. | 309 // These are inline to prevent ref-churn when returning a Position object. |
| 311 // If we ever add a PassPosition we can make these non-inline. | 310 // If we ever add a PassPosition we can make these non-inline. |
| 312 | 311 |
| 313 template <typename Strategy> | 312 template <typename Strategy> |
| 314 typename Strategy::PositionType PositionAlgorithm<Strategy>::inParentBeforeNode(
const Node& node) | 313 typename Strategy::PositionType PositionAlgorithm<Strategy>::inParentBeforeNode(
const Node& node) |
| 315 { | 314 { |
| 316 // FIXME: This should ASSERT(node.parentNode()) | 315 // FIXME: This should ASSERT(node.parentNode()) |
| 317 // At least one caller currently hits this ASSERT though, which indicates | 316 // At least one caller currently hits this ASSERT though, which indicates |
| 318 // that the caller is trying to make a position relative to a disconnected n
ode (which is likely an error) | 317 // that the caller is trying to make a position relative to a disconnected n
ode (which is likely an error) |
| 319 // Specifically, editing/deleting/delete-ligature-001.html crashes with ASSE
RT(node->parentNode()) | 318 // Specifically, editing/deleting/delete-ligature-001.html crashes with ASSE
RT(node->parentNode()) |
| 320 return PositionType(Strategy::parent(node), Strategy::index(node), PositionI
sOffsetInAnchor); | 319 return PositionType(Strategy::parent(node), Strategy::index(node)); |
| 321 } | 320 } |
| 322 | 321 |
| 323 inline Position positionInParentBeforeNode(const Node& node) | 322 inline Position positionInParentBeforeNode(const Node& node) |
| 324 { | 323 { |
| 325 return Position::inParentBeforeNode(node); | 324 return Position::inParentBeforeNode(node); |
| 326 } | 325 } |
| 327 | 326 |
| 328 template <typename Strategy> | 327 template <typename Strategy> |
| 329 typename Strategy::PositionType PositionAlgorithm<Strategy>::inParentAfterNode(c
onst Node& node) | 328 typename Strategy::PositionType PositionAlgorithm<Strategy>::inParentAfterNode(c
onst Node& node) |
| 330 { | 329 { |
| 331 ASSERT(node.parentNode()); | 330 ASSERT(node.parentNode()); |
| 332 return PositionType(Strategy::parent(node), Strategy::index(node) + 1, Posit
ionIsOffsetInAnchor); | 331 return PositionType(Strategy::parent(node), Strategy::index(node) + 1); |
| 333 } | 332 } |
| 334 | 333 |
| 335 inline Position positionInParentAfterNode(const Node& node) | 334 inline Position positionInParentAfterNode(const Node& node) |
| 336 { | 335 { |
| 337 return Position::inParentAfterNode(node); | 336 return Position::inParentAfterNode(node); |
| 338 } | 337 } |
| 339 | 338 |
| 340 // positionBeforeNode and positionAfterNode return neighbor-anchored positions,
construction is O(1) | 339 // positionBeforeNode and positionAfterNode return neighbor-anchored positions,
construction is O(1) |
| 341 template <typename Strategy> | 340 template <typename Strategy> |
| 342 typename Strategy::PositionType PositionAlgorithm<Strategy>::beforeNode(Node* an
chorNode) | 341 typename Strategy::PositionType PositionAlgorithm<Strategy>::beforeNode(Node* an
chorNode) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 371 inline int lastOffsetInNode(Node* node) | 370 inline int lastOffsetInNode(Node* node) |
| 372 { | 371 { |
| 373 return Position::lastOffsetInNode(node); | 372 return Position::lastOffsetInNode(node); |
| 374 } | 373 } |
| 375 | 374 |
| 376 // firstPositionInNode and lastPositionInNode return parent-anchored positions,
lastPositionInNode construction is O(n) due to countChildren() | 375 // firstPositionInNode and lastPositionInNode return parent-anchored positions,
lastPositionInNode construction is O(n) due to countChildren() |
| 377 template <typename Strategy> | 376 template <typename Strategy> |
| 378 typename Strategy::PositionType PositionAlgorithm<Strategy>::firstPositionInNode
(Node* anchorNode) | 377 typename Strategy::PositionType PositionAlgorithm<Strategy>::firstPositionInNode
(Node* anchorNode) |
| 379 { | 378 { |
| 380 if (anchorNode->isTextNode()) | 379 if (anchorNode->isTextNode()) |
| 381 return PositionType(anchorNode, 0, PositionIsOffsetInAnchor); | 380 return PositionType(anchorNode, 0); |
| 382 return PositionType(anchorNode, PositionIsBeforeChildren); | 381 return PositionType(anchorNode, PositionIsBeforeChildren); |
| 383 } | 382 } |
| 384 | 383 |
| 385 inline Position firstPositionInNode(Node* anchorNode) | 384 inline Position firstPositionInNode(Node* anchorNode) |
| 386 { | 385 { |
| 387 return Position::firstPositionInNode(anchorNode); | 386 return Position::firstPositionInNode(anchorNode); |
| 388 } | 387 } |
| 389 | 388 |
| 390 template <typename Strategy> | 389 template <typename Strategy> |
| 391 typename Strategy::PositionType PositionAlgorithm<Strategy>::lastPositionInNode(
Node* anchorNode) | 390 typename Strategy::PositionType PositionAlgorithm<Strategy>::lastPositionInNode(
Node* anchorNode) |
| 392 { | 391 { |
| 393 if (anchorNode->isTextNode()) | 392 if (anchorNode->isTextNode()) |
| 394 return PositionType(anchorNode, lastOffsetInNode(anchorNode), PositionIs
OffsetInAnchor); | 393 return PositionType(anchorNode, lastOffsetInNode(anchorNode)); |
| 395 return PositionType(anchorNode, PositionIsAfterChildren); | 394 return PositionType(anchorNode, PositionIsAfterChildren); |
| 396 } | 395 } |
| 397 | 396 |
| 398 inline Position lastPositionInNode(Node* anchorNode) | 397 inline Position lastPositionInNode(Node* anchorNode) |
| 399 { | 398 { |
| 400 return Position::lastPositionInNode(anchorNode); | 399 return Position::lastPositionInNode(anchorNode); |
| 401 } | 400 } |
| 402 | 401 |
| 403 template <typename Strategy> | 402 template <typename Strategy> |
| 404 int PositionAlgorithm<Strategy>::minOffsetForNode(Node* anchorNode, int offset) | 403 int PositionAlgorithm<Strategy>::minOffsetForNode(Node* anchorNode, int offset) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 | 456 |
| 458 } // namespace blink | 457 } // namespace blink |
| 459 | 458 |
| 460 #ifndef NDEBUG | 459 #ifndef NDEBUG |
| 461 // Outside the WebCore namespace for ease of invocation from gdb. | 460 // Outside the WebCore namespace for ease of invocation from gdb. |
| 462 void showTree(const blink::Position&); | 461 void showTree(const blink::Position&); |
| 463 void showTree(const blink::Position*); | 462 void showTree(const blink::Position*); |
| 464 #endif | 463 #endif |
| 465 | 464 |
| 466 #endif // Position_h | 465 #endif // Position_h |
| OLD | NEW |