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

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

Issue 2832503003: [css-flex] Implement the space-evenly content-distribution value (Closed)
Patch Set: 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 | « third_party/WebKit/LayoutTests/css3/flexbox/true-centering.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 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 if (justify_content == kContentPositionFlexEnd) 1509 if (justify_content == kContentPositionFlexEnd)
1510 return available_free_space; 1510 return available_free_space;
1511 if (justify_content == kContentPositionCenter) 1511 if (justify_content == kContentPositionCenter)
1512 return available_free_space / 2; 1512 return available_free_space / 2;
1513 if (justify_content_distribution == kContentDistributionSpaceAround) { 1513 if (justify_content_distribution == kContentDistributionSpaceAround) {
1514 if (available_free_space > 0 && number_of_children) 1514 if (available_free_space > 0 && number_of_children)
1515 return available_free_space / (2 * number_of_children); 1515 return available_free_space / (2 * number_of_children);
1516 1516
1517 return available_free_space / 2; 1517 return available_free_space / 2;
1518 } 1518 }
1519 if (justify_content_distribution == kContentDistributionSpaceEvenly) {
1520 if (available_free_space > 0 && number_of_children)
1521 return available_free_space / (number_of_children + 1);
1522 // Fallback to 'center'
Manuel Rego 2017/04/20 08:57:06 Supernit: End comment with dot.
1523 return available_free_space / 2;
1524 }
1519 return LayoutUnit(); 1525 return LayoutUnit();
1520 } 1526 }
1521 1527
1522 static LayoutUnit JustifyContentSpaceBetweenChildren( 1528 static LayoutUnit JustifyContentSpaceBetweenChildren(
1523 LayoutUnit available_free_space, 1529 LayoutUnit available_free_space,
1524 ContentDistributionType justify_content_distribution, 1530 ContentDistributionType justify_content_distribution,
1525 unsigned number_of_children) { 1531 unsigned number_of_children) {
1526 if (available_free_space > 0 && number_of_children > 1) { 1532 if (available_free_space > 0 && number_of_children > 1) {
1527 if (justify_content_distribution == kContentDistributionSpaceBetween) 1533 if (justify_content_distribution == kContentDistributionSpaceBetween)
1528 return available_free_space / (number_of_children - 1); 1534 return available_free_space / (number_of_children - 1);
1529 if (justify_content_distribution == kContentDistributionSpaceAround) 1535 if (justify_content_distribution == kContentDistributionSpaceAround)
1530 return available_free_space / number_of_children; 1536 return available_free_space / number_of_children;
1537 if (justify_content_distribution == kContentDistributionSpaceEvenly)
1538 return available_free_space / (number_of_children + 1);
1531 } 1539 }
1532 return LayoutUnit(); 1540 return LayoutUnit();
1533 } 1541 }
1534 1542
1535 static LayoutUnit AlignmentOffset(LayoutUnit available_free_space, 1543 static LayoutUnit AlignmentOffset(LayoutUnit available_free_space,
1536 ItemPosition position, 1544 ItemPosition position,
1537 LayoutUnit ascent, 1545 LayoutUnit ascent,
1538 LayoutUnit max_ascent, 1546 LayoutUnit max_ascent,
1539 bool is_wrap_reverse) { 1547 bool is_wrap_reverse) {
1540 switch (position) { 1548 switch (position) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 if (align_content == kContentPositionFlexEnd) 1966 if (align_content == kContentPositionFlexEnd)
1959 return available_free_space; 1967 return available_free_space;
1960 if (align_content == kContentPositionCenter) 1968 if (align_content == kContentPositionCenter)
1961 return available_free_space / 2; 1969 return available_free_space / 2;
1962 if (align_content_distribution == kContentDistributionSpaceAround) { 1970 if (align_content_distribution == kContentDistributionSpaceAround) {
1963 if (available_free_space > 0 && number_of_lines) 1971 if (available_free_space > 0 && number_of_lines)
1964 return available_free_space / (2 * number_of_lines); 1972 return available_free_space / (2 * number_of_lines);
1965 if (available_free_space < 0) 1973 if (available_free_space < 0)
1966 return available_free_space / 2; 1974 return available_free_space / 2;
1967 } 1975 }
1976 if (align_content_distribution == kContentDistributionSpaceEvenly) {
1977 if (available_free_space > 0)
1978 return available_free_space / (number_of_lines + 1);
1979 // Fallback to 'center'
Manuel Rego 2017/04/20 08:57:06 Ditto.
1980 return available_free_space / 2;
1981 }
1968 return LayoutUnit(); 1982 return LayoutUnit();
1969 } 1983 }
1970 1984
1971 static LayoutUnit AlignContentSpaceBetweenChildren( 1985 static LayoutUnit AlignContentSpaceBetweenChildren(
1972 LayoutUnit available_free_space, 1986 LayoutUnit available_free_space,
1973 ContentDistributionType align_content_distribution, 1987 ContentDistributionType align_content_distribution,
1974 unsigned number_of_lines) { 1988 unsigned number_of_lines) {
1975 if (available_free_space > 0 && number_of_lines > 1) { 1989 if (available_free_space > 0 && number_of_lines > 1) {
1976 if (align_content_distribution == kContentDistributionSpaceBetween) 1990 if (align_content_distribution == kContentDistributionSpaceBetween)
1977 return available_free_space / (number_of_lines - 1); 1991 return available_free_space / (number_of_lines - 1);
1978 if (align_content_distribution == kContentDistributionSpaceAround || 1992 if (align_content_distribution == kContentDistributionSpaceAround ||
1979 align_content_distribution == kContentDistributionStretch) 1993 align_content_distribution == kContentDistributionStretch)
1980 return available_free_space / number_of_lines; 1994 return available_free_space / number_of_lines;
1995 if (align_content_distribution == kContentDistributionSpaceEvenly)
1996 return available_free_space / (number_of_lines + 1);
1981 } 1997 }
1982 return LayoutUnit(); 1998 return LayoutUnit();
1983 } 1999 }
1984 2000
1985 void LayoutFlexibleBox::AlignFlexLines(Vector<LineContext>& line_contexts) { 2001 void LayoutFlexibleBox::AlignFlexLines(Vector<LineContext>& line_contexts) {
1986 ContentPosition position = 2002 ContentPosition position =
1987 StyleRef().ResolvedAlignContentPosition(ContentAlignmentNormalBehavior()); 2003 StyleRef().ResolvedAlignContentPosition(ContentAlignmentNormalBehavior());
1988 ContentDistributionType distribution = 2004 ContentDistributionType distribution =
1989 StyleRef().ResolvedAlignContentDistribution( 2005 StyleRef().ResolvedAlignContentDistribution(
1990 ContentAlignmentNormalBehavior()); 2006 ContentAlignmentNormalBehavior());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 LayoutUnit original_offset = 2218 LayoutUnit original_offset =
2203 line_contexts[line_number].cross_axis_offset - cross_axis_start_edge; 2219 line_contexts[line_number].cross_axis_offset - cross_axis_start_edge;
2204 LayoutUnit new_offset = 2220 LayoutUnit new_offset =
2205 content_extent - original_offset - line_cross_axis_extent; 2221 content_extent - original_offset - line_cross_axis_extent;
2206 AdjustAlignmentForChild(*flex_item.box, new_offset - original_offset); 2222 AdjustAlignmentForChild(*flex_item.box, new_offset - original_offset);
2207 } 2223 }
2208 } 2224 }
2209 } 2225 }
2210 2226
2211 } // namespace blink 2227 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/css3/flexbox/true-centering.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698