OLD | NEW |
---|---|
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 Loading... | |
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 // Grid items that were not previously stretched in row-axis need to be | |
140 // 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
| |
141 // Grid items that were previously stretching in column-axis need to be | |
142 // relayed out so we can compute new available space. | |
143 // This is only necessary for stretching since other alignment values don't | |
144 // change the size of the box. | |
145 for (LayoutBox* child = FirstInFlowChildBox(); child; | |
146 child = child->NextInFlowSiblingBox()) { | |
147 if (SelfAlignmentChangedToStretch(kGridRowAxis, *old_style, new_style, | |
148 *child) || | |
149 SelfAlignmentChangedFromStretch(kGridRowAxis, *old_style, new_style, | |
150 *child) || | |
151 SelfAlignmentChangedFromStretch(kGridColumnAxis, *old_style, | |
152 new_style, *child)) { | |
153 child->SetNeedsLayout(LayoutInvalidationReason::kGridChanged); | |
154 } | |
155 } | |
156 } | |
157 | |
106 // FIXME: The following checks could be narrowed down if we kept track of | 158 // FIXME: The following checks could be narrowed down if we kept track of |
107 // which type of grid items we have: | 159 // which type of grid items we have: |
108 // - explicit grid size changes impact negative explicitely positioned and | 160 // - explicit grid size changes impact negative explicitely positioned and |
109 // auto-placed grid items. | 161 // auto-placed grid items. |
110 // - named grid lines only impact grid items with named grid lines. | 162 // - named grid lines only impact grid items with named grid lines. |
111 // - auto-flow changes only impacts auto-placed children. | 163 // - auto-flow changes only impacts auto-placed children. |
112 | 164 |
113 if (ExplicitGridDidResize(*old_style) || | 165 if (ExplicitGridDidResize(*old_style) || |
114 NamedGridLinesDefinitionDidChange(*old_style) || | 166 NamedGridLinesDefinitionDidChange(*old_style) || |
115 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() || | 167 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() || |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 // performed before children are laid out, so we can't use the child cached | 1572 // 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 | 1573 // values. Hence, we need to compute margins in order to determine the |
1522 // available height before stretching. | 1574 // available height before stretching. |
1523 return grid_area_breadth_for_child - | 1575 return grid_area_breadth_for_child - |
1524 (child.NeedsLayout() | 1576 (child.NeedsLayout() |
1525 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child) | 1577 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child) |
1526 : MarginLogicalHeightForChild(child)); | 1578 : MarginLogicalHeightForChild(child)); |
1527 } | 1579 } |
1528 | 1580 |
1529 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( | 1581 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( |
1530 const LayoutBox& child) const { | 1582 const LayoutBox& child, |
1531 if (!child.IsAnonymous()) { | 1583 const ComputedStyle* style) const { |
1532 return child.StyleRef().ResolvedAlignSelf( | 1584 if (!style) |
1533 SelfAlignmentNormalBehavior(&child)); | 1585 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), | 1586 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), |
1539 Style()); | 1587 style); |
1540 } | 1588 } |
1541 | 1589 |
1542 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( | 1590 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( |
1543 const LayoutBox& child) const { | 1591 const LayoutBox& child, |
1544 if (!child.IsAnonymous()) { | 1592 const ComputedStyle* style) const { |
1545 return child.StyleRef().ResolvedJustifySelf( | 1593 if (!style) |
1546 SelfAlignmentNormalBehavior(&child)); | 1594 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( | 1595 return child.StyleRef().ResolvedJustifySelf( |
1552 SelfAlignmentNormalBehavior(&child), Style()); | 1596 SelfAlignmentNormalBehavior(&child), style); |
1553 } | 1597 } |
1554 | 1598 |
1555 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( | 1599 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( |
1556 const LayoutBox& child, | 1600 const LayoutBox& child, |
1557 GridTrackSizingDirection direction) const { | 1601 GridTrackSizingDirection direction) const { |
1558 return !IsOrthogonalChild(child) | 1602 return !IsOrthogonalChild(child) |
1559 ? direction | 1603 ? direction |
1560 : (direction == kForColumns ? kForRows : kForColumns); | 1604 : (direction == kForColumns ? kForRows : kForColumns); |
1561 } | 1605 } |
1562 | 1606 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1770 GridAxis baseline_axis) const { | 1814 GridAxis baseline_axis) const { |
1771 return IsHorizontalGridAxis(baseline_axis) && | 1815 return IsHorizontalGridAxis(baseline_axis) && |
1772 ((child.StyleRef().IsFlippedBlocksWritingMode() && | 1816 ((child.StyleRef().IsFlippedBlocksWritingMode() && |
1773 !StyleRef().IsFlippedBlocksWritingMode()) || | 1817 !StyleRef().IsFlippedBlocksWritingMode()) || |
1774 (child.StyleRef().IsFlippedLinesWritingMode() && | 1818 (child.StyleRef().IsFlippedLinesWritingMode() && |
1775 StyleRef().IsFlippedBlocksWritingMode())); | 1819 StyleRef().IsFlippedBlocksWritingMode())); |
1776 } | 1820 } |
1777 | 1821 |
1778 bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child, | 1822 bool LayoutGrid::IsBaselineAlignmentForChild(const LayoutBox& child, |
1779 GridAxis baseline_axis) const { | 1823 GridAxis baseline_axis) const { |
1780 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; | 1824 ItemPosition align = |
1781 ItemPosition align = is_column_axis_baseline | 1825 SelfAlignmentForChild(baseline_axis, child).GetPosition(); |
1782 ? AlignSelfForChild(child).GetPosition() | 1826 bool has_auto_margins = baseline_axis == kGridColumnAxis |
1783 : JustifySelfForChild(child).GetPosition(); | |
1784 bool has_auto_margins = is_column_axis_baseline | |
1785 ? HasAutoMarginsInColumnAxis(child) | 1827 ? HasAutoMarginsInColumnAxis(child) |
1786 : HasAutoMarginsInRowAxis(child); | 1828 : HasAutoMarginsInRowAxis(child); |
1787 return IsBaselinePosition(align) && !has_auto_margins; | 1829 return IsBaselinePosition(align) && !has_auto_margins; |
1788 } | 1830 } |
1789 | 1831 |
1790 const BaselineGroup& LayoutGrid::GetBaselineGroupForChild( | 1832 const BaselineGroup& LayoutGrid::GetBaselineGroupForChild( |
1791 const LayoutBox& child, | 1833 const LayoutBox& child, |
1792 GridAxis baseline_axis) const { | 1834 GridAxis baseline_axis) const { |
1793 DCHECK(IsBaselineAlignmentForChild(child, baseline_axis)); | 1835 DCHECK(IsBaselineAlignmentForChild(child, baseline_axis)); |
1794 auto& grid = track_sizing_algorithm_.GetGrid(); | 1836 auto& grid = track_sizing_algorithm_.GetGrid(); |
1795 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; | 1837 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; |
1796 bool is_row_axis_context = is_column_axis_baseline; | 1838 bool is_row_axis_context = is_column_axis_baseline; |
1797 const auto& span = is_row_axis_context | 1839 const auto& span = is_row_axis_context |
1798 ? grid.GridItemSpan(child, kForRows) | 1840 ? grid.GridItemSpan(child, kForRows) |
1799 : grid.GridItemSpan(child, kForColumns); | 1841 : grid.GridItemSpan(child, kForColumns); |
1800 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ | 1842 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ |
1801 : col_axis_alignment_context_; | 1843 : col_axis_alignment_context_; |
1802 auto* context = contexts_map.at(span.StartLine()); | 1844 auto* context = contexts_map.at(span.StartLine()); |
1803 DCHECK(context); | 1845 DCHECK(context); |
1804 ItemPosition align = is_column_axis_baseline | 1846 ItemPosition align = |
1805 ? AlignSelfForChild(child).GetPosition() | 1847 SelfAlignmentForChild(baseline_axis, child).GetPosition(); |
1806 : JustifySelfForChild(child).GetPosition(); | |
1807 return context->GetSharedGroup(child, align); | 1848 return context->GetSharedGroup(child, align); |
1808 } | 1849 } |
1809 | 1850 |
1810 LayoutUnit LayoutGrid::MarginOverForChild(const LayoutBox& child, | 1851 LayoutUnit LayoutGrid::MarginOverForChild(const LayoutBox& child, |
1811 GridAxis axis) const { | 1852 GridAxis axis) const { |
1812 return IsHorizontalGridAxis(axis) ? child.MarginRight() : child.MarginTop(); | 1853 return IsHorizontalGridAxis(axis) ? child.MarginRight() : child.MarginTop(); |
1813 } | 1854 } |
1814 | 1855 |
1815 LayoutUnit LayoutGrid::MarginUnderForChild(const LayoutBox& child, | 1856 LayoutUnit LayoutGrid::MarginUnderForChild(const LayoutBox& child, |
1816 GridAxis axis) const { | 1857 GridAxis axis) const { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1914 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; | 1955 bool is_column_axis_baseline = baseline_axis == kGridColumnAxis; |
1915 bool is_row_axis_context = is_column_axis_baseline; | 1956 bool is_row_axis_context = is_column_axis_baseline; |
1916 const auto& span = is_row_axis_context | 1957 const auto& span = is_row_axis_context |
1917 ? grid.GridItemSpan(child, kForRows) | 1958 ? grid.GridItemSpan(child, kForRows) |
1918 : grid.GridItemSpan(child, kForColumns); | 1959 : grid.GridItemSpan(child, kForColumns); |
1919 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ | 1960 auto& contexts_map = is_row_axis_context ? row_axis_alignment_context_ |
1920 : col_axis_alignment_context_; | 1961 : col_axis_alignment_context_; |
1921 auto add_result = contexts_map.insert(span.StartLine(), nullptr); | 1962 auto add_result = contexts_map.insert(span.StartLine(), nullptr); |
1922 | 1963 |
1923 // Looking for a compatible baseline-sharing group. | 1964 // Looking for a compatible baseline-sharing group. |
1924 ItemPosition align = is_column_axis_baseline | 1965 ItemPosition align = |
1925 ? AlignSelfForChild(child).GetPosition() | 1966 SelfAlignmentForChild(baseline_axis, child).GetPosition(); |
1926 : JustifySelfForChild(child).GetPosition(); | |
1927 if (add_result.is_new_entry) { | 1967 if (add_result.is_new_entry) { |
1928 add_result.stored_value->value = | 1968 add_result.stored_value->value = |
1929 WTF::MakeUnique<BaselineContext>(child, align, ascent, descent); | 1969 WTF::MakeUnique<BaselineContext>(child, align, ascent, descent); |
1930 } else { | 1970 } else { |
1931 auto* context = add_result.stored_value->value.get(); | 1971 auto* context = add_result.stored_value->value.get(); |
1932 context->UpdateSharedGroup(child, align, ascent, descent); | 1972 context->UpdateSharedGroup(child, align, ascent, descent); |
1933 } | 1973 } |
1934 } | 1974 } |
1935 | 1975 |
1936 LayoutUnit LayoutGrid::ColumnAxisBaselineOffsetForChild( | 1976 LayoutUnit LayoutGrid::ColumnAxisBaselineOffsetForChild( |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2388 if (direction == kForRows) | 2428 if (direction == kForRows) |
2389 return grid.NumTracks(kForRows); | 2429 return grid.NumTracks(kForRows); |
2390 | 2430 |
2391 return grid.NumTracks(kForRows) | 2431 return grid.NumTracks(kForRows) |
2392 ? grid.NumTracks(kForColumns) | 2432 ? grid.NumTracks(kForColumns) |
2393 : GridPositionsResolver::ExplicitGridColumnCount( | 2433 : GridPositionsResolver::ExplicitGridColumnCount( |
2394 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2434 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2395 } | 2435 } |
2396 | 2436 |
2397 } // namespace blink | 2437 } // namespace blink |
OLD | NEW |