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

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

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Output info for some DCHECKs, add TODOs. Created 4 years, 8 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 template <typename Strategy> 93 template <typename Strategy>
94 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const EphemeralRang eTemplate<Strategy>& range, TextAffinity affinity, bool isDirectional) 94 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const EphemeralRang eTemplate<Strategy>& range, TextAffinity affinity, bool isDirectional)
95 : VisibleSelectionTemplate(range.startPosition(), range.endPosition(), affin ity, isDirectional) 95 : VisibleSelectionTemplate(range.startPosition(), range.endPosition(), affin ity, isDirectional)
96 { 96 {
97 } 97 }
98 98
99 template <typename Strategy> 99 template <typename Strategy>
100 static SelectionType computeSelectionType(const PositionTemplate<Strategy>& star t, const PositionTemplate<Strategy>& end) 100 static SelectionType computeSelectionType(const PositionTemplate<Strategy>& star t, const PositionTemplate<Strategy>& end)
101 { 101 {
102 if (start.isNull()) { 102 if (start.isNull()) {
103 ASSERT(end.isNull()); 103 DCHECK(end.isNull());
104 return NoSelection; 104 return NoSelection;
105 } 105 }
106 if (start == end) 106 if (start == end)
107 return CaretSelection; 107 return CaretSelection;
108 // TODO(yosin) We should call |Document::updateLayout()| here for 108 // TODO(yosin) We should call |Document::updateLayout()| here for
109 // |mostBackwardCaretPosition()|. However, we are here during 109 // |mostBackwardCaretPosition()|. However, we are here during
110 // |Node::removeChild()|. 110 // |Node::removeChild()|.
111 start.anchorNode()->updateDistribution(); 111 start.anchorNode()->updateDistribution();
112 end.anchorNode()->updateDistribution(); 112 end.anchorNode()->updateDistribution();
113 if (mostBackwardCaretPosition(start) == mostBackwardCaretPosition(end)) 113 if (mostBackwardCaretPosition(start) == mostBackwardCaretPosition(end))
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 m_baseIsFirst = other.m_baseIsFirst; 146 m_baseIsFirst = other.m_baseIsFirst;
147 m_isDirectional = other.m_isDirectional; 147 m_isDirectional = other.m_isDirectional;
148 m_granularity = other.m_granularity; 148 m_granularity = other.m_granularity;
149 m_hasTrailingWhitespace = other.m_hasTrailingWhitespace; 149 m_hasTrailingWhitespace = other.m_hasTrailingWhitespace;
150 return *this; 150 return *this;
151 } 151 }
152 152
153 template <typename Strategy> 153 template <typename Strategy>
154 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection FromContentsOfNode(Node* node) 154 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection FromContentsOfNode(Node* node)
155 { 155 {
156 ASSERT(!Strategy::editingIgnoresContent(node)); 156 DCHECK(!Strategy::editingIgnoresContent(node));
157 return VisibleSelectionTemplate(PositionTemplate<Strategy>::firstPositionInN ode(node), PositionTemplate<Strategy>::lastPositionInNode(node)); 157 return VisibleSelectionTemplate(PositionTemplate<Strategy>::firstPositionInN ode(node), PositionTemplate<Strategy>::lastPositionInNode(node));
158 } 158 }
159 159
160 template <typename Strategy> 160 template <typename Strategy>
161 void VisibleSelectionTemplate<Strategy>::setBase(const PositionTemplate<Strategy >& position) 161 void VisibleSelectionTemplate<Strategy>::setBase(const PositionTemplate<Strategy >& position)
162 { 162 {
163 const PositionTemplate<Strategy> oldBase = m_base; 163 const PositionTemplate<Strategy> oldBase = m_base;
164 m_base = position; 164 m_base = position;
165 validate(); 165 validate();
166 if (m_base != oldBase) 166 if (m_base != oldBase)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // the selection. Again, this is to match the conventions of text editors 238 // the selection. Again, this is to match the conventions of text editors
239 // tested, which make style determinations based on the first character of 239 // tested, which make style determinations based on the first character of
240 // the selection. For instance, this operation helps to make sure that the 240 // the selection. For instance, this operation helps to make sure that the
241 // "X" selected below is the only thing selected. The range should not be 241 // "X" selected below is the only thing selected. The range should not be
242 // allowed to "leak" out to the end of the previous text node, or to the 242 // allowed to "leak" out to the end of the previous text node, or to the
243 // beginning of the next text node, each of which has a different style. 243 // beginning of the next text node, each of which has a different style.
244 // 244 //
245 // On a treasure map, <b>X</b> marks the spot. 245 // On a treasure map, <b>X</b> marks the spot.
246 // ^ selected 246 // ^ selected
247 // 247 //
248 ASSERT(isRange()); 248 DCHECK(isRange());
249 return normalizeRange(EphemeralRangeTemplate<Strategy>(m_start, m_end)); 249 return normalizeRange(EphemeralRangeTemplate<Strategy>(m_start, m_end));
250 } 250 }
251 251
252 template <typename Strategy> 252 template <typename Strategy>
253 bool VisibleSelectionTemplate<Strategy>::expandUsingGranularity(TextGranularity granularity) 253 bool VisibleSelectionTemplate<Strategy>::expandUsingGranularity(TextGranularity granularity)
254 { 254 {
255 if (isNone()) 255 if (isNone())
256 return false; 256 return false;
257 257
258 // TODO(yosin) Do we need to check all of them? 258 // TODO(yosin) Do we need to check all of them?
(...skipping 19 matching lines...) Expand all
278 Element* boundary = enclosingBlockFlowElement(*node); 278 Element* boundary = enclosingBlockFlowElement(*node);
279 if (!boundary) 279 if (!boundary)
280 return EphemeralRangeTemplate<Strategy>(); 280 return EphemeralRangeTemplate<Strategy>();
281 281
282 return EphemeralRangeTemplate<Strategy>(pos, PositionTemplate<Strategy>::las tPositionInNode(boundary)); 282 return EphemeralRangeTemplate<Strategy>(pos, PositionTemplate<Strategy>::las tPositionInNode(boundary));
283 } 283 }
284 284
285 template <typename Strategy> 285 template <typename Strategy>
286 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() 286 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace()
287 { 287 {
288 ASSERT(m_granularity == WordGranularity); 288 DCHECK_EQ(m_granularity, WordGranularity);
289 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end()); 289 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end());
290 if (searchRange.isNull()) 290 if (searchRange.isNull())
291 return; 291 return;
292 292
293 CharacterIteratorAlgorithm<Strategy> charIt(searchRange.startPosition(), sea rchRange.endPosition(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); 293 CharacterIteratorAlgorithm<Strategy> charIt(searchRange.startPosition(), sea rchRange.endPosition(), TextIteratorEmitsCharactersBetweenAllVisiblePositions);
294 bool changed = false; 294 bool changed = false;
295 295
296 for (; charIt.length(); charIt.advance(1)) { 296 for (; charIt.length(); charIt.advance(1)) {
297 UChar c = charIt.characterAt(0); 297 UChar c = charIt.characterAt(0);
298 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') 298 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n')
(...skipping 30 matching lines...) Expand all
329 m_extent = m_base; 329 m_extent = m_base;
330 m_baseIsFirst = true; 330 m_baseIsFirst = true;
331 } else { 331 } else {
332 m_baseIsFirst = m_base.compareTo(m_extent) <= 0; 332 m_baseIsFirst = m_base.compareTo(m_extent) <= 0;
333 } 333 }
334 } 334 }
335 335
336 template <typename Strategy> 336 template <typename Strategy>
337 void VisibleSelectionTemplate<Strategy>::setStartRespectingGranularity(TextGranu larity granularity, EWordSide wordSide) 337 void VisibleSelectionTemplate<Strategy>::setStartRespectingGranularity(TextGranu larity granularity, EWordSide wordSide)
338 { 338 {
339 ASSERT(m_base.isNotNull()); 339 DCHECK(m_base.isNotNull());
340 ASSERT(m_extent.isNotNull()); 340 DCHECK(m_extent.isNotNull());
341 341
342 m_start = m_baseIsFirst ? m_base : m_extent; 342 m_start = m_baseIsFirst ? m_base : m_extent;
343 343
344 switch (granularity) { 344 switch (granularity) {
345 case CharacterGranularity: 345 case CharacterGranularity:
346 // Don't do any expansion. 346 // Don't do any expansion.
347 break; 347 break;
348 case WordGranularity: { 348 case WordGranularity: {
349 // General case: Select the word the caret is positioned inside of. 349 // General case: Select the word the caret is positioned inside of.
350 // If the caret is on the word boundary, select the word according to |w ordSide|. 350 // If the caret is on the word boundary, select the word according to |w ordSide|.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 389 }
390 390
391 // Make sure we do not have a Null position. 391 // Make sure we do not have a Null position.
392 if (m_start.isNull()) 392 if (m_start.isNull())
393 m_start = m_baseIsFirst ? m_base : m_extent; 393 m_start = m_baseIsFirst ? m_base : m_extent;
394 } 394 }
395 395
396 template <typename Strategy> 396 template <typename Strategy>
397 void VisibleSelectionTemplate<Strategy>::setEndRespectingGranularity(TextGranula rity granularity, EWordSide wordSide) 397 void VisibleSelectionTemplate<Strategy>::setEndRespectingGranularity(TextGranula rity granularity, EWordSide wordSide)
398 { 398 {
399 ASSERT(m_base.isNotNull()); 399 DCHECK(m_base.isNotNull());
400 ASSERT(m_extent.isNotNull()); 400 DCHECK(m_extent.isNotNull());
401 401
402 m_end = m_baseIsFirst ? m_extent : m_base; 402 m_end = m_baseIsFirst ? m_extent : m_base;
403 403
404 switch (granularity) { 404 switch (granularity) {
405 case CharacterGranularity: 405 case CharacterGranularity:
406 // Don't do any expansion. 406 // Don't do any expansion.
407 break; 407 break;
408 case WordGranularity: { 408 case WordGranularity: {
409 // General case: Select the word the caret is positioned inside of. 409 // General case: Select the word the caret is positioned inside of.
410 // If the caret is on the word boundary, select the word according to 410 // If the caret is on the word boundary, select the word according to
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 setBaseAndExtentToDeepEquivalents(); 525 setBaseAndExtentToDeepEquivalents();
526 if (m_base.isNull() || m_extent.isNull()) { 526 if (m_base.isNull() || m_extent.isNull()) {
527 m_base = m_extent = m_start = m_end = PositionTemplate<Strategy>(); 527 m_base = m_extent = m_start = m_end = PositionTemplate<Strategy>();
528 updateSelectionType(); 528 updateSelectionType();
529 return; 529 return;
530 } 530 }
531 531
532 m_start = m_baseIsFirst ? m_base : m_extent; 532 m_start = m_baseIsFirst ? m_base : m_extent;
533 m_end = m_baseIsFirst ? m_extent : m_base; 533 m_end = m_baseIsFirst ? m_extent : m_base;
534 setStartRespectingGranularity(granularity); 534 setStartRespectingGranularity(granularity);
535 ASSERT(m_start.isNotNull()); 535 DCHECK(m_start.isNotNull());
536 setEndRespectingGranularity(granularity); 536 setEndRespectingGranularity(granularity);
537 ASSERT(m_end.isNotNull()); 537 DCHECK(m_end.isNotNull());
538 adjustSelectionToAvoidCrossingShadowBoundaries(); 538 adjustSelectionToAvoidCrossingShadowBoundaries();
539 adjustSelectionToAvoidCrossingEditingBoundaries(); 539 adjustSelectionToAvoidCrossingEditingBoundaries();
540 updateSelectionType(); 540 updateSelectionType();
541 541
542 if (getSelectionType() == RangeSelection) { 542 if (getSelectionType() == RangeSelection) {
543 // "Constrain" the selection to be the smallest equivalent range of 543 // "Constrain" the selection to be the smallest equivalent range of
544 // nodes. This is a somewhat arbitrary choice, but experience shows that 544 // nodes. This is a somewhat arbitrary choice, but experience shows that
545 // it is useful to make to make the selection "canonical" (if only for 545 // it is useful to make to make the selection "canonical" (if only for
546 // purposes of comparing selections). This is an ideal point of the code 546 // purposes of comparing selections). This is an ideal point of the code
547 // to do this operation, since all selection changes that result in a 547 // to do this operation, since all selection changes that result in a
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 { 791 {
792 } 792 }
793 793
794 VisibleSelectionChangeObserver::~VisibleSelectionChangeObserver() 794 VisibleSelectionChangeObserver::~VisibleSelectionChangeObserver()
795 { 795 {
796 } 796 }
797 797
798 template <typename Strategy> 798 template <typename Strategy>
799 void VisibleSelectionTemplate<Strategy>::setChangeObserver(VisibleSelectionChang eObserver& observer) 799 void VisibleSelectionTemplate<Strategy>::setChangeObserver(VisibleSelectionChang eObserver& observer)
800 { 800 {
801 ASSERT(!m_changeObserver); 801 DCHECK(!m_changeObserver);
802 m_changeObserver = &observer; 802 m_changeObserver = &observer;
803 } 803 }
804 804
805 template <typename Strategy> 805 template <typename Strategy>
806 void VisibleSelectionTemplate<Strategy>::clearChangeObserver() 806 void VisibleSelectionTemplate<Strategy>::clearChangeObserver()
807 { 807 {
808 ASSERT(m_changeObserver); 808 DCHECK(m_changeObserver);
809 m_changeObserver = nullptr; 809 m_changeObserver = nullptr;
810 } 810 }
811 811
812 template <typename Strategy> 812 template <typename Strategy>
813 void VisibleSelectionTemplate<Strategy>::didChange() 813 void VisibleSelectionTemplate<Strategy>::didChange()
814 { 814 {
815 if (m_changeObserver) 815 if (m_changeObserver)
816 m_changeObserver->didChangeVisibleSelection(); 816 m_changeObserver->didChangeVisibleSelection();
817 } 817 }
818 818
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 { 967 {
968 sel.showTreeForThis(); 968 sel.showTreeForThis();
969 } 969 }
970 970
971 void showTree(const blink::VisibleSelectionInFlatTree* sel) 971 void showTree(const blink::VisibleSelectionInFlatTree* sel)
972 { 972 {
973 if (sel) 973 if (sel)
974 sel->showTreeForThis(); 974 sel->showTreeForThis();
975 } 975 }
976 #endif 976 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698