| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // We use |firstChild|'s after instead of beforeAllChildren for backward | 92 // We use |firstChild|'s after instead of beforeAllChildren for backward |
| 93 // compatibility. The positions are same but the anchors would be different, | 93 // compatibility. The positions are same but the anchors would be different, |
| 94 // and selection painting uses anchor nodes. | 94 // and selection painting uses anchor nodes. |
| 95 if (Node* firstChild = FlatTreeTraversal::firstChild(*shadowHost)) | 95 if (Node* firstChild = FlatTreeTraversal::firstChild(*shadowHost)) |
| 96 return PositionInFlatTree::beforeNode(firstChild); | 96 return PositionInFlatTree::beforeNode(firstChild); |
| 97 return PositionInFlatTree(); | 97 return PositionInFlatTree(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 Position adjustPositionForEnd(const Position& currentPosition, Node* startContai
nerNode) | 100 Position adjustPositionForEnd(const Position& currentPosition, Node* startContai
nerNode) |
| 101 { | 101 { |
| 102 TreeScope& treeScope = startContainerNode->treeScope(); | 102 TreeScope& treeScope = startContainerNode->treeScopeOrDocument(); |
| 103 | 103 |
| 104 ASSERT(currentPosition.computeContainerNode()->treeScope() != treeScope); | 104 ASSERT(currentPosition.computeContainerNode()->treeScopeOrDocument() != tree
Scope); |
| 105 | 105 |
| 106 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo
ntainerNode())) { | 106 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo
ntainerNode())) { |
| 107 if (ancestor->contains(startContainerNode)) | 107 if (ancestor->contains(startContainerNode)) |
| 108 return positionAfterNode(ancestor); | 108 return positionAfterNode(ancestor); |
| 109 return positionBeforeNode(ancestor); | 109 return positionBeforeNode(ancestor); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (Node* lastChild = treeScope.rootNode().lastChild()) | 112 if (Node* lastChild = treeScope.rootNode().lastChild()) |
| 113 return positionAfterNode(lastChild); | 113 return positionAfterNode(lastChild); |
| 114 | 114 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 // We use |lastChild|'s after instead of afterAllChildren for backward | 126 // We use |lastChild|'s after instead of afterAllChildren for backward |
| 127 // compatibility. The positions are same but the anchors would be different, | 127 // compatibility. The positions are same but the anchors would be different, |
| 128 // and selection painting uses anchor nodes. | 128 // and selection painting uses anchor nodes. |
| 129 if (Node* lastChild = FlatTreeTraversal::lastChild(*shadowHost)) | 129 if (Node* lastChild = FlatTreeTraversal::lastChild(*shadowHost)) |
| 130 return PositionInFlatTree::afterNode(lastChild); | 130 return PositionInFlatTree::afterNode(lastChild); |
| 131 return PositionInFlatTree(); | 131 return PositionInFlatTree(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 Position adjustPositionForStart(const Position& currentPosition, Node* endContai
nerNode) | 134 Position adjustPositionForStart(const Position& currentPosition, Node* endContai
nerNode) |
| 135 { | 135 { |
| 136 TreeScope& treeScope = endContainerNode->treeScope(); | 136 TreeScope& treeScope = endContainerNode->treeScopeOrDocument(); |
| 137 | 137 |
| 138 ASSERT(currentPosition.computeContainerNode()->treeScope() != treeScope); | 138 ASSERT(currentPosition.computeContainerNode()->treeScopeOrDocument() != tree
Scope); |
| 139 | 139 |
| 140 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo
ntainerNode())) { | 140 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo
ntainerNode())) { |
| 141 if (ancestor->contains(endContainerNode)) | 141 if (ancestor->contains(endContainerNode)) |
| 142 return positionBeforeNode(ancestor); | 142 return positionBeforeNode(ancestor); |
| 143 return positionAfterNode(ancestor); | 143 return positionAfterNode(ancestor); |
| 144 } | 144 } |
| 145 | 145 |
| 146 if (Node* firstChild = treeScope.rootNode().firstChild()) | 146 if (Node* firstChild = treeScope.rootNode().firstChild()) |
| 147 return positionBeforeNode(firstChild); | 147 return positionBeforeNode(firstChild); |
| 148 | 148 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 selectionInFlatTree->m_end = position1; | 180 selectionInFlatTree->m_end = position1; |
| 181 } | 181 } |
| 182 selectionInFlatTree->updateSelectionType(); | 182 selectionInFlatTree->updateSelectionType(); |
| 183 selectionInFlatTree->didChange(); | 183 selectionInFlatTree->didChange(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 static bool isCrossingShadowBoundaries(const VisibleSelectionInFlatTree& selecti
on) | 186 static bool isCrossingShadowBoundaries(const VisibleSelectionInFlatTree& selecti
on) |
| 187 { | 187 { |
| 188 if (!selection.isRange()) | 188 if (!selection.isRange()) |
| 189 return false; | 189 return false; |
| 190 TreeScope& treeScope = selection.base().anchorNode()->treeScope(); | 190 TreeScope& treeScope = selection.base().anchorNode()->treeScopeOrDocument(); |
| 191 return selection.extent().anchorNode()->treeScope() != treeScope | 191 return selection.extent().anchorNode()->treeScopeOrDocument() != treeScope |
| 192 || selection.start().anchorNode()->treeScope() != treeScope | 192 || selection.start().anchorNode()->treeScopeOrDocument() != treeScope |
| 193 || selection.end().anchorNode()->treeScope() != treeScope; | 193 || selection.end().anchorNode()->treeScopeOrDocument() != treeScope; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void SelectionAdjuster::adjustSelectionInDOMTree(VisibleSelection* selection, co
nst VisibleSelectionInFlatTree& selectionInFlatTree) | 196 void SelectionAdjuster::adjustSelectionInDOMTree(VisibleSelection* selection, co
nst VisibleSelectionInFlatTree& selectionInFlatTree) |
| 197 { | 197 { |
| 198 if (selectionInFlatTree.isNone()) { | 198 if (selectionInFlatTree.isNone()) { |
| 199 *selection = VisibleSelection(); | 199 *selection = VisibleSelection(); |
| 200 return; | 200 return; |
| 201 } | 201 } |
| 202 | 202 |
| 203 const Position& base = toPositionInDOMTree(selectionInFlatTree.base()); | 203 const Position& base = toPositionInDOMTree(selectionInFlatTree.base()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 231 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSe
lection* selection) | 231 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSe
lection* selection) |
| 232 { | 232 { |
| 233 // Note: |m_selectionType| isn't computed yet. | 233 // Note: |m_selectionType| isn't computed yet. |
| 234 ASSERT(selection->base().isNotNull()); | 234 ASSERT(selection->base().isNotNull()); |
| 235 ASSERT(selection->extent().isNotNull()); | 235 ASSERT(selection->extent().isNotNull()); |
| 236 ASSERT(selection->start().isNotNull()); | 236 ASSERT(selection->start().isNotNull()); |
| 237 ASSERT(selection->end().isNotNull()); | 237 ASSERT(selection->end().isNotNull()); |
| 238 | 238 |
| 239 // TODO(hajimehoshi): Checking treeScope is wrong when a node is | 239 // TODO(hajimehoshi): Checking treeScope is wrong when a node is |
| 240 // distributed, but we leave it as it is for backward compatibility. | 240 // distributed, but we leave it as it is for backward compatibility. |
| 241 if (selection->start().anchorNode()->treeScope() == selection->end().anchorN
ode()->treeScope()) | 241 if (selection->start().anchorNode()->treeScopeOrDocument() == selection->end
().anchorNode()->treeScopeOrDocument()) |
| 242 return; | 242 return; |
| 243 | 243 |
| 244 if (selection->isBaseFirst()) { | 244 if (selection->isBaseFirst()) { |
| 245 const Position& newEnd = adjustPositionForEnd(selection->end(), selectio
n->start().computeContainerNode()); | 245 const Position& newEnd = adjustPositionForEnd(selection->end(), selectio
n->start().computeContainerNode()); |
| 246 selection->m_extent = newEnd; | 246 selection->m_extent = newEnd; |
| 247 selection->m_end = newEnd; | 247 selection->m_end = newEnd; |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 | 250 |
| 251 const Position& newStart = adjustPositionForStart(selection->start(), select
ion->end().computeContainerNode()); | 251 const Position& newStart = adjustPositionForStart(selection->start(), select
ion->end().computeContainerNode()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 270 selection->m_end = newEnd; | 270 selection->m_end = newEnd; |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; | 273 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; |
| 274 const PositionInFlatTree& newStart = adjustPositionInFlatTreeForStart(select
ion->start(), shadowHost); | 274 const PositionInFlatTree& newStart = adjustPositionInFlatTreeForStart(select
ion->start(), shadowHost); |
| 275 selection->m_extent = newStart; | 275 selection->m_extent = newStart; |
| 276 selection->m_start = newStart; | 276 selection->m_start = newStart; |
| 277 } | 277 } |
| 278 | 278 |
| 279 } // namespace blink | 279 } // namespace blink |
| OLD | NEW |