| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // |mostBackwardCaretPosition()|. However, we are here during | 104 // |mostBackwardCaretPosition()|. However, we are here during |
| 105 // |Node::removeChild()|. | 105 // |Node::removeChild()|. |
| 106 start.anchorNode()->updateDistribution(); | 106 start.anchorNode()->updateDistribution(); |
| 107 end.anchorNode()->updateDistribution(); | 107 end.anchorNode()->updateDistribution(); |
| 108 if (mostBackwardCaretPosition(start) == mostBackwardCaretPosition(end)) | 108 if (mostBackwardCaretPosition(start) == mostBackwardCaretPosition(end)) |
| 109 return CaretSelection; | 109 return CaretSelection; |
| 110 return RangeSelection; | 110 return RangeSelection; |
| 111 } | 111 } |
| 112 | 112 |
| 113 template <typename Strategy> | 113 template <typename Strategy> |
| 114 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate( | |
| 115 const PositionTemplate<Strategy>& base, | |
| 116 const PositionTemplate<Strategy>& extent, | |
| 117 const PositionTemplate<Strategy>& start, | |
| 118 const PositionTemplate<Strategy>& end, | |
| 119 TextAffinity affinity, | |
| 120 bool isDirectional) | |
| 121 : m_base(base) | |
| 122 , m_extent(extent) | |
| 123 , m_start(start) | |
| 124 , m_end(end) | |
| 125 , m_affinity(affinity) | |
| 126 , m_changeObserver(nullptr) // Observer is associated with only one VisibleS
election, so this should not be copied. | |
| 127 , m_selectionType(computeSelectionType(start, end)) | |
| 128 , m_baseIsFirst(base.isNull() || base.compareTo(extent) <= 0) | |
| 129 , m_isDirectional(isDirectional) | |
| 130 { | |
| 131 ASSERT(base.isNull() == extent.isNull()); | |
| 132 ASSERT(base.isNull() == start.isNull()); | |
| 133 ASSERT(base.isNull() == end.isNull()); | |
| 134 ASSERT(start.isNull() || start.compareTo(end) <= 0); | |
| 135 } | |
| 136 | |
| 137 template <typename Strategy> | |
| 138 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const VisibleSelect
ionTemplate<Strategy>& other) | 114 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const VisibleSelect
ionTemplate<Strategy>& other) |
| 139 : m_base(other.m_base) | 115 : m_base(other.m_base) |
| 140 , m_extent(other.m_extent) | 116 , m_extent(other.m_extent) |
| 141 , m_start(other.m_start) | 117 , m_start(other.m_start) |
| 142 , m_end(other.m_end) | 118 , m_end(other.m_end) |
| 143 , m_affinity(other.m_affinity) | 119 , m_affinity(other.m_affinity) |
| 144 , m_changeObserver(nullptr) // Observer is associated with only one VisibleS
election, so this should not be copied. | 120 , m_changeObserver(nullptr) // Observer is associated with only one VisibleS
election, so this should not be copied. |
| 145 , m_selectionType(other.m_selectionType) | 121 , m_selectionType(other.m_selectionType) |
| 146 , m_baseIsFirst(other.m_baseIsFirst) | 122 , m_baseIsFirst(other.m_baseIsFirst) |
| 147 , m_isDirectional(other.m_isDirectional) | 123 , m_isDirectional(other.m_isDirectional) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 158 m_start = other.m_start; | 134 m_start = other.m_start; |
| 159 m_end = other.m_end; | 135 m_end = other.m_end; |
| 160 m_affinity = other.m_affinity; | 136 m_affinity = other.m_affinity; |
| 161 m_changeObserver = nullptr; | 137 m_changeObserver = nullptr; |
| 162 m_selectionType = other.m_selectionType; | 138 m_selectionType = other.m_selectionType; |
| 163 m_baseIsFirst = other.m_baseIsFirst; | 139 m_baseIsFirst = other.m_baseIsFirst; |
| 164 m_isDirectional = other.m_isDirectional; | 140 m_isDirectional = other.m_isDirectional; |
| 165 return *this; | 141 return *this; |
| 166 } | 142 } |
| 167 | 143 |
| 168 template <typename Strategy> | |
| 169 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::createWit
houtValidation(const PositionTemplate<Strategy>& base, const PositionTemplate<St
rategy>& extent, const PositionTemplate<Strategy>& start, const PositionTemplate
<Strategy>& end, TextAffinity affinity, bool isDirectional) | |
| 170 { | |
| 171 return VisibleSelectionTemplate<Strategy>(base, extent, start, end, affinity
, isDirectional); | |
| 172 } | |
| 173 | |
| 174 #if !ENABLE(OILPAN) | 144 #if !ENABLE(OILPAN) |
| 175 template <typename Strategy> | 145 template <typename Strategy> |
| 176 VisibleSelectionTemplate<Strategy>::~VisibleSelectionTemplate() | 146 VisibleSelectionTemplate<Strategy>::~VisibleSelectionTemplate() |
| 177 { | 147 { |
| 178 didChange(); | 148 didChange(); |
| 179 } | 149 } |
| 180 #endif | 150 #endif |
| 181 | 151 |
| 182 template <typename Strategy> | 152 template <typename Strategy> |
| 183 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection
FromContentsOfNode(Node* node) | 153 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection
FromContentsOfNode(Node* node) |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 return positionBeforeNode(ancestor); | 706 return positionBeforeNode(ancestor); |
| 737 return positionAfterNode(ancestor); | 707 return positionAfterNode(ancestor); |
| 738 } | 708 } |
| 739 | 709 |
| 740 if (Node* firstChild = treeScope.rootNode().firstChild()) | 710 if (Node* firstChild = treeScope.rootNode().firstChild()) |
| 741 return positionBeforeNode(firstChild); | 711 return positionBeforeNode(firstChild); |
| 742 | 712 |
| 743 return Position(); | 713 return Position(); |
| 744 } | 714 } |
| 745 | 715 |
| 746 static VisibleSelection computeSelectionToAvoidCrossingShadowBoundaries(const Vi
sibleSelection& selection) | 716 // TODO(yosin): We should move |
| 717 // |SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries()| to |
| 718 // "SelectionAdjuster.cpp" |
| 719 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSe
lection* selection) |
| 747 { | 720 { |
| 748 // Note: |m_selectionType| isn't computed yet. | 721 // Note: |m_selectionType| isn't computed yet. |
| 749 ASSERT(selection.base().isNotNull()); | 722 ASSERT(selection->base().isNotNull()); |
| 750 ASSERT(selection.extent().isNotNull()); | 723 ASSERT(selection->extent().isNotNull()); |
| 751 ASSERT(selection.start().isNotNull()); | 724 ASSERT(selection->start().isNotNull()); |
| 752 ASSERT(selection.end().isNotNull()); | 725 ASSERT(selection->end().isNotNull()); |
| 753 | 726 |
| 754 // TODO(hajimehoshi): Checking treeScope is wrong when a node is | 727 // TODO(hajimehoshi): Checking treeScope is wrong when a node is |
| 755 // distributed, but we leave it as it is for backward compatibility. | 728 // distributed, but we leave it as it is for backward compatibility. |
| 756 if (selection.start().anchorNode()->treeScope() == selection.end().anchorNod
e()->treeScope()) | 729 if (selection->start().anchorNode()->treeScope() == selection->end().anchorN
ode()->treeScope()) |
| 757 return selection; | 730 return; |
| 758 | 731 |
| 759 if (selection.isBaseFirst()) { | 732 if (selection->isBaseFirst()) { |
| 760 const Position newEnd = adjustPositionForEnd(selection.end(), selection.
start().computeContainerNode()); | 733 const Position& newEnd = adjustPositionForEnd(selection->end(), selectio
n->start().computeContainerNode()); |
| 761 return VisibleSelection::createWithoutValidation(selection.base(), newEn
d, selection.start(), newEnd, selection.affinity(), selection.isDirectional()); | 734 selection->m_extent = newEnd; |
| 735 selection->m_end = newEnd; |
| 736 return; |
| 762 } | 737 } |
| 763 | 738 |
| 764 const Position newStart = adjustPositionForStart(selection.start(), selectio
n.end().computeContainerNode()); | 739 const Position& newStart = adjustPositionForStart(selection->start(), select
ion->end().computeContainerNode()); |
| 765 return VisibleSelection::createWithoutValidation(selection.base(), newStart,
newStart, selection.end(), selection.affinity(), selection.isDirectional()); | 740 selection->m_extent = newStart; |
| 741 selection->m_start = newStart; |
| 766 } | 742 } |
| 767 | 743 |
| 744 // TODO(yosin): We should move |
| 745 // |SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries()| to |
| 746 // "SelectionAdjuster.cpp" |
| 768 // This function is called twice. The first is called when |m_start| and |m_end| | 747 // This function is called twice. The first is called when |m_start| and |m_end| |
| 769 // or |m_extent| are same, and the second when |m_start| and |m_end| are changed | 748 // or |m_extent| are same, and the second when |m_start| and |m_end| are changed |
| 770 // after downstream/upstream. | 749 // after downstream/upstream. |
| 771 static VisibleSelectionInComposedTree computeSelectionToAvoidCrossingShadowBound
aries(const VisibleSelectionInComposedTree& selection) | 750 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSe
lectionInComposedTree* selection) |
| 772 { | 751 { |
| 773 Node* shadowHostStart = enclosingShadowHostForStart(selection.start()); | 752 Node* const shadowHostStart = enclosingShadowHostForStart(selection->start()
); |
| 774 Node* shadowHostEnd = enclosingShadowHostForEnd(selection.end()); | 753 Node* const shadowHostEnd = enclosingShadowHostForEnd(selection->end()); |
| 775 if (shadowHostStart == shadowHostEnd) | 754 if (shadowHostStart == shadowHostEnd) |
| 776 return selection; | 755 return; |
| 777 | 756 |
| 778 if (selection.isBaseFirst()) { | 757 if (selection->isBaseFirst()) { |
| 779 Node* shadowHost = shadowHostStart ? shadowHostStart : shadowHostEnd; | 758 Node* const shadowHost = shadowHostStart ? shadowHostStart : shadowHostE
nd; |
| 780 const PositionInComposedTree newEnd = adjustPositionInComposedTreeForEnd
(selection.end(), shadowHost); | 759 const PositionInComposedTree& newEnd = adjustPositionInComposedTreeForEn
d(selection->end(), shadowHost); |
| 781 return VisibleSelectionInComposedTree::createWithoutValidation(selection
.base(), newEnd, selection.start(), newEnd, selection.affinity(), selection.isDi
rectional()); | 760 selection->m_extent = newEnd; |
| 761 selection->m_end = newEnd; |
| 762 return; |
| 782 } | 763 } |
| 783 Node* shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; | 764 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; |
| 784 const PositionInComposedTree newStart = adjustPositionInComposedTreeForStart
(selection.start(), shadowHost); | 765 const PositionInComposedTree& newStart = adjustPositionInComposedTreeForStar
t(selection->start(), shadowHost); |
| 785 return VisibleSelectionInComposedTree::createWithoutValidation(selection.bas
e(), newStart, newStart, selection.end(), selection.affinity(), selection.isDire
ctional()); | 766 selection->m_extent = newStart; |
| 767 selection->m_start = newStart; |
| 786 } | 768 } |
| 787 | 769 |
| 788 template <typename Strategy> | 770 template <typename Strategy> |
| 789 void VisibleSelectionTemplate<Strategy>::adjustSelectionToAvoidCrossingShadowBou
ndaries() | 771 void VisibleSelectionTemplate<Strategy>::adjustSelectionToAvoidCrossingShadowBou
ndaries() |
| 790 { | 772 { |
| 791 if (m_base.isNull() || m_start.isNull() || m_base.isNull()) | 773 if (m_base.isNull() || m_start.isNull() || m_base.isNull()) |
| 792 return; | 774 return; |
| 793 *this = computeSelectionToAvoidCrossingShadowBoundaries(*this); | 775 SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(this); |
| 794 } | 776 } |
| 795 | 777 |
| 796 static Element* lowestEditableAncestor(Node* node) | 778 static Element* lowestEditableAncestor(Node* node) |
| 797 { | 779 { |
| 798 while (node) { | 780 while (node) { |
| 799 if (node->hasEditableStyle()) | 781 if (node->hasEditableStyle()) |
| 800 return node->rootEditableElement(); | 782 return node->rootEditableElement(); |
| 801 if (isHTMLBodyElement(*node)) | 783 if (isHTMLBodyElement(*node)) |
| 802 break; | 784 break; |
| 803 node = node->parentNode(); | 785 node = node->parentNode(); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 { | 1129 { |
| 1148 sel.showTreeForThis(); | 1130 sel.showTreeForThis(); |
| 1149 } | 1131 } |
| 1150 | 1132 |
| 1151 void showTree(const blink::VisibleSelectionInComposedTree* sel) | 1133 void showTree(const blink::VisibleSelectionInComposedTree* sel) |
| 1152 { | 1134 { |
| 1153 if (sel) | 1135 if (sel) |
| 1154 sel->showTreeForThis(); | 1136 sel->showTreeForThis(); |
| 1155 } | 1137 } |
| 1156 #endif | 1138 #endif |
| OLD | NEW |