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

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: Move isSelectionInDocument() and selectionHasFocus() to EditingUtilities 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 20 matching lines...) Expand all
31 31
32 namespace blink { 32 namespace blink {
33 33
34 PendingSelection::PendingSelection(FrameSelection& frameSelection) 34 PendingSelection::PendingSelection(FrameSelection& frameSelection)
35 : m_frameSelection(&frameSelection), m_hasPendingSelection(false) {} 35 : m_frameSelection(&frameSelection), m_hasPendingSelection(false) {}
36 36
37 const VisibleSelection& PendingSelection::visibleSelection() const { 37 const VisibleSelection& PendingSelection::visibleSelection() const {
38 return m_frameSelection->computeVisibleSelectionInDOMTree(); 38 return m_frameSelection->computeVisibleSelectionInDOMTree();
39 } 39 }
40 40
41 static bool isSelectionInDocument(
42 const VisibleSelectionInFlatTree& visibleSelection,
43 const Document& document) {
44 const PositionInFlatTree& start = visibleSelection.start();
45 if (start.isNotNull() &&
46 (!start.isConnected() || start.document() != document))
47 return false;
48 const PositionInFlatTree& end = visibleSelection.end();
49 if (end.isNotNull() && (!end.isConnected() || end.document() != document))
50 return false;
51 const PositionInFlatTree extent = visibleSelection.extent();
52 if (extent.isNotNull() &&
53 (!extent.isConnected() || extent.document() != document))
54 return false;
55 return true;
56 }
57
58 SelectionInFlatTree PendingSelection::calcVisibleSelection( 41 SelectionInFlatTree PendingSelection::calcVisibleSelection(
59 const VisibleSelectionInFlatTree& originalSelection) const { 42 const VisibleSelectionInFlatTree& originalSelection) const {
60 const PositionInFlatTree& start = originalSelection.start(); 43 const PositionInFlatTree& start = originalSelection.start();
61 const PositionInFlatTree& end = originalSelection.end(); 44 const PositionInFlatTree& end = originalSelection.end();
62 SelectionType selectionType = originalSelection.getSelectionType(); 45 SelectionType selectionType = originalSelection.getSelectionType();
63 const TextAffinity affinity = originalSelection.affinity(); 46 const TextAffinity affinity = originalSelection.affinity();
64 47
65 bool paintBlockCursor = 48 bool paintBlockCursor =
66 m_frameSelection->shouldShowBlockCursor() && 49 m_frameSelection->shouldShowBlockCursor() &&
67 selectionType == SelectionType::CaretSelection && 50 selectionType == SelectionType::CaretSelection &&
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if (!isSelectionInDocument(originalSelection, layoutView.document())) 102 if (!isSelectionInDocument(originalSelection, layoutView.document()))
120 return; 103 return;
121 104
122 // Construct a new VisibleSolution, since visibleSelection() is not 105 // Construct a new VisibleSolution, since visibleSelection() is not
123 // necessarily valid, and the following steps assume a valid selection. See 106 // necessarily valid, and the following steps assume a valid selection. See
124 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and 107 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and
125 // <rdar://problem/10232866>. 108 // <rdar://problem/10232866>.
126 const VisibleSelectionInFlatTree& selection = 109 const VisibleSelectionInFlatTree& selection =
127 createVisibleSelection(calcVisibleSelection(originalSelection)); 110 createVisibleSelection(calcVisibleSelection(originalSelection));
128 111
129 if (!selection.isRange()) { 112 const LocalFrame& frame = *layoutView.document().frame();
113 if (!selection.isRange() || !selectionHasFocus(frame)) {
130 layoutView.clearSelection(); 114 layoutView.clearSelection();
131 return; 115 return;
132 } 116 }
133 117
134 // Use the rightmost candidate for the start of the selection, and the 118 // 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>. 119 // 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. 120 // 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 121 // 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 122 // code will think that content on the line containing 'foo' is selected
139 // and will fill the gap before 'bar'. 123 // and will fill the gap before 'bar'.
(...skipping 21 matching lines...) Expand all
161 DCHECK(layoutView == endLayoutObject->view()); 145 DCHECK(layoutView == endLayoutObject->view());
162 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), 146 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(),
163 endLayoutObject, endPos.computeEditingOffset()); 147 endLayoutObject, endPos.computeEditingOffset());
164 } 148 }
165 149
166 DEFINE_TRACE(PendingSelection) { 150 DEFINE_TRACE(PendingSelection) {
167 visitor->trace(m_frameSelection); 151 visitor->trace(m_frameSelection);
168 } 152 }
169 153
170 } // namespace blink 154 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698