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

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

Issue 2910133002: [LayoutNG] Handle empty inlines and border edges (Closed)
Patch Set: Rebase 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 NGInlineBoxState_h 5 #ifndef NGInlineBoxState_h
6 #define NGInlineBoxState_h 6 #define NGInlineBoxState_h
7 7
8 #include "core/CoreExport.h" 8 #include "core/CoreExport.h"
9 #include "core/layout/ng/geometry/ng_logical_size.h" 9 #include "core/layout/ng/geometry/ng_logical_size.h"
10 #include "core/layout/ng/inline/ng_line_height_metrics.h" 10 #include "core/layout/ng/inline/ng_line_height_metrics.h"
11 #include "core/style/ComputedStyleConstants.h" 11 #include "core/style/ComputedStyleConstants.h"
12 #include "platform/LayoutUnit.h" 12 #include "platform/LayoutUnit.h"
13 #include "platform/fonts/FontBaseline.h" 13 #include "platform/fonts/FontBaseline.h"
14 #include "platform/wtf/Vector.h" 14 #include "platform/wtf/Vector.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 class NGInlineItem; 18 class NGInlineItem;
19 struct NGInlineItemResult;
19 class NGLineBoxFragmentBuilder; 20 class NGLineBoxFragmentBuilder;
20 21
21 // Fragments that require the layout position/size of ancestor are packed in 22 // Fragments that require the layout position/size of ancestor are packed in
22 // this struct. 23 // this struct.
23 struct NGPendingPositions { 24 struct NGPendingPositions {
24 unsigned fragment_start; 25 unsigned fragment_start;
25 unsigned fragment_end; 26 unsigned fragment_end;
26 NGLineHeightMetrics metrics; 27 NGLineHeightMetrics metrics;
27 EVerticalAlign vertical_align; 28 EVerticalAlign vertical_align;
28 }; 29 };
29 30
30 // Represents the current box while NGInlineLayoutAlgorithm performs layout. 31 // Represents the current box while NGInlineLayoutAlgorithm performs layout.
31 // Used 1) to cache common values for a box, and 2) to layout children that 32 // Used 1) to cache common values for a box, and 2) to layout children that
32 // require ancestor position or size. 33 // require ancestor position or size.
34 // This is a transient object only while building line boxes in a block.
33 struct NGInlineBoxState { 35 struct NGInlineBoxState {
34 unsigned fragment_start; 36 unsigned fragment_start;
35 const NGInlineItem* item; 37 const NGInlineItem* item;
36 const ComputedStyle* style; 38 const ComputedStyle* style;
37 NGLineHeightMetrics metrics; 39 NGLineHeightMetrics metrics;
38 NGLineHeightMetrics text_metrics; 40 NGLineHeightMetrics text_metrics;
39 LayoutUnit text_top; 41 LayoutUnit text_top;
40 42
41 // These values are to create a box fragment. Set only when needs_box_fragment 43 // These values are to create a box fragment. Set only when needs_box_fragment
42 // is set. 44 // is set.
43 LayoutUnit line_left_position; 45 LayoutUnit line_left_position;
46 LayoutUnit line_right_position;
44 LayoutUnit borders_paddings_block_start; 47 LayoutUnit borders_paddings_block_start;
45 LayoutUnit borders_paddings_block_height; 48 LayoutUnit borders_paddings_block_end;
49 NGBorderEdges border_edges;
46 50
47 Vector<NGPendingPositions> pending_descendants; 51 Vector<NGPendingPositions> pending_descendants;
48 bool include_used_fonts = false; 52 bool include_used_fonts = false;
49 bool needs_box_fragment = false; 53 bool needs_box_fragment = false;
50 54
51 // Compute text metrics for a box. All text in a box share the same metrics. 55 // Compute text metrics for a box. All text in a box share the same metrics.
52 void ComputeTextMetrics(const ComputedStyle& style, FontBaseline); 56 void ComputeTextMetrics(const ComputedStyle& style, FontBaseline);
53 void AccumulateUsedFonts(const NGInlineItem&, 57 void AccumulateUsedFonts(const NGInlineItem&,
54 unsigned start, 58 unsigned start,
55 unsigned end, 59 unsigned end,
56 FontBaseline); 60 FontBaseline);
57 61
58 // Create a box fragment for this box. 62 // Create a box fragment for this box.
59 void SetNeedsBoxFragment(LayoutUnit line_left_position, 63 void SetNeedsBoxFragment(const NGInlineItem&,
60 LayoutUnit borders_paddings_block_start, 64 const NGInlineItemResult&,
61 LayoutUnit borders_paddings_block_height); 65 LayoutUnit position);
66 void SetLineRightForBoxFragment(const NGInlineItem&,
67 const NGInlineItemResult&,
68 LayoutUnit position);
62 }; 69 };
63 70
64 // Represents the inline tree structure. This class provides: 71 // Represents the inline tree structure. This class provides:
65 // 1) Allow access to fragments belonging to the current box. 72 // 1) Allow access to fragments belonging to the current box.
66 // 2) Performs layout when the positin/size of a box was computed. 73 // 2) Performs layout when the positin/size of a box was computed.
67 // 3) Cache common values for a box. 74 // 3) Cache common values for a box.
68 class NGInlineLayoutStateStack { 75 class NGInlineLayoutStateStack {
69 public: 76 public:
70 // The box state for the line box. 77 // The box state for the line box.
71 NGInlineBoxState& LineBoxState() { return stack_.front(); } 78 NGInlineBoxState& LineBoxState() { return stack_.front(); }
72 79
73 // Initialize the box state stack for a new line. 80 // Initialize the box state stack for a new line.
74 // @return The initial box state for the line. 81 // @return The initial box state for the line.
75 NGInlineBoxState* OnBeginPlaceItems(const ComputedStyle*, FontBaseline); 82 NGInlineBoxState* OnBeginPlaceItems(const ComputedStyle*, FontBaseline);
76 83
77 // Push a box state stack. 84 // Push a box state stack.
78 NGInlineBoxState* OnOpenTag(const NGInlineItem&, NGLineBoxFragmentBuilder*); 85 NGInlineBoxState* OnOpenTag(const NGInlineItem&, NGLineBoxFragmentBuilder*);
79 86
80 // Pop a box state stack. 87 // Pop a box state stack.
81 NGInlineBoxState* OnCloseTag(const NGInlineItem&, 88 NGInlineBoxState* OnCloseTag(const NGInlineItem&,
82 NGLineBoxFragmentBuilder*, 89 NGLineBoxFragmentBuilder*,
83 NGInlineBoxState*, 90 NGInlineBoxState*,
84 FontBaseline, 91 FontBaseline);
85 LayoutUnit position);
86 92
87 // Compute all the pending positioning at the end of a line. 93 // Compute all the pending positioning at the end of a line.
88 void OnEndPlaceItems(NGLineBoxFragmentBuilder*, 94 void OnEndPlaceItems(NGLineBoxFragmentBuilder*,
89 FontBaseline, 95 FontBaseline,
90 LayoutUnit position); 96 LayoutUnit position);
91 97
92 private: 98 private:
93 // End of a box state, either explicitly by close tag, or implicitly at the 99 // End of a box state, either explicitly by close tag, or implicitly at the
94 // end of a line. 100 // end of a line.
95 void EndBoxState(NGInlineBoxState*, 101 void EndBoxState(NGInlineBoxState*, NGLineBoxFragmentBuilder*, FontBaseline);
96 NGLineBoxFragmentBuilder*,
97 FontBaseline,
98 LayoutUnit position);
99 102
100 void AddBoxFragmentPlaceholder(NGInlineBoxState*, 103 void AddBoxFragmentPlaceholder(NGInlineBoxState*,
101 NGLineBoxFragmentBuilder*, 104 NGLineBoxFragmentBuilder*,
102 FontBaseline, 105 FontBaseline);
103 LayoutUnit position);
104 void CreateBoxFragments(NGLineBoxFragmentBuilder*); 106 void CreateBoxFragments(NGLineBoxFragmentBuilder*);
105 107
106 enum PositionPending { kPositionNotPending, kPositionPending }; 108 enum PositionPending { kPositionNotPending, kPositionPending };
107 109
108 // Compute vertical position for the 'vertical-align' property. 110 // Compute vertical position for the 'vertical-align' property.
109 // The timing to apply varies by values; some values apply at the layout of 111 // The timing to apply varies by values; some values apply at the layout of
110 // the box was computed. Other values apply when the layout of the parent or 112 // the box was computed. Other values apply when the layout of the parent or
111 // the line box was computed. 113 // the line box was computed.
112 // https://www.w3.org/TR/CSS22/visudet.html#propdef-vertical-align 114 // https://www.w3.org/TR/CSS22/visudet.html#propdef-vertical-align
113 // https://www.w3.org/TR/css-inline-3/#propdef-vertical-align 115 // https://www.w3.org/TR/css-inline-3/#propdef-vertical-align
114 PositionPending ApplyBaselineShift(NGInlineBoxState*, 116 PositionPending ApplyBaselineShift(NGInlineBoxState*,
115 NGLineBoxFragmentBuilder*, 117 NGLineBoxFragmentBuilder*,
116 FontBaseline); 118 FontBaseline);
117 119
118 // Data for a box fragment placeholder. See AddBoxFragmentPlaceholder(). 120 // Data for a box fragment placeholder. See AddBoxFragmentPlaceholder().
121 // This is a transient object only while building a line box.
119 struct BoxFragmentPlaceholder { 122 struct BoxFragmentPlaceholder {
120 unsigned fragment_start; 123 unsigned fragment_start;
121 unsigned fragment_end; 124 unsigned fragment_end;
122 const NGInlineItem* item; 125 const NGInlineItem* item;
123 NGLogicalSize size; 126 NGLogicalSize size;
127 NGBorderEdges border_edges;
124 }; 128 };
125 129
126 Vector<NGInlineBoxState, 4> stack_; 130 Vector<NGInlineBoxState, 4> stack_;
127 Vector<BoxFragmentPlaceholder, 4> box_placeholders_; 131 Vector<BoxFragmentPlaceholder, 4> box_placeholders_;
128 }; 132 };
129 133
130 } // namespace blink 134 } // namespace blink
131 135
132 #endif // NGInlineBoxState_h 136 #endif // NGInlineBoxState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698