Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // TextIteratorTextNodeHandler extracts plain text from a text node by calling | |
| 54 // HandleTextNode() function. It should be used only by TextIterator. | |
| 55 class TextIteratorTextNodeHandler { | |
|
yosin_UTC9
2017/05/29 04:46:05
nit: s/{/final {/
Xiaocheng
2017/05/29 06:00:42
Done.
| |
| 56 STACK_ALLOCATED(); | |
| 57 | |
| 58 public: | |
| 59 TextIteratorTextNodeHandler(const TextIteratorBehavior&, | |
| 60 TextIteratorTextState*); | |
| 61 | |
| 62 void SetBoundaries(Node* start_container, | |
| 63 int start_offset, | |
| 64 Node* end_container, | |
| 65 int end_offset); | |
| 66 | |
| 67 Text* GetNode() const { return text_node_; } | |
| 68 | |
| 69 // Returns true if more text is emitted without traversing to the next node. | |
| 70 bool HandleRemainingTextRuns(); | |
| 71 | |
| 72 // Returns true if a leading white space is emitted before a replaced element. | |
| 73 bool FixLeadingWhiteSpaceForReplacedElement(Node*); | |
| 74 | |
| 75 void ResetCollapsedWhiteSpaceFixup(); | |
| 76 | |
| 77 // TODO(xiaochengh): Make the return type |void|. The current return value is | |
| 78 // not very meaningful. | |
| 79 bool HandleTextNode(Text*); | |
| 80 | |
| 81 private: | |
| 82 void HandlePreFormattedTextNode(); | |
| 83 void HandleTextBox(); | |
| 84 void HandleTextNodeFirstLetter(LayoutTextFragment*); | |
| 85 bool ShouldHandleFirstLetter(const LayoutText&) const; | |
| 86 bool ShouldProceedToRemainingText() const; | |
| 87 void ProceedToRemainingText(); | |
| 88 size_t RestoreCollapsedTrailingSpace(InlineTextBox* next_text_box, | |
| 89 size_t subrun_end); | |
| 90 | |
| 91 // Used when the visibility of the style should not affect text gathering. | |
| 92 bool IgnoresStyleVisibility() const { | |
| 93 return behavior_.IgnoresStyleVisibility(); | |
| 94 } | |
| 95 | |
| 96 void SpliceBuffer(UChar, | |
| 97 Node* text_node, | |
| 98 Node* offset_base_node, | |
| 99 int text_start_offset, | |
| 100 int text_end_offset); | |
| 101 void EmitText(Node* text_node, | |
| 102 LayoutText* layout_object, | |
| 103 int text_start_offset, | |
| 104 int text_end_offset); | |
| 105 | |
| 106 // The range. | |
| 107 Member<Node> start_container_; | |
| 108 int start_offset_ = 0; | |
| 109 Member<Node> end_container_; | |
| 110 int end_offset_ = 0; | |
| 111 | |
| 112 // The current text node and offset, from which text is being emitted. | |
| 113 Member<Text> text_node_; | |
| 114 int offset_ = 0; | |
| 115 | |
| 116 InlineTextBox* text_box_ = nullptr; | |
| 117 | |
| 118 // Remember if we are in the middle of handling a pre-formatted text node. | |
| 119 bool needs_handle_pre_formatted_text_node_ = false; | |
| 120 // Used when deciding text fragment created by :first-letter should be looked | |
| 121 // into. | |
| 122 bool handled_first_letter_ = false; | |
| 123 // Used when iteration over :first-letter text to save pointer to | |
| 124 // remaining text box. | |
| 125 InlineTextBox* remaining_text_box_ = nullptr; | |
| 126 // Used to point to LayoutText object for :first-letter. | |
| 127 LayoutText* first_letter_text_ = nullptr; | |
| 128 | |
| 129 // Used to do the whitespace collapsing logic. | |
| 130 bool last_text_node_ended_with_collapsed_space_ = false; | |
| 131 | |
| 132 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text) | |
| 133 Vector<InlineTextBox*> sorted_text_boxes_; | |
| 134 size_t sorted_text_boxes_position_ = 0; | |
| 135 | |
| 136 const TextIteratorBehavior behavior_; | |
| 137 | |
| 138 // Contains state of emitted text. | |
| 139 TextIteratorTextState* text_state_; | |
|
yosin_UTC9
2017/05/29 04:46:05
nit: s/TextIteratorTextState*/TextIteratorTextStat
Xiaocheng
2017/05/29 06:00:42
Done.
| |
| 140 | |
| 141 DISALLOW_COPY_AND_ASSIGN(TextIteratorTextNodeHandler); | |
| 142 }; | |
| 143 | |
| 52 // Iterates through the DOM range, returning all the text, and 0-length | 144 // 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 | 145 // 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. | 146 // text comes back in chunks so as to optimize for performance of the iteration. |
| 55 | 147 |
| 56 template <typename Strategy> | 148 template <typename Strategy> |
| 57 class CORE_TEMPLATE_CLASS_EXPORT TextIteratorAlgorithm { | 149 class CORE_TEMPLATE_CLASS_EXPORT TextIteratorAlgorithm { |
| 58 STACK_ALLOCATED(); | 150 STACK_ALLOCATED(); |
| 59 | 151 |
| 60 public: | 152 public: |
| 61 // [start, end] indicates the document range that the iteration should take | 153 // [start, end] indicates the document range that the iteration should take |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 bool ShouldRepresentNodeOffsetZero(); | 226 bool ShouldRepresentNodeOffsetZero(); |
| 135 bool ShouldEmitSpaceBeforeAndAfterNode(Node*); | 227 bool ShouldEmitSpaceBeforeAndAfterNode(Node*); |
| 136 void RepresentNodeOffsetZero(); | 228 void RepresentNodeOffsetZero(); |
| 137 | 229 |
| 138 // Return true if the iteration progress should advance to |kHandledNode| | 230 // Return true if the iteration progress should advance to |kHandledNode| |
| 139 // after calling a |HandleXXX| function. | 231 // after calling a |HandleXXX| function. |
| 140 // TODO(xiaochengh): The meaning of the return values is unclear, and they do | 232 // TODO(xiaochengh): The meaning of the return values is unclear, and they do |
| 141 // not always clearly control the iteration progress. Should consider removing | 233 // not always clearly control the iteration progress. Should consider removing |
| 142 // the return values and control the iteration in a cleaner way. | 234 // the return values and control the iteration in a cleaner way. |
| 143 bool HandleTextNode(); | 235 bool HandleTextNode(); |
| 144 void HandlePreFormattedTextNode(); | |
| 145 bool HandleReplacedElement(); | 236 bool HandleReplacedElement(); |
| 146 bool HandleNonTextNode(); | 237 bool HandleNonTextNode(); |
| 147 | |
| 148 void HandleTextBox(); | |
| 149 void HandleTextNodeFirstLetter(LayoutTextFragment*); | |
| 150 bool ShouldHandleFirstLetter(const LayoutText&) const; | |
| 151 bool ShouldProceedToRemainingText() const; | |
| 152 void ProceedToRemainingText(); | |
| 153 void ResetCollapsedWhiteSpaceFixup(); | |
| 154 | |
| 155 // Returns true if more text is emitted without traversing to the next node. | |
| 156 bool HandleRemainingTextRuns(); | |
| 157 | |
| 158 // Returns true if a leading white space is emitted before a replaced element. | |
| 159 bool FixLeadingWhiteSpaceForReplacedElement(Node* parent); | |
| 160 | |
| 161 void SpliceBuffer(UChar, | 238 void SpliceBuffer(UChar, |
| 162 Node* text_node, | 239 Node* text_node, |
| 163 Node* offset_base_node, | 240 Node* offset_base_node, |
| 164 int text_start_offset, | 241 int text_start_offset, |
| 165 int text_end_offset); | 242 int text_end_offset); |
| 166 void EmitText(Node* text_node, | |
| 167 LayoutText* layout_object, | |
| 168 int text_start_offset, | |
| 169 int text_end_offset); | |
| 170 size_t RestoreCollapsedTrailingSpace(InlineTextBox* next_text_box, | |
| 171 size_t subrun_end); | |
| 172 | 243 |
| 173 // Used by selection preservation code. There should be one character emitted | 244 // Used by selection preservation code. There should be one character emitted |
| 174 // between every VisiblePosition in the Range used to create the TextIterator. | 245 // between every VisiblePosition in the Range used to create the TextIterator. |
| 175 // FIXME <rdar://problem/6028818>: This functionality should eventually be | 246 // FIXME <rdar://problem/6028818>: This functionality should eventually be |
| 176 // phased out when we rewrite moveParagraphs to not clone/destroy moved | 247 // phased out when we rewrite moveParagraphs to not clone/destroy moved |
| 177 // content. | 248 // content. |
| 178 bool EmitsCharactersBetweenAllVisiblePositions() const { | 249 bool EmitsCharactersBetweenAllVisiblePositions() const { |
| 179 return behavior_.EmitsCharactersBetweenAllVisiblePositions(); | 250 return behavior_.EmitsCharactersBetweenAllVisiblePositions(); |
| 180 } | 251 } |
| 181 | 252 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 287 |
| 217 // Append code units with offset range [position, position + copyLength) | 288 // Append code units with offset range [position, position + copyLength) |
| 218 // to the output buffer. | 289 // to the output buffer. |
| 219 void CopyCodeUnitsTo(ForwardsTextBuffer* output, | 290 void CopyCodeUnitsTo(ForwardsTextBuffer* output, |
| 220 int position, | 291 int position, |
| 221 int copy_length) const; | 292 int copy_length) const; |
| 222 | 293 |
| 223 // Current position, not necessarily of the text being returned, but position | 294 // Current position, not necessarily of the text being returned, but position |
| 224 // as we walk through the DOM tree. | 295 // as we walk through the DOM tree. |
| 225 Member<Node> node_; | 296 Member<Node> node_; |
| 226 int offset_; | |
| 227 IterationProgress iteration_progress_; | 297 IterationProgress iteration_progress_; |
| 228 FullyClippedStateStackAlgorithm<Strategy> fully_clipped_stack_; | 298 FullyClippedStateStackAlgorithm<Strategy> fully_clipped_stack_; |
| 229 int shadow_depth_; | 299 int shadow_depth_; |
| 230 | 300 |
| 231 // The range. | 301 // The range. |
| 232 Member<Node> start_container_; | 302 Member<Node> start_container_; |
| 233 int start_offset_; | 303 int start_offset_; |
| 234 Member<Node> end_container_; | 304 Member<Node> end_container_; |
| 235 int end_offset_; | 305 int end_offset_; |
| 236 // |m_endNode| stores |Strategy::childAt(*m_endContainer, m_endOffset - 1)|, | 306 // |m_endNode| stores |Strategy::childAt(*m_endContainer, m_endOffset - 1)|, |
| 237 // if it exists, or |nullptr| otherwise. | 307 // if it exists, or |nullptr| otherwise. |
| 238 Member<Node> end_node_; | 308 Member<Node> end_node_; |
| 239 Member<Node> past_end_node_; | 309 Member<Node> past_end_node_; |
| 240 | 310 |
| 241 // The current text node, from which text is being emitted. | |
| 242 Member<Text> text_node_; | |
| 243 | |
| 244 // Used when there is still some pending text from the current node; when | 311 // Used when there is still some pending text from the current node; when |
| 245 // these are false and 0, we go back to normal iterating. | 312 // these are false and 0, we go back to normal iterating. |
| 246 bool needs_another_newline_; | 313 bool needs_another_newline_; |
| 247 InlineTextBox* text_box_; | |
| 248 // Used when iteration over :first-letter text to save pointer to | |
| 249 // remaining text box. | |
| 250 InlineTextBox* remaining_text_box_; | |
| 251 // Used to point to LayoutText object for :first-letter. | |
| 252 LayoutText* first_letter_text_; | |
| 253 | 314 |
| 254 // Used to do the whitespace collapsing logic. | |
| 255 Member<Text> last_text_node_; | 315 Member<Text> last_text_node_; |
| 256 bool last_text_node_ended_with_collapsed_space_; | |
| 257 | |
| 258 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text) | |
| 259 Vector<InlineTextBox*> sorted_text_boxes_; | |
| 260 size_t sorted_text_boxes_position_; | |
| 261 | 316 |
| 262 const TextIteratorBehavior behavior_; | 317 const TextIteratorBehavior behavior_; |
| 263 | 318 |
| 264 // Remember if we are in the middle of handling a pre-formatted text node. | |
| 265 bool needs_handle_pre_formatted_text_node_; | |
| 266 // Used when deciding text fragment created by :first-letter should be looked | |
| 267 // into. | |
| 268 bool handled_first_letter_; | |
| 269 // Used when stopsOnFormControls() is true to determine if the iterator should | 319 // Used when stopsOnFormControls() is true to determine if the iterator should |
| 270 // keep advancing. | 320 // keep advancing. |
| 271 bool should_stop_; | 321 bool should_stop_; |
| 272 // Used for use counter |InnerTextWithShadowTree| and | 322 // Used for use counter |InnerTextWithShadowTree| and |
| 273 // |SelectionToStringWithShadowTree|, we should not use other purpose. | 323 // |SelectionToStringWithShadowTree|, we should not use other purpose. |
| 274 bool handle_shadow_root_; | 324 bool handle_shadow_root_; |
| 275 | 325 |
| 276 // Contains state of emitted text. | 326 // Contains state of emitted text. |
| 277 TextIteratorTextState text_state_; | 327 TextIteratorTextState text_state_; |
| 328 | |
| 329 // Helper for extracting text content from text nodes. | |
| 330 // TODO(xiaochengh): We should store a pointer here, so that we can use | |
| 331 // forward declaration and switch it to Layout NG easier. | |
| 332 TextIteratorTextNodeHandler text_node_handler_; | |
| 278 }; | 333 }; |
| 279 | 334 |
| 280 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 335 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 281 TextIteratorAlgorithm<EditingStrategy>; | 336 TextIteratorAlgorithm<EditingStrategy>; |
| 282 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 337 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 283 TextIteratorAlgorithm<EditingInFlatTreeStrategy>; | 338 TextIteratorAlgorithm<EditingInFlatTreeStrategy>; |
| 284 | 339 |
| 285 using TextIterator = TextIteratorAlgorithm<EditingStrategy>; | 340 using TextIterator = TextIteratorAlgorithm<EditingStrategy>; |
| 286 using TextIteratorInFlatTree = TextIteratorAlgorithm<EditingInFlatTreeStrategy>; | 341 using TextIteratorInFlatTree = TextIteratorAlgorithm<EditingInFlatTreeStrategy>; |
| 287 | 342 |
| 288 } // namespace blink | 343 } // namespace blink |
| 289 | 344 |
| 290 #endif // TextIterator_h | 345 #endif // TextIterator_h |
| OLD | NEW |