Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NGInlineItemsBuilder_h | 5 #ifndef NGInlineItemsBuilder_h |
| 6 #define NGInlineItemsBuilder_h | 6 #define NGInlineItemsBuilder_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/inline/ng_inline_node.h" | 9 #include "core/layout/ng/inline/ng_inline_node.h" |
| 10 #include "platform/wtf/Allocator.h" | 10 #include "platform/wtf/Allocator.h" |
| 11 #include "platform/wtf/Vector.h" | 11 #include "platform/wtf/Vector.h" |
| 12 #include "platform/wtf/text/StringBuilder.h" | 12 #include "platform/wtf/text/StringBuilder.h" |
| 13 #include "platform/wtf/text/WTFString.h" | 13 #include "platform/wtf/text/WTFString.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class ComputedStyle; | 17 class ComputedStyle; |
| 18 class LayoutObject; | 18 class LayoutObject; |
| 19 class NGInlineItem; | 19 class NGInlineItem; |
| 20 | 20 |
| 21 // NGInlineItemsBuilder builds a string and a list of NGInlineItem from inlines. | 21 // NGInlineItemsBuilder builds a string and a list of NGInlineItem from inlines. |
| 22 // | 22 // |
| 23 // When appending, spaces are collapsed according to CSS Text, The white space | 23 // When appending, spaces are collapsed according to CSS Text, The white space |
| 24 // processing rules | 24 // processing rules |
| 25 // https://drafts.csswg.org/css-text-3/#white-space-rules | 25 // https://drafts.csswg.org/css-text-3/#white-space-rules |
| 26 // | 26 // |
| 27 // By calling EnterInline/ExitInline, it inserts bidirectional control | 27 // By calling EnterInline/ExitInline, it inserts bidirectional control |
| 28 // characters as defined in: | 28 // characters as defined in: |
| 29 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection-ta ble | 29 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection-ta ble |
| 30 // | |
| 31 // Optionally, NGInlineItemsBuilder takes parameter |collapsed_indexes| to | |
| 32 // return how spaces are collapsed. For each string appended to | |
| 33 // NGInlineItemsBuilder, a Vector<unsigned> will be added to | |
| 34 // |collapsed_indexes|, storing the indexes of all collapsed spaces in sorted | |
| 35 // order. See the unit tests for examples. | |
| 30 class CORE_EXPORT NGInlineItemsBuilder { | 36 class CORE_EXPORT NGInlineItemsBuilder { |
| 31 STACK_ALLOCATED(); | 37 STACK_ALLOCATED(); |
| 32 | 38 |
| 33 public: | 39 public: |
| 34 explicit NGInlineItemsBuilder(Vector<NGInlineItem>* items) : items_(items) {} | 40 explicit NGInlineItemsBuilder(Vector<NGInlineItem>* items) |
| 41 : items_(items), collapsed_indexes_(nullptr) {} | |
| 42 explicit NGInlineItemsBuilder(Vector<NGInlineItem>* items, | |
| 43 Vector<Vector<unsigned>>* collapsed_indexes) | |
| 44 : items_(items), collapsed_indexes_(collapsed_indexes) {} | |
| 35 ~NGInlineItemsBuilder(); | 45 ~NGInlineItemsBuilder(); |
| 36 | 46 |
| 37 String ToString(); | 47 String ToString(); |
| 38 | 48 |
| 39 void SetIsSVGText(bool value) { is_svgtext_ = value; } | 49 void SetIsSVGText(bool value) { is_svgtext_ = value; } |
| 40 | 50 |
| 41 // Returns whether the items contain any Bidi controls. | 51 // Returns whether the items contain any Bidi controls. |
| 42 bool HasBidiControls() const { return has_bidi_controls_; } | 52 bool HasBidiControls() const { return has_bidi_controls_; } |
| 43 | 53 |
| 44 // Append a string. | 54 // Append a string. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 UChar character; | 95 UChar character; |
| 86 } OnExitNode; | 96 } OnExitNode; |
| 87 Vector<OnExitNode> exits_; | 97 Vector<OnExitNode> exits_; |
| 88 | 98 |
| 89 enum class CollapsibleSpace { kNone, kSpace, kNewline }; | 99 enum class CollapsibleSpace { kNone, kSpace, kNewline }; |
| 90 | 100 |
| 91 CollapsibleSpace last_collapsible_space_ = CollapsibleSpace::kSpace; | 101 CollapsibleSpace last_collapsible_space_ = CollapsibleSpace::kSpace; |
| 92 bool is_svgtext_ = false; | 102 bool is_svgtext_ = false; |
| 93 bool has_bidi_controls_ = false; | 103 bool has_bidi_controls_ = false; |
| 94 | 104 |
| 105 // When provided, the indexes of collapsed spaces in each appended string will | |
| 106 // be eventually added to |collapsed_indexes_|. | |
| 107 Vector<Vector<unsigned>>* collapsed_indexes_; | |
|
yosin_UTC9
2017/06/21 04:22:41
Could you introduce OffsetMappingBuilder class to
kojii
2017/06/21 09:47:13
I take this opposite. Since this is tightly couple
Xiaocheng
2017/06/21 18:15:06
I agree with yosin@ that it's a better pattern if
| |
| 108 // Length of each appended string. Used only for computing the indexes of | |
| 109 // collapsed spaces when |collapsed_indexes_| is provided. | |
| 110 Vector<unsigned> input_strings_lengths_; | |
| 111 | |
| 95 void AppendWithWhiteSpaceCollapsing(const String&, | 112 void AppendWithWhiteSpaceCollapsing(const String&, |
| 96 unsigned start, | 113 unsigned start, |
| 97 unsigned end, | 114 unsigned end, |
| 98 const ComputedStyle*, | 115 const ComputedStyle*, |
| 99 LayoutObject*); | 116 LayoutObject*); |
| 100 void AppendWithoutWhiteSpaceCollapsing(const String&, | 117 void AppendWithoutWhiteSpaceCollapsing(const String&, |
| 101 const ComputedStyle*, | 118 const ComputedStyle*, |
| 102 LayoutObject*); | 119 LayoutObject*); |
| 103 void AppendWithPreservingNewlines(const String&, | 120 void AppendWithPreservingNewlines(const String&, |
| 104 const ComputedStyle*, | 121 const ComputedStyle*, |
| 105 LayoutObject*); | 122 LayoutObject*); |
| 106 | 123 |
| 107 void AppendForcedBreak(const ComputedStyle*, LayoutObject*); | 124 void AppendForcedBreak(const ComputedStyle*, LayoutObject*, unsigned); |
| 108 | 125 |
| 109 // Because newlines may be removed depends on following characters, newlines | 126 // Because newlines may be removed depends on following characters, newlines |
| 110 // at the end of input string is not added to |text_| but instead | 127 // at the end of input string is not added to |text_| but instead |
| 111 // |has_pending_newline_| flag is set. | 128 // |has_pending_newline_| flag is set. |
| 112 // This function determines whether to add the newline or ignore. | 129 // This function determines whether to add the newline or ignore. |
| 113 void ProcessPendingNewline(const String&, const ComputedStyle*); | 130 void ProcessPendingNewline(const String&, const ComputedStyle*); |
| 114 | 131 |
| 115 // Removes the collapsible space at the end of |text_| if exists. | 132 // Removes the collapsible space at the end of |text_| if exists. |
| 116 void RemoveTrailingCollapsibleSpaceIfExists(unsigned*); | 133 void RemoveTrailingCollapsibleSpaceIfExists(unsigned*, unsigned); |
| 117 void RemoveTrailingCollapsibleSpace(unsigned*); | 134 void RemoveTrailingCollapsibleSpace(unsigned*, unsigned); |
| 118 | 135 |
| 119 void RemoveTrailingCollapsibleNewlineIfNeeded(unsigned*, | 136 void RemoveTrailingCollapsibleNewlineIfNeeded(unsigned*, |
| 120 const String&, | 137 const String&, |
| 121 unsigned, | 138 unsigned, |
| 122 const ComputedStyle*); | 139 const ComputedStyle*); |
| 123 | 140 |
| 141 void AddLastTrailingSpaceToRemovedIndexes(unsigned); | |
| 142 | |
| 124 void Enter(LayoutObject*, UChar); | 143 void Enter(LayoutObject*, UChar); |
| 125 void Exit(LayoutObject*); | 144 void Exit(LayoutObject*); |
| 126 }; | 145 }; |
| 127 | 146 |
| 128 } // namespace blink | 147 } // namespace blink |
| 129 | 148 |
| 130 #endif // NGInlineItemsBuilder_h | 149 #endif // NGInlineItemsBuilder_h |
| OLD | NEW |