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

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

Issue 2135703002: [css-grid] Fix crash when using auto repeat for indefinite widths (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplest approach Created 4 years, 5 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/LayoutGrid.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 /* 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // may trigger relayout). 436 // may trigger relayout).
437 LayoutState state(*this, locationOffset()); 437 LayoutState state(*this, locationOffset());
438 438
439 LayoutSize previousSize = size(); 439 LayoutSize previousSize = size();
440 440
441 updateLogicalWidth(); 441 updateLogicalWidth();
442 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPref erredSize, style()->logicalHeight(), LayoutUnit(-1)) == LayoutUnit(-1); 442 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPref erredSize, style()->logicalHeight(), LayoutUnit(-1)) == LayoutUnit(-1);
443 443
444 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); 444 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope);
445 445
446 placeItemsOnGrid(); 446 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated
447 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812)
448 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns))
449 dirtyGrid();
450 placeItemsOnGrid(TrackSizing);
447 451
448 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 452 GridSizingData sizingData(gridColumnCount(), gridRowCount());
449 453
450 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. 454 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns.
451 // At this point the logical width is always definite as the above call to updateLogicalWidth() 455 // At this point the logical width is always definite as the above call to updateLogicalWidth()
452 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code 456 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code
453 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve 457 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
454 // heights properly (like for positioned items for example). 458 // heights properly (like for positioned items for example).
455 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); 459 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
456 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); 460 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 { 508 {
505 if (span <= 1) 509 if (span <= 1)
506 return LayoutUnit(); 510 return LayoutUnit();
507 511
508 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap(); 512 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap();
509 return valueForLength(trackGap, LayoutUnit()) * (span - 1); 513 return valueForLength(trackGap, LayoutUnit()) * (span - 1);
510 } 514 }
511 515
512 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const 516 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const
513 { 517 {
514 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(); 518 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation);
515 519
516 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 520 GridSizingData sizingData(gridColumnCount(), gridRowCount());
517 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); 521 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit();
518 sizingData.sizingOperation = IntrinsicSizeComputation; 522 sizingData.sizingOperation = IntrinsicSizeComputation;
519 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth); 523 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth);
520 524
521 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack s.size()); 525 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack s.size());
522 minLogicalWidth += totalGuttersSize; 526 minLogicalWidth += totalGuttersSize;
523 maxLogicalWidth += totalGuttersSize; 527 maxLogicalWidth += totalGuttersSize;
524 528
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1381
1378 // Provided the grid container does not have a definite size or max-size in the relevant axis, 1382 // Provided the grid container does not have a definite size or max-size in the relevant axis,
1379 // if the min size is definite then the number of repetitions is the largest possible positive 1383 // if the min size is definite then the number of repetitions is the largest possible positive
1380 // integer that fulfills that minimum requirement. 1384 // integer that fulfills that minimum requirement.
1381 if (needsToFulfillMinimumSize) 1385 if (needsToFulfillMinimumSize)
1382 ++repetitions; 1386 ++repetitions;
1383 1387
1384 return repetitions; 1388 return repetitions;
1385 } 1389 }
1386 1390
1387 void LayoutGrid::placeItemsOnGrid() 1391 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation)
1388 { 1392 {
1389 if (!m_gridIsDirty) 1393 if (!m_gridIsDirty)
1390 return; 1394 return;
1391 1395
1392 ASSERT(m_gridItemArea.isEmpty()); 1396 ASSERT(m_gridItemArea.isEmpty());
1393 1397
1394 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); 1398 if (sizingOperation == IntrinsicSizeComputation)
1399 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().isEmpty() ? 0 : 1;
1400 else
1401 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns);
1395 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); 1402 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows);
1396 1403
1397 populateExplicitGridAndOrderIterator(); 1404 populateExplicitGridAndOrderIterator();
1398 1405
1399 // We clear the dirty bit here as the grid sizes have been updated. 1406 // We clear the dirty bit here as the grid sizes have been updated.
1400 m_gridIsDirty = false; 1407 m_gridIsDirty = false;
1401 1408
1402 Vector<LayoutBox*> autoMajorAxisAutoGridItems; 1409 Vector<LayoutBox*> autoMajorAxisAutoGridItems;
1403 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; 1410 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems;
1404 m_hasAnyOrthogonalChild = false; 1411 m_hasAnyOrthogonalChild = false;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 // style changes events happening during the layout phase or even while the painting process 1631 // style changes events happening during the layout phase or even while the painting process
1625 // is still ongoing. 1632 // is still ongoing.
1626 // Forcing a new layout for the Grid layout would cancel any ongoing paintin g and ensure 1633 // Forcing a new layout for the Grid layout would cancel any ongoing paintin g and ensure
1627 // the grid and its children are correctly laid out according to the new sty le rules. 1634 // the grid and its children are correctly laid out according to the new sty le rules.
1628 setNeedsLayout(LayoutInvalidationReason::GridChanged); 1635 setNeedsLayout(LayoutInvalidationReason::GridChanged);
1629 1636
1630 m_grid.resize(0); 1637 m_grid.resize(0);
1631 m_gridItemArea.clear(); 1638 m_gridItemArea.clear();
1632 m_gridItemsOverflowingGridArea.resize(0); 1639 m_gridItemsOverflowingGridArea.resize(0);
1633 m_gridItemsIndexesMap.clear(); 1640 m_gridItemsIndexesMap.clear();
1641 m_autoRepeatColumns = 0;
1642 m_autoRepeatRows = 0;
1634 m_gridIsDirty = true; 1643 m_gridIsDirty = true;
1635 } 1644 }
1636 1645
1637 static const StyleContentAlignmentData& normalValueBehavior() 1646 static const StyleContentAlignmentData& normalValueBehavior()
1638 { 1647 {
1639 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch}; 1648 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch};
1640 return normalBehavior; 1649 return normalBehavior;
1641 } 1650 }
1642 1651
1643 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData) 1652 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData)
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; 2372 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation;
2364 } 2373 }
2365 2374
2366 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2375 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2367 { 2376 {
2368 if (!m_gridItemArea.isEmpty()) 2377 if (!m_gridItemArea.isEmpty())
2369 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2378 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2370 } 2379 }
2371 2380
2372 } // namespace blink 2381 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698