| 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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 return false; | 631 return false; |
| 632 } | 632 } |
| 633 | 633 |
| 634 static HTMLElement* firstInSpecialElement(const Position& pos) | 634 static HTMLElement* firstInSpecialElement(const Position& pos) |
| 635 { | 635 { |
| 636 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme
nt(); | 636 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme
nt(); |
| 637 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab
leElement; n = n->parentNode()) { | 637 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab
leElement; n = n->parentNode()) { |
| 638 if (isSpecialHTMLElement(*n)) { | 638 if (isSpecialHTMLElement(*n)) { |
| 639 HTMLElement* specialElement = toHTMLElement(n); | 639 HTMLElement* specialElement = toHTMLElement(n); |
| 640 VisiblePosition vPos = VisiblePosition(pos, DOWNSTREAM); | 640 VisiblePosition vPos = VisiblePosition(pos); |
| 641 VisiblePosition firstInElement = VisiblePosition(firstPositionInOrBe
foreNode(specialElement), DOWNSTREAM); | 641 VisiblePosition firstInElement = VisiblePosition(firstPositionInOrBe
foreNode(specialElement)); |
| 642 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent()
== firstInElement.next().deepEquivalent()) | 642 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent()
== firstInElement.next().deepEquivalent()) |
| 643 return specialElement; | 643 return specialElement; |
| 644 if (vPos.deepEquivalent() == firstInElement.deepEquivalent()) | 644 if (vPos.deepEquivalent() == firstInElement.deepEquivalent()) |
| 645 return specialElement; | 645 return specialElement; |
| 646 } | 646 } |
| 647 } | 647 } |
| 648 return 0; | 648 return 0; |
| 649 } | 649 } |
| 650 | 650 |
| 651 static HTMLElement* lastInSpecialElement(const Position& pos) | 651 static HTMLElement* lastInSpecialElement(const Position& pos) |
| 652 { | 652 { |
| 653 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme
nt(); | 653 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme
nt(); |
| 654 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab
leElement; n = n->parentNode()) { | 654 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab
leElement; n = n->parentNode()) { |
| 655 if (isSpecialHTMLElement(*n)) { | 655 if (isSpecialHTMLElement(*n)) { |
| 656 HTMLElement* specialElement = toHTMLElement(n); | 656 HTMLElement* specialElement = toHTMLElement(n); |
| 657 VisiblePosition vPos = VisiblePosition(pos, DOWNSTREAM); | 657 VisiblePosition vPos = VisiblePosition(pos); |
| 658 VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfte
rNode(specialElement), DOWNSTREAM); | 658 VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfte
rNode(specialElement)); |
| 659 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent()
== lastInElement.previous().deepEquivalent()) | 659 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent()
== lastInElement.previous().deepEquivalent()) |
| 660 return specialElement; | 660 return specialElement; |
| 661 if (vPos.deepEquivalent() == lastInElement.deepEquivalent()) | 661 if (vPos.deepEquivalent() == lastInElement.deepEquivalent()) |
| 662 return specialElement; | 662 return specialElement; |
| 663 } | 663 } |
| 664 } | 664 } |
| 665 return 0; | 665 return 0; |
| 666 } | 666 } |
| 667 | 667 |
| 668 Position positionBeforeContainingSpecialElement(const Position& pos, HTMLElement
** containingSpecialElement) | 668 Position positionBeforeContainingSpecialElement(const Position& pos, HTMLElement
** containingSpecialElement) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 return node; | 753 return node; |
| 754 node = nextNodeConsideringAtomicNodes(*node); | 754 node = nextNodeConsideringAtomicNodes(*node); |
| 755 } | 755 } |
| 756 return nullptr; | 756 return nullptr; |
| 757 } | 757 } |
| 758 | 758 |
| 759 // Returns the visible position at the beginning of a node | 759 // Returns the visible position at the beginning of a node |
| 760 VisiblePosition visiblePositionBeforeNode(Node& node) | 760 VisiblePosition visiblePositionBeforeNode(Node& node) |
| 761 { | 761 { |
| 762 if (node.hasChildren()) | 762 if (node.hasChildren()) |
| 763 return VisiblePosition(firstPositionInOrBeforeNode(&node), DOWNSTREAM); | 763 return VisiblePosition(firstPositionInOrBeforeNode(&node)); |
| 764 ASSERT(node.parentNode()); | 764 ASSERT(node.parentNode()); |
| 765 ASSERT(!node.parentNode()->isShadowRoot()); | 765 ASSERT(!node.parentNode()->isShadowRoot()); |
| 766 return VisiblePosition(positionInParentBeforeNode(node)); | 766 return VisiblePosition(positionInParentBeforeNode(node)); |
| 767 } | 767 } |
| 768 | 768 |
| 769 // Returns the visible position at the ending of a node | 769 // Returns the visible position at the ending of a node |
| 770 VisiblePosition visiblePositionAfterNode(Node& node) | 770 VisiblePosition visiblePositionAfterNode(Node& node) |
| 771 { | 771 { |
| 772 if (node.hasChildren()) | 772 if (node.hasChildren()) |
| 773 return VisiblePosition(lastPositionInOrAfterNode(&node), DOWNSTREAM); | 773 return VisiblePosition(lastPositionInOrAfterNode(&node)); |
| 774 ASSERT(node.parentNode()); | 774 ASSERT(node.parentNode()); |
| 775 ASSERT(!node.parentNode()->isShadowRoot()); | 775 ASSERT(!node.parentNode()->isShadowRoot()); |
| 776 return VisiblePosition(positionInParentAfterNode(node)); | 776 return VisiblePosition(positionInParentAfterNode(node)); |
| 777 } | 777 } |
| 778 | 778 |
| 779 bool isHTMLListElement(Node* n) | 779 bool isHTMLListElement(Node* n) |
| 780 { | 780 { |
| 781 return (n && (isHTMLUListElement(*n) || isHTMLOListElement(*n) || isHTMLDLis
tElement(*n))); | 781 return (n && (isHTMLUListElement(*n) || isHTMLOListElement(*n) || isHTMLDLis
tElement(*n))); |
| 782 } | 782 } |
| 783 | 783 |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 // if the selection starts just before a paragraph break, skip over it | 1434 // if the selection starts just before a paragraph break, skip over it |
| 1435 if (isEndOfParagraph(visiblePosition)) | 1435 if (isEndOfParagraph(visiblePosition)) |
| 1436 return visiblePosition.next().deepEquivalent().downstream(); | 1436 return visiblePosition.next().deepEquivalent().downstream(); |
| 1437 | 1437 |
| 1438 // otherwise, make sure to be at the start of the first selected node, | 1438 // otherwise, make sure to be at the start of the first selected node, |
| 1439 // instead of possibly at the end of the last node before the selection | 1439 // instead of possibly at the end of the last node before the selection |
| 1440 return visiblePosition.deepEquivalent().downstream(); | 1440 return visiblePosition.deepEquivalent().downstream(); |
| 1441 } | 1441 } |
| 1442 | 1442 |
| 1443 } // namespace blink | 1443 } // namespace blink |
| OLD | NEW |