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

Side by Side Diff: third_party/WebKit/Source/core/editing/iterators/TextIterator.h

Issue 2903693005: Introduce a wrapper class to handle text node in TextIterator (Closed)
Patch Set: Created 3 years, 7 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, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class LayoutText; 42 class LayoutText;
43 class LayoutTextFragment; 43 class LayoutTextFragment;
44 44
45 CORE_EXPORT String 45 CORE_EXPORT String
46 PlainText(const EphemeralRange&, 46 PlainText(const EphemeralRange&,
47 const TextIteratorBehavior& = TextIteratorBehavior()); 47 const TextIteratorBehavior& = TextIteratorBehavior());
48 48
49 String PlainText(const EphemeralRangeInFlatTree&, 49 String PlainText(const EphemeralRangeInFlatTree&,
50 const TextIteratorBehavior& = TextIteratorBehavior()); 50 const TextIteratorBehavior& = TextIteratorBehavior());
51 51
52 // TODO(xiaochengh): Move the class to dedicated files.
53 class CORE_EXPORT TextNodeContentExtractor {
yosin_UTC9 2017/05/25 06:44:09 - Please add class comment. - s/CORE_EXPORT// sinc
Xiaocheng 2017/05/25 23:47:58 Done.
54 STACK_ALLOCATED();
55
56 public:
57 TextNodeContentExtractor(const TextIteratorBehavior&, TextIteratorTextState&);
yosin_UTC9 2017/05/25 06:44:09 nit: s/TextIteratorState&/TextIterator*/
Xiaocheng 2017/05/25 23:47:58 Is there a style guide? I've seen a lot of classes
58
59 void SetBoundaries(Node* start_container,
60 int start_offset,
61 Node* end_container,
62 int end_offset);
63
64 // Returns true if more text is emitted without traversing to the next node.
65 bool HandleRemainingTextRuns();
66
67 // Returns true if a leading white space is emitted before a replaced element.
68 bool FixLeadingWhiteSpaceForReplacedElement(Node*);
69
70 bool HandleTextNode(Text*);
yosin_UTC9 2017/05/25 06:44:09 Please add a comment for |bool| return value.
Xiaocheng 2017/05/25 23:47:58 Done.
71
72 private:
73 void HandlePreFormattedTextNode();
74 void HandleTextBox();
75 void HandleTextNodeFirstLetter(LayoutTextFragment*);
76 bool ShouldHandleFirstLetter(const LayoutText&) const;
77 bool ShouldProceedToRemainingText() const;
78 void ProceedToRemainingText();
79 size_t RestoreCollapsedTrailingSpace(InlineTextBox* next_text_box,
80 size_t subrun_end);
81
82 // Used when the visibility of the style should not affect text gathering.
83 bool IgnoresStyleVisibility() const {
84 return behavior_.IgnoresStyleVisibility();
85 }
86
87 // The range.
88 Member<Node> start_container_;
89 int start_offset_;
90 Member<Node> end_container_;
91 int end_offset_;
92
93 // The current text node and offset, from which text is being emitted.
94 Member<Text> text_node_;
95 int offset_;
96
97 InlineTextBox* text_box_;
98
99 // Remember if we are in the middle of handling a pre-formatted text node.
100 bool needs_handle_pre_formatted_text_node_;
101 // Used when deciding text fragment created by :first-letter should be looked
102 // into.
103 bool handled_first_letter_;
104 // Used when iteration over :first-letter text to save pointer to
105 // remaining text box.
106 InlineTextBox* remaining_text_box_;
107 // Used to point to LayoutText object for :first-letter.
108 LayoutText* first_letter_text_;
109
110 // Used to do the whitespace collapsing logic.
111 bool last_text_node_ended_with_collapsed_space_;
112
113 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text)
114 Vector<InlineTextBox*> sorted_text_boxes_;
115 size_t sorted_text_boxes_position_;
116
117 const TextIteratorBehavior behavior_;
118
119 // Contains state of emitted text.
120 TextIteratorTextState& text_state_;
121 };
122
52 // Iterates through the DOM range, returning all the text, and 0-length 123 // Iterates through the DOM range, returning all the text, and 0-length
53 // boundaries at points where replaced elements break up the text flow. The 124 // boundaries at points where replaced elements break up the text flow. The
54 // text comes back in chunks so as to optimize for performance of the iteration. 125 // text comes back in chunks so as to optimize for performance of the iteration.
55 126
56 template <typename Strategy> 127 template <typename Strategy>
57 class CORE_TEMPLATE_CLASS_EXPORT TextIteratorAlgorithm { 128 class CORE_TEMPLATE_CLASS_EXPORT TextIteratorAlgorithm {
58 STACK_ALLOCATED(); 129 STACK_ALLOCATED();
59 130
60 public: 131 public:
61 // [start, end] indicates the document range that the iteration should take 132 // [start, end] indicates the document range that the iteration should take
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool ShouldRepresentNodeOffsetZero(); 205 bool ShouldRepresentNodeOffsetZero();
135 bool ShouldEmitSpaceBeforeAndAfterNode(Node*); 206 bool ShouldEmitSpaceBeforeAndAfterNode(Node*);
136 void RepresentNodeOffsetZero(); 207 void RepresentNodeOffsetZero();
137 208
138 // Return true if the iteration progress should advance to |kHandledNode| 209 // Return true if the iteration progress should advance to |kHandledNode|
139 // after calling a |HandleXXX| function. 210 // after calling a |HandleXXX| function.
140 // TODO(xiaochengh): The meaning of the return values is unclear, and they do 211 // TODO(xiaochengh): The meaning of the return values is unclear, and they do
141 // not always clearly control the iteration progress. Should consider removing 212 // not always clearly control the iteration progress. Should consider removing
142 // the return values and control the iteration in a cleaner way. 213 // the return values and control the iteration in a cleaner way.
143 bool HandleTextNode(); 214 bool HandleTextNode();
144 void HandlePreFormattedTextNode();
145 bool HandleReplacedElement(); 215 bool HandleReplacedElement();
146 bool HandleNonTextNode(); 216 bool HandleNonTextNode();
147
148 void HandleTextBox();
149 void HandleTextNodeFirstLetter(LayoutTextFragment*);
150 bool ShouldHandleFirstLetter(const LayoutText&) const;
151 bool ShouldProceedToRemainingText() const;
152 void ProceedToRemainingText();
153
154 // Returns true if more text is emitted without traversing to the next node.
155 bool HandleRemainingTextRuns();
156
157 // Returns true if a leading white space is emitted before a replaced element.
158 bool FixLeadingWhiteSpaceForReplacedElement(Node* parent);
159
160 void SpliceBuffer(UChar, 217 void SpliceBuffer(UChar,
161 Node* text_node, 218 Node* text_node,
162 Node* offset_base_node, 219 Node* offset_base_node,
163 int text_start_offset, 220 int text_start_offset,
164 int text_end_offset); 221 int text_end_offset);
165 void EmitText(Node* text_node, 222 void EmitText(Node* text_node,
166 LayoutText* layout_object, 223 LayoutText* layout_object,
167 int text_start_offset, 224 int text_start_offset,
168 int text_end_offset); 225 int text_end_offset);
169 size_t RestoreCollapsedTrailingSpace(InlineTextBox* next_text_box,
170 size_t subrun_end);
171 226
172 // Used by selection preservation code. There should be one character emitted 227 // Used by selection preservation code. There should be one character emitted
173 // between every VisiblePosition in the Range used to create the TextIterator. 228 // between every VisiblePosition in the Range used to create the TextIterator.
174 // FIXME <rdar://problem/6028818>: This functionality should eventually be 229 // FIXME <rdar://problem/6028818>: This functionality should eventually be
175 // phased out when we rewrite moveParagraphs to not clone/destroy moved 230 // phased out when we rewrite moveParagraphs to not clone/destroy moved
176 // content. 231 // content.
177 bool EmitsCharactersBetweenAllVisiblePositions() const { 232 bool EmitsCharactersBetweenAllVisiblePositions() const {
178 return behavior_.EmitsCharactersBetweenAllVisiblePositions(); 233 return behavior_.EmitsCharactersBetweenAllVisiblePositions();
179 } 234 }
180 235
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 270
216 // Append code units with offset range [position, position + copyLength) 271 // Append code units with offset range [position, position + copyLength)
217 // to the output buffer. 272 // to the output buffer.
218 void CopyCodeUnitsTo(ForwardsTextBuffer* output, 273 void CopyCodeUnitsTo(ForwardsTextBuffer* output,
219 int position, 274 int position,
220 int copy_length) const; 275 int copy_length) const;
221 276
222 // Current position, not necessarily of the text being returned, but position 277 // Current position, not necessarily of the text being returned, but position
223 // as we walk through the DOM tree. 278 // as we walk through the DOM tree.
224 Member<Node> node_; 279 Member<Node> node_;
225 int offset_;
226 IterationProgress iteration_progress_; 280 IterationProgress iteration_progress_;
227 FullyClippedStateStackAlgorithm<Strategy> fully_clipped_stack_; 281 FullyClippedStateStackAlgorithm<Strategy> fully_clipped_stack_;
228 int shadow_depth_; 282 int shadow_depth_;
229 283
230 // The range. 284 // The range.
231 Member<Node> start_container_; 285 Member<Node> start_container_;
232 int start_offset_; 286 int start_offset_;
233 Member<Node> end_container_; 287 Member<Node> end_container_;
234 int end_offset_; 288 int end_offset_;
235 // |m_endNode| stores |Strategy::childAt(*m_endContainer, m_endOffset - 1)|, 289 // |m_endNode| stores |Strategy::childAt(*m_endContainer, m_endOffset - 1)|,
236 // if it exists, or |nullptr| otherwise. 290 // if it exists, or |nullptr| otherwise.
237 Member<Node> end_node_; 291 Member<Node> end_node_;
238 Member<Node> past_end_node_; 292 Member<Node> past_end_node_;
239 293
240 // The current text node, from which text is being emitted.
241 Member<Text> text_node_;
242
243 // Used when there is still some pending text from the current node; when 294 // Used when there is still some pending text from the current node; when
244 // these are false and 0, we go back to normal iterating. 295 // these are false and 0, we go back to normal iterating.
245 bool needs_another_newline_; 296 bool needs_another_newline_;
246 InlineTextBox* text_box_;
247 // Used when iteration over :first-letter text to save pointer to
248 // remaining text box.
249 InlineTextBox* remaining_text_box_;
250 // Used to point to LayoutText object for :first-letter.
251 LayoutText* first_letter_text_;
252 297
253 // Used to do the whitespace collapsing logic.
254 Member<Text> last_text_node_; 298 Member<Text> last_text_node_;
255 bool last_text_node_ended_with_collapsed_space_;
256
257 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text)
258 Vector<InlineTextBox*> sorted_text_boxes_;
259 size_t sorted_text_boxes_position_;
260 299
261 const TextIteratorBehavior behavior_; 300 const TextIteratorBehavior behavior_;
262 301
263 // Remember if we are in the middle of handling a pre-formatted text node.
264 bool needs_handle_pre_formatted_text_node_;
265 // Used when deciding text fragment created by :first-letter should be looked
266 // into.
267 bool handled_first_letter_;
268 // Used when stopsOnFormControls() is true to determine if the iterator should 302 // Used when stopsOnFormControls() is true to determine if the iterator should
269 // keep advancing. 303 // keep advancing.
270 bool should_stop_; 304 bool should_stop_;
271 // Used for use counter |InnerTextWithShadowTree| and 305 // Used for use counter |InnerTextWithShadowTree| and
272 // |SelectionToStringWithShadowTree|, we should not use other purpose. 306 // |SelectionToStringWithShadowTree|, we should not use other purpose.
273 bool handle_shadow_root_; 307 bool handle_shadow_root_;
274 308
275 // Contains state of emitted text. 309 // Contains state of emitted text.
276 TextIteratorTextState text_state_; 310 TextIteratorTextState text_state_;
311
312 // Helper for extracting text content from text nodes.
313 TextNodeContentExtractor text_extractor_;
277 }; 314 };
278 315
279 extern template class CORE_EXTERN_TEMPLATE_EXPORT 316 extern template class CORE_EXTERN_TEMPLATE_EXPORT
280 TextIteratorAlgorithm<EditingStrategy>; 317 TextIteratorAlgorithm<EditingStrategy>;
281 extern template class CORE_EXTERN_TEMPLATE_EXPORT 318 extern template class CORE_EXTERN_TEMPLATE_EXPORT
282 TextIteratorAlgorithm<EditingInFlatTreeStrategy>; 319 TextIteratorAlgorithm<EditingInFlatTreeStrategy>;
283 320
284 using TextIterator = TextIteratorAlgorithm<EditingStrategy>; 321 using TextIterator = TextIteratorAlgorithm<EditingStrategy>;
285 using TextIteratorInFlatTree = TextIteratorAlgorithm<EditingInFlatTreeStrategy>; 322 using TextIteratorInFlatTree = TextIteratorAlgorithm<EditingInFlatTreeStrategy>;
286 323
287 } // namespace blink 324 } // namespace blink
288 325
289 #endif // TextIterator_h 326 #endif // TextIterator_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698