Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| index a3d2251f604ddcf99a55b211e97605c555f5ae2a..71ccc3843817aca1ec2f41db07d7f559af61d013 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| @@ -97,12 +97,64 @@ void LayoutGrid::RemoveChild(LayoutObject* child) { |
| DirtyGrid(); |
| } |
| +StyleSelfAlignmentData LayoutGrid::SelfAlignmentForChild( |
| + GridAxis axis, |
| + const LayoutBox& child, |
| + const ComputedStyle* style) const { |
| + return axis == kGridRowAxis ? JustifySelfForChild(child, style) |
| + : AlignSelfForChild(child, style); |
| +} |
| + |
| +bool LayoutGrid::SelfAlignmentChangedToStretch(GridAxis axis, |
| + const ComputedStyle& old_style, |
| + const ComputedStyle& new_style, |
| + const LayoutBox& child) const { |
| + return SelfAlignmentForChild(axis, child, &old_style).GetPosition() != |
| + kItemPositionStretch && |
| + SelfAlignmentForChild(axis, child, &new_style).GetPosition() == |
| + kItemPositionStretch; |
| +} |
| + |
| +bool LayoutGrid::SelfAlignmentChangedFromStretch(GridAxis axis, |
| + const ComputedStyle& old_style, |
| + const ComputedStyle& new_style, |
| + const LayoutBox& child) const { |
| + return SelfAlignmentForChild(axis, child, &old_style).GetPosition() == |
| + kItemPositionStretch && |
| + SelfAlignmentForChild(axis, child, &new_style).GetPosition() != |
| + kItemPositionStretch; |
| +} |
| + |
| void LayoutGrid::StyleDidChange(StyleDifference diff, |
| const ComputedStyle* old_style) { |
| LayoutBlock::StyleDidChange(diff, old_style); |
| if (!old_style) |
| return; |
| + const ComputedStyle& new_style = StyleRef(); |
| + if (old_style && |
| + old_style->ResolvedAlignItems(SelfAlignmentNormalBehavior(this)) |
| + .GetPosition() == kItemPositionStretch && |
| + diff.NeedsFullLayout()) { |
| + // Grid items that were not previously stretched in row-axis need to be |
| + // relayed out so we can compute new available space. |
|
cbiesinger1
2017/05/25 18:10:02
OK, thanks for the explanation. I think this comme
|
| + // Grid items that were previously stretching in column-axis need to be |
| + // relayed out so we can compute new available space. |
| + // This is only necessary for stretching since other alignment values don't |
| + // change the size of the box. |
| + for (LayoutBox* child = FirstInFlowChildBox(); child; |
| + child = child->NextInFlowSiblingBox()) { |
| + if (SelfAlignmentChangedToStretch(kGridRowAxis, *old_style, new_style, |
| + *child) || |
| + SelfAlignmentChangedFromStretch(kGridRowAxis, *old_style, new_style, |
| + *child) || |
| + SelfAlignmentChangedFromStretch(kGridColumnAxis, *old_style, |
| + new_style, *child)) { |
| + child->SetNeedsLayout(LayoutInvalidationReason::kGridChanged); |
| + } |
| + } |
| + } |
| + |
| // FIXME: The following checks could be narrowed down if we kept track of |
| // which type of grid items we have: |
| // - explicit grid size changes impact negative explicitely positioned and |
| @@ -1527,29 +1579,21 @@ LayoutUnit LayoutGrid::AvailableAlignmentSpaceForChildBeforeStretching( |
| } |
| StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( |
| - const LayoutBox& child) const { |
| - if (!child.IsAnonymous()) { |
| - return child.StyleRef().ResolvedAlignSelf( |
| - SelfAlignmentNormalBehavior(&child)); |
| - } |
| - // All the 'auto' values has been solved by the StyleAdjuster, but it's |
| - // possible that some grid items generate Anonymous boxes, which need to be |
| - // solved during layout. |
| + const LayoutBox& child, |
| + const ComputedStyle* style) const { |
| + if (!style) |
| + style = Style(); |
| return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), |
| - Style()); |
| + style); |
| } |
| StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( |
| - const LayoutBox& child) const { |
| - if (!child.IsAnonymous()) { |
| - return child.StyleRef().ResolvedJustifySelf( |
| - SelfAlignmentNormalBehavior(&child)); |
| - } |
| - // All the 'auto' values has been solved by the StyleAdjuster, but it's |
| - // possible that some grid items generate Anonymous boxes, which need to be |
| - // solved during layout. |
| + const LayoutBox& child, |
| + const ComputedStyle* style) const { |
| + if (!style) |
| + style = Style(); |
| return child.StyleRef().ResolvedJustifySelf( |
| - SelfAlignmentNormalBehavior(&child), Style()); |
| + SelfAlignmentNormalBehavior(&child), style); |
| } |
| GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( |
| @@ -1777,11 +1821,9 @@ bool LayoutGrid::IsDescentBaselineForChild(const LayoutBox& child, |
| bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child, |
| GridAxis baseline_axis) const { |
| - bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; |
| - ItemPosition align = is_column_axis_baseline |
| - ? AlignSelfForChild(child).GetPosition() |
| - : JustifySelfForChild(child).GetPosition(); |
| - bool has_auto_margins = is_column_axis_baseline |
| + ItemPosition align = |
| + SelfAlignmentForChild(baseline_axis, child).GetPosition(); |
| + bool has_auto_margins = baseline_axis == kGridColumnAxis |
| ? HasAutoMarginsInColumnAxis(child) |
| : HasAutoMarginsInRowAxis(child); |
| return IsBaselinePosition(align) && !has_auto_margins; |
| @@ -1801,9 +1843,8 @@ const BaselineGroup& LayoutGrid::GetBaselineGroupForChild( |
| : col_axis_alignment_context_; |
| auto* context = contexts_map.at(span.StartLine()); |
| DCHECK(context); |
| - ItemPosition align = is_column_axis_baseline |
| - ? AlignSelfForChild(child).GetPosition() |
| - : JustifySelfForChild(child).GetPosition(); |
| + ItemPosition align = |
| + SelfAlignmentForChild(baseline_axis, child).GetPosition(); |
| return context->GetSharedGroup(child, align); |
| } |
| @@ -1921,9 +1962,8 @@ void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( |
| auto add_result = contexts_map.insert(span.StartLine(), nullptr); |
| // Looking for a compatible baseline-sharing group. |
| - ItemPosition align = is_column_axis_baseline |
| - ? AlignSelfForChild(child).GetPosition() |
| - : JustifySelfForChild(child).GetPosition(); |
| + ItemPosition align = |
| + SelfAlignmentForChild(baseline_axis, child).GetPosition(); |
| if (add_result.is_new_entry) { |
| add_result.stored_value->value = |
| WTF::MakeUnique<BaselineContext>(child, align, ascent, descent); |