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

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

Issue 2653523003: Make DOMSelection cache Range (Closed)
Patch Set: update Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/DOMSelection.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/editing/SelectionEditor.h" 26 #include "core/editing/SelectionEditor.h"
27 27
28 #include "core/editing/DOMSelection.h"
28 #include "core/editing/EditingUtilities.h" 29 #include "core/editing/EditingUtilities.h"
29 #include "core/editing/Editor.h" 30 #include "core/editing/Editor.h"
30 #include "core/editing/SelectionAdjuster.h" 31 #include "core/editing/SelectionAdjuster.h"
31 #include "core/frame/LocalFrame.h" 32 #include "core/frame/LocalFrame.h"
32 33
33 namespace blink { 34 namespace blink {
34 35
35 SelectionEditor::SelectionEditor(LocalFrame& frame) 36 SelectionEditor::SelectionEditor(LocalFrame& frame)
36 : m_frame(frame), m_observingVisibleSelection(false) { 37 : m_frame(frame), m_observingVisibleSelection(false) {
37 clearVisibleSelection(); 38 clearVisibleSelection();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const VisibleSelectionInFlatTree& 74 const VisibleSelectionInFlatTree&
74 SelectionEditor::visibleSelection<EditingInFlatTreeStrategy>() const { 75 SelectionEditor::visibleSelection<EditingInFlatTreeStrategy>() const {
75 DCHECK_EQ(frame()->document(), document()); 76 DCHECK_EQ(frame()->document(), document());
76 DCHECK_EQ(frame(), document().frame()); 77 DCHECK_EQ(frame(), document().frame());
77 if (m_selectionInFlatTree.isNone()) 78 if (m_selectionInFlatTree.isNone())
78 return m_selectionInFlatTree; 79 return m_selectionInFlatTree;
79 DCHECK_EQ(m_selectionInFlatTree.base().document(), document()); 80 DCHECK_EQ(m_selectionInFlatTree.base().document(), document());
80 return m_selectionInFlatTree; 81 return m_selectionInFlatTree;
81 } 82 }
82 83
84 static void markDOMSelectionDirty(const VisibleSelection& selection) {
85 if (selection.isNone())
86 return;
87
88 selection.start().anchorNode()->treeScope().getSelection()->markRangeDirty();
yosin_UTC9 2017/01/27 10:19:34 We want to have |TreeScope::getSelectionIfExists()
89 if (selection.isCaret())
90 return;
91
92 selection.end().anchorNode()->treeScope().getSelection()->markRangeDirty();
93 }
94
83 void SelectionEditor::setVisibleSelection( 95 void SelectionEditor::setVisibleSelection(
84 const VisibleSelection& newSelection, 96 const VisibleSelection& newSelection,
85 FrameSelection::SetSelectionOptions options) { 97 FrameSelection::SetSelectionOptions options) {
86 DCHECK(newSelection.isValidFor(document())) << newSelection; 98 DCHECK(newSelection.isValidFor(document())) << newSelection;
87 resetLogicalRange(); 99 resetLogicalRange();
100 markDOMSelectionDirty(m_selection);
101
88 m_selection = newSelection; 102 m_selection = newSelection;
89 if (options & FrameSelection::DoNotAdjustInFlatTree) { 103 if (options & FrameSelection::DoNotAdjustInFlatTree) {
90 m_selectionInFlatTree.setWithoutValidation( 104 m_selectionInFlatTree.setWithoutValidation(
91 toPositionInFlatTree(m_selection.base()), 105 toPositionInFlatTree(m_selection.base()),
92 toPositionInFlatTree(m_selection.extent())); 106 toPositionInFlatTree(m_selection.extent()));
93 return; 107 return;
94 } 108 }
95 109
96 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, 110 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree,
97 m_selection); 111 m_selection);
112
113 markDOMSelectionDirty(m_selection);
98 } 114 }
99 115
100 void SelectionEditor::setVisibleSelection( 116 void SelectionEditor::setVisibleSelection(
101 const VisibleSelectionInFlatTree& newSelection, 117 const VisibleSelectionInFlatTree& newSelection,
102 FrameSelection::SetSelectionOptions options) { 118 FrameSelection::SetSelectionOptions options) {
103 DCHECK(newSelection.isValidFor(document())) << newSelection; 119 DCHECK(newSelection.isValidFor(document())) << newSelection;
104 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); 120 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree));
105 resetLogicalRange(); 121 resetLogicalRange();
122 markDOMSelectionDirty(m_selection);
123
106 m_selectionInFlatTree = newSelection; 124 m_selectionInFlatTree = newSelection;
107 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, 125 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection,
108 m_selectionInFlatTree); 126 m_selectionInFlatTree);
127
128 markDOMSelectionDirty(m_selection);
109 } 129 }
110 130
111 void SelectionEditor::setWithoutValidation(const Position& base, 131 void SelectionEditor::setWithoutValidation(const Position& base,
112 const Position& extent) { 132 const Position& extent) {
113 resetLogicalRange(); 133 resetLogicalRange();
114 if (base.isNotNull()) 134 if (base.isNotNull())
115 DCHECK_EQ(base.document(), document()); 135 DCHECK_EQ(base.document(), document());
116 if (extent.isNotNull()) 136 if (extent.isNotNull())
117 DCHECK_EQ(extent.document(), document()); 137 DCHECK_EQ(extent.document(), document());
138 markDOMSelectionDirty(m_selection);
139
118 m_selection.setWithoutValidation(base, extent); 140 m_selection.setWithoutValidation(base, extent);
119 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), 141 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base),
120 toPositionInFlatTree(extent)); 142 toPositionInFlatTree(extent));
143 markDOMSelectionDirty(m_selection);
121 } 144 }
122 145
123 void SelectionEditor::documentAttached(Document* document) { 146 void SelectionEditor::documentAttached(Document* document) {
124 DCHECK(document); 147 DCHECK(document);
125 DCHECK(!m_document) << m_document; 148 DCHECK(!m_document) << m_document;
126 m_document = document; 149 m_document = document;
127 } 150 }
128 151
129 void SelectionEditor::documentDetached(const Document& document) { 152 void SelectionEditor::documentDetached(const Document& document) {
130 DCHECK_EQ(m_document, &document); 153 DCHECK_EQ(m_document, &document);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 189
167 DEFINE_TRACE(SelectionEditor) { 190 DEFINE_TRACE(SelectionEditor) {
168 visitor->trace(m_document); 191 visitor->trace(m_document);
169 visitor->trace(m_frame); 192 visitor->trace(m_frame);
170 visitor->trace(m_selection); 193 visitor->trace(m_selection);
171 visitor->trace(m_selectionInFlatTree); 194 visitor->trace(m_selectionInFlatTree);
172 visitor->trace(m_logicalRange); 195 visitor->trace(m_logicalRange);
173 } 196 }
174 197
175 } // namespace blink 198 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/DOMSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698