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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 2455093002: [css-align] Don't resolve 'auto' values for computed style. (Closed)
Patch Set: Patch for landing. 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 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // layout of the grid, for that reason we don't need to mark the grid as dirty 90 // layout of the grid, for that reason we don't need to mark the grid as dirty
91 // when they are removed. 91 // when they are removed.
92 if (child->IsOutOfFlowPositioned()) 92 if (child->IsOutOfFlowPositioned())
93 return; 93 return;
94 94
95 // The grid needs to be recomputed as it might contain auto-placed items that 95 // The grid needs to be recomputed as it might contain auto-placed items that
96 // will change their position. 96 // will change their position.
97 DirtyGrid(); 97 DirtyGrid();
98 } 98 }
99 99
100 StyleSelfAlignmentData LayoutGrid::SelfAlignmentForChild(
101 GridAxis axis,
102 const LayoutBox& child,
103 const ComputedStyle* style) const {
104 return axis == kGridRowAxis ? JustifySelfForChild(child, style)
105 : AlignSelfForChild(child, style);
106 }
107
108 bool LayoutGrid::SelfAlignmentChangedToStretch(GridAxis axis,
109 const ComputedStyle& old_style,
110 const ComputedStyle& new_style,
111 const LayoutBox& child) const {
112 return SelfAlignmentForChild(axis, child, &old_style).GetPosition() !=
113 kItemPositionStretch &&
114 SelfAlignmentForChild(axis, child, &new_style).GetPosition() ==
115 kItemPositionStretch;
116 }
117
118 bool LayoutGrid::SelfAlignmentChangedFromStretch(GridAxis axis,
119 const ComputedStyle& old_style,
120 const ComputedStyle& new_style,
121 const LayoutBox& child) const {
122 return SelfAlignmentForChild(axis, child, &old_style).GetPosition() ==
123 kItemPositionStretch &&
124 SelfAlignmentForChild(axis, child, &new_style).GetPosition() !=
125 kItemPositionStretch;
126 }
127
100 void LayoutGrid::StyleDidChange(StyleDifference diff, 128 void LayoutGrid::StyleDidChange(StyleDifference diff,
101 const ComputedStyle* old_style) { 129 const ComputedStyle* old_style) {
102 LayoutBlock::StyleDidChange(diff, old_style); 130 LayoutBlock::StyleDidChange(diff, old_style);
103 if (!old_style) 131 if (!old_style)
104 return; 132 return;
105 133
134 const ComputedStyle& new_style = StyleRef();
135 if (old_style &&
136 old_style->ResolvedAlignItems(SelfAlignmentNormalBehavior(this))
137 .GetPosition() == kItemPositionStretch &&
138 diff.NeedsFullLayout()) {
139 // Style changes on the grid container implying stretching (to-stretch) or
140 // shrinking (from-stretch) require the affected items to be laid out again.
141 // These logic only applies to 'stretch' since the rest of the alignment
142 // values don't change the size of the box.
143 // In any case, the items' overrideSize will be cleared and recomputed (if
144 // necessary) as part of the Grid layout logic, triggered by this style
145 // change.
146 for (LayoutBox* child = FirstInFlowChildBox(); child;
147 child = child->NextInFlowSiblingBox()) {
148 if (SelfAlignmentChangedToStretch(kGridRowAxis, *old_style, new_style,
149 *child) ||
150 SelfAlignmentChangedFromStretch(kGridRowAxis, *old_style, new_style,
151 *child) ||
152 SelfAlignmentChangedToStretch(kGridColumnAxis, *old_style, new_style,
153 *child) ||
154 SelfAlignmentChangedFromStretch(kGridColumnAxis, *old_style,
155 new_style, *child)) {
156 child->SetNeedsLayout(LayoutInvalidationReason::kGridChanged);
157 }
158 }
159 }
160
106 // FIXME: The following checks could be narrowed down if we kept track of 161 // FIXME: The following checks could be narrowed down if we kept track of
107 // which type of grid items we have: 162 // which type of grid items we have:
108 // - explicit grid size changes impact negative explicitely positioned and 163 // - explicit grid size changes impact negative explicitely positioned and
109 // auto-placed grid items. 164 // auto-placed grid items.
110 // - named grid lines only impact grid items with named grid lines. 165 // - named grid lines only impact grid items with named grid lines.
111 // - auto-flow changes only impacts auto-placed children. 166 // - auto-flow changes only impacts auto-placed children.
112 167
113 if (ExplicitGridDidResize(*old_style) || 168 if (ExplicitGridDidResize(*old_style) ||
114 NamedGridLinesDefinitionDidChange(*old_style) || 169 NamedGridLinesDefinitionDidChange(*old_style) ||
115 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() || 170 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() ||
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 // performed before children are laid out, so we can't use the child cached 1575 // performed before children are laid out, so we can't use the child cached
1521 // values. Hence, we need to compute margins in order to determine the 1576 // values. Hence, we need to compute margins in order to determine the
1522 // available height before stretching. 1577 // available height before stretching.
1523 return grid_area_breadth_for_child - 1578 return grid_area_breadth_for_child -
1524 (child.NeedsLayout() 1579 (child.NeedsLayout()
1525 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child) 1580 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child)
1526 : MarginLogicalHeightForChild(child)); 1581 : MarginLogicalHeightForChild(child));
1527 } 1582 }
1528 1583
1529 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( 1584 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild(
1530 const LayoutBox& child) const { 1585 const LayoutBox& child,
1531 if (!child.IsAnonymous()) { 1586 const ComputedStyle* style) const {
1532 return child.StyleRef().ResolvedAlignSelf( 1587 if (!style)
1533 SelfAlignmentNormalBehavior(&child)); 1588 style = Style();
1534 }
1535 // All the 'auto' values has been solved by the StyleAdjuster, but it's
1536 // possible that some grid items generate Anonymous boxes, which need to be
1537 // solved during layout.
1538 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), 1589 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child),
1539 Style()); 1590 style);
1540 } 1591 }
1541 1592
1542 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( 1593 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild(
1543 const LayoutBox& child) const { 1594 const LayoutBox& child,
1544 if (!child.IsAnonymous()) { 1595 const ComputedStyle* style) const {
1545 return child.StyleRef().ResolvedJustifySelf( 1596 if (!style)
1546 SelfAlignmentNormalBehavior(&child)); 1597 style = Style();
1547 }
1548 // All the 'auto' values has been solved by the StyleAdjuster, but it's
1549 // possible that some grid items generate Anonymous boxes, which need to be
1550 // solved during layout.
1551 return child.StyleRef().ResolvedJustifySelf( 1598 return child.StyleRef().ResolvedJustifySelf(
1552 SelfAlignmentNormalBehavior(&child), Style()); 1599 SelfAlignmentNormalBehavior(&child), style);
1553 } 1600 }
1554 1601
1555 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( 1602 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild(
1556 const LayoutBox& child, 1603 const LayoutBox& child,
1557 GridTrackSizingDirection direction) const { 1604 GridTrackSizingDirection direction) const {
1558 return !IsOrthogonalChild(child) 1605 return !IsOrthogonalChild(child)
1559 ? direction 1606 ? direction
1560 : (direction == kForColumns ? kForRows : kForColumns); 1607 : (direction == kForColumns ? kForRows : kForColumns);
1561 } 1608 }
1562 1609
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 GridAxis baseline_axis) const { 1817 GridAxis baseline_axis) const {
1771 return IsHorizontalGridAxis(baseline_axis) && 1818 return IsHorizontalGridAxis(baseline_axis) &&
1772 ((child.StyleRef().IsFlippedBlocksWritingMode() && 1819 ((child.StyleRef().IsFlippedBlocksWritingMode() &&
1773 !StyleRef().IsFlippedBlocksWritingMode()) || 1820 !StyleRef().IsFlippedBlocksWritingMode()) ||
1774 (child.StyleRef().IsFlippedLinesWritingMode() && 1821 (child.StyleRef().IsFlippedLinesWritingMode() &&
1775 StyleRef().IsFlippedBlocksWritingMode())); 1822 StyleRef().IsFlippedBlocksWritingMode()));
1776 } 1823 }
1777 1824
1778 bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child, 1825 bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child,
1779 GridAxis baseline_axis) const { 1826 GridAxis baseline_axis) const {
1780 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; 1827 ItemPosition align =
1781 ItemPosition align = is_column_axis_baseline 1828 SelfAlignmentForChild(baseline_axis, child).GetPosition();
1782 ? AlignSelfForChild(child).GetPosition() 1829 bool has_auto_margins = baseline_axis == kGridColumnAxis
1783 : JustifySelfForChild(child).GetPosition();
1784 bool has_auto_margins = is_column_axis_baseline
1785 ? HasAutoMarginsInColumnAxis(child) 1830 ? HasAutoMarginsInColumnAxis(child)
1786 : HasAutoMarginsInRowAxis(child); 1831 : HasAutoMarginsInRowAxis(child);
1787 return IsBaselinePosition(align) && !has_auto_margins; 1832 return IsBaselinePosition(align) && !has_auto_margins;
1788 } 1833 }
1789 1834
1790 const BaselineGroup& LayoutGrid::GetBaselineGroupForChild( 1835 const BaselineGroup& LayoutGrid::GetBaselineGroupForChild(
1791 const LayoutBox& child, 1836 const LayoutBox& child,
1792 GridAxis baseline_axis) const { 1837 GridAxis baseline_axis) const {
1793 DCHECK(IsBaselineAlignmentForChild(child, baseline_axis)); 1838 DCHECK(IsBaselineAlignmentForChild(child, baseline_axis));
1794 auto& grid = track_sizing_algorithm_.GetGrid(); 1839 auto& grid = track_sizing_algorithm_.GetGrid();
1795 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; 1840 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis;
1796 bool is_row_axis_context = is_column_axis_baseline; 1841 bool is_row_axis_context = is_column_axis_baseline;
1797 const auto& span = is_row_axis_context 1842 const auto& span = is_row_axis_context
1798 ? grid.GridItemSpan(child, kForRows) 1843 ? grid.GridItemSpan(child, kForRows)
1799 : grid.GridItemSpan(child, kForColumns); 1844 : grid.GridItemSpan(child, kForColumns);
1800 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ 1845 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_
1801 : col_axis_alignment_context_; 1846 : col_axis_alignment_context_;
1802 auto* context = contexts_map.at(span.StartLine()); 1847 auto* context = contexts_map.at(span.StartLine());
1803 DCHECK(context); 1848 DCHECK(context);
1804 ItemPosition align = is_column_axis_baseline 1849 ItemPosition align =
1805 ? AlignSelfForChild(child).GetPosition() 1850 SelfAlignmentForChild(baseline_axis, child).GetPosition();
1806 : JustifySelfForChild(child).GetPosition();
1807 return context->GetSharedGroup(child, align); 1851 return context->GetSharedGroup(child, align);
1808 } 1852 }
1809 1853
1810 LayoutUnit LayoutGrid::MarginOverForChild(const LayoutBox& child, 1854 LayoutUnit LayoutGrid::MarginOverForChild(const LayoutBox& child,
1811 GridAxis axis) const { 1855 GridAxis axis) const {
1812 return IsHorizontalGridAxis(axis) ? child.MarginRight() : child.MarginTop(); 1856 return IsHorizontalGridAxis(axis) ? child.MarginRight() : child.MarginTop();
1813 } 1857 }
1814 1858
1815 LayoutUnit LayoutGrid::MarginUnderForChild(const LayoutBox& child, 1859 LayoutUnit LayoutGrid::MarginUnderForChild(const LayoutBox& child,
1816 GridAxis axis) const { 1860 GridAxis axis) const {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; 1958 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis;
1915 bool is_row_axis_context = is_column_axis_baseline; 1959 bool is_row_axis_context = is_column_axis_baseline;
1916 const auto& span = is_row_axis_context 1960 const auto& span = is_row_axis_context
1917 ? grid.GridItemSpan(child, kForRows) 1961 ? grid.GridItemSpan(child, kForRows)
1918 : grid.GridItemSpan(child, kForColumns); 1962 : grid.GridItemSpan(child, kForColumns);
1919 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ 1963 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_
1920 : col_axis_alignment_context_; 1964 : col_axis_alignment_context_;
1921 auto add_result = contexts_map.insert(span.StartLine(), nullptr); 1965 auto add_result = contexts_map.insert(span.StartLine(), nullptr);
1922 1966
1923 // Looking for a compatible baseline-sharing group. 1967 // Looking for a compatible baseline-sharing group.
1924 ItemPosition align = is_column_axis_baseline 1968 ItemPosition align =
1925 ? AlignSelfForChild(child).GetPosition() 1969 SelfAlignmentForChild(baseline_axis, child).GetPosition();
1926 : JustifySelfForChild(child).GetPosition();
1927 if (add_result.is_new_entry) { 1970 if (add_result.is_new_entry) {
1928 add_result.stored_value->value = 1971 add_result.stored_value->value =
1929 WTF::MakeUnique<BaselineContext>(child, align, ascent, descent); 1972 WTF::MakeUnique<BaselineContext>(child, align, ascent, descent);
1930 } else { 1973 } else {
1931 auto* context = add_result.stored_value->value.get(); 1974 auto* context = add_result.stored_value->value.get();
1932 context->UpdateSharedGroup(child, align, ascent, descent); 1975 context->UpdateSharedGroup(child, align, ascent, descent);
1933 } 1976 }
1934 } 1977 }
1935 1978
1936 LayoutUnit LayoutGrid::ColumnAxisBaselineOffsetForChild( 1979 LayoutUnit LayoutGrid::ColumnAxisBaselineOffsetForChild(
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 if (direction == kForRows) 2431 if (direction == kForRows)
2389 return grid.NumTracks(kForRows); 2432 return grid.NumTracks(kForRows);
2390 2433
2391 return grid.NumTracks(kForRows) 2434 return grid.NumTracks(kForRows)
2392 ? grid.NumTracks(kForColumns) 2435 ? grid.NumTracks(kForColumns)
2393 : GridPositionsResolver::ExplicitGridColumnCount( 2436 : GridPositionsResolver::ExplicitGridColumnCount(
2394 StyleRef(), grid.AutoRepeatTracks(kForColumns)); 2437 StyleRef(), grid.AutoRepeatTracks(kForColumns));
2395 } 2438 }
2396 2439
2397 } // namespace blink 2440 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | third_party/WebKit/Source/core/style/ComputedStyle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698