Index: chrome/browser/views/download_shelf_view.cc |
=================================================================== |
--- chrome/browser/views/download_shelf_view.cc (revision 3391) |
+++ chrome/browser/views/download_shelf_view.cc (working copy) |
@@ -60,13 +60,13 @@ |
namespace { |
-// Sets size->cx to view's preferred width + size->cx. |
-// Sets size->cy to the max of the view's preferred height and size->cy; |
-void AdjustSize(ChromeViews::View* view, CSize* size) { |
- CSize view_preferred; |
- view->GetPreferredSize(&view_preferred); |
- size->cx += view_preferred.cx; |
- size->cy = std::max(view_preferred.cy, size->cy); |
+// Sets size->width() to view's preferred width + size->width().s |
+// Sets size->height() to the max of the view's preferred height and |
+// size->height(); |
+void AdjustSize(ChromeViews::View* view, gfx::Size* size) { |
+ gfx::Size view_preferred = view->GetPreferredSize(); |
+ size->Enlarge(view_preferred.width(), 0); |
Elliot Glaysher
2008/10/15 17:21:46
One general comment: I haven't seen a case yet whe
Ben Goodger (Google)
2008/10/15 17:37:32
OK I tried EnlargeWidth and EnlargeHeight. But I d
|
+ size->set_height(std::max(view_preferred.height(), size->height())); |
} |
int CenterPosition(int size, int target_size) { |
@@ -159,21 +159,22 @@ |
canvas->FillRectInt(kBorderColor, 0, 0, width(), 1); |
} |
-void DownloadShelfView::GetPreferredSize(CSize *out) { |
- out->cx = kRightPadding + kLeftPadding + kCloseAndLinkPadding; |
- out->cy = 0; |
- AdjustSize(close_button_, out); |
- AdjustSize(show_all_view_, out); |
+gfx::Size DownloadShelfView::GetPreferredSize() { |
+ gfx::Size prefsize(kRightPadding + kLeftPadding + kCloseAndLinkPadding, 0); |
+ AdjustSize(close_button_, &prefsize); |
+ AdjustSize(show_all_view_, &prefsize); |
// Add one download view to the preferred size. |
if (download_views_.size() > 0) { |
- AdjustSize(*download_views_.begin(), out); |
- out->cx += kDownloadPadding; |
+ AdjustSize(*download_views_.begin(), &prefsize); |
+ prefsize.Enlarge(kDownloadPadding, 0); |
} |
- out->cy += kTopBottomPadding + kTopBottomPadding; |
+ prefsize.Enlarge(0, kTopBottomPadding + kTopBottomPadding); |
if (shelf_animation_->IsAnimating()) { |
- out->cy = static_cast<int>(static_cast<double>(out->cy) * |
- shelf_animation_->GetCurrentValue()); |
+ prefsize.set_height(static_cast<int>( |
+ static_cast<double>(prefsize.height()) * |
+ shelf_animation_->GetCurrentValue())); |
} |
+ return prefsize; |
} |
void DownloadShelfView::DidChangeBounds(const CRect& previous, |
@@ -203,43 +204,40 @@ |
} |
void DownloadShelfView::Layout() { |
- CSize image_size; |
- arrow_image_->GetPreferredSize(&image_size); |
- CSize close_button_size; |
- close_button_->GetPreferredSize(&close_button_size); |
- CSize show_all_size; |
- show_all_view_->GetPreferredSize(&show_all_size); |
+ gfx::Size image_size = arrow_image_->GetPreferredSize(); |
+ gfx::Size close_button_size = close_button_->GetPreferredSize(); |
+ gfx::Size show_all_size = show_all_view_->GetPreferredSize(); |
int max_download_x = |
- std::max<int>(0, width() - kRightPadding - close_button_size.cx - |
- kCloseAndLinkPadding - show_all_size.cx - |
- image_size.cx - kDownloadPadding); |
+ std::max<int>(0, width() - kRightPadding - close_button_size.width() - |
+ kCloseAndLinkPadding - show_all_size.width() - |
+ image_size.width() - kDownloadPadding); |
int next_x = max_download_x + kDownloadPadding; |
// Align vertically with show_all_view_. |
- arrow_image_->SetBounds(next_x, CenterPosition(show_all_size.cy, height()), |
- image_size.cx, image_size.cy); |
- next_x += image_size.cx + kDownloadsTitlePadding; |
+ arrow_image_->SetBounds(next_x, |
+ CenterPosition(show_all_size.height(), height()), |
+ image_size.width(), image_size.height()); |
+ next_x += image_size.width() + kDownloadsTitlePadding; |
show_all_view_->SetBounds(next_x, |
- CenterPosition(show_all_size.cy, height()), |
- show_all_size.cx, |
- show_all_size.cy); |
- next_x += show_all_size.cx + kCloseAndLinkPadding; |
+ CenterPosition(show_all_size.height(), height()), |
+ show_all_size.width(), |
+ show_all_size.height()); |
+ next_x += show_all_size.width() + kCloseAndLinkPadding; |
close_button_->SetBounds(next_x, |
- CenterPosition(close_button_size.cy, height()), |
- close_button_size.cx, |
- close_button_size.cy); |
+ CenterPosition(close_button_size.height(), height()), |
+ close_button_size.width(), |
+ close_button_size.height()); |
next_x = kLeftPadding; |
std::vector<View*>::reverse_iterator ri; |
for (ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) { |
- CSize view_size; |
- (*ri)->GetPreferredSize(&view_size); |
+ gfx::Size view_size = (*ri)->GetPreferredSize(); |
int x = next_x; |
// Figure out width of item. |
- int item_width = view_size.cx; |
+ int item_width = view_size.width(); |
if (new_item_animation_->IsAnimating() && ri == download_views_.rbegin()) { |
- item_width = static_cast<int>(static_cast<double>(view_size.cx) * |
+ item_width = static_cast<int>(static_cast<double>(view_size.width()) * |
new_item_animation_->GetCurrentValue()); |
} |
@@ -248,8 +246,8 @@ |
// Make sure our item can be contained within the shelf. |
if (next_x < max_download_x) { |
(*ri)->SetVisible(true); |
- (*ri)->SetBounds(x, CenterPosition(view_size.cy, height()), item_width, |
- view_size.cy); |
+ (*ri)->SetBounds(x, CenterPosition(view_size.height(), height()), |
+ item_width, view_size.height()); |
} else { |
(*ri)->SetVisible(false); |
} |