OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All |
3 * rights reserved. | 3 * rights reserved. |
4 * Copyright (C) 2005 Alexey Proskuryakov. | 4 * Copyright (C) 2005 Alexey Proskuryakov. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 m_handledFirstLetter = false; | 525 m_handledFirstLetter = false; |
526 m_firstLetterText = nullptr; | 526 m_firstLetterText = nullptr; |
527 | 527 |
528 // how would this ever be? | 528 // how would this ever be? |
529 if (m_textState.positionNode()) | 529 if (m_textState.positionNode()) |
530 return; | 530 return; |
531 } | 531 } |
532 } | 532 } |
533 | 533 |
534 static bool hasVisibleTextNode(LayoutText* layoutObject) { | 534 static bool hasVisibleTextNode(LayoutText* layoutObject) { |
535 if (layoutObject->style()->visibility() == EVisibility::Visible) | 535 if (layoutObject->style()->visibility() == EVisibility::kVisible) |
536 return true; | 536 return true; |
537 | 537 |
538 if (!layoutObject->isTextFragment()) | 538 if (!layoutObject->isTextFragment()) |
539 return false; | 539 return false; |
540 | 540 |
541 LayoutTextFragment* fragment = toLayoutTextFragment(layoutObject); | 541 LayoutTextFragment* fragment = toLayoutTextFragment(layoutObject); |
542 if (!fragment->isRemainingTextLayoutObject()) | 542 if (!fragment->isRemainingTextLayoutObject()) |
543 return false; | 543 return false; |
544 | 544 |
545 DCHECK(fragment->firstLetterPseudoElement()); | 545 DCHECK(fragment->firstLetterPseudoElement()); |
546 LayoutObject* pseudoElementLayoutObject = | 546 LayoutObject* pseudoElementLayoutObject = |
547 fragment->firstLetterPseudoElement()->layoutObject(); | 547 fragment->firstLetterPseudoElement()->layoutObject(); |
548 return pseudoElementLayoutObject && | 548 return pseudoElementLayoutObject && |
549 pseudoElementLayoutObject->style()->visibility() == | 549 pseudoElementLayoutObject->style()->visibility() == |
550 EVisibility::Visible; | 550 EVisibility::kVisible; |
551 } | 551 } |
552 | 552 |
553 template <typename Strategy> | 553 template <typename Strategy> |
554 bool TextIteratorAlgorithm<Strategy>::handleTextNode() { | 554 bool TextIteratorAlgorithm<Strategy>::handleTextNode() { |
555 if (excludesAutofilledValue()) { | 555 if (excludesAutofilledValue()) { |
556 TextControlElement* control = enclosingTextControl(m_node); | 556 TextControlElement* control = enclosingTextControl(m_node); |
557 // For security reason, we don't expose suggested value if it is | 557 // For security reason, we don't expose suggested value if it is |
558 // auto-filled. | 558 // auto-filled. |
559 if (control && control->isAutofilled()) | 559 if (control && control->isAutofilled()) |
560 return true; | 560 return true; |
(...skipping 24 matching lines...) Expand all Loading... |
585 handleTextNodeFirstLetter(toLayoutTextFragment(layoutObject)); | 585 handleTextNodeFirstLetter(toLayoutTextFragment(layoutObject)); |
586 if (m_firstLetterText) { | 586 if (m_firstLetterText) { |
587 String firstLetter = m_firstLetterText->text(); | 587 String firstLetter = m_firstLetterText->text(); |
588 emitText(textNode, m_firstLetterText, m_offset, | 588 emitText(textNode, m_firstLetterText, m_offset, |
589 m_offset + firstLetter.length()); | 589 m_offset + firstLetter.length()); |
590 m_firstLetterText = nullptr; | 590 m_firstLetterText = nullptr; |
591 m_textBox = 0; | 591 m_textBox = 0; |
592 return false; | 592 return false; |
593 } | 593 } |
594 } | 594 } |
595 if (layoutObject->style()->visibility() != EVisibility::Visible && | 595 if (layoutObject->style()->visibility() != EVisibility::kVisible && |
596 !ignoresStyleVisibility()) | 596 !ignoresStyleVisibility()) |
597 return false; | 597 return false; |
598 int strLength = str.length(); | 598 int strLength = str.length(); |
599 int end = (textNode == m_endContainer) ? m_endOffset : INT_MAX; | 599 int end = (textNode == m_endContainer) ? m_endOffset : INT_MAX; |
600 int runEnd = std::min(strLength, end); | 600 int runEnd = std::min(strLength, end); |
601 | 601 |
602 if (runStart >= runEnd) | 602 if (runStart >= runEnd) |
603 return true; | 603 return true; |
604 | 604 |
605 emitText(textNode, textNode->layoutObject(), runStart, runEnd); | 605 emitText(textNode, textNode->layoutObject(), runStart, runEnd); |
606 return true; | 606 return true; |
607 } | 607 } |
608 | 608 |
609 if (layoutObject->firstTextBox()) | 609 if (layoutObject->firstTextBox()) |
610 m_textBox = layoutObject->firstTextBox(); | 610 m_textBox = layoutObject->firstTextBox(); |
611 | 611 |
612 bool shouldHandleFirstLetter = | 612 bool shouldHandleFirstLetter = |
613 !m_handledFirstLetter && layoutObject->isTextFragment() && !m_offset; | 613 !m_handledFirstLetter && layoutObject->isTextFragment() && !m_offset; |
614 if (shouldHandleFirstLetter) | 614 if (shouldHandleFirstLetter) |
615 handleTextNodeFirstLetter(toLayoutTextFragment(layoutObject)); | 615 handleTextNodeFirstLetter(toLayoutTextFragment(layoutObject)); |
616 | 616 |
617 if (!layoutObject->firstTextBox() && str.length() > 0 && | 617 if (!layoutObject->firstTextBox() && str.length() > 0 && |
618 !shouldHandleFirstLetter) { | 618 !shouldHandleFirstLetter) { |
619 if (layoutObject->style()->visibility() != EVisibility::Visible && | 619 if (layoutObject->style()->visibility() != EVisibility::kVisible && |
620 !ignoresStyleVisibility()) | 620 !ignoresStyleVisibility()) |
621 return false; | 621 return false; |
622 m_lastTextNodeEndedWithCollapsedSpace = | 622 m_lastTextNodeEndedWithCollapsedSpace = |
623 true; // entire block is collapsed space | 623 true; // entire block is collapsed space |
624 return true; | 624 return true; |
625 } | 625 } |
626 | 626 |
627 if (m_firstLetterText) | 627 if (m_firstLetterText) |
628 layoutObject = m_firstLetterText; | 628 layoutObject = m_firstLetterText; |
629 | 629 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 691 |
692 return runStart; | 692 return runStart; |
693 } | 693 } |
694 | 694 |
695 template <typename Strategy> | 695 template <typename Strategy> |
696 void TextIteratorAlgorithm<Strategy>::handleTextBox() { | 696 void TextIteratorAlgorithm<Strategy>::handleTextBox() { |
697 LayoutText* layoutObject = m_firstLetterText | 697 LayoutText* layoutObject = m_firstLetterText |
698 ? m_firstLetterText | 698 ? m_firstLetterText |
699 : toLayoutText(m_node->layoutObject()); | 699 : toLayoutText(m_node->layoutObject()); |
700 | 700 |
701 if (layoutObject->style()->visibility() != EVisibility::Visible && | 701 if (layoutObject->style()->visibility() != EVisibility::kVisible && |
702 !ignoresStyleVisibility()) { | 702 !ignoresStyleVisibility()) { |
703 m_textBox = nullptr; | 703 m_textBox = nullptr; |
704 } else { | 704 } else { |
705 String str = layoutObject->text(); | 705 String str = layoutObject->text(); |
706 unsigned start = m_offset; | 706 unsigned start = m_offset; |
707 unsigned end = (m_node == m_endContainer) | 707 unsigned end = (m_node == m_endContainer) |
708 ? static_cast<unsigned>(m_endOffset) | 708 ? static_cast<unsigned>(m_endOffset) |
709 : INT_MAX; | 709 : INT_MAX; |
710 while (m_textBox) { | 710 while (m_textBox) { |
711 unsigned textBoxStart = m_textBox->start(); | 711 unsigned textBoxStart = m_textBox->start(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 nextTextBox->getLineLayoutItem().isEqual(layoutObject)); | 760 nextTextBox->getLineLayoutItem().isEqual(layoutObject)); |
761 | 761 |
762 if (runStart < runEnd) { | 762 if (runStart < runEnd) { |
763 // Handle either a single newline character (which becomes a space), | 763 // Handle either a single newline character (which becomes a space), |
764 // or a run of characters that does not include a newline. | 764 // or a run of characters that does not include a newline. |
765 // This effectively translates newlines to spaces without copying the | 765 // This effectively translates newlines to spaces without copying the |
766 // text. | 766 // text. |
767 if (str[runStart] == '\n') { | 767 if (str[runStart] == '\n') { |
768 // We need to preserve new lines in case of PreLine. | 768 // We need to preserve new lines in case of PreLine. |
769 // See bug crbug.com/317365. | 769 // See bug crbug.com/317365. |
770 if (layoutObject->style()->whiteSpace() == EWhiteSpace::PreLine) | 770 if (layoutObject->style()->whiteSpace() == EWhiteSpace::kPreLine) |
771 spliceBuffer('\n', m_node, 0, runStart, runStart); | 771 spliceBuffer('\n', m_node, 0, runStart, runStart); |
772 else | 772 else |
773 spliceBuffer(spaceCharacter, m_node, 0, runStart, runStart + 1); | 773 spliceBuffer(spaceCharacter, m_node, 0, runStart, runStart + 1); |
774 m_offset = runStart + 1; | 774 m_offset = runStart + 1; |
775 } else { | 775 } else { |
776 size_t subrunEnd = str.find('\n', runStart); | 776 size_t subrunEnd = str.find('\n', runStart); |
777 if (subrunEnd == kNotFound || subrunEnd > runEnd) { | 777 if (subrunEnd == kNotFound || subrunEnd > runEnd) { |
778 subrunEnd = runEnd; | 778 subrunEnd = runEnd; |
779 runStart = restoreCollapsedLeadingSpace(runStart); | 779 runStart = restoreCollapsedLeadingSpace(runStart); |
780 subrunEnd = restoreCollapsedTrailingSpace(nextTextBox, subrunEnd); | 780 subrunEnd = restoreCollapsedTrailingSpace(nextTextBox, subrunEnd); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 | 825 |
826 if (!layoutObject->isRemainingTextLayoutObject()) | 826 if (!layoutObject->isRemainingTextLayoutObject()) |
827 return; | 827 return; |
828 | 828 |
829 FirstLetterPseudoElement* firstLetterElement = | 829 FirstLetterPseudoElement* firstLetterElement = |
830 layoutObject->firstLetterPseudoElement(); | 830 layoutObject->firstLetterPseudoElement(); |
831 if (!firstLetterElement) | 831 if (!firstLetterElement) |
832 return; | 832 return; |
833 | 833 |
834 LayoutObject* pseudoLayoutObject = firstLetterElement->layoutObject(); | 834 LayoutObject* pseudoLayoutObject = firstLetterElement->layoutObject(); |
835 if (pseudoLayoutObject->style()->visibility() != EVisibility::Visible && | 835 if (pseudoLayoutObject->style()->visibility() != EVisibility::kVisible && |
836 !ignoresStyleVisibility()) | 836 !ignoresStyleVisibility()) |
837 return; | 837 return; |
838 | 838 |
839 LayoutObject* firstLetter = pseudoLayoutObject->slowFirstChild(); | 839 LayoutObject* firstLetter = pseudoLayoutObject->slowFirstChild(); |
840 DCHECK(firstLetter); | 840 DCHECK(firstLetter); |
841 | 841 |
842 m_remainingTextBox = m_textBox; | 842 m_remainingTextBox = m_textBox; |
843 m_textBox = toLayoutText(firstLetter)->firstTextBox(); | 843 m_textBox = toLayoutText(firstLetter)->firstTextBox(); |
844 m_sortedTextBoxes.clear(); | 844 m_sortedTextBoxes.clear(); |
845 m_firstLetterText = toLayoutText(firstLetter); | 845 m_firstLetterText = toLayoutText(firstLetter); |
(...skipping 13 matching lines...) Expand all Loading... |
859 return true; | 859 return true; |
860 return false; | 860 return false; |
861 } | 861 } |
862 | 862 |
863 template <typename Strategy> | 863 template <typename Strategy> |
864 bool TextIteratorAlgorithm<Strategy>::handleReplacedElement() { | 864 bool TextIteratorAlgorithm<Strategy>::handleReplacedElement() { |
865 if (m_fullyClippedStack.top()) | 865 if (m_fullyClippedStack.top()) |
866 return false; | 866 return false; |
867 | 867 |
868 LayoutObject* layoutObject = m_node->layoutObject(); | 868 LayoutObject* layoutObject = m_node->layoutObject(); |
869 if (layoutObject->style()->visibility() != EVisibility::Visible && | 869 if (layoutObject->style()->visibility() != EVisibility::kVisible && |
870 !ignoresStyleVisibility()) | 870 !ignoresStyleVisibility()) |
871 return false; | 871 return false; |
872 | 872 |
873 if (emitsObjectReplacementCharacter()) { | 873 if (emitsObjectReplacementCharacter()) { |
874 spliceBuffer(objectReplacementCharacter, Strategy::parent(*m_node), m_node, | 874 spliceBuffer(objectReplacementCharacter, Strategy::parent(*m_node), m_node, |
875 0, 1); | 875 0, 1); |
876 return true; | 876 return true; |
877 } | 877 } |
878 | 878 |
879 if (m_behavior & TextIteratorCollapseTrailingSpace) { | 879 if (m_behavior & TextIteratorCollapseTrailingSpace) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 // now. | 1076 // now. |
1077 if (!m_startOffset) | 1077 if (!m_startOffset) |
1078 return false; | 1078 return false; |
1079 | 1079 |
1080 // If this node is unrendered or invisible the VisiblePosition checks below | 1080 // If this node is unrendered or invisible the VisiblePosition checks below |
1081 // won't have much meaning. | 1081 // won't have much meaning. |
1082 // Additionally, if the range we are iterating over contains huge sections of | 1082 // Additionally, if the range we are iterating over contains huge sections of |
1083 // unrendered content, we would create VisiblePositions on every call to this | 1083 // unrendered content, we would create VisiblePositions on every call to this |
1084 // function without this check. | 1084 // function without this check. |
1085 if (!m_node->layoutObject() || | 1085 if (!m_node->layoutObject() || |
1086 m_node->layoutObject()->style()->visibility() != EVisibility::Visible || | 1086 m_node->layoutObject()->style()->visibility() != EVisibility::kVisible || |
1087 (m_node->layoutObject()->isLayoutBlockFlow() && | 1087 (m_node->layoutObject()->isLayoutBlockFlow() && |
1088 !toLayoutBlock(m_node->layoutObject())->size().height() && | 1088 !toLayoutBlock(m_node->layoutObject())->size().height() && |
1089 !isHTMLBodyElement(*m_node))) | 1089 !isHTMLBodyElement(*m_node))) |
1090 return false; | 1090 return false; |
1091 | 1091 |
1092 // The startPos.isNotNull() check is needed because the start could be before | 1092 // The startPos.isNotNull() check is needed because the start could be before |
1093 // the body, and in that case we'll get null. We don't want to put in newlines | 1093 // the body, and in that case we'll get null. We don't want to put in newlines |
1094 // at the start in that case. | 1094 // at the start in that case. |
1095 // The currPos.isNotNull() check is needed because positions in non-HTML | 1095 // The currPos.isNotNull() check is needed because positions in non-HTML |
1096 // content (like SVG) do not have visible positions, and we don't want to emit | 1096 // content (like SVG) do not have visible positions, and we don't want to emit |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 String plainText(const EphemeralRangeInFlatTree& range, | 1443 String plainText(const EphemeralRangeInFlatTree& range, |
1444 TextIteratorBehaviorFlags behavior) { | 1444 TextIteratorBehaviorFlags behavior) { |
1445 return createPlainText<EditingInFlatTreeStrategy>(range, behavior); | 1445 return createPlainText<EditingInFlatTreeStrategy>(range, behavior); |
1446 } | 1446 } |
1447 | 1447 |
1448 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingStrategy>; | 1448 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingStrategy>; |
1449 template class CORE_TEMPLATE_EXPORT | 1449 template class CORE_TEMPLATE_EXPORT |
1450 TextIteratorAlgorithm<EditingInFlatTreeStrategy>; | 1450 TextIteratorAlgorithm<EditingInFlatTreeStrategy>; |
1451 | 1451 |
1452 } // namespace blink | 1452 } // namespace blink |
OLD | NEW |