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

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

Issue 1362683003: [css-grid] Small refactoring in LayoutGrid::layoutPositionedObjects() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 return; 1397 return;
1398 1398
1399 bool containerHasHorizontalWritingMode = isHorizontalWritingMode(); 1399 bool containerHasHorizontalWritingMode = isHorizontalWritingMode();
1400 for (auto* child : *positionedDescendants) { 1400 for (auto* child : *positionedDescendants) {
1401 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != cont ainerHasHorizontalWritingMode; 1401 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != cont ainerHasHorizontalWritingMode;
1402 if (hasOrthogonalWritingMode) { 1402 if (hasOrthogonalWritingMode) {
1403 // FIXME: Properly support orthogonal writing mode. 1403 // FIXME: Properly support orthogonal writing mode.
1404 continue; 1404 continue;
1405 } 1405 }
1406 1406
1407 // FIXME: Detect properly if start/end is auto for inexistent named grid lines. 1407 // FIXME: Detect properly if start/end is auto for inexistent named grid lines.
cbiesinger 2015/09/30 14:27:35 This comment should probably move to offsetAndBrea
Manuel Rego 2015/09/30 20:53:51 Yep, you're right, I forgot to move it in this pat
1408 bool columnStartIsAuto = child->style()->gridColumnStart().isAuto();
1409 LayoutUnit columnOffset = LayoutUnit(); 1408 LayoutUnit columnOffset = LayoutUnit();
1410 LayoutUnit columnBreadth = LayoutUnit(); 1409 LayoutUnit columnBreadth = LayoutUnit();
1411 offsetAndBreadthForPositionedChild(*child, ForColumns, columnStartIsAuto , child->style()->gridColumnEnd().isAuto(), columnOffset, columnBreadth); 1410 offsetAndBreadthForPositionedChild(*child, ForColumns, columnOffset, col umnBreadth);
1412 bool rowStartIsAuto = child->style()->gridRowStart().isAuto();
1413 LayoutUnit rowOffset = LayoutUnit(); 1411 LayoutUnit rowOffset = LayoutUnit();
1414 LayoutUnit rowBreadth = LayoutUnit(); 1412 LayoutUnit rowBreadth = LayoutUnit();
1415 offsetAndBreadthForPositionedChild(*child, ForRows, rowStartIsAuto, chil d->style()->gridRowEnd().isAuto(), rowOffset, rowBreadth); 1413 offsetAndBreadthForPositionedChild(*child, ForRows, rowOffset, rowBreadt h);
1416 1414
1417 child->setOverrideContainingBlockContentLogicalWidth(columnBreadth); 1415 child->setOverrideContainingBlockContentLogicalWidth(columnBreadth);
1418 child->setOverrideContainingBlockContentLogicalHeight(rowBreadth); 1416 child->setOverrideContainingBlockContentLogicalHeight(rowBreadth);
1419 child->setExtraInlineOffset(columnOffset); 1417 child->setExtraInlineOffset(columnOffset);
1420 child->setExtraBlockOffset(rowOffset); 1418 child->setExtraBlockOffset(rowOffset);
1421
1422 if (child->parent() == this) {
1423 // If column/row start is "auto" the static position has been alread y set in prepareChildForPositionedLayout().
1424 // If column/row start is not "auto" the padding has been already co mputed in offsetAndBreadthForPositionedChild().
1425 DeprecatedPaintLayer* childLayer = child->layer();
1426 if (!columnStartIsAuto)
1427 childLayer->setStaticInlinePosition(borderStart() + columnOffset );
1428 if (!rowStartIsAuto)
1429 childLayer->setStaticBlockPosition(borderBefore() + rowOffset);
1430 }
1431 } 1419 }
1432 1420
1433 LayoutBlock::layoutPositionedObjects(relayoutChildren, info); 1421 LayoutBlock::layoutPositionedObjects(relayoutChildren, info);
1434 } 1422 }
1435 1423
1436 void LayoutGrid::offsetAndBreadthForPositionedChild(const LayoutBox& child, Grid TrackSizingDirection direction, bool startIsAuto, bool endIsAuto, LayoutUnit& of fset, LayoutUnit& breadth) 1424 void LayoutGrid::offsetAndBreadthForPositionedChild(const LayoutBox& child, Grid TrackSizingDirection direction, LayoutUnit& offset, LayoutUnit& breadth)
1437 { 1425 {
1438 ASSERT(child.isHorizontalWritingMode() == isHorizontalWritingMode()); 1426 ASSERT(child.isHorizontalWritingMode() == isHorizontalWritingMode());
1439 1427
1440 OwnPtr<GridSpan> positions = GridResolvedPosition::resolveGridPositionsFromS tyle(*style(), child, direction); 1428 OwnPtr<GridSpan> positions = GridResolvedPosition::resolveGridPositionsFromS tyle(*style(), child, direction);
1441 if (!positions) { 1429 if (!positions) {
1442 offset = LayoutUnit(); 1430 offset = LayoutUnit();
1443 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic alHeight(); 1431 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic alHeight();
1444 return; 1432 return;
1445 } 1433 }
1446 1434
1435 bool startIsAuto = (direction == ForColumns) ? child.style()->gridColumnStar t().isAuto() : child.style()->gridRowStart().isAuto();
1436 bool endIsAuto = (direction == ForColumns) ? child.style()->gridColumnEnd(). isAuto() : child.style()->gridRowEnd().isAuto();
1437
1447 GridResolvedPosition firstPosition = GridResolvedPosition(0); 1438 GridResolvedPosition firstPosition = GridResolvedPosition(0);
1448 GridResolvedPosition initialPosition = startIsAuto ? firstPosition : positio ns->resolvedInitialPosition; 1439 GridResolvedPosition initialPosition = startIsAuto ? firstPosition : positio ns->resolvedInitialPosition;
1449 GridResolvedPosition lastPosition = GridResolvedPosition((direction == ForCo lumns ? gridColumnCount() : gridRowCount()) - 1); 1440 GridResolvedPosition lastPosition = GridResolvedPosition((direction == ForCo lumns ? gridColumnCount() : gridRowCount()) - 1);
1450 GridResolvedPosition finalPosition = endIsAuto ? lastPosition : positions->r esolvedFinalPosition; 1441 GridResolvedPosition finalPosition = endIsAuto ? lastPosition : positions->r esolvedFinalPosition;
1451 1442
1452 // Positioned children do not grow the grid, so we need to clamp the positio ns to avoid ending up outside of it. 1443 // Positioned children do not grow the grid, so we need to clamp the positio ns to avoid ending up outside of it.
1453 initialPosition = std::min<GridResolvedPosition>(initialPosition, lastPositi on); 1444 initialPosition = std::min<GridResolvedPosition>(initialPosition, lastPositi on);
1454 finalPosition = std::min<GridResolvedPosition>(finalPosition, lastPosition); 1445 finalPosition = std::min<GridResolvedPosition>(finalPosition, lastPosition);
1455 1446
1456 LayoutUnit start = startIsAuto ? LayoutUnit() : (direction == ForColumns) ? m_columnPositions[initialPosition.toInt()] : m_rowPositions[initialPosition.toI nt()]; 1447 LayoutUnit start = startIsAuto ? LayoutUnit() : (direction == ForColumns) ? m_columnPositions[initialPosition.toInt()] : m_rowPositions[initialPosition.toI nt()];
1457 LayoutUnit end = endIsAuto ? (direction == ForColumns) ? logicalWidth() : lo gicalHeight() : (direction == ForColumns) ? m_columnPositions[finalPosition.nex t().toInt()] : m_rowPositions[finalPosition.next().toInt()]; 1448 LayoutUnit end = endIsAuto ? (direction == ForColumns) ? logicalWidth() : lo gicalHeight() : (direction == ForColumns) ? m_columnPositions[finalPosition.nex t().toInt()] : m_rowPositions[finalPosition.next().toInt()];
1458 1449
1459 breadth = end - start; 1450 breadth = end - start;
1460 1451
1461 if (startIsAuto) 1452 if (startIsAuto)
1462 breadth -= (direction == ForColumns) ? borderStart() : borderBefore(); 1453 breadth -= (direction == ForColumns) ? borderStart() : borderBefore();
1463 else 1454 else
1464 start -= ((direction == ForColumns) ? borderStart() : borderBefore()); 1455 start -= ((direction == ForColumns) ? borderStart() : borderBefore());
1465 1456
1466 if (endIsAuto) { 1457 if (endIsAuto) {
1467 breadth -= (direction == ForColumns) ? borderEnd() : borderAfter(); 1458 breadth -= (direction == ForColumns) ? borderEnd() : borderAfter();
1468 breadth -= scrollbarLogicalWidth(); 1459 breadth -= scrollbarLogicalWidth();
1469 } 1460 }
1470 1461
1471 offset = start; 1462 offset = start;
1463
1464 if (child.parent() == this && !startIsAuto) {
1465 // If column/row start is "auto" the static position has been already se t in prepareChildForPositionedLayout().
1466 DeprecatedPaintLayer* childLayer = child.layer();
1467 if (direction == ForColumns)
1468 childLayer->setStaticInlinePosition(borderStart() + offset);
1469 else
1470 childLayer->setStaticBlockPosition(borderBefore() + offset);
1471 }
svillar 2015/09/28 08:09:28 So now you're doing this before all the child->set
Manuel Rego 2015/09/28 09:49:09 Yeah, I wouldn't expect other effects as they're j
1472 } 1472 }
1473 1473
1474 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const 1474 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const
1475 { 1475 {
1476 ASSERT(m_gridItemCoordinate.contains(&gridItem)); 1476 ASSERT(m_gridItemCoordinate.contains(&gridItem));
1477 return m_gridItemCoordinate.get(&gridItem); 1477 return m_gridItemCoordinate.get(&gridItem);
1478 } 1478 }
1479 1479
1480 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const 1480 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const
1481 { 1481 {
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 1926
1927 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); 1927 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child));
1928 } 1928 }
1929 1929
1930 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) 1930 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset)
1931 { 1931 {
1932 GridPainter(*this).paintChildren(paintInfo, paintOffset); 1932 GridPainter(*this).paintChildren(paintInfo, paintOffset);
1933 } 1933 }
1934 1934
1935 } // namespace blink 1935 } // 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