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

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

Issue 494273003: Add a minimum cross axis size to BoxLayout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test, remove oops Created 6 years, 3 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 | Annotate | Revision Log
« 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/rect.h" 7 #include "ui/gfx/rect.h"
8 #include "ui/views/view.h" 8 #include "ui/views/view.h"
9 9
10 namespace views { 10 namespace views {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Calculate the child views' preferred width. 155 // Calculate the child views' preferred width.
156 int width = 0; 156 int width = 0;
157 if (orientation_ == kVertical) { 157 if (orientation_ == kVertical) {
158 for (int i = 0; i < host->child_count(); ++i) { 158 for (int i = 0; i < host->child_count(); ++i) {
159 const View* child = host->child_at(i); 159 const View* child = host->child_at(i);
160 if (!child->visible()) 160 if (!child->visible())
161 continue; 161 continue;
162 162
163 width = std::max(width, child->GetPreferredSize().width()); 163 width = std::max(width, child->GetPreferredSize().width());
164 } 164 }
165 width = std::max(width, minimum_cross_axis_size_);
benwells 2014/08/26 22:05:51 Nit: initialize minimum_cross_axis_size_
calamity 2014/08/27 03:59:33 Done.
165 } 166 }
166 167
167 return GetPreferredSizeForChildWidth(host, width); 168 return GetPreferredSizeForChildWidth(host, width);
168 } 169 }
169 170
170 int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const { 171 int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const {
171 DCHECK_EQ(host_, host); 172 DCHECK_EQ(host_, host);
172 int child_width = width - NonChildSize(host).width(); 173 int child_width = width - NonChildSize(host).width();
173 return GetPreferredSizeForChildWidth(host, child_width).height(); 174 return GetPreferredSizeForChildWidth(host, child_width).height();
174 } 175 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 continue; 272 continue;
272 273
273 gfx::Size size(child->GetPreferredSize()); 274 gfx::Size size(child->GetPreferredSize());
274 if (size.IsEmpty()) 275 if (size.IsEmpty())
275 continue; 276 continue;
276 277
277 gfx::Rect child_bounds(position, 0, size.width(), size.height()); 278 gfx::Rect child_bounds(position, 0, size.width(), size.height());
278 child_area_bounds.Union(child_bounds); 279 child_area_bounds.Union(child_bounds);
279 position += size.width() + between_child_spacing_; 280 position += size.width() + between_child_spacing_;
280 } 281 }
282 child_area_bounds.set_height(
283 std::max(child_area_bounds.height(), minimum_cross_axis_size_));
281 } else { 284 } else {
282 int height = 0; 285 int height = 0;
283 for (int i = 0; i < host->child_count(); ++i) { 286 for (int i = 0; i < host->child_count(); ++i) {
284 const View* child = host->child_at(i); 287 const View* child = host->child_at(i);
285 if (!child->visible()) 288 if (!child->visible())
286 continue; 289 continue;
287 290
288 // Use the child area width for getting the height if the child is 291 // Use the child area width for getting the height if the child is
289 // supposed to stretch. Use its preferred size otherwise. 292 // supposed to stretch. Use its preferred size otherwise.
290 int extra_height = MainAxisSizeForView(child, child_area_width); 293 int extra_height = MainAxisSizeForView(child, child_area_width);
(...skipping 12 matching lines...) Expand all
303 child_area_bounds.height() + non_child_size.height()); 306 child_area_bounds.height() + non_child_size.height());
304 } 307 }
305 308
306 gfx::Size BoxLayout::NonChildSize(const View* host) const { 309 gfx::Size BoxLayout::NonChildSize(const View* host) const {
307 gfx::Insets insets(host->GetInsets()); 310 gfx::Insets insets(host->GetInsets());
308 return gfx::Size(insets.width() + inside_border_insets_.width(), 311 return gfx::Size(insets.width() + inside_border_insets_.width(),
309 insets.height() + inside_border_insets_.height()); 312 insets.height() + inside_border_insets_.height());
310 } 313 }
311 314
312 } // namespace views 315 } // 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