Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/core/editing/PendingSelection.cpp

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Skip isSelectionInDocument(). Use SelectionInFlatTree. Don't change EditorCommand. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 const LocalFrame& frame = *layoutView.document().frame();
131 if (!visibleSelection.isRange() || !selectionHasFocus(frame, selection)) {
130 layoutView.clearSelection(); 132 layoutView.clearSelection();
131 return; 133 return;
132 } 134 }
133 135
134 // Use the rightmost candidate for the start of the selection, and the 136 // 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>. 137 // 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. 138 // 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 139 // 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 140 // code will think that content on the line containing 'foo' is selected
139 // and will fill the gap before 'bar'. 141 // and will fill the gap before 'bar'.
140 PositionInFlatTree startPos = selection.start(); 142 PositionInFlatTree startPos = visibleSelection.start();
141 PositionInFlatTree candidate = mostForwardCaretPosition(startPos); 143 PositionInFlatTree candidate = mostForwardCaretPosition(startPos);
142 if (isVisuallyEquivalentCandidate(candidate)) 144 if (isVisuallyEquivalentCandidate(candidate))
143 startPos = candidate; 145 startPos = candidate;
144 PositionInFlatTree endPos = selection.end(); 146 PositionInFlatTree endPos = visibleSelection.end();
145 candidate = mostBackwardCaretPosition(endPos); 147 candidate = mostBackwardCaretPosition(endPos);
146 if (isVisuallyEquivalentCandidate(candidate)) 148 if (isVisuallyEquivalentCandidate(candidate))
147 endPos = candidate; 149 endPos = candidate;
148 150
149 // We can get into a state where the selection endpoints map to the same 151 // 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 152 // |VisiblePosition| when a selection is deleted because we don't yet notify
151 // the |FrameSelection| of text removal. 153 // the |FrameSelection| of text removal.
152 if (startPos.isNull() || endPos.isNull() || 154 if (startPos.isNull() || endPos.isNull() ||
153 selection.visibleStart().deepEquivalent() == 155 visibleSelection.visibleStart().deepEquivalent() ==
154 selection.visibleEnd().deepEquivalent()) 156 visibleSelection.visibleEnd().deepEquivalent())
155 return; 157 return;
156 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); 158 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject();
157 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); 159 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject();
158 if (!startLayoutObject || !endLayoutObject) 160 if (!startLayoutObject || !endLayoutObject)
159 return; 161 return;
160 DCHECK(layoutView == startLayoutObject->view()); 162 DCHECK(layoutView == startLayoutObject->view());
161 DCHECK(layoutView == endLayoutObject->view()); 163 DCHECK(layoutView == endLayoutObject->view());
162 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), 164 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(),
163 endLayoutObject, endPos.computeEditingOffset()); 165 endLayoutObject, endPos.computeEditingOffset());
164 } 166 }
165 167
166 DEFINE_TRACE(PendingSelection) { 168 DEFINE_TRACE(PendingSelection) {
167 visitor->trace(m_frameSelection); 169 visitor->trace(m_frameSelection);
168 } 170 }
169 171
170 } // namespace blink 172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698