| 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 "chrome/browser/ui/views/download/download_shelf_view.h" | 5 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/download/download_item_model.h" | 12 #include "chrome/browser/download/download_item_model.h" |
| 13 #include "chrome/browser/download/download_stats.h" | 13 #include "chrome/browser/download/download_stats.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/chrome_pages.h" | 16 #include "chrome/browser/ui/chrome_pages.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 17 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/browser/ui/views/download/download_item_view.h" | 18 #include "chrome/browser/ui/views/download/download_item_view.h" |
| 19 #include "chrome/browser/ui/views/download/download_item_view_md.h" | |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 22 #include "chrome/grit/theme_resources.h" | 21 #include "chrome/grit/theme_resources.h" |
| 23 #include "components/strings/grit/components_strings.h" | 22 #include "components/strings/grit/components_strings.h" |
| 24 #include "content/public/browser/download_item.h" | 23 #include "content/public/browser/download_item.h" |
| 25 #include "content/public/browser/download_manager.h" | 24 #include "content/public/browser/download_manager.h" |
| 26 #include "content/public/browser/page_navigator.h" | 25 #include "content/public/browser/page_navigator.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/material_design/material_design_controller.h" | |
| 29 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/base/theme_provider.h" | 28 #include "ui/base/theme_provider.h" |
| 31 #include "ui/gfx/animation/slide_animation.h" | 29 #include "ui/gfx/animation/slide_animation.h" |
| 32 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/vector_icons_public.h" | 31 #include "ui/gfx/vector_icons_public.h" |
| 34 #include "ui/resources/grit/ui_resources.h" | 32 #include "ui/resources/grit/ui_resources.h" |
| 35 #include "ui/views/background.h" | 33 #include "ui/views/background.h" |
| 36 #include "ui/views/border.h" | 34 #include "ui/views/border.h" |
| 37 #include "ui/views/controls/button/image_button.h" | |
| 38 #include "ui/views/controls/button/md_text_button.h" | 35 #include "ui/views/controls/button/md_text_button.h" |
| 39 #include "ui/views/controls/button/vector_icon_button.h" | 36 #include "ui/views/controls/button/vector_icon_button.h" |
| 40 #include "ui/views/controls/image_view.h" | |
| 41 #include "ui/views/controls/link.h" | 37 #include "ui/views/controls/link.h" |
| 42 #include "ui/views/mouse_watcher_view_host.h" | 38 #include "ui/views/mouse_watcher_view_host.h" |
| 43 | 39 |
| 44 using content::DownloadItem; | 40 using content::DownloadItem; |
| 45 | 41 |
| 46 namespace { | 42 namespace { |
| 47 | 43 |
| 48 // Max number of download views we'll contain. Any time a view is added and | 44 // Max number of download views we'll contain. Any time a view is added and |
| 49 // we already have this many download views, one is removed. | 45 // we already have this many download views, one is removed. |
| 50 const size_t kMaxDownloadViews = 15; | 46 const size_t kMaxDownloadViews = 15; |
| 51 | 47 |
| 52 // Padding from left edge and first download view. | 48 // Padding from left edge and first download view. |
| 53 const int kLeftPadding = 2; | 49 const int kStartPadding = 4; |
| 54 const int kStartPaddingMd = 4; | |
| 55 | 50 |
| 56 // Padding from right edge and close button/show downloads link. | 51 // Padding from right edge and close button/show downloads link. |
| 57 const int kRightPadding = 10; | 52 const int kEndPadding = 6; |
| 58 const int kEndPaddingMd = 6; | |
| 59 | 53 |
| 60 // Padding between the show all link and close button. | 54 // Padding between the show all link and close button. |
| 61 const int kCloseAndLinkPadding = 14; | 55 const int kCloseAndLinkPadding = 6; |
| 62 const int kCloseAndLinkPaddingMd = 6; | |
| 63 | 56 |
| 64 // Padding between the download views. | 57 // Padding above the content. |
| 65 const int kDownloadPadding = 10; | 58 const int kTopPadding = 1; |
| 66 | |
| 67 // Padding between the top/bottom and the content. | |
| 68 const int kTopBottomPadding = 2; | |
| 69 | |
| 70 // Padding between the icon and 'show all downloads' link | |
| 71 const int kDownloadsTitlePadding = 4; | |
| 72 | 59 |
| 73 // Border color. | 60 // Border color. |
| 74 const SkColor kBorderColor = SkColorSetRGB(214, 214, 214); | 61 const SkColor kBorderColor = SkColorSetRGB(214, 214, 214); |
| 75 | 62 |
| 76 // New download item animation speed in milliseconds. | 63 // New download item animation speed in milliseconds. |
| 77 const int kNewItemAnimationDurationMs = 800; | 64 const int kNewItemAnimationDurationMs = 800; |
| 78 | 65 |
| 79 // Shelf show/hide speed. | 66 // Shelf show/hide speed. |
| 80 const int kShelfAnimationDurationMs = 120; | 67 const int kShelfAnimationDurationMs = 120; |
| 81 | 68 |
| 82 // Amount of time to delay if the mouse leaves the shelf by way of entering | 69 // Amount of time to delay if the mouse leaves the shelf by way of entering |
| 83 // another window. This is much larger than the normal delay as openning a | 70 // another window. This is much larger than the normal delay as openning a |
| 84 // download is most likely going to trigger a new window to appear over the | 71 // download is most likely going to trigger a new window to appear over the |
| 85 // button. Delay the time so that the user has a chance to quickly close the | 72 // button. Delay the time so that the user has a chance to quickly close the |
| 86 // other app and return to chrome with the download shelf still open. | 73 // other app and return to chrome with the download shelf still open. |
| 87 const int kNotifyOnExitTimeMS = 5000; | 74 const int kNotifyOnExitTimeMS = 5000; |
| 88 | 75 |
| 89 int GetStartPadding() { | 76 // Sets size->width() to view's preferred width + size->width(). |
| 90 return ui::MaterialDesignController::IsModeMaterial() ? kStartPaddingMd | |
| 91 : kLeftPadding; | |
| 92 } | |
| 93 | |
| 94 int GetEndPadding() { | |
| 95 return ui::MaterialDesignController::IsModeMaterial() ? kEndPaddingMd | |
| 96 : kRightPadding; | |
| 97 } | |
| 98 | |
| 99 int GetCloseAndLinkPadding() { | |
| 100 return ui::MaterialDesignController::IsModeMaterial() ? kCloseAndLinkPaddingMd | |
| 101 : kCloseAndLinkPadding; | |
| 102 } | |
| 103 | |
| 104 int GetBetweenItemPadding() { | |
| 105 return ui::MaterialDesignController::IsModeMaterial() ? 0 : kDownloadPadding; | |
| 106 } | |
| 107 | |
| 108 int GetTopPadding() { | |
| 109 return ui::MaterialDesignController::IsModeMaterial() ? 1 : kTopBottomPadding; | |
| 110 } | |
| 111 | |
| 112 int GetBottomPadding() { | |
| 113 return ui::MaterialDesignController::IsModeMaterial() ? 0 : kTopBottomPadding; | |
| 114 } | |
| 115 | |
| 116 // Sets size->width() to view's preferred width + size->width().s | |
| 117 // Sets size->height() to the max of the view's preferred height and | 77 // Sets size->height() to the max of the view's preferred height and |
| 118 // size->height(); | 78 // size->height(); |
| 119 void AdjustSize(views::View* view, gfx::Size* size) { | 79 void AdjustSize(views::View* view, gfx::Size* size) { |
| 120 gfx::Size view_preferred = view->GetPreferredSize(); | 80 gfx::Size view_preferred = view->GetPreferredSize(); |
| 121 size->Enlarge(view_preferred.width(), 0); | 81 size->Enlarge(view_preferred.width(), 0); |
| 122 size->set_height(std::max(view_preferred.height(), size->height())); | 82 size->set_height(std::max(view_preferred.height(), size->height())); |
| 123 } | 83 } |
| 124 | 84 |
| 125 int CenterPosition(int size, int target_size) { | 85 int CenterPosition(int size, int target_size) { |
| 126 return std::max((target_size - size) / 2, GetTopPadding()); | 86 return std::max((target_size - size) / 2, kTopPadding); |
| 127 } | 87 } |
| 128 | 88 |
| 129 } // namespace | 89 } // namespace |
| 130 | 90 |
| 131 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) | 91 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) |
| 132 : browser_(browser), | 92 : browser_(browser), |
| 133 new_item_animation_(this), | 93 new_item_animation_(this), |
| 134 shelf_animation_(this), | 94 shelf_animation_(this), |
| 135 arrow_image_(nullptr), | |
| 136 show_all_view_(nullptr), | 95 show_all_view_(nullptr), |
| 137 show_all_view_md_(nullptr), | |
| 138 close_button_(nullptr), | 96 close_button_(nullptr), |
| 139 parent_(parent), | 97 parent_(parent), |
| 140 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()), | 98 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()), |
| 141 this) { | 99 this) { |
| 142 // Start out hidden: the shelf might be created but never shown in some | 100 // Start out hidden: the shelf might be created but never shown in some |
| 143 // cases, like when installing a theme. See DownloadShelf::AddDownload(). | 101 // cases, like when installing a theme. See DownloadShelf::AddDownload(). |
| 144 SetVisible(false); | 102 SetVisible(false); |
| 145 | 103 |
| 146 mouse_watcher_.set_notify_on_exit_time( | 104 mouse_watcher_.set_notify_on_exit_time( |
| 147 base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS)); | 105 base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS)); |
| 148 set_id(VIEW_ID_DOWNLOAD_SHELF); | 106 set_id(VIEW_ID_DOWNLOAD_SHELF); |
| 149 parent->AddChildView(this); | 107 parent->AddChildView(this); |
| 150 | 108 |
| 151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 109 show_all_view_ = views::MdTextButton::Create( |
| 110 this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); |
| 111 AddChildView(show_all_view_); |
| 152 | 112 |
| 153 arrow_image_ = new views::ImageView(); | 113 views::VectorIconButton* close_button = new views::VectorIconButton(this); |
| 154 AddChildView(arrow_image_); | 114 close_button->SetIcon(gfx::VectorIconId::BAR_CLOSE); |
| 155 if (!ui::MaterialDesignController::IsModeMaterial()) { | 115 close_button_ = close_button; |
| 156 arrow_image_->SetImage(rb.GetImageSkiaNamed(IDR_DOWNLOADS_FAVICON)); | |
| 157 | |
| 158 views::Link* show_all_view = | |
| 159 new views::Link(l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); | |
| 160 show_all_view->set_listener(this); | |
| 161 show_all_view_ = show_all_view; | |
| 162 | |
| 163 close_button_ = new views::ImageButton(this); | |
| 164 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | |
| 165 rb.GetImageSkiaNamed(IDR_CLOSE_1)); | |
| 166 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | |
| 167 rb.GetImageSkiaNamed(IDR_CLOSE_1_H)); | |
| 168 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | |
| 169 rb.GetImageSkiaNamed(IDR_CLOSE_1_P)); | |
| 170 } else { | |
| 171 show_all_view_md_ = views::MdTextButton::Create( | |
| 172 this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS_MD)); | |
| 173 show_all_view_ = show_all_view_md_; | |
| 174 | |
| 175 views::VectorIconButton* close_button = new views::VectorIconButton(this); | |
| 176 close_button->SetIcon(gfx::VectorIconId::BAR_CLOSE); | |
| 177 close_button_ = close_button; | |
| 178 } | |
| 179 close_button_->SetAccessibleName( | 116 close_button_->SetAccessibleName( |
| 180 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 117 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 181 AddChildView(show_all_view_); | |
| 182 AddChildView(close_button_); | 118 AddChildView(close_button_); |
| 183 | 119 |
| 184 new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs); | 120 new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs); |
| 185 shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs); | 121 shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs); |
| 186 } | 122 } |
| 187 | 123 |
| 188 DownloadShelfView::~DownloadShelfView() { | 124 DownloadShelfView::~DownloadShelfView() { |
| 189 parent_->RemoveChildView(this); | 125 parent_->RemoveChildView(this); |
| 190 } | 126 } |
| 191 | 127 |
| 192 void DownloadShelfView::AddDownloadView(views::View* view) { | 128 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { |
| 193 mouse_watcher_.Stop(); | 129 mouse_watcher_.Stop(); |
| 194 | 130 |
| 195 DCHECK(view); | 131 DCHECK(view); |
| 196 download_views_.push_back(view); | 132 download_views_.push_back(view); |
| 197 | 133 |
| 198 // Insert the new view as the first child, so the logical child order matches | 134 // Insert the new view as the first child, so the logical child order matches |
| 199 // the visual order. This ensures that tabbing through downloads happens in | 135 // the visual order. This ensures that tabbing through downloads happens in |
| 200 // the order users would expect. | 136 // the order users would expect. |
| 201 AddChildViewAt(view, 0); | 137 AddChildViewAt(view, 0); |
| 202 if (download_views_.size() > kMaxDownloadViews) | 138 if (download_views_.size() > kMaxDownloadViews) |
| 203 RemoveDownloadView(*download_views_.begin()); | 139 RemoveDownloadView(*download_views_.begin()); |
| 204 | 140 |
| 205 new_item_animation_.Reset(); | 141 new_item_animation_.Reset(); |
| 206 new_item_animation_.Show(); | 142 new_item_animation_.Show(); |
| 207 } | 143 } |
| 208 | 144 |
| 209 void DownloadShelfView::DoAddDownload(DownloadItem* download) { | 145 void DownloadShelfView::DoAddDownload(DownloadItem* download) { |
| 210 if (ui::MaterialDesignController::IsModeMaterial()) | 146 AddDownloadView(new DownloadItemView(download, this)); |
| 211 AddDownloadView(new DownloadItemViewMd(download, this)); | |
| 212 else | |
| 213 AddDownloadView(new DownloadItemView(download, this)); | |
| 214 } | 147 } |
| 215 | 148 |
| 216 void DownloadShelfView::MouseMovedOutOfHost() { | 149 void DownloadShelfView::MouseMovedOutOfHost() { |
| 217 Close(AUTOMATIC); | 150 Close(AUTOMATIC); |
| 218 } | 151 } |
| 219 | 152 |
| 220 void DownloadShelfView::RemoveDownloadView(View* view) { | 153 void DownloadShelfView::RemoveDownloadView(View* view) { |
| 221 DCHECK(view); | 154 DCHECK(view); |
| 222 auto i = find(download_views_.begin(), download_views_.end(), view); | 155 auto i = find(download_views_.begin(), download_views_.end(), view); |
| 223 DCHECK(i != download_views_.end()); | 156 DCHECK(i != download_views_.end()); |
| 224 download_views_.erase(i); | 157 download_views_.erase(i); |
| 225 RemoveChildView(view); | 158 RemoveChildView(view); |
| 226 delete view; | 159 delete view; |
| 227 if (download_views_.empty()) | 160 if (download_views_.empty()) |
| 228 Close(AUTOMATIC); | 161 Close(AUTOMATIC); |
| 229 else if (CanAutoClose()) | 162 else if (CanAutoClose()) |
| 230 mouse_watcher_.Start(); | 163 mouse_watcher_.Start(); |
| 231 Layout(); | 164 Layout(); |
| 232 SchedulePaint(); | 165 SchedulePaint(); |
| 233 } | 166 } |
| 234 | 167 |
| 235 views::View* DownloadShelfView::GetDefaultFocusableChild() { | 168 views::View* DownloadShelfView::GetDefaultFocusableChild() { |
| 236 return download_views_.empty() ? show_all_view_ : download_views_.back(); | 169 if (!download_views_.empty()) |
| 170 return download_views_.back(); |
| 171 |
| 172 return show_all_view_; |
| 237 } | 173 } |
| 238 | 174 |
| 239 void DownloadShelfView::OnPaintBorder(gfx::Canvas* canvas) { | 175 void DownloadShelfView::OnPaintBorder(gfx::Canvas* canvas) { |
| 240 canvas->FillRect(gfx::Rect(0, 0, width(), 1), kBorderColor); | 176 canvas->FillRect(gfx::Rect(0, 0, width(), 1), kBorderColor); |
| 241 } | 177 } |
| 242 | 178 |
| 243 void DownloadShelfView::OpenedDownload() { | 179 void DownloadShelfView::OpenedDownload() { |
| 244 if (CanAutoClose()) | 180 if (CanAutoClose()) |
| 245 mouse_watcher_.Start(); | 181 mouse_watcher_.Start(); |
| 246 } | 182 } |
| 247 | 183 |
| 248 content::PageNavigator* DownloadShelfView::GetNavigator() { | 184 content::PageNavigator* DownloadShelfView::GetNavigator() { |
| 249 return browser_; | 185 return browser_; |
| 250 } | 186 } |
| 251 | 187 |
| 252 gfx::Size DownloadShelfView::GetPreferredSize() const { | 188 gfx::Size DownloadShelfView::GetPreferredSize() const { |
| 253 gfx::Size prefsize( | 189 gfx::Size prefsize(kEndPadding + kStartPadding + kCloseAndLinkPadding, 0); |
| 254 GetEndPadding() + GetStartPadding() + GetCloseAndLinkPadding(), 0); | |
| 255 AdjustSize(close_button_, &prefsize); | 190 AdjustSize(close_button_, &prefsize); |
| 256 AdjustSize(show_all_view_, &prefsize); | 191 AdjustSize(show_all_view_, &prefsize); |
| 257 // Add one download view to the preferred size. | 192 // Add one download view to the preferred size. |
| 258 if (!download_views_.empty()) { | 193 if (!download_views_.empty()) |
| 259 AdjustSize(*download_views_.begin(), &prefsize); | 194 AdjustSize(*download_views_.begin(), &prefsize); |
| 260 prefsize.Enlarge(GetBetweenItemPadding(), 0); | 195 prefsize.Enlarge(0, kTopPadding); |
| 261 } | |
| 262 prefsize.Enlarge(0, GetTopPadding() + GetBottomPadding()); | |
| 263 if (shelf_animation_.is_animating()) { | 196 if (shelf_animation_.is_animating()) { |
| 264 prefsize.set_height( | 197 prefsize.set_height( |
| 265 static_cast<int>(static_cast<double>(prefsize.height()) * | 198 static_cast<int>(static_cast<double>(prefsize.height()) * |
| 266 shelf_animation_.GetCurrentValue())); | 199 shelf_animation_.GetCurrentValue())); |
| 267 } | 200 } |
| 268 return prefsize; | 201 return prefsize; |
| 269 } | 202 } |
| 270 | 203 |
| 271 void DownloadShelfView::AnimationProgressed(const gfx::Animation* animation) { | 204 void DownloadShelfView::AnimationProgressed(const gfx::Animation* animation) { |
| 272 if (animation == &new_item_animation_) { | 205 if (animation == &new_item_animation_) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 293 | 226 |
| 294 void DownloadShelfView::Layout() { | 227 void DownloadShelfView::Layout() { |
| 295 // Let our base class layout our child views | 228 // Let our base class layout our child views |
| 296 views::View::Layout(); | 229 views::View::Layout(); |
| 297 | 230 |
| 298 // If there is not enough room to show the first download item, show the | 231 // If there is not enough room to show the first download item, show the |
| 299 // "Show all downloads" link to the left to make it more visible that there is | 232 // "Show all downloads" link to the left to make it more visible that there is |
| 300 // something to see. | 233 // something to see. |
| 301 bool show_link_only = !CanFitFirstDownloadItem(); | 234 bool show_link_only = !CanFitFirstDownloadItem(); |
| 302 | 235 |
| 303 gfx::Size image_size = arrow_image_->GetPreferredSize(); | |
| 304 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 236 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
| 305 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); | 237 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); |
| 306 int max_download_x = | 238 int max_download_x = |
| 307 std::max<int>(0, width() - GetEndPadding() - close_button_size.width() - | 239 std::max<int>(0, width() - kEndPadding - close_button_size.width() - |
| 308 GetCloseAndLinkPadding() - show_all_size.width() - | 240 kCloseAndLinkPadding - show_all_size.width()); |
| 309 kDownloadsTitlePadding - image_size.width() - | 241 int next_x = show_link_only ? kStartPadding : max_download_x; |
| 310 GetBetweenItemPadding()); | |
| 311 int next_x = show_link_only ? GetStartPadding() | |
| 312 : max_download_x + GetBetweenItemPadding(); | |
| 313 // Align vertically with show_all_view_. | |
| 314 arrow_image_->SetBounds(next_x, | |
| 315 CenterPosition(image_size.height(), height()), | |
| 316 image_size.width(), image_size.height()); | |
| 317 next_x += image_size.width() + kDownloadsTitlePadding; | |
| 318 show_all_view_->SetBounds(next_x, | 242 show_all_view_->SetBounds(next_x, |
| 319 CenterPosition(show_all_size.height(), height()), | 243 CenterPosition(show_all_size.height(), height()), |
| 320 show_all_size.width(), | 244 show_all_size.width(), |
| 321 show_all_size.height()); | 245 show_all_size.height()); |
| 322 next_x += show_all_size.width() + GetCloseAndLinkPadding(); | 246 next_x += show_all_size.width() + kCloseAndLinkPadding; |
| 323 close_button_->SizeToPreferredSize(); | 247 close_button_->SizeToPreferredSize(); |
| 324 close_button_->SetPosition( | 248 close_button_->SetPosition( |
| 325 gfx::Point(next_x, CenterPosition(close_button_->height(), height()))); | 249 gfx::Point(next_x, CenterPosition(close_button_->height(), height()))); |
| 326 if (show_link_only) { | 250 if (show_link_only) { |
| 327 // Let's hide all the items. | 251 // Let's hide all the items. |
| 328 for (auto ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) | 252 for (auto ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) |
| 329 (*ri)->SetVisible(false); | 253 (*ri)->SetVisible(false); |
| 330 return; | 254 return; |
| 331 } | 255 } |
| 332 | 256 |
| 333 next_x = GetStartPadding(); | 257 next_x = kStartPadding; |
| 334 for (auto ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) { | 258 for (auto ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) { |
| 335 gfx::Size view_size = (*ri)->GetPreferredSize(); | 259 gfx::Size view_size = (*ri)->GetPreferredSize(); |
| 336 | 260 |
| 337 int x = next_x; | 261 int x = next_x; |
| 338 | 262 |
| 339 // Figure out width of item. | 263 // Figure out width of item. |
| 340 int item_width = view_size.width(); | 264 int item_width = view_size.width(); |
| 341 if (new_item_animation_.is_animating() && ri == download_views_.rbegin()) { | 265 if (new_item_animation_.is_animating() && ri == download_views_.rbegin()) { |
| 342 item_width = static_cast<int>(static_cast<double>(view_size.width()) * | 266 item_width = static_cast<int>(static_cast<double>(view_size.width()) * |
| 343 new_item_animation_.GetCurrentValue()); | 267 new_item_animation_.GetCurrentValue()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 360 const ViewHierarchyChangedDetails& details) { | 284 const ViewHierarchyChangedDetails& details) { |
| 361 View::ViewHierarchyChanged(details); | 285 View::ViewHierarchyChanged(details); |
| 362 if (details.is_add) | 286 if (details.is_add) |
| 363 UpdateColorsFromTheme(); | 287 UpdateColorsFromTheme(); |
| 364 } | 288 } |
| 365 | 289 |
| 366 bool DownloadShelfView::CanFitFirstDownloadItem() { | 290 bool DownloadShelfView::CanFitFirstDownloadItem() { |
| 367 if (download_views_.empty()) | 291 if (download_views_.empty()) |
| 368 return true; | 292 return true; |
| 369 | 293 |
| 370 gfx::Size image_size = arrow_image_->GetPreferredSize(); | |
| 371 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 294 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
| 372 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); | 295 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); |
| 373 | 296 |
| 374 // Let's compute the width available for download items, which is the width | 297 // Let's compute the width available for download items, which is the width |
| 375 // of the shelf minus the "Show all downloads" link, arrow and close button | 298 // of the shelf minus the "Show all downloads" link, arrow and close button |
| 376 // and the padding. | 299 // and the padding. |
| 377 int available_width = width() - GetEndPadding() - close_button_size.width() - | 300 int available_width = width() - kEndPadding - close_button_size.width() - |
| 378 GetCloseAndLinkPadding() - show_all_size.width() - | 301 kCloseAndLinkPadding - show_all_size.width() - |
| 379 kDownloadsTitlePadding - image_size.width() - | 302 kStartPadding; |
| 380 GetBetweenItemPadding() - GetStartPadding(); | |
| 381 if (available_width <= 0) | 303 if (available_width <= 0) |
| 382 return false; | 304 return false; |
| 383 | 305 |
| 384 gfx::Size item_size = (*download_views_.rbegin())->GetPreferredSize(); | 306 gfx::Size item_size = (*download_views_.rbegin())->GetPreferredSize(); |
| 385 return item_size.width() < available_width; | 307 return item_size.width() < available_width; |
| 386 } | 308 } |
| 387 | 309 |
| 388 void DownloadShelfView::UpdateColorsFromTheme() { | 310 void DownloadShelfView::UpdateColorsFromTheme() { |
| 389 if (show_all_view_ && close_button_ && GetThemeProvider()) { | 311 if (show_all_view_ && close_button_ && GetThemeProvider()) { |
| 390 set_background(views::Background::CreateSolidBackground( | 312 set_background(views::Background::CreateSolidBackground( |
| 391 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); | 313 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); |
| 392 | 314 show_all_view_->SetEnabledTextColors( |
| 393 if (ui::MaterialDesignController::IsModeMaterial()) { | 315 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| 394 show_all_view_md_->SetEnabledTextColors( | |
| 395 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | |
| 396 } else { | |
| 397 views::Link* show_all_view = static_cast<views::Link*>(show_all_view_); | |
| 398 show_all_view->SetBackgroundColor(background()->get_color()); | |
| 399 show_all_view->SetEnabledColor( | |
| 400 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | |
| 401 | |
| 402 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 403 close_button_->SetBackground( | |
| 404 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | |
| 405 rb.GetImageSkiaNamed(IDR_CLOSE_1), | |
| 406 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | |
| 407 } | |
| 408 } | 316 } |
| 409 } | 317 } |
| 410 | 318 |
| 411 void DownloadShelfView::OnThemeChanged() { | 319 void DownloadShelfView::OnThemeChanged() { |
| 412 UpdateColorsFromTheme(); | 320 UpdateColorsFromTheme(); |
| 413 } | 321 } |
| 414 | 322 |
| 415 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { | 323 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { |
| 416 chrome::ShowDownloads(browser_); | 324 chrome::ShowDownloads(browser_); |
| 417 } | 325 } |
| 418 | 326 |
| 419 void DownloadShelfView::ButtonPressed( | 327 void DownloadShelfView::ButtonPressed( |
| 420 views::Button* button, const ui::Event& event) { | 328 views::Button* button, const ui::Event& event) { |
| 421 if (button == close_button_) | 329 if (button == close_button_) |
| 422 Close(USER_ACTION); | 330 Close(USER_ACTION); |
| 423 else if (button == show_all_view_) | 331 else if (button == show_all_view_) |
| 424 chrome::ShowDownloads(browser_); | 332 chrome::ShowDownloads(browser_); |
| 425 else | 333 else |
| 426 NOTREACHED(); | 334 NOTREACHED(); |
| 427 } | 335 } |
| 428 | 336 |
| 429 SkColor DownloadShelfView::GetVectorIconBaseColor() const { | 337 SkColor DownloadShelfView::GetVectorIconBaseColor() const { |
| 430 return DownloadItemViewMd::GetTextColorForThemeProvider(GetThemeProvider()); | 338 return DownloadItemView::GetTextColorForThemeProvider(GetThemeProvider()); |
| 431 } | 339 } |
| 432 | 340 |
| 433 bool DownloadShelfView::IsShowing() const { | 341 bool DownloadShelfView::IsShowing() const { |
| 434 return visible() && shelf_animation_.IsShowing(); | 342 return visible() && shelf_animation_.IsShowing(); |
| 435 } | 343 } |
| 436 | 344 |
| 437 bool DownloadShelfView::IsClosing() const { | 345 bool DownloadShelfView::IsClosing() const { |
| 438 return shelf_animation_.IsClosing(); | 346 return shelf_animation_.IsClosing(); |
| 439 } | 347 } |
| 440 | 348 |
| 441 void DownloadShelfView::DoShow() { | 349 void DownloadShelfView::DoShow() { |
| 442 SetVisible(true); | 350 SetVisible(true); |
| 443 shelf_animation_.Show(); | 351 shelf_animation_.Show(); |
| 444 } | 352 } |
| 445 | 353 |
| 446 void DownloadShelfView::DoClose(CloseReason reason) { | 354 void DownloadShelfView::DoClose(CloseReason reason) { |
| 447 int num_in_progress = 0; | 355 int num_in_progress = 0; |
| 448 for (size_t i = 0; i < download_views_.size(); ++i) { | 356 for (size_t i = 0; i < download_views_.size(); ++i) { |
| 449 if (GetDownloadItemForView(i)->GetState() == DownloadItem::IN_PROGRESS) | 357 if (download_views_[i]->download()->GetState() == DownloadItem::IN_PROGRESS) |
| 450 ++num_in_progress; | 358 ++num_in_progress; |
| 451 } | 359 } |
| 452 RecordDownloadShelfClose( | 360 RecordDownloadShelfClose( |
| 453 download_views_.size(), num_in_progress, reason == AUTOMATIC); | 361 download_views_.size(), num_in_progress, reason == AUTOMATIC); |
| 454 parent_->SetDownloadShelfVisible(false); | 362 parent_->SetDownloadShelfVisible(false); |
| 455 shelf_animation_.Hide(); | 363 shelf_animation_.Hide(); |
| 456 } | 364 } |
| 457 | 365 |
| 458 Browser* DownloadShelfView::browser() const { | 366 Browser* DownloadShelfView::browser() const { |
| 459 return browser_; | 367 return browser_; |
| 460 } | 368 } |
| 461 | 369 |
| 462 void DownloadShelfView::Closed() { | 370 void DownloadShelfView::Closed() { |
| 463 // Don't remove completed downloads if the shelf is just being auto-hidden | 371 // Don't remove completed downloads if the shelf is just being auto-hidden |
| 464 // rather than explicitly closed by the user. | 372 // rather than explicitly closed by the user. |
| 465 if (is_hidden()) | 373 if (is_hidden()) |
| 466 return; | 374 return; |
| 467 // When the close animation is complete, remove all completed downloads. | 375 // When the close animation is complete, remove all completed downloads. |
| 468 size_t i = 0; | 376 size_t i = 0; |
| 469 while (i < download_views_.size()) { | 377 while (i < download_views_.size()) { |
| 470 DownloadItem* download = GetDownloadItemForView(i); | 378 DownloadItem* download = download_views_[i]->download(); |
| 471 DownloadItem::DownloadState state = download->GetState(); | 379 DownloadItem::DownloadState state = download->GetState(); |
| 472 bool is_transfer_done = state == DownloadItem::COMPLETE || | 380 bool is_transfer_done = state == DownloadItem::COMPLETE || |
| 473 state == DownloadItem::CANCELLED || | 381 state == DownloadItem::CANCELLED || |
| 474 state == DownloadItem::INTERRUPTED; | 382 state == DownloadItem::INTERRUPTED; |
| 475 if (is_transfer_done && !download->IsDangerous()) { | 383 if (is_transfer_done && !download->IsDangerous()) { |
| 476 RemoveDownloadView(download_views_[i]); | 384 RemoveDownloadView(download_views_[i]); |
| 477 } else { | 385 } else { |
| 478 // Treat the item as opened when we close. This way if we get shown again | 386 // Treat the item as opened when we close. This way if we get shown again |
| 479 // the user need not open this item for the shelf to auto-close. | 387 // the user need not open this item for the shelf to auto-close. |
| 480 download->SetOpened(true); | 388 download->SetOpened(true); |
| 481 ++i; | 389 ++i; |
| 482 } | 390 } |
| 483 } | 391 } |
| 484 SetVisible(false); | 392 SetVisible(false); |
| 485 } | 393 } |
| 486 | 394 |
| 487 bool DownloadShelfView::CanAutoClose() { | 395 bool DownloadShelfView::CanAutoClose() { |
| 488 for (size_t i = 0; i < download_views_.size(); ++i) { | 396 for (size_t i = 0; i < download_views_.size(); ++i) { |
| 489 if (!GetDownloadItemForView(i)->GetOpened()) | 397 if (!download_views_[i]->download()->GetOpened()) |
| 490 return false; | 398 return false; |
| 491 } | 399 } |
| 492 return true; | 400 return true; |
| 493 } | 401 } |
| 494 | |
| 495 content::DownloadItem* DownloadShelfView::GetDownloadItemForView(size_t i) { | |
| 496 if (ui::MaterialDesignController::IsModeMaterial()) | |
| 497 return static_cast<DownloadItemViewMd*>(download_views_[i])->download(); | |
| 498 return static_cast<DownloadItemView*>(download_views_[i])->download(); | |
| 499 } | |
| OLD | NEW |