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

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: Fixed error in the test expectations Created 3 years, 7 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 | « third_party/WebKit/LayoutTests/external/wpt/css/reference/ref-filled-green-300px-square.html ('k') | 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 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 // The grid container's frame elements (border, padding and <content-position> 1413 // The grid container's frame elements (border, padding and <content-position>
1414 // offset) are sensible to the inline-axis flow direction. However, column 1414 // offset) are sensible to the inline-axis flow direction. However, column
1415 // lines positions are 'direction' unaware. This simplification allows us to 1415 // lines positions are 'direction' unaware. This simplification allows us to
1416 // use the same indexes to identify the columns independently on the 1416 // use the same indexes to identify the columns independently on the
1417 // inline-axis direction. 1417 // inline-axis direction.
1418 bool is_row_axis = direction == kForColumns; 1418 bool is_row_axis = direction == kForColumns;
1419 auto& tracks = track_sizing_algorithm_.Tracks(direction); 1419 auto& tracks = track_sizing_algorithm_.Tracks(direction);
1420 size_t number_of_tracks = tracks.size(); 1420 size_t number_of_tracks = tracks.size();
1421 size_t number_of_lines = number_of_tracks + 1; 1421 size_t number_of_lines = number_of_tracks + 1;
1422 size_t last_line = number_of_lines - 1; 1422 size_t last_line = number_of_lines - 1;
1423 bool has_collapsed_tracks = grid_.HasAutoRepeatEmptyTracks(direction);
1424 size_t number_of_collapsed_tracks =
1425 has_collapsed_tracks ? grid_.AutoRepeatEmptyTracks(direction)->size() : 0;
1423 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset( 1426 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset(
1424 direction, track_sizing_algorithm_.FreeSpace(direction).value(), 1427 direction, track_sizing_algorithm_.FreeSpace(direction).value(),
1425 number_of_tracks); 1428 number_of_tracks - number_of_collapsed_tracks);
1426 auto& positions = is_row_axis ? column_positions_ : row_positions_; 1429 auto& positions = is_row_axis ? column_positions_ : row_positions_;
1427 positions.resize(number_of_lines); 1430 positions.resize(number_of_lines);
1428 auto border_and_padding = 1431 auto border_and_padding =
1429 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore(); 1432 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore();
1430 positions[0] = border_and_padding + offset.position_offset; 1433 positions[0] = border_and_padding + offset.position_offset;
1431 const Grid& grid = track_sizing_algorithm_.GetGrid();
1432 if (number_of_lines > 1) { 1434 if (number_of_lines > 1) {
1433 // If we have collapsed tracks we just ignore gaps here and add them later 1435 // If we have collapsed tracks we just ignore gaps here and add them later
1434 // as we might not compute the gap between two consecutive tracks without 1436 // as we might not compute the gap between two consecutive tracks without
1435 // examining the surrounding ones. 1437 // examining the surrounding ones.
1436 bool has_collapsed_tracks = grid.HasAutoRepeatEmptyTracks(direction);
1437 LayoutUnit gap = !has_collapsed_tracks ? GridGap(direction) : LayoutUnit(); 1438 LayoutUnit gap = !has_collapsed_tracks ? GridGap(direction) : LayoutUnit();
1438 size_t next_to_last_line = number_of_lines - 2; 1439 size_t next_to_last_line = number_of_lines - 2;
1439 for (size_t i = 0; i < next_to_last_line; ++i) 1440 for (size_t i = 0; i < next_to_last_line; ++i)
1440 positions[i + 1] = positions[i] + offset.distribution_offset + 1441 positions[i + 1] = positions[i] + offset.distribution_offset +
1441 tracks[i].BaseSize() + gap; 1442 tracks[i].BaseSize() + gap;
1442 positions[last_line] = 1443 positions[last_line] =
1443 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize(); 1444 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize();
1444 1445
1445 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to 1446 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to
1446 // collapse (they coincide exactly) except on the edges of the grid where 1447 // collapse (they coincide exactly) except on the edges of the grid where
1447 // they become 0. 1448 // they become 0.
1448 if (has_collapsed_tracks) { 1449 if (has_collapsed_tracks) {
1449 gap = GridGap(direction); 1450 gap = GridGap(direction);
1450 size_t remaining_empty_tracks = 1451 size_t remaining_empty_tracks = number_of_collapsed_tracks;
1451 grid.AutoRepeatEmptyTracks(direction)->size(); 1452 LayoutUnit offset_accumulator;
1452 LayoutUnit gap_accumulator; 1453 LayoutUnit gap_accumulator;
1453 for (size_t i = 1; i < last_line; ++i) { 1454 for (size_t i = 1; i < last_line; ++i) {
1454 if (grid.IsEmptyAutoRepeatTrack(direction, i - 1)) { 1455 if (grid_.IsEmptyAutoRepeatTrack(direction, i - 1)) {
1455 --remaining_empty_tracks; 1456 --remaining_empty_tracks;
1457 offset_accumulator += offset.distribution_offset;
1456 } else { 1458 } else {
1457 // Add gap between consecutive non empty tracks. Add it also just once 1459 // Add gap between consecutive non empty tracks. Add it also just once
1458 // for an arbitrary number of empty tracks between two non empty ones. 1460 // for an arbitrary number of empty tracks between two non empty ones.
1459 bool all_remaining_tracks_are_empty = 1461 bool all_remaining_tracks_are_empty =
1460 remaining_empty_tracks == (last_line - i); 1462 remaining_empty_tracks == (last_line - i);
1461 if (!all_remaining_tracks_are_empty || 1463 if (!all_remaining_tracks_are_empty ||
1462 !grid.IsEmptyAutoRepeatTrack(direction, i)) 1464 !grid_.IsEmptyAutoRepeatTrack(direction, i))
1463 gap_accumulator += gap; 1465 gap_accumulator += gap;
1464 } 1466 }
1465 positions[i] += gap_accumulator; 1467 positions[i] += gap_accumulator - offset_accumulator;
1466 } 1468 }
1467 positions[last_line] += gap_accumulator; 1469 positions[last_line] += gap_accumulator - offset_accumulator;
1468 } 1470 }
1469 } 1471 }
1470 auto& offset_between_tracks = 1472 auto& offset_between_tracks =
1471 is_row_axis ? offset_between_columns_ : offset_between_rows_; 1473 is_row_axis ? offset_between_columns_ : offset_between_rows_;
1472 offset_between_tracks = offset.distribution_offset; 1474 offset_between_tracks = offset.distribution_offset;
1473 } 1475 }
1474 1476
1475 static LayoutUnit ComputeOverflowAlignmentOffset(OverflowAlignment overflow, 1477 static LayoutUnit ComputeOverflowAlignmentOffset(OverflowAlignment overflow,
1476 LayoutUnit track_size, 1478 LayoutUnit track_size,
1477 LayoutUnit child_size) { 1479 LayoutUnit child_size) {
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 if (direction == kForRows) 2406 if (direction == kForRows)
2405 return grid.NumTracks(kForRows); 2407 return grid.NumTracks(kForRows);
2406 2408
2407 return grid.NumTracks(kForRows) 2409 return grid.NumTracks(kForRows)
2408 ? grid.NumTracks(kForColumns) 2410 ? grid.NumTracks(kForColumns)
2409 : GridPositionsResolver::ExplicitGridColumnCount( 2411 : GridPositionsResolver::ExplicitGridColumnCount(
2410 StyleRef(), grid.AutoRepeatTracks(kForColumns)); 2412 StyleRef(), grid.AutoRepeatTracks(kForColumns));
2411 } 2413 }
2412 2414
2413 } // namespace blink 2415 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/css/reference/ref-filled-green-300px-square.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698