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

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

Issue 2082503003: ASSERT -> DCHECK conversions in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2009 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
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 switch (anchorType()) { 128 switch (anchorType()) {
129 case PositionAnchorType::BeforeChildren: 129 case PositionAnchorType::BeforeChildren:
130 case PositionAnchorType::AfterChildren: 130 case PositionAnchorType::AfterChildren:
131 case PositionAnchorType::OffsetInAnchor: 131 case PositionAnchorType::OffsetInAnchor:
132 return m_anchorNode.get(); 132 return m_anchorNode.get();
133 case PositionAnchorType::BeforeAnchor: 133 case PositionAnchorType::BeforeAnchor:
134 case PositionAnchorType::AfterAnchor: 134 case PositionAnchorType::AfterAnchor:
135 return Strategy::parent(*m_anchorNode); 135 return Strategy::parent(*m_anchorNode);
136 } 136 }
137 ASSERT_NOT_REACHED(); 137 NOTREACHED();
138 return 0; 138 return 0;
139 } 139 }
140 140
141 template <typename Strategy> 141 template <typename Strategy>
142 int PositionTemplate<Strategy>::computeOffsetInContainerNode() const 142 int PositionTemplate<Strategy>::computeOffsetInContainerNode() const
143 { 143 {
144 if (!m_anchorNode) 144 if (!m_anchorNode)
145 return 0; 145 return 0;
146 146
147 switch (anchorType()) { 147 switch (anchorType()) {
148 case PositionAnchorType::BeforeChildren: 148 case PositionAnchorType::BeforeChildren:
149 return 0; 149 return 0;
150 case PositionAnchorType::AfterChildren: 150 case PositionAnchorType::AfterChildren:
151 return lastOffsetInNode(m_anchorNode.get()); 151 return lastOffsetInNode(m_anchorNode.get());
152 case PositionAnchorType::OffsetInAnchor: 152 case PositionAnchorType::OffsetInAnchor:
153 return minOffsetForNode(m_anchorNode.get(), m_offset); 153 return minOffsetForNode(m_anchorNode.get(), m_offset);
154 case PositionAnchorType::BeforeAnchor: 154 case PositionAnchorType::BeforeAnchor:
155 return Strategy::index(*m_anchorNode); 155 return Strategy::index(*m_anchorNode);
156 case PositionAnchorType::AfterAnchor: 156 case PositionAnchorType::AfterAnchor:
157 return Strategy::index(*m_anchorNode) + 1; 157 return Strategy::index(*m_anchorNode) + 1;
158 } 158 }
159 ASSERT_NOT_REACHED(); 159 NOTREACHED();
160 return 0; 160 return 0;
161 } 161 }
162 162
163 // Neighbor-anchored positions are invalid DOM positions, so they need to be 163 // Neighbor-anchored positions are invalid DOM positions, so they need to be
164 // fixed up before handing them off to the Range object. 164 // fixed up before handing them off to the Range object.
165 template <typename Strategy> 165 template <typename Strategy>
166 PositionTemplate<Strategy> PositionTemplate<Strategy>::parentAnchoredEquivalent( ) const 166 PositionTemplate<Strategy> PositionTemplate<Strategy>::parentAnchoredEquivalent( ) const
167 { 167 {
168 if (!m_anchorNode) 168 if (!m_anchorNode)
169 return PositionTemplate<Strategy>(); 169 return PositionTemplate<Strategy>();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return 0; 211 return 0;
212 case PositionAnchorType::AfterChildren: 212 case PositionAnchorType::AfterChildren:
213 return Strategy::lastChild(*m_anchorNode); 213 return Strategy::lastChild(*m_anchorNode);
214 case PositionAnchorType::OffsetInAnchor: 214 case PositionAnchorType::OffsetInAnchor:
215 return m_offset ? Strategy::childAt(*m_anchorNode, m_offset - 1) : 0; 215 return m_offset ? Strategy::childAt(*m_anchorNode, m_offset - 1) : 0;
216 case PositionAnchorType::BeforeAnchor: 216 case PositionAnchorType::BeforeAnchor:
217 return Strategy::previousSibling(*m_anchorNode); 217 return Strategy::previousSibling(*m_anchorNode);
218 case PositionAnchorType::AfterAnchor: 218 case PositionAnchorType::AfterAnchor:
219 return m_anchorNode.get(); 219 return m_anchorNode.get();
220 } 220 }
221 ASSERT_NOT_REACHED(); 221 NOTREACHED();
222 return 0; 222 return 0;
223 } 223 }
224 224
225 template <typename Strategy> 225 template <typename Strategy>
226 Node* PositionTemplate<Strategy>::computeNodeAfterPosition() const 226 Node* PositionTemplate<Strategy>::computeNodeAfterPosition() const
227 { 227 {
228 if (!m_anchorNode) 228 if (!m_anchorNode)
229 return 0; 229 return 0;
230 230
231 switch (anchorType()) { 231 switch (anchorType()) {
232 case PositionAnchorType::BeforeChildren: 232 case PositionAnchorType::BeforeChildren:
233 return Strategy::firstChild(*m_anchorNode); 233 return Strategy::firstChild(*m_anchorNode);
234 case PositionAnchorType::AfterChildren: 234 case PositionAnchorType::AfterChildren:
235 return 0; 235 return 0;
236 case PositionAnchorType::OffsetInAnchor: 236 case PositionAnchorType::OffsetInAnchor:
237 return Strategy::childAt(*m_anchorNode, m_offset); 237 return Strategy::childAt(*m_anchorNode, m_offset);
238 case PositionAnchorType::BeforeAnchor: 238 case PositionAnchorType::BeforeAnchor:
239 return m_anchorNode.get(); 239 return m_anchorNode.get();
240 case PositionAnchorType::AfterAnchor: 240 case PositionAnchorType::AfterAnchor:
241 return Strategy::nextSibling(*m_anchorNode); 241 return Strategy::nextSibling(*m_anchorNode);
242 } 242 }
243 ASSERT_NOT_REACHED(); 243 NOTREACHED();
244 return 0; 244 return 0;
245 } 245 }
246 246
247 // An implementation of |Range::firstNode()|. 247 // An implementation of |Range::firstNode()|.
248 template <typename Strategy> 248 template <typename Strategy>
249 Node* PositionTemplate<Strategy>::nodeAsRangeFirstNode() const 249 Node* PositionTemplate<Strategy>::nodeAsRangeFirstNode() const
250 { 250 {
251 if (!m_anchorNode) 251 if (!m_anchorNode)
252 return nullptr; 252 return nullptr;
253 if (!isOffsetInAnchor()) 253 if (!isOffsetInAnchor())
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 return m_offset == 0; 348 return m_offset == 0;
349 case PositionAnchorType::BeforeChildren: 349 case PositionAnchorType::BeforeChildren:
350 case PositionAnchorType::BeforeAnchor: 350 case PositionAnchorType::BeforeAnchor:
351 return true; 351 return true;
352 case PositionAnchorType::AfterChildren: 352 case PositionAnchorType::AfterChildren:
353 case PositionAnchorType::AfterAnchor: 353 case PositionAnchorType::AfterAnchor:
354 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead 354 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead
355 // of DOM tree version. 355 // of DOM tree version.
356 return !EditingStrategy::lastOffsetForEditing(anchorNode()); 356 return !EditingStrategy::lastOffsetForEditing(anchorNode());
357 } 357 }
358 ASSERT_NOT_REACHED(); 358 NOTREACHED();
359 return false; 359 return false;
360 } 360 }
361 361
362 template <typename Strategy> 362 template <typename Strategy>
363 bool PositionTemplate<Strategy>::atLastEditingPositionForNode() const 363 bool PositionTemplate<Strategy>::atLastEditingPositionForNode() const
364 { 364 {
365 if (isNull()) 365 if (isNull())
366 return true; 366 return true;
367 // TODO(yosin): Position after anchor shouldn't be considered as at the 367 // TODO(yosin): Position after anchor shouldn't be considered as at the
368 // first editing position for node since that position resides outside of 368 // first editing position for node since that position resides outside of
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 if (child) 574 if (child)
575 return Position(child->parentNode(), child->nodeIndex()); 575 return Position(child->parentNode(), child->nodeIndex());
576 if (!position.offsetInContainerNode()) 576 if (!position.offsetInContainerNode())
577 return Position(anchorNode, PositionAnchorType::BeforeChildren); 577 return Position(anchorNode, PositionAnchorType::BeforeChildren);
578 578
579 // |child| is null when the position is at the end of the children. 579 // |child| is null when the position is at the end of the children.
580 // <div>foo|</div> 580 // <div>foo|</div>
581 return Position(anchorNode, PositionAnchorType::AfterChildren); 581 return Position(anchorNode, PositionAnchorType::AfterChildren);
582 } 582 }
583 default: 583 default:
584 ASSERT_NOT_REACHED(); 584 NOTREACHED();
585 return Position(); 585 return Position();
586 } 586 }
587 } 587 }
588 588
589 #ifndef NDEBUG 589 #ifndef NDEBUG
590 590
591 template <typename Strategy> 591 template <typename Strategy>
592 void PositionTemplate<Strategy>::formatForDebugger(char* buffer, unsigned length ) const 592 void PositionTemplate<Strategy>::formatForDebugger(char* buffer, unsigned length ) const
593 { 593 {
594 StringBuilder result; 594 StringBuilder result;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 703
704 void showTree(const blink::Position* pos) 704 void showTree(const blink::Position* pos)
705 { 705 {
706 if (pos) 706 if (pos)
707 pos->showTreeForThis(); 707 pos->showTreeForThis();
708 else 708 else
709 fprintf(stderr, "Cannot showTree for (nil)\n"); 709 fprintf(stderr, "Cannot showTree for (nil)\n");
710 } 710 }
711 711
712 #endif 712 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EphemeralRange.cpp ('k') | third_party/WebKit/Source/core/editing/RenderedPosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698