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 |
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 bool has_collapsed_tracks = grid_.HasAutoRepeatEmptyTracks(direction); | |
1409 size_t number_of_collapsed_tracks = | |
1410 has_collapsed_tracks ? grid_.AutoRepeatEmptyTracks(direction)->size() : 0; | |
1408 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset( | 1411 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset( |
1409 direction, track_sizing_algorithm_.FreeSpace(direction).value(), | 1412 direction, track_sizing_algorithm_.FreeSpace(direction).value(), |
1410 number_of_tracks); | 1413 number_of_tracks - number_of_collapsed_tracks); |
1411 auto& positions = is_row_axis ? column_positions_ : row_positions_; | 1414 auto& positions = is_row_axis ? column_positions_ : row_positions_; |
1412 positions.Resize(number_of_lines); | 1415 positions.Resize(number_of_lines); |
1413 auto border_and_padding = | 1416 auto border_and_padding = |
1414 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore(); | 1417 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore(); |
1415 positions[0] = border_and_padding + offset.position_offset; | 1418 positions[0] = border_and_padding + offset.position_offset; |
1416 const Grid& grid = track_sizing_algorithm_.GetGrid(); | |
1417 if (number_of_lines > 1) { | 1419 if (number_of_lines > 1) { |
1418 // If we have collapsed tracks we just ignore gaps here and add them later | 1420 // 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 | 1421 // as we might not compute the gap between two consecutive tracks without |
1420 // examining the surrounding ones. | 1422 // examining the surrounding ones. |
1421 bool has_collapsed_tracks = grid.HasAutoRepeatEmptyTracks(direction); | |
1422 LayoutUnit gap = !has_collapsed_tracks ? GridGap(direction) : LayoutUnit(); | 1423 LayoutUnit gap = !has_collapsed_tracks ? GridGap(direction) : LayoutUnit(); |
1423 size_t next_to_last_line = number_of_lines - 2; | 1424 size_t next_to_last_line = number_of_lines - 2; |
1424 for (size_t i = 0; i < next_to_last_line; ++i) | 1425 for (size_t i = 0; i < next_to_last_line; ++i) |
1425 positions[i + 1] = positions[i] + offset.distribution_offset + | 1426 positions[i + 1] = positions[i] + offset.distribution_offset + |
1426 tracks[i].BaseSize() + gap; | 1427 tracks[i].BaseSize() + gap; |
1427 positions[last_line] = | 1428 positions[last_line] = |
1428 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize(); | 1429 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize(); |
1429 | 1430 |
1430 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to | 1431 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to |
1431 // collapse (they coincide exactly) except on the edges of the grid where | 1432 // collapse (they coincide exactly) except on the edges of the grid where |
1432 // they become 0. | 1433 // they become 0. |
1433 if (has_collapsed_tracks) { | 1434 if (has_collapsed_tracks) { |
1434 gap = GridGap(direction); | 1435 gap = GridGap(direction); |
1435 size_t remaining_empty_tracks = | 1436 size_t remaining_empty_tracks = number_of_collapsed_tracks; |
1436 grid.AutoRepeatEmptyTracks(direction)->size(); | 1437 size_t last_empty_track = 0; |
svillar
2017/04/25 15:12:25
Sorry for nitpicking but this name is unaccurate n
| |
1437 LayoutUnit gap_accumulator; | 1438 LayoutUnit gap_accumulator; |
1438 for (size_t i = 1; i < last_line; ++i) { | 1439 for (size_t i = 1; i < last_line; ++i) { |
1439 if (grid.IsEmptyAutoRepeatTrack(direction, i - 1)) { | 1440 if (grid_.IsEmptyAutoRepeatTrack(direction, i - 1)) { |
1440 --remaining_empty_tracks; | 1441 --remaining_empty_tracks; |
1442 ++last_empty_track; | |
1441 } else { | 1443 } else { |
1442 // Add gap between consecutive non empty tracks. Add it also just once | 1444 // 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. | 1445 // for an arbitrary number of empty tracks between two non empty ones. |
1444 bool all_remaining_tracks_are_empty = | 1446 bool all_remaining_tracks_are_empty = |
1445 remaining_empty_tracks == (last_line - i); | 1447 remaining_empty_tracks == (last_line - i); |
1446 if (!all_remaining_tracks_are_empty || | 1448 if (!all_remaining_tracks_are_empty || |
1447 !grid.IsEmptyAutoRepeatTrack(direction, i)) | 1449 !grid_.IsEmptyAutoRepeatTrack(direction, i)) |
1448 gap_accumulator += gap; | 1450 gap_accumulator += gap; |
1449 } | 1451 } |
1450 positions[i] += gap_accumulator; | 1452 positions[i] += |
1453 gap_accumulator - last_empty_track * offset.distribution_offset; | |
1451 } | 1454 } |
1452 positions[last_line] += gap_accumulator; | 1455 positions[last_line] += gap_accumulator; |
1453 } | 1456 } |
1454 } | 1457 } |
1455 auto& offset_between_tracks = | 1458 auto& offset_between_tracks = |
1456 is_row_axis ? offset_between_columns_ : offset_between_rows_; | 1459 is_row_axis ? offset_between_columns_ : offset_between_rows_; |
1457 offset_between_tracks = offset.distribution_offset; | 1460 offset_between_tracks = offset.distribution_offset; |
1458 } | 1461 } |
1459 | 1462 |
1460 static LayoutUnit ComputeOverflowAlignmentOffset(OverflowAlignment overflow, | 1463 static LayoutUnit ComputeOverflowAlignmentOffset(OverflowAlignment overflow, |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2389 if (direction == kForRows) | 2392 if (direction == kForRows) |
2390 return grid.NumTracks(kForRows); | 2393 return grid.NumTracks(kForRows); |
2391 | 2394 |
2392 return grid.NumTracks(kForRows) | 2395 return grid.NumTracks(kForRows) |
2393 ? grid.NumTracks(kForColumns) | 2396 ? grid.NumTracks(kForColumns) |
2394 : GridPositionsResolver::ExplicitGridColumnCount( | 2397 : GridPositionsResolver::ExplicitGridColumnCount( |
2395 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2398 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2396 } | 2399 } |
2397 | 2400 |
2398 } // namespace blink | 2401 } // namespace blink |
OLD | NEW |