Chromium Code Reviews| Index: Source/core/rendering/style/GridResolvedPosition.h |
| diff --git a/Source/core/rendering/style/GridResolvedPosition.h b/Source/core/rendering/style/GridResolvedPosition.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8005337ad02a7edf8ec57c59bdb0e1bdd28dfd56 |
| --- /dev/null |
| +++ b/Source/core/rendering/style/GridResolvedPosition.h |
| @@ -0,0 +1,125 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GridResolvedPosition_h |
| +#define GridResolvedPosition_h |
| + |
| +#include "core/rendering/style/GridPosition.h" |
| + |
| +namespace WebCore { |
| + |
| +class GridSpan; |
| +class RenderBox; |
| +class RenderStyle; |
| + |
| +enum GridPositionSide { |
| + ColumnStartSide, |
| + ColumnEndSide, |
| + RowStartSide, |
| + RowEndSide |
| +}; |
| + |
| +enum GridTrackSizingDirection { |
| + ForColumns, |
| + ForRows |
| +}; |
| + |
|
Julien - ping for review
2014/03/21 23:49:27
Maybe worth adding a class comment that this is an
|
| +class GridResolvedPosition { |
| +public: |
| + static size_t adjustGridPositionForAfterEndSide(size_t resolvedPosition) |
| + { |
| + return resolvedPosition ? resolvedPosition - 1 : 0; |
| + } |
| + |
| + static size_t adjustGridPositionForSide(size_t resolvedPosition, GridPositionSide side) |
| + { |
| + // An item finishing on the N-th line belongs to the N-1-th cell. |
| + if (side == ColumnEndSide || side == RowEndSide) |
| + return adjustGridPositionForAfterEndSide(resolvedPosition); |
| + |
| + return resolvedPosition; |
| + } |
| + |
| + static GridSpan resolveGridPositionsFromAutoPlacementPosition(const RenderBox*, GridTrackSizingDirection, const GridResolvedPosition&); |
| + static PassOwnPtr<GridSpan> resolveGridPositionsFromStyle(const RenderStyle&, const RenderBox*, GridTrackSizingDirection); |
| + static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const RenderStyle&, const GridPosition&, GridPositionSide); |
| + static GridResolvedPosition resolveGridPositionFromStyle(const RenderStyle&, const GridPosition&, GridPositionSide); |
| + static PassOwnPtr<GridSpan> resolveGridPositionAgainstOppositePosition(const RenderStyle&, const GridResolvedPosition& resolvedOppositePosition, const GridPosition&, GridPositionSide); |
| + static PassOwnPtr<GridSpan> resolveNamedGridLinePositionAgainstOppositePosition(const RenderStyle&, const GridResolvedPosition& resolvedOppositePosition, const GridPosition&, GridPositionSide); |
| + |
| + GridResolvedPosition(size_t position) |
| + : m_integerPosition(position) |
| + { |
| + } |
| + |
| + GridResolvedPosition(const GridPosition& position, GridPositionSide side) |
| + { |
| + size_t integerPosition; |
|
Julien - ping for review
2014/03/21 23:49:27
No need to define this variable here. Better just
|
| + |
| + ASSERT(position.integerPosition()); |
| + integerPosition = position.integerPosition() - 1; |
| + |
| + m_integerPosition = adjustGridPositionForSide(integerPosition, side); |
| + } |
| + |
| + GridResolvedPosition next() const |
| + { |
| + return GridResolvedPosition(m_integerPosition + 1); |
| + } |
| + |
| + GridResolvedPosition& operator++() |
| + { |
| + m_integerPosition++; |
| + return *this; |
| + } |
| + |
| + GridResolvedPosition& operator=(const GridResolvedPosition& other) |
| + { |
| + m_integerPosition = other.m_integerPosition; |
| + return *this; |
| + } |
| + |
| + bool operator==(const GridResolvedPosition& other) const |
| + { |
| + return m_integerPosition == other.m_integerPosition; |
| + } |
| + |
| + bool operator<(const GridResolvedPosition& other) const |
| + { |
| + return m_integerPosition < other.m_integerPosition; |
| + } |
| + |
| + bool operator<=(const GridResolvedPosition& other) const |
| + { |
| + return m_integerPosition <= other.m_integerPosition; |
| + } |
| + |
| + bool operator<(size_t otherIntegerPosition) const |
| + { |
| + return m_integerPosition < otherIntegerPosition; |
| + } |
| + |
| + bool operator<=(size_t otherIntegerPosition) const |
| + { |
| + return m_integerPosition <= otherIntegerPosition; |
| + } |
| + |
| + operator size_t() const |
| + { |
| + return m_integerPosition; |
| + } |
| + |
| + static size_t explicitGridColumnCount(const RenderStyle&); |
| + static size_t explicitGridRowCount(const RenderStyle&); |
| + |
| +private: |
| + |
| + static size_t explicitGridSizeForSide(const RenderStyle&, GridPositionSide); |
| + |
| + size_t m_integerPosition; |
| +}; |
| + |
| +} // namespace WebCore |
| + |
| +#endif // GridResolvedPosition_h |