Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_); | |
| 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; |
|
benwells
2014/08/26 07:22:16
Why has this changed?
calamity
2014/08/26 08:38:24
Removed.
| |
| 173 return GetPreferredSizeForChildWidth(host, child_width).height(); | 174 return GetPreferredSizeForChildWidth(host, child_width).height(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void BoxLayout::Installed(View* host) { | 177 void BoxLayout::Installed(View* host) { |
| 177 DCHECK(!host_); | 178 DCHECK(!host_); |
| 178 host_ = host; | 179 host_ = host; |
| 179 } | 180 } |
| 180 | 181 |
| 181 void BoxLayout::Uninstalled(View* host) { | 182 void BoxLayout::Uninstalled(View* host) { |
| 182 DCHECK_EQ(host_, host); | 183 DCHECK_EQ(host_, host); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |