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

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

Issue 2834473003: [css-grid] Preemptively store intrinsic sizes during layout (Closed)
Patch Set: More tests Created 3 years, 8 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 LayoutBox& child) const { 271 LayoutBox& child) const {
273 GridTrackSizingDirection child_block_direction = 272 GridTrackSizingDirection child_block_direction =
274 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForRows); 273 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForRows);
275 274
276 // If |child| has a relative logical height, we shouldn't let it override its 275 // If |child| has a relative logical height, we shouldn't let it override its
277 // intrinsic height, which is what we are interested in here. Thus we need to 276 // intrinsic height, which is what we are interested in here. Thus we need to
278 // set the block-axis override size to -1 (no possible resolution). 277 // set the block-axis override size to -1 (no possible resolution).
279 if (ShouldClearOverrideContainingBlockContentSizeForChild(child, kForRows)) { 278 if (ShouldClearOverrideContainingBlockContentSizeForChild(child, kForRows)) {
280 SetOverrideContainingBlockContentSizeForChild(child, child_block_direction, 279 SetOverrideContainingBlockContentSizeForChild(child, child_block_direction,
281 LayoutUnit(-1)); 280 LayoutUnit(-1));
282 SetGridItemNeedsLayout(child); 281 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
283 } 282 }
284 283
285 // 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
286 // during layout. 285 // during layout.
287 if (child.NeedsLayout()) 286 if (child.NeedsLayout())
288 child.ClearOverrideLogicalContentHeight(); 287 child.ClearOverrideLogicalContentHeight();
289 288
290 child.LayoutIfNeeded(); 289 child.LayoutIfNeeded();
291 GridAxis baseline_axis = GetLayoutGrid()->IsOrthogonalChild(child) 290 GridAxis baseline_axis = GetLayoutGrid()->IsOrthogonalChild(child)
292 ? kGridRowAxis 291 ? kGridRowAxis
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, kGridRowAxis) && 330 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, kGridRowAxis) &&
332 GetLayoutGrid()->IsBaselineContextComputed(kGridRowAxis)) { 331 GetLayoutGrid()->IsBaselineContextComputed(kGridRowAxis)) {
333 auto& group = 332 auto& group =
334 GetLayoutGrid()->GetBaselineGroupForChild(child, kGridRowAxis); 333 GetLayoutGrid()->GetBaselineGroupForChild(child, kGridRowAxis);
335 return group.MaxAscent() + group.MaxDescent(); 334 return group.MaxAscent() + group.MaxDescent();
336 } 335 }
337 } 336 }
338 337
339 if (UpdateOverrideContainingBlockContentSizeForChild(child, 338 if (UpdateOverrideContainingBlockContentSizeForChild(child,
340 child_inline_direction)) 339 child_inline_direction))
341 SetGridItemNeedsLayout(child); 340 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
342 return LogicalHeightForChild(child); 341 return LogicalHeightForChild(child);
343 } 342 }
344 343
345 DISABLE_CFI_PERF 344 DISABLE_CFI_PERF
346 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild( 345 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild(
347 LayoutBox& child) const { 346 LayoutBox& child) const {
348 GridTrackSizingDirection child_inline_direction = 347 GridTrackSizingDirection child_inline_direction =
349 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); 348 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns);
350 if (Direction() == child_inline_direction) { 349 if (Direction() == child_inline_direction) {
351 // If |child| has a relative logical width, we shouldn't let it override its 350 // If |child| has a relative logical width, we shouldn't let it override its
(...skipping 10 matching lines...) Expand all
362 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 361 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
363 LayoutUnit margin_logical_width = 362 LayoutUnit margin_logical_width =
364 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild( 363 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild(
365 kInlineDirection, GetLayoutGrid(), child) 364 kInlineDirection, GetLayoutGrid(), child)
366 : child.MarginLogicalWidth(); 365 : child.MarginLogicalWidth();
367 return child.MaxPreferredLogicalWidth() + margin_logical_width; 366 return child.MaxPreferredLogicalWidth() + margin_logical_width;
368 } 367 }
369 368
370 if (UpdateOverrideContainingBlockContentSizeForChild(child, 369 if (UpdateOverrideContainingBlockContentSizeForChild(child,
371 child_inline_direction)) 370 child_inline_direction))
372 SetGridItemNeedsLayout(child); 371 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
373 return LogicalHeightForChild(child); 372 return LogicalHeightForChild(child);
374 } 373 }
375 374
376 LayoutUnit GridTrackSizingAlgorithmStrategy::MinSizeForChild( 375 LayoutUnit GridTrackSizingAlgorithmStrategy::MinSizeForChild(
377 LayoutBox& child) const { 376 LayoutBox& child) const {
378 GridTrackSizingDirection child_inline_direction = 377 GridTrackSizingDirection child_inline_direction =
379 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); 378 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns);
380 bool is_row_axis = Direction() == child_inline_direction; 379 bool is_row_axis = Direction() == child_inline_direction;
381 const Length& child_size = is_row_axis ? child.StyleRef().LogicalWidth() 380 const Length& child_size = is_row_axis ? child.StyleRef().LogicalWidth()
382 : child.StyleRef().LogicalHeight(); 381 : child.StyleRef().LogicalHeight();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 return algorithm_.FindFrUnitSize(tracks_span, left_over_space); 424 return algorithm_.FindFrUnitSize(tracks_span, left_over_space);
426 } 425 }
427 426
428 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks( 427 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks(
429 Vector<GridTrack*>& tracks, 428 Vector<GridTrack*>& tracks,
430 LayoutUnit& available_logical_space) const { 429 LayoutUnit& available_logical_space) const {
431 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr, 430 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr,
432 available_logical_space); 431 available_logical_space);
433 } 432 }
434 433
435 void GridTrackSizingAlgorithmStrategy::SetGridItemNeedsLayout(
436 LayoutBox& grid_item) const {
437 // Mac code can call computIntrinsicLogicalWidths() after the layout in
438 // content::RenderViewImpl::didUpdateLayout().
439 if (!GetLayoutGrid()->GetDocument().View()->IsInPerformLayout())
440 return;
441
442 grid_item.SetNeedsLayout(LayoutInvalidationReason::kGridChanged,
443 kMarkOnlyThis);
444 }
445
446 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild( 434 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild(
447 LayoutBox& child, 435 LayoutBox& child,
448 Length child_min_size, 436 Length child_min_size,
449 GridTrackSizingDirection child_inline_direction) const { 437 GridTrackSizingDirection child_inline_direction) const {
450 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild( 438 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild(
451 kInlineDirection, GetLayoutGrid(), child); 439 kInlineDirection, GetLayoutGrid(), child);
452 return child.ComputeLogicalWidthUsing( 440 return child.ComputeLogicalWidthUsing(
453 kMinSize, child_min_size, 441 kMinSize, child_min_size,
454 OverrideContainingBlockContentSizeForChild(child, 442 OverrideContainingBlockContentSizeForChild(child,
455 child_inline_direction), 443 child_inline_direction),
456 GetLayoutGrid()) + 444 GetLayoutGrid()) +
457 margin_logical_width; 445 margin_logical_width;
458 } 446 }
459 447
460 void DefiniteSizeStrategy::LayoutGridItemForMinSizeComputation( 448 void DefiniteSizeStrategy::LayoutGridItemForMinSizeComputation(
461 LayoutBox& child, 449 LayoutBox& child,
462 bool override_size_has_changed) const { 450 bool override_size_has_changed) const {
463 if (override_size_has_changed) 451 if (override_size_has_changed)
464 SetGridItemNeedsLayout(child); 452 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
465 child.LayoutIfNeeded(); 453 child.LayoutIfNeeded();
466 } 454 }
467 455
468 void DefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks, 456 void DefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks,
469 Optional<LayoutUnit>& free_space) { 457 Optional<LayoutUnit>& free_space) {
470 size_t tracks_size = tracks.size(); 458 size_t tracks_size = tracks.size();
471 Vector<GridTrack*> tracks_for_distribution(tracks_size); 459 Vector<GridTrack*> tracks_for_distribution(tracks_size);
472 for (size_t i = 0; i < tracks_size; ++i) { 460 for (size_t i = 0; i < tracks_size; ++i) {
473 tracks_for_distribution[i] = tracks.data() + i; 461 tracks_for_distribution[i] = tracks.data() + i;
474 tracks_for_distribution[i]->SetPlannedSize( 462 tracks_for_distribution[i]->SetPlannedSize(
(...skipping 30 matching lines...) Expand all
505 OverrideContainingBlockContentSizeForChild(child, 493 OverrideContainingBlockContentSizeForChild(child,
506 child_inline_direction), 494 child_inline_direction),
507 GetLayoutGrid()) + 495 GetLayoutGrid()) +
508 margin_logical_width; 496 margin_logical_width;
509 } 497 }
510 498
511 void IndefiniteSizeStrategy::LayoutGridItemForMinSizeComputation( 499 void IndefiniteSizeStrategy::LayoutGridItemForMinSizeComputation(
512 LayoutBox& child, 500 LayoutBox& child,
513 bool override_size_has_changed) const { 501 bool override_size_has_changed) const {
514 if (override_size_has_changed && Direction() != kForColumns) 502 if (override_size_has_changed && Direction() != kForColumns)
515 SetGridItemNeedsLayout(child); 503 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis);
516 child.LayoutIfNeeded(); 504 child.LayoutIfNeeded();
517 } 505 }
518 506
519 void IndefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks, 507 void IndefiniteSizeStrategy::MaximizeTracks(Vector<GridTrack>& tracks,
520 Optional<LayoutUnit>&) { 508 Optional<LayoutUnit>&) {
521 for (auto& track : tracks) 509 for (auto& track : tracks)
522 track.SetBaseSize(track.GrowthLimit()); 510 track.SetBaseSize(track.GrowthLimit());
523 } 511 }
524 512
525 static inline double NormalizedFlexFraction(const GridTrack& track, 513 static inline double NormalizedFlexFraction(const GridTrack& track,
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 DCHECK(algorithm_.IsValidTransition()); 1497 DCHECK(algorithm_.IsValidTransition());
1510 DCHECK(!algorithm_.needs_setup_); 1498 DCHECK(!algorithm_.needs_setup_);
1511 } 1499 }
1512 1500
1513 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { 1501 GridTrackSizingAlgorithm::StateMachine::~StateMachine() {
1514 algorithm_.AdvanceNextState(); 1502 algorithm_.AdvanceNextState();
1515 algorithm_.needs_setup_ = true; 1503 algorithm_.needs_setup_ = true;
1516 } 1504 }
1517 1505
1518 } // namespace blink 1506 } // 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