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

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

Issue 2913093002: Revert of [css-align] Don't resolve 'auto' values for computed style. (Closed)
Patch Set: 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
128 void LayoutGrid::StyleDidChange(StyleDifference diff, 100 void LayoutGrid::StyleDidChange(StyleDifference diff,
129 const ComputedStyle* old_style) { 101 const ComputedStyle* old_style) {
130 LayoutBlock::StyleDidChange(diff, old_style); 102 LayoutBlock::StyleDidChange(diff, old_style);
131 if (!old_style) 103 if (!old_style)
132 return; 104 return;
133 105
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
161 // FIXME: The following checks could be narrowed down if we kept track of 106 // FIXME: The following checks could be narrowed down if we kept track of
162 // which type of grid items we have: 107 // which type of grid items we have:
163 // - explicit grid size changes impact negative explicitely positioned and 108 // - explicit grid size changes impact negative explicitely positioned and
164 // auto-placed grid items. 109 // auto-placed grid items.
165 // - named grid lines only impact grid items with named grid lines. 110 // - named grid lines only impact grid items with named grid lines.
166 // - auto-flow changes only impacts auto-placed children. 111 // - auto-flow changes only impacts auto-placed children.
167 112
168 if (ExplicitGridDidResize(*old_style) || 113 if (ExplicitGridDidResize(*old_style) ||
169 NamedGridLinesDefinitionDidChange(*old_style) || 114 NamedGridLinesDefinitionDidChange(*old_style) ||
170 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() || 115 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() ||
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 // performed before children are laid out, so we can't use the child cached 1520 // performed before children are laid out, so we can't use the child cached
1576 // values. Hence, we need to compute margins in order to determine the 1521 // values. Hence, we need to compute margins in order to determine the
1577 // available height before stretching. 1522 // available height before stretching.
1578 return grid_area_breadth_for_child - 1523 return grid_area_breadth_for_child -
1579 (child.NeedsLayout() 1524 (child.NeedsLayout()
1580 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child) 1525 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child)
1581 : MarginLogicalHeightForChild(child)); 1526 : MarginLogicalHeightForChild(child));
1582 } 1527 }
1583 1528
1584 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( 1529 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild(
1585 const LayoutBox& child, 1530 const LayoutBox& child) const {
1586 const ComputedStyle* style) const { 1531 if (!child.IsAnonymous()) {
1587 if (!style) 1532 return child.StyleRef().ResolvedAlignSelf(
1588 style = Style(); 1533 SelfAlignmentNormalBehavior(&child));
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.
1589 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), 1538 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child),
1590 style); 1539 Style());
1591 } 1540 }
1592 1541
1593 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( 1542 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild(
1594 const LayoutBox& child, 1543 const LayoutBox& child) const {
1595 const ComputedStyle* style) const { 1544 if (!child.IsAnonymous()) {
1596 if (!style) 1545 return child.StyleRef().ResolvedJustifySelf(
1597 style = Style(); 1546 SelfAlignmentNormalBehavior(&child));
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.
1598 return child.StyleRef().ResolvedJustifySelf( 1551 return child.StyleRef().ResolvedJustifySelf(
1599 SelfAlignmentNormalBehavior(&child), style); 1552 SelfAlignmentNormalBehavior(&child), Style());
1600 } 1553 }
1601 1554
1602 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( 1555 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild(
1603 const LayoutBox& child, 1556 const LayoutBox& child,
1604 GridTrackSizingDirection direction) const { 1557 GridTrackSizingDirection direction) const {
1605 return !IsOrthogonalChild(child) 1558 return !IsOrthogonalChild(child)
1606 ? direction 1559 ? direction
1607 : (direction == kForColumns ? kForRows : kForColumns); 1560 : (direction == kForColumns ? kForRows : kForColumns);
1608 } 1561 }
1609 1562
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 GridAxis baseline_axis) const { 1770 GridAxis baseline_axis) const {
1818 return IsHorizontalGridAxis(baseline_axis) && 1771 return IsHorizontalGridAxis(baseline_axis) &&
1819 ((child.StyleRef().IsFlippedBlocksWritingMode() && 1772 ((child.StyleRef().IsFlippedBlocksWritingMode() &&
1820 !StyleRef().IsFlippedBlocksWritingMode()) || 1773 !StyleRef().IsFlippedBlocksWritingMode()) ||
1821 (child.StyleRef().IsFlippedLinesWritingMode() && 1774 (child.StyleRef().IsFlippedLinesWritingMode() &&
1822 StyleRef().IsFlippedBlocksWritingMode())); 1775 StyleRef().IsFlippedBlocksWritingMode()));
1823 } 1776 }
1824 1777
1825 bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child, 1778 bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child,
1826 GridAxis baseline_axis) const { 1779 GridAxis baseline_axis) const {
1827 ItemPosition align = 1780 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis;
1828 SelfAlignmentForChild(baseline_axis, child).GetPosition(); 1781 ItemPosition align = is_column_axis_baseline
1829 bool has_auto_margins = baseline_axis == kGridColumnAxis 1782 ? AlignSelfForChild(child).GetPosition()
1783 : JustifySelfForChild(child).GetPosition();
1784 bool has_auto_margins = is_column_axis_baseline
1830 ? HasAutoMarginsInColumnAxis(child) 1785 ? HasAutoMarginsInColumnAxis(child)
1831 : HasAutoMarginsInRowAxis(child); 1786 : HasAutoMarginsInRowAxis(child);
1832 return IsBaselinePosition(align) && !has_auto_margins; 1787 return IsBaselinePosition(align) && !has_auto_margins;
1833 } 1788 }
1834 1789
1835 const BaselineGroup& LayoutGrid::GetBaselineGroupForChild( 1790 const BaselineGroup& LayoutGrid::GetBaselineGroupForChild(
1836 const LayoutBox& child, 1791 const LayoutBox& child,
1837 GridAxis baseline_axis) const { 1792 GridAxis baseline_axis) const {
1838 DCHECK(IsBaselineAlignmentForChild(child, baseline_axis)); 1793 DCHECK(IsBaselineAlignmentForChild(child, baseline_axis));
1839 auto& grid = track_sizing_algorithm_.GetGrid(); 1794 auto& grid = track_sizing_algorithm_.GetGrid();
1840 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; 1795 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis;
1841 bool is_row_axis_context = is_column_axis_baseline; 1796 bool is_row_axis_context = is_column_axis_baseline;
1842 const auto& span = is_row_axis_context 1797 const auto& span = is_row_axis_context
1843 ? grid.GridItemSpan(child, kForRows) 1798 ? grid.GridItemSpan(child, kForRows)
1844 : grid.GridItemSpan(child, kForColumns); 1799 : grid.GridItemSpan(child, kForColumns);
1845 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ 1800 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_
1846 : col_axis_alignment_context_; 1801 : col_axis_alignment_context_;
1847 auto* context = contexts_map.at(span.StartLine()); 1802 auto* context = contexts_map.at(span.StartLine());
1848 DCHECK(context); 1803 DCHECK(context);
1849 ItemPosition align = 1804 ItemPosition align = is_column_axis_baseline
1850 SelfAlignmentForChild(baseline_axis, child).GetPosition(); 1805 ? AlignSelfForChild(child).GetPosition()
1806 : JustifySelfForChild(child).GetPosition();
1851 return context->GetSharedGroup(child, align); 1807 return context->GetSharedGroup(child, align);
1852 } 1808 }
1853 1809
1854 LayoutUnit LayoutGrid::MarginOverForChild(const LayoutBox& child, 1810 LayoutUnit LayoutGrid::MarginOverForChild(const LayoutBox& child,
1855 GridAxis axis) const { 1811 GridAxis axis) const {
1856 return IsHorizontalGridAxis(axis) ? child.MarginRight() : child.MarginTop(); 1812 return IsHorizontalGridAxis(axis) ? child.MarginRight() : child.MarginTop();
1857 } 1813 }
1858 1814
1859 LayoutUnit LayoutGrid::MarginUnderForChild(const LayoutBox& child, 1815 LayoutUnit LayoutGrid::MarginUnderForChild(const LayoutBox& child,
1860 GridAxis axis) const { 1816 GridAxis axis) const {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; 1914 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis;
1959 bool is_row_axis_context = is_column_axis_baseline; 1915 bool is_row_axis_context = is_column_axis_baseline;
1960 const auto& span = is_row_axis_context 1916 const auto& span = is_row_axis_context
1961 ? grid.GridItemSpan(child, kForRows) 1917 ? grid.GridItemSpan(child, kForRows)
1962 : grid.GridItemSpan(child, kForColumns); 1918 : grid.GridItemSpan(child, kForColumns);
1963 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ 1919 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_
1964 : col_axis_alignment_context_; 1920 : col_axis_alignment_context_;
1965 auto add_result = contexts_map.insert(span.StartLine(), nullptr); 1921 auto add_result = contexts_map.insert(span.StartLine(), nullptr);
1966 1922
1967 // Looking for a compatible baseline-sharing group. 1923 // Looking for a compatible baseline-sharing group.
1968 ItemPosition align = 1924 ItemPosition align = is_column_axis_baseline
1969 SelfAlignmentForChild(baseline_axis, child).GetPosition(); 1925 ? AlignSelfForChild(child).GetPosition()
1926 : JustifySelfForChild(child).GetPosition();
1970 if (add_result.is_new_entry) { 1927 if (add_result.is_new_entry) {
1971 add_result.stored_value->value = 1928 add_result.stored_value->value =
1972 WTF::MakeUnique<BaselineContext>(child, align, ascent, descent); 1929 WTF::MakeUnique<BaselineContext>(child, align, ascent, descent);
1973 } else { 1930 } else {
1974 auto* context = add_result.stored_value->value.get(); 1931 auto* context = add_result.stored_value->value.get();
1975 context->UpdateSharedGroup(child, align, ascent, descent); 1932 context->UpdateSharedGroup(child, align, ascent, descent);
1976 } 1933 }
1977 } 1934 }
1978 1935
1979 LayoutUnit LayoutGrid::ColumnAxisBaselineOffsetForChild( 1936 LayoutUnit LayoutGrid::ColumnAxisBaselineOffsetForChild(
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 if (direction == kForRows) 2388 if (direction == kForRows)
2432 return grid.NumTracks(kForRows); 2389 return grid.NumTracks(kForRows);
2433 2390
2434 return grid.NumTracks(kForRows) 2391 return grid.NumTracks(kForRows)
2435 ? grid.NumTracks(kForColumns) 2392 ? grid.NumTracks(kForColumns)
2436 : GridPositionsResolver::ExplicitGridColumnCount( 2393 : GridPositionsResolver::ExplicitGridColumnCount(
2437 StyleRef(), grid.AutoRepeatTracks(kForColumns)); 2394 StyleRef(), grid.AutoRepeatTracks(kForColumns));
2438 } 2395 }
2439 2396
2440 } // namespace blink 2397 } // 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