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

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

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 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, 2005, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 : m_affinity(TextAffinity::Downstream) 46 : m_affinity(TextAffinity::Downstream)
47 , m_selectionType(NoSelection) 47 , m_selectionType(NoSelection)
48 , m_baseIsFirst(true) 48 , m_baseIsFirst(true)
49 , m_isDirectional(false) 49 , m_isDirectional(false)
50 , m_granularity(CharacterGranularity) 50 , m_granularity(CharacterGranularity)
51 , m_hasTrailingWhitespace(false) 51 , m_hasTrailingWhitespace(false)
52 { 52 {
53 } 53 }
54 54
55 template <typename Strategy> 55 template <typename Strategy>
56 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const PositionTempl ate<Strategy>& pos, TextAffinity affinity, bool isDirectional)
57 : VisibleSelectionTemplate(pos, pos, affinity, isDirectional)
58 {
59 }
60
61 template <typename Strategy>
62 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const PositionTempl ate<Strategy>& base, const PositionTemplate<Strategy>& extent, TextAffinity affi nity, bool isDirectional) 56 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const PositionTempl ate<Strategy>& base, const PositionTemplate<Strategy>& extent, TextAffinity affi nity, bool isDirectional)
63 : m_base(base) 57 : m_base(base)
64 , m_extent(extent) 58 , m_extent(extent)
65 , m_affinity(affinity) 59 , m_affinity(affinity)
66 , m_isDirectional(isDirectional) 60 , m_isDirectional(isDirectional)
67 , m_granularity(CharacterGranularity) 61 , m_granularity(CharacterGranularity)
68 , m_hasTrailingWhitespace(false) 62 , m_hasTrailingWhitespace(false)
69 { 63 {
70 Document* document = m_base.document() ? m_base.document() : m_extent.docume nt();
71 if (document) {
72 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesh eets
73 // needs to be audited. see http://crbug.com/590369 for more details.
74 document->updateStyleAndLayoutIgnorePendingStylesheets();
75 }
76 validate(); 64 validate();
77 } 65 }
78 66
79 template <typename Strategy> 67 template <typename Strategy>
80 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const PositionWithA ffinityTemplate<Strategy>& pos, bool isDirectional) 68 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::create(co nst PositionTemplate<Strategy>& base, const PositionTemplate<Strategy>& extent, TextAffinity affinity, bool isDirectional)
81 : VisibleSelectionTemplate(pos.position(), pos.affinity(), isDirectional)
82 { 69 {
70 return VisibleSelectionTemplate(base, extent, affinity, isDirectional);
71 }
72
73 VisibleSelection createVisibleSelectionDeprecated(const Position& pos, TextAffin ity affinity, bool isDirectional)
74 {
75 if (pos.isNotNull())
76 pos.document()->updateStyleAndLayoutIgnorePendingStylesheets();
77 return VisibleSelection::create(pos, pos, affinity, isDirectional);
78 }
79
80 VisibleSelection createVisibleSelectionDeprecated(const Position& base, const Po sition& extent, TextAffinity affinity, bool isDirectional)
81 {
82 if (base.isNotNull())
83 base.document()->updateStyleAndLayoutIgnorePendingStylesheets();
84 if (extent.isNotNull())
85 extent.document()->updateStyleAndLayoutIgnorePendingStylesheets();
86 return VisibleSelection::create(base, extent, affinity, isDirectional);
87 }
88
89 VisibleSelection createVisibleSelectionDeprecated(const PositionWithAffinity& po s, bool isDirectional)
90 {
91 if (pos.isNotNull())
92 pos.position().document()->updateStyleAndLayoutIgnorePendingStylesheets( );
93 return VisibleSelection::create(pos.position(), pos.position(), pos.affinity (), isDirectional);
94 }
95
96 VisibleSelection createVisibleSelectionDeprecated(const VisiblePosition& pos, bo ol isDirectional)
97 {
98 if (pos.isNotNull())
99 pos.deepEquivalent().document()->updateStyleAndLayoutIgnorePendingStyles heets();
100 return VisibleSelection::create(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity(), isDirectional);
101 }
102
103 VisibleSelection createVisibleSelectionDeprecated(const VisiblePosition& base, c onst VisiblePosition& extent, bool isDirectional)
104 {
105 if (base.isNotNull())
106 base.deepEquivalent().document()->updateStyleAndLayoutIgnorePendingStyle sheets();
107 if (extent.isNotNull())
yosin_UTC9 2016/09/30 01:20:35 Note: We will fix callers which pass base=null, ex
108 extent.deepEquivalent().document()->updateStyleAndLayoutIgnorePendingSty lesheets();
109 return VisibleSelection::create(base.deepEquivalent(), extent.deepEquivalent (), base.affinity(), isDirectional);
110 }
111
112 VisibleSelection createVisibleSelectionDeprecated(const EphemeralRange& range, T extAffinity affinity, bool isDirectional)
113 {
114 if (range.isNotNull())
115 range.startPosition().document()->updateStyleAndLayoutIgnorePendingStyle sheets();
116 return VisibleSelection::create(range.startPosition(), range.endPosition(), affinity, isDirectional);
117 }
118
119 VisibleSelectionInFlatTree createVisibleSelectionDeprecated(const PositionInFlat Tree& pos, TextAffinity affinity, bool isDirectional)
120 {
121 if (pos.isNotNull())
122 pos.document()->updateStyleAndLayoutIgnorePendingStylesheets();
123 return VisibleSelectionInFlatTree::create(pos, pos, affinity, isDirectional) ;
124 }
125
126 VisibleSelectionInFlatTree createVisibleSelectionDeprecated(const PositionInFlat Tree& base, const PositionInFlatTree& extent, TextAffinity affinity, bool isDire ctional)
127 {
128 if (base.isNotNull())
129 base.document()->updateStyleAndLayoutIgnorePendingStylesheets();
130 if (extent.isNotNull())
131 extent.document()->updateStyleAndLayoutIgnorePendingStylesheets();
132 return VisibleSelectionInFlatTree::create(base, extent, affinity, isDirectio nal);
133 }
134
135 VisibleSelectionInFlatTree createVisibleSelectionDeprecated(const PositionInFlat TreeWithAffinity& pos, bool isDirectional)
136 {
137 if (pos.isNotNull())
138 pos.position().document()->updateStyleAndLayoutIgnorePendingStylesheets( );
139 return VisibleSelectionInFlatTree::create(pos.position(), pos.position(), po s.affinity(), isDirectional);
140 }
141
142 VisibleSelectionInFlatTree createVisibleSelectionDeprecated(const VisiblePositio nInFlatTree& pos, bool isDirectional)
143 {
144 if (pos.isNotNull())
145 pos.deepEquivalent().document()->updateStyleAndLayoutIgnorePendingStyles heets();
146 return VisibleSelectionInFlatTree::create(pos.deepEquivalent(), pos.deepEqui valent(), pos.affinity(), isDirectional);
147 }
148
149 VisibleSelectionInFlatTree createVisibleSelectionDeprecated(const VisiblePositio nInFlatTree& base, const VisiblePositionInFlatTree& extent, bool isDirectional)
150 {
151 if (base.isNotNull())
152 base.deepEquivalent().document()->updateStyleAndLayoutIgnorePendingStyle sheets();
153 if (extent.isNotNull())
154 extent.deepEquivalent().document()->updateStyleAndLayoutIgnorePendingSty lesheets();
155 return VisibleSelectionInFlatTree::create(base.deepEquivalent(), extent.deep Equivalent(), base.affinity(), isDirectional);
156 }
157
158 VisibleSelectionInFlatTree createVisibleSelectionDeprecated(const EphemeralRange InFlatTree& range, TextAffinity affinity, bool isDirectional)
159 {
160 if (range.isNotNull())
161 range.startPosition().document()->updateStyleAndLayoutIgnorePendingStyle sheets();
162 return VisibleSelectionInFlatTree::create(range.startPosition(), range.endPo sition(), affinity, isDirectional);
163 }
164
165 VisibleSelection createVisibleSelection(const Position& pos, TextAffinity affini ty, bool isDirectional)
166 {
167 DCHECK(!needsLayoutTreeUpdate(pos));
168 return VisibleSelection::create(pos, pos, affinity, isDirectional);
169 }
170
171 VisibleSelection createVisibleSelection(const Position& base, const Position& ex tent, TextAffinity affinity, bool isDirectional)
172 {
173 DCHECK(!needsLayoutTreeUpdate(base));
174 DCHECK(!needsLayoutTreeUpdate(extent));
175 return VisibleSelection::create(base, extent, affinity, isDirectional);
176 }
177
178 VisibleSelection createVisibleSelection(const PositionWithAffinity& pos, bool is Directional)
179 {
180 DCHECK(!needsLayoutTreeUpdate(pos.position()));
181 return VisibleSelection::create(pos.position(), pos.position(), pos.affinity (), isDirectional);
182 }
183
184 VisibleSelection createVisibleSelection(const VisiblePosition& pos, bool isDirec tional)
185 {
186 DCHECK(pos.isValid());
187 return VisibleSelection::create(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity(), isDirectional);
188 }
189
190 VisibleSelection createVisibleSelection(const VisiblePosition& base, const Visib lePosition& extent, bool isDirectional)
191 {
192 DCHECK(base.isValid());
193 DCHECK(extent.isValid());
194 return VisibleSelection::create(base.deepEquivalent(), extent.deepEquivalent (), base.affinity(), isDirectional);
195 }
196
197 VisibleSelection createVisibleSelection(const EphemeralRange& range, TextAffinit y affinity, bool isDirectional)
198 {
199 DCHECK(!needsLayoutTreeUpdate(range.startPosition()));
200 DCHECK(!needsLayoutTreeUpdate(range.endPosition()));
201 return VisibleSelection::create(range.startPosition(), range.endPosition(), affinity, isDirectional);
202 }
203
204 VisibleSelectionInFlatTree createVisibleSelection(const PositionInFlatTree& pos, TextAffinity affinity, bool isDirectional)
205 {
206 DCHECK(!needsLayoutTreeUpdate(pos));
207 return VisibleSelectionInFlatTree::create(pos, pos, affinity, isDirectional) ;
208 }
209
210 VisibleSelectionInFlatTree createVisibleSelection(const PositionInFlatTree& base , const PositionInFlatTree& extent, TextAffinity affinity, bool isDirectional)
211 {
212 DCHECK(!needsLayoutTreeUpdate(base));
213 DCHECK(!needsLayoutTreeUpdate(extent));
214 return VisibleSelectionInFlatTree::create(base, extent, affinity, isDirectio nal);
215 }
216
217 VisibleSelectionInFlatTree createVisibleSelection(const PositionInFlatTreeWithAf finity& pos, bool isDirectional)
218 {
219 DCHECK(!needsLayoutTreeUpdate(pos.position()));
220 return VisibleSelectionInFlatTree::create(pos.position(), pos.position(), po s.affinity(), isDirectional);
221 }
222
223 VisibleSelectionInFlatTree createVisibleSelection(const VisiblePositionInFlatTre e& pos, bool isDirectional)
224 {
225 DCHECK(pos.isValid());
226 return VisibleSelectionInFlatTree::create(pos.deepEquivalent(), pos.deepEqui valent(), pos.affinity(), isDirectional);
227 }
228
229 VisibleSelectionInFlatTree createVisibleSelection(const VisiblePositionInFlatTre e& base, const VisiblePositionInFlatTree& extent, bool isDirectional)
230 {
231 DCHECK(base.isValid());
232 DCHECK(extent.isValid());
233 return VisibleSelectionInFlatTree::create(base.deepEquivalent(), extent.deep Equivalent(), base.affinity(), isDirectional);
234 }
235
236 VisibleSelectionInFlatTree createVisibleSelection(const EphemeralRangeInFlatTree & range, TextAffinity affinity, bool isDirectional)
237 {
238 DCHECK(!needsLayoutTreeUpdate(range.startPosition()));
239 DCHECK(!needsLayoutTreeUpdate(range.endPosition()));
240 return VisibleSelectionInFlatTree::create(range.startPosition(), range.endPo sition(), affinity, isDirectional);
83 } 241 }
84 242
85 template <typename Strategy> 243 template <typename Strategy>
86 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const VisiblePositi onTemplate<Strategy>& pos, bool isDirectional)
87 : VisibleSelectionTemplate(pos, pos, isDirectional)
88 {
89 }
90
91 template <typename Strategy>
92 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const VisiblePositi onTemplate<Strategy>& base, const VisiblePositionTemplate<Strategy>& extent, boo l isDirectional)
93 : VisibleSelectionTemplate(base.deepEquivalent(), extent.deepEquivalent(), b ase.affinity(), isDirectional)
94 {
95 }
96
97 template <typename Strategy>
98 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const EphemeralRang eTemplate<Strategy>& range, TextAffinity affinity, bool isDirectional)
99 : VisibleSelectionTemplate(range.startPosition(), range.endPosition(), affin ity, isDirectional)
100 {
101 }
102
103 template <typename Strategy>
104 static SelectionType computeSelectionType(const PositionTemplate<Strategy>& star t, const PositionTemplate<Strategy>& end) 244 static SelectionType computeSelectionType(const PositionTemplate<Strategy>& star t, const PositionTemplate<Strategy>& end)
105 { 245 {
106 if (start.isNull()) { 246 if (start.isNull()) {
107 DCHECK(end.isNull()); 247 DCHECK(end.isNull());
108 return NoSelection; 248 return NoSelection;
109 } 249 }
110 if (start == end) 250 if (start == end)
111 return CaretSelection; 251 return CaretSelection;
112 // TODO(yosin) We should call |Document::updateStyleAndLayout()| here for 252 // TODO(yosin) We should call |Document::updateStyleAndLayout()| here for
113 // |mostBackwardCaretPosition()|. However, we are here during 253 // |mostBackwardCaretPosition()|. However, we are here during
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 m_isDirectional = other.m_isDirectional; 287 m_isDirectional = other.m_isDirectional;
148 m_granularity = other.m_granularity; 288 m_granularity = other.m_granularity;
149 m_hasTrailingWhitespace = other.m_hasTrailingWhitespace; 289 m_hasTrailingWhitespace = other.m_hasTrailingWhitespace;
150 return *this; 290 return *this;
151 } 291 }
152 292
153 template <typename Strategy> 293 template <typename Strategy>
154 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection FromContentsOfNode(Node* node) 294 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection FromContentsOfNode(Node* node)
155 { 295 {
156 DCHECK(!Strategy::editingIgnoresContent(node)); 296 DCHECK(!Strategy::editingIgnoresContent(node));
157 return VisibleSelectionTemplate(PositionTemplate<Strategy>::firstPositionInN ode(node), PositionTemplate<Strategy>::lastPositionInNode(node)); 297
298 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
299 // needs to be audited. see http://crbug.com/590369 for more details.
300 node->document().updateStyleAndLayoutIgnorePendingStylesheets();
301
302 return VisibleSelectionTemplate::create(PositionTemplate<Strategy>::firstPos itionInNode(node), PositionTemplate<Strategy>::lastPositionInNode(node), SelDefa ultAffinity, false);
158 } 303 }
159 304
160 template <typename Strategy> 305 template <typename Strategy>
161 void VisibleSelectionTemplate<Strategy>::setBase(const PositionTemplate<Strategy >& position) 306 void VisibleSelectionTemplate<Strategy>::setBase(const PositionTemplate<Strategy >& position)
162 { 307 {
163 DCHECK(!needsLayoutTreeUpdate(position)); 308 DCHECK(!needsLayoutTreeUpdate(position));
164 m_base = position; 309 m_base = position;
165 validate(); 310 validate();
166 } 311 }
167 312
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 { 1001 {
857 sel.showTreeForThis(); 1002 sel.showTreeForThis();
858 } 1003 }
859 1004
860 void showTree(const blink::VisibleSelectionInFlatTree* sel) 1005 void showTree(const blink::VisibleSelectionInFlatTree* sel)
861 { 1006 {
862 if (sel) 1007 if (sel)
863 sel->showTreeForThis(); 1008 sel->showTreeForThis();
864 } 1009 }
865 #endif 1010 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698