| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // Recommended maximum size for both explicit and implicit grids. | 43 // Recommended maximum size for both explicit and implicit grids. |
| 44 const size_t kGridMaxTracks = 1000000; | 44 const size_t kGridMaxTracks = 1000000; |
| 45 | 45 |
| 46 // A span in a single direction (either rows or columns). Note that |resolvedIni
tialPosition| | 46 // A span in a single direction (either rows or columns). Note that |resolvedIni
tialPosition| |
| 47 // and |resolvedFinalPosition| are grid areas' indexes, NOT grid lines'. Iterati
ng over the | 47 // and |resolvedFinalPosition| are grid areas' indexes, NOT grid lines'. Iterati
ng over the |
| 48 // span should include both |resolvedInitialPosition| and |resolvedFinalPosition
| to be correct. | 48 // span should include both |resolvedInitialPosition| and |resolvedFinalPosition
| to be correct. |
| 49 struct GridSpan { | 49 struct GridSpan { |
| 50 USING_FAST_MALLOC(GridSpan); | 50 USING_FAST_MALLOC(GridSpan); |
| 51 public: | 51 public: |
| 52 static PassOwnPtr<GridSpan> create(const GridResolvedPosition& resolvedIniti
alPosition, const GridResolvedPosition& resolvedFinalPosition) | |
| 53 { | |
| 54 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosit
ion)); | |
| 55 } | |
| 56 | |
| 57 static PassOwnPtr<GridSpan> createWithSpanAgainstOpposite(const GridResolved
Position& resolvedOppositePosition, const GridPosition& position, GridPositionSi
de side) | |
| 58 { | |
| 59 // 'span 1' is contained inside a single grid track regardless of the di
rection. | |
| 60 // That's why the CSS span value is one more than the offset we apply. | |
| 61 size_t positionOffset = position.spanPosition() - 1; | |
| 62 if (side == ColumnStartSide || side == RowStartSide) { | |
| 63 GridResolvedPosition initialResolvedPosition = GridResolvedPosition(
std::max<int>(0, resolvedOppositePosition.toInt() - positionOffset)); | |
| 64 return GridSpan::create(initialResolvedPosition, resolvedOppositePos
ition); | |
| 65 } | |
| 66 | |
| 67 return GridSpan::create(resolvedOppositePosition, GridResolvedPosition(r
esolvedOppositePosition.toInt() + positionOffset)); | |
| 68 } | |
| 69 | |
| 70 static PassOwnPtr<GridSpan> createWithNamedSpanAgainstOpposite(const GridRes
olvedPosition& resolvedOppositePosition, const GridPosition& position, GridPosit
ionSide side, const Vector<size_t>& gridLines) | |
| 71 { | |
| 72 if (side == RowStartSide || side == ColumnStartSide) | |
| 73 return createWithInitialNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); | |
| 74 | |
| 75 return createWithFinalNamedSpanAgainstOpposite(resolvedOppositePosition,
position, gridLines); | |
| 76 } | |
| 77 | |
| 78 static PassOwnPtr<GridSpan> createWithInitialNamedSpanAgainstOpposite(const
GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, co
nst Vector<size_t>& gridLines) | |
| 79 { | |
| 80 // The grid line inequality needs to be strict (which doesn't match the
after / end case) because |resolvedOppositePosition| | |
| 81 // is already converted to an index in our grid representation (ie one w
as removed from the grid line to account for the side). | |
| 82 size_t firstLineBeforeOppositePositionIndex = 0; | |
| 83 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLin
es.begin(), gridLines.end(), resolvedOppositePosition.toInt()); | |
| 84 if (firstLineBeforeOppositePosition != gridLines.end()) { | |
| 85 if (*firstLineBeforeOppositePosition > resolvedOppositePosition.toIn
t() && firstLineBeforeOppositePosition != gridLines.begin()) | |
| 86 --firstLineBeforeOppositePosition; | |
| 87 | |
| 88 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePositi
on - gridLines.begin(); | |
| 89 } | |
| 90 | |
| 91 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionI
ndex - position.spanPosition() + 1); | |
| 92 GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(gri
dLines[gridLineIndex]); | |
| 93 if (resolvedGridLinePosition > resolvedOppositePosition) | |
| 94 resolvedGridLinePosition = resolvedOppositePosition; | |
| 95 return GridSpan::create(resolvedGridLinePosition, resolvedOppositePositi
on); | |
| 96 } | |
| 97 | |
| 98 static PassOwnPtr<GridSpan> createWithFinalNamedSpanAgainstOpposite(const Gr
idResolvedPosition& resolvedOppositePosition, const GridPosition& position, cons
t Vector<size_t>& gridLines) | |
| 99 { | |
| 100 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; | |
| 101 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLine
s.begin(), gridLines.end(), resolvedOppositePosition.toInt()); | |
| 102 if (firstLineAfterOppositePosition != gridLines.end()) | |
| 103 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition
- gridLines.begin(); | |
| 104 | |
| 105 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppo
sitePositionIndex + position.spanPosition() - 1); | |
| 106 GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition::ad
justGridPositionForAfterEndSide(gridLines[gridLineIndex]); | |
| 107 if (resolvedGridLinePosition < resolvedOppositePosition) | |
| 108 resolvedGridLinePosition = resolvedOppositePosition; | |
| 109 return GridSpan::create(resolvedOppositePosition, resolvedGridLinePositi
on); | |
| 110 } | |
| 111 | 52 |
| 112 GridSpan(const GridResolvedPosition& resolvedInitialPosition, const GridReso
lvedPosition& resolvedFinalPosition) | 53 GridSpan(const GridResolvedPosition& resolvedInitialPosition, const GridReso
lvedPosition& resolvedFinalPosition) |
| 113 : resolvedInitialPosition(std::min(resolvedInitialPosition.toInt(), kGri
dMaxTracks - 1)) | 54 : resolvedInitialPosition(std::min(resolvedInitialPosition.toInt(), kGri
dMaxTracks - 1)) |
| 114 , resolvedFinalPosition(std::min(resolvedFinalPosition.toInt(), kGridMax
Tracks)) | 55 , resolvedFinalPosition(std::min(resolvedFinalPosition.toInt(), kGridMax
Tracks)) |
| 115 { | 56 { |
| 116 ASSERT(resolvedInitialPosition <= resolvedFinalPosition); | 57 ASSERT(resolvedInitialPosition <= resolvedFinalPosition); |
| 117 } | 58 } |
| 118 | 59 |
| 119 bool operator==(const GridSpan& o) const | 60 bool operator==(const GridSpan& o) const |
| 120 { | 61 { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 128 |
| 188 GridSpan columns; | 129 GridSpan columns; |
| 189 GridSpan rows; | 130 GridSpan rows; |
| 190 }; | 131 }; |
| 191 | 132 |
| 192 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; | 133 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; |
| 193 | 134 |
| 194 } // namespace blink | 135 } // namespace blink |
| 195 | 136 |
| 196 #endif // GridCoordinate_h | 137 #endif // GridCoordinate_h |
| OLD | NEW |