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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 #endif | 245 #endif |
246 } | 246 } |
247 | 247 |
248 void LayoutGrid::RepeatTracksSizingIfNeeded( | 248 void LayoutGrid::RepeatTracksSizingIfNeeded( |
249 LayoutUnit available_space_for_columns, | 249 LayoutUnit available_space_for_columns, |
250 LayoutUnit available_space_for_rows) { | 250 LayoutUnit available_space_for_rows) { |
251 // Baseline alignment may change item's intrinsic size, hence changing its | 251 // Baseline alignment may change item's intrinsic size, hence changing its |
252 // min-content contribution. | 252 // min-content contribution. |
253 // https://drafts.csswg.org/css-align-3/#baseline-align-content | 253 // https://drafts.csswg.org/css-align-3/#baseline-align-content |
254 // https://drafts.csswg.org/css-align-3/#baseline-align-self | 254 // https://drafts.csswg.org/css-align-3/#baseline-align-self |
255 bool baseline_affect_intrinsic_width = BaselineMayAffectIntrinsicWidth(); | 255 bool baseline_affect_intrinsic_width = |
256 bool baseline_affect_intrinsic_height = BaselineMayAffectIntrinsicHeight(); | 256 BaselineMayAffectIntrinsicSize(kForColumns); |
| 257 bool baseline_affect_intrinsic_height = |
| 258 BaselineMayAffectIntrinsicSize(kForRows); |
257 | 259 |
258 // In orthogonal flow cases column track's size is determined by using the | 260 // In orthogonal flow cases column track's size is determined by using the |
259 // computed row track's size, which it was estimated during the first cycle of | 261 // computed row track's size, which it was estimated during the first cycle of |
260 // the sizing algorithm. | 262 // the sizing algorithm. |
261 bool has_any_orthogonal = | 263 bool has_any_orthogonal = |
262 track_sizing_algorithm_.GetGrid().HasAnyOrthogonalGridItem(); | 264 track_sizing_algorithm_.GetGrid().HasAnyOrthogonalGridItem(); |
263 | 265 |
264 // TODO (lajava): these are just some of the cases which may require | 266 // TODO (lajava): these are just some of the cases which may require |
265 // a new cycle of the sizing algorithm; there may be more. In addition, not | 267 // a new cycle of the sizing algorithm; there may be more. In addition, not |
266 // all the cases with orthogonal flows require this extra cycle; we need a | 268 // all the cases with orthogonal flows require this extra cycle; we need a |
267 // more specific condition to detect whether child's min-content contribution | 269 // more specific condition to detect whether child's min-content contribution |
268 // has changed or not. | 270 // has changed or not. |
269 if (!baseline_affect_intrinsic_width && !baseline_affect_intrinsic_height && | 271 if (!baseline_affect_intrinsic_width && !baseline_affect_intrinsic_height && |
270 !has_any_orthogonal) | 272 !has_any_orthogonal) |
271 return; | 273 return; |
272 | 274 |
273 // TODO (lajava): Whenever the min-content contribution of a grid item changes | 275 // TODO (lajava): Whenever the min-content contribution of a grid item changes |
274 // we may need to update the grid container's intrinsic width. The new | 276 // we may need to update the grid container's intrinsic width. The new |
275 // intrinsic width may also affect the extra Track Sizing algorithm cycles we | 277 // intrinsic width may also affect the extra Track Sizing algorithm cycles we |
276 // are about to execute. | 278 // are about to execute. |
277 // https://crbug.com/704713 | 279 // https://crbug.com/704713 |
278 // https://github.com/w3c/csswg-drafts/issues/1039 | 280 // https://github.com/w3c/csswg-drafts/issues/1039 |
279 | 281 |
280 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns | 282 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns |
281 // and rows, to determine the final values. | 283 // and rows, to determine the final values. |
282 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); | 284 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); |
283 ComputeTrackSizesForDefiniteSize(kForRows, available_space_for_rows); | 285 ComputeTrackSizesForDefiniteSize(kForRows, available_space_for_rows); |
284 | 286 |
285 if (baseline_affect_intrinsic_height) { | 287 if (baseline_affect_intrinsic_height && |
| 288 StyleRef().LogicalHeight().IsIntrinsicOrAuto()) { |
286 SetLogicalHeight(ComputeTrackBasedLogicalHeight() + | 289 SetLogicalHeight(ComputeTrackBasedLogicalHeight() + |
287 BorderAndPaddingLogicalHeight() + | 290 BorderAndPaddingLogicalHeight() + |
288 ScrollbarLogicalHeight()); | 291 ScrollbarLogicalHeight()); |
289 } | 292 } |
290 } | 293 } |
291 | 294 |
292 void LayoutGrid::UpdateBlockLayout(bool relayout_children) { | 295 void LayoutGrid::UpdateBlockLayout(bool relayout_children) { |
293 DCHECK(NeedsLayout()); | 296 DCHECK(NeedsLayout()); |
294 | 297 |
295 // We cannot perform a simplifiedLayout() on a dirty grid that | 298 // We cannot perform a simplifiedLayout() on a dirty grid that |
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1865 return child.MarginLogicalHeight() + child.LogicalHeight() - ascent; | 1868 return child.MarginLogicalHeight() + child.LogicalHeight() - ascent; |
1866 return child.MarginLogicalWidth() + child.LogicalWidth() - ascent; | 1869 return child.MarginLogicalWidth() + child.LogicalWidth() - ascent; |
1867 } | 1870 } |
1868 | 1871 |
1869 bool LayoutGrid::IsBaselineContextComputed(GridAxis baseline_axis) const { | 1872 bool LayoutGrid::IsBaselineContextComputed(GridAxis baseline_axis) const { |
1870 return baseline_axis == kGridColumnAxis | 1873 return baseline_axis == kGridColumnAxis |
1871 ? !row_axis_alignment_context_.IsEmpty() | 1874 ? !row_axis_alignment_context_.IsEmpty() |
1872 : !col_axis_alignment_context_.IsEmpty(); | 1875 : !col_axis_alignment_context_.IsEmpty(); |
1873 } | 1876 } |
1874 | 1877 |
1875 bool LayoutGrid::BaselineMayAffectIntrinsicWidth() const { | 1878 bool LayoutGrid::BaselineMayAffectIntrinsicSize( |
1876 if (!StyleRef().LogicalWidth().IsIntrinsicOrAuto()) | 1879 GridTrackSizingDirection direction) const { |
1877 return false; | 1880 const auto& contexts_map = direction == kForColumns |
1878 for (const auto& context : col_axis_alignment_context_) { | 1881 ? col_axis_alignment_context_ |
| 1882 : row_axis_alignment_context_; |
| 1883 for (const auto& context : contexts_map) { |
| 1884 auto track_size = |
| 1885 track_sizing_algorithm_.GetGridTrackSize(direction, context.key); |
| 1886 // TODO(lajava): Should we consider flexible tracks as well ? |
| 1887 if (!track_size.IsContentSized()) |
| 1888 continue; |
1879 for (const auto& group : context.value->SharedGroups()) { | 1889 for (const auto& group : context.value->SharedGroups()) { |
1880 if (group.size() > 1) | 1890 if (group.size() > 1) { |
1881 return true; | 1891 auto grid_area_size = |
| 1892 track_sizing_algorithm_.Tracks(direction)[context.key].BaseSize(); |
| 1893 if (group.MaxAscent() + group.MaxDescent() > grid_area_size) |
| 1894 return true; |
| 1895 } |
1882 } | 1896 } |
1883 } | 1897 } |
1884 return false; | 1898 return false; |
1885 } | 1899 } |
1886 | 1900 |
1887 bool LayoutGrid::BaselineMayAffectIntrinsicHeight() const { | |
1888 if (!StyleRef().LogicalHeight().IsIntrinsicOrAuto()) | |
1889 return false; | |
1890 for (const auto& context : row_axis_alignment_context_) { | |
1891 for (const auto& group : context.value->SharedGroups()) { | |
1892 if (group.size() > 1) | |
1893 return true; | |
1894 } | |
1895 } | |
1896 return false; | |
1897 } | |
1898 | 1901 |
1899 void LayoutGrid::ComputeBaselineAlignmentContext() { | 1902 void LayoutGrid::ComputeBaselineAlignmentContext() { |
1900 for (auto* child = FirstInFlowChildBox(); child; | 1903 for (auto* child = FirstInFlowChildBox(); child; |
1901 child = child->NextInFlowSiblingBox()) { | 1904 child = child->NextInFlowSiblingBox()) { |
1902 UpdateBaselineAlignmentContextIfNeeded(*child, kGridRowAxis); | 1905 UpdateBaselineAlignmentContextIfNeeded(*child, kGridRowAxis); |
1903 UpdateBaselineAlignmentContextIfNeeded(*child, kGridColumnAxis); | 1906 UpdateBaselineAlignmentContextIfNeeded(*child, kGridColumnAxis); |
1904 } | 1907 } |
1905 } | 1908 } |
1906 | 1909 |
1907 void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( | 1910 void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2402 if (direction == kForRows) | 2405 if (direction == kForRows) |
2403 return grid.NumTracks(kForRows); | 2406 return grid.NumTracks(kForRows); |
2404 | 2407 |
2405 return grid.NumTracks(kForRows) | 2408 return grid.NumTracks(kForRows) |
2406 ? grid.NumTracks(kForColumns) | 2409 ? grid.NumTracks(kForColumns) |
2407 : GridPositionsResolver::ExplicitGridColumnCount( | 2410 : GridPositionsResolver::ExplicitGridColumnCount( |
2408 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2411 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2409 } | 2412 } |
2410 | 2413 |
2411 } // namespace blink | 2414 } // namespace blink |
OLD | NEW |