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

Side by Side Diff: ui/views/layout/box_layout.cc

Issue 1422703004: BoxLayout: Added set_collapse_when_hidden(), like views::Label. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@exclusiveaccess-minor-refactor
Patch Set: Created 5 years, 1 month 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 | « ui/views/layout/box_layout.h ('k') | ui/views/layout/box_layout_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/layout/box_layout.h" 5 #include "ui/views/layout/box_layout.h"
6 6
7 #include "ui/gfx/geometry/rect.h" 7 #include "ui/gfx/geometry/rect.h"
8 #include "ui/views/view.h" 8 #include "ui/views/view.h"
9 9
10 namespace views { 10 namespace views {
11 11
12 BoxLayout::BoxLayout(BoxLayout::Orientation orientation, 12 BoxLayout::BoxLayout(BoxLayout::Orientation orientation,
13 int inside_border_horizontal_spacing, 13 int inside_border_horizontal_spacing,
14 int inside_border_vertical_spacing, 14 int inside_border_vertical_spacing,
15 int between_child_spacing) 15 int between_child_spacing)
16 : orientation_(orientation), 16 : orientation_(orientation),
17 inside_border_insets_(inside_border_vertical_spacing, 17 inside_border_insets_(inside_border_vertical_spacing,
18 inside_border_horizontal_spacing, 18 inside_border_horizontal_spacing,
19 inside_border_vertical_spacing, 19 inside_border_vertical_spacing,
20 inside_border_horizontal_spacing), 20 inside_border_horizontal_spacing),
21 between_child_spacing_(between_child_spacing), 21 between_child_spacing_(between_child_spacing),
22 main_axis_alignment_(MAIN_AXIS_ALIGNMENT_START), 22 main_axis_alignment_(MAIN_AXIS_ALIGNMENT_START),
23 cross_axis_alignment_(CROSS_AXIS_ALIGNMENT_STRETCH), 23 cross_axis_alignment_(CROSS_AXIS_ALIGNMENT_STRETCH),
24 default_flex_(0), 24 default_flex_(0),
25 minimum_cross_axis_size_(0), 25 minimum_cross_axis_size_(0),
26 collapse_when_hidden_(false),
26 host_(NULL) { 27 host_(NULL) {
27 } 28 }
28 29
29 BoxLayout::~BoxLayout() { 30 BoxLayout::~BoxLayout() {
30 } 31 }
31 32
32 void BoxLayout::SetFlexForView(const View* view, int flex_weight) { 33 void BoxLayout::SetFlexForView(const View* view, int flex_weight) {
33 DCHECK(host_); 34 DCHECK(host_);
34 DCHECK(view); 35 DCHECK(view);
35 DCHECK_EQ(host_, view->parent()); 36 DCHECK_EQ(host_, view->parent());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 child->SetBoundsRect(bounds); 150 child->SetBoundsRect(bounds);
150 } 151 }
151 152
152 // Flex views should have grown/shrunk to consume all free space. 153 // Flex views should have grown/shrunk to consume all free space.
153 if (flex_sum) 154 if (flex_sum)
154 DCHECK_EQ(total_padding, main_free_space); 155 DCHECK_EQ(total_padding, main_free_space);
155 } 156 }
156 157
157 gfx::Size BoxLayout::GetPreferredSize(const View* host) const { 158 gfx::Size BoxLayout::GetPreferredSize(const View* host) const {
158 DCHECK_EQ(host_, host); 159 DCHECK_EQ(host_, host);
160 if (!host->visible() && collapse_when_hidden_)
161 return gfx::Size();
162
159 // Calculate the child views' preferred width. 163 // Calculate the child views' preferred width.
160 int width = 0; 164 int width = 0;
161 if (orientation_ == kVertical) { 165 if (orientation_ == kVertical) {
162 for (int i = 0; i < host->child_count(); ++i) { 166 for (int i = 0; i < host->child_count(); ++i) {
163 const View* child = host->child_at(i); 167 const View* child = host->child_at(i);
164 if (!child->visible()) 168 if (!child->visible())
165 continue; 169 continue;
sadrul 2015/10/29 17:57:29 Most layout-managers currently explicitly check fo
Matt Giuca 2015/11/05 05:36:58 I think you're right about this. But let's break i
Matt Giuca 2015/11/06 05:44:48 Note: Just mailed out https://codereview.chromium.
166 170
167 width = std::max(width, child->GetPreferredSize().width()); 171 width = std::max(width, child->GetPreferredSize().width());
168 } 172 }
169 width = std::max(width, minimum_cross_axis_size_); 173 width = std::max(width, minimum_cross_axis_size_);
170 } 174 }
171 175
172 return GetPreferredSizeForChildWidth(host, width); 176 return GetPreferredSizeForChildWidth(host, width);
173 } 177 }
174 178
175 int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const { 179 int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 child_area_bounds.height() + non_child_size.height()); 314 child_area_bounds.height() + non_child_size.height());
311 } 315 }
312 316
313 gfx::Size BoxLayout::NonChildSize(const View* host) const { 317 gfx::Size BoxLayout::NonChildSize(const View* host) const {
314 gfx::Insets insets(host->GetInsets()); 318 gfx::Insets insets(host->GetInsets());
315 return gfx::Size(insets.width() + inside_border_insets_.width(), 319 return gfx::Size(insets.width() + inside_border_insets_.width(),
316 insets.height() + inside_border_insets_.height()); 320 insets.height() + inside_border_insets_.height());
317 } 321 }
318 322
319 } // namespace views 323 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/layout/box_layout.h ('k') | ui/views/layout/box_layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698