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 Document* rootDocument = |
| 89 selection.start().anchorNode()->document().frame()->document(); |
| 90 |
| 91 if (rootDocument->hasSelection()) |
| 92 rootDocument->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); |
98 } | 112 } |
99 | 113 |
100 void SelectionEditor::setVisibleSelection( | 114 void SelectionEditor::setVisibleSelection( |
101 const VisibleSelectionInFlatTree& newSelection, | 115 const VisibleSelectionInFlatTree& newSelection, |
102 FrameSelection::SetSelectionOptions options) { | 116 FrameSelection::SetSelectionOptions options) { |
103 DCHECK(newSelection.isValidFor(document())) << newSelection; | 117 DCHECK(newSelection.isValidFor(document())) << newSelection; |
104 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); | 118 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); |
105 resetLogicalRange(); | 119 resetLogicalRange(); |
| 120 markDOMSelectionDirty(m_selection); |
| 121 |
106 m_selectionInFlatTree = newSelection; | 122 m_selectionInFlatTree = newSelection; |
107 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, | 123 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, |
108 m_selectionInFlatTree); | 124 m_selectionInFlatTree); |
109 } | 125 } |
110 | 126 |
111 void SelectionEditor::setWithoutValidation(const Position& base, | 127 void SelectionEditor::setWithoutValidation(const Position& base, |
112 const Position& extent) { | 128 const Position& extent) { |
113 resetLogicalRange(); | 129 resetLogicalRange(); |
114 if (base.isNotNull()) | 130 if (base.isNotNull()) |
115 DCHECK_EQ(base.document(), document()); | 131 DCHECK_EQ(base.document(), document()); |
116 if (extent.isNotNull()) | 132 if (extent.isNotNull()) |
117 DCHECK_EQ(extent.document(), document()); | 133 DCHECK_EQ(extent.document(), document()); |
| 134 markDOMSelectionDirty(m_selection); |
| 135 |
118 m_selection.setWithoutValidation(base, extent); | 136 m_selection.setWithoutValidation(base, extent); |
119 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), | 137 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), |
120 toPositionInFlatTree(extent)); | 138 toPositionInFlatTree(extent)); |
121 } | 139 } |
122 | 140 |
123 void SelectionEditor::documentAttached(Document* document) { | 141 void SelectionEditor::documentAttached(Document* document) { |
124 DCHECK(document); | 142 DCHECK(document); |
125 DCHECK(!m_document) << m_document; | 143 DCHECK(!m_document) << m_document; |
126 m_document = document; | 144 m_document = document; |
127 } | 145 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 184 |
167 DEFINE_TRACE(SelectionEditor) { | 185 DEFINE_TRACE(SelectionEditor) { |
168 visitor->trace(m_document); | 186 visitor->trace(m_document); |
169 visitor->trace(m_frame); | 187 visitor->trace(m_frame); |
170 visitor->trace(m_selection); | 188 visitor->trace(m_selection); |
171 visitor->trace(m_selectionInFlatTree); | 189 visitor->trace(m_selectionInFlatTree); |
172 visitor->trace(m_logicalRange); | 190 visitor->trace(m_logicalRange); |
173 } | 191 } |
174 | 192 |
175 } // namespace blink | 193 } // namespace blink |
OLD | NEW |