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

Side by Side Diff: Source/core/editing/TextIterator.cpp

Issue 210363006: Add a constructor to TextIterator taking two Positions as iteration range. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/TextIterator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
3 * Copyright (C) 2005 Alexey Proskuryakov. 3 * Copyright (C) 2005 Alexey Proskuryakov.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // -------- 240 // --------
241 241
242 TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio r) 242 TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio r)
243 : m_shadowDepth(0) 243 : m_shadowDepth(0)
244 , m_startContainer(0) 244 , m_startContainer(0)
245 , m_startOffset(0) 245 , m_startOffset(0)
246 , m_endContainer(0) 246 , m_endContainer(0)
247 , m_endOffset(0) 247 , m_endOffset(0)
248 , m_positionNode(0) 248 , m_positionNode(0)
249 , m_textLength(0) 249 , m_textLength(0)
250 , m_needsAnotherNewline(false)
251 , m_textBox(0)
250 , m_remainingTextBox(0) 252 , m_remainingTextBox(0)
251 , m_firstLetterText(0) 253 , m_firstLetterText(0)
254 , m_lastTextNode(0)
255 , m_lastTextNodeEndedWithCollapsedSpace(false)
256 , m_lastCharacter(0)
252 , m_sortedTextBoxesPosition(0) 257 , m_sortedTextBoxesPosition(0)
258 , m_hasEmitted(false)
253 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions) 259 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions)
254 , m_entersTextControls(behavior & TextIteratorEntersTextControls) 260 , m_entersTextControls(behavior & TextIteratorEntersTextControls)
255 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) 261 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText)
256 , m_handledFirstLetter(false) 262 , m_handledFirstLetter(false)
257 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) 263 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility)
258 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) 264 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
259 , m_shouldStop(false) 265 , m_shouldStop(false)
260 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) 266 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
261 , m_entersAuthorShadowRoots(behavior & TextIteratorEntersAuthorShadowRoots) 267 , m_entersAuthorShadowRoots(behavior & TextIteratorEntersAuthorShadowRoots)
262 { 268 {
263 if (!range) 269 if (range)
264 return; 270 initialize(range->startPosition(), range->endPosition());
271 }
265 272
266 // get and validate the range endpoints 273 TextIterator::TextIterator(const Position& start, const Position& end, TextItera torBehaviorFlags behavior)
267 Node* startContainer = range->startContainer(); 274 : m_shadowDepth(0)
275 , m_startContainer(0)
276 , m_startOffset(0)
277 , m_endContainer(0)
278 , m_endOffset(0)
279 , m_positionNode(0)
280 , m_textLength(0)
281 , m_needsAnotherNewline(false)
282 , m_textBox(0)
283 , m_remainingTextBox(0)
284 , m_firstLetterText(0)
285 , m_lastTextNode(0)
286 , m_lastTextNodeEndedWithCollapsedSpace(false)
287 , m_lastCharacter(0)
288 , m_sortedTextBoxesPosition(0)
289 , m_hasEmitted(false)
290 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions)
291 , m_entersTextControls(behavior & TextIteratorEntersTextControls)
292 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText)
293 , m_handledFirstLetter(false)
294 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility)
295 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
296 , m_shouldStop(false)
297 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
298 , m_entersAuthorShadowRoots(behavior & TextIteratorEntersAuthorShadowRoots)
yosin_UTC9 2014/03/26 01:08:02 Once Blink incorporate C++11 delegating constructo
Yuta Kitamura 2014/03/26 01:58:58 Yup; actually this long initializer list is kind o
299 {
300 initialize(start, end);
301 }
302
303 void TextIterator::initialize(const Position& start, const Position& end)
304 {
305 ASSERT(comparePositions(start, end) <= 0);
306
307 // Get and validate |start| and |end|.
308 Node* startContainer = start.containerNode();
268 if (!startContainer) 309 if (!startContainer)
269 return; 310 return;
270 int startOffset = range->startOffset(); 311 int startOffset = start.computeOffsetInContainerNode();
271 Node* endContainer = range->endContainer(); 312 Node* endContainer = end.containerNode();
272 int endOffset = range->endOffset(); 313 if (!endContainer)
314 return;
315 int endOffset = end.computeOffsetInContainerNode();
273 316
274 // Callers should be handing us well-formed ranges. If we discover that this isn't 317 // Remember the range - this does not change.
275 // the case, we could consider changing this assertion to an early return.
276 ASSERT(range->boundaryPointsValid());
277
278 // remember range - this does not change
279 m_startContainer = startContainer; 318 m_startContainer = startContainer;
280 m_startOffset = startOffset; 319 m_startOffset = startOffset;
281 m_endContainer = endContainer; 320 m_endContainer = endContainer;
282 m_endOffset = endOffset; 321 m_endOffset = endOffset;
283 322
284 // set up the current node for processing 323 // Set up the current node for processing.
285 m_node = range->firstNode(); 324 if (startContainer->offsetInCharacters())
325 m_node = startContainer;
326 else if (Node* child = startContainer->traverseToChildAt(startOffset))
327 m_node = child;
328 else if (!startOffset)
329 m_node = startContainer;
330 else
331 m_node = NodeTraversal::nextSkippingChildren(*startContainer);
332
286 if (!m_node) 333 if (!m_node)
287 return; 334 return;
335
288 setUpFullyClippedStack(m_fullyClippedStack, m_node); 336 setUpFullyClippedStack(m_fullyClippedStack, m_node);
289 m_offset = m_node == m_startContainer ? m_startOffset : 0; 337 m_offset = m_node == m_startContainer ? m_startOffset : 0;
290 m_iterationProgress = HandledNone; 338 m_iterationProgress = HandledNone;
291 339
292 // calculate first out of bounds node 340 // Calculate first out of bounds node.
293 m_pastEndNode = nextInPreOrderCrossingShadowBoundaries(endContainer, endOffs et); 341 m_pastEndNode = nextInPreOrderCrossingShadowBoundaries(endContainer, endOffs et);
294 342
295 // initialize node processing state 343 // Identify the first run.
296 m_needsAnotherNewline = false;
297 m_textBox = 0;
298
299 // initialize record of previous node processing
300 m_hasEmitted = false;
301 m_lastTextNode = 0;
302 m_lastTextNodeEndedWithCollapsedSpace = false;
303 m_lastCharacter = 0;
304
305 // identify the first run
306 advance(); 344 advance();
307 } 345 }
308 346
309 TextIterator::~TextIterator() 347 TextIterator::~TextIterator()
310 { 348 {
311 } 349 }
312 350
313 void TextIterator::advance() 351 void TextIterator::advance()
314 { 352 {
315 if (m_shouldStop) 353 if (m_shouldStop)
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 if (!matchLength) 2119 if (!matchLength)
2082 return collapsedToBoundary(range, !(options & Backwards)); 2120 return collapsedToBoundary(range, !(options & Backwards));
2083 } 2121 }
2084 2122
2085 // Then, find the document position of the start and the end of the text. 2123 // Then, find the document position of the start and the end of the text.
2086 CharacterIterator computeRangeIterator(range, TextIteratorEntersTextControls | TextIteratorEntersAuthorShadowRoots); 2124 CharacterIterator computeRangeIterator(range, TextIteratorEntersTextControls | TextIteratorEntersAuthorShadowRoots);
2087 return characterSubrange(computeRangeIterator, matchStart, matchLength); 2125 return characterSubrange(computeRangeIterator, matchStart, matchLength);
2088 } 2126 }
2089 2127
2090 } 2128 }
OLDNEW
« no previous file with comments | « Source/core/editing/TextIterator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698