OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
4 * reserved. | 4 * reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 m_frameSelection->computeVisibleSelectionInFlatTree(); | 116 m_frameSelection->computeVisibleSelectionInFlatTree(); |
117 | 117 |
118 // Skip if pending VisibilePositions became invalid before we reach here. | 118 // Skip if pending VisibilePositions became invalid before we reach here. |
119 if (!isSelectionInDocument(originalSelection, layoutView.document())) | 119 if (!isSelectionInDocument(originalSelection, layoutView.document())) |
120 return; | 120 return; |
121 | 121 |
122 // Construct a new VisibleSolution, since visibleSelection() is not | 122 // Construct a new VisibleSolution, since visibleSelection() is not |
123 // necessarily valid, and the following steps assume a valid selection. See | 123 // necessarily valid, and the following steps assume a valid selection. See |
124 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | 124 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and |
125 // <rdar://problem/10232866>. | 125 // <rdar://problem/10232866>. |
126 const SelectionInFlatTree selection = calcVisibleSelection(originalSelection); | 126 const VisibleSelectionInFlatTree& selection = |
127 const VisibleSelectionInFlatTree& visibleSelection = | 127 createVisibleSelection(calcVisibleSelection(originalSelection)); |
128 createVisibleSelection(selection); | |
129 | 128 |
130 if (!visibleSelection.isRange() || !selectionHasFocus(selection)) { | 129 if (!selection.isRange()) { |
131 layoutView.clearSelection(); | 130 layoutView.clearSelection(); |
132 return; | 131 return; |
133 } | 132 } |
134 | 133 |
135 // Use the rightmost candidate for the start of the selection, and the | 134 // Use the rightmost candidate for the start of the selection, and the |
136 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 135 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
137 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 136 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
138 // If we pass [foo, 3] as the start of the selection, the selection painting | 137 // If we pass [foo, 3] as the start of the selection, the selection painting |
139 // code will think that content on the line containing 'foo' is selected | 138 // code will think that content on the line containing 'foo' is selected |
140 // and will fill the gap before 'bar'. | 139 // and will fill the gap before 'bar'. |
141 PositionInFlatTree startPos = visibleSelection.start(); | 140 PositionInFlatTree startPos = selection.start(); |
142 PositionInFlatTree candidate = mostForwardCaretPosition(startPos); | 141 PositionInFlatTree candidate = mostForwardCaretPosition(startPos); |
143 if (isVisuallyEquivalentCandidate(candidate)) | 142 if (isVisuallyEquivalentCandidate(candidate)) |
144 startPos = candidate; | 143 startPos = candidate; |
145 PositionInFlatTree endPos = visibleSelection.end(); | 144 PositionInFlatTree endPos = selection.end(); |
146 candidate = mostBackwardCaretPosition(endPos); | 145 candidate = mostBackwardCaretPosition(endPos); |
147 if (isVisuallyEquivalentCandidate(candidate)) | 146 if (isVisuallyEquivalentCandidate(candidate)) |
148 endPos = candidate; | 147 endPos = candidate; |
149 | 148 |
150 // We can get into a state where the selection endpoints map to the same | 149 // We can get into a state where the selection endpoints map to the same |
151 // |VisiblePosition| when a selection is deleted because we don't yet notify | 150 // |VisiblePosition| when a selection is deleted because we don't yet notify |
152 // the |FrameSelection| of text removal. | 151 // the |FrameSelection| of text removal. |
153 if (startPos.isNull() || endPos.isNull() || | 152 if (startPos.isNull() || endPos.isNull() || |
154 visibleSelection.visibleStart().deepEquivalent() == | 153 selection.visibleStart().deepEquivalent() == |
155 visibleSelection.visibleEnd().deepEquivalent()) | 154 selection.visibleEnd().deepEquivalent()) |
156 return; | 155 return; |
157 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); | 156 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); |
158 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); | 157 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); |
159 if (!startLayoutObject || !endLayoutObject) | 158 if (!startLayoutObject || !endLayoutObject) |
160 return; | 159 return; |
161 DCHECK(layoutView == startLayoutObject->view()); | 160 DCHECK(layoutView == startLayoutObject->view()); |
162 DCHECK(layoutView == endLayoutObject->view()); | 161 DCHECK(layoutView == endLayoutObject->view()); |
163 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), | 162 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), |
164 endLayoutObject, endPos.computeEditingOffset()); | 163 endLayoutObject, endPos.computeEditingOffset()); |
165 } | 164 } |
166 | 165 |
167 DEFINE_TRACE(PendingSelection) { | 166 DEFINE_TRACE(PendingSelection) { |
168 visitor->trace(m_frameSelection); | 167 visitor->trace(m_frameSelection); |
169 } | 168 } |
170 | 169 |
171 } // namespace blink | 170 } // namespace blink |
OLD | NEW |