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/Optional.h" | |
| 11 #include "platform/wtf/Vector.h" | 12 #include "platform/wtf/Vector.h" |
| 12 #include "platform/wtf/text/StringBuilder.h" | 13 #include "platform/wtf/text/StringBuilder.h" |
| 13 #include "platform/wtf/text/WTFString.h" | 14 #include "platform/wtf/text/WTFString.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 class ComputedStyle; | 18 class ComputedStyle; |
| 18 class LayoutObject; | 19 class LayoutObject; |
| 19 class NGInlineItem; | 20 class NGInlineItem; |
| 20 | 21 |
| 21 // NGInlineItemsBuilder builds a string and a list of NGInlineItem from inlines. | 22 // NGInlineItemsBuilder builds a string and a list of NGInlineItem from inlines. |
| 22 // | 23 // |
| 23 // When appending, spaces are collapsed according to CSS Text, The white space | 24 // When appending, spaces are collapsed according to CSS Text, The white space |
| 24 // processing rules | 25 // processing rules |
| 25 // https://drafts.csswg.org/css-text-3/#white-space-rules | 26 // https://drafts.csswg.org/css-text-3/#white-space-rules |
| 26 // | 27 // |
| 27 // By calling EnterInline/ExitInline, it inserts bidirectional control | 28 // By calling EnterInline/ExitInline, it inserts bidirectional control |
| 28 // characters as defined in: | 29 // characters as defined in: |
| 29 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection-ta ble | 30 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection-ta ble |
| 31 // | |
| 32 // Optionally, NGInlineItemsBuilder takes parameter |removed_indexes| to return | |
|
kojii
2017/06/19 05:56:33
How about naming |removed_indexes| as |collapsed_i
Xiaocheng
2017/06/19 17:53:01
Sound good. Done.
| |
| 33 // how spaces are collapsed. For each string appended to NGInlineItemsBuilder, | |
| 34 // a Vector<unsigned> is added to |removed_indexes|, storing the indexes of all | |
| 35 // removed spaces in sorted 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), removed_indexes_(nullptr) {} | |
| 42 explicit NGInlineItemsBuilder(Vector<NGInlineItem>* items, | |
| 43 Vector<Vector<unsigned>>* removed_indexes); | |
| 35 ~NGInlineItemsBuilder(); | 44 ~NGInlineItemsBuilder(); |
| 36 | 45 |
| 37 String ToString(); | 46 String ToString(); |
| 38 | 47 |
| 39 void SetIsSVGText(bool value) { is_svgtext_ = value; } | 48 void SetIsSVGText(bool value) { is_svgtext_ = value; } |
| 40 | 49 |
| 41 // Returns whether the items contain any Bidi controls. | 50 // Returns whether the items contain any Bidi controls. |
| 42 bool HasBidiControls() const { return has_bidi_controls_; } | 51 bool HasBidiControls() const { return has_bidi_controls_; } |
| 43 | 52 |
| 44 // Append a string. | 53 // Append a string. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 71 // Append a Bidi control character, for LTR or RTL depends on the style. | 80 // Append a Bidi control character, for LTR or RTL depends on the style. |
| 72 void AppendBidiControl(const ComputedStyle*, UChar ltr, UChar rtl); | 81 void AppendBidiControl(const ComputedStyle*, UChar ltr, UChar rtl); |
| 73 | 82 |
| 74 void EnterBlock(const ComputedStyle*); | 83 void EnterBlock(const ComputedStyle*); |
| 75 void ExitBlock(); | 84 void ExitBlock(); |
| 76 void EnterInline(LayoutObject*); | 85 void EnterInline(LayoutObject*); |
| 77 void ExitInline(LayoutObject*); | 86 void ExitInline(LayoutObject*); |
| 78 | 87 |
| 79 private: | 88 private: |
| 80 Vector<NGInlineItem>* items_; | 89 Vector<NGInlineItem>* items_; |
| 90 Vector<Vector<unsigned>>* removed_indexes_; | |
|
kojii
2017/06/19 05:56:33
ditto.
Xiaocheng
2017/06/19 17:53:01
Done.
| |
| 91 Optional<Vector<unsigned>> input_strings_lengths_; | |
|
Xiaocheng
2017/06/17 00:35:06
Appending a string may result in the removal of a
yosin_UTC9
2017/06/19 03:23:11
Since NGInlineItemsBuild allocated on stack, == on
Xiaocheng
2017/06/19 05:15:51
Will do.
yosin_UTC9
2017/06/19 05:55:13
It is functional abstraction of each then-clause a
| |
| 81 StringBuilder text_; | 92 StringBuilder text_; |
| 82 | 93 |
| 83 typedef struct OnExitNode { | 94 typedef struct OnExitNode { |
| 84 LayoutObject* node; | 95 LayoutObject* node; |
| 85 UChar character; | 96 UChar character; |
| 86 } OnExitNode; | 97 } OnExitNode; |
| 87 Vector<OnExitNode> exits_; | 98 Vector<OnExitNode> exits_; |
| 88 | 99 |
| 89 enum class CollapsibleSpace { kNone, kSpace, kNewline }; | 100 enum class CollapsibleSpace { kNone, kSpace, kNewline }; |
| 90 | 101 |
| 91 CollapsibleSpace last_collapsible_space_ = CollapsibleSpace::kSpace; | 102 CollapsibleSpace last_collapsible_space_ = CollapsibleSpace::kSpace; |
| 92 bool is_svgtext_ = false; | 103 bool is_svgtext_ = false; |
| 93 bool has_bidi_controls_ = false; | 104 bool has_bidi_controls_ = false; |
| 94 | 105 |
| 95 void AppendWithWhiteSpaceCollapsing(const String&, | 106 void AppendWithWhiteSpaceCollapsing(const String&, |
| 96 unsigned start, | 107 unsigned start, |
| 97 unsigned end, | 108 unsigned end, |
| 98 const ComputedStyle*, | 109 const ComputedStyle*, |
| 99 LayoutObject*); | 110 LayoutObject*); |
| 100 void AppendWithoutWhiteSpaceCollapsing(const String&, | 111 void AppendWithoutWhiteSpaceCollapsing(const String&, |
| 101 const ComputedStyle*, | 112 const ComputedStyle*, |
| 102 LayoutObject*); | 113 LayoutObject*); |
| 103 void AppendWithPreservingNewlines(const String&, | 114 void AppendWithPreservingNewlines(const String&, |
| 104 const ComputedStyle*, | 115 const ComputedStyle*, |
| 105 LayoutObject*); | 116 LayoutObject*); |
| 106 | 117 |
| 107 void AppendForcedBreak(const ComputedStyle*, LayoutObject*); | 118 // Returns true if a previously appended collapsible space is removed. |
| 119 bool AppendForcedBreak(const ComputedStyle*, LayoutObject*); | |
| 108 | 120 |
| 109 // Because newlines may be removed depends on following characters, newlines | 121 // Because newlines may be removed depends on following characters, newlines |
| 110 // at the end of input string is not added to |text_| but instead | 122 // at the end of input string is not added to |text_| but instead |
| 111 // |has_pending_newline_| flag is set. | 123 // |has_pending_newline_| flag is set. |
| 112 // This function determines whether to add the newline or ignore. | 124 // This function determines whether to add the newline or ignore. |
| 113 void ProcessPendingNewline(const String&, const ComputedStyle*); | 125 void ProcessPendingNewline(const String&, const ComputedStyle*); |
| 114 | 126 |
| 115 // Removes the collapsible space at the end of |text_| if exists. | 127 // Removes the collapsible space at the end of |text_| if exists. Returns true |
| 116 void RemoveTrailingCollapsibleSpaceIfExists(unsigned*); | 128 // if such a space is removed. |
| 129 bool RemoveTrailingCollapsibleSpaceIfExists(unsigned*); | |
| 117 void RemoveTrailingCollapsibleSpace(unsigned*); | 130 void RemoveTrailingCollapsibleSpace(unsigned*); |
| 118 | 131 |
| 119 void RemoveTrailingCollapsibleNewlineIfNeeded(unsigned*, | 132 // Returns true if a collapsible newline at the end of |text_| is removed. |
| 133 bool RemoveTrailingCollapsibleNewlineIfNeeded(unsigned*, | |
| 120 const String&, | 134 const String&, |
| 121 unsigned, | 135 unsigned, |
| 122 const ComputedStyle*); | 136 const ComputedStyle*); |
| 123 | 137 |
| 138 void AddLastTrailingSpaceToRemovedIndexes(unsigned); | |
| 139 | |
| 124 void Enter(LayoutObject*, UChar); | 140 void Enter(LayoutObject*, UChar); |
| 125 void Exit(LayoutObject*); | 141 void Exit(LayoutObject*); |
| 126 }; | 142 }; |
| 127 | 143 |
| 128 } // namespace blink | 144 } // namespace blink |
| 129 | 145 |
| 130 #endif // NGInlineItemsBuilder_h | 146 #endif // NGInlineItemsBuilder_h |
| OLD | NEW |