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 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1359 // Since we add alignment offsets and track gutters, grid lines are not always | 1359 // Since we add alignment offsets and track gutters, grid lines are not always |
1360 // adjacent. Hence we will have to assume from now on that we just store | 1360 // adjacent. Hence we will have to assume from now on that we just store |
1361 // positions of the initial grid lines of each track, except the last one, | 1361 // positions of the initial grid lines of each track, except the last one, |
1362 // which is the only one considered as a final grid line of a track. | 1362 // which is the only one considered as a final grid line of a track. |
1363 | 1363 |
1364 // The grid container's frame elements (border, padding and <content-position> | 1364 // The grid container's frame elements (border, padding and <content-position> |
1365 // offset) are sensible to the inline-axis flow direction. However, column | 1365 // offset) are sensible to the inline-axis flow direction. However, column |
1366 // lines positions are 'direction' unaware. This simplification allows us to | 1366 // lines positions are 'direction' unaware. This simplification allows us to |
1367 // use the same indexes to identify the columns independently on the | 1367 // use the same indexes to identify the columns independently on the |
1368 // inline-axis direction. | 1368 // inline-axis direction. |
1369 auto& grid = track_sizing_algorithm_.GetGrid(); | |
svillar
2017/04/20 08:49:37
You don't need to do this. You already have grid_
| |
1369 bool is_row_axis = direction == kForColumns; | 1370 bool is_row_axis = direction == kForColumns; |
1370 auto& tracks = track_sizing_algorithm_.Tracks(direction); | 1371 auto& tracks = track_sizing_algorithm_.Tracks(direction); |
1371 size_t number_of_tracks = tracks.size(); | 1372 size_t number_of_tracks = tracks.size(); |
1372 size_t number_of_lines = number_of_tracks + 1; | 1373 size_t number_of_lines = number_of_tracks + 1; |
1373 size_t last_line = number_of_lines - 1; | 1374 size_t last_line = number_of_lines - 1; |
1375 size_t number_of_non_empty_tracks = number_of_tracks; | |
1376 size_t number_of_collapsed_tracks = 0; | |
1377 bool has_collapsed_tracks = grid.HasAutoRepeatEmptyTracks(direction); | |
1378 if (has_collapsed_tracks) { | |
1379 number_of_collapsed_tracks = grid.AutoRepeatEmptyTracks(direction)->size(); | |
1380 number_of_non_empty_tracks -= number_of_collapsed_tracks; | |
1381 } | |
Manuel Rego
2017/04/19 10:33:51
Nit: I think you can change this by something like
jfernandez
2017/04/19 11:05:51
yes, I thought about that, but with this new code
Manuel Rego
2017/04/19 11:46:08
Yeah, I didn't realize. Good point.
svillar
2017/04/20 08:49:36
Adding one arithmetic operation per layout is not
jfernandez
2017/04/20 17:29:47
Acknowledged.
| |
1374 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset( | 1382 ContentAlignmentData offset = ComputeContentPositionAndDistributionOffset( |
1375 direction, track_sizing_algorithm_.FreeSpace(direction).value(), | 1383 direction, track_sizing_algorithm_.FreeSpace(direction).value(), |
1376 number_of_tracks); | 1384 number_of_non_empty_tracks); |
1377 auto& positions = is_row_axis ? column_positions_ : row_positions_; | 1385 auto& positions = is_row_axis ? column_positions_ : row_positions_; |
1378 positions.Resize(number_of_lines); | 1386 positions.Resize(number_of_lines); |
1379 auto border_and_padding = | 1387 auto border_and_padding = |
1380 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore(); | 1388 is_row_axis ? BorderAndPaddingLogicalLeft() : BorderAndPaddingBefore(); |
1381 positions[0] = border_and_padding + offset.position_offset; | 1389 positions[0] = border_and_padding + offset.position_offset; |
1382 const Grid& grid = track_sizing_algorithm_.GetGrid(); | |
1383 if (number_of_lines > 1) { | 1390 if (number_of_lines > 1) { |
1384 // If we have collapsed tracks we just ignore gaps here and add them later | 1391 // If we have collapsed tracks we just ignore gaps here and add them later |
1385 // as we might not compute the gap between two consecutive tracks without | 1392 // as we might not compute the gap between two consecutive tracks without |
1386 // examining the surrounding ones. | 1393 // examining the surrounding ones. |
1387 bool has_collapsed_tracks = grid.HasAutoRepeatEmptyTracks(direction); | |
1388 LayoutUnit gap = !has_collapsed_tracks | 1394 LayoutUnit gap = !has_collapsed_tracks |
1389 ? GridGapForDirection(direction, kTrackSizing) | 1395 ? GridGapForDirection(direction, kTrackSizing) |
1390 : LayoutUnit(); | 1396 : LayoutUnit(); |
1391 size_t next_to_last_line = number_of_lines - 2; | 1397 size_t next_to_last_line = number_of_lines - 2; |
1392 for (size_t i = 0; i < next_to_last_line; ++i) | 1398 for (size_t i = 0; i < next_to_last_line; ++i) { |
1393 positions[i + 1] = positions[i] + offset.distribution_offset + | 1399 positions[i + 1] = positions[i] + tracks[i].BaseSize() + gap; |
1394 tracks[i].BaseSize() + gap; | 1400 if (!has_collapsed_tracks || |
1401 !grid.IsEmptyAutoRepeatTrack(direction, i + 1)) | |
svillar
2017/04/20 08:49:37
In contrast this might be potentially problematic
jfernandez
2017/04/20 17:29:47
Only in the case that there are collapsed tracks.
svillar
2017/04/21 07:37:51
No because as you said 0px is a valid value for ro
| |
1402 positions[i + 1] += offset.distribution_offset; | |
1403 } | |
1395 positions[last_line] = | 1404 positions[last_line] = |
1396 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize(); | 1405 positions[next_to_last_line] + tracks[next_to_last_line].BaseSize(); |
1397 | 1406 |
1398 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to | 1407 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters to |
1399 // collapse (they coincide exactly) except on the edges of the grid where | 1408 // collapse (they coincide exactly) except on the edges of the grid where |
1400 // they become 0. | 1409 // they become 0. |
1401 if (has_collapsed_tracks) { | 1410 if (has_collapsed_tracks) { |
1402 gap = GridGapForDirection(direction, kTrackSizing); | 1411 gap = GridGapForDirection(direction, kTrackSizing); |
1403 size_t remaining_empty_tracks = | 1412 size_t remaining_empty_tracks = number_of_collapsed_tracks; |
Manuel Rego
2017/04/19 10:33:51
We're mixing "collapsed" and "empty" terms...
Not
jfernandez
2017/04/19 11:05:51
Im using the old notation, hence if we want to ren
| |
1404 grid.AutoRepeatEmptyTracks(direction)->size(); | |
1405 LayoutUnit gap_accumulator; | 1413 LayoutUnit gap_accumulator; |
1406 for (size_t i = 1; i < last_line; ++i) { | 1414 for (size_t i = 1; i < last_line; ++i) { |
1407 if (grid.IsEmptyAutoRepeatTrack(direction, i - 1)) { | 1415 if (grid.IsEmptyAutoRepeatTrack(direction, i - 1)) { |
1408 --remaining_empty_tracks; | 1416 --remaining_empty_tracks; |
1409 } else { | 1417 } else { |
1410 // Add gap between consecutive non empty tracks. Add it also just once | 1418 // Add gap between consecutive non empty tracks. Add it also just once |
1411 // for an arbitrary number of empty tracks between two non empty ones. | 1419 // for an arbitrary number of empty tracks between two non empty ones. |
1412 bool all_remaining_tracks_are_empty = | 1420 bool all_remaining_tracks_are_empty = |
1413 remaining_empty_tracks == (last_line - i); | 1421 remaining_empty_tracks == (last_line - i); |
1414 if (!all_remaining_tracks_are_empty || | 1422 if (!all_remaining_tracks_are_empty || |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2357 if (direction == kForRows) | 2365 if (direction == kForRows) |
2358 return grid.NumTracks(kForRows); | 2366 return grid.NumTracks(kForRows); |
2359 | 2367 |
2360 return grid.NumTracks(kForRows) | 2368 return grid.NumTracks(kForRows) |
2361 ? grid.NumTracks(kForColumns) | 2369 ? grid.NumTracks(kForColumns) |
2362 : GridPositionsResolver::ExplicitGridColumnCount( | 2370 : GridPositionsResolver::ExplicitGridColumnCount( |
2363 StyleRef(), grid.AutoRepeatTracks(kForColumns)); | 2371 StyleRef(), grid.AutoRepeatTracks(kForColumns)); |
2364 } | 2372 } |
2365 | 2373 |
2366 } // namespace blink | 2374 } // namespace blink |
OLD | NEW |