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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_floats_utils.cc

Issue 2872593003: [LayoutNG] Introduce NGPositionedFloat. (Closed)
Patch Set: address comments. Created 3 years, 7 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 #include "core/layout/ng/ng_floats_utils.h" 5 #include "core/layout/ng/ng_floats_utils.h"
6 6
7 #include "core/layout/ng/ng_box_fragment.h" 7 #include "core/layout/ng/ng_box_fragment.h"
8 #include "core/layout/ng/ng_layout_opportunity_iterator.h" 8 #include "core/layout/ng/ng_layout_opportunity_iterator.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 exclusion.type = exclusion_type; 71 exclusion.type = exclusion_type;
72 NGLogicalRect& rect = exclusion.rect; 72 NGLogicalRect& rect = exclusion.rect;
73 rect.offset = opportunity.offset; 73 rect.offset = opportunity.offset;
74 rect.offset.inline_offset += float_offset; 74 rect.offset.inline_offset += float_offset;
75 75
76 rect.size.inline_size = fragment.InlineSize() + margins.InlineSum(); 76 rect.size.inline_size = fragment.InlineSize() + margins.InlineSum();
77 rect.size.block_size = fragment.BlockSize() + margins.BlockSum(); 77 rect.size.block_size = fragment.BlockSize() + margins.BlockSum();
78 return exclusion; 78 return exclusion;
79 } 79 }
80 80
81 // Updates the Floating Object's left offset from the provided parent_space 81 // Calculates the Floating Object's left offset from the provided parent_space
82 // and {@code floating_object}'s space and margins. 82 // and {@code floating_object}'s space and margins.
83 void UpdateFloatingObjectLeftOffset(const NGConstraintSpace& new_parent_space, 83 LayoutUnit CalculateLeftOffset(const NGConstraintSpace& new_parent_space,
84 const NGLogicalOffset& float_logical_offset, 84 const NGLogicalOffset& float_logical_offset,
85 NGFloatingObject* floating_object) { 85 const NGFloatingObject& floating_object) {
86 DCHECK(floating_object);
87 // TODO(glebl): We should use physical offset here. 86 // TODO(glebl): We should use physical offset here.
88 floating_object->left_offset = floating_object->from_offset.inline_offset - 87 return floating_object.from_offset.inline_offset -
89 new_parent_space.BfcOffset().inline_offset + 88 new_parent_space.BfcOffset().inline_offset +
90 float_logical_offset.inline_offset; 89 float_logical_offset.inline_offset;
91 } 90 }
92 } // namespace 91 } // namespace
93 92
94 NGLogicalOffset PositionFloat(NGFloatingObject* floating_object, 93 NGPositionedFloat PositionFloat(NGFloatingObject* floating_object,
95 NGConstraintSpace* new_parent_space) { 94 NGConstraintSpace* new_parent_space) {
96 DCHECK(floating_object); 95 DCHECK(floating_object);
97 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; 96 DCHECK(floating_object->fragment) << "Fragment cannot be null here";
98 97
99 // TODO(ikilpatrick): The writing mode switching here looks wrong. 98 // TODO(ikilpatrick): The writing mode switching here looks wrong.
100 NGBoxFragment float_fragment( 99 NGBoxFragment float_fragment(
101 floating_object->writing_mode, 100 floating_object->writing_mode,
102 ToNGPhysicalBoxFragment(floating_object->fragment.Get())); 101 ToNGPhysicalBoxFragment(floating_object->fragment.Get()));
103 102
104 // Find a layout opportunity that will fit our float. 103 // Find a layout opportunity that will fit our float.
105 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFloat( 104 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFloat(
(...skipping 19 matching lines...) Expand all
125 } 124 }
126 125
127 // Add the float as an exclusion. 126 // Add the float as an exclusion.
128 const NGExclusion exclusion = CreateExclusion( 127 const NGExclusion exclusion = CreateExclusion(
129 float_fragment, opportunity, float_offset, floating_object->margins, 128 float_fragment, opportunity, float_offset, floating_object->margins,
130 floating_object->exclusion_type); 129 floating_object->exclusion_type);
131 new_parent_space->AddExclusion(exclusion); 130 new_parent_space->AddExclusion(exclusion);
132 131
133 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( 132 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity(
134 opportunity, float_offset, floating_object); 133 opportunity, float_offset, floating_object);
135 UpdateFloatingObjectLeftOffset(*new_parent_space, logical_offset, 134
136 floating_object); 135 LayoutUnit left_offset =
137 return logical_offset; 136 CalculateLeftOffset(*new_parent_space, logical_offset, *floating_object);
137
138 return NGPositionedFloat(floating_object->fragment, logical_offset,
139 left_offset);
138 } 140 }
139 141
140 void PositionFloats(LayoutUnit origin_block_offset, 142 const Vector<NGPositionedFloat> PositionFloats(
141 LayoutUnit from_block_offset, 143 LayoutUnit origin_block_offset,
142 const Vector<RefPtr<NGFloatingObject>>& floating_objects, 144 LayoutUnit from_block_offset,
143 NGConstraintSpace* space) { 145 const Vector<RefPtr<NGFloatingObject>>& floating_objects,
146 NGConstraintSpace* space) {
147 Vector<NGPositionedFloat> positioned_floats;
148 positioned_floats.ReserveCapacity(floating_objects.size());
149
144 for (auto& floating_object : floating_objects) { 150 for (auto& floating_object : floating_objects) {
145 floating_object->origin_offset.block_offset = origin_block_offset; 151 floating_object->origin_offset.block_offset = origin_block_offset;
146 floating_object->from_offset.block_offset = from_block_offset; 152 floating_object->from_offset.block_offset = from_block_offset;
147 floating_object->logical_offset = 153 positioned_floats.push_back(PositionFloat(floating_object.Get(), space));
148 PositionFloat(floating_object.Get(), space);
149 } 154 }
155
156 return positioned_floats;
150 } 157 }
151 158
152 } // namespace blink 159 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698