OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/GridTrackSizingAlgorithm.h" | 5 #include "core/layout/GridTrackSizingAlgorithm.h" |
6 | 6 |
7 #include "core/layout/Grid.h" | 7 #include "core/layout/Grid.h" |
8 #include "core/layout/LayoutGrid.h" | 8 #include "core/layout/LayoutGrid.h" |
9 #include "platform/LengthFunctions.h" | 9 #include "platform/LengthFunctions.h" |
10 | 10 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 LayoutUnit(-1)); | 280 LayoutUnit(-1)); |
281 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); | 281 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); |
282 } | 282 } |
283 | 283 |
284 // We need to clear the stretched height to properly compute logical height | 284 // We need to clear the stretched height to properly compute logical height |
285 // during layout. | 285 // during layout. |
286 if (child.NeedsLayout()) | 286 if (child.NeedsLayout()) |
287 child.ClearOverrideLogicalContentHeight(); | 287 child.ClearOverrideLogicalContentHeight(); |
288 | 288 |
289 child.LayoutIfNeeded(); | 289 child.LayoutIfNeeded(); |
290 GridAxis baseline_axis = GetLayoutGrid()->IsOrthogonalChild(child) | 290 |
291 ? kGridRowAxis | 291 if (auto baseline_extent = ExtentForBaselineAlignment(child)) |
292 : kGridColumnAxis; | 292 return baseline_extent.value(); |
293 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, baseline_axis) && | 293 |
294 GetLayoutGrid()->IsBaselineContextComputed(baseline_axis)) { | |
295 auto& group = | |
296 GetLayoutGrid()->GetBaselineGroupForChild(child, baseline_axis); | |
297 return group.MaxAscent() + group.MaxDescent(); | |
298 } | |
299 return child.LogicalHeight() + child.MarginLogicalHeight(); | 294 return child.LogicalHeight() + child.MarginLogicalHeight(); |
300 } | 295 } |
301 | 296 |
302 DISABLE_CFI_PERF | 297 DISABLE_CFI_PERF |
303 LayoutUnit GridTrackSizingAlgorithmStrategy::MinContentForChild( | 298 LayoutUnit GridTrackSizingAlgorithmStrategy::MinContentForChild( |
304 LayoutBox& child) const { | 299 LayoutBox& child) const { |
305 GridTrackSizingDirection child_inline_direction = | 300 GridTrackSizingDirection child_inline_direction = |
306 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); | 301 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); |
307 if (Direction() == child_inline_direction) { | 302 if (Direction() == child_inline_direction) { |
308 // If |child| has a relative logical width, we shouldn't let it override its | 303 // If |child| has a relative logical width, we shouldn't let it override its |
309 // intrinsic width, which is what we are interested in here. Thus we need to | 304 // intrinsic width, which is what we are interested in here. Thus we need to |
310 // set the inline-axis override size to -1 (no possible resolution). | 305 // set the inline-axis override size to -1 (no possible resolution). |
311 if (ShouldClearOverrideContainingBlockContentSizeForChild(child, | 306 if (ShouldClearOverrideContainingBlockContentSizeForChild(child, |
312 kForColumns)) { | 307 kForColumns)) { |
313 SetOverrideContainingBlockContentSizeForChild( | 308 SetOverrideContainingBlockContentSizeForChild( |
314 child, child_inline_direction, LayoutUnit(-1)); | 309 child, child_inline_direction, LayoutUnit(-1)); |
315 } | 310 } |
316 | 311 |
317 // FIXME: It's unclear if we should return the intrinsic width or the | 312 // FIXME: It's unclear if we should return the intrinsic width or the |
318 // preferred width. | 313 // preferred width. |
319 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 314 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
320 LayoutUnit margin_logical_width = | 315 LayoutUnit margin_logical_width = |
321 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild( | 316 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild( |
322 kInlineDirection, GetLayoutGrid(), child) | 317 kInlineDirection, GetLayoutGrid(), child) |
323 : child.MarginLogicalWidth(); | 318 : child.MarginLogicalWidth(); |
324 return child.MinPreferredLogicalWidth() + margin_logical_width; | 319 return child.MinPreferredLogicalWidth() + margin_logical_width; |
325 } | 320 } |
326 | 321 |
327 if (Direction() == kForColumns && | 322 if (Direction() == kForColumns && !AvailableSpace()) { |
328 algorithm_.sizing_operation_ == kIntrinsicSizeComputation) { | |
329 DCHECK(GetLayoutGrid()->IsOrthogonalChild(child)); | 323 DCHECK(GetLayoutGrid()->IsOrthogonalChild(child)); |
330 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, kGridRowAxis) && | 324 if (auto baseline_extent = ExtentForBaselineAlignment(child)) |
331 GetLayoutGrid()->IsBaselineContextComputed(kGridRowAxis)) { | 325 return baseline_extent.value(); |
332 auto& group = | |
333 GetLayoutGrid()->GetBaselineGroupForChild(child, kGridRowAxis); | |
334 return group.MaxAscent() + group.MaxDescent(); | |
335 } | |
336 } | 326 } |
337 | 327 |
338 if (UpdateOverrideContainingBlockContentSizeForChild(child, | 328 if (UpdateOverrideContainingBlockContentSizeForChild(child, |
339 child_inline_direction)) | 329 child_inline_direction)) |
340 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); | 330 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); |
341 return LogicalHeightForChild(child); | 331 return LogicalHeightForChild(child); |
342 } | 332 } |
343 | 333 |
344 DISABLE_CFI_PERF | 334 DISABLE_CFI_PERF |
345 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild( | 335 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 return algorithm_.FindFrUnitSize(tracks_span, left_over_space); | 414 return algorithm_.FindFrUnitSize(tracks_span, left_over_space); |
425 } | 415 } |
426 | 416 |
427 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks( | 417 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks( |
428 Vector<GridTrack*>& tracks, | 418 Vector<GridTrack*>& tracks, |
429 LayoutUnit& available_logical_space) const { | 419 LayoutUnit& available_logical_space) const { |
430 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr, | 420 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr, |
431 available_logical_space); | 421 available_logical_space); |
432 } | 422 } |
433 | 423 |
424 Optional<LayoutUnit> | |
425 GridTrackSizingAlgorithmStrategy::ExtentForBaselineAlignment( | |
Manuel Rego
2017/04/27 16:06:48
This seems unrelated to the SizingOperation remova
| |
426 LayoutBox& child) const { | |
427 auto grid = algorithm_.layout_grid_; | |
Manuel Rego
2017/04/27 16:06:48
Nit: We've GetLayoutGrid() for this.
| |
428 GridAxis baseline_axis = | |
429 grid->IsOrthogonalChild(child) ? kGridRowAxis : kGridColumnAxis; | |
430 if (!grid->IsBaselineAlignmentForChild(child, baseline_axis) || | |
431 !grid->IsBaselineContextComputed(baseline_axis)) | |
432 return WTF::kNullopt; | |
433 | |
434 auto& group = grid->GetBaselineGroupForChild(child, baseline_axis); | |
435 return group.MaxAscent() + group.MaxDescent(); | |
436 } | |
437 | |
434 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild( | 438 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild( |
435 LayoutBox& child, | 439 LayoutBox& child, |
436 Length child_min_size, | 440 Length child_min_size, |
437 GridTrackSizingDirection child_inline_direction) const { | 441 GridTrackSizingDirection child_inline_direction) const { |
438 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild( | 442 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild( |
439 kInlineDirection, GetLayoutGrid(), child); | 443 kInlineDirection, GetLayoutGrid(), child); |
440 return child.ComputeLogicalWidthUsing( | 444 return child.ComputeLogicalWidthUsing( |
441 kMinSize, child_min_size, | 445 kMinSize, child_min_size, |
442 OverrideContainingBlockContentSizeForChild(child, | 446 OverrideContainingBlockContentSizeForChild(child, |
443 child_inline_direction), | 447 child_inline_direction), |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1398 case kRowSizingFirstIteration: | 1402 case kRowSizingFirstIteration: |
1399 case kRowSizingSecondIteration: | 1403 case kRowSizingSecondIteration: |
1400 return direction_ == kForRows; | 1404 return direction_ == kForRows; |
1401 } | 1405 } |
1402 NOTREACHED(); | 1406 NOTREACHED(); |
1403 return false; | 1407 return false; |
1404 } | 1408 } |
1405 | 1409 |
1406 void GridTrackSizingAlgorithm::Setup(GridTrackSizingDirection direction, | 1410 void GridTrackSizingAlgorithm::Setup(GridTrackSizingDirection direction, |
1407 size_t num_tracks, | 1411 size_t num_tracks, |
1408 SizingOperation sizing_operation, | |
1409 Optional<LayoutUnit> available_space, | 1412 Optional<LayoutUnit> available_space, |
1410 Optional<LayoutUnit> free_space) { | 1413 Optional<LayoutUnit> free_space) { |
1411 DCHECK(needs_setup_); | 1414 DCHECK(needs_setup_); |
1412 DCHECK_EQ(!!available_space, !!free_space); | 1415 DCHECK_EQ(!!available_space, !!free_space); |
1413 direction_ = direction; | 1416 direction_ = direction; |
1414 SetAvailableSpace( | 1417 SetAvailableSpace( |
1415 direction, available_space ? available_space.value().ClampNegativeToZero() | 1418 direction, available_space ? available_space.value().ClampNegativeToZero() |
1416 : available_space); | 1419 : available_space); |
1417 | 1420 |
1418 sizing_operation_ = sizing_operation; | |
1419 | |
1420 if (available_space) | 1421 if (available_space) |
1421 strategy_ = WTF::MakeUnique<DefiniteSizeStrategy>(*this); | 1422 strategy_ = WTF::MakeUnique<DefiniteSizeStrategy>(*this); |
1422 else | 1423 else |
1423 strategy_ = WTF::MakeUnique<IndefiniteSizeStrategy>(*this); | 1424 strategy_ = WTF::MakeUnique<IndefiniteSizeStrategy>(*this); |
1424 | 1425 |
1425 content_sized_tracks_index_.Shrink(0); | 1426 content_sized_tracks_index_.Shrink(0); |
1426 flexible_sized_tracks_index_.Shrink(0); | 1427 flexible_sized_tracks_index_.Shrink(0); |
1427 | 1428 |
1428 SetFreeSpace(direction, free_space); | 1429 SetFreeSpace(direction, free_space); |
1429 Tracks(direction).Resize(num_tracks); | 1430 Tracks(direction).Resize(num_tracks); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1497 DCHECK(algorithm_.IsValidTransition()); | 1498 DCHECK(algorithm_.IsValidTransition()); |
1498 DCHECK(!algorithm_.needs_setup_); | 1499 DCHECK(!algorithm_.needs_setup_); |
1499 } | 1500 } |
1500 | 1501 |
1501 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { | 1502 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { |
1502 algorithm_.AdvanceNextState(); | 1503 algorithm_.AdvanceNextState(); |
1503 algorithm_.needs_setup_ = true; | 1504 algorithm_.needs_setup_ = true; |
1504 } | 1505 } |
1505 | 1506 |
1506 } // namespace blink | 1507 } // namespace blink |
OLD | NEW |