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

Side by Side Diff: Source/core/editing/iterators/TextIterator.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
« no previous file with comments | « Source/core/editing/iterators/TextIterator.h ('k') | Source/core/inspector/InspectorCSSAgent.h » ('j') | 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 28 matching lines...) Expand all
39 #include "core/editing/iterators/CharacterIterator.h" 39 #include "core/editing/iterators/CharacterIterator.h"
40 #include "core/editing/iterators/WordAwareIterator.h" 40 #include "core/editing/iterators/WordAwareIterator.h"
41 #include "core/frame/FrameView.h" 41 #include "core/frame/FrameView.h"
42 #include "core/html/HTMLElement.h" 42 #include "core/html/HTMLElement.h"
43 #include "core/html/HTMLImageElement.h" 43 #include "core/html/HTMLImageElement.h"
44 #include "core/html/HTMLInputElement.h" 44 #include "core/html/HTMLInputElement.h"
45 #include "core/html/HTMLTextFormControlElement.h" 45 #include "core/html/HTMLTextFormControlElement.h"
46 #include "core/layout/LayoutTableCell.h" 46 #include "core/layout/LayoutTableCell.h"
47 #include "core/layout/LayoutTableRow.h" 47 #include "core/layout/LayoutTableRow.h"
48 #include "core/layout/LayoutTextControl.h" 48 #include "core/layout/LayoutTextControl.h"
49 #include "core/layout/LayoutTextFragment.h"
49 #include "core/layout/line/InlineTextBox.h" 50 #include "core/layout/line/InlineTextBox.h"
50 #include "core/rendering/RenderTextFragment.h"
51 #include "platform/fonts/Font.h" 51 #include "platform/fonts/Font.h"
52 #include "wtf/text/CString.h" 52 #include "wtf/text/CString.h"
53 #include "wtf/text/StringBuilder.h" 53 #include "wtf/text/StringBuilder.h"
54 #include <unicode/utf16.h> 54 #include <unicode/utf16.h>
55 55
56 using namespace WTF::Unicode; 56 using namespace WTF::Unicode;
57 57
58 namespace blink { 58 namespace blink {
59 59
60 using namespace HTMLNames; 60 using namespace HTMLNames;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 builder.append(string(), positionStartOffset() + position, lengthToAppen d); 439 builder.append(string(), positionStartOffset() + position, lengthToAppen d);
440 } 440 }
441 } 441 }
442 442
443 bool TextIterator::handleTextNode() 443 bool TextIterator::handleTextNode()
444 { 444 {
445 if (m_fullyClippedStack.top() && !m_ignoresStyleVisibility) 445 if (m_fullyClippedStack.top() && !m_ignoresStyleVisibility)
446 return false; 446 return false;
447 447
448 Text* textNode = toText(m_node); 448 Text* textNode = toText(m_node);
449 RenderText* renderer = textNode->renderer(); 449 LayoutText* renderer = textNode->renderer();
450 450
451 m_lastTextNode = textNode; 451 m_lastTextNode = textNode;
452 String str = renderer->text(); 452 String str = renderer->text();
453 453
454 // handle pre-formatted text 454 // handle pre-formatted text
455 if (!renderer->style()->collapseWhiteSpace()) { 455 if (!renderer->style()->collapseWhiteSpace()) {
456 int runStart = m_offset; 456 int runStart = m_offset;
457 if (m_lastTextNodeEndedWithCollapsedSpace && hasVisibleTextNode(renderer )) { 457 if (m_lastTextNodeEndedWithCollapsedSpace && hasVisibleTextNode(renderer )) {
458 emitCharacter(space, textNode, 0, runStart, runStart); 458 emitCharacter(space, textNode, 0, runStart, runStart);
459 return false; 459 return false;
460 } 460 }
461 if (!m_handledFirstLetter && renderer->isTextFragment() && !m_offset) { 461 if (!m_handledFirstLetter && renderer->isTextFragment() && !m_offset) {
462 handleTextNodeFirstLetter(toRenderTextFragment(renderer)); 462 handleTextNodeFirstLetter(toLayoutTextFragment(renderer));
463 if (m_firstLetterText) { 463 if (m_firstLetterText) {
464 String firstLetter = m_firstLetterText->text(); 464 String firstLetter = m_firstLetterText->text();
465 emitText(textNode, m_firstLetterText, m_offset, m_offset + first Letter.length()); 465 emitText(textNode, m_firstLetterText, m_offset, m_offset + first Letter.length());
466 m_firstLetterText = nullptr; 466 m_firstLetterText = nullptr;
467 m_textBox = 0; 467 m_textBox = 0;
468 return false; 468 return false;
469 } 469 }
470 } 470 }
471 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibil ity) 471 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibil ity)
472 return false; 472 return false;
473 int strLength = str.length(); 473 int strLength = str.length();
474 int end = (textNode == m_endContainer) ? m_endOffset : INT_MAX; 474 int end = (textNode == m_endContainer) ? m_endOffset : INT_MAX;
475 int runEnd = std::min(strLength, end); 475 int runEnd = std::min(strLength, end);
476 476
477 if (runStart >= runEnd) 477 if (runStart >= runEnd)
478 return true; 478 return true;
479 479
480 emitText(textNode, textNode->renderer(), runStart, runEnd); 480 emitText(textNode, textNode->renderer(), runStart, runEnd);
481 return true; 481 return true;
482 } 482 }
483 483
484 if (renderer->firstTextBox()) 484 if (renderer->firstTextBox())
485 m_textBox = renderer->firstTextBox(); 485 m_textBox = renderer->firstTextBox();
486 486
487 bool shouldHandleFirstLetter = !m_handledFirstLetter && renderer->isTextFrag ment() && !m_offset; 487 bool shouldHandleFirstLetter = !m_handledFirstLetter && renderer->isTextFrag ment() && !m_offset;
488 if (shouldHandleFirstLetter) 488 if (shouldHandleFirstLetter)
489 handleTextNodeFirstLetter(toRenderTextFragment(renderer)); 489 handleTextNodeFirstLetter(toLayoutTextFragment(renderer));
490 490
491 if (!renderer->firstTextBox() && str.length() > 0 && !shouldHandleFirstLette r) { 491 if (!renderer->firstTextBox() && str.length() > 0 && !shouldHandleFirstLette r) {
492 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibil ity) 492 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibil ity)
493 return false; 493 return false;
494 m_lastTextNodeEndedWithCollapsedSpace = true; // entire block is collaps ed space 494 m_lastTextNodeEndedWithCollapsedSpace = true; // entire block is collaps ed space
495 return true; 495 return true;
496 } 496 }
497 497
498 if (m_firstLetterText) 498 if (m_firstLetterText)
499 renderer = m_firstLetterText; 499 renderer = m_firstLetterText;
500 500
501 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text) 501 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text)
502 if (renderer->containsReversedText()) { 502 if (renderer->containsReversedText()) {
503 m_sortedTextBoxes.clear(); 503 m_sortedTextBoxes.clear();
504 for (InlineTextBox* textBox = renderer->firstTextBox(); textBox; textBox = textBox->nextTextBox()) { 504 for (InlineTextBox* textBox = renderer->firstTextBox(); textBox; textBox = textBox->nextTextBox()) {
505 m_sortedTextBoxes.append(textBox); 505 m_sortedTextBoxes.append(textBox);
506 } 506 }
507 std::sort(m_sortedTextBoxes.begin(), m_sortedTextBoxes.end(), InlineText Box::compareByStart); 507 std::sort(m_sortedTextBoxes.begin(), m_sortedTextBoxes.end(), InlineText Box::compareByStart);
508 m_sortedTextBoxesPosition = 0; 508 m_sortedTextBoxesPosition = 0;
509 m_textBox = m_sortedTextBoxes.isEmpty() ? 0 : m_sortedTextBoxes[0]; 509 m_textBox = m_sortedTextBoxes.isEmpty() ? 0 : m_sortedTextBoxes[0];
510 } 510 }
511 511
512 handleTextBox(); 512 handleTextBox();
513 return true; 513 return true;
514 } 514 }
515 515
516 void TextIterator::handleTextBox() 516 void TextIterator::handleTextBox()
517 { 517 {
518 RenderText* renderer = m_firstLetterText ? m_firstLetterText.get() : toRende rText(m_node->renderer()); 518 LayoutText* renderer = m_firstLetterText ? m_firstLetterText.get() : toLayou tText(m_node->renderer());
519 519
520 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibility) { 520 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibility) {
521 m_textBox = 0; 521 m_textBox = 0;
522 } else { 522 } else {
523 String str = renderer->text(); 523 String str = renderer->text();
524 unsigned start = m_offset; 524 unsigned start = m_offset;
525 unsigned end = (m_node == m_endContainer) ? static_cast<unsigned>(m_endO ffset) : INT_MAX; 525 unsigned end = (m_node == m_endContainer) ? static_cast<unsigned>(m_endO ffset) : INT_MAX;
526 while (m_textBox) { 526 while (m_textBox) {
527 unsigned textBoxStart = m_textBox->start(); 527 unsigned textBoxStart = m_textBox->start();
528 unsigned runStart = std::max(textBoxStart, start); 528 unsigned runStart = std::max(textBoxStart, start);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 605
606 if (!m_textBox && m_remainingTextBox) { 606 if (!m_textBox && m_remainingTextBox) {
607 m_textBox = m_remainingTextBox; 607 m_textBox = m_remainingTextBox;
608 m_remainingTextBox = 0; 608 m_remainingTextBox = 0;
609 m_firstLetterText = nullptr; 609 m_firstLetterText = nullptr;
610 m_offset = 0; 610 m_offset = 0;
611 handleTextBox(); 611 handleTextBox();
612 } 612 }
613 } 613 }
614 614
615 void TextIterator::handleTextNodeFirstLetter(RenderTextFragment* renderer) 615 void TextIterator::handleTextNodeFirstLetter(LayoutTextFragment* renderer)
616 { 616 {
617 m_handledFirstLetter = true; 617 m_handledFirstLetter = true;
618 618
619 if (!renderer->isRemainingTextRenderer()) 619 if (!renderer->isRemainingTextRenderer())
620 return; 620 return;
621 621
622 FirstLetterPseudoElement* firstLetterElement = renderer->firstLetterPseudoEl ement(); 622 FirstLetterPseudoElement* firstLetterElement = renderer->firstLetterPseudoEl ement();
623 if (!firstLetterElement) 623 if (!firstLetterElement)
624 return; 624 return;
625 625
626 LayoutObject* pseudoRenderer = firstLetterElement->renderer(); 626 LayoutObject* pseudoRenderer = firstLetterElement->renderer();
627 if (pseudoRenderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisib ility) 627 if (pseudoRenderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisib ility)
628 return; 628 return;
629 629
630 LayoutObject* firstLetter = pseudoRenderer->slowFirstChild(); 630 LayoutObject* firstLetter = pseudoRenderer->slowFirstChild();
631 ASSERT(firstLetter); 631 ASSERT(firstLetter);
632 632
633 m_remainingTextBox = m_textBox; 633 m_remainingTextBox = m_textBox;
634 m_textBox = toRenderText(firstLetter)->firstTextBox(); 634 m_textBox = toLayoutText(firstLetter)->firstTextBox();
635 m_sortedTextBoxes.clear(); 635 m_sortedTextBoxes.clear();
636 m_firstLetterText = toRenderText(firstLetter); 636 m_firstLetterText = toLayoutText(firstLetter);
637 } 637 }
638 638
639 bool TextIterator::supportsAltText(Node* m_node) 639 bool TextIterator::supportsAltText(Node* m_node)
640 { 640 {
641 if (!m_node->isHTMLElement()) 641 if (!m_node->isHTMLElement())
642 return false; 642 return false;
643 HTMLElement& element = toHTMLElement(*m_node); 643 HTMLElement& element = toHTMLElement(*m_node);
644 644
645 // FIXME: Add isSVGImageElement. 645 // FIXME: Add isSVGImageElement.
646 if (isHTMLImageElement(element)) 646 if (isHTMLImageElement(element))
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 return true; 698 return true;
699 } 699 }
700 } 700 }
701 701
702 m_textLength = 0; 702 m_textLength = 0;
703 m_lastCharacter = 0; 703 m_lastCharacter = 0;
704 704
705 return true; 705 return true;
706 } 706 }
707 707
708 bool TextIterator::hasVisibleTextNode(RenderText* renderer) 708 bool TextIterator::hasVisibleTextNode(LayoutText* renderer)
709 { 709 {
710 if (renderer->style()->visibility() == VISIBLE) 710 if (renderer->style()->visibility() == VISIBLE)
711 return true; 711 return true;
712 712
713 if (!renderer->isTextFragment()) 713 if (!renderer->isTextFragment())
714 return false; 714 return false;
715 715
716 RenderTextFragment* fragment = toRenderTextFragment(renderer); 716 LayoutTextFragment* fragment = toLayoutTextFragment(renderer);
717 if (!fragment->isRemainingTextRenderer()) 717 if (!fragment->isRemainingTextRenderer())
718 return false; 718 return false;
719 719
720 ASSERT(fragment->firstLetterPseudoElement()); 720 ASSERT(fragment->firstLetterPseudoElement());
721 LayoutObject* pseudoElementRenderer = fragment->firstLetterPseudoElement()-> renderer(); 721 LayoutObject* pseudoElementRenderer = fragment->firstLetterPseudoElement()-> renderer();
722 return pseudoElementRenderer && pseudoElementRenderer->style()->visibility() == VISIBLE; 722 return pseudoElementRenderer && pseudoElementRenderer->style()->visibility() == VISIBLE;
723 } 723 }
724 724
725 bool TextIterator::shouldEmitTabBeforeNode(Node* node) 725 bool TextIterator::shouldEmitTabBeforeNode(Node* node)
726 { 726 {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 // remember information with which to construct the TextIterator::characters () and length() 1004 // remember information with which to construct the TextIterator::characters () and length()
1005 m_singleCharacterBuffer = c; 1005 m_singleCharacterBuffer = c;
1006 ASSERT(m_singleCharacterBuffer); 1006 ASSERT(m_singleCharacterBuffer);
1007 m_textLength = 1; 1007 m_textLength = 1;
1008 1008
1009 // remember some iteration state 1009 // remember some iteration state
1010 m_lastTextNodeEndedWithCollapsedSpace = false; 1010 m_lastTextNodeEndedWithCollapsedSpace = false;
1011 m_lastCharacter = c; 1011 m_lastCharacter = c;
1012 } 1012 }
1013 1013
1014 void TextIterator::emitText(Node* textNode, RenderText* renderer, int textStartO ffset, int textEndOffset) 1014 void TextIterator::emitText(Node* textNode, LayoutText* renderer, int textStartO ffset, int textEndOffset)
1015 { 1015 {
1016 m_text = m_emitsOriginalText ? renderer->originalText() : renderer->text(); 1016 m_text = m_emitsOriginalText ? renderer->originalText() : renderer->text();
1017 ASSERT(!m_text.isEmpty()); 1017 ASSERT(!m_text.isEmpty());
1018 ASSERT(0 <= textStartOffset && textStartOffset < static_cast<int>(m_text.len gth())); 1018 ASSERT(0 <= textStartOffset && textStartOffset < static_cast<int>(m_text.len gth()));
1019 ASSERT(0 <= textEndOffset && textEndOffset <= static_cast<int>(m_text.length ())); 1019 ASSERT(0 <= textEndOffset && textEndOffset <= static_cast<int>(m_text.length ()));
1020 ASSERT(textStartOffset <= textEndOffset); 1020 ASSERT(textStartOffset <= textEndOffset);
1021 1021
1022 m_positionNode = textNode; 1022 m_positionNode = textNode;
1023 m_positionOffsetBaseNode = nullptr; 1023 m_positionOffsetBaseNode = nullptr;
1024 m_positionStartOffset = textStartOffset; 1024 m_positionStartOffset = textStartOffset;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 return createPlainText(it); 1177 return createPlainText(it);
1178 } 1178 }
1179 1179
1180 String plainText(const Position& start, const Position& end, TextIteratorBehavio rFlags behavior) 1180 String plainText(const Position& start, const Position& end, TextIteratorBehavio rFlags behavior)
1181 { 1181 {
1182 TextIterator it(start, end, behavior); 1182 TextIterator it(start, end, behavior);
1183 return createPlainText(it); 1183 return createPlainText(it);
1184 } 1184 }
1185 1185
1186 } 1186 }
OLDNEW
« no previous file with comments | « Source/core/editing/iterators/TextIterator.h ('k') | Source/core/inspector/InspectorCSSAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698