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

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

Issue 2698663003: [css-grid] Improve intrinsic size computation with orthogonal flows (Closed)
Patch Set: Patch for landing 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/GridTrackSizingAlgorithm.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
7 #include "core/layout/Grid.h" 8 #include "core/layout/Grid.h"
8 #include "core/layout/LayoutGrid.h" 9 #include "core/layout/LayoutGrid.h"
9 #include "platform/LengthFunctions.h" 10 #include "platform/LengthFunctions.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 class GridSizingData; 14 class GridSizingData;
14 15
15 LayoutUnit GridTrack::baseSize() const { 16 LayoutUnit GridTrack::baseSize() const {
16 DCHECK(isGrowthLimitBiggerThanBaseSize()); 17 DCHECK(isGrowthLimitBiggerThanBaseSize());
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 LayoutBox& child) const { 260 LayoutBox& child) const {
260 GridTrackSizingDirection childBlockDirection = 261 GridTrackSizingDirection childBlockDirection =
261 flowAwareDirectionForChild(layoutGrid(), child, ForRows); 262 flowAwareDirectionForChild(layoutGrid(), child, ForRows);
262 263
263 // If |child| has a relative logical height, we shouldn't let it override its 264 // If |child| has a relative logical height, we shouldn't let it override its
264 // intrinsic height, which is what we are interested in here. Thus we need to 265 // intrinsic height, which is what we are interested in here. Thus we need to
265 // set the block-axis override size to -1 (no possible resolution). 266 // set the block-axis override size to -1 (no possible resolution).
266 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForRows)) { 267 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForRows)) {
267 setOverrideContainingBlockContentSizeForChild(child, childBlockDirection, 268 setOverrideContainingBlockContentSizeForChild(child, childBlockDirection,
268 LayoutUnit(-1)); 269 LayoutUnit(-1));
269 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 270 setGridItemNeedsLayout(child);
270 } 271 }
271 272
272 // We need to clear the stretched height to properly compute logical height 273 // We need to clear the stretched height to properly compute logical height
273 // during layout. 274 // during layout.
274 if (child.needsLayout()) 275 if (child.needsLayout())
275 child.clearOverrideLogicalContentHeight(); 276 child.clearOverrideLogicalContentHeight();
276 277
277 child.layoutIfNeeded(); 278 child.layoutIfNeeded();
278 return child.logicalHeight() + child.marginLogicalHeight(); 279 return child.logicalHeight() + child.marginLogicalHeight();
279 } 280 }
(...skipping 16 matching lines...) Expand all
296 // FIXME: It's unclear if we should return the intrinsic width or the 297 // FIXME: It's unclear if we should return the intrinsic width or the
297 // preferred width. 298 // preferred width.
298 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 299 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
299 LayoutUnit marginLogicalWidth = 300 LayoutUnit marginLogicalWidth =
300 child.needsLayout() ? computeMarginLogicalSizeForChild( 301 child.needsLayout() ? computeMarginLogicalSizeForChild(
301 InlineDirection, layoutGrid(), child) 302 InlineDirection, layoutGrid(), child)
302 : child.marginLogicalWidth(); 303 : child.marginLogicalWidth();
303 return child.minPreferredLogicalWidth() + marginLogicalWidth; 304 return child.minPreferredLogicalWidth() + marginLogicalWidth;
304 } 305 }
305 306
306 // All orthogonal flow boxes were already laid out during an early layout
307 // phase performed in FrameView::performLayout.
308 // It's true that grid track sizing was not completed at that time and it may
309 // afffect the final height of a grid item, but since it's forbidden to
310 // perform a layout during intrinsic width computation, we have to use that
311 // computed height for now.
312 if (direction() == ForColumns &&
313 m_algorithm.m_sizingOperation == IntrinsicSizeComputation) {
314 DCHECK(layoutGrid()->isOrthogonalChild(child));
315 return child.logicalHeight() + child.marginLogicalHeight();
316 }
317
318 if (updateOverrideContainingBlockContentSizeForChild(child, 307 if (updateOverrideContainingBlockContentSizeForChild(child,
319 childInlineDirection)) 308 childInlineDirection))
320 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 309 setGridItemNeedsLayout(child);
321 return logicalHeightForChild(child); 310 return logicalHeightForChild(child);
322 } 311 }
323 312
324 DISABLE_CFI_PERF 313 DISABLE_CFI_PERF
325 LayoutUnit GridTrackSizingAlgorithmStrategy::maxContentForChild( 314 LayoutUnit GridTrackSizingAlgorithmStrategy::maxContentForChild(
326 LayoutBox& child) const { 315 LayoutBox& child) const {
327 GridTrackSizingDirection childInlineDirection = 316 GridTrackSizingDirection childInlineDirection =
328 flowAwareDirectionForChild(layoutGrid(), child, ForColumns); 317 flowAwareDirectionForChild(layoutGrid(), child, ForColumns);
329 if (direction() == childInlineDirection) { 318 if (direction() == childInlineDirection) {
330 // If |child| has a relative logical width, we shouldn't let it override its 319 // If |child| has a relative logical width, we shouldn't let it override its
331 // intrinsic width, which is what we are interested in here. Thus we need to 320 // intrinsic width, which is what we are interested in here. Thus we need to
332 // set the inline-axis override size to -1 (no possible resolution). 321 // set the inline-axis override size to -1 (no possible resolution).
333 if (shouldClearOverrideContainingBlockContentSizeForChild(child, 322 if (shouldClearOverrideContainingBlockContentSizeForChild(child,
334 ForColumns)) { 323 ForColumns)) {
335 setOverrideContainingBlockContentSizeForChild(child, childInlineDirection, 324 setOverrideContainingBlockContentSizeForChild(child, childInlineDirection,
336 LayoutUnit(-1)); 325 LayoutUnit(-1));
337 } 326 }
338 327
339 // FIXME: It's unclear if we should return the intrinsic width or the 328 // FIXME: It's unclear if we should return the intrinsic width or the
340 // preferred width. 329 // preferred width.
341 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 330 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
342 LayoutUnit marginLogicalWidth = 331 LayoutUnit marginLogicalWidth =
343 child.needsLayout() ? computeMarginLogicalSizeForChild( 332 child.needsLayout() ? computeMarginLogicalSizeForChild(
344 InlineDirection, layoutGrid(), child) 333 InlineDirection, layoutGrid(), child)
345 : child.marginLogicalWidth(); 334 : child.marginLogicalWidth();
346 return child.maxPreferredLogicalWidth() + marginLogicalWidth; 335 return child.maxPreferredLogicalWidth() + marginLogicalWidth;
347 } 336 }
348 337
349 if (direction() == ForColumns &&
350 m_algorithm.m_sizingOperation == IntrinsicSizeComputation) {
351 // All orthogonal flow boxes were already laid out during an early layout
352 // phase performed in FrameView::performLayout. It's true that grid track
353 // sizing was not completed at that time and it may afffect the final height
354 // of a grid item, but since it's forbidden to perform a layout during
355 // intrinsic width computation, we have to use that computed height for now.
356 DCHECK(layoutGrid()->isOrthogonalChild(child));
357 return child.logicalHeight() + child.marginLogicalHeight();
358 }
359
360 if (updateOverrideContainingBlockContentSizeForChild(child, 338 if (updateOverrideContainingBlockContentSizeForChild(child,
361 childInlineDirection)) 339 childInlineDirection))
362 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 340 setGridItemNeedsLayout(child);
363 return logicalHeightForChild(child); 341 return logicalHeightForChild(child);
364 } 342 }
365 343
366 LayoutUnit GridTrackSizingAlgorithmStrategy::minSizeForChild( 344 LayoutUnit GridTrackSizingAlgorithmStrategy::minSizeForChild(
367 LayoutBox& child) const { 345 LayoutBox& child) const {
368 GridTrackSizingDirection childInlineDirection = 346 GridTrackSizingDirection childInlineDirection =
369 flowAwareDirectionForChild(layoutGrid(), child, ForColumns); 347 flowAwareDirectionForChild(layoutGrid(), child, ForColumns);
370 bool isRowAxis = direction() == childInlineDirection; 348 bool isRowAxis = direction() == childInlineDirection;
371 const Length& childSize = isRowAxis ? child.styleRef().logicalWidth() 349 const Length& childSize = isRowAxis ? child.styleRef().logicalWidth()
372 : child.styleRef().logicalHeight(); 350 : child.styleRef().logicalHeight();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return m_algorithm.findFrUnitSize(tracksSpan, leftOverSpace); 390 return m_algorithm.findFrUnitSize(tracksSpan, leftOverSpace);
413 } 391 }
414 392
415 void GridTrackSizingAlgorithmStrategy::distributeSpaceToTracks( 393 void GridTrackSizingAlgorithmStrategy::distributeSpaceToTracks(
416 Vector<GridTrack*>& tracks, 394 Vector<GridTrack*>& tracks,
417 LayoutUnit& availableLogicalSpace) const { 395 LayoutUnit& availableLogicalSpace) const {
418 m_algorithm.distributeSpaceToTracks<MaximizeTracks>(tracks, nullptr, 396 m_algorithm.distributeSpaceToTracks<MaximizeTracks>(tracks, nullptr,
419 availableLogicalSpace); 397 availableLogicalSpace);
420 } 398 }
421 399
400 void GridTrackSizingAlgorithmStrategy::setGridItemNeedsLayout(
401 LayoutBox& gridItem) const {
402 // Mac code can call computIntrinsicLogicalWidths() after the layout in
403 // content::RenderViewImpl::didUpdateLayout().
404 if (!layoutGrid()->document().view()->isInPerformLayout())
405 return;
406
407 gridItem.setNeedsLayout(LayoutInvalidationReason::GridChanged, MarkOnlyThis);
408 }
409
422 LayoutUnit DefiniteSizeStrategy::minLogicalWidthForChild( 410 LayoutUnit DefiniteSizeStrategy::minLogicalWidthForChild(
423 LayoutBox& child, 411 LayoutBox& child,
424 Length childMinSize, 412 Length childMinSize,
425 GridTrackSizingDirection childInlineDirection) const { 413 GridTrackSizingDirection childInlineDirection) const {
426 LayoutUnit marginLogicalWidth = 414 LayoutUnit marginLogicalWidth =
427 computeMarginLogicalSizeForChild(InlineDirection, layoutGrid(), child); 415 computeMarginLogicalSizeForChild(InlineDirection, layoutGrid(), child);
428 return child.computeLogicalWidthUsing( 416 return child.computeLogicalWidthUsing(
429 MinSize, childMinSize, overrideContainingBlockContentSizeForChild( 417 MinSize, childMinSize, overrideContainingBlockContentSizeForChild(
430 child, childInlineDirection), 418 child, childInlineDirection),
431 layoutGrid()) + 419 layoutGrid()) +
432 marginLogicalWidth; 420 marginLogicalWidth;
433 } 421 }
434 422
435 void DefiniteSizeStrategy::layoutGridItemForMinSizeComputation( 423 void DefiniteSizeStrategy::layoutGridItemForMinSizeComputation(
436 LayoutBox& child, 424 LayoutBox& child,
437 bool overrideSizeHasChanged) const { 425 bool overrideSizeHasChanged) const {
438 if (overrideSizeHasChanged) 426 if (overrideSizeHasChanged)
439 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 427 setGridItemNeedsLayout(child);
440 child.layoutIfNeeded(); 428 child.layoutIfNeeded();
441 } 429 }
442 430
443 void DefiniteSizeStrategy::maximizeTracks(Vector<GridTrack>& tracks, 431 void DefiniteSizeStrategy::maximizeTracks(Vector<GridTrack>& tracks,
444 LayoutUnit& freeSpace) { 432 LayoutUnit& freeSpace) {
445 size_t tracksSize = tracks.size(); 433 size_t tracksSize = tracks.size();
446 Vector<GridTrack*> tracksForDistribution(tracksSize); 434 Vector<GridTrack*> tracksForDistribution(tracksSize);
447 for (size_t i = 0; i < tracksSize; ++i) { 435 for (size_t i = 0; i < tracksSize; ++i) {
448 tracksForDistribution[i] = tracks.data() + i; 436 tracksForDistribution[i] = tracks.data() + i;
449 tracksForDistribution[i]->setPlannedSize( 437 tracksForDistribution[i]->setPlannedSize(
(...skipping 27 matching lines...) Expand all
477 MinSize, childMinSize, overrideContainingBlockContentSizeForChild( 465 MinSize, childMinSize, overrideContainingBlockContentSizeForChild(
478 child, childInlineDirection), 466 child, childInlineDirection),
479 layoutGrid()) + 467 layoutGrid()) +
480 marginLogicalWidth; 468 marginLogicalWidth;
481 } 469 }
482 470
483 void IndefiniteSizeStrategy::layoutGridItemForMinSizeComputation( 471 void IndefiniteSizeStrategy::layoutGridItemForMinSizeComputation(
484 LayoutBox& child, 472 LayoutBox& child,
485 bool overrideSizeHasChanged) const { 473 bool overrideSizeHasChanged) const {
486 if (overrideSizeHasChanged && direction() != ForColumns) 474 if (overrideSizeHasChanged && direction() != ForColumns)
487 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 475 setGridItemNeedsLayout(child);
488 child.layoutIfNeeded(); 476 child.layoutIfNeeded();
489 } 477 }
490 478
491 void IndefiniteSizeStrategy::maximizeTracks(Vector<GridTrack>& tracks, 479 void IndefiniteSizeStrategy::maximizeTracks(Vector<GridTrack>& tracks,
492 LayoutUnit&) { 480 LayoutUnit&) {
493 for (auto& track : tracks) 481 for (auto& track : tracks)
494 track.setBaseSize(track.growthLimit()); 482 track.setBaseSize(track.growthLimit());
495 } 483 }
496 484
497 static inline double normalizedFlexFraction(const GridTrack& track, 485 static inline double normalizedFlexFraction(const GridTrack& track,
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 DCHECK(m_algorithm.isValidTransition()); 1423 DCHECK(m_algorithm.isValidTransition());
1436 DCHECK(!m_algorithm.m_needsSetup); 1424 DCHECK(!m_algorithm.m_needsSetup);
1437 } 1425 }
1438 1426
1439 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { 1427 GridTrackSizingAlgorithm::StateMachine::~StateMachine() {
1440 m_algorithm.advanceNextState(); 1428 m_algorithm.advanceNextState();
1441 m_algorithm.m_needsSetup = true; 1429 m_algorithm.m_needsSetup = true;
1442 } 1430 }
1443 1431
1444 } // namespace blink 1432 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/GridTrackSizingAlgorithm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698