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 bool LayoutGrid::SelfAlignmentChangedToStretchInRowAxis( | |
101 const ComputedStyle& old_style, | |
102 const ComputedStyle& new_style, | |
103 const LayoutBox& child) { | |
104 return child.StyleRef() | |
105 .ResolvedJustifySelf(SelfAlignmentNormalBehavior(&child), | |
106 &old_style) | |
107 .GetPosition() != kItemPositionStretch && | |
108 child.StyleRef() | |
109 .ResolvedJustifySelf(SelfAlignmentNormalBehavior(&child), | |
110 &new_style) | |
111 .GetPosition() == kItemPositionStretch; | |
112 } | |
113 | |
114 bool LayoutGrid::SelfAlignmentChangedFromStretchInRowAxis( | |
115 const ComputedStyle& old_style, | |
116 const ComputedStyle& new_style, | |
117 const LayoutBox& child) { | |
118 return child.StyleRef() | |
119 .ResolvedJustifySelf(SelfAlignmentNormalBehavior(&child), | |
120 &old_style) | |
121 .GetPosition() == kItemPositionStretch && | |
122 child.StyleRef() | |
123 .ResolvedJustifySelf(SelfAlignmentNormalBehavior(&child), | |
124 &new_style) | |
125 .GetPosition() != kItemPositionStretch; | |
126 } | |
127 | |
128 bool LayoutGrid::SelfAlignmentChangedFromStretchInColumnAxis( | |
129 const ComputedStyle& old_style, | |
130 const ComputedStyle& new_style, | |
131 const LayoutBox& child) { | |
132 return child.StyleRef() | |
133 .ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), | |
134 &old_style) | |
135 .GetPosition() == kItemPositionStretch && | |
136 child.StyleRef() | |
137 .ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), | |
138 &new_style) | |
139 .GetPosition() != kItemPositionStretch; | |
140 } | |
141 | |
100 void LayoutGrid::StyleDidChange(StyleDifference diff, | 142 void LayoutGrid::StyleDidChange(StyleDifference diff, |
101 const ComputedStyle* old_style) { | 143 const ComputedStyle* old_style) { |
102 LayoutBlock::StyleDidChange(diff, old_style); | 144 LayoutBlock::StyleDidChange(diff, old_style); |
103 if (!old_style) | 145 if (!old_style) |
104 return; | 146 return; |
105 | 147 |
148 const ComputedStyle& new_style = StyleRef(); | |
149 if (old_style && | |
150 old_style->ResolvedAlignItems(SelfAlignmentNormalBehavior(this)) | |
151 .GetPosition() == kItemPositionStretch && | |
152 diff.NeedsFullLayout()) { | |
153 // Grid items that were not previously stretched in row-axis need to be | |
154 // relayed out so we can compute new available space. | |
155 // Grid items that were previously stretching in column-axis need to be | |
156 // relayed out so we can compute new available space. | |
cbiesinger
2017/05/24 16:54:15
This comment is not quite correct -- in the row ax
jfernandez
2017/05/24 22:46:58
The reason is that such case, to-stretch in the co
| |
157 // This is only necessary for stretching since other alignment values don't | |
158 // change the size of the box. | |
159 for (LayoutBox* child = FirstInFlowChildBox(); child; | |
160 child = child->NextInFlowSiblingBox()) { | |
161 if (SelfAlignmentChangedToStretchInRowAxis(*old_style, new_style, | |
162 *child) || | |
163 SelfAlignmentChangedFromStretchInRowAxis(*old_style, new_style, | |
164 *child) || | |
165 SelfAlignmentChangedFromStretchInColumnAxis(*old_style, new_style, | |
166 *child)) { | |
167 child->SetNeedsLayout(LayoutInvalidationReason::kGridChanged); | |
168 } | |
169 } | |
170 } | |
171 | |
106 // FIXME: The following checks could be narrowed down if we kept track of | 172 // FIXME: The following checks could be narrowed down if we kept track of |
107 // which type of grid items we have: | 173 // which type of grid items we have: |
108 // - explicit grid size changes impact negative explicitely positioned and | 174 // - explicit grid size changes impact negative explicitely positioned and |
109 // auto-placed grid items. | 175 // auto-placed grid items. |
110 // - named grid lines only impact grid items with named grid lines. | 176 // - named grid lines only impact grid items with named grid lines. |
111 // - auto-flow changes only impacts auto-placed children. | 177 // - auto-flow changes only impacts auto-placed children. |
112 | 178 |
113 if (ExplicitGridDidResize(*old_style) || | 179 if (ExplicitGridDidResize(*old_style) || |
114 NamedGridLinesDefinitionDidChange(*old_style) || | 180 NamedGridLinesDefinitionDidChange(*old_style) || |
115 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() || | 181 old_style->GetGridAutoFlow() != StyleRef().GetGridAutoFlow() || |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1523 // values. Hence, we need to compute margins in order to determine the | 1589 // values. Hence, we need to compute margins in order to determine the |
1524 // available height before stretching. | 1590 // available height before stretching. |
1525 return grid_area_breadth_for_child - | 1591 return grid_area_breadth_for_child - |
1526 (child.NeedsLayout() | 1592 (child.NeedsLayout() |
1527 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child) | 1593 ? ComputeMarginLogicalSizeForChild(kBlockDirection, child) |
1528 : MarginLogicalHeightForChild(child)); | 1594 : MarginLogicalHeightForChild(child)); |
1529 } | 1595 } |
1530 | 1596 |
1531 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( | 1597 StyleSelfAlignmentData LayoutGrid::AlignSelfForChild( |
1532 const LayoutBox& child) const { | 1598 const LayoutBox& child) const { |
1533 if (!child.IsAnonymous()) { | |
1534 return child.StyleRef().ResolvedAlignSelf( | |
1535 SelfAlignmentNormalBehavior(&child)); | |
1536 } | |
1537 // All the 'auto' values has been solved by the StyleAdjuster, but it's | |
1538 // possible that some grid items generate Anonymous boxes, which need to be | |
1539 // solved during layout. | |
1540 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), | 1599 return child.StyleRef().ResolvedAlignSelf(SelfAlignmentNormalBehavior(&child), |
1541 Style()); | 1600 Style()); |
1542 } | 1601 } |
1543 | 1602 |
1544 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( | 1603 StyleSelfAlignmentData LayoutGrid::JustifySelfForChild( |
1545 const LayoutBox& child) const { | 1604 const LayoutBox& child) const { |
1546 if (!child.IsAnonymous()) { | |
1547 return child.StyleRef().ResolvedJustifySelf( | |
1548 SelfAlignmentNormalBehavior(&child)); | |
1549 } | |
1550 // All the 'auto' values has been solved by the StyleAdjuster, but it's | |
1551 // possible that some grid items generate Anonymous boxes, which need to be | |
1552 // solved during layout. | |
1553 return child.StyleRef().ResolvedJustifySelf( | 1605 return child.StyleRef().ResolvedJustifySelf( |
1554 SelfAlignmentNormalBehavior(&child), Style()); | 1606 SelfAlignmentNormalBehavior(&child), Style()); |
1555 } | 1607 } |
1556 | 1608 |
1557 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( | 1609 GridTrackSizingDirection LayoutGrid::FlowAwareDirectionForChild( |
1558 const LayoutBox& child, | 1610 const LayoutBox& child, |
1559 GridTrackSizingDirection direction) const { | 1611 GridTrackSizingDirection direction) const { |
1560 return !IsOrthogonalChild(child) | 1612 return !IsOrthogonalChild(child) |
1561 ? direction | 1613 ? direction |
1562 : (direction == kForColumns ? kForRows : kForColumns); | 1614 : (direction == kForColumns ? kForRows : kForColumns); |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2390 if (direction == kForRows) | 2442 if (direction == kForRows) |
2391 return grid.NumTracks(kForRows); | 2443 return grid.NumTracks(kForRows); |
2392 | 2444 |
2393 return grid.NumTracks(kForRows) | 2445 return grid.NumTracks(kForRows) |
2394 ? grid.NumTracks(kForColumns) | 2446 ? grid.NumTracks(kForColumns) |
2395 : GridPositionsResolver::ExplicitGridColumnCount( | 2447 : GridPositionsResolver::ExplicitGridColumnCount( |
2396 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2448 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2397 } | 2449 } |
2398 | 2450 |
2399 } // namespace blink | 2451 } // namespace blink |
OLD | NEW |