| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 using namespace std; | 58 using namespace std; |
| 59 | 59 |
| 60 namespace WebCore { | 60 namespace WebCore { |
| 61 | 61 |
| 62 using namespace HTMLNames; | 62 using namespace HTMLNames; |
| 63 | 63 |
| 64 // Atomic means that the node has no children, or has children which are ignored
for the | 64 // Atomic means that the node has no children, or has children which are ignored
for the |
| 65 // purposes of editing. | 65 // purposes of editing. |
| 66 bool isAtomicNode(const Node *node) | 66 bool isAtomicNode(const Node *node) |
| 67 { | 67 { |
| 68 return node && (!node->hasChildNodes() || editingIgnoresContent(node)); | 68 return node && (!node->hasChildren() || editingIgnoresContent(node)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Compare two positions, taking into account the possibility that one or both | 71 // Compare two positions, taking into account the possibility that one or both |
| 72 // could be inside a shadow tree. Only works for non-null values. | 72 // could be inside a shadow tree. Only works for non-null values. |
| 73 int comparePositions(const Position& a, const Position& b) | 73 int comparePositions(const Position& a, const Position& b) |
| 74 { | 74 { |
| 75 TreeScope* commonScope = commonTreeScope(a.containerNode(), b.containerNode(
)); | 75 TreeScope* commonScope = commonTreeScope(a.containerNode(), b.containerNode(
)); |
| 76 | 76 |
| 77 ASSERT(commonScope); | 77 ASSERT(commonScope); |
| 78 if (!commonScope) | 78 if (!commonScope) |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 // creates technically invalid DOM Positions. Be sure to call parentAnchoredEqui
valent | 341 // creates technically invalid DOM Positions. Be sure to call parentAnchoredEqui
valent |
| 342 // on a Position before using it to create a DOM Range, or an exception will be
thrown. | 342 // on a Position before using it to create a DOM Range, or an exception will be
thrown. |
| 343 int lastOffsetForEditing(const Node* node) | 343 int lastOffsetForEditing(const Node* node) |
| 344 { | 344 { |
| 345 ASSERT(node); | 345 ASSERT(node); |
| 346 if (!node) | 346 if (!node) |
| 347 return 0; | 347 return 0; |
| 348 if (node->offsetInCharacters()) | 348 if (node->offsetInCharacters()) |
| 349 return node->maxCharacterOffset(); | 349 return node->maxCharacterOffset(); |
| 350 | 350 |
| 351 if (node->hasChildNodes()) | 351 if (node->hasChildren()) |
| 352 return node->childNodeCount(); | 352 return node->countChildren(); |
| 353 | 353 |
| 354 // NOTE: This should preempt the childNodeCount for, e.g., select nodes | 354 // NOTE: This should preempt the childNodeCount for, e.g., select nodes |
| 355 if (editingIgnoresContent(node)) | 355 if (editingIgnoresContent(node)) |
| 356 return 1; | 356 return 1; |
| 357 | 357 |
| 358 return 0; | 358 return 0; |
| 359 } | 359 } |
| 360 | 360 |
| 361 String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
aragraph, bool endIsEndOfParagraph) | 361 String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
aragraph, bool endIsEndOfParagraph) |
| 362 { | 362 { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 if (isRenderedTable(downstream.deprecatedNode()) && downstream.atFirstEditin
gPositionForNode()) | 496 if (isRenderedTable(downstream.deprecatedNode()) && downstream.atFirstEditin
gPositionForNode()) |
| 497 return downstream.deprecatedNode(); | 497 return downstream.deprecatedNode(); |
| 498 | 498 |
| 499 return 0; | 499 return 0; |
| 500 } | 500 } |
| 501 | 501 |
| 502 // Returns the visible position at the beginning of a node | 502 // Returns the visible position at the beginning of a node |
| 503 VisiblePosition visiblePositionBeforeNode(Node* node) | 503 VisiblePosition visiblePositionBeforeNode(Node* node) |
| 504 { | 504 { |
| 505 ASSERT(node); | 505 ASSERT(node); |
| 506 if (node->hasChildNodes()) | 506 if (node->hasChildren()) |
| 507 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM); | 507 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM); |
| 508 ASSERT(node->parentNode()); | 508 ASSERT(node->parentNode()); |
| 509 ASSERT(!node->parentNode()->isShadowRoot()); | 509 ASSERT(!node->parentNode()->isShadowRoot()); |
| 510 return positionInParentBeforeNode(node); | 510 return positionInParentBeforeNode(node); |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Returns the visible position at the ending of a node | 513 // Returns the visible position at the ending of a node |
| 514 VisiblePosition visiblePositionAfterNode(Node* node) | 514 VisiblePosition visiblePositionAfterNode(Node* node) |
| 515 { | 515 { |
| 516 ASSERT(node); | 516 ASSERT(node); |
| 517 if (node->hasChildNodes()) | 517 if (node->hasChildren()) |
| 518 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM); | 518 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM); |
| 519 ASSERT(node->parentNode()); | 519 ASSERT(node->parentNode()); |
| 520 ASSERT(!node->parentNode()->isShadowRoot()); | 520 ASSERT(!node->parentNode()->isShadowRoot()); |
| 521 return positionInParentAfterNode(node); | 521 return positionInParentAfterNode(node); |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Create a range object with two visible positions, start and end. | 524 // Create a range object with two visible positions, start and end. |
| 525 // create(Document*, const Position&, const Position&); will use deprecatedEditi
ngOffset | 525 // create(Document*, const Position&, const Position&); will use deprecatedEditi
ngOffset |
| 526 // Use this function instead of create a regular range object (avoiding editing
offset). | 526 // Use this function instead of create a regular range object (avoiding editing
offset). |
| 527 PassRefPtr<Range> createRange(Document& document, const VisiblePosition& start,
const VisiblePosition& end, ExceptionState& exceptionState) | 527 PassRefPtr<Range> createRange(Document& document, const VisiblePosition& start,
const VisiblePosition& end, ExceptionState& exceptionState) |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 // if the selection starts just before a paragraph break, skip over it | 1118 // if the selection starts just before a paragraph break, skip over it |
| 1119 if (isEndOfParagraph(visiblePosition)) | 1119 if (isEndOfParagraph(visiblePosition)) |
| 1120 return visiblePosition.next().deepEquivalent().downstream(); | 1120 return visiblePosition.next().deepEquivalent().downstream(); |
| 1121 | 1121 |
| 1122 // otherwise, make sure to be at the start of the first selected node, | 1122 // otherwise, make sure to be at the start of the first selected node, |
| 1123 // instead of possibly at the end of the last node before the selection | 1123 // instead of possibly at the end of the last node before the selection |
| 1124 return visiblePosition.deepEquivalent().downstream(); | 1124 return visiblePosition.deepEquivalent().downstream(); |
| 1125 } | 1125 } |
| 1126 | 1126 |
| 1127 } // namespace WebCore | 1127 } // namespace WebCore |
| OLD | NEW |