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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 track_sizing_algorithm_.Run(); | 178 track_sizing_algorithm_.Run(); |
179 | 179 |
180 #if DCHECK_IS_ON() | 180 #if DCHECK_IS_ON() |
181 DCHECK(track_sizing_algorithm_.TracksAreWiderThanMinTrackBreadth()); | 181 DCHECK(track_sizing_algorithm_.TracksAreWiderThanMinTrackBreadth()); |
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 | |
189 // min-content contribution. | |
190 // https://drafts.csswg.org/css-align-3/#baseline-align-content | |
191 // https://drafts.csswg.org/css-align-3/#baseline-align-self | |
192 bool baseline_affect_intrinsic_width = BaselineMayAffectIntrinsicWidth(); | |
193 bool baseline_affect_intrinsic_height = BaselineMayAffectIntrinsicHeight(); | |
194 | |
195 // In orthogonal flow cases column track's size is determined by using the | 188 // 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 | 189 // computed row track's size, which it was estimated during the first cycle of |
197 // the sizing algorithm. | 190 // the sizing algorithm. |
198 bool has_any_orthogonal = | |
199 track_sizing_algorithm_.GetGrid().HasAnyOrthogonalGridItem(); | |
200 | |
201 // TODO (lajava): these are just some of the cases which may require | 191 // 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 | 192 // 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 | 193 // 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 | 194 // more specific condition to detect whether child's min-content contribution |
205 // has changed or not. | 195 // has changed or not. |
206 if (!baseline_affect_intrinsic_width && !baseline_affect_intrinsic_height && | 196 if (!track_sizing_algorithm_.GetGrid().HasAnyOrthogonalGridItem()) |
svillar
2017/05/11 07:15:04
This method is executed only as part of the layout
| |
207 !has_any_orthogonal) | |
208 return; | 197 return; |
209 | 198 |
210 // TODO (lajava): Whenever the min-content contribution of a grid item changes | 199 // 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 | 200 // 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 | 201 // intrinsic width may also affect the extra Track Sizing algorithm cycles we |
213 // are about to execute. | 202 // are about to execute. |
214 // https://crbug.com/704713 | 203 // https://crbug.com/704713 |
215 // https://github.com/w3c/csswg-drafts/issues/1039 | 204 // https://github.com/w3c/csswg-drafts/issues/1039 |
216 | 205 |
217 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns | 206 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns |
218 // and rows, to determine the final values. | 207 // and rows, to determine the final values. |
219 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); | 208 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); |
220 ComputeTrackSizesForDefiniteSize(kForRows, available_space_for_rows); | 209 ComputeTrackSizesForDefiniteSize(kForRows, available_space_for_rows); |
221 | |
222 if (baseline_affect_intrinsic_height) { | |
223 SetLogicalHeight(ComputeTrackBasedLogicalHeight() + | |
224 BorderAndPaddingLogicalHeight() + | |
225 ScrollbarLogicalHeight()); | |
226 } | |
227 } | 210 } |
228 | 211 |
229 void LayoutGrid::UpdateBlockLayout(bool relayout_children) { | 212 void LayoutGrid::UpdateBlockLayout(bool relayout_children) { |
230 DCHECK(NeedsLayout()); | 213 DCHECK(NeedsLayout()); |
231 | 214 |
232 // We cannot perform a simplifiedLayout() on a dirty grid that | 215 // We cannot perform a simplifiedLayout() on a dirty grid that |
233 // has positioned items to be laid out. | 216 // has positioned items to be laid out. |
234 if (!relayout_children && | 217 if (!relayout_children && |
235 (!grid_.NeedsItemsPlacement() || !PosChildNeedsLayout()) && | 218 (!grid_.NeedsItemsPlacement() || !PosChildNeedsLayout()) && |
236 SimplifiedLayout()) | 219 SimplifiedLayout()) |
(...skipping 19 matching lines...) Expand all Loading... | |
256 child = child->NextInFlowSiblingBox()) | 239 child = child->NextInFlowSiblingBox()) |
257 child->ClearOverrideSize(); | 240 child->ClearOverrideSize(); |
258 | 241 |
259 UpdateLogicalWidth(); | 242 UpdateLogicalWidth(); |
260 | 243 |
261 TextAutosizer::LayoutScope text_autosizer_layout_scope(this, &layout_scope); | 244 TextAutosizer::LayoutScope text_autosizer_layout_scope(this, &layout_scope); |
262 | 245 |
263 LayoutUnit available_space_for_columns = AvailableLogicalWidth(); | 246 LayoutUnit available_space_for_columns = AvailableLogicalWidth(); |
264 PlaceItemsOnGrid(grid_, available_space_for_columns); | 247 PlaceItemsOnGrid(grid_, available_space_for_columns); |
265 | 248 |
249 // TODO (lajava): Items with relative size may have problems to synthesize | |
250 // a baseline, since we neeed to resolve the size but we haven't defined yet | |
251 // their corresponding grid area. This may lead to an incorrect baseline | |
252 // computation, either because relative sizes are resolved as 0 (undefined | |
253 // container's size) or they are based on the grid container's size instead | |
254 // of the grid area. | |
255 ComputeBaselineAlignmentContext(); | |
256 | |
266 // 1- First, the track sizing algorithm is used to resolve the sizes of the | 257 // 1- First, the track sizing algorithm is used to resolve the sizes of the |
267 // grid columns. | 258 // grid columns. |
268 // At this point the logical width is always definite as the above call to | 259 // At this point the logical width is always definite as the above call to |
269 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the | 260 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the |
270 // same for heights though because many code paths inside | 261 // same for heights though because many code paths inside |
271 // updateLogicalHeight() require a previous call to setLogicalHeight() to | 262 // updateLogicalHeight() require a previous call to setLogicalHeight() to |
272 // resolve heights properly (like for positioned items for example). | 263 // resolve heights properly (like for positioned items for example). |
273 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); | 264 ComputeTrackSizesForDefiniteSize(kForColumns, available_space_for_columns); |
274 | 265 |
275 // We take the chance to store the intrinsic sizes as they are just an | 266 // We take the chance to store the intrinsic sizes as they are just an |
(...skipping 30 matching lines...) Expand all Loading... | |
306 LayoutUnit old_client_after_edge = ClientLogicalBottom(); | 297 LayoutUnit old_client_after_edge = ClientLogicalBottom(); |
307 UpdateLogicalHeight(); | 298 UpdateLogicalHeight(); |
308 | 299 |
309 // Once grid's indefinite height is resolved, we can compute the | 300 // Once grid's indefinite height is resolved, we can compute the |
310 // available free space for Content Alignment. | 301 // available free space for Content Alignment. |
311 if (!CachedHasDefiniteLogicalHeight()) { | 302 if (!CachedHasDefiniteLogicalHeight()) { |
312 track_sizing_algorithm_.SetFreeSpace( | 303 track_sizing_algorithm_.SetFreeSpace( |
313 kForRows, LogicalHeight() - track_based_logical_height); | 304 kForRows, LogicalHeight() - track_based_logical_height); |
314 } | 305 } |
315 | 306 |
316 // TODO (lajava): We need to compute baselines after step 2 so | |
317 // items with a relative size (percentages) can resolve it before | |
318 // determining its baseline. However, we only set item's grid area | |
319 // (via override sizes) as part of the content-sized tracks sizing | |
320 // logic. Hence, items located at fixed or flexible tracks can't | |
321 // resolve correctly their size at this stage, which may lead to | |
322 // an incorrect computation of their shared context's baseline. | |
323 ComputeBaselineAlignmentContext(); | |
324 | |
325 // 3- If the min-content contribution of any grid items have changed based | 307 // 3- If the min-content contribution of any grid items have changed based |
326 // on the row sizes calculated in step 2, steps 1 and 2 are repeated with | 308 // on the row sizes calculated in step 2, steps 1 and 2 are repeated with |
327 // the new min-content contribution (once only). | 309 // the new min-content contribution (once only). |
328 RepeatTracksSizingIfNeeded(available_space_for_columns, | 310 RepeatTracksSizingIfNeeded(available_space_for_columns, |
329 ContentLogicalHeight()); | 311 ContentLogicalHeight()); |
330 | 312 |
331 // Grid container should have the minimum height of a line if it's editable. | 313 // Grid container should have the minimum height of a line if it's editable. |
332 // That doesn't affect track sizing though. | 314 // That doesn't affect track sizing though. |
333 if (HasLineIfEmpty()) | 315 if (HasLineIfEmpty()) |
334 SetLogicalHeight( | 316 SetLogicalHeight( |
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1855 return child.MarginLogicalHeight() + child.LogicalHeight() - ascent; | 1837 return child.MarginLogicalHeight() + child.LogicalHeight() - ascent; |
1856 return child.MarginLogicalWidth() + child.LogicalWidth() - ascent; | 1838 return child.MarginLogicalWidth() + child.LogicalWidth() - ascent; |
1857 } | 1839 } |
1858 | 1840 |
1859 bool LayoutGrid::IsBaselineContextComputed(GridAxis baseline_axis) const { | 1841 bool LayoutGrid::IsBaselineContextComputed(GridAxis baseline_axis) const { |
1860 return baseline_axis == kGridColumnAxis | 1842 return baseline_axis == kGridColumnAxis |
1861 ? !row_axis_alignment_context_.IsEmpty() | 1843 ? !row_axis_alignment_context_.IsEmpty() |
1862 : !col_axis_alignment_context_.IsEmpty(); | 1844 : !col_axis_alignment_context_.IsEmpty(); |
1863 } | 1845 } |
1864 | 1846 |
1865 bool LayoutGrid::BaselineMayAffectIntrinsicWidth() const { | |
1866 if (!StyleRef().LogicalWidth().IsIntrinsicOrAuto()) | |
1867 return false; | |
1868 for (const auto& context : col_axis_alignment_context_) { | |
1869 for (const auto& group : context.value->SharedGroups()) { | |
1870 if (group.size() > 1) | |
1871 return true; | |
1872 } | |
1873 } | |
1874 return false; | |
1875 } | |
1876 | |
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 | |
1889 void LayoutGrid::ComputeBaselineAlignmentContext() { | 1847 void LayoutGrid::ComputeBaselineAlignmentContext() { |
1890 for (auto* child = FirstInFlowChildBox(); child; | 1848 for (auto* child = FirstInFlowChildBox(); child; |
1891 child = child->NextInFlowSiblingBox()) { | 1849 child = child->NextInFlowSiblingBox()) { |
1892 UpdateBaselineAlignmentContextIfNeeded(*child, kGridRowAxis); | 1850 UpdateBaselineAlignmentContextIfNeeded(*child, kGridRowAxis); |
1893 UpdateBaselineAlignmentContextIfNeeded(*child, kGridColumnAxis); | 1851 UpdateBaselineAlignmentContextIfNeeded(*child, kGridColumnAxis); |
1894 } | 1852 } |
1895 } | 1853 } |
1896 | 1854 |
1897 void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( | 1855 void LayoutGrid::UpdateBaselineAlignmentContextIfNeeded( |
1898 LayoutBox& child, | 1856 LayoutBox& child, |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2391 if (direction == kForRows) | 2349 if (direction == kForRows) |
2392 return grid.NumTracks(kForRows); | 2350 return grid.NumTracks(kForRows); |
2393 | 2351 |
2394 return grid.NumTracks(kForRows) | 2352 return grid.NumTracks(kForRows) |
2395 ? grid.NumTracks(kForColumns) | 2353 ? grid.NumTracks(kForColumns) |
2396 : GridPositionsResolver::ExplicitGridColumnCount( | 2354 : GridPositionsResolver::ExplicitGridColumnCount( |
2397 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2355 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2398 } | 2356 } |
2399 | 2357 |
2400 } // namespace blink | 2358 } // namespace blink |
OLD | NEW |