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 "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" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 98 |
| 99 int GetCloseAndLinkPadding() { | 99 int GetCloseAndLinkPadding() { |
| 100 return ui::MaterialDesignController::IsModeMaterial() ? kCloseAndLinkPaddingMd | 100 return ui::MaterialDesignController::IsModeMaterial() ? kCloseAndLinkPaddingMd |
| 101 : kCloseAndLinkPadding; | 101 : kCloseAndLinkPadding; |
| 102 } | 102 } |
| 103 | 103 |
| 104 int GetBetweenItemPadding() { | 104 int GetBetweenItemPadding() { |
| 105 return ui::MaterialDesignController::IsModeMaterial() ? 0 : kDownloadPadding; | 105 return ui::MaterialDesignController::IsModeMaterial() ? 0 : kDownloadPadding; |
| 106 } | 106 } |
| 107 | 107 |
| 108 int GetTopBottomPadding() { | 108 int GetTopPadding() { |
| 109 return ui::MaterialDesignController::IsModeMaterial() ? 1 : kTopBottomPadding; | |
|
Evan Stade
2016/04/11 19:22:44
this change leaves room for the top separator.
| |
| 110 } | |
| 111 | |
| 112 int GetBottomPadding() { | |
| 109 return ui::MaterialDesignController::IsModeMaterial() ? 0 : kTopBottomPadding; | 113 return ui::MaterialDesignController::IsModeMaterial() ? 0 : kTopBottomPadding; |
| 110 } | 114 } |
| 111 | 115 |
| 112 // Sets size->width() to view's preferred width + size->width().s | 116 // Sets size->width() to view's preferred width + size->width().s |
| 113 // Sets size->height() to the max of the view's preferred height and | 117 // Sets size->height() to the max of the view's preferred height and |
| 114 // size->height(); | 118 // size->height(); |
| 115 void AdjustSize(views::View* view, gfx::Size* size) { | 119 void AdjustSize(views::View* view, gfx::Size* size) { |
| 116 gfx::Size view_preferred = view->GetPreferredSize(); | 120 gfx::Size view_preferred = view->GetPreferredSize(); |
| 117 size->Enlarge(view_preferred.width(), 0); | 121 size->Enlarge(view_preferred.width(), 0); |
| 118 size->set_height(std::max(view_preferred.height(), size->height())); | 122 size->set_height(std::max(view_preferred.height(), size->height())); |
| 119 } | 123 } |
| 120 | 124 |
| 121 int CenterPosition(int size, int target_size) { | 125 int CenterPosition(int size, int target_size) { |
| 122 return std::max((target_size - size) / 2, GetTopBottomPadding()); | 126 return std::max((target_size - size) / 2, GetTopPadding()); |
| 123 } | 127 } |
| 124 | 128 |
| 125 } // namespace | 129 } // namespace |
| 126 | 130 |
| 127 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) | 131 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) |
| 128 : browser_(browser), | 132 : browser_(browser), |
| 129 new_item_animation_(this), | 133 new_item_animation_(this), |
| 130 shelf_animation_(this), | 134 shelf_animation_(this), |
| 131 arrow_image_(nullptr), | 135 arrow_image_(nullptr), |
| 132 show_all_view_(nullptr), | 136 show_all_view_(nullptr), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 gfx::Size DownloadShelfView::GetPreferredSize() const { | 254 gfx::Size DownloadShelfView::GetPreferredSize() const { |
| 251 gfx::Size prefsize( | 255 gfx::Size prefsize( |
| 252 GetEndPadding() + GetStartPadding() + GetCloseAndLinkPadding(), 0); | 256 GetEndPadding() + GetStartPadding() + GetCloseAndLinkPadding(), 0); |
| 253 AdjustSize(close_button_, &prefsize); | 257 AdjustSize(close_button_, &prefsize); |
| 254 AdjustSize(show_all_view_, &prefsize); | 258 AdjustSize(show_all_view_, &prefsize); |
| 255 // Add one download view to the preferred size. | 259 // Add one download view to the preferred size. |
| 256 if (!download_views_.empty()) { | 260 if (!download_views_.empty()) { |
| 257 AdjustSize(*download_views_.begin(), &prefsize); | 261 AdjustSize(*download_views_.begin(), &prefsize); |
| 258 prefsize.Enlarge(GetBetweenItemPadding(), 0); | 262 prefsize.Enlarge(GetBetweenItemPadding(), 0); |
| 259 } | 263 } |
| 260 prefsize.Enlarge(0, 2 * GetTopBottomPadding()); | 264 prefsize.Enlarge(0, GetTopPadding() + GetBottomPadding()); |
| 261 if (shelf_animation_.is_animating()) { | 265 if (shelf_animation_.is_animating()) { |
| 262 prefsize.set_height( | 266 prefsize.set_height( |
| 263 static_cast<int>(static_cast<double>(prefsize.height()) * | 267 static_cast<int>(static_cast<double>(prefsize.height()) * |
| 264 shelf_animation_.GetCurrentValue())); | 268 shelf_animation_.GetCurrentValue())); |
| 265 } | 269 } |
| 266 return prefsize; | 270 return prefsize; |
| 267 } | 271 } |
| 268 | 272 |
| 269 void DownloadShelfView::AnimationProgressed(const gfx::Animation* animation) { | 273 void DownloadShelfView::AnimationProgressed(const gfx::Animation* animation) { |
| 270 if (animation == &new_item_animation_) { | 274 if (animation == &new_item_animation_) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 | 489 |
| 486 content::DownloadItem* DownloadShelfView::GetDownloadItemForView(size_t i) { | 490 content::DownloadItem* DownloadShelfView::GetDownloadItemForView(size_t i) { |
| 487 if (ui::MaterialDesignController::IsModeMaterial()) | 491 if (ui::MaterialDesignController::IsModeMaterial()) |
| 488 return static_cast<DownloadItemViewMd*>(download_views_[i])->download(); | 492 return static_cast<DownloadItemViewMd*>(download_views_[i])->download(); |
| 489 return static_cast<DownloadItemView*>(download_views_[i])->download(); | 493 return static_cast<DownloadItemView*>(download_views_[i])->download(); |
| 490 } | 494 } |
| 491 | 495 |
| 492 SkColor DownloadShelfView::GetTextColorForIconMd() { | 496 SkColor DownloadShelfView::GetTextColorForIconMd() { |
| 493 return DownloadItemViewMd::GetTextColorForThemeProvider(GetThemeProvider()); | 497 return DownloadItemViewMd::GetTextColorForThemeProvider(GetThemeProvider()); |
| 494 } | 498 } |
| OLD | NEW |