OLD | NEW |
---|---|
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 28 matching lines...) Expand all Loading... | |
39 #include "core/html/HTMLTextAreaElement.h" | 39 #include "core/html/HTMLTextAreaElement.h" |
40 #include "core/frame/FrameView.h" | 40 #include "core/frame/FrameView.h" |
41 #include "core/frame/Settings.h" | 41 #include "core/frame/Settings.h" |
42 #include "core/rendering/Pagination.h" | 42 #include "core/rendering/Pagination.h" |
43 #include "core/rendering/RenderTheme.h" | 43 #include "core/rendering/RenderTheme.h" |
44 #include "core/rendering/style/GridPosition.h" | 44 #include "core/rendering/style/GridPosition.h" |
45 #include "core/rendering/style/RenderStyle.h" | 45 #include "core/rendering/style/RenderStyle.h" |
46 #include "core/rendering/style/RenderStyleConstants.h" | 46 #include "core/rendering/style/RenderStyleConstants.h" |
47 #include "platform/Length.h" | 47 #include "platform/Length.h" |
48 #include "wtf/Assertions.h" | 48 #include "wtf/Assertions.h" |
49 #include "wtf/text/StringBuilder.h" | |
49 | 50 |
50 namespace WebCore { | 51 namespace WebCore { |
51 | 52 |
52 using namespace HTMLNames; | 53 using namespace HTMLNames; |
53 | 54 |
54 // FIXME: This is duplicated with StyleResolver.cpp | 55 // FIXME: This is duplicated with StyleResolver.cpp |
55 // Perhaps this should move onto ElementResolveContext or even Element? | 56 // Perhaps this should move onto ElementResolveContext or even Element? |
56 static inline bool isAtShadowBoundary(const Element* element) | 57 static inline bool isAtShadowBoundary(const Element* element) |
57 { | 58 { |
58 if (!element) | 59 if (!element) |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 // not be scaled again. | 379 // not be scaled again. |
379 if (e->hasTagName(SVGNames::foreignObjectTag)) | 380 if (e->hasTagName(SVGNames::foreignObjectTag)) |
380 style->setEffectiveZoom(RenderStyle::initialZoom()); | 381 style->setEffectiveZoom(RenderStyle::initialZoom()); |
381 | 382 |
382 // SVG text layout code expects us to be a block-level style element. | 383 // SVG text layout code expects us to be a block-level style element. |
383 if ((e->hasTagName(SVGNames::foreignObjectTag) || e->hasTagName(SVGNames ::textTag)) && style->isDisplayInlineType()) | 384 if ((e->hasTagName(SVGNames::foreignObjectTag) || e->hasTagName(SVGNames ::textTag)) && style->isDisplayInlineType()) |
384 style->setDisplay(BLOCK); | 385 style->setDisplay(BLOCK); |
385 } | 386 } |
386 } | 387 } |
387 | 388 |
389 static inline bool gridLineDefinedBeforeGridArea(const String& gridLineName, con st String& gridAreaName, const NamedGridAreaMap& gridAreaMap, const NamedGridLin esMap& namedLinesMap, GridPositionSide side) | |
390 { | |
391 ASSERT(namedLinesMap.contains(gridLineName)); | |
392 // Grid line indexes are inserted in order. | |
393 size_t namedGridLineFirstDefinitionIndex = namedLinesMap.get(gridLineName)[0 ]; | |
394 | |
395 ASSERT(gridAreaMap.contains(gridAreaName)); | |
396 const GridCoordinate gridAreaCoordinates = gridAreaMap.get(gridAreaName); | |
Julien - ping for review
2014/02/12 21:55:31
It should be a reference, we don't need a copy her
svillar
2014/02/13 10:13:39
yep
| |
397 | |
398 // GridCoordinate refers to tracks while the indexes in namedLinesMap refer to lines, that's why we need to add 1 to | |
399 // the grid coordinate to get the end line index. | |
Julien - ping for review
2014/02/12 21:55:31
We have a helper function that does something very
svillar
2014/02/13 10:13:39
Oh indeed, I forgot about that
| |
400 switch (side) { | |
401 case ColumnStartSide: | |
402 return namedGridLineFirstDefinitionIndex < gridAreaCoordinates.columns.i nitialPositionIndex; | |
403 case ColumnEndSide: | |
404 return namedGridLineFirstDefinitionIndex < gridAreaCoordinates.columns.f inalPositionIndex + 1; | |
405 case RowStartSide: | |
406 return namedGridLineFirstDefinitionIndex < gridAreaCoordinates.rows.init ialPositionIndex; | |
407 case RowEndSide: | |
408 return namedGridLineFirstDefinitionIndex < gridAreaCoordinates.rows.fina lPositionIndex + 1; | |
409 default: | |
410 ASSERT_NOT_REACHED(); | |
411 return false; | |
412 } | |
413 } | |
414 | |
415 PassOwnPtr<GridPosition> StyleAdjuster::adjustNamedGridItemPosition(const NamedG ridAreaMap& gridAreaMap, const NamedGridLinesMap& namedLinesMap, const GridPosit ion& position, GridPositionSide side) const | |
416 { | |
417 ASSERT(position.isNamedGridArea()); | |
418 // The StyleBuilder always treats <ident> as a named grid area. We must deci de here if they are going to be resolved | |
Julien - ping for review
2014/02/12 21:55:31
<ident> is not <custom-ident> so let's try to matc
| |
419 // to either a grid area or a grid line. | |
420 OwnPtr<GridPosition> adjustedPosition; | |
Julien - ping for review
2014/02/12 21:55:31
I don't understand why we use OwnPtr here instead
svillar
2014/02/28 17:37:13
Note that I need to use a pointer here, because th
| |
421 | |
422 String namedGridAreaOrGridLine = position.namedGridLine(); | |
423 const bool hasStartSuffix = namedGridAreaOrGridLine.endsWith("-start"); | |
424 const bool hasEndSuffix = namedGridAreaOrGridLine.endsWith("-end"); | |
Julien - ping for review
2014/02/12 21:55:31
I don't think this logic is right. We are asked to
svillar
2014/02/13 10:13:39
Which specific logic do you think is wrong? I'm us
Julien - ping for review
2014/02/13 19:32:01
The way you handle the named grid line doesn't fol
svillar
2014/02/24 16:44:31
I think the code works like the algorithm above bu
| |
425 const bool isStartSide = side == ColumnStartSide || side == RowStartSide; | |
426 const bool hasStartSuffixForStartSide = hasStartSuffix && isStartSide; | |
427 const bool hasEndSuffixForEndSide = hasEndSuffix && !isStartSide; | |
428 const size_t suffixLength = hasStartSuffix ? strlen("-start") : strlen("-end "); | |
429 String gridAreaName = hasStartSuffixForStartSide || hasEndSuffixForEndSide ? namedGridAreaOrGridLine.substring(0, namedGridAreaOrGridLine.length() - suffixL ength) : namedGridAreaOrGridLine; | |
430 | |
431 if (gridAreaMap.contains(gridAreaName)) { | |
Julien - ping for review
2014/02/13 19:32:01
Tab pointed out that in the new specification, nam
svillar
2014/02/24 16:44:31
That's right, I wonder how that would affect the a
| |
432 StringBuilder gridLineNameBuilder; | |
433 gridLineNameBuilder.append(namedGridAreaOrGridLine); | |
434 if (isStartSide && !hasStartSuffix) | |
435 gridLineNameBuilder.append("-start"); | |
436 else if (!isStartSide && !hasEndSuffix) | |
437 gridLineNameBuilder.append("-end"); | |
438 | |
439 String gridLineName = gridLineNameBuilder.toString(); | |
440 if (namedLinesMap.contains(gridLineName) && gridLineDefinedBeforeGridAre a(gridLineName, gridAreaName, gridAreaMap, namedLinesMap, side)) { | |
441 // Use the explicitly defined grid line defined before the grid area instead of the grid area. | |
442 adjustedPosition = adoptPtr(new GridPosition()); | |
443 adjustedPosition->setExplicitPosition(1, gridLineName); | |
444 } else if (hasStartSuffixForStartSide || hasEndSuffixForEndSide) { | |
445 // Renderer expects the grid area name instead of the implicit grid line name. | |
446 adjustedPosition = adoptPtr(new GridPosition()); | |
447 adjustedPosition->setNamedGridArea(gridAreaName); | |
448 } | |
449 | |
450 return adjustedPosition.release(); | |
451 } | |
452 | |
453 if (namedLinesMap.contains(namedGridAreaOrGridLine)) { | |
454 adjustedPosition = adoptPtr(new GridPosition()); | |
455 adjustedPosition->setExplicitPosition(1, namedGridAreaOrGridLine); | |
456 return adjustedPosition.release(); | |
457 } | |
458 | |
459 return adoptPtr(new GridPosition()); | |
460 } | |
461 | |
388 void StyleAdjuster::adjustGridItemPosition(RenderStyle* style, RenderStyle* pare ntStyle) const | 462 void StyleAdjuster::adjustGridItemPosition(RenderStyle* style, RenderStyle* pare ntStyle) const |
389 { | 463 { |
390 const GridPosition& columnStartPosition = style->gridColumnStart(); | 464 const GridPosition& columnStartPosition = style->gridColumnStart(); |
391 const GridPosition& columnEndPosition = style->gridColumnEnd(); | 465 const GridPosition& columnEndPosition = style->gridColumnEnd(); |
392 const GridPosition& rowStartPosition = style->gridRowStart(); | 466 const GridPosition& rowStartPosition = style->gridRowStart(); |
393 const GridPosition& rowEndPosition = style->gridRowEnd(); | 467 const GridPosition& rowEndPosition = style->gridRowEnd(); |
394 | 468 |
395 // If opposing grid-placement properties both specify a grid span, they both compute to ‘auto’. | 469 // If opposing grid-placement properties both specify a grid span, they both compute to ‘auto’. |
396 if (columnStartPosition.isSpan() && columnEndPosition.isSpan()) { | 470 if (columnStartPosition.isSpan() && columnEndPosition.isSpan()) { |
397 style->setGridColumnStart(GridPosition()); | 471 style->setGridColumnStart(GridPosition()); |
398 style->setGridColumnEnd(GridPosition()); | 472 style->setGridColumnEnd(GridPosition()); |
399 } | 473 } |
400 | 474 |
401 if (rowStartPosition.isSpan() && rowEndPosition.isSpan()) { | 475 if (rowStartPosition.isSpan() && rowEndPosition.isSpan()) { |
402 style->setGridRowStart(GridPosition()); | 476 style->setGridRowStart(GridPosition()); |
403 style->setGridRowEnd(GridPosition()); | 477 style->setGridRowEnd(GridPosition()); |
404 } | 478 } |
405 | 479 |
406 // Unknown named grid area compute to 'auto'. | 480 // If the grid position is a single <ident> then the spec mandates us to res olve it following this steps: |
407 const NamedGridAreaMap& map = parentStyle->namedGridArea(); | 481 // * If there is a named grid area called <ident> resolve the position t o the area's corresponding edge. |
482 // * If a grid area was found with that name, check that there is no <ident>-start or <ident>-end (depending | |
483 // on the css property being defined) specified before the grid area. If tha t's the case resolve to that grid line. | |
484 // * Otherwise check if there is a grid line named <ident>. | |
485 // * Otherwise treat it as auto. | |
408 | 486 |
409 #define CLEAR_UNKNOWN_NAMED_AREA(prop, Prop) \ | 487 const NamedGridLinesMap& namedGridColumnLines = parentStyle->namedGridColumn Lines(); |
410 if (prop.isNamedGridArea() && !map.contains(prop.namedGridLine())) \ | 488 const NamedGridLinesMap& namedGridRowLines = parentStyle->namedGridRowLines( ); |
411 style->setGrid##Prop(GridPosition()); | 489 const NamedGridAreaMap& gridAreaMap = parentStyle->namedGridArea(); |
412 | 490 |
413 CLEAR_UNKNOWN_NAMED_AREA(columnStartPosition, ColumnStart); | 491 #define ADJUST_GRID_POSITION_MAYBE(position, Prop, namedGridLines, side) \ |
414 CLEAR_UNKNOWN_NAMED_AREA(columnEndPosition, ColumnEnd); | 492 if (position.isNamedGridArea()) { \ |
415 CLEAR_UNKNOWN_NAMED_AREA(rowStartPosition, RowStart); | 493 OwnPtr<GridPosition> adjustedPosition = adjustNamedGridItemPosition(grid AreaMap, namedGridLines, position, side); \ |
416 CLEAR_UNKNOWN_NAMED_AREA(rowEndPosition, RowEnd); | 494 if (adjustedPosition) \ |
495 style->setGrid##Prop(*adjustedPosition); \ | |
496 } | |
497 | |
498 ADJUST_GRID_POSITION_MAYBE(columnStartPosition, ColumnStart, namedGridColumn Lines, ColumnStartSide); | |
499 ADJUST_GRID_POSITION_MAYBE(columnEndPosition, ColumnEnd, namedGridColumnLine s, ColumnEndSide); | |
500 ADJUST_GRID_POSITION_MAYBE(rowStartPosition, RowStart, namedGridRowLines, Ro wStartSide); | |
501 ADJUST_GRID_POSITION_MAYBE(rowEndPosition, RowEnd, namedGridRowLines, RowEnd Side); | |
417 } | 502 } |
418 | 503 |
419 } | 504 } |
OLD | NEW |