| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/editing/SelectionAdjuster.h" | 27 #include "core/editing/SelectionAdjuster.h" |
| 28 | 28 |
| 29 #include "core/editing/EditingUtilities.h" | 29 #include "core/editing/EditingUtilities.h" |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 // TODO(xiaochengh): Move everything to VisibleSelection.cpp. |
| 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 Node* enclosingShadowHost(Node* node) { | 37 Node* enclosingShadowHost(Node* node) { |
| 36 for (Node* runner = node; runner; | 38 for (Node* runner = node; runner; |
| 37 runner = FlatTreeTraversal::parent(*runner)) { | 39 runner = FlatTreeTraversal::parent(*runner)) { |
| 38 if (isShadowHost(runner)) | 40 if (isShadowHost(runner)) |
| 39 return runner; | 41 return runner; |
| 40 } | 42 } |
| 41 return nullptr; | 43 return nullptr; |
| 42 } | 44 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 148 } |
| 147 | 149 |
| 148 if (Node* firstChild = treeScope.rootNode().firstChild()) | 150 if (Node* firstChild = treeScope.rootNode().firstChild()) |
| 149 return Position::beforeNode(firstChild); | 151 return Position::beforeNode(firstChild); |
| 150 | 152 |
| 151 return Position(); | 153 return Position(); |
| 152 } | 154 } |
| 153 | 155 |
| 154 } // namespace | 156 } // namespace |
| 155 | 157 |
| 156 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries( | 158 std::pair<AdjustDirection, Position> adjustmentToAvoidCrossingShadowBoundaries( |
| 157 VisibleSelection* selection) { | 159 const VisibleSelection& selection) { |
| 158 // Note: |m_selectionType| isn't computed yet. | 160 // Note: |m_selectionType| isn't computed yet. |
| 159 DCHECK(selection->base().isNotNull()); | 161 DCHECK(selection.base().isNotNull()); |
| 160 DCHECK(selection->extent().isNotNull()); | 162 DCHECK(selection.extent().isNotNull()); |
| 161 DCHECK(selection->start().isNotNull()); | 163 DCHECK(selection.start().isNotNull()); |
| 162 DCHECK(selection->end().isNotNull()); | 164 DCHECK(selection.end().isNotNull()); |
| 163 | 165 |
| 164 // TODO(hajimehoshi): Checking treeScope is wrong when a node is | 166 // TODO(hajimehoshi): Checking treeScope is wrong when a node is |
| 165 // distributed, but we leave it as it is for backward compatibility. | 167 // distributed, but we leave it as it is for backward compatibility. |
| 166 if (selection->start().anchorNode()->treeScope() == | 168 if (selection.start().anchorNode()->treeScope() == |
| 167 selection->end().anchorNode()->treeScope()) | 169 selection.end().anchorNode()->treeScope()) |
| 168 return; | 170 return std::make_pair(AdjustDirection::kAdjustNone, Position()); |
| 169 | 171 |
| 170 if (selection->isBaseFirst()) { | 172 if (selection.isBaseFirst()) { |
| 171 const Position& newEnd = adjustPositionForEnd( | 173 const Position& newEnd = adjustPositionForEnd( |
| 172 selection->end(), selection->start().computeContainerNode()); | 174 selection.end(), selection.start().computeContainerNode()); |
| 173 selection->m_extent = newEnd; | 175 return std::make_pair(AdjustDirection::kAdjustEnd, newEnd); |
| 174 selection->m_end = newEnd; | |
| 175 return; | |
| 176 } | 176 } |
| 177 | 177 |
| 178 const Position& newStart = adjustPositionForStart( | 178 const Position& newStart = adjustPositionForStart( |
| 179 selection->start(), selection->end().computeContainerNode()); | 179 selection.start(), selection.end().computeContainerNode()); |
| 180 selection->m_extent = newStart; | 180 return std::make_pair(AdjustDirection::kAdjustStart, newStart); |
| 181 selection->m_start = newStart; | |
| 182 } | 181 } |
| 183 | 182 |
| 184 // This function is called twice. The first is called when |m_start| and |m_end| | 183 // This function is called twice. The first is called when |m_start| and |m_end| |
| 185 // or |m_extent| are same, and the second when |m_start| and |m_end| are changed | 184 // or |m_extent| are same, and the second when |m_start| and |m_end| are changed |
| 186 // after downstream/upstream. | 185 // after downstream/upstream. |
| 187 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries( | 186 std::pair<AdjustDirection, PositionInFlatTree> |
| 188 VisibleSelectionInFlatTree* selection) { | 187 adjustmentToAvoidCrossingShadowBoundaries( |
| 189 Node* const shadowHostStart = enclosingShadowHostForStart(selection->start()); | 188 const VisibleSelectionInFlatTree& selection) { |
| 190 Node* const shadowHostEnd = enclosingShadowHostForEnd(selection->end()); | 189 Node* const shadowHostStart = enclosingShadowHostForStart(selection.start()); |
| 190 Node* const shadowHostEnd = enclosingShadowHostForEnd(selection.end()); |
| 191 if (shadowHostStart == shadowHostEnd) | 191 if (shadowHostStart == shadowHostEnd) |
| 192 return; | 192 return std::make_pair(AdjustDirection::kAdjustNone, PositionInFlatTree()); |
| 193 | 193 |
| 194 if (selection->isBaseFirst()) { | 194 if (selection.isBaseFirst()) { |
| 195 Node* const shadowHost = shadowHostStart ? shadowHostStart : shadowHostEnd; | 195 Node* const shadowHost = shadowHostStart ? shadowHostStart : shadowHostEnd; |
| 196 const PositionInFlatTree& newEnd = | 196 const PositionInFlatTree& newEnd = |
| 197 adjustPositionInFlatTreeForEnd(selection->end(), shadowHost); | 197 adjustPositionInFlatTreeForEnd(selection.end(), shadowHost); |
| 198 selection->m_extent = newEnd; | 198 return std::make_pair(AdjustDirection::kAdjustEnd, newEnd); |
| 199 selection->m_end = newEnd; | |
| 200 return; | |
| 201 } | 199 } |
| 202 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; | 200 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; |
| 203 const PositionInFlatTree& newStart = | 201 const PositionInFlatTree& newStart = |
| 204 adjustPositionInFlatTreeForStart(selection->start(), shadowHost); | 202 adjustPositionInFlatTreeForStart(selection.start(), shadowHost); |
| 205 selection->m_extent = newStart; | 203 return std::make_pair(AdjustDirection::kAdjustStart, newStart); |
| 206 selection->m_start = newStart; | |
| 207 } | 204 } |
| 208 | 205 |
| 209 } // namespace blink | 206 } // namespace blink |
| OLD | NEW |