Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 2825133003: [css-grid] Ignore collapsed tracks on content-distribution alignment (Closed)
Patch Set: Applied suggested changes. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 // The grid container's frame elements (border, padding and <content-position> 1398 // The grid container's frame elements (border, padding and <content-position>
1399 // offset) are sensible to the inline-axis flow direction. However, column 1399 // offset) are sensible to the inline-axis flow direction. However, column
1400 // lines positions are 'direction' unaware. This simplification allows us to 1400 // lines positions are 'direction' unaware. This simplification allows us to
1401 // use the same indexes to identify the columns independently on the 1401 // use the same indexes to identify the columns independently on the
1402 // inline-axis direction. 1402 // inline-axis direction.
1403 bool is_row_axis = direction == kForColumns; 1403 bool is_row_axis = direction == kForColumns;
1404 auto& tracks = track_sizing_algorithm_.Tracks(direction); 1404 auto& tracks = track_sizing_algorithm_.Tracks(direction);
1405 size_t number_of_tracks = tracks.size(); 1405 size_t number_of_tracks = tracks.size();
1406 size_t number_of_lines = number_of_tracks + 1; 1406 size_t number_of_lines = number_of_tracks + 1;
1407 size_t last_line = number_of_lines - 1; 1407 size_t last_line = number_of_lines - 1;
1408 auto& grid = track_sizing_algorithm_.GetGrid();
svillar 2017/04/25 08:03:29 Same comment, I know this was already here, but yo
1409 bool has_collapsed_tracks = grid.HasAutoRepeatEmptyTracks(direction);
1410 size_t number_of_collapsed_tracks =
1411 has_collapsed_tracks ? grid.AutoRepeatEmptyTracks(direction)->size() : 0;
1408 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset( 1412 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset(
1409 direction, track_sizing_algorithm_.FreeSpace(direction).value(), 1413 direction, track_sizing_algorithm_.FreeSpace(direction).value(),
1410 number_of_tracks); 1414 number_of_tracks - number_of_collapsed_tracks);
1411 auto& positions = is_row_axis ? column_positions_ : row_positions_; 1415 auto& positions = is_row_axis ? column_positions_ : row_positions_;
1412 positions.Resize(number_of_lines); 1416 positions.Resize(number_of_lines);
1413 auto border_and_padding = 1417 auto border_and_padding =
1414 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore(); 1418 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore();
1415 positions[0] = border_and_padding + offset.position_offset; 1419 positions[0] = border_and_padding + offset.position_offset;
1416 const Grid& grid = track_sizing_algorithm_.GetGrid();
1417 if (number_of_lines > 1) { 1420 if (number_of_lines > 1) {
1418 // If we have collapsed tracks we just ignore gaps here and add them later 1421 // If we have collapsed tracks we just ignore gaps here and add them later
1419 // as we might not compute the gap between two consecutive tracks without 1422 // as we might not compute the gap between two consecutive tracks without
1420 // examining the surrounding ones. 1423 // examining the surrounding ones.
1421 bool has_collapsed_tracks = grid.HasAutoRepeatEmptyTracks(direction);
1422 LayoutUnit gap = !has_collapsed_tracks ? GridGap(direction) : LayoutUnit(); 1424 LayoutUnit gap = !has_collapsed_tracks ? GridGap(direction) : LayoutUnit();
1423 size_t next_to_last_line = number_of_lines - 2; 1425 size_t next_to_last_line = number_of_lines - 2;
1424 for (size_t i = 0; i < next_to_last_line; ++i) 1426 for (size_t i = 0; i < next_to_last_line; ++i)
1425 positions[i + 1] = positions[i] + offset.distribution_offset + 1427 positions[i + 1] = positions[i] + offset.distribution_offset +
1426 tracks[i].BaseSize() + gap; 1428 tracks[i].BaseSize() + gap;
1427 positions[last_line] = 1429 positions[last_line] =
1428 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize(); 1430 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize();
1429 1431
1430 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to 1432 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to
1431 // collapse (they coincide exactly) except on the edges of the grid where 1433 // collapse (they coincide exactly) except on the edges of the grid where
1432 // they become 0. 1434 // they become 0.
1433 if (has_collapsed_tracks) { 1435 if (has_collapsed_tracks) {
1434 gap = GridGap(direction); 1436 gap = GridGap(direction);
1435 size_t remaining_empty_tracks = 1437 size_t remaining_empty_tracks = number_of_collapsed_tracks;
1436 grid.AutoRepeatEmptyTracks(direction)->size(); 1438 size_t last_empty_track = 0;
1437 LayoutUnit gap_accumulator; 1439 LayoutUnit gap_accumulator;
1438 for (size_t i = 1; i < last_line; ++i) { 1440 for (size_t i = 1; i < last_line; ++i) {
1439 if (grid.IsEmptyAutoRepeatTrack(direction, i - 1)) { 1441 if (grid.IsEmptyAutoRepeatTrack(direction, i - 1)) {
1440 --remaining_empty_tracks; 1442 --remaining_empty_tracks;
1443 last_empty_track = i - 1;
1441 } else { 1444 } else {
1442 // Add gap between consecutive non empty tracks. Add it also just once 1445 // Add gap between consecutive non empty tracks. Add it also just once
1443 // for an arbitrary number of empty tracks between two non empty ones. 1446 // for an arbitrary number of empty tracks between two non empty ones.
1444 bool all_remaining_tracks_are_empty = 1447 bool all_remaining_tracks_are_empty =
1445 remaining_empty_tracks == (last_line - i); 1448 remaining_empty_tracks == (last_line - i);
1446 if (!all_remaining_tracks_are_empty || 1449 if (!all_remaining_tracks_are_empty ||
1447 !grid.IsEmptyAutoRepeatTrack(direction, i)) 1450 !grid.IsEmptyAutoRepeatTrack(direction, i))
1448 gap_accumulator += gap; 1451 gap_accumulator += gap;
1449 } 1452 }
1450 positions[i] += gap_accumulator; 1453 positions[i] +=
1454 gap_accumulator - last_empty_track * offset.distribution_offset;
svillar 2017/04/25 08:03:29 I think this is wrong. Instead of the last empty t
1451 } 1455 }
1452 positions[last_line] += gap_accumulator; 1456 positions[last_line] += gap_accumulator;
1453 } 1457 }
1454 } 1458 }
1455 auto& offset_between_tracks = 1459 auto& offset_between_tracks =
1456 is_row_axis ? offset_between_columns_ : offset_between_rows_; 1460 is_row_axis ? offset_between_columns_ : offset_between_rows_;
1457 offset_between_tracks = offset.distribution_offset; 1461 offset_between_tracks = offset.distribution_offset;
1458 } 1462 }
1459 1463
1460 static LayoutUnit ComputeOverflowAlignmentOffset(OverflowAlignment overflow, 1464 static LayoutUnit ComputeOverflowAlignmentOffset(OverflowAlignment overflow,
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 if (direction == kForRows) 2393 if (direction == kForRows)
2390 return grid.NumTracks(kForRows); 2394 return grid.NumTracks(kForRows);
2391 2395
2392 return grid.NumTracks(kForRows) 2396 return grid.NumTracks(kForRows)
2393 ? grid.NumTracks(kForColumns) 2397 ? grid.NumTracks(kForColumns)
2394 : GridPositionsResolver::ExplicitGridColumnCount( 2398 : GridPositionsResolver::ExplicitGridColumnCount(
2395 StyleRef(), grid.AutoRepeatTracks(kForColumns)); 2399 StyleRef(), grid.AutoRepeatTracks(kForColumns));
2396 } 2400 }
2397 2401
2398 } // namespace blink 2402 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698