OLD | NEW |
---|---|
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" | |
yosin_UTC9
2017/02/09 06:52:06
nit: SelectionEditor should not depend to DOMSelec
yoichio
2017/02/09 09:31:19
Done.
| |
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(); |
38 } | 39 } |
39 | 40 |
40 SelectionEditor::~SelectionEditor() {} | 41 SelectionEditor::~SelectionEditor() {} |
41 | 42 |
42 void SelectionEditor::clearVisibleSelection() { | 43 void SelectionEditor::clearVisibleSelection() { |
43 m_selection = VisibleSelection(); | 44 m_selection = VisibleSelection(); |
44 m_selectionInFlatTree = VisibleSelectionInFlatTree(); | 45 m_selectionInFlatTree = VisibleSelectionInFlatTree(); |
45 if (!shouldAlwaysUseDirectionalSelection()) | 46 if (!shouldAlwaysUseDirectionalSelection()) |
46 return; | 47 return; |
47 m_selection.setIsDirectional(true); | 48 m_selection.setIsDirectional(true); |
48 m_selectionInFlatTree.setIsDirectional(true); | 49 m_selectionInFlatTree.setIsDirectional(true); |
49 } | 50 } |
50 | 51 |
51 void SelectionEditor::dispose() { | 52 void SelectionEditor::dispose() { |
52 resetLogicalRange(); | 53 resetLogicalRange(); |
54 clearDocumentCachedRange(); | |
53 clearVisibleSelection(); | 55 clearVisibleSelection(); |
54 } | 56 } |
55 | 57 |
56 const Document& SelectionEditor::document() const { | 58 const Document& SelectionEditor::document() const { |
57 DCHECK(m_document); | 59 DCHECK(m_document); |
58 return *m_document; | 60 return *m_document; |
59 } | 61 } |
60 | 62 |
61 template <> | 63 template <> |
62 const VisibleSelection& SelectionEditor::visibleSelection<EditingStrategy>() | 64 const VisibleSelection& SelectionEditor::visibleSelection<EditingStrategy>() |
(...skipping 15 matching lines...) Expand all Loading... | |
78 return m_selectionInFlatTree; | 80 return m_selectionInFlatTree; |
79 DCHECK_EQ(m_selectionInFlatTree.base().document(), document()); | 81 DCHECK_EQ(m_selectionInFlatTree.base().document(), document()); |
80 return m_selectionInFlatTree; | 82 return m_selectionInFlatTree; |
81 } | 83 } |
82 | 84 |
83 void SelectionEditor::setVisibleSelection( | 85 void SelectionEditor::setVisibleSelection( |
84 const VisibleSelection& newSelection, | 86 const VisibleSelection& newSelection, |
85 FrameSelection::SetSelectionOptions options) { | 87 FrameSelection::SetSelectionOptions options) { |
86 DCHECK(newSelection.isValidFor(document())) << newSelection; | 88 DCHECK(newSelection.isValidFor(document())) << newSelection; |
87 resetLogicalRange(); | 89 resetLogicalRange(); |
90 clearDocumentCachedRange(); | |
91 | |
88 m_selection = newSelection; | 92 m_selection = newSelection; |
89 if (options & FrameSelection::DoNotAdjustInFlatTree) { | 93 if (options & FrameSelection::DoNotAdjustInFlatTree) { |
90 m_selectionInFlatTree.setWithoutValidation( | 94 m_selectionInFlatTree.setWithoutValidation( |
91 toPositionInFlatTree(m_selection.base()), | 95 toPositionInFlatTree(m_selection.base()), |
92 toPositionInFlatTree(m_selection.extent())); | 96 toPositionInFlatTree(m_selection.extent())); |
93 return; | 97 return; |
94 } | 98 } |
95 | 99 |
96 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, | 100 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, |
97 m_selection); | 101 m_selection); |
98 } | 102 } |
99 | 103 |
100 void SelectionEditor::setVisibleSelection( | 104 void SelectionEditor::setVisibleSelection( |
101 const VisibleSelectionInFlatTree& newSelection, | 105 const VisibleSelectionInFlatTree& newSelection, |
102 FrameSelection::SetSelectionOptions options) { | 106 FrameSelection::SetSelectionOptions options) { |
103 DCHECK(newSelection.isValidFor(document())) << newSelection; | 107 DCHECK(newSelection.isValidFor(document())) << newSelection; |
104 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); | 108 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); |
105 resetLogicalRange(); | 109 resetLogicalRange(); |
110 clearDocumentCachedRange(); | |
111 | |
106 m_selectionInFlatTree = newSelection; | 112 m_selectionInFlatTree = newSelection; |
107 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, | 113 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, |
108 m_selectionInFlatTree); | 114 m_selectionInFlatTree); |
109 } | 115 } |
110 | 116 |
111 void SelectionEditor::setWithoutValidation(const Position& base, | 117 void SelectionEditor::setWithoutValidation(const Position& base, |
112 const Position& extent) { | 118 const Position& extent) { |
113 resetLogicalRange(); | 119 resetLogicalRange(); |
114 if (base.isNotNull()) | 120 if (base.isNotNull()) |
115 DCHECK_EQ(base.document(), document()); | 121 DCHECK_EQ(base.document(), document()); |
116 if (extent.isNotNull()) | 122 if (extent.isNotNull()) |
117 DCHECK_EQ(extent.document(), document()); | 123 DCHECK_EQ(extent.document(), document()); |
124 clearDocumentCachedRange(); | |
125 | |
118 m_selection.setWithoutValidation(base, extent); | 126 m_selection.setWithoutValidation(base, extent); |
119 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), | 127 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), |
120 toPositionInFlatTree(extent)); | 128 toPositionInFlatTree(extent)); |
121 } | 129 } |
122 | 130 |
123 void SelectionEditor::documentAttached(Document* document) { | 131 void SelectionEditor::documentAttached(Document* document) { |
124 DCHECK(document); | 132 DCHECK(document); |
125 DCHECK(!m_document) << m_document; | 133 DCHECK(!m_document) << m_document; |
126 m_document = document; | 134 m_document = document; |
127 } | 135 } |
(...skipping 29 matching lines...) Expand all Loading... | |
157 return frame()->editor().behavior().shouldConsiderSelectionAsDirectional(); | 165 return frame()->editor().behavior().shouldConsiderSelectionAsDirectional(); |
158 } | 166 } |
159 | 167 |
160 void SelectionEditor::updateIfNeeded() { | 168 void SelectionEditor::updateIfNeeded() { |
161 DCHECK(m_selection.isValidFor(document())) << m_selection; | 169 DCHECK(m_selection.isValidFor(document())) << m_selection; |
162 DCHECK(m_selectionInFlatTree.isValidFor(document())) << m_selection; | 170 DCHECK(m_selectionInFlatTree.isValidFor(document())) << m_selection; |
163 m_selection.updateIfNeeded(); | 171 m_selection.updateIfNeeded(); |
164 m_selectionInFlatTree.updateIfNeeded(); | 172 m_selectionInFlatTree.updateIfNeeded(); |
165 } | 173 } |
166 | 174 |
175 void SelectionEditor::clearDocumentCachedRange() { | |
176 if (!m_cachedRange) | |
177 return; | |
178 | |
179 m_cachedRange->dispose(); | |
180 m_cachedRange = nullptr; | |
181 } | |
182 | |
167 DEFINE_TRACE(SelectionEditor) { | 183 DEFINE_TRACE(SelectionEditor) { |
168 visitor->trace(m_document); | 184 visitor->trace(m_document); |
169 visitor->trace(m_frame); | 185 visitor->trace(m_frame); |
170 visitor->trace(m_selection); | 186 visitor->trace(m_selection); |
171 visitor->trace(m_selectionInFlatTree); | 187 visitor->trace(m_selectionInFlatTree); |
172 visitor->trace(m_logicalRange); | 188 visitor->trace(m_logicalRange); |
189 visitor->trace(m_cachedRange); | |
173 } | 190 } |
174 | 191 |
175 } // namespace blink | 192 } // namespace blink |
OLD | NEW |