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

Side by Side Diff: Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp

Issue 940373003: Rename RenderText to LayoutText (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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, 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 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" 28 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h"
29 29
30 #include "core/dom/FirstLetterPseudoElement.h" 30 #include "core/dom/FirstLetterPseudoElement.h"
31 #include "core/editing/htmlediting.h" 31 #include "core/editing/htmlediting.h"
32 #include "core/editing/iterators/TextIterator.h" 32 #include "core/editing/iterators/TextIterator.h"
33 #include "core/html/HTMLElement.h" 33 #include "core/html/HTMLElement.h"
34 #include "core/html/HTMLTextFormControlElement.h" 34 #include "core/html/HTMLTextFormControlElement.h"
35 #include "core/rendering/RenderTextFragment.h" 35 #include "core/layout/LayoutTextFragment.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 static int collapsedSpaceLength(RenderText* renderer, int textEnd) 39 static int collapsedSpaceLength(LayoutText* renderer, int textEnd)
40 { 40 {
41 const String& text = renderer->text(); 41 const String& text = renderer->text();
42 int length = text.length(); 42 int length = text.length();
43 for (int i = textEnd; i < length; ++i) { 43 for (int i = textEnd; i < length; ++i) {
44 if (!renderer->style()->isCollapsibleWhiteSpace(text[i])) 44 if (!renderer->style()->isCollapsibleWhiteSpace(text[i]))
45 return i - textEnd; 45 return i - textEnd;
46 } 46 }
47 47
48 return length - textEnd; 48 return length - textEnd;
49 } 49 }
50 50
51 static int maxOffsetIncludingCollapsedSpaces(Node* node) 51 static int maxOffsetIncludingCollapsedSpaces(Node* node)
52 { 52 {
53 int offset = caretMaxOffset(node); 53 int offset = caretMaxOffset(node);
54 54
55 if (node->renderer() && node->renderer()->isText()) 55 if (node->renderer() && node->renderer()->isText())
56 offset += collapsedSpaceLength(toRenderText(node->renderer()), offset); 56 offset += collapsedSpaceLength(toLayoutText(node->renderer()), offset);
57 57
58 return offset; 58 return offset;
59 } 59 }
60 60
61 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r, TextIteratorBehaviorFlags behavior) 61 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r, TextIteratorBehaviorFlags behavior)
62 : m_node(nullptr) 62 : m_node(nullptr)
63 , m_offset(0) 63 , m_offset(0)
64 , m_handledNode(false) 64 , m_handledNode(false)
65 , m_handledChildren(false) 65 , m_handledChildren(false)
66 , m_startNode(nullptr) 66 , m_startNode(nullptr)
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 if (m_positionNode) 247 if (m_positionNode)
248 return; 248 return;
249 } 249 }
250 } 250 }
251 251
252 bool SimplifiedBackwardsTextIterator::handleTextNode() 252 bool SimplifiedBackwardsTextIterator::handleTextNode()
253 { 253 {
254 int startOffset; 254 int startOffset;
255 int offsetInNode; 255 int offsetInNode;
256 RenderText* renderer = handleFirstLetter(startOffset, offsetInNode); 256 LayoutText* renderer = handleFirstLetter(startOffset, offsetInNode);
257 if (!renderer) 257 if (!renderer)
258 return true; 258 return true;
259 259
260 String text = renderer->text(); 260 String text = renderer->text();
261 if (!renderer->firstTextBox() && text.length() > 0) 261 if (!renderer->firstTextBox() && text.length() > 0)
262 return true; 262 return true;
263 263
264 m_positionEndOffset = m_offset; 264 m_positionEndOffset = m_offset;
265 m_offset = startOffset + offsetInNode; 265 m_offset = startOffset + offsetInNode;
266 m_positionNode = m_node; 266 m_positionNode = m_node;
267 m_positionStartOffset = m_offset; 267 m_positionStartOffset = m_offset;
268 268
269 ASSERT(0 <= m_positionStartOffset - offsetInNode && m_positionStartOffset - offsetInNode <= static_cast<int>(text.length())); 269 ASSERT(0 <= m_positionStartOffset - offsetInNode && m_positionStartOffset - offsetInNode <= static_cast<int>(text.length()));
270 ASSERT(1 <= m_positionEndOffset - offsetInNode && m_positionEndOffset - offs etInNode <= static_cast<int>(text.length())); 270 ASSERT(1 <= m_positionEndOffset - offsetInNode && m_positionEndOffset - offs etInNode <= static_cast<int>(text.length()));
271 ASSERT(m_positionStartOffset <= m_positionEndOffset); 271 ASSERT(m_positionStartOffset <= m_positionEndOffset);
272 272
273 m_textLength = m_positionEndOffset - m_positionStartOffset; 273 m_textLength = m_positionEndOffset - m_positionStartOffset;
274 m_textOffset = m_positionStartOffset - offsetInNode; 274 m_textOffset = m_positionStartOffset - offsetInNode;
275 m_textContainer = text; 275 m_textContainer = text;
276 m_singleCharacterBuffer = 0; 276 m_singleCharacterBuffer = 0;
277 RELEASE_ASSERT(static_cast<unsigned>(m_textOffset + m_textLength) <= text.le ngth()); 277 RELEASE_ASSERT(static_cast<unsigned>(m_textOffset + m_textLength) <= text.le ngth());
278 278
279 return !m_shouldHandleFirstLetter; 279 return !m_shouldHandleFirstLetter;
280 } 280 }
281 281
282 RenderText* SimplifiedBackwardsTextIterator::handleFirstLetter(int& startOffset, int& offsetInNode) 282 LayoutText* SimplifiedBackwardsTextIterator::handleFirstLetter(int& startOffset, int& offsetInNode)
283 { 283 {
284 RenderText* renderer = toRenderText(m_node->renderer()); 284 LayoutText* renderer = toLayoutText(m_node->renderer());
285 startOffset = (m_node == m_startNode) ? m_startOffset : 0; 285 startOffset = (m_node == m_startNode) ? m_startOffset : 0;
286 286
287 if (!renderer->isTextFragment()) { 287 if (!renderer->isTextFragment()) {
288 offsetInNode = 0; 288 offsetInNode = 0;
289 return renderer; 289 return renderer;
290 } 290 }
291 291
292 RenderTextFragment* fragment = toRenderTextFragment(renderer); 292 LayoutTextFragment* fragment = toLayoutTextFragment(renderer);
293 int offsetAfterFirstLetter = fragment->start(); 293 int offsetAfterFirstLetter = fragment->start();
294 if (startOffset >= offsetAfterFirstLetter) { 294 if (startOffset >= offsetAfterFirstLetter) {
295 ASSERT(!m_shouldHandleFirstLetter); 295 ASSERT(!m_shouldHandleFirstLetter);
296 offsetInNode = offsetAfterFirstLetter; 296 offsetInNode = offsetAfterFirstLetter;
297 return renderer; 297 return renderer;
298 } 298 }
299 299
300 if (!m_shouldHandleFirstLetter && offsetAfterFirstLetter < m_offset) { 300 if (!m_shouldHandleFirstLetter && offsetAfterFirstLetter < m_offset) {
301 m_shouldHandleFirstLetter = true; 301 m_shouldHandleFirstLetter = true;
302 offsetInNode = offsetAfterFirstLetter; 302 offsetInNode = offsetAfterFirstLetter;
303 return renderer; 303 return renderer;
304 } 304 }
305 305
306 m_shouldHandleFirstLetter = false; 306 m_shouldHandleFirstLetter = false;
307 offsetInNode = 0; 307 offsetInNode = 0;
308 308
309 ASSERT(fragment->isRemainingTextRenderer()); 309 ASSERT(fragment->isRemainingTextRenderer());
310 ASSERT(fragment->firstLetterPseudoElement()); 310 ASSERT(fragment->firstLetterPseudoElement());
311 311
312 LayoutObject* pseudoElementRenderer = fragment->firstLetterPseudoElement()-> renderer(); 312 LayoutObject* pseudoElementRenderer = fragment->firstLetterPseudoElement()-> renderer();
313 ASSERT(pseudoElementRenderer); 313 ASSERT(pseudoElementRenderer);
314 ASSERT(pseudoElementRenderer->slowFirstChild()); 314 ASSERT(pseudoElementRenderer->slowFirstChild());
315 RenderText* firstLetterRenderer = toRenderText(pseudoElementRenderer->slowFi rstChild()); 315 LayoutText* firstLetterRenderer = toLayoutText(pseudoElementRenderer->slowFi rstChild());
316 316
317 m_offset = firstLetterRenderer->caretMaxOffset(); 317 m_offset = firstLetterRenderer->caretMaxOffset();
318 m_offset += collapsedSpaceLength(firstLetterRenderer, m_offset); 318 m_offset += collapsedSpaceLength(firstLetterRenderer, m_offset);
319 319
320 return firstLetterRenderer; 320 return firstLetterRenderer;
321 } 321 }
322 322
323 bool SimplifiedBackwardsTextIterator::handleReplacedElement() 323 bool SimplifiedBackwardsTextIterator::handleReplacedElement()
324 { 324 {
325 unsigned index = m_node->nodeIndex(); 325 unsigned index = m_node->nodeIndex();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 396 }
397 397
398 Position SimplifiedBackwardsTextIterator::endPosition() const 398 Position SimplifiedBackwardsTextIterator::endPosition() const
399 { 399 {
400 if (m_positionNode) 400 if (m_positionNode)
401 return createLegacyEditingPosition(m_positionNode, m_positionEndOffset); 401 return createLegacyEditingPosition(m_positionNode, m_positionEndOffset);
402 return createLegacyEditingPosition(m_startNode, m_startOffset); 402 return createLegacyEditingPosition(m_startNode, m_startOffset);
403 } 403 }
404 404
405 } // namespace blink 405 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/iterators/SimplifiedBackwardsTextIterator.h ('k') | Source/core/editing/iterators/TextIterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698