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

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

Issue 1640623002: Move SelectionAdjust to its own file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-01-27T14:51:58 Created 4 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
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/EditingUtilities.h" 28 #include "core/editing/EditingUtilities.h"
29 #include "core/editing/Editor.h" 29 #include "core/editing/Editor.h"
30 #include "core/editing/SelectionAdjuster.h"
30 #include "core/events/Event.h" 31 #include "core/events/Event.h"
31 #include "core/frame/LocalFrame.h" 32 #include "core/frame/LocalFrame.h"
32 #include "core/frame/Settings.h" 33 #include "core/frame/Settings.h"
33 #include "core/layout/LayoutBlock.h" 34 #include "core/layout/LayoutBlock.h"
34 #include "core/layout/line/InlineTextBox.h" 35 #include "core/layout/line/InlineTextBox.h"
35 #include "core/page/SpatialNavigation.h" 36 #include "core/page/SpatialNavigation.h"
36 37
37 namespace blink { 38 namespace blink {
38 39
39 static inline LayoutUnit NoXPosForVerticalArrowNavigation() 40 static inline LayoutUnit NoXPosForVerticalArrowNavigation()
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 SelectionAdjuster::adjustSelectionInComposedTree(&m_selectionInComposedTree, m_selection); 91 SelectionAdjuster::adjustSelectionInComposedTree(&m_selectionInComposedTree, m_selection);
91 } 92 }
92 93
93 void SelectionEditor::setVisibleSelection(const VisibleSelectionInComposedTree& newSelection, FrameSelection::SetSelectionOptions options) 94 void SelectionEditor::setVisibleSelection(const VisibleSelectionInComposedTree& newSelection, FrameSelection::SetSelectionOptions options)
94 { 95 {
95 ASSERT(!(options & FrameSelection::DoNotAdjustInComposedTree)); 96 ASSERT(!(options & FrameSelection::DoNotAdjustInComposedTree));
96 m_selectionInComposedTree = newSelection; 97 m_selectionInComposedTree = newSelection;
97 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInCompo sedTree); 98 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInCompo sedTree);
98 } 99 }
99 100
100 // TODO(yosin): We should move
101 // |SelectionAdjuster::adjustSelectionInComposedTree()| to
102 // "SelectionAdjuster.cpp"
103 // Updates |selectionInComposedTree| to match with |selection|.
104 void SelectionAdjuster::adjustSelectionInComposedTree(VisibleSelectionInComposed Tree* selectionInComposedTree, const VisibleSelection& selection)
105 {
106 if (selection.isNone()) {
107 *selectionInComposedTree = VisibleSelectionInComposedTree();
108 return;
109 }
110
111 const PositionInComposedTree& base = toPositionInComposedTree(selection.base ());
112 const PositionInComposedTree& extent = toPositionInComposedTree(selection.ex tent());
113 const PositionInComposedTree& position1 = toPositionInComposedTree(selection .start());
114 const PositionInComposedTree& position2 = toPositionInComposedTree(selection .end());
115 position1.anchorNode()->updateDistribution();
116 position2.anchorNode()->updateDistribution();
117 selectionInComposedTree->m_base = base;
118 selectionInComposedTree->m_extent = extent;
119 selectionInComposedTree->m_affinity = selection.m_affinity;
120 selectionInComposedTree->m_isDirectional = selection.m_isDirectional;
121 selectionInComposedTree->m_baseIsFirst = base.isNull() || base.compareTo(ext ent) <= 0;
122 if (position1.compareTo(position2) <= 0) {
123 selectionInComposedTree->m_start = position1;
124 selectionInComposedTree->m_end = position2;
125 } else {
126 selectionInComposedTree->m_start = position2;
127 selectionInComposedTree->m_end = position1;
128 }
129 selectionInComposedTree->updateSelectionType();
130 }
131
132 static bool isCrossingShadowBoundaries(const VisibleSelectionInComposedTree& sel ection)
133 {
134 if (!selection.isRange())
135 return false;
136 TreeScope& treeScope = selection.base().anchorNode()->treeScope();
137 return selection.extent().anchorNode()->treeScope() != treeScope
138 || selection.start().anchorNode()->treeScope() != treeScope
139 || selection.end().anchorNode()->treeScope() != treeScope;
140 }
141
142 // TODO(yosin): We should move
143 // |SelectionAdjuster::adjustSelectionInDOMTree()| to
144 // "SelectionAdjuster.cpp"
145 void SelectionAdjuster::adjustSelectionInDOMTree(VisibleSelection* selection, co nst VisibleSelectionInComposedTree& selectionInComposedTree)
146 {
147 if (selectionInComposedTree.isNone()) {
148 *selection = VisibleSelection();
149 return;
150 }
151
152 const Position& base = toPositionInDOMTree(selectionInComposedTree.base());
153 const Position& extent = toPositionInDOMTree(selectionInComposedTree.extent( ));
154
155 if (isCrossingShadowBoundaries(selectionInComposedTree)) {
156 *selection = VisibleSelection(base, extent);
157 return;
158 }
159
160 const Position& position1 = toPositionInDOMTree(selectionInComposedTree.star t());
161 const Position& position2 = toPositionInDOMTree(selectionInComposedTree.end( ));
162 selection->m_base = base;
163 selection->m_extent = extent;
164 selection->m_affinity = selectionInComposedTree.m_affinity;
165 selection->m_isDirectional = selectionInComposedTree.m_isDirectional;
166 selection->m_baseIsFirst = base.isNull() || base.compareTo(extent) <= 0;
167 if (position1.compareTo(position2) <= 0) {
168 selection->m_start = position1;
169 selection->m_end = position2;
170 } else {
171 selection->m_start = position2;
172 selection->m_end = position1;
173 }
174 selection->updateSelectionType();
175 }
176
177 void SelectionEditor::resetXPosForVerticalArrowNavigation() 101 void SelectionEditor::resetXPosForVerticalArrowNavigation()
178 { 102 {
179 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); 103 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation();
180 } 104 }
181 105
182 void SelectionEditor::setIsDirectional(bool isDirectional) 106 void SelectionEditor::setIsDirectional(bool isDirectional)
183 { 107 {
184 m_selection.setIsDirectional(isDirectional); 108 m_selection.setIsDirectional(isDirectional);
185 m_selectionInComposedTree.setIsDirectional(isDirectional); 109 m_selectionInComposedTree.setIsDirectional(isDirectional);
186 } 110 }
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 DEFINE_TRACE(SelectionEditor) 886 DEFINE_TRACE(SelectionEditor)
963 { 887 {
964 visitor->trace(m_frameSelection); 888 visitor->trace(m_frameSelection);
965 visitor->trace(m_selection); 889 visitor->trace(m_selection);
966 visitor->trace(m_selectionInComposedTree); 890 visitor->trace(m_selectionInComposedTree);
967 visitor->trace(m_logicalRange); 891 visitor->trace(m_logicalRange);
968 VisibleSelectionChangeObserver::trace(visitor); 892 VisibleSelectionChangeObserver::trace(visitor);
969 } 893 }
970 894
971 } // namespace blink 895 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698