Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: chrome/browser/ui/views/download/download_shelf_view.cc

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 #include "content/public/browser/page_navigator.h" 27 #include "content/public/browser/page_navigator.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/theme_provider.h" 30 #include "ui/base/theme_provider.h"
31 #include "ui/gfx/animation/slide_animation.h" 31 #include "ui/gfx/animation/slide_animation.h"
32 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/resources/grit/ui_resources.h" 33 #include "ui/resources/grit/ui_resources.h"
34 #include "ui/vector_icons/vector_icons.h" 34 #include "ui/vector_icons/vector_icons.h"
35 #include "ui/views/background.h" 35 #include "ui/views/background.h"
36 #include "ui/views/border.h" 36 #include "ui/views/border.h"
37 #include "ui/views/controls/button/image_button.h"
38 #include "ui/views/controls/button/image_button_util.h"
37 #include "ui/views/controls/button/md_text_button.h" 39 #include "ui/views/controls/button/md_text_button.h"
38 #include "ui/views/controls/button/vector_icon_button.h"
39 #include "ui/views/controls/link.h" 40 #include "ui/views/controls/link.h"
40 #include "ui/views/mouse_watcher_view_host.h" 41 #include "ui/views/mouse_watcher_view_host.h"
41 42
42 using content::DownloadItem; 43 using content::DownloadItem;
43 44
44 namespace { 45 namespace {
45 46
46 // Max number of download views we'll contain. Any time a view is added and 47 // Max number of download views we'll contain. Any time a view is added and
47 // we already have this many download views, one is removed. 48 // we already have this many download views, one is removed.
48 const size_t kMaxDownloadViews = 15; 49 const size_t kMaxDownloadViews = 15;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return std::max((target_size - size) / 2, kTopPadding); 89 return std::max((target_size - size) / 2, kTopPadding);
89 } 90 }
90 91
91 } // namespace 92 } // namespace
92 93
93 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) 94 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent)
94 : browser_(browser), 95 : browser_(browser),
95 new_item_animation_(this), 96 new_item_animation_(this),
96 shelf_animation_(this), 97 shelf_animation_(this),
97 show_all_view_(nullptr), 98 show_all_view_(nullptr),
98 close_button_(nullptr), 99 close_button_(views::CreateImageButtonWithVectorIconStyling(this)),
99 parent_(parent), 100 parent_(parent),
100 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()), 101 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()),
101 this) { 102 this) {
102 // Start out hidden: the shelf might be created but never shown in some 103 // Start out hidden: the shelf might be created but never shown in some
103 // cases, like when installing a theme. See DownloadShelf::AddDownload(). 104 // cases, like when installing a theme. See DownloadShelf::AddDownload().
104 SetVisible(false); 105 SetVisible(false);
105 106
106 mouse_watcher_.set_notify_on_exit_time( 107 mouse_watcher_.set_notify_on_exit_time(
107 base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS)); 108 base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS));
108 set_id(VIEW_ID_DOWNLOAD_SHELF); 109 set_id(VIEW_ID_DOWNLOAD_SHELF);
109 parent->AddChildView(this); 110 parent->AddChildView(this);
110 111
111 show_all_view_ = views::MdTextButton::Create( 112 show_all_view_ = views::MdTextButton::Create(
112 this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); 113 this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS));
113 AddChildView(show_all_view_); 114 AddChildView(show_all_view_);
114 115
115 views::VectorIconButton* close_button = new views::VectorIconButton(this);
116 close_button->SetIcon(ui::kCloseIcon);
117 close_button_ = close_button;
118 close_button_->SetAccessibleName( 116 close_button_->SetAccessibleName(
119 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); 117 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
120 AddChildView(close_button_); 118 AddChildView(close_button_);
119 UpdateCloseButton();
Evan Stade 2017/03/17 13:54:44 is this necessary? We do it when added to the view
Bret 2017/03/17 23:41:41 This one isn't necessary. Removed.
121 120
122 new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs); 121 new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs);
123 shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs); 122 shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs);
124 } 123 }
125 124
126 DownloadShelfView::~DownloadShelfView() { 125 DownloadShelfView::~DownloadShelfView() {
127 parent_->RemoveChildView(this); 126 parent_->RemoveChildView(this);
128 } 127 }
129 128
130 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { 129 void DownloadShelfView::AddDownloadView(DownloadItemView* view) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 327
329 void DownloadShelfView::UpdateColorsFromTheme() { 328 void DownloadShelfView::UpdateColorsFromTheme() {
330 if (!GetThemeProvider()) 329 if (!GetThemeProvider())
331 return; 330 return;
332 331
333 if (show_all_view_) 332 if (show_all_view_)
334 ConfigureButtonForTheme(show_all_view_); 333 ConfigureButtonForTheme(show_all_view_);
335 334
336 set_background(views::Background::CreateSolidBackground( 335 set_background(views::Background::CreateSolidBackground(
337 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); 336 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)));
337
338 UpdateCloseButton();
338 } 339 }
339 340
340 void DownloadShelfView::OnThemeChanged() { 341 void DownloadShelfView::OnThemeChanged() {
341 UpdateColorsFromTheme(); 342 UpdateColorsFromTheme();
342 } 343 }
343 344
345 void DownloadShelfView::UpdateCloseButton() {
346 views::SetImageFromVectorIcon(
347 close_button_, ui::kCloseIcon,
348 DownloadItemView::GetTextColorForThemeProvider(GetThemeProvider()));
349 }
350
344 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { 351 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) {
345 chrome::ShowDownloads(browser_); 352 chrome::ShowDownloads(browser_);
346 } 353 }
347 354
348 void DownloadShelfView::ButtonPressed( 355 void DownloadShelfView::ButtonPressed(
349 views::Button* button, const ui::Event& event) { 356 views::Button* button, const ui::Event& event) {
350 if (button == close_button_) 357 if (button == close_button_)
351 Close(USER_ACTION); 358 Close(USER_ACTION);
352 else if (button == show_all_view_) 359 else if (button == show_all_view_)
353 chrome::ShowDownloads(browser_); 360 chrome::ShowDownloads(browser_);
354 else 361 else
355 NOTREACHED(); 362 NOTREACHED();
356 } 363 }
357 364
358 SkColor DownloadShelfView::GetVectorIconBaseColor() const {
359 return DownloadItemView::GetTextColorForThemeProvider(GetThemeProvider());
360 }
361
362 bool DownloadShelfView::IsShowing() const { 365 bool DownloadShelfView::IsShowing() const {
363 return visible() && shelf_animation_.IsShowing(); 366 return visible() && shelf_animation_.IsShowing();
364 } 367 }
365 368
366 bool DownloadShelfView::IsClosing() const { 369 bool DownloadShelfView::IsClosing() const {
367 return shelf_animation_.IsClosing(); 370 return shelf_animation_.IsClosing();
368 } 371 }
369 372
370 void DownloadShelfView::DoOpen() { 373 void DownloadShelfView::DoOpen() {
371 SetVisible(true); 374 SetVisible(true);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 SetVisible(false); 428 SetVisible(false);
426 } 429 }
427 430
428 bool DownloadShelfView::CanAutoClose() { 431 bool DownloadShelfView::CanAutoClose() {
429 for (size_t i = 0; i < download_views_.size(); ++i) { 432 for (size_t i = 0; i < download_views_.size(); ++i) {
430 if (!download_views_[i]->download()->GetOpened()) 433 if (!download_views_[i]->download()->GetOpened())
431 return false; 434 return false;
432 } 435 }
433 return true; 436 return true;
434 } 437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698