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

Side by Side Diff: Source/core/css/resolver/StyleAdjuster.cpp

Issue 148293008: [CSS Grid Layout] Add support to place items using named grid lines (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Improved readability of adjustNamedGridItemPosition Created 6 years, 9 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 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // not be scaled again. 370 // not be scaled again.
371 if (e->hasTagName(SVGNames::foreignObjectTag)) 371 if (e->hasTagName(SVGNames::foreignObjectTag))
372 style->setEffectiveZoom(RenderStyle::initialZoom()); 372 style->setEffectiveZoom(RenderStyle::initialZoom());
373 373
374 // SVG text layout code expects us to be a block-level style element. 374 // SVG text layout code expects us to be a block-level style element.
375 if ((e->hasTagName(SVGNames::foreignObjectTag) || e->hasTagName(SVGNames ::textTag)) && style->isDisplayInlineType()) 375 if ((e->hasTagName(SVGNames::foreignObjectTag) || e->hasTagName(SVGNames ::textTag)) && style->isDisplayInlineType())
376 style->setDisplay(BLOCK); 376 style->setDisplay(BLOCK);
377 } 377 }
378 } 378 }
379 379
380 static inline bool gridLineDefinedBeforeGridArea(const String& gridLineName, con st String& gridAreaName, const NamedGridAreaMap& gridAreaMap, const NamedGridLin esMap& namedLinesMap, GridPositionSide side)
381 {
382 ASSERT(namedLinesMap.contains(gridLineName));
383 // Grid line indexes are inserted in order.
384 size_t namedGridLineFirstDefinition = GridPosition::adjustGridPositionForSid e(namedLinesMap.get(gridLineName)[0], side);
385
386 ASSERT(gridAreaMap.contains(gridAreaName));
387 const GridCoordinate& gridAreaCoordinates = gridAreaMap.get(gridAreaName);
388
389 // GridCoordinate refers to tracks while the indexes in namedLinesMap refer to lines, that's why we need to add 1 to
390 // the grid coordinate to get the end line index.
391 switch (side) {
392 case ColumnStartSide:
393 return namedGridLineFirstDefinition < gridAreaCoordinates.columns.initia lPositionIndex;
394 case ColumnEndSide:
395 return namedGridLineFirstDefinition < gridAreaCoordinates.columns.finalP ositionIndex;
396 case RowStartSide:
397 return namedGridLineFirstDefinition < gridAreaCoordinates.rows.initialPo sitionIndex;
398 case RowEndSide:
399 return namedGridLineFirstDefinition < gridAreaCoordinates.rows.finalPosi tionIndex;
400 default:
401 ASSERT_NOT_REACHED();
402 return false;
403 }
404 }
405
406 PassOwnPtr<GridPosition> StyleAdjuster::adjustNamedGridItemPosition(const NamedG ridAreaMap& gridAreaMap, const NamedGridLinesMap& namedLinesMap, const GridPosit ion& position, GridPositionSide side) const
407 {
408 ASSERT(position.isNamedGridArea());
409 // The StyleBuilder always treats <custom-ident> as a named grid area. We mu st decide here if they are going to be resolved
410 // to either a grid area or a grid line.
411
412 String namedGridAreaOrGridLine = position.namedGridLine();
413 bool hasStartSuffix = namedGridAreaOrGridLine.endsWith("-start");
414 bool hasEndSuffix = namedGridAreaOrGridLine.endsWith("-end");
415 bool isStartSide = side == ColumnStartSide || side == RowStartSide;
Julien - ping for review 2014/03/05 01:12:35 This could probably be an helper function (not rea
416 bool hasStartSuffixForStartSide = hasStartSuffix && isStartSide;
417 bool hasEndSuffixForEndSide = hasEndSuffix && !isStartSide;
418 size_t suffixLength = hasStartSuffix ? strlen("-start") : strlen("-end");
419 String gridAreaName = hasStartSuffixForStartSide || hasEndSuffixForEndSide ? namedGridAreaOrGridLine.substring(0, namedGridAreaOrGridLine.length() - suffixL ength) : namedGridAreaOrGridLine;
420
421 if (gridAreaMap.contains(gridAreaName)) {
422 String gridLineName;
423 if (isStartSide && !hasStartSuffix)
Julien - ping for review 2014/03/05 01:12:35 I think I get why we need this now, thanks for the
424 gridLineName = namedGridAreaOrGridLine + "-start";
425 else if (!isStartSide && !hasEndSuffix)
426 gridLineName = namedGridAreaOrGridLine + "-end";
427 else
428 gridLineName = namedGridAreaOrGridLine;
429
430 if (namedLinesMap.contains(gridLineName) && gridLineDefinedBeforeGridAre a(gridLineName, gridAreaName, gridAreaMap, namedLinesMap, side)) {
431 // Use the explicitly defined grid line defined before the grid area instead of the grid area.
432 OwnPtr<GridPosition> adjustedPosition = adoptPtr(new GridPosition()) ;
433 adjustedPosition->setExplicitPosition(1, gridLineName);
434 return adjustedPosition.release();
435 }
436
437 if (hasStartSuffixForStartSide || hasEndSuffixForEndSide) {
438 // Renderer expects the grid area name instead of the implicit grid line name.
439 OwnPtr<GridPosition> adjustedPosition = adoptPtr(new GridPosition()) ;
440 adjustedPosition->setNamedGridArea(gridAreaName);
441 return adjustedPosition.release();
442 }
443
444 return nullptr;
445 }
446
447 if (namedLinesMap.contains(namedGridAreaOrGridLine)) {
448 OwnPtr<GridPosition> adjustedPosition = adoptPtr(new GridPosition());
449 adjustedPosition->setExplicitPosition(1, namedGridAreaOrGridLine);
450 return adjustedPosition.release();
451 }
452
453 // We need to clear unknown named grid areas
454 return adoptPtr(new GridPosition());
455 }
456
380 void StyleAdjuster::adjustGridItemPosition(RenderStyle* style, RenderStyle* pare ntStyle) const 457 void StyleAdjuster::adjustGridItemPosition(RenderStyle* style, RenderStyle* pare ntStyle) const
381 { 458 {
382 const GridPosition& columnStartPosition = style->gridColumnStart(); 459 const GridPosition& columnStartPosition = style->gridColumnStart();
383 const GridPosition& columnEndPosition = style->gridColumnEnd(); 460 const GridPosition& columnEndPosition = style->gridColumnEnd();
384 const GridPosition& rowStartPosition = style->gridRowStart(); 461 const GridPosition& rowStartPosition = style->gridRowStart();
385 const GridPosition& rowEndPosition = style->gridRowEnd(); 462 const GridPosition& rowEndPosition = style->gridRowEnd();
386 463
387 // If opposing grid-placement properties both specify a grid span, they both compute to ‘auto’. 464 // If opposing grid-placement properties both specify a grid span, they both compute to ‘auto’.
388 if (columnStartPosition.isSpan() && columnEndPosition.isSpan()) { 465 if (columnStartPosition.isSpan() && columnEndPosition.isSpan()) {
389 style->setGridColumnStart(GridPosition()); 466 style->setGridColumnStart(GridPosition());
390 style->setGridColumnEnd(GridPosition()); 467 style->setGridColumnEnd(GridPosition());
391 } 468 }
392 469
393 if (rowStartPosition.isSpan() && rowEndPosition.isSpan()) { 470 if (rowStartPosition.isSpan() && rowEndPosition.isSpan()) {
394 style->setGridRowStart(GridPosition()); 471 style->setGridRowStart(GridPosition());
395 style->setGridRowEnd(GridPosition()); 472 style->setGridRowEnd(GridPosition());
396 } 473 }
397 474
398 // Unknown named grid area compute to 'auto'. 475 // If the grid position is a single <ident> then the spec mandates us to res olve it following this steps:
399 const NamedGridAreaMap& map = parentStyle->namedGridArea(); 476 // * If there is a named grid area called <ident> resolve the position t o the area's corresponding edge.
477 // * If a grid area was found with that name, check that there is no <ident>-start or <ident>-end (depending
478 // on the css property being defined) specified before the grid area. If tha t's the case resolve to that grid line.
479 // * Otherwise check if there is a grid line named <ident>.
480 // * Otherwise treat it as auto.
400 481
401 #define CLEAR_UNKNOWN_NAMED_AREA(prop, Prop) \ 482 const NamedGridLinesMap& namedGridColumnLines = parentStyle->namedGridColumn Lines();
402 if (prop.isNamedGridArea() && !map.contains(prop.namedGridLine())) \ 483 const NamedGridLinesMap& namedGridRowLines = parentStyle->namedGridRowLines( );
403 style->setGrid##Prop(GridPosition()); 484 const NamedGridAreaMap& gridAreaMap = parentStyle->namedGridArea();
404 485
405 CLEAR_UNKNOWN_NAMED_AREA(columnStartPosition, ColumnStart); 486 #define ADJUST_GRID_POSITION_MAYBE(position, Prop, namedGridLines, side) \
406 CLEAR_UNKNOWN_NAMED_AREA(columnEndPosition, ColumnEnd); 487 if (position.isNamedGridArea()) { \
407 CLEAR_UNKNOWN_NAMED_AREA(rowStartPosition, RowStart); 488 OwnPtr<GridPosition> adjustedPosition = adjustNamedGridItemPosition(grid AreaMap, namedGridLines, position, side); \
408 CLEAR_UNKNOWN_NAMED_AREA(rowEndPosition, RowEnd); 489 if (adjustedPosition) \
490 style->setGrid##Prop(*adjustedPosition); \
491 }
492
493 ADJUST_GRID_POSITION_MAYBE(columnStartPosition, ColumnStart, namedGridColumn Lines, ColumnStartSide);
494 ADJUST_GRID_POSITION_MAYBE(columnEndPosition, ColumnEnd, namedGridColumnLine s, ColumnEndSide);
495 ADJUST_GRID_POSITION_MAYBE(rowStartPosition, RowStart, namedGridRowLines, Ro wStartSide);
496 ADJUST_GRID_POSITION_MAYBE(rowEndPosition, RowEnd, namedGridRowLines, RowEnd Side);
409 } 497 }
410 498
411 } 499 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleAdjuster.h ('k') | Source/core/css/resolver/StyleBuilderCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698