Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: third_party/WebKit/Source/core/layout/GridTrackSizingAlgorithm.cpp

Issue 2839893002: [css-grid] Preemptively store intrinsic sizes during layout (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/frame/FrameView.h"
8 #include "core/layout/Grid.h" 7 #include "core/layout/Grid.h"
9 #include "core/layout/LayoutGrid.h" 8 #include "core/layout/LayoutGrid.h"
10 #include "platform/LengthFunctions.h" 9 #include "platform/LengthFunctions.h"
11 10
12 namespace blink { 11 namespace blink {
13 12
14 class GridSizingData; 13 class GridSizingData;
15 14
16 LayoutUnit GridTrack::BaseSize() const { 15 LayoutUnit GridTrack::BaseSize() const {
17 DCHECK(IsGrowthLimitBiggerThanBaseSize()); 16 DCHECK(IsGrowthLimitBiggerThanBaseSize());
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 LayoutBox& child) const { 270 LayoutBox& child) const {
272 GridTrackSizingDirection child_block_direction = 271 GridTrackSizingDirection child_block_direction =
273 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForRows); 272 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForRows);
274 273
275 // If |child| has a relative logical height, we shouldn't let it override its 274 // If |child| has a relative logical height, we shouldn't let it override its
276 // intrinsic height, which is what we are interested in here. Thus we need to 275 // intrinsic height, which is what we are interested in here. Thus we need to
277 // set the block-axis override size to -1 (no possible resolution). 276 // set the block-axis override size to -1 (no possible resolution).
278 if (ShouldClearOverrideContainingBlockContentSizeForChild(child, kForRows)) { 277 if (ShouldClearOverrideContainingBlockContentSizeForChild(child, kForRows)) {
279 SetOverrideContainingBlockContentSizeForChild(child, child_block_direction, 278 SetOverrideContainingBlockContentSizeForChild(child, child_block_direction,
280 LayoutUnit(-1)); 279 LayoutUnit(-1));
281 SetGridItemNeedsLayout(child); 280 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
282 } 281 }
283 282
284 // We need to clear the stretched height to properly compute logical height 283 // We need to clear the stretched height to properly compute logical height
285 // during layout. 284 // during layout.
286 if (child.NeedsLayout()) 285 if (child.NeedsLayout())
287 child.ClearOverrideLogicalContentHeight(); 286 child.ClearOverrideLogicalContentHeight();
288 287
289 child.LayoutIfNeeded(); 288 child.LayoutIfNeeded();
290 GridAxis baseline_axis = GetLayoutGrid()->IsOrthogonalChild(child) 289 GridAxis baseline_axis = GetLayoutGrid()->IsOrthogonalChild(child)
291 ? kGridRowAxis 290 ? kGridRowAxis
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, kGridRowAxis) && 329 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, kGridRowAxis) &&
331 GetLayoutGrid()->IsBaselineContextComputed(kGridRowAxis)) { 330 GetLayoutGrid()->IsBaselineContextComputed(kGridRowAxis)) {
332 auto& group = 331 auto& group =
333 GetLayoutGrid()->GetBaselineGroupForChild(child, kGridRowAxis); 332 GetLayoutGrid()->GetBaselineGroupForChild(child, kGridRowAxis);
334 return group.MaxAscent() + group.MaxDescent(); 333 return group.MaxAscent() + group.MaxDescent();
335 } 334 }
336 } 335 }
337 336
338 if (UpdateOverrideContainingBlockContentSizeForChild(child, 337 if (UpdateOverrideContainingBlockContentSizeForChild(child,
339 child_inline_direction)) 338 child_inline_direction))
340 SetGridItemNeedsLayout(child); 339 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
341 return LogicalHeightForChild(child); 340 return LogicalHeightForChild(child);
342 } 341 }
343 342
344 DISABLE_CFI_PERF 343 DISABLE_CFI_PERF
345 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild( 344 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild(
346 LayoutBox& child) const { 345 LayoutBox& child) const {
347 GridTrackSizingDirection child_inline_direction = 346 GridTrackSizingDirection child_inline_direction =
348 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); 347 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns);
349 if (Direction() == child_inline_direction) { 348 if (Direction() == child_inline_direction) {
350 // If |child| has a relative logical width, we shouldn't let it override its 349 // If |child| has a relative logical width, we shouldn't let it override its
(...skipping 10 matching lines...) Expand all
361 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 360 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
362 LayoutUnit margin_logical_width = 361 LayoutUnit margin_logical_width =
363 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild( 362 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild(
364 kInlineDirection, GetLayoutGrid(), child) 363 kInlineDirection, GetLayoutGrid(), child)
365 : child.MarginLogicalWidth(); 364 : child.MarginLogicalWidth();
366 return child.MaxPreferredLogicalWidth() + margin_logical_width; 365 return child.MaxPreferredLogicalWidth() + margin_logical_width;
367 } 366 }
368 367
369 if (UpdateOverrideContainingBlockContentSizeForChild(child, 368 if (UpdateOverrideContainingBlockContentSizeForChild(child,
370 child_inline_direction)) 369 child_inline_direction))
371 SetGridItemNeedsLayout(child); 370 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
372 return LogicalHeightForChild(child); 371 return LogicalHeightForChild(child);
373 } 372 }
374 373
375 LayoutUnit GridTrackSizingAlgorithmStrategy::MinSizeForChild( 374 LayoutUnit GridTrackSizingAlgorithmStrategy::MinSizeForChild(
376 LayoutBox& child) const { 375 LayoutBox& child) const {
377 GridTrackSizingDirection child_inline_direction = 376 GridTrackSizingDirection child_inline_direction =
378 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); 377 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns);
379 bool is_row_axis = Direction() == child_inline_direction; 378 bool is_row_axis = Direction() == child_inline_direction;
380 const Length& child_size = is_row_axis ? child.StyleRef().LogicalWidth() 379 const Length& child_size = is_row_axis ? child.StyleRef().LogicalWidth()
381 : child.StyleRef().LogicalHeight(); 380 : child.StyleRef().LogicalHeight();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return algorithm_.FindFrUnitSize(tracks_span, left_over_space); 423 return algorithm_.FindFrUnitSize(tracks_span, left_over_space);
425 } 424 }
426 425
427 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks( 426 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks(
428 Vector<GridTrack*>& tracks, 427 Vector<GridTrack*>& tracks,
429 LayoutUnit& available_logical_space) const { 428 LayoutUnit& available_logical_space) const {
430 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr, 429 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr,
431 available_logical_space); 430 available_logical_space);
432 } 431 }
433 432
434 void GridTrackSizingAlgorithmStrategy::SetGridItemNeedsLayout(
435 LayoutBox& grid_item) const {
436 // Mac code can call computIntrinsicLogicalWidths() after the layout in
437 // content::RenderViewImpl::didUpdateLayout().
438 if (!GetLayoutGrid()->GetDocument().View()->IsInPerformLayout())
439 return;
440
441 grid_item.SetNeedsLayout(LayoutInvalidationReason::kGridChanged,
442 kMarkOnlyThis);
443 }
444
445 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild( 433 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild(
446 LayoutBox& child, 434 LayoutBox& child,
447 Length child_min_size, 435 Length child_min_size,
448 GridTrackSizingDirection child_inline_direction) const { 436 GridTrackSizingDirection child_inline_direction) const {
449 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild( 437 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild(
450 kInlineDirection, GetLayoutGrid(), child); 438 kInlineDirection, GetLayoutGrid(), child);
451 return child.ComputeLogicalWidthUsing( 439 return child.ComputeLogicalWidthUsing(
452 kMinSize, child_min_size, 440 kMinSize, child_min_size,
453 OverrideContainingBlockContentSizeForChild(child, 441 OverrideContainingBlockContentSizeForChild(child,
454 child_inline_direction), 442 child_inline_direction),
455 GetLayoutGrid()) + 443 GetLayoutGrid()) +
456 margin_logical_width; 444 margin_logical_width;
457 } 445 }
458 446
459 void DefiniteSizeStrategy::LayoutGridItemForMinSizeComputation( 447 void DefiniteSizeStrategy::LayoutGridItemForMinSizeComputation(
460 LayoutBox& child, 448 LayoutBox& child,
461 bool override_size_has_changed) const { 449 bool override_size_has_changed) const {
462 if (override_size_has_changed) 450 if (override_size_has_changed)
463 SetGridItemNeedsLayout(child); 451 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
464 child.LayoutIfNeeded(); 452 child.LayoutIfNeeded();
465 } 453 }
466 454
467 void DefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks, 455 void DefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks,
468 Optional<LayoutUnit>& free_space) { 456 Optional<LayoutUnit>& free_space) {
469 size_t tracks_size = tracks.size(); 457 size_t tracks_size = tracks.size();
470 Vector<GridTrack*> tracks_for_distribution(tracks_size); 458 Vector<GridTrack*> tracks_for_distribution(tracks_size);
471 for (size_t i = 0; i < tracks_size; ++i) { 459 for (size_t i = 0; i < tracks_size; ++i) {
472 tracks_for_distribution[i] = tracks.Data() + i; 460 tracks_for_distribution[i] = tracks.Data() + i;
473 tracks_for_distribution[i]->SetPlannedSize( 461 tracks_for_distribution[i]->SetPlannedSize(
(...skipping 30 matching lines...) Expand all
504 OverrideContainingBlockContentSizeForChild(child, 492 OverrideContainingBlockContentSizeForChild(child,
505 child_inline_direction), 493 child_inline_direction),
506 GetLayoutGrid()) + 494 GetLayoutGrid()) +
507 margin_logical_width; 495 margin_logical_width;
508 } 496 }
509 497
510 void IndefiniteSizeStrategy::LayoutGridItemForMinSizeComputation( 498 void IndefiniteSizeStrategy::LayoutGridItemForMinSizeComputation(
511 LayoutBox& child, 499 LayoutBox& child,
512 bool override_size_has_changed) const { 500 bool override_size_has_changed) const {
513 if (override_size_has_changed && Direction() != kForColumns) 501 if (override_size_has_changed && Direction() != kForColumns)
514 SetGridItemNeedsLayout(child); 502 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
515 child.LayoutIfNeeded(); 503 child.LayoutIfNeeded();
516 } 504 }
517 505
518 void IndefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks, 506 void IndefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks,
519 Optional<LayoutUnit>&) { 507 Optional<LayoutUnit>&) {
520 for (auto& track : tracks) 508 for (auto& track : tracks)
521 track.SetBaseSize(track.GrowthLimit()); 509 track.SetBaseSize(track.GrowthLimit());
522 } 510 }
523 511
524 static inline double NormalizedFlexFraction(const GridTrack& track, 512 static inline double NormalizedFlexFraction(const GridTrack& track,
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 DCHECK(algorithm_.IsValidTransition()); 1479 DCHECK(algorithm_.IsValidTransition());
1492 DCHECK(!algorithm_.needs_setup_); 1480 DCHECK(!algorithm_.needs_setup_);
1493 } 1481 }
1494 1482
1495 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { 1483 GridTrackSizingAlgorithm::StateMachine::~StateMachine() {
1496 algorithm_.AdvanceNextState(); 1484 algorithm_.AdvanceNextState();
1497 algorithm_.needs_setup_ = true; 1485 algorithm_.needs_setup_ = true;
1498 } 1486 }
1499 1487
1500 } // namespace blink 1488 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/GridTrackSizingAlgorithm.h ('k') | third_party/WebKit/Source/core/layout/LayoutGrid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698