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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/inline/ng_inline_items_builder.h

Issue 2943573002: Make NGInlineItemsBuilder construct whitespace-collapsed offset mapping (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/inline/ng_inline_items_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 23 matching lines...) Expand all
34 explicit NGInlineItemsBuilder(Vector<NGInlineItem>* items) : items_(items) {} 34 explicit NGInlineItemsBuilder(Vector<NGInlineItem>* items) : items_(items) {}
35 ~NGInlineItemsBuilder(); 35 ~NGInlineItemsBuilder();
36 36
37 String ToString(); 37 String ToString();
38 38
39 void SetIsSVGText(bool value) { is_svgtext_ = value; } 39 void SetIsSVGText(bool value) { is_svgtext_ = value; }
40 40
41 // Returns whether the items contain any Bidi controls. 41 // Returns whether the items contain any Bidi controls.
42 bool HasBidiControls() const { return has_bidi_controls_; } 42 bool HasBidiControls() const { return has_bidi_controls_; }
43 43
44 using AppendResult = std::pair<bool, Vector<unsigned>>;
45
44 // Append a string. 46 // Append a string.
45 // When appending, spaces are collapsed according to CSS Text, The white space 47 // When appending, spaces are collapsed according to CSS Text, The white space
46 // processing rules 48 // processing rules
47 // https://drafts.csswg.org/css-text-3/#white-space-rules 49 // https://drafts.csswg.org/css-text-3/#white-space-rules
48 // @param style The style for the string. 50 // @param style The style for the string.
49 // If a nullptr, it should skip shaping. Atomic inlines and bidi controls use 51 // If a nullptr, it should skip shaping. Atomic inlines and bidi controls use
50 // this. 52 // this.
51 // @param LayoutObject The LayoutObject for the string. 53 // @param LayoutObject The LayoutObject for the string.
52 // If a nullptr, it does not generate BidiRun. Bidi controls use this. 54 // If a nullptr, it does not generate BidiRun. Bidi controls use this.
53 void Append(const String&, const ComputedStyle*, LayoutObject* = nullptr); 55 // @return A pair, where the boolean denotes if the appending results in the
56 // removal of a preceeding collapsible space, and the vector gives the indexes
57 // of the collapsed spaces in the appended string.
yoichio 2017/06/16 01:47:48 Does this value have enough information to build o
Xiaocheng 2017/06/16 01:59:14 Yes. The returned vector will contain the indexes
58 AppendResult Append(const String&,
59 const ComputedStyle*,
60 LayoutObject* = nullptr);
54 61
55 // Append a character. 62 // Append a character.
56 // Currently this function is for adding control characters such as 63 // Currently this function is for adding control characters such as
57 // objectReplacementCharacter, and does not support all space collapsing logic 64 // objectReplacementCharacter, and does not support all space collapsing logic
58 // as its String version does. 65 // as its String version does.
59 // See the String version for using nullptr for ComputedStyle and 66 // See the String version for using nullptr for ComputedStyle and
60 // LayoutObject. 67 // LayoutObject.
61 void Append(NGInlineItem::NGInlineItemType, 68 void Append(NGInlineItem::NGInlineItemType,
62 UChar, 69 UChar,
63 const ComputedStyle* = nullptr, 70 const ComputedStyle* = nullptr,
64 LayoutObject* = nullptr); 71 LayoutObject* = nullptr);
65 72
66 // Append a non-character item. 73 // Append a non-character item.
67 void Append(NGInlineItem::NGInlineItemType, 74 void Append(NGInlineItem::NGInlineItemType,
68 const ComputedStyle* = nullptr, 75 const ComputedStyle* = nullptr,
69 LayoutObject* = nullptr); 76 LayoutObject* = nullptr);
70 77
71 // Append a Bidi control character, for LTR or RTL depends on the style. 78 // Append a Bidi control character, for LTR or RTL depends on the style.
72 void AppendBidiControl(const ComputedStyle*, UChar ltr, UChar rtl); 79 void AppendBidiControl(const ComputedStyle*, UChar ltr, UChar rtl);
73 80
74 void EnterBlock(const ComputedStyle*); 81 void EnterBlock(const ComputedStyle*);
75 void ExitBlock(); 82 void ExitBlock();
76 void EnterInline(LayoutObject*); 83 void EnterInline(LayoutObject*);
77 void ExitInline(LayoutObject*); 84 void ExitInline(LayoutObject*);
78 85
86 // Returns true if the finalization removes a previous collapsible space.
87 bool Finalize();
Xiaocheng 2017/06/16 00:09:44 This function is refactored out from ToString(), s
88
79 private: 89 private:
80 Vector<NGInlineItem>* items_; 90 Vector<NGInlineItem>* items_;
81 StringBuilder text_; 91 StringBuilder text_;
82 92
83 typedef struct OnExitNode { 93 typedef struct OnExitNode {
84 LayoutObject* node; 94 LayoutObject* node;
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
95 void AppendWithWhiteSpaceCollapsing(const String&, 105 AppendResult AppendWithWhiteSpaceCollapsing(const String&,
96 unsigned start, 106 unsigned start,
97 unsigned end, 107 unsigned end,
98 const ComputedStyle*, 108 const ComputedStyle*,
99 LayoutObject*); 109 LayoutObject*);
100 void AppendWithoutWhiteSpaceCollapsing(const String&, 110 AppendResult AppendWithoutWhiteSpaceCollapsing(const String&,
101 const ComputedStyle*, 111 const ComputedStyle*,
102 LayoutObject*); 112 LayoutObject*);
103 void AppendWithPreservingNewlines(const String&, 113 AppendResult AppendWithPreservingNewlines(const String&,
104 const ComputedStyle*, 114 const ComputedStyle*,
105 LayoutObject*); 115 LayoutObject*);
106 116
107 void AppendForcedBreak(const ComputedStyle*, LayoutObject*); 117 // Returns if a previous collapsible space is removed.
118 bool AppendForcedBreak(const ComputedStyle*, LayoutObject*);
108 119
109 // Because newlines may be removed depends on following characters, newlines 120 // Because newlines may be removed depends on following characters, newlines
110 // at the end of input string is not added to |text_| but instead 121 // at the end of input string is not added to |text_| but instead
111 // |has_pending_newline_| flag is set. 122 // |has_pending_newline_| flag is set.
112 // This function determines whether to add the newline or ignore. 123 // This function determines whether to add the newline or ignore.
113 void ProcessPendingNewline(const String&, const ComputedStyle*); 124 void ProcessPendingNewline(const String&, const ComputedStyle*);
114 125
115 // Removes the collapsible space at the end of |text_| if exists. 126 // Removes the collapsible space at the end of |text_| if exists. Returns true
116 void RemoveTrailingCollapsibleSpaceIfExists(unsigned*); 127 // is a collapsible space is removed.
128 bool RemoveTrailingCollapsibleSpaceIfExists(unsigned*);
117 void RemoveTrailingCollapsibleSpace(unsigned*); 129 void RemoveTrailingCollapsibleSpace(unsigned*);
118 130
119 void RemoveTrailingCollapsibleNewlineIfNeeded(unsigned*, 131 // Returns true if a collapsible newline is removed.
132 bool RemoveTrailingCollapsibleNewlineIfNeeded(unsigned*,
120 const String&, 133 const String&,
121 unsigned, 134 unsigned,
122 const ComputedStyle*); 135 const ComputedStyle*);
123 136
124 void Enter(LayoutObject*, UChar); 137 void Enter(LayoutObject*, UChar);
125 void Exit(LayoutObject*); 138 void Exit(LayoutObject*);
126 }; 139 };
127 140
128 } // namespace blink 141 } // namespace blink
129 142
130 #endif // NGInlineItemsBuilder_h 143 #endif // NGInlineItemsBuilder_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/inline/ng_inline_items_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698