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 markDOMSelectionDirty(const VisibleSelection& selection) { | |
85 if (selection.isNone()) | |
86 return; | |
87 | |
88 DCHECK(selection.start().anchorNode()); | |
yosin_UTC9
2017/01/26 08:12:49
nit: We don't need to have this DCHECK() because f
yoichio
2017/01/27 08:33:04
Done.
| |
89 selection.start().anchorNode()->treeScope().getSelection()->markRangeDirty(); | |
90 if (selection.isCaret()) | |
91 return; | |
92 | |
93 DCHECK(selection.end().anchorNode()); | |
yosin_UTC9
2017/01/26 08:12:49
nit: We don't need to have this DCHECK() because f
yoichio
2017/01/27 08:33:04
Done.
| |
94 selection.end().anchorNode()->treeScope().getSelection()->markRangeDirty(); | |
95 } | |
96 | |
83 void SelectionEditor::setVisibleSelection( | 97 void SelectionEditor::setVisibleSelection( |
84 const VisibleSelection& newSelection, | 98 const VisibleSelection& newSelection, |
85 FrameSelection::SetSelectionOptions options) { | 99 FrameSelection::SetSelectionOptions options) { |
86 DCHECK(newSelection.isValidFor(document())) << newSelection; | 100 DCHECK(newSelection.isValidFor(document())) << newSelection; |
87 resetLogicalRange(); | 101 resetLogicalRange(); |
102 markDOMSelectionDirty(m_selection); | |
103 | |
88 m_selection = newSelection; | 104 m_selection = newSelection; |
89 if (options & FrameSelection::DoNotAdjustInFlatTree) { | 105 if (options & FrameSelection::DoNotAdjustInFlatTree) { |
90 m_selectionInFlatTree.setWithoutValidation( | 106 m_selectionInFlatTree.setWithoutValidation( |
91 toPositionInFlatTree(m_selection.base()), | 107 toPositionInFlatTree(m_selection.base()), |
92 toPositionInFlatTree(m_selection.extent())); | 108 toPositionInFlatTree(m_selection.extent())); |
93 return; | 109 return; |
94 } | 110 } |
95 | 111 |
96 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, | 112 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, |
97 m_selection); | 113 m_selection); |
114 | |
115 markDOMSelectionDirty(m_selection); | |
98 } | 116 } |
99 | 117 |
100 void SelectionEditor::setVisibleSelection( | 118 void SelectionEditor::setVisibleSelection( |
101 const VisibleSelectionInFlatTree& newSelection, | 119 const VisibleSelectionInFlatTree& newSelection, |
102 FrameSelection::SetSelectionOptions options) { | 120 FrameSelection::SetSelectionOptions options) { |
103 DCHECK(newSelection.isValidFor(document())) << newSelection; | 121 DCHECK(newSelection.isValidFor(document())) << newSelection; |
104 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); | 122 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); |
105 resetLogicalRange(); | 123 resetLogicalRange(); |
124 markDOMSelectionDirty(m_selection); | |
125 | |
106 m_selectionInFlatTree = newSelection; | 126 m_selectionInFlatTree = newSelection; |
107 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, | 127 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, |
108 m_selectionInFlatTree); | 128 m_selectionInFlatTree); |
129 | |
130 markDOMSelectionDirty(m_selection); | |
109 } | 131 } |
110 | 132 |
111 void SelectionEditor::setWithoutValidation(const Position& base, | 133 void SelectionEditor::setWithoutValidation(const Position& base, |
112 const Position& extent) { | 134 const Position& extent) { |
113 resetLogicalRange(); | 135 resetLogicalRange(); |
114 if (base.isNotNull()) | 136 if (base.isNotNull()) |
115 DCHECK_EQ(base.document(), document()); | 137 DCHECK_EQ(base.document(), document()); |
116 if (extent.isNotNull()) | 138 if (extent.isNotNull()) |
117 DCHECK_EQ(extent.document(), document()); | 139 DCHECK_EQ(extent.document(), document()); |
140 markDOMSelectionDirty(m_selection); | |
141 | |
118 m_selection.setWithoutValidation(base, extent); | 142 m_selection.setWithoutValidation(base, extent); |
119 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), | 143 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), |
120 toPositionInFlatTree(extent)); | 144 toPositionInFlatTree(extent)); |
145 markDOMSelectionDirty(m_selection); | |
121 } | 146 } |
122 | 147 |
123 void SelectionEditor::documentAttached(Document* document) { | 148 void SelectionEditor::documentAttached(Document* document) { |
124 DCHECK(document); | 149 DCHECK(document); |
125 DCHECK(!m_document) << m_document; | 150 DCHECK(!m_document) << m_document; |
126 m_document = document; | 151 m_document = document; |
127 } | 152 } |
128 | 153 |
129 void SelectionEditor::documentDetached(const Document& document) { | 154 void SelectionEditor::documentDetached(const Document& document) { |
130 DCHECK_EQ(m_document, &document); | 155 DCHECK_EQ(m_document, &document); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 191 |
167 DEFINE_TRACE(SelectionEditor) { | 192 DEFINE_TRACE(SelectionEditor) { |
168 visitor->trace(m_document); | 193 visitor->trace(m_document); |
169 visitor->trace(m_frame); | 194 visitor->trace(m_frame); |
170 visitor->trace(m_selection); | 195 visitor->trace(m_selection); |
171 visitor->trace(m_selectionInFlatTree); | 196 visitor->trace(m_selectionInFlatTree); |
172 visitor->trace(m_logicalRange); | 197 visitor->trace(m_logicalRange); |
173 } | 198 } |
174 | 199 |
175 } // namespace blink | 200 } // namespace blink |
OLD | NEW |