| 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 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/rendering/RenderGrid.h" | 27 #include "core/layout/LayoutGrid.h" |
| 28 | 28 |
| 29 #include "core/layout/Layer.h" | 29 #include "core/layout/Layer.h" |
| 30 #include "core/layout/TextAutosizer.h" | 30 #include "core/layout/TextAutosizer.h" |
| 31 #include "core/layout/style/GridCoordinate.h" | 31 #include "core/layout/style/GridCoordinate.h" |
| 32 #include "core/layout/style/LayoutStyle.h" | 32 #include "core/layout/style/LayoutStyle.h" |
| 33 #include "core/paint/GridPainter.h" | 33 #include "core/paint/GridPainter.h" |
| 34 #include "core/rendering/RenderView.h" | 34 #include "core/rendering/RenderView.h" |
| 35 #include "platform/LengthFunctions.h" | 35 #include "platform/LengthFunctions.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 const LayoutUnit& plannedIncrease() const { return m_plannedIncrease; } | 103 const LayoutUnit& plannedIncrease() const { return m_plannedIncrease; } |
| 104 | 104 |
| 105 void growPlannedIncrease(const LayoutUnit& plannedIncrease) | 105 void growPlannedIncrease(const LayoutUnit& plannedIncrease) |
| 106 { | 106 { |
| 107 ASSERT(plannedIncrease >= 0); | 107 ASSERT(plannedIncrease >= 0); |
| 108 m_plannedIncrease += plannedIncrease; | 108 m_plannedIncrease += plannedIncrease; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void updateFromPlannedIncrease(RenderGrid::AccumulatorGrowFunction trackGrow
thFunction) | 111 void updateFromPlannedIncrease(LayoutGrid::AccumulatorGrowFunction trackGrow
thFunction) |
| 112 { | 112 { |
| 113 if (m_plannedIncrease == 0) | 113 if (m_plannedIncrease == 0) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 (this->*trackGrowthFunction)(m_plannedIncrease); | 116 (this->*trackGrowthFunction)(m_plannedIncrease); |
| 117 m_plannedIncrease = 0; | 117 m_plannedIncrease = 0; |
| 118 } | 118 } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite(
) || m_growthLimit >= m_baseSize; } | 121 bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite(
) || m_growthLimit >= m_baseSize; } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 146 m_flex = o.m_flex; | 146 m_flex = o.m_flex; |
| 147 m_normalizedFlexValue = o.m_normalizedFlexValue; | 147 m_normalizedFlexValue = o.m_normalizedFlexValue; |
| 148 return *this; | 148 return *this; |
| 149 } | 149 } |
| 150 | 150 |
| 151 const GridTrack* m_track; | 151 const GridTrack* m_track; |
| 152 double m_flex; | 152 double m_flex; |
| 153 LayoutUnit m_normalizedFlexValue; | 153 LayoutUnit m_normalizedFlexValue; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 class RenderGrid::GridIterator { | 156 class LayoutGrid::GridIterator { |
| 157 WTF_MAKE_NONCOPYABLE(GridIterator); | 157 WTF_MAKE_NONCOPYABLE(GridIterator); |
| 158 public: | 158 public: |
| 159 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g | 159 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g |
| 160 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd co
lumn. | 160 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd co
lumn. |
| 161 GridIterator(const GridRepresentation& grid, GridTrackSizingDirection direct
ion, size_t fixedTrackIndex, size_t varyingTrackIndex = 0) | 161 GridIterator(const GridRepresentation& grid, GridTrackSizingDirection direct
ion, size_t fixedTrackIndex, size_t varyingTrackIndex = 0) |
| 162 : m_grid(grid) | 162 : m_grid(grid) |
| 163 , m_direction(direction) | 163 , m_direction(direction) |
| 164 , m_rowIndex((direction == ForColumns) ? varyingTrackIndex : fixedTrackI
ndex) | 164 , m_rowIndex((direction == ForColumns) ? varyingTrackIndex : fixedTrackI
ndex) |
| 165 , m_columnIndex((direction == ForColumns) ? fixedTrackIndex : varyingTra
ckIndex) | 165 , m_columnIndex((direction == ForColumns) ? fixedTrackIndex : varyingTra
ckIndex) |
| 166 , m_childIndex(0) | 166 , m_childIndex(0) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 | 226 |
| 227 private: | 227 private: |
| 228 const GridRepresentation& m_grid; | 228 const GridRepresentation& m_grid; |
| 229 GridTrackSizingDirection m_direction; | 229 GridTrackSizingDirection m_direction; |
| 230 size_t m_rowIndex; | 230 size_t m_rowIndex; |
| 231 size_t m_columnIndex; | 231 size_t m_columnIndex; |
| 232 size_t m_childIndex; | 232 size_t m_childIndex; |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 struct RenderGrid::GridSizingData { | 235 struct LayoutGrid::GridSizingData { |
| 236 WTF_MAKE_NONCOPYABLE(GridSizingData); | 236 WTF_MAKE_NONCOPYABLE(GridSizingData); |
| 237 STACK_ALLOCATED(); | 237 STACK_ALLOCATED(); |
| 238 public: | 238 public: |
| 239 GridSizingData(size_t gridColumnCount, size_t gridRowCount) | 239 GridSizingData(size_t gridColumnCount, size_t gridRowCount) |
| 240 : columnTracks(gridColumnCount) | 240 : columnTracks(gridColumnCount) |
| 241 , rowTracks(gridRowCount) | 241 , rowTracks(gridRowCount) |
| 242 { | 242 { |
| 243 } | 243 } |
| 244 | 244 |
| 245 Vector<GridTrack> columnTracks; | 245 Vector<GridTrack> columnTracks; |
| 246 Vector<GridTrack> rowTracks; | 246 Vector<GridTrack> rowTracks; |
| 247 Vector<size_t> contentSizedTracksIndex; | 247 Vector<size_t> contentSizedTracksIndex; |
| 248 | 248 |
| 249 // Performance optimization: hold onto these Vectors until the end of Layout
to avoid repeated malloc / free. | 249 // Performance optimization: hold onto these Vectors until the end of Layout
to avoid repeated malloc / free. |
| 250 Vector<GridTrack*> filteredTracks; | 250 Vector<GridTrack*> filteredTracks; |
| 251 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 251 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
| 252 Vector<GridTrack*> growBeyondGrowthLimitsTracks; | 252 Vector<GridTrack*> growBeyondGrowthLimitsTracks; |
| 253 }; | 253 }; |
| 254 | 254 |
| 255 RenderGrid::RenderGrid(Element* element) | 255 LayoutGrid::LayoutGrid(Element* element) |
| 256 : RenderBlock(element) | 256 : RenderBlock(element) |
| 257 , m_gridIsDirty(true) | 257 , m_gridIsDirty(true) |
| 258 , m_orderIterator(this) | 258 , m_orderIterator(this) |
| 259 { | 259 { |
| 260 ASSERT(!childrenInline()); | 260 ASSERT(!childrenInline()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 RenderGrid::~RenderGrid() | 263 LayoutGrid::~LayoutGrid() |
| 264 { | 264 { |
| 265 } | 265 } |
| 266 | 266 |
| 267 void RenderGrid::addChild(LayoutObject* newChild, LayoutObject* beforeChild) | 267 void LayoutGrid::addChild(LayoutObject* newChild, LayoutObject* beforeChild) |
| 268 { | 268 { |
| 269 RenderBlock::addChild(newChild, beforeChild); | 269 RenderBlock::addChild(newChild, beforeChild); |
| 270 | 270 |
| 271 if (gridIsDirty()) | 271 if (gridIsDirty()) |
| 272 return; | 272 return; |
| 273 | 273 |
| 274 // The grid needs to be recomputed as it might contain auto-placed items tha
t will change their position. | 274 // The grid needs to be recomputed as it might contain auto-placed items tha
t will change their position. |
| 275 dirtyGrid(); | 275 dirtyGrid(); |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void RenderGrid::removeChild(LayoutObject* child) | 279 void LayoutGrid::removeChild(LayoutObject* child) |
| 280 { | 280 { |
| 281 RenderBlock::removeChild(child); | 281 RenderBlock::removeChild(child); |
| 282 | 282 |
| 283 if (gridIsDirty()) | 283 if (gridIsDirty()) |
| 284 return; | 284 return; |
| 285 | 285 |
| 286 // The grid needs to be recomputed as it might contain auto-placed items tha
t will change their position. | 286 // The grid needs to be recomputed as it might contain auto-placed items tha
t will change their position. |
| 287 dirtyGrid(); | 287 dirtyGrid(); |
| 288 return; | 288 return; |
| 289 } | 289 } |
| 290 | 290 |
| 291 void RenderGrid::styleDidChange(StyleDifference diff, const LayoutStyle* oldStyl
e) | 291 void LayoutGrid::styleDidChange(StyleDifference diff, const LayoutStyle* oldStyl
e) |
| 292 { | 292 { |
| 293 RenderBlock::styleDidChange(diff, oldStyle); | 293 RenderBlock::styleDidChange(diff, oldStyle); |
| 294 if (!oldStyle) | 294 if (!oldStyle) |
| 295 return; | 295 return; |
| 296 | 296 |
| 297 // FIXME: The following checks could be narrowed down if we kept track of wh
ich type of grid items we have: | 297 // FIXME: The following checks could be narrowed down if we kept track of wh
ich type of grid items we have: |
| 298 // - explicit grid size changes impact negative explicitely positioned and a
uto-placed grid items. | 298 // - explicit grid size changes impact negative explicitely positioned and a
uto-placed grid items. |
| 299 // - named grid lines only impact grid items with named grid lines. | 299 // - named grid lines only impact grid items with named grid lines. |
| 300 // - auto-flow changes only impacts auto-placed children. | 300 // - auto-flow changes only impacts auto-placed children. |
| 301 | 301 |
| 302 if (explicitGridDidResize(*oldStyle) | 302 if (explicitGridDidResize(*oldStyle) |
| 303 || namedGridLinesDefinitionDidChange(*oldStyle) | 303 || namedGridLinesDefinitionDidChange(*oldStyle) |
| 304 || oldStyle->gridAutoFlow() != styleRef().gridAutoFlow()) | 304 || oldStyle->gridAutoFlow() != styleRef().gridAutoFlow()) |
| 305 dirtyGrid(); | 305 dirtyGrid(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool RenderGrid::explicitGridDidResize(const LayoutStyle& oldStyle) const | 308 bool LayoutGrid::explicitGridDidResize(const LayoutStyle& oldStyle) const |
| 309 { | 309 { |
| 310 return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColum
ns().size() | 310 return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColum
ns().size() |
| 311 || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().s
ize(); | 311 || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().s
ize(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 bool RenderGrid::namedGridLinesDefinitionDidChange(const LayoutStyle& oldStyle)
const | 314 bool LayoutGrid::namedGridLinesDefinitionDidChange(const LayoutStyle& oldStyle)
const |
| 315 { | 315 { |
| 316 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() | 316 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() |
| 317 || oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); | 317 || oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void RenderGrid::layoutBlock(bool relayoutChildren) | 320 void LayoutGrid::layoutBlock(bool relayoutChildren) |
| 321 { | 321 { |
| 322 ASSERT(needsLayout()); | 322 ASSERT(needsLayout()); |
| 323 | 323 |
| 324 if (!relayoutChildren && simplifiedLayout()) | 324 if (!relayoutChildren && simplifiedLayout()) |
| 325 return; | 325 return; |
| 326 | 326 |
| 327 // FIXME: Much of this method is boiler plate that matches LayoutBox::layout
Block and Render*FlexibleBox::layoutBlock. | 327 // FIXME: Much of this method is boiler plate that matches LayoutBox::layout
Block and Render*FlexibleBox::layoutBlock. |
| 328 // It would be nice to refactor some of the duplicate code. | 328 // It would be nice to refactor some of the duplicate code. |
| 329 { | 329 { |
| 330 // LayoutState needs this deliberate scope to pop before updating scroll
information (which | 330 // LayoutState needs this deliberate scope to pop before updating scroll
information (which |
| (...skipping 23 matching lines...) Expand all Loading... |
| 354 updateLayerTransformAfterLayout(); | 354 updateLayerTransformAfterLayout(); |
| 355 | 355 |
| 356 // Update our scroll information if we're overflow:auto/scroll/hidden now th
at we know if | 356 // Update our scroll information if we're overflow:auto/scroll/hidden now th
at we know if |
| 357 // we overflow or not. | 357 // we overflow or not. |
| 358 if (hasOverflowClip()) | 358 if (hasOverflowClip()) |
| 359 layer()->scrollableArea()->updateAfterLayout(); | 359 layer()->scrollableArea()->updateAfterLayout(); |
| 360 | 360 |
| 361 clearNeedsLayout(); | 361 clearNeedsLayout(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void RenderGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const | 364 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const |
| 365 { | 365 { |
| 366 const_cast<RenderGrid*>(this)->placeItemsOnGrid(); | 366 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(); |
| 367 | 367 |
| 368 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 368 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
| 369 LayoutUnit availableLogicalSpace = 0; | 369 LayoutUnit availableLogicalSpace = 0; |
| 370 const_cast<RenderGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si
zingData, availableLogicalSpace); | 370 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si
zingData, availableLogicalSpace); |
| 371 | 371 |
| 372 for (const auto& column : sizingData.columnTracks) { | 372 for (const auto& column : sizingData.columnTracks) { |
| 373 const LayoutUnit& minTrackBreadth = column.baseSize(); | 373 const LayoutUnit& minTrackBreadth = column.baseSize(); |
| 374 const LayoutUnit& maxTrackBreadth = column.growthLimit(); | 374 const LayoutUnit& maxTrackBreadth = column.growthLimit(); |
| 375 | 375 |
| 376 minLogicalWidth += minTrackBreadth; | 376 minLogicalWidth += minTrackBreadth; |
| 377 maxLogicalWidth += maxTrackBreadth; | 377 maxLogicalWidth += maxTrackBreadth; |
| 378 | 378 |
| 379 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); | 379 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); |
| 380 maxLogicalWidth += scrollbarWidth; | 380 maxLogicalWidth += scrollbarWidth; |
| 381 minLogicalWidth += scrollbarWidth; | 381 minLogicalWidth += scrollbarWidth; |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 void RenderGrid::computePreferredLogicalWidths() | 385 void LayoutGrid::computePreferredLogicalWidths() |
| 386 { | 386 { |
| 387 ASSERT(preferredLogicalWidthsDirty()); | 387 ASSERT(preferredLogicalWidthsDirty()); |
| 388 | 388 |
| 389 m_minPreferredLogicalWidth = 0; | 389 m_minPreferredLogicalWidth = 0; |
| 390 m_maxPreferredLogicalWidth = 0; | 390 m_maxPreferredLogicalWidth = 0; |
| 391 | 391 |
| 392 // FIXME: We don't take our own logical width into account. Once we do, we n
eed to make sure | 392 // FIXME: We don't take our own logical width into account. Once we do, we n
eed to make sure |
| 393 // we apply (and test the interaction with) min-width / max-width. | 393 // we apply (and test the interaction with) min-width / max-width. |
| 394 | 394 |
| 395 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogi
calWidth); | 395 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogi
calWidth); |
| 396 | 396 |
| 397 LayoutUnit borderAndPaddingInInlineDirection = borderAndPaddingLogicalWidth(
); | 397 LayoutUnit borderAndPaddingInInlineDirection = borderAndPaddingLogicalWidth(
); |
| 398 m_minPreferredLogicalWidth += borderAndPaddingInInlineDirection; | 398 m_minPreferredLogicalWidth += borderAndPaddingInInlineDirection; |
| 399 m_maxPreferredLogicalWidth += borderAndPaddingInInlineDirection; | 399 m_maxPreferredLogicalWidth += borderAndPaddingInInlineDirection; |
| 400 | 400 |
| 401 clearPreferredLogicalWidthsDirty(); | 401 clearPreferredLogicalWidthsDirty(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
on, GridSizingData& sizingData) | 404 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
on, GridSizingData& sizingData) |
| 405 { | 405 { |
| 406 LayoutUnit availableLogicalSpace = (direction == ForColumns) ? availableLogi
calWidth() : availableLogicalHeight(IncludeMarginBorderPadding); | 406 LayoutUnit availableLogicalSpace = (direction == ForColumns) ? availableLogi
calWidth() : availableLogicalHeight(IncludeMarginBorderPadding); |
| 407 computeUsedBreadthOfGridTracks(direction, sizingData, availableLogicalSpace)
; | 407 computeUsedBreadthOfGridTracks(direction, sizingData, availableLogicalSpace)
; |
| 408 } | 408 } |
| 409 | 409 |
| 410 bool RenderGrid::gridElementIsShrinkToFit() | 410 bool LayoutGrid::gridElementIsShrinkToFit() |
| 411 { | 411 { |
| 412 return isFloatingOrOutOfFlowPositioned(); | 412 return isFloatingOrOutOfFlowPositioned(); |
| 413 } | 413 } |
| 414 | 414 |
| 415 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
on, GridSizingData& sizingData, LayoutUnit& freeSpace) | 415 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
on, GridSizingData& sizingData, LayoutUnit& freeSpace) |
| 416 { | 416 { |
| 417 const LayoutUnit initialFreeSpace = freeSpace; | 417 const LayoutUnit initialFreeSpace = freeSpace; |
| 418 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra
cks : sizingData.rowTracks; | 418 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra
cks : sizingData.rowTracks; |
| 419 Vector<size_t> flexibleSizedTracksIndex; | 419 Vector<size_t> flexibleSizedTracksIndex; |
| 420 sizingData.contentSizedTracksIndex.shrink(0); | 420 sizingData.contentSizedTracksIndex.shrink(0); |
| 421 | 421 |
| 422 // 1. Initialize per Grid track variables. | 422 // 1. Initialize per Grid track variables. |
| 423 for (size_t i = 0; i < tracks.size(); ++i) { | 423 for (size_t i = 0; i < tracks.size(); ++i) { |
| 424 GridTrack& track = tracks[i]; | 424 GridTrack& track = tracks[i]; |
| 425 GridTrackSize trackSize = gridTrackSize(direction, i); | 425 GridTrackSize trackSize = gridTrackSize(direction, i); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); | 495 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
| 496 | 496 |
| 497 LayoutUnit baseSize = std::max<LayoutUnit>(tracks[trackIndex].baseSize()
, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()); | 497 LayoutUnit baseSize = std::max<LayoutUnit>(tracks[trackIndex].baseSize()
, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()); |
| 498 tracks[trackIndex].setBaseSize(baseSize); | 498 tracks[trackIndex].setBaseSize(baseSize); |
| 499 freeSpace -= baseSize; | 499 freeSpace -= baseSize; |
| 500 } | 500 } |
| 501 | 501 |
| 502 // FIXME: Should ASSERT flexible tracks exhaust the freeSpace ? (see issue 7
39613002). | 502 // FIXME: Should ASSERT flexible tracks exhaust the freeSpace ? (see issue 7
39613002). |
| 503 } | 503 } |
| 504 | 504 |
| 505 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di
rection, const GridLength& gridLength) const | 505 LayoutUnit LayoutGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di
rection, const GridLength& gridLength) const |
| 506 { | 506 { |
| 507 if (gridLength.isFlex()) | 507 if (gridLength.isFlex()) |
| 508 return 0; | 508 return 0; |
| 509 | 509 |
| 510 const Length& trackLength = gridLength.length(); | 510 const Length& trackLength = gridLength.length(); |
| 511 ASSERT(!trackLength.isAuto()); | 511 ASSERT(!trackLength.isAuto()); |
| 512 if (trackLength.isSpecified()) | 512 if (trackLength.isSpecified()) |
| 513 return computeUsedBreadthOfSpecifiedLength(direction, trackLength); | 513 return computeUsedBreadthOfSpecifiedLength(direction, trackLength); |
| 514 | 514 |
| 515 ASSERT(trackLength.isMinContent() || trackLength.isMaxContent()); | 515 ASSERT(trackLength.isMinContent() || trackLength.isMaxContent()); |
| 516 return 0; | 516 return 0; |
| 517 } | 517 } |
| 518 | 518 |
| 519 LayoutUnit RenderGrid::computeUsedBreadthOfMaxLength(GridTrackSizingDirection di
rection, const GridLength& gridLength, LayoutUnit usedBreadth) const | 519 LayoutUnit LayoutGrid::computeUsedBreadthOfMaxLength(GridTrackSizingDirection di
rection, const GridLength& gridLength, LayoutUnit usedBreadth) const |
| 520 { | 520 { |
| 521 if (gridLength.isFlex()) | 521 if (gridLength.isFlex()) |
| 522 return usedBreadth; | 522 return usedBreadth; |
| 523 | 523 |
| 524 const Length& trackLength = gridLength.length(); | 524 const Length& trackLength = gridLength.length(); |
| 525 ASSERT(!trackLength.isAuto()); | 525 ASSERT(!trackLength.isAuto()); |
| 526 if (trackLength.isSpecified()) { | 526 if (trackLength.isSpecified()) { |
| 527 LayoutUnit computedBreadth = computeUsedBreadthOfSpecifiedLength(directi
on, trackLength); | 527 LayoutUnit computedBreadth = computeUsedBreadthOfSpecifiedLength(directi
on, trackLength); |
| 528 ASSERT(computedBreadth != infinity); | 528 ASSERT(computedBreadth != infinity); |
| 529 return computedBreadth; | 529 return computedBreadth; |
| 530 } | 530 } |
| 531 | 531 |
| 532 ASSERT(trackLength.isMinContent() || trackLength.isMaxContent()); | 532 ASSERT(trackLength.isMinContent() || trackLength.isMaxContent()); |
| 533 return infinity; | 533 return infinity; |
| 534 } | 534 } |
| 535 | 535 |
| 536 LayoutUnit RenderGrid::computeUsedBreadthOfSpecifiedLength(GridTrackSizingDirect
ion direction, const Length& trackLength) const | 536 LayoutUnit LayoutGrid::computeUsedBreadthOfSpecifiedLength(GridTrackSizingDirect
ion direction, const Length& trackLength) const |
| 537 { | 537 { |
| 538 ASSERT(trackLength.isSpecified()); | 538 ASSERT(trackLength.isSpecified()); |
| 539 // FIXME: The -1 here should be replaced by whatever the intrinsic height of
the grid is. | 539 // FIXME: The -1 here should be replaced by whatever the intrinsic height of
the grid is. |
| 540 return valueForLength(trackLength, direction == ForColumns ? logicalWidth()
: computeContentLogicalHeight(style()->logicalHeight(), -1)); | 540 return valueForLength(trackLength, direction == ForColumns ? logicalWidth()
: computeContentLogicalHeight(style()->logicalHeight(), -1)); |
| 541 } | 541 } |
| 542 | 542 |
| 543 static bool sortByGridNormalizedFlexValue(const GridTrackForNormalization& track
1, const GridTrackForNormalization& track2) | 543 static bool sortByGridNormalizedFlexValue(const GridTrackForNormalization& track
1, const GridTrackForNormalization& track2) |
| 544 { | 544 { |
| 545 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; | 545 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; |
| 546 } | 546 } |
| 547 | 547 |
| 548 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit spaceT
oFill) const | 548 double LayoutGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit spaceT
oFill) const |
| 549 { | 549 { |
| 550 LayoutUnit allocatedSpace; | 550 LayoutUnit allocatedSpace; |
| 551 Vector<GridTrackForNormalization> tracksForNormalization; | 551 Vector<GridTrackForNormalization> tracksForNormalization; |
| 552 for (const auto& resolvedPosition : tracksSpan) { | 552 for (const auto& resolvedPosition : tracksSpan) { |
| 553 GridTrack& track = tracks[resolvedPosition.toInt()]; | 553 GridTrack& track = tracks[resolvedPosition.toInt()]; |
| 554 allocatedSpace += track.baseSize(); | 554 allocatedSpace += track.baseSize(); |
| 555 | 555 |
| 556 GridTrackSize trackSize = gridTrackSize(direction, resolvedPosition.toIn
t()); | 556 GridTrackSize trackSize = gridTrackSize(direction, resolvedPosition.toIn
t()); |
| 557 if (!trackSize.maxTrackBreadth().isFlex()) | 557 if (!trackSize.maxTrackBreadth().isFlex()) |
| 558 continue; | 558 continue; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 583 } | 583 } |
| 584 | 584 |
| 585 accumulatedFractions += track.m_flex; | 585 accumulatedFractions += track.m_flex; |
| 586 // This item was processed so we re-add its used breadth to the availabl
e space to accurately count the remaining space. | 586 // This item was processed so we re-add its used breadth to the availabl
e space to accurately count the remaining space. |
| 587 availableLogicalSpaceIgnoringFractionTracks += track.m_track->baseSize()
; | 587 availableLogicalSpaceIgnoringFractionTracks += track.m_track->baseSize()
; |
| 588 } | 588 } |
| 589 | 589 |
| 590 return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions; | 590 return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions; |
| 591 } | 591 } |
| 592 | 592 |
| 593 bool RenderGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons
t | 593 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons
t |
| 594 { | 594 { |
| 595 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi
calWidth(); | 595 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi
calWidth(); |
| 596 } | 596 } |
| 597 | 597 |
| 598 GridTrackSize RenderGrid::gridTrackSize(GridTrackSizingDirection direction, size
_t i) const | 598 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size
_t i) const |
| 599 { | 599 { |
| 600 bool isForColumns = direction == ForColumns; | 600 bool isForColumns = direction == ForColumns; |
| 601 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl
ateColumns() : style()->gridTemplateRows(); | 601 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl
ateColumns() : style()->gridTemplateRows(); |
| 602 const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ?
style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i]; | 602 const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ?
style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i]; |
| 603 | 603 |
| 604 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto> (or in | 604 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto> (or in |
| 605 // the case of minmax() as min-content for the first position and max-conten
t for the second). | 605 // the case of minmax() as min-content for the first position and max-conten
t for the second). |
| 606 if (!hasDefiniteLogicalSize(direction)) { | 606 if (!hasDefiniteLogicalSize(direction)) { |
| 607 const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth(); | 607 const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth(); |
| 608 const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth(); | 608 const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth(); |
| 609 return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinConte
nt) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent)
: oldMaxTrackBreadth); | 609 return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinConte
nt) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent)
: oldMaxTrackBreadth); |
| 610 } | 610 } |
| 611 | 611 |
| 612 return trackSize; | 612 return trackSize; |
| 613 } | 613 } |
| 614 | 614 |
| 615 LayoutUnit RenderGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack>
& columnTracks) | 615 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack>
& columnTracks) |
| 616 { | 616 { |
| 617 SubtreeLayoutScope layoutScope(child); | 617 SubtreeLayoutScope layoutScope(child); |
| 618 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride
ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth
() : LayoutUnit(); | 618 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride
ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth
() : LayoutUnit(); |
| 619 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh
ild(child, ForColumns, columnTracks); | 619 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh
ild(child, ForColumns, columnTracks); |
| 620 if (child.style()->logicalHeight().isPercent() || oldOverrideContainingBlock
ContentLogicalWidth != overrideContainingBlockContentLogicalWidth) | 620 if (child.style()->logicalHeight().isPercent() || oldOverrideContainingBlock
ContentLogicalWidth != overrideContainingBlockContentLogicalWidth) |
| 621 layoutScope.setNeedsLayout(&child); | 621 layoutScope.setNeedsLayout(&child); |
| 622 | 622 |
| 623 child.clearOverrideLogicalContentHeight(); | 623 child.clearOverrideLogicalContentHeight(); |
| 624 | 624 |
| 625 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC
ontentLogicalWidth); | 625 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC
ontentLogicalWidth); |
| 626 // If |child| has a percentage logical height, we shouldn't let it override
its intrinsic height, which is | 626 // If |child| has a percentage logical height, we shouldn't let it override
its intrinsic height, which is |
| 627 // what we are interested in here. Thus we need to set the override logical
height to -1 (no possible resolution). | 627 // what we are interested in here. Thus we need to set the override logical
height to -1 (no possible resolution). |
| 628 child.setOverrideContainingBlockContentLogicalHeight(-1); | 628 child.setOverrideContainingBlockContentLogicalHeight(-1); |
| 629 child.layoutIfNeeded(); | 629 child.layoutIfNeeded(); |
| 630 return child.logicalHeight() + child.marginLogicalHeight(); | 630 return child.logicalHeight() + child.marginLogicalHeight(); |
| 631 } | 631 } |
| 632 | 632 |
| 633 LayoutUnit RenderGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec
tion direction, Vector<GridTrack>& columnTracks) | 633 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec
tion direction, Vector<GridTrack>& columnTracks) |
| 634 { | 634 { |
| 635 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 635 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
| 636 // FIXME: Properly support orthogonal writing mode. | 636 // FIXME: Properly support orthogonal writing mode. |
| 637 if (hasOrthogonalWritingMode) | 637 if (hasOrthogonalWritingMode) |
| 638 return 0; | 638 return 0; |
| 639 | 639 |
| 640 if (direction == ForColumns) { | 640 if (direction == ForColumns) { |
| 641 // FIXME: It's unclear if we should return the intrinsic width or the pr
eferred width. | 641 // FIXME: It's unclear if we should return the intrinsic width or the pr
eferred width. |
| 642 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 642 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
| 643 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor
Child(child); | 643 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor
Child(child); |
| 644 } | 644 } |
| 645 | 645 |
| 646 return logicalHeightForChild(child, columnTracks); | 646 return logicalHeightForChild(child, columnTracks); |
| 647 } | 647 } |
| 648 | 648 |
| 649 LayoutUnit RenderGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec
tion direction, Vector<GridTrack>& columnTracks) | 649 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec
tion direction, Vector<GridTrack>& columnTracks) |
| 650 { | 650 { |
| 651 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 651 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
| 652 // FIXME: Properly support orthogonal writing mode. | 652 // FIXME: Properly support orthogonal writing mode. |
| 653 if (hasOrthogonalWritingMode) | 653 if (hasOrthogonalWritingMode) |
| 654 return LayoutUnit(); | 654 return LayoutUnit(); |
| 655 | 655 |
| 656 if (direction == ForColumns) { | 656 if (direction == ForColumns) { |
| 657 // FIXME: It's unclear if we should return the intrinsic width or the pr
eferred width. | 657 // FIXME: It's unclear if we should return the intrinsic width or the pr
eferred width. |
| 658 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 658 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
| 659 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor
Child(child); | 659 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor
Child(child); |
| 660 } | 660 } |
| 661 | 661 |
| 662 return logicalHeightForChild(child, columnTracks); | 662 return logicalHeightForChild(child, columnTracks); |
| 663 } | 663 } |
| 664 | 664 |
| 665 // We're basically using a class instead of a std::pair for two reasons. First o
f all, accessing gridItem() or | 665 // We're basically using a class instead of a std::pair for two reasons. First o
f all, accessing gridItem() or |
| 666 // coordinate() is much more self-explanatory that using .first or .second membe
rs in the pair. Secondly the class | 666 // coordinate() is much more self-explanatory that using .first or .second membe
rs in the pair. Secondly the class |
| 667 // allows us to precompute the value of the span, something which is quite conve
nient for the sorting. Having a | 667 // allows us to precompute the value of the span, something which is quite conve
nient for the sorting. Having a |
| 668 // std::pair<LayoutBox*, size_t> does not work either because we still need the
GridCoordinate so we'd have to add an | 668 // std::pair<LayoutBox*, size_t> does not work either because we still need the
GridCoordinate so we'd have to add an |
| 669 // extra hash lookup for each item at the beginning of RenderGrid::resolveConten
tBasedTrackSizingFunctionsForItems(). | 669 // extra hash lookup for each item at the beginning of LayoutGrid::resolveConten
tBasedTrackSizingFunctionsForItems(). |
| 670 class GridItemWithSpan { | 670 class GridItemWithSpan { |
| 671 public: | 671 public: |
| 672 GridItemWithSpan(LayoutBox& gridItem, const GridCoordinate& coordinate, Grid
TrackSizingDirection direction) | 672 GridItemWithSpan(LayoutBox& gridItem, const GridCoordinate& coordinate, Grid
TrackSizingDirection direction) |
| 673 : m_gridItem(&gridItem) | 673 : m_gridItem(&gridItem) |
| 674 , m_coordinate(coordinate) | 674 , m_coordinate(coordinate) |
| 675 { | 675 { |
| 676 const GridSpan& span = (direction == ForRows) ? coordinate.rows : coordi
nate.columns; | 676 const GridSpan& span = (direction == ForRows) ? coordinate.rows : coordi
nate.columns; |
| 677 m_span = span.resolvedFinalPosition.toInt() - span.resolvedInitialPositi
on.toInt() + 1; | 677 m_span = span.resolvedFinalPosition.toInt() - span.resolvedInitialPositi
on.toInt() + 1; |
| 678 } | 678 } |
| 679 | 679 |
| 680 LayoutBox& gridItem() const { return *m_gridItem; } | 680 LayoutBox& gridItem() const { return *m_gridItem; } |
| 681 GridCoordinate coordinate() const { return m_coordinate; } | 681 GridCoordinate coordinate() const { return m_coordinate; } |
| 682 #if ENABLE(ASSERT) | 682 #if ENABLE(ASSERT) |
| 683 size_t span() const { return m_span; } | 683 size_t span() const { return m_span; } |
| 684 #endif | 684 #endif |
| 685 | 685 |
| 686 bool operator<(const GridItemWithSpan other) const { return m_span < other.m
_span; } | 686 bool operator<(const GridItemWithSpan other) const { return m_span < other.m
_span; } |
| 687 | 687 |
| 688 private: | 688 private: |
| 689 LayoutBox* m_gridItem; | 689 LayoutBox* m_gridItem; |
| 690 GridCoordinate m_coordinate; | 690 GridCoordinate m_coordinate; |
| 691 size_t m_span; | 691 size_t m_span; |
| 692 }; | 692 }; |
| 693 | 693 |
| 694 bool RenderGrid::spanningItemCrossesFlexibleSizedTracks(const GridCoordinate& co
ordinate, GridTrackSizingDirection direction) const | 694 bool LayoutGrid::spanningItemCrossesFlexibleSizedTracks(const GridCoordinate& co
ordinate, GridTrackSizingDirection direction) const |
| 695 { | 695 { |
| 696 const GridResolvedPosition initialTrackPosition = (direction == ForColumns)
? coordinate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPo
sition; | 696 const GridResolvedPosition initialTrackPosition = (direction == ForColumns)
? coordinate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPo
sition; |
| 697 const GridResolvedPosition finalTrackPosition = (direction == ForColumns) ?
coordinate.columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition
; | 697 const GridResolvedPosition finalTrackPosition = (direction == ForColumns) ?
coordinate.columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition
; |
| 698 | 698 |
| 699 for (GridResolvedPosition trackPosition = initialTrackPosition; trackPositio
n <= finalTrackPosition; ++trackPosition) { | 699 for (GridResolvedPosition trackPosition = initialTrackPosition; trackPositio
n <= finalTrackPosition; ++trackPosition) { |
| 700 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition.
toInt()); | 700 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition.
toInt()); |
| 701 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth().
isFlex()) | 701 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth().
isFlex()) |
| 702 return true; | 702 return true; |
| 703 } | 703 } |
| 704 | 704 |
| 705 return false; | 705 return false; |
| 706 } | 706 } |
| 707 | 707 |
| 708 static inline size_t integerSpanForDirection(const GridCoordinate& coordinate, G
ridTrackSizingDirection direction) | 708 static inline size_t integerSpanForDirection(const GridCoordinate& coordinate, G
ridTrackSizingDirection direction) |
| 709 { | 709 { |
| 710 return (direction == ForRows) ? coordinate.rows.integerSpan() : coordinate.c
olumns.integerSpan(); | 710 return (direction == ForRows) ? coordinate.rows.integerSpan() : coordinate.c
olumns.integerSpan(); |
| 711 } | 711 } |
| 712 | 712 |
| 713 void RenderGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio
n direction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) | 713 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio
n direction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) |
| 714 { | 714 { |
| 715 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 715 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
| 716 HashSet<LayoutBox*> itemsSet; | 716 HashSet<LayoutBox*> itemsSet; |
| 717 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 717 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 718 GridIterator iterator(m_grid, direction, trackIndex); | 718 GridIterator iterator(m_grid, direction, trackIndex); |
| 719 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; | 719 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; |
| 720 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 720 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 721 if (itemsSet.add(gridItem).isNewEntry) { | 721 if (itemsSet.add(gridItem).isNewEntry) { |
| 722 const GridCoordinate& coordinate = cachedGridCoordinate(*gridIte
m); | 722 const GridCoordinate& coordinate = cachedGridCoordinate(*gridIte
m); |
| 723 if (integerSpanForDirection(coordinate, direction) == 1) { | 723 if (integerSpanForDirection(coordinate, direction) == 1) { |
| 724 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d
irection, coordinate, *gridItem, track, sizingData.columnTracks); | 724 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d
irection, coordinate, *gridItem, track, sizingData.columnTracks); |
| 725 } else if (!spanningItemCrossesFlexibleSizedTracks(coordinate, d
irection)) { | 725 } else if (!spanningItemCrossesFlexibleSizedTracks(coordinate, d
irection)) { |
| 726 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp
an(*gridItem, coordinate, direction)); | 726 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp
an(*gridItem, coordinate, direction)); |
| 727 } | 727 } |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo
rtedByIncreasingSpan.end()); | 731 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo
rtedByIncreasingSpan.end()); |
| 732 | 732 |
| 733 Vector<GridItemWithSpan>::iterator end = sizingData.itemsSortedByIncreasingS
pan.end(); | 733 Vector<GridItemWithSpan>::iterator end = sizingData.itemsSortedByIncreasingS
pan.end(); |
| 734 for (Vector<GridItemWithSpan>::iterator it = sizingData.itemsSortedByIncreas
ingSpan.begin(); it != end; ++it) { | 734 for (Vector<GridItemWithSpan>::iterator it = sizingData.itemsSortedByIncreas
ingSpan.begin(); it != end; ++it) { |
| 735 GridItemWithSpan itemWithSpan = *it; | 735 GridItemWithSpan itemWithSpan = *it; |
| 736 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMinOrMaxContentMinTrackBreadth, &RenderGrid::min
ContentForChild, &GridTrack::baseSize, &GridTrack::growBaseSize, &GridTrackSize:
:hasMinContentMinTrackBreadthAndMinOrMaxContentMaxTrackBreadth); | 736 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMinOrMaxContentMinTrackBreadth, &LayoutGrid::min
ContentForChild, &GridTrack::baseSize, &GridTrack::growBaseSize, &GridTrackSize:
:hasMinContentMinTrackBreadthAndMinOrMaxContentMaxTrackBreadth); |
| 737 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMaxContentMinTrackBreadth, &RenderGrid::maxConte
ntForChild, &GridTrack::baseSize, &GridTrack::growBaseSize, &GridTrackSize::hasM
axContentMinTrackBreadthAndMaxContentMaxTrackBreadth); | 737 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMaxContentMinTrackBreadth, &LayoutGrid::maxConte
ntForChild, &GridTrack::baseSize, &GridTrack::growBaseSize, &GridTrackSize::hasM
axContentMinTrackBreadthAndMaxContentMaxTrackBreadth); |
| 738 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMinOrMaxContentMaxTrackBreadth, &RenderGrid::min
ContentForChild, &GridTrack::growthLimitIfNotInfinite, &GridTrack::growGrowthLim
it); | 738 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMinOrMaxContentMaxTrackBreadth, &LayoutGrid::min
ContentForChild, &GridTrack::growthLimitIfNotInfinite, &GridTrack::growGrowthLim
it); |
| 739 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMaxContentMaxTrackBreadth, &RenderGrid::maxConte
ntForChild, &GridTrack::growthLimitIfNotInfinite, &GridTrack::growGrowthLimit); | 739 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, i
temWithSpan, &GridTrackSize::hasMaxContentMaxTrackBreadth, &LayoutGrid::maxConte
ntForChild, &GridTrack::growthLimitIfNotInfinite, &GridTrack::growGrowthLimit); |
| 740 } | 740 } |
| 741 | 741 |
| 742 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 742 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 743 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; | 743 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; |
| 744 if (track.growthLimitIsInfinite()) | 744 if (track.growthLimitIsInfinite()) |
| 745 track.setGrowthLimit(track.baseSize()); | 745 track.setGrowthLimit(track.baseSize()); |
| 746 } | 746 } |
| 747 } | 747 } |
| 748 | 748 |
| 749 void RenderGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid
TrackSizingDirection direction, const GridCoordinate& coordinate, LayoutBox& gri
dItem, GridTrack& track, Vector<GridTrack>& columnTracks) | 749 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid
TrackSizingDirection direction, const GridCoordinate& coordinate, LayoutBox& gri
dItem, GridTrack& track, Vector<GridTrack>& columnTracks) |
| 750 { | 750 { |
| 751 const GridResolvedPosition trackPosition = (direction == ForColumns) ? coord
inate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPosition; | 751 const GridResolvedPosition trackPosition = (direction == ForColumns) ? coord
inate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPosition; |
| 752 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); | 752 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); |
| 753 | 753 |
| 754 if (trackSize.hasMinContentMinTrackBreadth()) | 754 if (trackSize.hasMinContentMinTrackBreadth()) |
| 755 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem
, direction, columnTracks))); | 755 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem
, direction, columnTracks))); |
| 756 else if (trackSize.hasMaxContentMinTrackBreadth()) | 756 else if (trackSize.hasMaxContentMinTrackBreadth()) |
| 757 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem
, direction, columnTracks))); | 757 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem
, direction, columnTracks))); |
| 758 | 758 |
| 759 if (trackSize.hasMinContentMaxTrackBreadth()) | 759 if (trackSize.hasMinContentMaxTrackBreadth()) |
| 760 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr
idItem, direction, columnTracks))); | 760 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr
idItem, direction, columnTracks))); |
| 761 else if (trackSize.hasMaxContentMaxTrackBreadth()) | 761 else if (trackSize.hasMaxContentMaxTrackBreadth()) |
| 762 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr
idItem, direction, columnTracks))); | 762 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr
idItem, direction, columnTracks))); |
| 763 } | 763 } |
| 764 | 764 |
| 765 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
Direction direction, GridSizingData& sizingData, GridItemWithSpan& gridItemWithS
pan, FilterFunction filterFunction, SizingFunction sizingFunction, AccumulatorGe
tter trackGetter, AccumulatorGrowFunction trackGrowthFunction, FilterFunction gr
owAboveMaxBreadthFilterFunction) | 765 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
Direction direction, GridSizingData& sizingData, GridItemWithSpan& gridItemWithS
pan, FilterFunction filterFunction, SizingFunction sizingFunction, AccumulatorGe
tter trackGetter, AccumulatorGrowFunction trackGrowthFunction, FilterFunction gr
owAboveMaxBreadthFilterFunction) |
| 766 { | 766 { |
| 767 ASSERT(gridItemWithSpan.span() > 1); | 767 ASSERT(gridItemWithSpan.span() > 1); |
| 768 const GridCoordinate coordinate = gridItemWithSpan.coordinate(); | 768 const GridCoordinate coordinate = gridItemWithSpan.coordinate(); |
| 769 const GridSpan& itemSpan = (direction == ForColumns) ? coordinate.columns :
coordinate.rows; | 769 const GridSpan& itemSpan = (direction == ForColumns) ? coordinate.columns :
coordinate.rows; |
| 770 | 770 |
| 771 sizingData.growBeyondGrowthLimitsTracks.shrink(0); | 771 sizingData.growBeyondGrowthLimitsTracks.shrink(0); |
| 772 sizingData.filteredTracks.shrink(0); | 772 sizingData.filteredTracks.shrink(0); |
| 773 LayoutUnit spanningTracksSize; | 773 LayoutUnit spanningTracksSize; |
| 774 for (const auto& trackPosition : itemSpan) { | 774 for (const auto& trackPosition : itemSpan) { |
| 775 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()
); | 775 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()
); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 802 // (forall x: NOT x < x). | 802 // (forall x: NOT x < x). |
| 803 if (track1->growthLimitIsInfinite() && track2->growthLimitIsInfinite()) | 803 if (track1->growthLimitIsInfinite() && track2->growthLimitIsInfinite()) |
| 804 return false; | 804 return false; |
| 805 | 805 |
| 806 if (track1->growthLimitIsInfinite() || track2->growthLimitIsInfinite()) | 806 if (track1->growthLimitIsInfinite() || track2->growthLimitIsInfinite()) |
| 807 return track2->growthLimitIsInfinite(); | 807 return track2->growthLimitIsInfinite(); |
| 808 | 808 |
| 809 return (track1->growthLimit() - track1->baseSize()) < (track2->growthLimit()
- track2->baseSize()); | 809 return (track1->growthLimit() - track1->baseSize()) < (track2->growthLimit()
- track2->baseSize()); |
| 810 } | 810 } |
| 811 | 811 |
| 812 void RenderGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, const Vecto
r<GridTrack*>* growBeyondGrowthLimitsTracks, AccumulatorGetter trackGetter, Accu
mulatorGrowFunction trackGrowthFunction, GridSizingData& sizingData, LayoutUnit&
availableLogicalSpace) | 812 void LayoutGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, const Vecto
r<GridTrack*>* growBeyondGrowthLimitsTracks, AccumulatorGetter trackGetter, Accu
mulatorGrowFunction trackGrowthFunction, GridSizingData& sizingData, LayoutUnit&
availableLogicalSpace) |
| 813 { | 813 { |
| 814 ASSERT(availableLogicalSpace > 0); | 814 ASSERT(availableLogicalSpace > 0); |
| 815 std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential); | 815 std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential); |
| 816 | 816 |
| 817 size_t tracksSize = tracks.size(); | 817 size_t tracksSize = tracks.size(); |
| 818 for (size_t i = 0; i < tracksSize; ++i) { | 818 for (size_t i = 0; i < tracksSize; ++i) { |
| 819 GridTrack& track = *tracks[i]; | 819 GridTrack& track = *tracks[i]; |
| 820 ASSERT(track.plannedIncrease() == 0); | 820 ASSERT(track.plannedIncrease() == 0); |
| 821 LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksS
ize - i); | 821 LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksS
ize - i); |
| 822 const LayoutUnit& trackBreadth = (track.*trackGetter)(); | 822 const LayoutUnit& trackBreadth = (track.*trackGetter)(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 838 } | 838 } |
| 839 } | 839 } |
| 840 | 840 |
| 841 for (auto* track: tracks) { | 841 for (auto* track: tracks) { |
| 842 track->updateFromPlannedIncrease(trackGrowthFunction); | 842 track->updateFromPlannedIncrease(trackGrowthFunction); |
| 843 ASSERT(track->plannedIncrease() == 0); | 843 ASSERT(track->plannedIncrease() == 0); |
| 844 } | 844 } |
| 845 } | 845 } |
| 846 | 846 |
| 847 #if ENABLE(ASSERT) | 847 #if ENABLE(ASSERT) |
| 848 bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire
ction, const Vector<GridTrack>& tracks) | 848 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire
ction, const Vector<GridTrack>& tracks) |
| 849 { | 849 { |
| 850 for (size_t i = 0; i < tracks.size(); ++i) { | 850 for (size_t i = 0; i < tracks.size(); ++i) { |
| 851 GridTrackSize trackSize = gridTrackSize(direction, i); | 851 GridTrackSize trackSize = gridTrackSize(direction, i); |
| 852 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 852 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
| 853 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i
].baseSize()) | 853 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i
].baseSize()) |
| 854 return false; | 854 return false; |
| 855 } | 855 } |
| 856 return true; | 856 return true; |
| 857 } | 857 } |
| 858 #endif | 858 #endif |
| 859 | 859 |
| 860 void RenderGrid::ensureGridSize(size_t maximumRowIndex, size_t maximumColumnInde
x) | 860 void LayoutGrid::ensureGridSize(size_t maximumRowIndex, size_t maximumColumnInde
x) |
| 861 { | 861 { |
| 862 const size_t oldRowSize = gridRowCount(); | 862 const size_t oldRowSize = gridRowCount(); |
| 863 if (maximumRowIndex >= oldRowSize) { | 863 if (maximumRowIndex >= oldRowSize) { |
| 864 m_grid.grow(maximumRowIndex + 1); | 864 m_grid.grow(maximumRowIndex + 1); |
| 865 for (size_t row = oldRowSize; row < gridRowCount(); ++row) | 865 for (size_t row = oldRowSize; row < gridRowCount(); ++row) |
| 866 m_grid[row].grow(gridColumnCount()); | 866 m_grid[row].grow(gridColumnCount()); |
| 867 } | 867 } |
| 868 | 868 |
| 869 if (maximumColumnIndex >= gridColumnCount()) { | 869 if (maximumColumnIndex >= gridColumnCount()) { |
| 870 for (size_t row = 0; row < gridRowCount(); ++row) | 870 for (size_t row = 0; row < gridRowCount(); ++row) |
| 871 m_grid[row].grow(maximumColumnIndex + 1); | 871 m_grid[row].grow(maximumColumnIndex + 1); |
| 872 } | 872 } |
| 873 } | 873 } |
| 874 | 874 |
| 875 void RenderGrid::insertItemIntoGrid(LayoutBox& child, const GridCoordinate& coor
dinate) | 875 void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridCoordinate& coor
dinate) |
| 876 { | 876 { |
| 877 ensureGridSize(coordinate.rows.resolvedFinalPosition.toInt(), coordinate.col
umns.resolvedFinalPosition.toInt()); | 877 ensureGridSize(coordinate.rows.resolvedFinalPosition.toInt(), coordinate.col
umns.resolvedFinalPosition.toInt()); |
| 878 | 878 |
| 879 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row
s.end(); ++row) { | 879 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row
s.end(); ++row) { |
| 880 for (GridSpan::iterator column = coordinate.columns.begin(); column != c
oordinate.columns.end(); ++column) | 880 for (GridSpan::iterator column = coordinate.columns.begin(); column != c
oordinate.columns.end(); ++column) |
| 881 m_grid[row.toInt()][column.toInt()].append(&child); | 881 m_grid[row.toInt()][column.toInt()].append(&child); |
| 882 } | 882 } |
| 883 | 883 |
| 884 RELEASE_ASSERT(!m_gridItemCoordinate.contains(&child)); | 884 RELEASE_ASSERT(!m_gridItemCoordinate.contains(&child)); |
| 885 m_gridItemCoordinate.set(&child, coordinate); | 885 m_gridItemCoordinate.set(&child, coordinate); |
| 886 } | 886 } |
| 887 | 887 |
| 888 void RenderGrid::placeItemsOnGrid() | 888 void LayoutGrid::placeItemsOnGrid() |
| 889 { | 889 { |
| 890 if (!gridIsDirty()) | 890 if (!gridIsDirty()) |
| 891 return; | 891 return; |
| 892 | 892 |
| 893 ASSERT(m_gridItemCoordinate.isEmpty()); | 893 ASSERT(m_gridItemCoordinate.isEmpty()); |
| 894 | 894 |
| 895 populateExplicitGridAndOrderIterator(); | 895 populateExplicitGridAndOrderIterator(); |
| 896 | 896 |
| 897 // We clear the dirty bit here as the grid sizes have been updated, this mea
ns | 897 // We clear the dirty bit here as the grid sizes have been updated, this mea
ns |
| 898 // that we can safely call gridRowCount() / gridColumnCount(). | 898 // that we can safely call gridRowCount() / gridColumnCount(). |
| (...skipping 20 matching lines...) Expand all Loading... |
| 919 | 919 |
| 920 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style()
)); | 920 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style()
)); |
| 921 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s
tyle())); | 921 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s
tyle())); |
| 922 | 922 |
| 923 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 923 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 924 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 924 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 925 | 925 |
| 926 m_grid.shrinkToFit(); | 926 m_grid.shrinkToFit(); |
| 927 } | 927 } |
| 928 | 928 |
| 929 void RenderGrid::populateExplicitGridAndOrderIterator() | 929 void LayoutGrid::populateExplicitGridAndOrderIterator() |
| 930 { | 930 { |
| 931 OrderIteratorPopulator populator(m_orderIterator); | 931 OrderIteratorPopulator populator(m_orderIterator); |
| 932 | 932 |
| 933 size_t maximumRowIndex = std::max<size_t>(1, GridResolvedPosition::explicitG
ridRowCount(*style())); | 933 size_t maximumRowIndex = std::max<size_t>(1, GridResolvedPosition::explicitG
ridRowCount(*style())); |
| 934 size_t maximumColumnIndex = std::max<size_t>(1, GridResolvedPosition::explic
itGridColumnCount(*style())); | 934 size_t maximumColumnIndex = std::max<size_t>(1, GridResolvedPosition::explic
itGridColumnCount(*style())); |
| 935 | 935 |
| 936 ASSERT(m_gridItemsIndexesMap.isEmpty()); | 936 ASSERT(m_gridItemsIndexesMap.isEmpty()); |
| 937 size_t childIndex = 0; | 937 size_t childIndex = 0; |
| 938 for (LayoutBox* child = firstChildBox(); child; child = child->nextInFlowSib
lingBox()) { | 938 for (LayoutBox* child = firstChildBox(); child; child = child->nextInFlowSib
lingBox()) { |
| 939 populator.collectChild(child); | 939 populator.collectChild(child); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 959 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA
utoPlacementPosition(*style(), *child, ForColumns, GridResolvedPosition(0)); | 959 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA
utoPlacementPosition(*style(), *child, ForColumns, GridResolvedPosition(0)); |
| 960 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, positions.
resolvedFinalPosition.next().toInt()); | 960 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, positions.
resolvedFinalPosition.next().toInt()); |
| 961 } | 961 } |
| 962 } | 962 } |
| 963 | 963 |
| 964 m_grid.grow(maximumRowIndex); | 964 m_grid.grow(maximumRowIndex); |
| 965 for (auto& column : m_grid) | 965 for (auto& column : m_grid) |
| 966 column.grow(maximumColumnIndex); | 966 column.grow(maximumColumnIndex); |
| 967 } | 967 } |
| 968 | 968 |
| 969 PassOwnPtr<GridCoordinate> RenderGrid::createEmptyGridAreaAtSpecifiedPositionsOu
tsideGrid(const LayoutBox& gridItem, GridTrackSizingDirection specifiedDirection
, const GridSpan& specifiedPositions) const | 969 PassOwnPtr<GridCoordinate> LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOu
tsideGrid(const LayoutBox& gridItem, GridTrackSizingDirection specifiedDirection
, const GridSpan& specifiedPositions) const |
| 970 { | 970 { |
| 971 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ?
ForRows : ForColumns; | 971 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ?
ForRows : ForColumns; |
| 972 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumn
Count() : gridRowCount(); | 972 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumn
Count() : gridRowCount(); |
| 973 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPosition
sFromAutoPlacementPosition(*style(), gridItem, crossDirection, GridResolvedPosit
ion(endOfCrossDirection)); | 973 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPosition
sFromAutoPlacementPosition(*style(), gridItem, crossDirection, GridResolvedPosit
ion(endOfCrossDirection)); |
| 974 return adoptPtr(new GridCoordinate(specifiedDirection == ForColumns ? crossD
irectionPositions : specifiedPositions, specifiedDirection == ForColumns ? speci
fiedPositions : crossDirectionPositions)); | 974 return adoptPtr(new GridCoordinate(specifiedDirection == ForColumns ? crossD
irectionPositions : specifiedPositions, specifiedDirection == ForColumns ? speci
fiedPositions : crossDirectionPositions)); |
| 975 } | 975 } |
| 976 | 976 |
| 977 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>& au
toGridItems) | 977 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>& au
toGridItems) |
| 978 { | 978 { |
| 979 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; | 979 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; |
| 980 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 980 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 981 | 981 |
| 982 // Mapping between the major axis tracks (rows or columns) and the last auto
-placed item's position inserted on | 982 // Mapping between the major axis tracks (rows or columns) and the last auto
-placed item's position inserted on |
| 983 // that track. This is needed to implement "sparse" packing for items locked
to a given track. | 983 // that track. This is needed to implement "sparse" packing for items locked
to a given track. |
| 984 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo | 984 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo |
| 985 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZe
roKeyHashTraits<unsigned>> minorAxisCursors; | 985 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZe
roKeyHashTraits<unsigned>> minorAxisCursors; |
| 986 | 986 |
| 987 for (const auto& autoGridItem : autoGridItems) { | 987 for (const auto& autoGridItem : autoGridItems) { |
| 988 OwnPtr<GridSpan> majorAxisPositions = GridResolvedPosition::resolveGridP
ositionsFromStyle(*style(), *autoGridItem, autoPlacementMajorAxisDirection()); | 988 OwnPtr<GridSpan> majorAxisPositions = GridResolvedPosition::resolveGridP
ositionsFromStyle(*style(), *autoGridItem, autoPlacementMajorAxisDirection()); |
| 989 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions
FromAutoPlacementPosition(*style(), *autoGridItem, autoPlacementMinorAxisDirecti
on(), GridResolvedPosition(0)); | 989 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions
FromAutoPlacementPosition(*style(), *autoGridItem, autoPlacementMinorAxisDirecti
on(), GridResolvedPosition(0)); |
| 990 unsigned majorAxisInitialPosition = majorAxisPositions->resolvedInitialP
osition.toInt(); | 990 unsigned majorAxisInitialPosition = majorAxisPositions->resolvedInitialP
osition.toInt(); |
| 991 | 991 |
| 992 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->resolvedInitialPosition.toInt(), isGridAutoFlowDense ? 0 : minorAxi
sCursors.get(majorAxisInitialPosition)); | 992 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->resolvedInitialPosition.toInt(), isGridAutoFlowDense ? 0 : minorAxi
sCursors.get(majorAxisInitialPosition)); |
| 993 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA
xisPositions->integerSpan(), minorAxisPositions.integerSpan()); | 993 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA
xisPositions->integerSpan(), minorAxisPositions.integerSpan()); |
| 994 if (!emptyGridArea) | 994 if (!emptyGridArea) |
| 995 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*
autoGridItem, autoPlacementMajorAxisDirection(), *majorAxisPositions); | 995 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*
autoGridItem, autoPlacementMajorAxisDirection(), *majorAxisPositions); |
| 996 insertItemIntoGrid(*autoGridItem, *emptyGridArea); | 996 insertItemIntoGrid(*autoGridItem, *emptyGridArea); |
| 997 | 997 |
| 998 if (!isGridAutoFlowDense) | 998 if (!isGridAutoFlowDense) |
| 999 minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyG
ridArea->rows.resolvedInitialPosition.toInt() : emptyGridArea->columns.resolvedI
nitialPosition.toInt()); | 999 minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyG
ridArea->rows.resolvedInitialPosition.toInt() : emptyGridArea->columns.resolvedI
nitialPosition.toInt()); |
| 1000 } | 1000 } |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>& autoGri
dItems) | 1003 void LayoutGrid::placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>& autoGri
dItems) |
| 1004 { | 1004 { |
| 1005 std::pair<size_t, size_t> autoPlacementCursor = std::make_pair(0, 0); | 1005 std::pair<size_t, size_t> autoPlacementCursor = std::make_pair(0, 0); |
| 1006 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 1006 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 1007 | 1007 |
| 1008 for (const auto& autoGridItem : autoGridItems) { | 1008 for (const auto& autoGridItem : autoGridItems) { |
| 1009 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); | 1009 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); |
| 1010 | 1010 |
| 1011 // If grid-auto-flow is dense, reset auto-placement cursor. | 1011 // If grid-auto-flow is dense, reset auto-placement cursor. |
| 1012 if (isGridAutoFlowDense) { | 1012 if (isGridAutoFlowDense) { |
| 1013 autoPlacementCursor.first = 0; | 1013 autoPlacementCursor.first = 0; |
| 1014 autoPlacementCursor.second = 0; | 1014 autoPlacementCursor.second = 0; |
| 1015 } | 1015 } |
| 1016 } | 1016 } |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 void RenderGrid::placeAutoMajorAxisItemOnGrid(LayoutBox& gridItem, std::pair<siz
e_t, size_t>& autoPlacementCursor) | 1019 void LayoutGrid::placeAutoMajorAxisItemOnGrid(LayoutBox& gridItem, std::pair<siz
e_t, size_t>& autoPlacementCursor) |
| 1020 { | 1020 { |
| 1021 OwnPtr<GridSpan> minorAxisPositions = GridResolvedPosition::resolveGridPosit
ionsFromStyle(*style(), gridItem, autoPlacementMinorAxisDirection()); | 1021 OwnPtr<GridSpan> minorAxisPositions = GridResolvedPosition::resolveGridPosit
ionsFromStyle(*style(), gridItem, autoPlacementMinorAxisDirection()); |
| 1022 ASSERT(!GridResolvedPosition::resolveGridPositionsFromStyle(*style(), gridIt
em, autoPlacementMajorAxisDirection())); | 1022 ASSERT(!GridResolvedPosition::resolveGridPositionsFromStyle(*style(), gridIt
em, autoPlacementMajorAxisDirection())); |
| 1023 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom
AutoPlacementPosition(*style(), gridItem, autoPlacementMajorAxisDirection(), Gri
dResolvedPosition(0)); | 1023 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom
AutoPlacementPosition(*style(), gridItem, autoPlacementMajorAxisDirection(), Gri
dResolvedPosition(0)); |
| 1024 | 1024 |
| 1025 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColum
ns) ? gridColumnCount() : gridRowCount(); | 1025 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColum
ns) ? gridColumnCount() : gridRowCount(); |
| 1026 size_t majorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.second : autoPlacementCursor.first; | 1026 size_t majorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.second : autoPlacementCursor.first; |
| 1027 size_t minorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.first : autoPlacementCursor.second; | 1027 size_t minorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.first : autoPlacementCursor.second; |
| 1028 | 1028 |
| 1029 OwnPtr<GridCoordinate> emptyGridArea; | 1029 OwnPtr<GridCoordinate> emptyGridArea; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 if (!emptyGridArea) | 1065 if (!emptyGridArea) |
| 1066 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g
ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); | 1066 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g
ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 insertItemIntoGrid(gridItem, *emptyGridArea); | 1069 insertItemIntoGrid(gridItem, *emptyGridArea); |
| 1070 // Move auto-placement cursor to the new position. | 1070 // Move auto-placement cursor to the new position. |
| 1071 autoPlacementCursor.first = emptyGridArea->rows.resolvedInitialPosition.toIn
t(); | 1071 autoPlacementCursor.first = emptyGridArea->rows.resolvedInitialPosition.toIn
t(); |
| 1072 autoPlacementCursor.second = emptyGridArea->columns.resolvedInitialPosition.
toInt(); | 1072 autoPlacementCursor.second = emptyGridArea->columns.resolvedInitialPosition.
toInt(); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const | 1075 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const |
| 1076 { | 1076 { |
| 1077 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; | 1077 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const | 1080 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const |
| 1081 { | 1081 { |
| 1082 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 1082 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 void RenderGrid::dirtyGrid() | 1085 void LayoutGrid::dirtyGrid() |
| 1086 { | 1086 { |
| 1087 // Even if this could be redundant, it could be seen as a defensive strategy
against | 1087 // Even if this could be redundant, it could be seen as a defensive strategy
against |
| 1088 // style changes events happening during the layout phase or even while the
painting process | 1088 // style changes events happening during the layout phase or even while the
painting process |
| 1089 // is still ongoing. | 1089 // is still ongoing. |
| 1090 // Forcing a new layout for the Grid render would cancel any ongoing paintin
g and ensure | 1090 // Forcing a new layout for the Grid render would cancel any ongoing paintin
g and ensure |
| 1091 // the grid and its children are correctly laid out according to the new sty
le rules. | 1091 // the grid and its children are correctly laid out according to the new sty
le rules. |
| 1092 setNeedsLayout(); | 1092 setNeedsLayout(); |
| 1093 | 1093 |
| 1094 m_grid.resize(0); | 1094 m_grid.resize(0); |
| 1095 m_gridItemCoordinate.clear(); | 1095 m_gridItemCoordinate.clear(); |
| 1096 m_gridIsDirty = true; | 1096 m_gridIsDirty = true; |
| 1097 m_gridItemsOverflowingGridArea.resize(0); | 1097 m_gridItemsOverflowingGridArea.resize(0); |
| 1098 m_gridItemsIndexesMap.clear(); | 1098 m_gridItemsIndexesMap.clear(); |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 void RenderGrid::layoutGridItems() | 1101 void LayoutGrid::layoutGridItems() |
| 1102 { | 1102 { |
| 1103 placeItemsOnGrid(); | 1103 placeItemsOnGrid(); |
| 1104 | 1104 |
| 1105 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 1105 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
| 1106 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); | 1106 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); |
| 1107 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 1107 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
| 1108 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu
mns); | 1108 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu
mns); |
| 1109 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks
)); | 1109 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks
)); |
| 1110 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); | 1110 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); |
| 1111 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); | 1111 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 for (const auto& row : sizingData.rowTracks) | 1162 for (const auto& row : sizingData.rowTracks) |
| 1163 setLogicalHeight(logicalHeight() + row.baseSize()); | 1163 setLogicalHeight(logicalHeight() + row.baseSize()); |
| 1164 | 1164 |
| 1165 // Min / max logical height is handled by the call to updateLogicalHeight in
layoutBlock. | 1165 // Min / max logical height is handled by the call to updateLogicalHeight in
layoutBlock. |
| 1166 | 1166 |
| 1167 setLogicalHeight(logicalHeight() + borderAndPaddingLogicalHeight()); | 1167 setLogicalHeight(logicalHeight() + borderAndPaddingLogicalHeight()); |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 void RenderGrid::layoutPositionedObjects(bool relayoutChildren, PositionedLayout
Behavior info) | 1170 void LayoutGrid::layoutPositionedObjects(bool relayoutChildren, PositionedLayout
Behavior info) |
| 1171 { | 1171 { |
| 1172 TrackedRendererListHashSet* positionedDescendants = positionedObjects(); | 1172 TrackedRendererListHashSet* positionedDescendants = positionedObjects(); |
| 1173 if (!positionedDescendants) | 1173 if (!positionedDescendants) |
| 1174 return; | 1174 return; |
| 1175 | 1175 |
| 1176 bool containerHasHorizontalWritingMode = isHorizontalWritingMode(); | 1176 bool containerHasHorizontalWritingMode = isHorizontalWritingMode(); |
| 1177 for (auto* child : *positionedDescendants) { | 1177 for (auto* child : *positionedDescendants) { |
| 1178 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != cont
ainerHasHorizontalWritingMode; | 1178 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != cont
ainerHasHorizontalWritingMode; |
| 1179 if (hasOrthogonalWritingMode) { | 1179 if (hasOrthogonalWritingMode) { |
| 1180 // FIXME: Properly support orthogonal writing mode. | 1180 // FIXME: Properly support orthogonal writing mode. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1206 if (rowStartIsAuto) | 1206 if (rowStartIsAuto) |
| 1207 childLayer->setStaticBlockPosition(borderAndPaddingBefore()); | 1207 childLayer->setStaticBlockPosition(borderAndPaddingBefore()); |
| 1208 else | 1208 else |
| 1209 childLayer->setStaticBlockPosition(borderBefore() + rowOffset); | 1209 childLayer->setStaticBlockPosition(borderBefore() + rowOffset); |
| 1210 } | 1210 } |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 RenderBlock::layoutPositionedObjects(relayoutChildren, info); | 1213 RenderBlock::layoutPositionedObjects(relayoutChildren, info); |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 void RenderGrid::offsetAndBreadthForPositionedChild(const LayoutBox& child, Grid
TrackSizingDirection direction, bool startIsAuto, bool endIsAuto, LayoutUnit& of
fset, LayoutUnit& breadth) | 1216 void LayoutGrid::offsetAndBreadthForPositionedChild(const LayoutBox& child, Grid
TrackSizingDirection direction, bool startIsAuto, bool endIsAuto, LayoutUnit& of
fset, LayoutUnit& breadth) |
| 1217 { | 1217 { |
| 1218 ASSERT(child.isHorizontalWritingMode() == isHorizontalWritingMode()); | 1218 ASSERT(child.isHorizontalWritingMode() == isHorizontalWritingMode()); |
| 1219 | 1219 |
| 1220 OwnPtr<GridSpan> positions = GridResolvedPosition::resolveGridPositionsFromS
tyle(*style(), child, direction); | 1220 OwnPtr<GridSpan> positions = GridResolvedPosition::resolveGridPositionsFromS
tyle(*style(), child, direction); |
| 1221 if (!positions) { | 1221 if (!positions) { |
| 1222 offset = LayoutUnit(0); | 1222 offset = LayoutUnit(0); |
| 1223 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic
alHeight(); | 1223 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic
alHeight(); |
| 1224 return; | 1224 return; |
| 1225 } | 1225 } |
| 1226 | 1226 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1244 start -= ((direction == ForColumns) ? borderStart() : borderBefore()); | 1244 start -= ((direction == ForColumns) ? borderStart() : borderBefore()); |
| 1245 | 1245 |
| 1246 if (endIsAuto) { | 1246 if (endIsAuto) { |
| 1247 breadth -= (direction == ForColumns) ? borderEnd() : borderAfter(); | 1247 breadth -= (direction == ForColumns) ? borderEnd() : borderAfter(); |
| 1248 breadth -= scrollbarLogicalWidth(); | 1248 breadth -= scrollbarLogicalWidth(); |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 offset = start; | 1251 offset = start; |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 GridCoordinate RenderGrid::cachedGridCoordinate(const LayoutBox& gridItem) const | 1254 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const |
| 1255 { | 1255 { |
| 1256 ASSERT(m_gridItemCoordinate.contains(&gridItem)); | 1256 ASSERT(m_gridItemCoordinate.contains(&gridItem)); |
| 1257 return m_gridItemCoordinate.get(&gridItem); | 1257 return m_gridItemCoordinate.get(&gridItem); |
| 1258 } | 1258 } |
| 1259 | 1259 |
| 1260 LayoutUnit RenderGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const | 1260 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const |
| 1261 { | 1261 { |
| 1262 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1262 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1263 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; | 1263 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; |
| 1264 LayoutUnit gridAreaBreadth = 0; | 1264 LayoutUnit gridAreaBreadth = 0; |
| 1265 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.
end(); ++trackPosition) | 1265 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.
end(); ++trackPosition) |
| 1266 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); | 1266 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); |
| 1267 return gridAreaBreadth; | 1267 return gridAreaBreadth; |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 void RenderGrid::populateGridPositions(const GridSizingData& sizingData, LayoutU
nit availableSpaceForColumns, LayoutUnit availableSpaceForRows) | 1270 void LayoutGrid::populateGridPositions(const GridSizingData& sizingData, LayoutU
nit availableSpaceForColumns, LayoutUnit availableSpaceForRows) |
| 1271 { | 1271 { |
| 1272 unsigned numberOfColumnTracks = sizingData.columnTracks.size(); | 1272 unsigned numberOfColumnTracks = sizingData.columnTracks.size(); |
| 1273 unsigned numberOfRowTracks = sizingData.rowTracks.size(); | 1273 unsigned numberOfRowTracks = sizingData.rowTracks.size(); |
| 1274 | 1274 |
| 1275 m_columnPositions.resize(numberOfColumnTracks + 1); | 1275 m_columnPositions.resize(numberOfColumnTracks + 1); |
| 1276 m_columnPositions[0] = borderAndPaddingStart(); | 1276 m_columnPositions[0] = borderAndPaddingStart(); |
| 1277 for (unsigned i = 0; i < numberOfColumnTracks; ++i) | 1277 for (unsigned i = 0; i < numberOfColumnTracks; ++i) |
| 1278 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].baseSize(); | 1278 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].baseSize(); |
| 1279 | 1279 |
| 1280 m_rowPositions.resize(numberOfRowTracks + 1); | 1280 m_rowPositions.resize(numberOfRowTracks + 1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1292 // edge (potentially cause some data loss as the overflow is unreachable). | 1292 // edge (potentially cause some data loss as the overflow is unreachable). |
| 1293 if (overflow == OverflowAlignmentSafe) | 1293 if (overflow == OverflowAlignmentSafe) |
| 1294 offset = std::max<LayoutUnit>(0, offset); | 1294 offset = std::max<LayoutUnit>(0, offset); |
| 1295 | 1295 |
| 1296 // If we overflow our alignment container and overflow is 'true' (default),
we | 1296 // If we overflow our alignment container and overflow is 'true' (default),
we |
| 1297 // ignore the overflow and just return the value regardless (which may cause
data | 1297 // ignore the overflow and just return the value regardless (which may cause
data |
| 1298 // loss as we overflow the 'start' edge). | 1298 // loss as we overflow the 'start' edge). |
| 1299 return offset; | 1299 return offset; |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 LayoutUnit RenderGrid::startOfColumnForChild(const LayoutBox& child) const | 1302 LayoutUnit LayoutGrid::startOfColumnForChild(const LayoutBox& child) const |
| 1303 { | 1303 { |
| 1304 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1304 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1305 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1305 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; |
| 1306 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1306 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1307 return startOfColumn + marginStartForChild(child); | 1307 return startOfColumn + marginStartForChild(child); |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 LayoutUnit RenderGrid::endOfColumnForChild(const LayoutBox& child) const | 1310 LayoutUnit LayoutGrid::endOfColumnForChild(const LayoutBox& child) const |
| 1311 { | 1311 { |
| 1312 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1312 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1313 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1313 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; |
| 1314 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1314 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1315 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | 1315 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1316 | 1316 |
| 1317 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; | 1317 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; |
| 1318 // FIXME: This might not work as expected with orthogonal writing-modes. | 1318 // FIXME: This might not work as expected with orthogonal writing-modes. |
| 1319 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth() + child.marginLogicalWidth()); | 1319 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth() + child.marginLogicalWidth()); |
| 1320 | 1320 |
| 1321 return columnPosition + offsetFromColumnPosition; | 1321 return columnPosition + offsetFromColumnPosition; |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 LayoutUnit RenderGrid::columnPositionLeft(const LayoutBox& child) const | 1324 LayoutUnit LayoutGrid::columnPositionLeft(const LayoutBox& child) const |
| 1325 { | 1325 { |
| 1326 if (style()->isLeftToRightDirection()) | 1326 if (style()->isLeftToRightDirection()) |
| 1327 return startOfColumnForChild(child); | 1327 return startOfColumnForChild(child); |
| 1328 | 1328 |
| 1329 return endOfColumnForChild(child); | 1329 return endOfColumnForChild(child); |
| 1330 } | 1330 } |
| 1331 | 1331 |
| 1332 LayoutUnit RenderGrid::columnPositionRight(const LayoutBox& child) const | 1332 LayoutUnit LayoutGrid::columnPositionRight(const LayoutBox& child) const |
| 1333 { | 1333 { |
| 1334 if (!style()->isLeftToRightDirection()) | 1334 if (!style()->isLeftToRightDirection()) |
| 1335 return startOfColumnForChild(child); | 1335 return startOfColumnForChild(child); |
| 1336 | 1336 |
| 1337 return endOfColumnForChild(child); | 1337 return endOfColumnForChild(child); |
| 1338 } | 1338 } |
| 1339 | 1339 |
| 1340 LayoutUnit RenderGrid::centeredColumnPositionForChild(const LayoutBox& child) co
nst | 1340 LayoutUnit LayoutGrid::centeredColumnPositionForChild(const LayoutBox& child) co
nst |
| 1341 { | 1341 { |
| 1342 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1342 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1343 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1343 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; |
| 1344 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; | 1344 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; |
| 1345 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | 1345 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1346 // FIXME: This might not work as expected with orthogonal writing-modes. | 1346 // FIXME: This might not work as expected with orthogonal writing-modes. |
| 1347 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth() + child.marginLogicalWidth()); | 1347 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth() + child.marginLogicalWidth()); |
| 1348 | 1348 |
| 1349 return columnPosition + offsetFromColumnPosition / 2; | 1349 return columnPosition + offsetFromColumnPosition / 2; |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 LayoutUnit RenderGrid::columnPositionForChild(const LayoutBox& child) const | 1352 LayoutUnit LayoutGrid::columnPositionForChild(const LayoutBox& child) const |
| 1353 { | 1353 { |
| 1354 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1354 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
| 1355 | 1355 |
| 1356 switch (LayoutStyle::resolveJustification(styleRef(), child.styleRef(), Item
PositionStretch)) { | 1356 switch (LayoutStyle::resolveJustification(styleRef(), child.styleRef(), Item
PositionStretch)) { |
| 1357 case ItemPositionSelfStart: | 1357 case ItemPositionSelfStart: |
| 1358 // For orthogonal writing-modes, this computes to 'start' | 1358 // For orthogonal writing-modes, this computes to 'start' |
| 1359 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 1359 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. |
| 1360 if (hasOrthogonalWritingMode) | 1360 if (hasOrthogonalWritingMode) |
| 1361 return startOfColumnForChild(child); | 1361 return startOfColumnForChild(child); |
| 1362 | 1362 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 case ItemPositionBaseline: | 1399 case ItemPositionBaseline: |
| 1400 case ItemPositionLastBaseline: | 1400 case ItemPositionLastBaseline: |
| 1401 // FIXME: Implement the previous values. For now, we always 'start' alig
n the child. | 1401 // FIXME: Implement the previous values. For now, we always 'start' alig
n the child. |
| 1402 return startOfColumnForChild(child); | 1402 return startOfColumnForChild(child); |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 ASSERT_NOT_REACHED(); | 1405 ASSERT_NOT_REACHED(); |
| 1406 return 0; | 1406 return 0; |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 LayoutUnit RenderGrid::endOfRowForChild(const LayoutBox& child) const | 1409 LayoutUnit LayoutGrid::endOfRowForChild(const LayoutBox& child) const |
| 1410 { | 1410 { |
| 1411 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1411 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1412 | 1412 |
| 1413 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; | 1413 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; |
| 1414 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1414 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1415 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | 1415 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| 1416 | 1416 |
| 1417 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; | 1417 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; |
| 1418 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight() +
child.marginLogicalHeight()); | 1418 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight() +
child.marginLogicalHeight()); |
| 1419 | 1419 |
| 1420 return rowPosition + offsetFromRowPosition; | 1420 return rowPosition + offsetFromRowPosition; |
| 1421 } | 1421 } |
| 1422 | 1422 |
| 1423 LayoutUnit RenderGrid::startOfRowForChild(const LayoutBox& child) const | 1423 LayoutUnit LayoutGrid::startOfRowForChild(const LayoutBox& child) const |
| 1424 { | 1424 { |
| 1425 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1425 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1426 | 1426 |
| 1427 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; | 1427 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; |
| 1428 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1428 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1429 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | 1429 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| 1430 | 1430 |
| 1431 return rowPosition; | 1431 return rowPosition; |
| 1432 } | 1432 } |
| 1433 | 1433 |
| 1434 LayoutUnit RenderGrid::centeredRowPositionForChild(const LayoutBox& child) const | 1434 LayoutUnit LayoutGrid::centeredRowPositionForChild(const LayoutBox& child) const |
| 1435 { | 1435 { |
| 1436 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1436 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1437 | 1437 |
| 1438 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1438 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1439 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; | 1439 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()]; |
| 1440 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; | 1440 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; |
| 1441 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | 1441 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| 1442 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight() +
child.marginLogicalHeight()); | 1442 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight() +
child.marginLogicalHeight()); |
| 1443 | 1443 |
| 1444 return rowPosition + offsetFromRowPosition / 2; | 1444 return rowPosition + offsetFromRowPosition / 2; |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
outBox& child) | 1447 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
outBox& child) |
| 1448 { | 1448 { |
| 1449 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); | 1449 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); |
| 1450 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | 1450 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
| 1451 } | 1451 } |
| 1452 | 1452 |
| 1453 bool RenderGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c
onst | 1453 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c
onst |
| 1454 { | 1454 { |
| 1455 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo
reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); | 1455 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo
reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. | 1458 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. |
| 1459 bool RenderGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const | 1459 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const |
| 1460 { | 1460 { |
| 1461 if (LayoutStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPosition
Stretch) != ItemPositionStretch) | 1461 if (LayoutStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPosition
Stretch) != ItemPositionStretch) |
| 1462 return false; | 1462 return false; |
| 1463 | 1463 |
| 1464 return isHorizontalWritingMode() && child.style()->height().isAuto(); | 1464 return isHorizontalWritingMode() && child.style()->height().isAuto(); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. | 1467 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. |
| 1468 LayoutUnit RenderGrid::childIntrinsicHeight(const LayoutBox& child) const | 1468 LayoutUnit LayoutGrid::childIntrinsicHeight(const LayoutBox& child) const |
| 1469 { | 1469 { |
| 1470 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child
)) | 1470 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child
)) |
| 1471 return constrainedChildIntrinsicContentLogicalHeight(child); | 1471 return constrainedChildIntrinsicContentLogicalHeight(child); |
| 1472 return child.size().height(); | 1472 return child.size().height(); |
| 1473 } | 1473 } |
| 1474 | 1474 |
| 1475 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. | 1475 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. |
| 1476 LayoutUnit RenderGrid::childIntrinsicWidth(const LayoutBox& child) const | 1476 LayoutUnit LayoutGrid::childIntrinsicWidth(const LayoutBox& child) const |
| 1477 { | 1477 { |
| 1478 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil
d)) | 1478 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil
d)) |
| 1479 return constrainedChildIntrinsicContentLogicalHeight(child); | 1479 return constrainedChildIntrinsicContentLogicalHeight(child); |
| 1480 return child.size().width(); | 1480 return child.size().width(); |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. | 1483 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. |
| 1484 LayoutUnit RenderGrid::intrinsicLogicalHeightForChild(const LayoutBox& child) co
nst | 1484 LayoutUnit LayoutGrid::intrinsicLogicalHeightForChild(const LayoutBox& child) co
nst |
| 1485 { | 1485 { |
| 1486 return isHorizontalWritingMode() ? childIntrinsicHeight(child) : childIntrin
sicWidth(child); | 1486 return isHorizontalWritingMode() ? childIntrinsicHeight(child) : childIntrin
sicWidth(child); |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. | 1489 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. |
| 1490 LayoutUnit RenderGrid::marginLogicalHeightForChild(const LayoutBox& child) const | 1490 LayoutUnit LayoutGrid::marginLogicalHeightForChild(const LayoutBox& child) const |
| 1491 { | 1491 { |
| 1492 return isHorizontalWritingMode() ? child.marginHeight() : child.marginWidth(
); | 1492 return isHorizontalWritingMode() ? child.marginHeight() : child.marginWidth(
); |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 LayoutUnit RenderGrid::computeMarginLogicalHeightForChild(const LayoutBox& child
) const | 1495 LayoutUnit LayoutGrid::computeMarginLogicalHeightForChild(const LayoutBox& child
) const |
| 1496 { | 1496 { |
| 1497 LayoutUnit marginBefore; | 1497 LayoutUnit marginBefore; |
| 1498 LayoutUnit marginAfter; | 1498 LayoutUnit marginAfter; |
| 1499 child.computeMarginsForDirection(BlockDirection, this, child.containingBlock
LogicalWidthForContent(), child.logicalHeight(), marginBefore, marginAfter, | 1499 child.computeMarginsForDirection(BlockDirection, this, child.containingBlock
LogicalWidthForContent(), child.logicalHeight(), marginBefore, marginAfter, |
| 1500 child.style()->marginBeforeUsing(style()), | 1500 child.style()->marginBeforeUsing(style()), |
| 1501 child.style()->marginAfterUsing(style())); | 1501 child.style()->marginAfterUsing(style())); |
| 1502 | 1502 |
| 1503 return marginBefore + marginAfter; | 1503 return marginBefore + marginAfter; |
| 1504 } | 1504 } |
| 1505 | 1505 |
| 1506 LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUni
t gridAreaBreadthForChild, const LayoutBox& child) const | 1506 LayoutUnit LayoutGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUni
t gridAreaBreadthForChild, const LayoutBox& child) const |
| 1507 { | 1507 { |
| 1508 LayoutUnit childMarginLogicalHeight = marginLogicalHeightForChild(child); | 1508 LayoutUnit childMarginLogicalHeight = marginLogicalHeightForChild(child); |
| 1509 | 1509 |
| 1510 // Because we want to avoid multiple layouts, stretching logic might be perf
ormed before | 1510 // Because we want to avoid multiple layouts, stretching logic might be perf
ormed before |
| 1511 // children are laid out, so we can't use the child cached values. Hence, we
need to | 1511 // children are laid out, so we can't use the child cached values. Hence, we
need to |
| 1512 // compute margins in order to determine the available height before stretch
ing. | 1512 // compute margins in order to determine the available height before stretch
ing. |
| 1513 if (childMarginLogicalHeight == 0) | 1513 if (childMarginLogicalHeight == 0) |
| 1514 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); | 1514 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); |
| 1515 | 1515 |
| 1516 LayoutUnit childLogicalHeight = childMarginLogicalHeight + intrinsicLogicalH
eightForChild(child); | 1516 LayoutUnit childLogicalHeight = childMarginLogicalHeight + intrinsicLogicalH
eightForChild(child); |
| 1517 return gridAreaBreadthForChild - childLogicalHeight; | 1517 return gridAreaBreadthForChild - childLogicalHeight; |
| 1518 } | 1518 } |
| 1519 | 1519 |
| 1520 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. | 1520 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to La
youtBox. |
| 1521 void RenderGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn
it gridAreaBreadthForChild) | 1521 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn
it gridAreaBreadthForChild) |
| 1522 { | 1522 { |
| 1523 if (LayoutStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPosition
Stretch) != ItemPositionStretch) | 1523 if (LayoutStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPosition
Stretch) != ItemPositionStretch) |
| 1524 return; | 1524 return; |
| 1525 | 1525 |
| 1526 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1526 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
| 1527 if (allowedToStretchLogicalHeightForChild(child)) { | 1527 if (allowedToStretchLogicalHeightForChild(child)) { |
| 1528 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. | 1528 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. |
| 1529 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 1529 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. |
| 1530 if (!hasOrthogonalWritingMode) { | 1530 if (!hasOrthogonalWritingMode) { |
| 1531 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(
child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHei
ght(); | 1531 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(
child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHei
ght(); |
| 1532 LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availab
leAlignmentSpaceForChildBeforeStretching(gridAreaBreadthForChild, child); | 1532 LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availab
leAlignmentSpaceForChildBeforeStretching(gridAreaBreadthForChild, child); |
| 1533 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM
ax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogica
lHeight()); | 1533 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM
ax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogica
lHeight()); |
| 1534 LayoutUnit desiredLogicalContentHeight = desiredLogicalHeight - chil
d.borderAndPaddingLogicalHeight(); | 1534 LayoutUnit desiredLogicalContentHeight = desiredLogicalHeight - chil
d.borderAndPaddingLogicalHeight(); |
| 1535 | 1535 |
| 1536 // FIXME: Can avoid laying out here in some cases. See https://webki
t.org/b/87905. | 1536 // FIXME: Can avoid laying out here in some cases. See https://webki
t.org/b/87905. |
| 1537 if (desiredLogicalHeight != child.logicalHeight() || !child.hasOverr
ideHeight() || desiredLogicalContentHeight != child.overrideLogicalContentHeight
()) { | 1537 if (desiredLogicalHeight != child.logicalHeight() || !child.hasOverr
ideHeight() || desiredLogicalContentHeight != child.overrideLogicalContentHeight
()) { |
| 1538 child.setOverrideLogicalContentHeight(desiredLogicalContentHeigh
t); | 1538 child.setOverrideLogicalContentHeight(desiredLogicalContentHeigh
t); |
| 1539 child.setLogicalHeight(0); | 1539 child.setLogicalHeight(0); |
| 1540 child.forceChildLayout(); | 1540 child.forceChildLayout(); |
| 1541 } | 1541 } |
| 1542 } | 1542 } |
| 1543 } | 1543 } |
| 1544 } | 1544 } |
| 1545 | 1545 |
| 1546 LayoutUnit RenderGrid::rowPositionForChild(const LayoutBox& child) const | 1546 LayoutUnit LayoutGrid::rowPositionForChild(const LayoutBox& child) const |
| 1547 { | 1547 { |
| 1548 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1548 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
| 1549 switch (LayoutStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPosi
tionStretch)) { | 1549 switch (LayoutStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPosi
tionStretch)) { |
| 1550 case ItemPositionSelfStart: | 1550 case ItemPositionSelfStart: |
| 1551 // If orthogonal writing-modes, this computes to 'start'. | 1551 // If orthogonal writing-modes, this computes to 'start'. |
| 1552 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 1552 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. |
| 1553 if (hasOrthogonalWritingMode) | 1553 if (hasOrthogonalWritingMode) |
| 1554 return startOfRowForChild(child); | 1554 return startOfRowForChild(child); |
| 1555 | 1555 |
| 1556 // self-start is based on the child's block axis direction. That's why w
e need to check against the grid container's block flow. | 1556 // self-start is based on the child's block axis direction. That's why w
e need to check against the grid container's block flow. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 static inline LayoutUnit offsetToStartEdge(bool isLeftToRight, LayoutUnit availa
bleSpace) | 1633 static inline LayoutUnit offsetToStartEdge(bool isLeftToRight, LayoutUnit availa
bleSpace) |
| 1634 { | 1634 { |
| 1635 return isLeftToRight ? LayoutUnit(0) : availableSpace; | 1635 return isLeftToRight ? LayoutUnit(0) : availableSpace; |
| 1636 } | 1636 } |
| 1637 | 1637 |
| 1638 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl
eSpace) | 1638 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl
eSpace) |
| 1639 { | 1639 { |
| 1640 return !isLeftToRight ? LayoutUnit(0) : availableSpace; | 1640 return !isLeftToRight ? LayoutUnit(0) : availableSpace; |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 LayoutUnit RenderGrid::contentPositionAndDistributionColumnOffset(LayoutUnit ava
ilableFreeSpace, ContentPosition position, ContentDistributionType distribution,
OverflowAlignment overflow, unsigned numberOfGridTracks) const | 1643 LayoutUnit LayoutGrid::contentPositionAndDistributionColumnOffset(LayoutUnit ava
ilableFreeSpace, ContentPosition position, ContentDistributionType distribution,
OverflowAlignment overflow, unsigned numberOfGridTracks) const |
| 1644 { | 1644 { |
| 1645 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) | 1645 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) |
| 1646 return 0; | 1646 return 0; |
| 1647 | 1647 |
| 1648 // FIXME: for the time being, spec states that it will always fallback for G
rids, but | 1648 // FIXME: for the time being, spec states that it will always fallback for G
rids, but |
| 1649 // discussion is ongoing. | 1649 // discussion is ongoing. |
| 1650 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) | 1650 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) |
| 1651 position = resolveContentDistributionFallback(distribution); | 1651 position = resolveContentDistributionFallback(distribution); |
| 1652 | 1652 |
| 1653 switch (position) { | 1653 switch (position) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1671 // crbug.com/234191 | 1671 // crbug.com/234191 |
| 1672 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); | 1672 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); |
| 1673 case ContentPositionAuto: | 1673 case ContentPositionAuto: |
| 1674 break; | 1674 break; |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 ASSERT_NOT_REACHED(); | 1677 ASSERT_NOT_REACHED(); |
| 1678 return 0; | 1678 return 0; |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 LayoutUnit RenderGrid::contentPositionAndDistributionRowOffset(LayoutUnit availa
bleFreeSpace, ContentPosition position, ContentDistributionType distribution, Ov
erflowAlignment overflow, unsigned numberOfGridTracks) const | 1681 LayoutUnit LayoutGrid::contentPositionAndDistributionRowOffset(LayoutUnit availa
bleFreeSpace, ContentPosition position, ContentDistributionType distribution, Ov
erflowAlignment overflow, unsigned numberOfGridTracks) const |
| 1682 { | 1682 { |
| 1683 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) | 1683 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) |
| 1684 return 0; | 1684 return 0; |
| 1685 | 1685 |
| 1686 // FIXME: for the time being, spec states that it will always fallback for G
rids, but | 1686 // FIXME: for the time being, spec states that it will always fallback for G
rids, but |
| 1687 // discussion is ongoing. | 1687 // discussion is ongoing. |
| 1688 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) | 1688 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) |
| 1689 position = resolveContentDistributionFallback(distribution); | 1689 position = resolveContentDistributionFallback(distribution); |
| 1690 | 1690 |
| 1691 switch (position) { | 1691 switch (position) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1711 // crbug.com/234191 | 1711 // crbug.com/234191 |
| 1712 return 0; | 1712 return 0; |
| 1713 case ContentPositionAuto: | 1713 case ContentPositionAuto: |
| 1714 break; | 1714 break; |
| 1715 } | 1715 } |
| 1716 | 1716 |
| 1717 ASSERT_NOT_REACHED(); | 1717 ASSERT_NOT_REACHED(); |
| 1718 return 0; | 1718 return 0; |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 LayoutPoint RenderGrid::findChildLogicalPosition(const LayoutBox& child, LayoutS
ize contentAlignmentOffset) const | 1721 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, LayoutS
ize contentAlignmentOffset) const |
| 1722 { | 1722 { |
| 1723 LayoutUnit columnPosition = columnPositionForChild(child); | 1723 LayoutUnit columnPosition = columnPositionForChild(child); |
| 1724 // We stored m_columnPositions's data ignoring the direction, hence we might
need now | 1724 // We stored m_columnPositions's data ignoring the direction, hence we might
need now |
| 1725 // to translate positions from RTL to LTR, as it's more convenient for paint
ing. | 1725 // to translate positions from RTL to LTR, as it's more convenient for paint
ing. |
| 1726 if (!style()->isLeftToRightDirection()) | 1726 if (!style()->isLeftToRightDirection()) |
| 1727 columnPosition = (m_columnPositions[m_columnPositions.size() - 1] + bord
erAndPaddingLogicalLeft()) - columnPosition - child.logicalWidth(); | 1727 columnPosition = (m_columnPositions[m_columnPositions.size() - 1] + bord
erAndPaddingLogicalLeft()) - columnPosition - child.logicalWidth(); |
| 1728 | 1728 |
| 1729 // The Content Alignment offset accounts for the RTL to LTR flip. | 1729 // The Content Alignment offset accounts for the RTL to LTR flip. |
| 1730 LayoutPoint childLocation(columnPosition, rowPositionForChild(child)); | 1730 LayoutPoint childLocation(columnPosition, rowPositionForChild(child)); |
| 1731 childLocation.move(contentAlignmentOffset); | 1731 childLocation.move(contentAlignmentOffset); |
| 1732 | 1732 |
| 1733 return childLocation; | 1733 return childLocation; |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 void RenderGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) | 1736 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) |
| 1737 { | 1737 { |
| 1738 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1738 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 1739 } | 1739 } |
| 1740 | 1740 |
| 1741 const char* RenderGrid::renderName() const | 1741 const char* LayoutGrid::renderName() const |
| 1742 { | 1742 { |
| 1743 if (isFloating()) | 1743 if (isFloating()) |
| 1744 return "RenderGrid (floating)"; | 1744 return "LayoutGrid (floating)"; |
| 1745 if (isOutOfFlowPositioned()) | 1745 if (isOutOfFlowPositioned()) |
| 1746 return "RenderGrid (positioned)"; | 1746 return "LayoutGrid (positioned)"; |
| 1747 if (isAnonymous()) | 1747 if (isAnonymous()) |
| 1748 return "RenderGrid (generated)"; | 1748 return "LayoutGrid (generated)"; |
| 1749 if (isRelPositioned()) | 1749 if (isRelPositioned()) |
| 1750 return "RenderGrid (relative positioned)"; | 1750 return "LayoutGrid (relative positioned)"; |
| 1751 return "RenderGrid"; | 1751 return "LayoutGrid"; |
| 1752 } | 1752 } |
| 1753 | 1753 |
| 1754 } // namespace blink | 1754 } // namespace blink |
| OLD | NEW |