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 VisibleSelectionInFlatTree& selection = | 126 const SelectionInFlatTree selection = calcVisibleSelection(originalSelection); |
127 createVisibleSelection(calcVisibleSelection(originalSelection)); | 127 const VisibleSelectionInFlatTree& visibleSelection = |
| 128 createVisibleSelection(selection); |
128 | 129 |
129 if (!selection.isRange()) { | 130 if (!visibleSelection.isRange() || !selectionHasFocus(selection)) { |
130 layoutView.clearSelection(); | 131 layoutView.clearSelection(); |
131 return; | 132 return; |
132 } | 133 } |
133 | 134 |
134 // Use the rightmost candidate for the start of the selection, and the | 135 // Use the rightmost candidate for the start of the selection, and the |
135 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 136 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
136 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 137 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
137 // If we pass [foo, 3] as the start of the selection, the selection painting | 138 // If we pass [foo, 3] as the start of the selection, the selection painting |
138 // code will think that content on the line containing 'foo' is selected | 139 // code will think that content on the line containing 'foo' is selected |
139 // and will fill the gap before 'bar'. | 140 // and will fill the gap before 'bar'. |
140 PositionInFlatTree startPos = selection.start(); | 141 PositionInFlatTree startPos = visibleSelection.start(); |
141 PositionInFlatTree candidate = mostForwardCaretPosition(startPos); | 142 PositionInFlatTree candidate = mostForwardCaretPosition(startPos); |
142 if (isVisuallyEquivalentCandidate(candidate)) | 143 if (isVisuallyEquivalentCandidate(candidate)) |
143 startPos = candidate; | 144 startPos = candidate; |
144 PositionInFlatTree endPos = selection.end(); | 145 PositionInFlatTree endPos = visibleSelection.end(); |
145 candidate = mostBackwardCaretPosition(endPos); | 146 candidate = mostBackwardCaretPosition(endPos); |
146 if (isVisuallyEquivalentCandidate(candidate)) | 147 if (isVisuallyEquivalentCandidate(candidate)) |
147 endPos = candidate; | 148 endPos = candidate; |
148 | 149 |
149 // We can get into a state where the selection endpoints map to the same | 150 // We can get into a state where the selection endpoints map to the same |
150 // |VisiblePosition| when a selection is deleted because we don't yet notify | 151 // |VisiblePosition| when a selection is deleted because we don't yet notify |
151 // the |FrameSelection| of text removal. | 152 // the |FrameSelection| of text removal. |
152 if (startPos.isNull() || endPos.isNull() || | 153 if (startPos.isNull() || endPos.isNull() || |
153 selection.visibleStart().deepEquivalent() == | 154 visibleSelection.visibleStart().deepEquivalent() == |
154 selection.visibleEnd().deepEquivalent()) | 155 visibleSelection.visibleEnd().deepEquivalent()) |
155 return; | 156 return; |
156 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); | 157 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); |
157 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); | 158 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); |
158 if (!startLayoutObject || !endLayoutObject) | 159 if (!startLayoutObject || !endLayoutObject) |
159 return; | 160 return; |
160 DCHECK(layoutView == startLayoutObject->view()); | 161 DCHECK(layoutView == startLayoutObject->view()); |
161 DCHECK(layoutView == endLayoutObject->view()); | 162 DCHECK(layoutView == endLayoutObject->view()); |
162 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), | 163 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), |
163 endLayoutObject, endPos.computeEditingOffset()); | 164 endLayoutObject, endPos.computeEditingOffset()); |
164 } | 165 } |
165 | 166 |
166 DEFINE_TRACE(PendingSelection) { | 167 DEFINE_TRACE(PendingSelection) { |
167 visitor->trace(m_frameSelection); | 168 visitor->trace(m_frameSelection); |
168 } | 169 } |
169 | 170 |
170 } // namespace blink | 171 } // namespace blink |
OLD | NEW |