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