| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef GridCoordinate_h | 31 #ifndef GridCoordinate_h |
| 32 #define GridCoordinate_h | 32 #define GridCoordinate_h |
| 33 | 33 |
| 34 #include "core/rendering/style/GridPosition.h" | 34 #include "core/rendering/style/GridResolvedPosition.h" |
| 35 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
| 36 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 // A span in a single direction (either rows or columns). Note that |initialPosi
tionIndex| | 41 // A span in a single direction (either rows or columns). Note that |initialPosi
tionIndex| |
| 42 // and |finalPositionIndex| are grid areas' indexes, NOT grid lines'. Iterating
over the | 42 // and |finalPositionIndex| are grid areas' indexes, NOT grid lines'. Iterating
over the |
| 43 // span should include both |initialPositionIndex| and |finalPositionIndex| to b
e correct. | 43 // span should include both |initialPositionIndex| and |finalPositionIndex| to b
e correct. |
| 44 struct GridSpan { | 44 struct GridSpan { |
| 45 static PassOwnPtr<GridSpan> create(size_t initialPosition, size_t finalPosit
ion) | 45 static PassOwnPtr<GridSpan> create(const GridResolvedPosition& initialPositi
on, const GridResolvedPosition& finalPosition) |
| 46 { | 46 { |
| 47 return adoptPtr(new GridSpan(initialPosition, finalPosition)); | 47 return adoptPtr(new GridSpan(initialPosition, finalPosition)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 static PassOwnPtr<GridSpan> createWithSpanAgainstOpposite(size_t resolvedOpp
ositePosition, const GridPosition& position, GridPositionSide side) | 50 static PassOwnPtr<GridSpan> createWithSpanAgainstOpposite(const GridResolved
Position& resolvedOppositePosition, const GridPosition& position, GridPositionSi
de side) |
| 51 { | 51 { |
| 52 // 'span 1' is contained inside a single grid track regardless of the di
rection. | 52 // 'span 1' is contained inside a single grid track regardless of the di
rection. |
| 53 // That's why the CSS span value is one more than the offset we apply. | 53 // That's why the CSS span value is one more than the offset we apply. |
| 54 size_t positionOffset = position.spanPosition() - 1; | 54 size_t positionOffset = position.spanPosition() - 1; |
| 55 if (side == ColumnStartSide || side == RowStartSide) { | 55 if (side == ColumnStartSide || side == RowStartSide) { |
| 56 size_t initialResolvedPosition = std::max<int>(0, resolvedOppositePo
sition - positionOffset); | 56 GridResolvedPosition initialResolvedPosition = GridResolvedPosition(
std::max<int>(0, resolvedOppositePosition.integerPosition() - positionOffset)); |
| 57 return GridSpan::create(initialResolvedPosition, resolvedOppositePos
ition); | 57 return GridSpan::create(initialResolvedPosition, resolvedOppositePos
ition); |
| 58 } | 58 } |
| 59 | 59 |
| 60 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on + positionOffset); | 60 return GridSpan::create(resolvedOppositePosition, GridResolvedPosition(r
esolvedOppositePosition.integerPosition() + positionOffset)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 static PassOwnPtr<GridSpan> createWithNamedSpanAgainstOpposite(size_t resolv
edOppositePosition, const GridPosition& position, GridPositionSide side, const V
ector<size_t>& gridLines) | 63 static PassOwnPtr<GridSpan> createWithNamedSpanAgainstOpposite(const GridRes
olvedPosition& resolvedOppositePosition, const GridPosition& position, GridPosit
ionSide side, const Vector<size_t>& gridLines) |
| 64 { | 64 { |
| 65 if (side == RowStartSide || side == ColumnStartSide) | 65 if (side == RowStartSide || side == ColumnStartSide) |
| 66 return createWithInitialNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); | 66 return createWithInitialNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); |
| 67 | 67 |
| 68 return createWithFinalNamedSpanAgainstOpposite(resolvedOppositePosition,
position, gridLines); | 68 return createWithFinalNamedSpanAgainstOpposite(resolvedOppositePosition,
position, gridLines); |
| 69 } | 69 } |
| 70 | 70 |
| 71 static PassOwnPtr<GridSpan> createWithInitialNamedSpanAgainstOpposite(size_t
resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& g
ridLines) | 71 static PassOwnPtr<GridSpan> createWithInitialNamedSpanAgainstOpposite(const
GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, co
nst Vector<size_t>& gridLines) |
| 72 { | 72 { |
| 73 // The grid line inequality needs to be strict (which doesn't match the
after / end case) because |resolvedOppositePosition| | 73 // The grid line inequality needs to be strict (which doesn't match the
after / end case) because |resolvedOppositePosition| |
| 74 // is already converted to an index in our grid representation (ie one w
as removed from the grid line to account for the side). | 74 // is already converted to an index in our grid representation (ie one w
as removed from the grid line to account for the side). |
| 75 size_t firstLineBeforeOppositePositionIndex = 0; | 75 size_t firstLineBeforeOppositePositionIndex = 0; |
| 76 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLin
es.begin(), gridLines.end(), resolvedOppositePosition); | 76 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLin
es.begin(), gridLines.end(), resolvedOppositePosition.integerPosition()); |
| 77 if (firstLineBeforeOppositePosition != gridLines.end()) | 77 if (firstLineBeforeOppositePosition != gridLines.end()) |
| 78 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePositi
on - gridLines.begin(); | 78 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePositi
on - gridLines.begin(); |
| 79 | 79 |
| 80 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionI
ndex - position.spanPosition() + 1); | 80 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionI
ndex - position.spanPosition() + 1); |
| 81 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; | 81 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; |
| 82 if (resolvedGridLinePosition > resolvedOppositePosition) | 82 if (resolvedGridLinePosition > resolvedOppositePosition.integerPosition(
)) |
| 83 resolvedGridLinePosition = resolvedOppositePosition; | 83 resolvedGridLinePosition = resolvedOppositePosition.integerPosition(
); |
| 84 return GridSpan::create(resolvedGridLinePosition, resolvedOppositePositi
on); | 84 return GridSpan::create(GridResolvedPosition(resolvedGridLinePosition),
resolvedOppositePosition); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static PassOwnPtr<GridSpan> createWithFinalNamedSpanAgainstOpposite(size_t r
esolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gri
dLines) | 87 static PassOwnPtr<GridSpan> createWithFinalNamedSpanAgainstOpposite(const Gr
idResolvedPosition& resolvedOppositePosition, const GridPosition& position, cons
t Vector<size_t>& gridLines) |
| 88 { | 88 { |
| 89 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; | 89 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; |
| 90 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLine
s.begin(), gridLines.end(), resolvedOppositePosition); | 90 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLine
s.begin(), gridLines.end(), resolvedOppositePosition.integerPosition()); |
| 91 if (firstLineAfterOppositePosition != gridLines.end()) | 91 if (firstLineAfterOppositePosition != gridLines.end()) |
| 92 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition
- gridLines.begin(); | 92 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition
- gridLines.begin(); |
| 93 | 93 |
| 94 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppo
sitePositionIndex + position.spanPosition() - 1); | 94 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppo
sitePositionIndex + position.spanPosition() - 1); |
| 95 size_t resolvedGridLinePosition = GridPosition::adjustGridPositionForAft
erEndSide(gridLines[gridLineIndex]); | 95 size_t resolvedGridLinePositionInteger = GridResolvedPosition::adjustGri
dPositionForAfterEndSide(gridLines[gridLineIndex]); |
| 96 GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(res
olvedGridLinePositionInteger); |
| 96 if (resolvedGridLinePosition < resolvedOppositePosition) | 97 if (resolvedGridLinePosition < resolvedOppositePosition) |
| 97 resolvedGridLinePosition = resolvedOppositePosition; | 98 resolvedGridLinePosition.setIntegerPosition(resolvedOppositePosition
.integerPosition()); |
| 98 return GridSpan::create(resolvedOppositePosition, resolvedGridLinePositi
on); | 99 return GridSpan::create(resolvedOppositePosition, resolvedGridLinePositi
on); |
| 99 } | 100 } |
| 100 | 101 |
| 101 GridSpan(size_t initialPosition, size_t finalPosition) | 102 GridSpan(const GridResolvedPosition& initialPosition, const GridResolvedPosi
tion& finalPosition) |
| 102 : initialPositionIndex(initialPosition) | 103 : initialPositionIndex(initialPosition) |
| 103 , finalPositionIndex(finalPosition) | 104 , finalPositionIndex(finalPosition) |
| 104 { | 105 { |
| 105 ASSERT(initialPositionIndex <= finalPositionIndex); | 106 ASSERT(initialPositionIndex <= finalPositionIndex); |
| 106 } | 107 } |
| 107 | 108 |
| 108 bool operator==(const GridSpan& o) const | 109 bool operator==(const GridSpan& o) const |
| 109 { | 110 { |
| 110 return initialPositionIndex == o.initialPositionIndex && finalPositionIn
dex == o.finalPositionIndex; | 111 return initialPositionIndex == o.initialPositionIndex && finalPositionIn
dex == o.finalPositionIndex; |
| 111 } | 112 } |
| 112 | 113 |
| 113 size_t initialPositionIndex; | 114 GridResolvedPosition initialPositionIndex; |
| 114 size_t finalPositionIndex; | 115 GridResolvedPosition finalPositionIndex; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 // This represents a grid area that spans in both rows' and columns' direction. | 118 // This represents a grid area that spans in both rows' and columns' direction. |
| 118 struct GridCoordinate { | 119 struct GridCoordinate { |
| 119 // HashMap requires a default constuctor. | 120 // HashMap requires a default constuctor. |
| 120 GridCoordinate() | 121 GridCoordinate() |
| 121 : columns(0, 0) | 122 : columns(0, 0) |
| 122 , rows(0, 0) | 123 , rows(0, 0) |
| 123 { | 124 { |
| 124 } | 125 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 141 | 142 |
| 142 GridSpan columns; | 143 GridSpan columns; |
| 143 GridSpan rows; | 144 GridSpan rows; |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; | 147 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; |
| 147 | 148 |
| 148 } // namespace WebCore | 149 } // namespace WebCore |
| 149 | 150 |
| 150 #endif // GridCoordinate_h | 151 #endif // GridCoordinate_h |
| OLD | NEW |