| Index: ui/views/layout/box_layout.cc
|
| diff --git a/ui/views/layout/box_layout.cc b/ui/views/layout/box_layout.cc
|
| index f81fd68e3cbd6883abf200a59b64fbc39ebfe3bd..63a7faf290adec0593d64c5a72ce793da07b5229 100644
|
| --- a/ui/views/layout/box_layout.cc
|
| +++ b/ui/views/layout/box_layout.cc
|
| @@ -103,49 +103,8 @@ void BoxLayout::Layout(View* host) {
|
| int main_position = MainAxisPosition(child_area);
|
| int total_padding = 0;
|
| int current_flex = 0;
|
| - for (int i = 0; i < host->child_count(); ++i) {
|
| - View* child = host->child_at(i);
|
| - if (!child->visible())
|
| - continue;
|
| -
|
| - // Calculate cross axis size.
|
| - gfx::Rect bounds(child_area);
|
| - SetMainAxisPosition(main_position, &bounds);
|
| - if (cross_axis_alignment_ != CROSS_AXIS_ALIGNMENT_STRETCH) {
|
| - int free_space = CrossAxisSize(bounds) - CrossAxisSizeForView(child);
|
| - int position = CrossAxisPosition(bounds);
|
| - if (cross_axis_alignment_ == CROSS_AXIS_ALIGNMENT_CENTER) {
|
| - position += free_space / 2;
|
| - } else if (cross_axis_alignment_ == CROSS_AXIS_ALIGNMENT_END) {
|
| - position += free_space;
|
| - }
|
| - SetCrossAxisPosition(position, &bounds);
|
| - SetCrossAxisSize(CrossAxisSizeForView(child), &bounds);
|
| - }
|
| -
|
| - // Calculate flex padding.
|
| - int current_padding = 0;
|
| - if (GetFlexForView(child) > 0) {
|
| - current_flex += GetFlexForView(child);
|
| - int quot = (main_free_space * current_flex) / flex_sum;
|
| - int rem = (main_free_space * current_flex) % flex_sum;
|
| - current_padding = quot - total_padding;
|
| - // Use the current remainder to round to the nearest pixel.
|
| - if (std::abs(rem) * 2 >= flex_sum)
|
| - current_padding += main_free_space > 0 ? 1 : -1;
|
| - total_padding += current_padding;
|
| - }
|
| -
|
| - // Set main axis size.
|
| - int child_main_axis_size = MainAxisSizeForView(child, child_area.width());
|
| - SetMainAxisSize(child_main_axis_size + current_padding, &bounds);
|
| - if (MainAxisSize(bounds) > 0 || GetFlexForView(child) > 0)
|
| - main_position += MainAxisSize(bounds) + between_child_spacing_;
|
| -
|
| - // Clamp child view bounds to |child_area|.
|
| - bounds.Intersect(child_area);
|
| - child->SetBoundsRect(bounds);
|
| - }
|
| + LayoutChildren(host, child_area, main_free_space, flex_sum, main_position,
|
| + current_flex, &total_padding);
|
|
|
| // Flex views should have grown/shrunk to consume all free space.
|
| if (flex_sum)
|
| @@ -176,6 +135,68 @@ int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const {
|
| return GetPreferredSizeForChildWidth(host, child_width).height();
|
| }
|
|
|
| +void BoxLayout::LayoutChild(View* child,
|
| + const gfx::Rect& child_area,
|
| + int main_free_space,
|
| + int flex_sum,
|
| + int* main_position,
|
| + int* current_flex,
|
| + int* total_padding) {
|
| + // Calculate cross axis size.
|
| + gfx::Rect bounds(child_area);
|
| + SetMainAxisPosition(*main_position, &bounds);
|
| + if (cross_axis_alignment_ != CROSS_AXIS_ALIGNMENT_STRETCH) {
|
| + int free_space = CrossAxisSize(bounds) - CrossAxisSizeForView(child);
|
| + int position = CrossAxisPosition(bounds);
|
| + if (cross_axis_alignment_ == CROSS_AXIS_ALIGNMENT_CENTER) {
|
| + position += free_space / 2;
|
| + } else if (cross_axis_alignment_ == CROSS_AXIS_ALIGNMENT_END) {
|
| + position += free_space;
|
| + }
|
| + SetCrossAxisPosition(position, &bounds);
|
| + SetCrossAxisSize(CrossAxisSizeForView(child), &bounds);
|
| + }
|
| +
|
| + // Calculate flex padding.
|
| + int current_padding = 0;
|
| + if (GetFlexForView(child) > 0) {
|
| + *current_flex += GetFlexForView(child);
|
| + int quot = (main_free_space * *current_flex) / flex_sum;
|
| + int rem = (main_free_space * *current_flex) % flex_sum;
|
| + current_padding = quot - *total_padding;
|
| + // Use the current remainder to round to the nearest pixel.
|
| + if (std::abs(rem) * 2 >= flex_sum)
|
| + current_padding += main_free_space > 0 ? 1 : -1;
|
| + *total_padding += current_padding;
|
| + }
|
| +
|
| + // Set main axis size.
|
| + int child_main_axis_size = MainAxisSizeForView(child, child_area.width());
|
| + SetMainAxisSize(child_main_axis_size + current_padding, &bounds);
|
| + if (MainAxisSize(bounds) > 0 || GetFlexForView(child) > 0)
|
| + *main_position += MainAxisSize(bounds) + between_child_spacing_;
|
| +
|
| + // Clamp child view bounds to |child_area|.
|
| + bounds.Intersect(child_area);
|
| + child->SetBoundsRect(bounds);
|
| +}
|
| +
|
| +void BoxLayout::LayoutChildren(View* host,
|
| + const gfx::Rect& child_area,
|
| + int main_free_space,
|
| + int flex_sum,
|
| + int main_position,
|
| + int current_flex,
|
| + int* total_padding) {
|
| + for (int i = 0; i < host->child_count(); ++i) {
|
| + View* child = host->child_at(i);
|
| + if (!child->visible())
|
| + continue;
|
| + LayoutChild(child, child_area, main_free_space, flex_sum, &main_position,
|
| + ¤t_flex, total_padding);
|
| + }
|
| +}
|
| +
|
| void BoxLayout::Installed(View* host) {
|
| DCHECK(!host_);
|
| host_ = host;
|
|
|