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/empty_offset_mapping_builder.h" | 9 #include "core/layout/ng/inline/empty_offset_mapping_builder.h" |
10 #include "core/layout/ng/inline/ng_inline_node.h" | 10 #include "core/layout/ng/inline/ng_inline_node.h" |
| 11 #include "core/layout/ng/inline/ng_offset_mapping_builder.h" |
11 #include "platform/wtf/Allocator.h" | 12 #include "platform/wtf/Allocator.h" |
12 #include "platform/wtf/Vector.h" | 13 #include "platform/wtf/Vector.h" |
13 #include "platform/wtf/text/StringBuilder.h" | 14 #include "platform/wtf/text/StringBuilder.h" |
14 #include "platform/wtf/text/WTFString.h" | 15 #include "platform/wtf/text/WTFString.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 class ComputedStyle; | 19 class ComputedStyle; |
19 class LayoutObject; | 20 class LayoutObject; |
20 class NGInlineItem; | 21 class NGInlineItem; |
21 | 22 |
22 // NGInlineItemsBuilder builds a string and a list of NGInlineItem from inlines. | 23 // NGInlineItemsBuilder builds a string and a list of NGInlineItem from inlines. |
23 // | 24 // |
24 // When appending, spaces are collapsed according to CSS Text, The white space | 25 // When appending, spaces are collapsed according to CSS Text, The white space |
25 // processing rules | 26 // processing rules |
26 // https://drafts.csswg.org/css-text-3/#white-space-rules | 27 // https://drafts.csswg.org/css-text-3/#white-space-rules |
27 // | 28 // |
28 // By calling EnterInline/ExitInline, it inserts bidirectional control | 29 // By calling EnterInline/ExitInline, it inserts bidirectional control |
29 // characters as defined in: | 30 // characters as defined in: |
30 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection-ta
ble | 31 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection-ta
ble |
31 // TODO(xiaochengh): Utilize the passed-in OffsetMappingBuilder to construct | 32 // |
32 // the whitespace-collapsed offset mapping. | 33 // NGInlineItemsBuilder may optionally take an NGOffsetMappingBuilder template |
| 34 // parameter to construct the white-space collapsed offset mapping, which maps |
| 35 // offsets in the concatenation of all appended strings and characters to |
| 36 // offsets in |text_|. |
| 37 // See https://goo.gl/CJbxky for more details about offset mapping. |
33 template <typename OffsetMappingBuilder> | 38 template <typename OffsetMappingBuilder> |
34 class CORE_TEMPLATE_CLASS_EXPORT NGInlineItemsBuilderTemplate { | 39 class CORE_TEMPLATE_CLASS_EXPORT NGInlineItemsBuilderTemplate { |
35 STACK_ALLOCATED(); | 40 STACK_ALLOCATED(); |
36 | 41 |
37 public: | 42 public: |
38 explicit NGInlineItemsBuilderTemplate(Vector<NGInlineItem>* items) | 43 explicit NGInlineItemsBuilderTemplate(Vector<NGInlineItem>* items) |
39 : items_(items) {} | 44 : items_(items) {} |
40 ~NGInlineItemsBuilderTemplate(); | 45 ~NGInlineItemsBuilderTemplate(); |
41 | 46 |
42 String ToString(); | 47 String ToString(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 LayoutObject* = nullptr); | 85 LayoutObject* = nullptr); |
81 | 86 |
82 // Append a Bidi control character, for LTR or RTL depends on the style. | 87 // Append a Bidi control character, for LTR or RTL depends on the style. |
83 void AppendBidiControl(const ComputedStyle*, UChar ltr, UChar rtl); | 88 void AppendBidiControl(const ComputedStyle*, UChar ltr, UChar rtl); |
84 | 89 |
85 void EnterBlock(const ComputedStyle*); | 90 void EnterBlock(const ComputedStyle*); |
86 void ExitBlock(); | 91 void ExitBlock(); |
87 void EnterInline(LayoutObject*); | 92 void EnterInline(LayoutObject*); |
88 void ExitInline(LayoutObject*); | 93 void ExitInline(LayoutObject*); |
89 | 94 |
| 95 OffsetMappingBuilder& GetOffsetMappingBuilder() { return mapping_builder_; } |
| 96 |
90 private: | 97 private: |
91 Vector<NGInlineItem>* items_; | 98 Vector<NGInlineItem>* items_; |
92 StringBuilder text_; | 99 StringBuilder text_; |
| 100 OffsetMappingBuilder mapping_builder_; |
93 | 101 |
94 typedef struct OnExitNode { | 102 typedef struct OnExitNode { |
95 LayoutObject* node; | 103 LayoutObject* node; |
96 UChar character; | 104 UChar character; |
97 } OnExitNode; | 105 } OnExitNode; |
98 Vector<OnExitNode> exits_; | 106 Vector<OnExitNode> exits_; |
99 | 107 |
100 enum class CollapsibleSpace { kNone, kSpace, kNewline }; | 108 enum class CollapsibleSpace { kNone, kSpace, kNewline }; |
101 | 109 |
102 CollapsibleSpace last_collapsible_space_ = CollapsibleSpace::kSpace; | 110 CollapsibleSpace last_collapsible_space_ = CollapsibleSpace::kSpace; |
(...skipping 19 matching lines...) Expand all Loading... |
122 void RemoveTrailingCollapsibleNewlineIfNeeded(const String&, | 130 void RemoveTrailingCollapsibleNewlineIfNeeded(const String&, |
123 unsigned, | 131 unsigned, |
124 const ComputedStyle*); | 132 const ComputedStyle*); |
125 | 133 |
126 void Enter(LayoutObject*, UChar); | 134 void Enter(LayoutObject*, UChar); |
127 void Exit(LayoutObject*); | 135 void Exit(LayoutObject*); |
128 }; | 136 }; |
129 | 137 |
130 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 138 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
131 NGInlineItemsBuilderTemplate<EmptyOffsetMappingBuilder>; | 139 NGInlineItemsBuilderTemplate<EmptyOffsetMappingBuilder>; |
| 140 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 141 NGInlineItemsBuilderTemplate<NGOffsetMappingBuilder>; |
132 | 142 |
133 using NGInlineItemsBuilder = | 143 using NGInlineItemsBuilder = |
134 NGInlineItemsBuilderTemplate<EmptyOffsetMappingBuilder>; | 144 NGInlineItemsBuilderTemplate<EmptyOffsetMappingBuilder>; |
| 145 using NGInlineItemsBuilderForOffsetMapping = |
| 146 NGInlineItemsBuilderTemplate<NGOffsetMappingBuilder>; |
135 | 147 |
136 } // namespace blink | 148 } // namespace blink |
137 | 149 |
138 #endif // NGInlineItemsBuilder_h | 150 #endif // NGInlineItemsBuilder_h |
OLD | NEW |