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" | |
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 Loading... | |
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 markRangeDirty(TreeScope* treeScope) { | |
85 while (treeScope) { | |
yosin_UTC9
2017/02/07 10:04:29
Better to use for-statement;
for (TreeScope* runn
| |
86 if (treeScope->hasSelection()) | |
87 treeScope->getSelection()->markRangeDirty(); | |
88 treeScope = treeScope->parentTreeScope(); | |
89 } | |
90 } | |
91 | |
92 static void markDOMSelectionDirty(const VisibleSelection& selection) { | |
93 if (selection.isNone()) | |
94 return; | |
95 | |
96 markRangeDirty(&selection.start().anchorNode()->treeScope()); | |
97 if (selection.isCaret()) | |
98 return; | |
99 | |
100 markRangeDirty(&selection.end().anchorNode()->treeScope()); | |
101 } | |
102 | |
83 void SelectionEditor::setVisibleSelection( | 103 void SelectionEditor::setVisibleSelection( |
84 const VisibleSelection& newSelection, | 104 const VisibleSelection& newSelection, |
85 FrameSelection::SetSelectionOptions options) { | 105 FrameSelection::SetSelectionOptions options) { |
86 DCHECK(newSelection.isValidFor(document())) << newSelection; | 106 DCHECK(newSelection.isValidFor(document())) << newSelection; |
87 resetLogicalRange(); | 107 resetLogicalRange(); |
108 markDOMSelectionDirty(m_selection); | |
109 | |
88 m_selection = newSelection; | 110 m_selection = newSelection; |
89 if (options & FrameSelection::DoNotAdjustInFlatTree) { | 111 if (options & FrameSelection::DoNotAdjustInFlatTree) { |
90 m_selectionInFlatTree.setWithoutValidation( | 112 m_selectionInFlatTree.setWithoutValidation( |
91 toPositionInFlatTree(m_selection.base()), | 113 toPositionInFlatTree(m_selection.base()), |
92 toPositionInFlatTree(m_selection.extent())); | 114 toPositionInFlatTree(m_selection.extent())); |
93 return; | 115 return; |
94 } | 116 } |
95 | 117 |
96 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, | 118 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, |
97 m_selection); | 119 m_selection); |
120 | |
121 markDOMSelectionDirty(m_selection); | |
98 } | 122 } |
99 | 123 |
100 void SelectionEditor::setVisibleSelection( | 124 void SelectionEditor::setVisibleSelection( |
101 const VisibleSelectionInFlatTree& newSelection, | 125 const VisibleSelectionInFlatTree& newSelection, |
102 FrameSelection::SetSelectionOptions options) { | 126 FrameSelection::SetSelectionOptions options) { |
103 DCHECK(newSelection.isValidFor(document())) << newSelection; | 127 DCHECK(newSelection.isValidFor(document())) << newSelection; |
104 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); | 128 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); |
105 resetLogicalRange(); | 129 resetLogicalRange(); |
130 markDOMSelectionDirty(m_selection); | |
131 | |
106 m_selectionInFlatTree = newSelection; | 132 m_selectionInFlatTree = newSelection; |
107 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, | 133 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, |
108 m_selectionInFlatTree); | 134 m_selectionInFlatTree); |
135 | |
136 markDOMSelectionDirty(m_selection); | |
109 } | 137 } |
110 | 138 |
111 void SelectionEditor::setWithoutValidation(const Position& base, | 139 void SelectionEditor::setWithoutValidation(const Position& base, |
112 const Position& extent) { | 140 const Position& extent) { |
113 resetLogicalRange(); | 141 resetLogicalRange(); |
114 if (base.isNotNull()) | 142 if (base.isNotNull()) |
115 DCHECK_EQ(base.document(), document()); | 143 DCHECK_EQ(base.document(), document()); |
116 if (extent.isNotNull()) | 144 if (extent.isNotNull()) |
117 DCHECK_EQ(extent.document(), document()); | 145 DCHECK_EQ(extent.document(), document()); |
146 markDOMSelectionDirty(m_selection); | |
147 | |
118 m_selection.setWithoutValidation(base, extent); | 148 m_selection.setWithoutValidation(base, extent); |
119 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), | 149 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), |
120 toPositionInFlatTree(extent)); | 150 toPositionInFlatTree(extent)); |
151 markDOMSelectionDirty(m_selection); | |
121 } | 152 } |
122 | 153 |
123 void SelectionEditor::documentAttached(Document* document) { | 154 void SelectionEditor::documentAttached(Document* document) { |
124 DCHECK(document); | 155 DCHECK(document); |
125 DCHECK(!m_document) << m_document; | 156 DCHECK(!m_document) << m_document; |
126 m_document = document; | 157 m_document = document; |
127 } | 158 } |
128 | 159 |
129 void SelectionEditor::documentDetached(const Document& document) { | 160 void SelectionEditor::documentDetached(const Document& document) { |
130 DCHECK_EQ(m_document, &document); | 161 DCHECK_EQ(m_document, &document); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 197 |
167 DEFINE_TRACE(SelectionEditor) { | 198 DEFINE_TRACE(SelectionEditor) { |
168 visitor->trace(m_document); | 199 visitor->trace(m_document); |
169 visitor->trace(m_frame); | 200 visitor->trace(m_frame); |
170 visitor->trace(m_selection); | 201 visitor->trace(m_selection); |
171 visitor->trace(m_selectionInFlatTree); | 202 visitor->trace(m_selectionInFlatTree); |
172 visitor->trace(m_logicalRange); | 203 visitor->trace(m_logicalRange); |
173 } | 204 } |
174 | 205 |
175 } // namespace blink | 206 } // namespace blink |
OLD | NEW |