Changeset 164609 in webkit for trunk/Source/WebCore/rendering/RenderGrid.cpp
- Timestamp:
- Feb 24, 2014, 2:29:20 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/Source/WebCore/rendering/RenderGrid.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/rendering/RenderGrid.cpp
r164214 r164609 223 223 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 224 224 LayoutUnit availableLogicalSpace = 0; 225 const_cast<RenderGrid*>(this)->compute dUsedBreadthOfGridTracks(ForColumns, sizingData, availableLogicalSpace);225 const_cast<RenderGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableLogicalSpace); 226 226 227 227 for (size_t i = 0; i < sizingData.columnTracks.size(); ++i) { … … 258 258 } 259 259 260 void RenderGrid::compute dUsedBreadthOfGridTracks(GridTrackSizingDirection direction, GridSizingData& sizingData)260 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection direction, GridSizingData& sizingData) 261 261 { 262 262 LayoutUnit availableLogicalSpace = (direction == ForColumns) ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); 263 computedUsedBreadthOfGridTracks(direction, sizingData, availableLogicalSpace); 264 } 265 266 void RenderGrid::computedUsedBreadthOfGridTracks(GridTrackSizingDirection direction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) 263 computeUsedBreadthOfGridTracks(direction, sizingData, availableLogicalSpace); 264 } 265 266 bool RenderGrid::gridElementIsShrinkToFit() 267 { 268 return isFloatingOrOutOfFlowPositioned(); 269 } 270 271 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection direction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) 267 272 { 268 273 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTracks : sizingData.rowTracks; 274 Vector<size_t> flexibleSizedTracksIndex; 269 275 sizingData.contentSizedTracksIndex.shrink(0); 276 277 // 1. Initialize per Grid track variables. 270 278 for (size_t i = 0; i < tracks.size(); ++i) { 271 279 GridTrack& track = tracks[i]; … … 281 289 if (trackSize.isContentSized()) 282 290 sizingData.contentSizedTracksIndex.append(i); 283 } 284 291 if (trackSize.maxTrackBreadth().isFlex()) 292 flexibleSizedTracksIndex.append(i); 293 } 294 295 // 2. Resolve content-based TrackSizingFunctions. 285 296 if (!sizingData.contentSizedTracksIndex.isEmpty()) 286 297 resolveContentBasedTrackSizingFunctions(direction, sizingData); … … 291 302 } 292 303 293 if (availableLogicalSpace <= 0) 304 const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style().logicalHeight().isAuto() : gridElementIsShrinkToFit(); 305 306 if (!hasUndefinedRemainingSpace && availableLogicalSpace <= 0) 294 307 return; 295 308 309 // 3. Grow all Grid tracks in GridTracks from their UsedBreadth up to their MaxBreadth value until 310 // availableLogicalSpace (RemainingSpace in the specs) is exhausted. 296 311 const size_t tracksSize = tracks.size(); 297 Vector<GridTrack*> tracksForDistribution(tracksSize); 298 for (size_t i = 0; i < tracksSize; ++i) 299 tracksForDistribution[i] = tracks.data() + i; 300 301 distributeSpaceToTracks(tracksForDistribution, 0, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth, sizingData, availableLogicalSpace); 312 if (!hasUndefinedRemainingSpace) { 313 Vector<GridTrack*> tracksForDistribution(tracksSize); 314 for (size_t i = 0; i < tracksSize; ++i) 315 tracksForDistribution[i] = tracks.data() + i; 316 317 distributeSpaceToTracks(tracksForDistribution, 0, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth, sizingData, availableLogicalSpace); 318 } else { 319 for (size_t i = 0; i < tracksSize; ++i) 320 tracks[i].m_usedBreadth = tracks[i].m_maxBreadth; 321 } 322 323 if (flexibleSizedTracksIndex.isEmpty()) 324 return; 302 325 303 326 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. 304 305 // FIXME: Handle the case where RemainingSpace is not defined. 306 double normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, direction, availableLogicalSpace); 307 for (size_t i = 0; i < tracksSize; ++i) { 308 const GridTrackSize& trackSize = gridTrackSize(direction, i); 309 if (!trackSize.maxTrackBreadth().isFlex()) 310 continue; 311 312 tracks[i].m_usedBreadth = std::max<LayoutUnit>(tracks[i].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()); 327 double normalizedFractionBreadth = 0; 328 if (!hasUndefinedRemainingSpace) 329 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, GridSpan(0, tracks.size() - 1), direction, availableLogicalSpace); 330 else { 331 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { 332 const size_t trackIndex = flexibleSizedTracksIndex[i]; 333 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex); 334 normalizedFractionBreadth = std::max(normalizedFractionBreadth, tracks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); 335 } 336 337 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { 338 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]); 339 while (RenderBox* gridItem = iterator.nextGridItem()) { 340 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); 341 const GridSpan span = (direction == ForColumns) ? coordinate.columns : coordinate.rows; 342 343 // Do not include already processed items. 344 if (i > 0 && span.initialPositionIndex <= flexibleSizedTracksIndex[i - 1]) 345 continue; 346 347 double itemNormalizedFlexBreadth = computeNormalizedFractionBreadth(tracks, span, direction, maxContentForChild(gridItem, direction, sizingData.columnTracks)); 348 normalizedFractionBreadth = std::max(normalizedFractionBreadth, itemNormalizedFlexBreadth); 349 } 350 } 351 } 352 353 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { 354 const size_t trackIndex = flexibleSizedTracksIndex[i]; 355 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex); 356 357 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackIndex].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()); 313 358 } 314 359 } … … 351 396 } 352 397 353 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, GridTrackSizingDirection direction, LayoutUnit availableLogicalSpace) const398 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, const GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availableLogicalSpace) const 354 399 { 355 400 // |availableLogicalSpace| already accounts for the used breadths so no need to remove it here. 356 401 357 402 Vector<GridTrackForNormalization> tracksForNormalization; 358 for (size_t i = 0; i < tracks.size(); ++i) {403 for (size_t i = tracksSpan.initialPositionIndex; i <= tracksSpan.finalPositionIndex; ++i) { 359 404 const GridTrackSize& trackSize = gridTrackSize(direction, i); 360 405 if (!trackSize.maxTrackBreadth().isFlex()) … … 364 409 } 365 410 366 // FIXME: Ideally we shouldn't come here without any <flex> grid track. 367 if (tracksForNormalization.isEmpty()) 368 return LayoutUnit(); 411 // The function is not called if we don't have <flex> grid tracks 412 ASSERT(!tracksForNormalization.isEmpty()); 369 413 370 414 std::sort(tracksForNormalization.begin(), tracksForNormalization.end(), … … 749 793 750 794 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 751 compute dUsedBreadthOfGridTracks(ForColumns, sizingData);795 computeUsedBreadthOfGridTracks(ForColumns, sizingData); 752 796 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks)); 753 compute dUsedBreadthOfGridTracks(ForRows, sizingData);797 computeUsedBreadthOfGridTracks(ForRows, sizingData); 754 798 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); 755 799
Note:
See TracChangeset
for help on using the changeset viewer.