diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-15 21:38:07 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-15 21:38:07 +0000 |
commit | a9f8899794e8867395ad6665043ab02638e1d2c8 (patch) | |
tree | 8808ac965db53e10382e42151ea970788c2efea8 /chrome/browser/views | |
parent | 8dde66528d2a057e087b4d3459e3323b0c65d5c5 (diff) | |
download | chromium_src-a9f8899794e8867395ad6665043ab02638e1d2c8.zip chromium_src-a9f8899794e8867395ad6665043ab02638e1d2c8.tar.gz chromium_src-a9f8899794e8867395ad6665043ab02638e1d2c8.tar.bz2 |
If there is not enough room in the download shelf to show a download, move the "show all download" link to the right to make it more visible that something happened.
This is a quick fix to mitigate the Malaysian case where the text is really long.
BUG=11816
TEST=Make sure download shelf still works as expected: download items still show and are animated. Dangerous downloads prompt for confirmation. If the browser window is too small, the download item is not shown and the link "Show all downloads" is displayed on the left.
Review URL: http://codereview.chromium.org/113417
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16191 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/download_item_view.cc | 5 | ||||
-rw-r--r-- | chrome/browser/views/download_shelf_view.cc | 41 | ||||
-rw-r--r-- | chrome/browser/views/download_shelf_view.h | 3 |
3 files changed, 43 insertions, 6 deletions
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc index 138158e..6ba34d7 100644 --- a/chrome/browser/views/download_item_view.cc +++ b/chrome/browser/views/download_item_view.cc @@ -404,8 +404,7 @@ void DownloadItemView::Layout() { y = (height() - button_size.height()) / 2; save_button_->SetBounds(x, y, button_size.width(), button_size.height()); x += button_size.width() + kButtonPadding; - discard_button_->SetBounds(x, y, button_size.width(), - button_size.height()); + discard_button_->SetBounds(x, y, button_size.width(), button_size.height()); } } @@ -873,7 +872,7 @@ gfx::Size DownloadItemView::GetButtonSize() { // not showing, the native buttons are not parented and their preferred size // is 0, messing-up the layout. if (cached_button_size_.width() != 0) - size = cached_button_size_; + return cached_button_size_; size = save_button_->GetMinimumSize(); gfx::Size discard_size = discard_button_->GetMinimumSize(); diff --git a/chrome/browser/views/download_shelf_view.cc b/chrome/browser/views/download_shelf_view.cc index 40d6520..bd6a7b1 100644 --- a/chrome/browser/views/download_shelf_view.cc +++ b/chrome/browser/views/download_shelf_view.cc @@ -208,14 +208,21 @@ void DownloadShelfView::Layout() { // Let our base class layout our child views views::View::Layout(); + // If there is not enought room to show the first download item, show the + // "Show all downloads" link to the left to make it more visible that there is + // something to see. + bool show_link_only = !CanFitFirstDownloadItem(); + 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.width() - kCloseAndLinkPadding - show_all_size.width() - - image_size.width() - kDownloadPadding); - int next_x = max_download_x + kDownloadPadding; + kDownloadsTitlePadding - image_size.width() - + kDownloadPadding); + int next_x = show_link_only ? kLeftPadding : + max_download_x + kDownloadPadding; // Align vertically with show_all_view_. arrow_image_->SetBounds(next_x, CenterPosition(show_all_size.height(), height()), @@ -230,6 +237,13 @@ void DownloadShelfView::Layout() { CenterPosition(close_button_size.height(), height()), close_button_size.width(), close_button_size.height()); + if (show_link_only) { + // Let's hide all the items. + std::vector<View*>::reverse_iterator ri; + for (ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) + (*ri)->SetVisible(false); + return; + } next_x = kLeftPadding; std::vector<View*>::reverse_iterator ri; @@ -245,7 +259,7 @@ void DownloadShelfView::Layout() { new_item_animation_->GetCurrentValue()); } - next_x += (item_width + kDownloadPadding); + next_x += item_width; // Make sure our item can be contained within the shelf. if (next_x < max_download_x) { @@ -258,6 +272,27 @@ void DownloadShelfView::Layout() { } } +bool DownloadShelfView::CanFitFirstDownloadItem() { + if (download_views_.empty()) + return true; + + gfx::Size image_size = arrow_image_->GetPreferredSize(); + gfx::Size close_button_size = close_button_->GetPreferredSize(); + gfx::Size show_all_size = show_all_view_->GetPreferredSize(); + + // Let's compute the width available for download items, which is the width + // of the shelf minus the "Show all downloads" link, arrow and close button + // and the padding. + int available_width = width() - kRightPadding - close_button_size.width() - + kCloseAndLinkPadding - show_all_size.width() - kDownloadsTitlePadding - + image_size.width() - kDownloadPadding - kLeftPadding; + if (available_width <= 0) + return false; + + gfx::Size item_size = (*download_views_.rbegin())->GetPreferredSize(); + return item_size.width() < available_width; +} + void DownloadShelfView::LinkActivated(views::Link* source, int event_flags) { ShowAllDownloads(); } diff --git a/chrome/browser/views/download_shelf_view.h b/chrome/browser/views/download_shelf_view.h index af3fd59..1c1ee23 100644 --- a/chrome/browser/views/download_shelf_view.h +++ b/chrome/browser/views/download_shelf_view.h @@ -72,6 +72,9 @@ class DownloadShelfView : public DownloadShelf, // Paints the border. void PaintBorder(gfx::Canvas* canvas); + // Returns true if the shelf is wide enough to show the first download item. + bool CanFitFirstDownloadItem(); + // The animation for adding new items to the shelf. scoped_ptr<SlideAnimation> new_item_animation_; |