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

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

Issue 1041463003: Remove methods of TextIterator that take Range objects (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add assertions Created 5 years, 8 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 for (Node* node = rangeEndContainer; node; node = node->parentOrShadowHostNo de()) { 71 for (Node* node = rangeEndContainer; node; node = node->parentOrShadowHostNo de()) {
72 if (Node* next = node->nextSibling()) 72 if (Node* next = node->nextSibling())
73 return next; 73 return next;
74 } 74 }
75 return 0; 75 return 0;
76 } 76 }
77 77
78 // -------- 78 // --------
79 79
80 TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio r)
81 : m_startContainer(nullptr)
82 , m_startOffset(0)
83 , m_endContainer(nullptr)
84 , m_endOffset(0)
85 , m_positionNode(nullptr)
86 , m_textLength(0)
87 , m_needsAnotherNewline(false)
88 , m_textBox(0)
89 , m_remainingTextBox(0)
90 , m_firstLetterText(nullptr)
91 , m_lastTextNode(nullptr)
92 , m_lastTextNodeEndedWithCollapsedSpace(false)
93 , m_lastCharacter(0)
94 , m_sortedTextBoxesPosition(0)
95 , m_hasEmitted(false)
96 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions)
97 , m_entersTextControls(behavior & TextIteratorEntersTextControls)
98 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText)
99 , m_handledFirstLetter(false)
100 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility)
101 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
102 , m_shouldStop(false)
103 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
104 , m_entersOpenShadowRoots(behavior & TextIteratorEntersOpenShadowRoots)
105 , m_emitsObjectReplacementCharacter(behavior & TextIteratorEmitsObjectReplac ementCharacter)
106 , m_breaksAtReplacedElement(!(behavior & TextIteratorDoesNotBreakAtReplacedE lement))
107 {
108 if (range)
109 initialize(range->startPosition(), range->endPosition());
110 }
111
112 TextIterator::TextIterator(const Position& start, const Position& end, TextItera torBehaviorFlags behavior) 80 TextIterator::TextIterator(const Position& start, const Position& end, TextItera torBehaviorFlags behavior)
113 : m_startContainer(nullptr) 81 : m_startContainer(nullptr)
114 , m_startOffset(0) 82 , m_startOffset(0)
115 , m_endContainer(nullptr) 83 , m_endContainer(nullptr)
116 , m_endOffset(0) 84 , m_endOffset(0)
117 , m_positionNode(nullptr) 85 , m_positionNode(nullptr)
118 , m_textLength(0) 86 , m_textLength(0)
119 , m_needsAnotherNewline(false) 87 , m_needsAnotherNewline(false)
120 , m_textBox(0) 88 , m_textBox(0)
121 , m_remainingTextBox(0) 89 , m_remainingTextBox(0)
122 , m_firstLetterText(nullptr) 90 , m_firstLetterText(nullptr)
123 , m_lastTextNode(nullptr) 91 , m_lastTextNode(nullptr)
124 , m_lastTextNodeEndedWithCollapsedSpace(false) 92 , m_lastTextNodeEndedWithCollapsedSpace(false)
125 , m_lastCharacter(0) 93 , m_lastCharacter(0)
126 , m_sortedTextBoxesPosition(0) 94 , m_sortedTextBoxesPosition(0)
127 , m_hasEmitted(false) 95 , m_hasEmitted(false)
128 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions) 96 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions)
129 , m_entersTextControls(behavior & TextIteratorEntersTextControls) 97 , m_entersTextControls(behavior & TextIteratorEntersTextControls)
130 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) 98 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText)
131 , m_handledFirstLetter(false) 99 , m_handledFirstLetter(false)
132 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) 100 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility)
133 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) 101 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
134 , m_shouldStop(false) 102 , m_shouldStop(false)
135 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) 103 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
136 , m_entersOpenShadowRoots(behavior & TextIteratorEntersOpenShadowRoots) 104 , m_entersOpenShadowRoots(behavior & TextIteratorEntersOpenShadowRoots)
137 , m_emitsObjectReplacementCharacter(behavior & TextIteratorEmitsObjectReplac ementCharacter) 105 , m_emitsObjectReplacementCharacter(behavior & TextIteratorEmitsObjectReplac ementCharacter)
138 , m_breaksAtReplacedElement(!(behavior & TextIteratorDoesNotBreakAtReplacedE lement)) 106 , m_breaksAtReplacedElement(!(behavior & TextIteratorDoesNotBreakAtReplacedE lement))
139 { 107 {
108 ASSERT(start.isNotNull());
109 ASSERT(end.isNotNull());
140 initialize(start, end); 110 initialize(start, end);
141 } 111 }
142 112
143 void TextIterator::initialize(const Position& start, const Position& end) 113 void TextIterator::initialize(const Position& start, const Position& end)
144 { 114 {
145 ASSERT(comparePositions(start, end) <= 0); 115 ASSERT(comparePositions(start, end) <= 0);
146 116
147 // Get and validate |start| and |end|. 117 // Get and validate |start| and |end|.
148 Node* startContainer = start.containerNode(); 118 Node* startContainer = start.containerNode();
149 if (!startContainer) 119 if (!startContainer)
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 Position TextIterator::startPosition() const 1073 Position TextIterator::startPosition() const
1104 { 1074 {
1105 return createLegacyEditingPosition(startContainer(), startOffset()); 1075 return createLegacyEditingPosition(startContainer(), startOffset());
1106 } 1076 }
1107 1077
1108 Position TextIterator::endPosition() const 1078 Position TextIterator::endPosition() const
1109 { 1079 {
1110 return createLegacyEditingPosition(endContainer(), endOffset()); 1080 return createLegacyEditingPosition(endContainer(), endOffset());
1111 } 1081 }
1112 1082
1113 int TextIterator::rangeLength(const Range* r, bool forSelectionPreservation)
1114 {
1115 int length = 0;
1116 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character;
1117 if (forSelectionPreservation)
1118 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions;
1119 for (TextIterator it(r, behaviorFlags); !it.atEnd(); it.advance())
1120 length += it.length();
1121
1122 return length;
1123 }
1124
1125 int TextIterator::rangeLength(const Position& start, const Position& end, bool f orSelectionPreservation) 1083 int TextIterator::rangeLength(const Position& start, const Position& end, bool f orSelectionPreservation)
1126 { 1084 {
1127 int length = 0; 1085 int length = 0;
1128 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character; 1086 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character;
1129 if (forSelectionPreservation) 1087 if (forSelectionPreservation)
1130 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; 1088 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions;
1131 for (TextIterator it(start, end, behaviorFlags); !it.atEnd(); it.advance()) 1089 for (TextIterator it(start, end, behaviorFlags); !it.atEnd(); it.advance())
1132 length += it.length(); 1090 length += it.length();
1133 1091
1134 return length; 1092 return length;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 } 1124 }
1167 1125
1168 if (!bufferLength) 1126 if (!bufferLength)
1169 return emptyString(); 1127 return emptyString();
1170 1128
1171 return builder.toString(); 1129 return builder.toString();
1172 } 1130 }
1173 1131
1174 String plainText(const Range* r, TextIteratorBehaviorFlags behavior) 1132 String plainText(const Range* r, TextIteratorBehaviorFlags behavior)
1175 { 1133 {
1176 TextIterator it(r, behavior); 1134 TextIterator it(r->startPosition(), r->endPosition(), behavior);
1177 return createPlainText(it); 1135 return createPlainText(it);
1178 } 1136 }
1179 1137
1180 String plainText(const Position& start, const Position& end, TextIteratorBehavio rFlags behavior) 1138 String plainText(const Position& start, const Position& end, TextIteratorBehavio rFlags behavior)
1181 { 1139 {
1182 TextIterator it(start, end, behavior); 1140 TextIterator it(start, end, behavior);
1183 return createPlainText(it); 1141 return createPlainText(it);
1184 } 1142 }
1185 1143
1186 } 1144 }
OLDNEW
« no previous file with comments | « Source/core/editing/iterators/TextIterator.h ('k') | Source/core/editing/iterators/TextIteratorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698