| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef LayoutGrid_h | 26 #ifndef LayoutGrid_h |
| 27 #define LayoutGrid_h | 27 #define LayoutGrid_h |
| 28 | 28 |
| 29 #include <memory> |
| 30 #include "core/layout/BaselineAlignment.h" |
| 29 #include "core/layout/Grid.h" | 31 #include "core/layout/Grid.h" |
| 30 #include "core/layout/GridTrackSizingAlgorithm.h" | 32 #include "core/layout/GridTrackSizingAlgorithm.h" |
| 31 #include "core/layout/LayoutBlock.h" | 33 #include "core/layout/LayoutBlock.h" |
| 32 #include "core/layout/OrderIterator.h" | 34 #include "core/layout/OrderIterator.h" |
| 33 #include "core/style/GridPositionsResolver.h" | 35 #include "core/style/GridPositionsResolver.h" |
| 34 #include <memory> | |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 struct ContentAlignmentData; | 39 struct ContentAlignmentData; |
| 39 struct GridArea; | 40 struct GridArea; |
| 40 struct GridSpan; | 41 struct GridSpan; |
| 41 | 42 |
| 42 enum GridAxisPosition { GridAxisStart, GridAxisEnd, GridAxisCenter }; | 43 enum GridAxisPosition { GridAxisStart, GridAxisEnd, GridAxisCenter }; |
| 44 enum GridAxis { GridRowAxis, GridColumnAxis }; |
| 43 | 45 |
| 44 class LayoutGrid final : public LayoutBlock { | 46 class LayoutGrid final : public LayoutBlock { |
| 45 public: | 47 public: |
| 46 explicit LayoutGrid(Element*); | 48 explicit LayoutGrid(Element*); |
| 47 ~LayoutGrid() override; | 49 ~LayoutGrid() override; |
| 48 | 50 |
| 49 static LayoutGrid* createAnonymous(Document*); | 51 static LayoutGrid* createAnonymous(Document*); |
| 50 const char* name() const override { return "LayoutGrid"; } | 52 const char* name() const override { return "LayoutGrid"; } |
| 51 | 53 |
| 52 void layoutBlock(bool relayoutChildren) override; | 54 void layoutBlock(bool relayoutChildren) override; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 90 |
| 89 // TODO(svillar): We need these for the GridTrackSizingAlgorithm. Let's figure | 91 // TODO(svillar): We need these for the GridTrackSizingAlgorithm. Let's figure |
| 90 // it out how to remove this dependency. | 92 // it out how to remove this dependency. |
| 91 LayoutUnit guttersSize(const Grid&, | 93 LayoutUnit guttersSize(const Grid&, |
| 92 GridTrackSizingDirection, | 94 GridTrackSizingDirection, |
| 93 size_t startLine, | 95 size_t startLine, |
| 94 size_t span, | 96 size_t span, |
| 95 SizingOperation) const; | 97 SizingOperation) const; |
| 96 bool cachedHasDefiniteLogicalHeight() const; | 98 bool cachedHasDefiniteLogicalHeight() const; |
| 97 bool isOrthogonalChild(const LayoutBox&) const; | 99 bool isOrthogonalChild(const LayoutBox&) const; |
| 100 bool isBaselineContextComputed(GridAxis) const; |
| 101 bool isBaselineAlignmentForChild(const LayoutBox&, |
| 102 GridAxis = GridColumnAxis) const; |
| 103 const BaselineGroup& getBaselineGroupForChild(const LayoutBox&, |
| 104 GridAxis) const; |
| 98 | 105 |
| 99 protected: | 106 protected: |
| 100 ItemPosition selfAlignmentNormalBehavior( | 107 ItemPosition selfAlignmentNormalBehavior( |
| 101 const LayoutBox* child = nullptr) const override { | 108 const LayoutBox* child = nullptr) const override { |
| 102 DCHECK(child); | 109 DCHECK(child); |
| 103 return child->isLayoutReplaced() ? ItemPositionStart : ItemPositionStretch; | 110 return child->isLayoutReplaced() ? ItemPositionStart : ItemPositionStretch; |
| 104 } | 111 } |
| 105 | 112 |
| 106 private: | 113 private: |
| 107 bool isOfType(LayoutObjectType type) const override { | 114 bool isOfType(LayoutObjectType type) const override { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 void updateAutoMarginsInColumnAxisIfNeeded(LayoutBox&); | 230 void updateAutoMarginsInColumnAxisIfNeeded(LayoutBox&); |
| 224 void updateAutoMarginsInRowAxisIfNeeded(LayoutBox&); | 231 void updateAutoMarginsInRowAxisIfNeeded(LayoutBox&); |
| 225 | 232 |
| 226 int baselinePosition( | 233 int baselinePosition( |
| 227 FontBaseline, | 234 FontBaseline, |
| 228 bool firstLine, | 235 bool firstLine, |
| 229 LineDirectionMode, | 236 LineDirectionMode, |
| 230 LinePositionMode = PositionOnContainingLine) const override; | 237 LinePositionMode = PositionOnContainingLine) const override; |
| 231 int firstLineBoxBaseline() const override; | 238 int firstLineBoxBaseline() const override; |
| 232 int inlineBlockBaseline(LineDirectionMode) const override; | 239 int inlineBlockBaseline(LineDirectionMode) const override; |
| 233 bool isInlineBaselineAlignedChild(const LayoutBox* child) const; | 240 |
| 241 bool isHorizontalGridAxis(GridAxis) const; |
| 242 bool isParallelToBlockAxisForChild(const LayoutBox&, GridAxis) const; |
| 243 bool isDescentBaselineForChild(const LayoutBox&, GridAxis) const; |
| 244 |
| 245 LayoutUnit marginOverForChild(const LayoutBox&, GridAxis) const; |
| 246 LayoutUnit logicalAscentForChild(const LayoutBox&, GridAxis) const; |
| 247 LayoutUnit ascentForChild(const LayoutBox&, GridAxis) const; |
| 248 LayoutUnit descentForChild(const LayoutBox&, |
| 249 LayoutUnit ascent, |
| 250 GridAxis) const; |
| 251 |
| 252 bool baselineMayAffectIntrinsicWidth() const; |
| 253 bool baselineMayAffectIntrinsicHeight() const; |
| 254 void computeBaselineAlignmentContext(); |
| 255 void updateBaselineAlignmentContextIfNeeded(LayoutBox&, GridAxis); |
| 256 |
| 257 LayoutUnit columnAxisBaselineOffsetForChild(const LayoutBox&) const; |
| 258 LayoutUnit rowAxisBaselineOffsetForChild(const LayoutBox&) const; |
| 234 | 259 |
| 235 LayoutUnit gridGapForDirection(GridTrackSizingDirection, | 260 LayoutUnit gridGapForDirection(GridTrackSizingDirection, |
| 236 SizingOperation) const; | 261 SizingOperation) const; |
| 237 | 262 |
| 238 size_t gridItemSpan(const LayoutBox&, GridTrackSizingDirection); | 263 size_t gridItemSpan(const LayoutBox&, GridTrackSizingDirection); |
| 239 | 264 |
| 240 GridTrackSizingDirection flowAwareDirectionForChild( | 265 GridTrackSizingDirection flowAwareDirectionForChild( |
| 241 const LayoutBox&, | 266 const LayoutBox&, |
| 242 GridTrackSizingDirection) const; | 267 GridTrackSizingDirection) const; |
| 243 | 268 |
| 244 size_t numTracks(GridTrackSizingDirection, const Grid&) const; | 269 size_t numTracks(GridTrackSizingDirection, const Grid&) const; |
| 245 | 270 |
| 271 typedef HashMap<unsigned, |
| 272 std::unique_ptr<BaselineContext>, |
| 273 DefaultHash<unsigned>::Hash, |
| 274 WTF::UnsignedWithZeroKeyHashTraits<unsigned>> |
| 275 BaselineContextsMap; |
| 276 |
| 277 BaselineContextsMap m_rowAxisAlignmentContext; |
| 278 BaselineContextsMap m_colAxisAlignmentContext; |
| 279 |
| 246 Grid m_grid; | 280 Grid m_grid; |
| 247 GridTrackSizingAlgorithm m_trackSizingAlgorithm; | 281 GridTrackSizingAlgorithm m_trackSizingAlgorithm; |
| 248 | 282 |
| 249 Vector<LayoutUnit> m_rowPositions; | 283 Vector<LayoutUnit> m_rowPositions; |
| 250 Vector<LayoutUnit> m_columnPositions; | 284 Vector<LayoutUnit> m_columnPositions; |
| 251 LayoutUnit m_offsetBetweenColumns; | 285 LayoutUnit m_offsetBetweenColumns; |
| 252 LayoutUnit m_offsetBetweenRows; | 286 LayoutUnit m_offsetBetweenRows; |
| 253 Vector<LayoutBox*> m_gridItemsOverflowingGridArea; | 287 Vector<LayoutBox*> m_gridItemsOverflowingGridArea; |
| 254 | 288 |
| 255 LayoutUnit m_minContentHeight{-1}; | 289 LayoutUnit m_minContentHeight{-1}; |
| 256 LayoutUnit m_maxContentHeight{-1}; | 290 LayoutUnit m_maxContentHeight{-1}; |
| 257 | 291 |
| 258 Optional<bool> m_hasDefiniteLogicalHeight; | 292 Optional<bool> m_hasDefiniteLogicalHeight; |
| 259 }; | 293 }; |
| 260 | 294 |
| 261 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid()); | 295 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid()); |
| 262 | 296 |
| 263 } // namespace blink | 297 } // namespace blink |
| 264 | 298 |
| 265 #endif // LayoutGrid_h | 299 #endif // LayoutGrid_h |
| OLD | NEW |