| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (!IsEnclosedBy(position, *shadow_host)) | 77 if (!IsEnclosedBy(position, *shadow_host)) |
| 78 return nullptr; | 78 return nullptr; |
| 79 return IsSelectionBoundary(*shadow_host) ? shadow_host : nullptr; | 79 return IsSelectionBoundary(*shadow_host) ? shadow_host : nullptr; |
| 80 } | 80 } |
| 81 | 81 |
| 82 PositionInFlatTree AdjustPositionInFlatTreeForStart( | 82 PositionInFlatTree AdjustPositionInFlatTreeForStart( |
| 83 const PositionInFlatTree& position, | 83 const PositionInFlatTree& position, |
| 84 Node* shadow_host) { | 84 Node* shadow_host) { |
| 85 if (IsEnclosedBy(position, *shadow_host)) { | 85 if (IsEnclosedBy(position, *shadow_host)) { |
| 86 if (position.IsBeforeChildren()) | 86 if (position.IsBeforeChildren()) |
| 87 return PositionInFlatTree::BeforeNode(shadow_host); | 87 return PositionInFlatTree::BeforeNode(*shadow_host); |
| 88 return PositionInFlatTree::AfterNode(shadow_host); | 88 return PositionInFlatTree::AfterNode(shadow_host); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // We use |firstChild|'s after instead of beforeAllChildren for backward | 91 // We use |firstChild|'s after instead of beforeAllChildren for backward |
| 92 // compatibility. The positions are same but the anchors would be different, | 92 // compatibility. The positions are same but the anchors would be different, |
| 93 // and selection painting uses anchor nodes. | 93 // and selection painting uses anchor nodes. |
| 94 if (Node* first_child = FlatTreeTraversal::FirstChild(*shadow_host)) | 94 if (Node* first_child = FlatTreeTraversal::FirstChild(*shadow_host)) |
| 95 return PositionInFlatTree::BeforeNode(first_child); | 95 return PositionInFlatTree::BeforeNode(*first_child); |
| 96 return PositionInFlatTree(); | 96 return PositionInFlatTree(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 Position AdjustPositionForEnd(const Position& current_position, | 99 Position AdjustPositionForEnd(const Position& current_position, |
| 100 Node* start_container_node) { | 100 Node* start_container_node) { |
| 101 TreeScope& tree_scope = start_container_node->GetTreeScope(); | 101 TreeScope& tree_scope = start_container_node->GetTreeScope(); |
| 102 | 102 |
| 103 DCHECK(current_position.ComputeContainerNode()->GetTreeScope() != tree_scope); | 103 DCHECK(current_position.ComputeContainerNode()->GetTreeScope() != tree_scope); |
| 104 | 104 |
| 105 if (Node* ancestor = tree_scope.AncestorInThisScope( | 105 if (Node* ancestor = tree_scope.AncestorInThisScope( |
| 106 current_position.ComputeContainerNode())) { | 106 current_position.ComputeContainerNode())) { |
| 107 if (ancestor->contains(start_container_node)) | 107 if (ancestor->contains(start_container_node)) |
| 108 return Position::AfterNode(ancestor); | 108 return Position::AfterNode(ancestor); |
| 109 return Position::BeforeNode(ancestor); | 109 return Position::BeforeNode(*ancestor); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (Node* last_child = tree_scope.RootNode().lastChild()) | 112 if (Node* last_child = tree_scope.RootNode().lastChild()) |
| 113 return Position::AfterNode(last_child); | 113 return Position::AfterNode(last_child); |
| 114 | 114 |
| 115 return Position(); | 115 return Position(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 PositionInFlatTree AdjustPositionInFlatTreeForEnd( | 118 PositionInFlatTree AdjustPositionInFlatTreeForEnd( |
| 119 const PositionInFlatTree& position, | 119 const PositionInFlatTree& position, |
| 120 Node* shadow_host) { | 120 Node* shadow_host) { |
| 121 if (IsEnclosedBy(position, *shadow_host)) { | 121 if (IsEnclosedBy(position, *shadow_host)) { |
| 122 if (position.IsAfterChildren()) | 122 if (position.IsAfterChildren()) |
| 123 return PositionInFlatTree::AfterNode(shadow_host); | 123 return PositionInFlatTree::AfterNode(shadow_host); |
| 124 return PositionInFlatTree::BeforeNode(shadow_host); | 124 return PositionInFlatTree::BeforeNode(*shadow_host); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // We use |lastChild|'s after instead of afterAllChildren for backward | 127 // We use |lastChild|'s after instead of afterAllChildren for backward |
| 128 // compatibility. The positions are same but the anchors would be different, | 128 // compatibility. The positions are same but the anchors would be different, |
| 129 // and selection painting uses anchor nodes. | 129 // and selection painting uses anchor nodes. |
| 130 if (Node* last_child = FlatTreeTraversal::LastChild(*shadow_host)) | 130 if (Node* last_child = FlatTreeTraversal::LastChild(*shadow_host)) |
| 131 return PositionInFlatTree::AfterNode(last_child); | 131 return PositionInFlatTree::AfterNode(last_child); |
| 132 return PositionInFlatTree(); | 132 return PositionInFlatTree(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 Position AdjustPositionForStart(const Position& current_position, | 135 Position AdjustPositionForStart(const Position& current_position, |
| 136 Node* end_container_node) { | 136 Node* end_container_node) { |
| 137 TreeScope& tree_scope = end_container_node->GetTreeScope(); | 137 TreeScope& tree_scope = end_container_node->GetTreeScope(); |
| 138 | 138 |
| 139 DCHECK(current_position.ComputeContainerNode()->GetTreeScope() != tree_scope); | 139 DCHECK(current_position.ComputeContainerNode()->GetTreeScope() != tree_scope); |
| 140 | 140 |
| 141 if (Node* ancestor = tree_scope.AncestorInThisScope( | 141 if (Node* ancestor = tree_scope.AncestorInThisScope( |
| 142 current_position.ComputeContainerNode())) { | 142 current_position.ComputeContainerNode())) { |
| 143 if (ancestor->contains(end_container_node)) | 143 if (ancestor->contains(end_container_node)) |
| 144 return Position::BeforeNode(ancestor); | 144 return Position::BeforeNode(*ancestor); |
| 145 return Position::AfterNode(ancestor); | 145 return Position::AfterNode(ancestor); |
| 146 } | 146 } |
| 147 | 147 |
| 148 if (Node* first_child = tree_scope.RootNode().firstChild()) | 148 if (Node* first_child = tree_scope.RootNode().firstChild()) |
| 149 return Position::BeforeNode(first_child); | 149 return Position::BeforeNode(*first_child); |
| 150 | 150 |
| 151 return Position(); | 151 return Position(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace | 154 } // namespace |
| 155 | 155 |
| 156 void SelectionAdjuster::AdjustSelectionToAvoidCrossingShadowBoundaries( | 156 void SelectionAdjuster::AdjustSelectionToAvoidCrossingShadowBoundaries( |
| 157 VisibleSelection* selection) { | 157 VisibleSelection* selection) { |
| 158 // Note: |m_selectionType| isn't computed yet. | 158 // Note: |m_selectionType| isn't computed yet. |
| 159 DCHECK(selection->Base().IsNotNull()); | 159 DCHECK(selection->Base().IsNotNull()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 203 } |
| 204 Node* const shadow_host = | 204 Node* const shadow_host = |
| 205 shadow_host_end ? shadow_host_end : shadow_host_start; | 205 shadow_host_end ? shadow_host_end : shadow_host_start; |
| 206 const PositionInFlatTree& new_start = | 206 const PositionInFlatTree& new_start = |
| 207 AdjustPositionInFlatTreeForStart(selection->Start(), shadow_host); | 207 AdjustPositionInFlatTreeForStart(selection->Start(), shadow_host); |
| 208 selection->extent_ = new_start; | 208 selection->extent_ = new_start; |
| 209 selection->start_ = new_start; | 209 selection->start_ = new_start; |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace blink | 212 } // namespace blink |
| OLD | NEW |