| 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 NGInlineLayoutAlgorithm_h | 5 #ifndef NGInlineLayoutAlgorithm_h |
| 6 #define NGInlineLayoutAlgorithm_h | 6 #define NGInlineLayoutAlgorithm_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/geometry/ng_logical_offset.h" | 9 #include "core/layout/ng/geometry/ng_logical_offset.h" |
| 10 #include "core/layout/ng/inline/ng_inline_box_state.h" | 10 #include "core/layout/ng/inline/ng_inline_box_state.h" |
| 11 #include "core/layout/ng/inline/ng_inline_break_token.h" | 11 #include "core/layout/ng/inline/ng_inline_break_token.h" |
| 12 #include "core/layout/ng/inline/ng_inline_item_result.h" |
| 12 #include "core/layout/ng/inline/ng_line_height_metrics.h" | 13 #include "core/layout/ng/inline/ng_line_height_metrics.h" |
| 13 #include "core/layout/ng/ng_constraint_space_builder.h" | 14 #include "core/layout/ng/ng_constraint_space_builder.h" |
| 14 #include "core/layout/ng/ng_fragment_builder.h" | 15 #include "core/layout/ng/ng_fragment_builder.h" |
| 15 #include "core/layout/ng/ng_layout_algorithm.h" | 16 #include "core/layout/ng/ng_layout_algorithm.h" |
| 16 #include "platform/fonts/FontBaseline.h" | 17 #include "platform/fonts/FontBaseline.h" |
| 17 #include "platform/heap/Handle.h" | 18 #include "platform/heap/Handle.h" |
| 18 #include "platform/wtf/Vector.h" | 19 #include "platform/wtf/Vector.h" |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 // and |end|. |end| can be extended multiple times before creating a line, | 36 // and |end|. |end| can be extended multiple times before creating a line, |
| 36 // usually until |!CanFitOnLine()|. |SetBreakOpportunity| can mark the last | 37 // usually until |!CanFitOnLine()|. |SetBreakOpportunity| can mark the last |
| 37 // confirmed offset that can fit. | 38 // confirmed offset that can fit. |
| 38 class CORE_EXPORT NGInlineLayoutAlgorithm final | 39 class CORE_EXPORT NGInlineLayoutAlgorithm final |
| 39 : public NGLayoutAlgorithm<NGInlineNode, NGInlineBreakToken> { | 40 : public NGLayoutAlgorithm<NGInlineNode, NGInlineBreakToken> { |
| 40 public: | 41 public: |
| 41 NGInlineLayoutAlgorithm(NGInlineNode*, | 42 NGInlineLayoutAlgorithm(NGInlineNode*, |
| 42 NGConstraintSpace*, | 43 NGConstraintSpace*, |
| 43 NGInlineBreakToken* = nullptr); | 44 NGInlineBreakToken* = nullptr); |
| 44 | 45 |
| 45 LayoutUnit MaxInlineSize() const { return max_inline_size_; } | 46 // The available width for the current line. |
| 46 | 47 LayoutUnit AvailableWidth() const; |
| 47 // Returns if the current items fit on a line. | |
| 48 bool CanFitOnLine() const; | |
| 49 | |
| 50 // Returns if there were any items. | |
| 51 bool HasItems() const; | |
| 52 | |
| 53 // Set the end offset. | |
| 54 void SetEnd(unsigned end_offset); | |
| 55 | |
| 56 // Set the end offset if caller knows the inline size since the current end. | |
| 57 void SetEnd(unsigned index, | |
| 58 unsigned end_offset, | |
| 59 LayoutUnit inline_size_since_current_end); | |
| 60 | 48 |
| 61 // Create a line up to the end offset. | 49 // Create a line up to the end offset. |
| 62 // Then set the start to the end offset, and thus empty the current line. | 50 // Then set the start to the end offset, and thus empty the current line. |
| 63 // @return false if the line does not fit in the constraint space in block | 51 // @return false if the line does not fit in the constraint space in block |
| 64 // direction. | 52 // direction. |
| 65 bool CreateLine(); | 53 bool CreateLine(NGInlineItemResults*, RefPtr<NGInlineBreakToken> = nullptr); |
| 66 | |
| 67 // Returns if a break opportunity was set on the current line. | |
| 68 bool HasBreakOpportunity() const; | |
| 69 | |
| 70 // Returns if there were items after the last break opportunity. | |
| 71 bool HasItemsAfterLastBreakOpportunity() const; | |
| 72 | |
| 73 // Set the break opportunity at the current end offset. | |
| 74 void SetBreakOpportunity(); | |
| 75 | |
| 76 // Create a line up to the last break opportunity. | |
| 77 // Items after that are sent to the next line. | |
| 78 // @return false if the line does not fit in the constraint space in block | |
| 79 // direction. | |
| 80 bool CreateLineUpToLastBreakOpportunity(); | |
| 81 | |
| 82 // Set the start offset of hangables; e.g., spaces or hanging punctuations. | |
| 83 // Hangable characters can go beyond the right margin, and are ignored for | |
| 84 // center/right alignment. | |
| 85 void SetStartOfHangables(unsigned offset); | |
| 86 | 54 |
| 87 RefPtr<NGLayoutResult> Layout() override; | 55 RefPtr<NGLayoutResult> Layout() override; |
| 88 | 56 |
| 89 // Compute MinMaxContentSize by performing layout. | 57 // Lays out the inline float. |
| 90 // Unlike NGLayoutAlgorithm::ComputeMinMaxContentSize(), this function runs | 58 // List of actions: |
| 91 // part of layout operations and modifies the state of |this|. | 59 // - tries to position the float right away if we have enough space. |
| 92 MinMaxContentSize ComputeMinMaxContentSizeByLayout(); | 60 // - updates the current_opportunity if we actually place the float. |
| 93 | 61 // - if it's too wide then we add the float to the unpositioned list so it can |
| 94 // Compute inline size of an NGInlineItem. | 62 // be positioned after we're done with the current line. |
| 95 // Same as NGInlineItem::InlineSize(), except that this function can compute | 63 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*); |
| 96 // atomic inlines by performing layout. | |
| 97 LayoutUnit InlineSize(const NGInlineItem&); | |
| 98 | 64 |
| 99 private: | 65 private: |
| 100 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; } | 66 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; } |
| 101 | 67 |
| 102 bool IsFirstLine() const; | 68 bool IsFirstLine() const; |
| 103 const ComputedStyle& FirstLineStyle() const; | 69 const ComputedStyle& FirstLineStyle() const; |
| 104 const ComputedStyle& LineStyle() const; | 70 const ComputedStyle& LineStyle() const; |
| 105 | 71 |
| 106 // Set the start and the end to the specified offset. | 72 void BidiReorder(NGInlineItemResults*); |
| 107 // This empties the current line. | |
| 108 void Initialize(unsigned index, unsigned offset); | |
| 109 | 73 |
| 110 LayoutUnit InlineSize(const NGInlineItem&, | 74 bool PlaceItems(NGInlineItemResults*, RefPtr<NGInlineBreakToken>); |
| 111 unsigned start_offset, | |
| 112 unsigned end_offset); | |
| 113 LayoutUnit InlineSizeFromLayout(const NGInlineItem&); | |
| 114 const NGLayoutResult* LayoutItem(const NGInlineItem&); | |
| 115 | |
| 116 struct LineItemChunk { | |
| 117 unsigned index; | |
| 118 unsigned start_offset; | |
| 119 unsigned end_offset; | |
| 120 LayoutUnit inline_size; | |
| 121 }; | |
| 122 | |
| 123 void BidiReorder(Vector<LineItemChunk, 32>*); | |
| 124 | |
| 125 // Lays out the inline float. | |
| 126 // List of actions: | |
| 127 // - tries to position the float right away if we have enough space. | |
| 128 // - updates the current_opportunity if we actually place the float. | |
| 129 // - if it's too wide then we add the float to the unpositioned list so it can | |
| 130 // be positioned after we're done with the current line. | |
| 131 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*); | |
| 132 | |
| 133 bool PlaceItems(const Vector<LineItemChunk, 32>&); | |
| 134 void AccumulateUsedFonts(const NGInlineItem&, | |
| 135 const LineItemChunk&, | |
| 136 NGLineBoxFragmentBuilder*); | |
| 137 LayoutUnit PlaceAtomicInline(const NGInlineItem&, | 75 LayoutUnit PlaceAtomicInline(const NGInlineItem&, |
| 76 NGInlineItemResult*, |
| 138 NGLineBoxFragmentBuilder*, | 77 NGLineBoxFragmentBuilder*, |
| 139 NGInlineBoxState*, | 78 NGInlineBoxState*, |
| 140 NGTextFragmentBuilder*); | 79 NGTextFragmentBuilder*); |
| 141 | 80 |
| 142 // Finds the next layout opportunity for the next text fragment. | 81 // Finds the next layout opportunity for the next text fragment. |
| 143 void FindNextLayoutOpportunity(); | 82 void FindNextLayoutOpportunity(); |
| 144 | 83 |
| 145 Vector<RefPtr<NGLayoutResult>, 32> layout_results_; | |
| 146 NGInlineLayoutStateStack box_states_; | 84 NGInlineLayoutStateStack box_states_; |
| 147 unsigned start_index_ = 0; | |
| 148 unsigned start_offset_ = 0; | |
| 149 unsigned last_index_ = 0; | |
| 150 unsigned end_offset_ = 0; | |
| 151 unsigned last_break_opportunity_index_ = 0; | |
| 152 unsigned last_break_opportunity_offset_ = 0; | |
| 153 LayoutUnit end_position_; | |
| 154 LayoutUnit last_break_opportunity_position_; | |
| 155 LayoutUnit content_size_; | 85 LayoutUnit content_size_; |
| 156 LayoutUnit max_inline_size_; | 86 LayoutUnit max_inline_size_; |
| 157 FontBaseline baseline_type_ = FontBaseline::kAlphabeticBaseline; | 87 FontBaseline baseline_type_ = FontBaseline::kAlphabeticBaseline; |
| 158 | 88 |
| 159 NGLogicalOffset bfc_offset_; | 89 NGLogicalOffset bfc_offset_; |
| 160 NGLogicalRect current_opportunity_; | 90 NGLogicalRect current_opportunity_; |
| 161 | 91 |
| 162 unsigned is_horizontal_writing_mode_ : 1; | 92 unsigned is_horizontal_writing_mode_ : 1; |
| 163 unsigned disallow_first_line_rules_ : 1; | 93 unsigned disallow_first_line_rules_ : 1; |
| 164 | 94 |
| 165 NGConstraintSpaceBuilder space_builder_; | 95 NGConstraintSpaceBuilder space_builder_; |
| 166 #if DCHECK_IS_ON() | |
| 167 unsigned is_bidi_reordered_ : 1; | |
| 168 #endif | |
| 169 }; | 96 }; |
| 170 | 97 |
| 171 } // namespace blink | 98 } // namespace blink |
| 172 | 99 |
| 173 #endif // NGInlineLayoutAlgorithm_h | 100 #endif // NGInlineLayoutAlgorithm_h |
| OLD | NEW |