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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 #endif | 182 #endif |
183 } | 183 } |
184 | 184 |
185 void LayoutGrid::RepeatTracksSizingIfNeeded( | 185 void LayoutGrid::RepeatTracksSizingIfNeeded( |
186 LayoutUnit available_space_for_columns, | 186 LayoutUnit available_space_for_columns, |
187 LayoutUnit available_space_for_rows) { | 187 LayoutUnit available_space_for_rows) { |
188 // Baseline alignment may change item's intrinsic size, hence changing its | 188 // Baseline alignment may change item's intrinsic size, hence changing its |
189 // min-content contribution. | 189 // min-content contribution. |
190 // https://drafts.csswg.org/css-align-3/#baseline-align-content | 190 // https://drafts.csswg.org/css-align-3/#baseline-align-content |
191 // https://drafts.csswg.org/css-align-3/#baseline-align-self | 191 // https://drafts.csswg.org/css-align-3/#baseline-align-self |
192 bool baseline_affect_intrinsic_width = BaselineMayAffectIntrinsicWidth(); | 192 bool baseline_affect_intrinsic_width = |
193 bool baseline_affect_intrinsic_height = BaselineMayAffectIntrinsicHeight(); | 193 BaselineMayAffectIntrinsicSize(kForColumns); |
194 bool baseline_affect_intrinsic_height = | |
195 BaselineMayAffectIntrinsicSize(kForRows); | |
194 | 196 |
195 // In orthogonal flow cases column track's size is determined by using the | 197 // In orthogonal flow cases column track's size is determined by using the |
196 // computed row track's size, which it was estimated during the first cycle of | 198 // computed row track's size, which it was estimated during the first cycle of |
197 // the sizing algorithm. | 199 // the sizing algorithm. |
198 bool has_any_orthogonal = | 200 bool has_any_orthogonal = |
199 track_sizing_algorithm_.GetGrid().HasAnyOrthogonalGridItem(); | 201 track_sizing_algorithm_.GetGrid().HasAnyOrthogonalGridItem(); |
200 | 202 |
201 // TODO (lajava): these are just some of the cases which may require | 203 // TODO (lajava): these are just some of the cases which may require |
202 // a new cycle of the sizing algorithm; there may be more. In addition, not | 204 // a new cycle of the sizing algorithm; there may be more. In addition, not |
203 // all the cases with orthogonal flows require this extra cycle; we need a | 205 // all the cases with orthogonal flows require this extra cycle; we need a |
204 // more specific condition to detect whether child's min-content contribution | 206 // more specific condition to detect whether child's min-content contribution |
205 // has changed or not. | 207 // has changed or not. |
206 if (!baseline_affect_intrinsic_width && !baseline_affect_intrinsic_height && | 208 if (!baseline_affect_intrinsic_width && !baseline_affect_intrinsic_height && |
207 !has_any_orthogonal) | 209 !has_any_orthogonal) |
208 return; | 210 return; |
209 | 211 |
210 // TODO (lajava): Whenever the min-content contribution of a grid item changes | 212 // TODO (lajava): Whenever the min-content contribution of a grid item changes |
211 // we may need to update the grid container's intrinsic width. The new | 213 // we may need to update the grid container's intrinsic width. The new |
212 // intrinsic width may also affect the extra Track Sizing algorithm cycles we | 214 // intrinsic width may also affect the extra Track Sizing algorithm cycles we |
213 // are about to execute. | 215 // are about to execute. |
214 // https://crbug.com/704713 | 216 // https://crbug.com/704713 |
215 // https://github.com/w3c/csswg-drafts/issues/1039 | 217 // https://github.com/w3c/csswg-drafts/issues/1039 |
216 | 218 |
217 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns | 219 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns |
218 // and rows, to determine the final values. | 220 // and rows, to determine the final values. |
219 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); | 221 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); |
220 ComputeTrackSizesForDefiniteSize(kForRows, available_space_for_rows); | 222 ComputeTrackSizesForDefiniteSize(kForRows, available_space_for_rows); |
221 | 223 |
222 if (baseline_affect_intrinsic_height) { | 224 if (baseline_affect_intrinsic_height && |
225 StyleRef().LogicalHeight().IsIntrinsicOrAuto()) { | |
223 SetLogicalHeight(ComputeTrackBasedLogicalHeight() + | 226 SetLogicalHeight(ComputeTrackBasedLogicalHeight() + |
224 BorderAndPaddingLogicalHeight() + | 227 BorderAndPaddingLogicalHeight() + |
225 ScrollbarLogicalHeight()); | 228 ScrollbarLogicalHeight()); |
226 } | 229 } |
227 } | 230 } |
228 | 231 |
229 void LayoutGrid::UpdateBlockLayout(bool relayout_children) { | 232 void LayoutGrid::UpdateBlockLayout(bool relayout_children) { |
230 DCHECK(NeedsLayout()); | 233 DCHECK(NeedsLayout()); |
231 | 234 |
232 // We cannot perform a simplifiedLayout() on a dirty grid that | 235 // We cannot perform a simplifiedLayout() on a dirty grid that |
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1855 return child.MarginLogicalHeight() + child.LogicalHeight() - ascent; | 1858 return child.MarginLogicalHeight() + child.LogicalHeight() - ascent; |
1856 return child.MarginLogicalWidth() + child.LogicalWidth() - ascent; | 1859 return child.MarginLogicalWidth() + child.LogicalWidth() - ascent; |
1857 } | 1860 } |
1858 | 1861 |
1859 bool LayoutGrid::IsBaselineContextComputed(GridAxis baseline_axis) const { | 1862 bool LayoutGrid::IsBaselineContextComputed(GridAxis baseline_axis) const { |
1860 return baseline_axis == kGridColumnAxis | 1863 return baseline_axis == kGridColumnAxis |
1861 ? !row_axis_alignment_context_.IsEmpty() | 1864 ? !row_axis_alignment_context_.IsEmpty() |
1862 : !col_axis_alignment_context_.IsEmpty(); | 1865 : !col_axis_alignment_context_.IsEmpty(); |
1863 } | 1866 } |
1864 | 1867 |
1865 bool LayoutGrid::BaselineMayAffectIntrinsicWidth() const { | 1868 bool LayoutGrid::BaselineMayAffectIntrinsicSize( |
1866 if (!StyleRef().LogicalWidth().IsIntrinsicOrAuto()) | 1869 GridTrackSizingDirection direction) const { |
1867 return false; | 1870 const auto& contexts_map = direction == kForColumns |
1868 for (const auto& context : col_axis_alignment_context_) { | 1871 ? col_axis_alignment_context_ |
1872 : row_axis_alignment_context_; | |
1873 for (const auto& context : contexts_map) { | |
1874 auto track_size = | |
1875 track_sizing_algorithm_.GetGridTrackSize(direction, context.key); | |
1876 // TODO(lajava): Should we consider flexible tracks as well ? | |
1877 if (!track_size.IsContentSized()) | |
1878 continue; | |
1869 for (const auto& group : context.value->SharedGroups()) { | 1879 for (const auto& group : context.value->SharedGroups()) { |
1870 if (group.size() > 1) | 1880 auto grid_area_size = |
1881 track_sizing_algorithm_.Tracks(direction)[context.key].BaseSize(); | |
1882 if ((group.size() > 1) && | |
1883 (group.MaxAscent() + group.MaxDescent() > grid_area_size)) | |
svillar
2017/07/04 09:46:57
We don't really need to get the area size if group
| |
1871 return true; | 1884 return true; |
1872 } | 1885 } |
1873 } | 1886 } |
1874 return false; | 1887 return false; |
1875 } | 1888 } |
1876 | 1889 |
1877 bool LayoutGrid::BaselineMayAffectIntrinsicHeight() const { | |
1878 if (!StyleRef().LogicalHeight().IsIntrinsicOrAuto()) | |
1879 return false; | |
1880 for (const auto& context : row_axis_alignment_context_) { | |
1881 for (const auto& group : context.value->SharedGroups()) { | |
1882 if (group.size() > 1) | |
1883 return true; | |
1884 } | |
1885 } | |
1886 return false; | |
1887 } | |
1888 | 1890 |
1889 void LayoutGrid::ComputeBaselineAlignmentContext() { | 1891 void LayoutGrid::ComputeBaselineAlignmentContext() { |
1890 for (auto* child = FirstInFlowChildBox(); child; | 1892 for (auto* child = FirstInFlowChildBox(); child; |
1891 child = child->NextInFlowSiblingBox()) { | 1893 child = child->NextInFlowSiblingBox()) { |
1892 UpdateBaselineAlignmentContextIfNeeded(*child, kGridRowAxis); | 1894 UpdateBaselineAlignmentContextIfNeeded(*child, kGridRowAxis); |
1893 UpdateBaselineAlignmentContextIfNeeded(*child, kGridColumnAxis); | 1895 UpdateBaselineAlignmentContextIfNeeded(*child, kGridColumnAxis); |
1894 } | 1896 } |
1895 } | 1897 } |
1896 | 1898 |
1897 void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( | 1899 void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2391 if (direction == kForRows) | 2393 if (direction == kForRows) |
2392 return grid.NumTracks(kForRows); | 2394 return grid.NumTracks(kForRows); |
2393 | 2395 |
2394 return grid.NumTracks(kForRows) | 2396 return grid.NumTracks(kForRows) |
2395 ? grid.NumTracks(kForColumns) | 2397 ? grid.NumTracks(kForColumns) |
2396 : GridPositionsResolver::ExplicitGridColumnCount( | 2398 : GridPositionsResolver::ExplicitGridColumnCount( |
2397 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2399 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2398 } | 2400 } |
2399 | 2401 |
2400 } // namespace blink | 2402 } // namespace blink |
OLD | NEW |