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

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

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: check details 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_factory.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::CreateVectorImageButton(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_);
121 119
122 new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs); 120 new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs);
123 shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs); 121 shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs);
124 } 122 }
125 123
126 DownloadShelfView::~DownloadShelfView() { 124 DownloadShelfView::~DownloadShelfView() {
127 parent_->RemoveChildView(this); 125 parent_->RemoveChildView(this);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 326
329 void DownloadShelfView::UpdateColorsFromTheme() { 327 void DownloadShelfView::UpdateColorsFromTheme() {
330 if (!GetThemeProvider()) 328 if (!GetThemeProvider())
331 return; 329 return;
332 330
333 if (show_all_view_) 331 if (show_all_view_)
334 ConfigureButtonForTheme(show_all_view_); 332 ConfigureButtonForTheme(show_all_view_);
335 333
336 set_background(views::Background::CreateSolidBackground( 334 set_background(views::Background::CreateSolidBackground(
337 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); 335 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)));
336
337 views::SetImageFromVectorIcon(
338 close_button_, ui::kCloseIcon,
339 DownloadItemView::GetTextColorForThemeProvider(GetThemeProvider()));
338 } 340 }
339 341
340 void DownloadShelfView::OnThemeChanged() { 342 void DownloadShelfView::OnThemeChanged() {
341 UpdateColorsFromTheme(); 343 UpdateColorsFromTheme();
342 } 344 }
343 345
344 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { 346 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) {
345 chrome::ShowDownloads(browser_); 347 chrome::ShowDownloads(browser_);
346 } 348 }
347 349
348 void DownloadShelfView::ButtonPressed( 350 void DownloadShelfView::ButtonPressed(
349 views::Button* button, const ui::Event& event) { 351 views::Button* button, const ui::Event& event) {
350 if (button == close_button_) 352 if (button == close_button_)
351 Close(USER_ACTION); 353 Close(USER_ACTION);
352 else if (button == show_all_view_) 354 else if (button == show_all_view_)
353 chrome::ShowDownloads(browser_); 355 chrome::ShowDownloads(browser_);
354 else 356 else
355 NOTREACHED(); 357 NOTREACHED();
356 } 358 }
357 359
358 SkColor DownloadShelfView::GetVectorIconBaseColor() const {
359 return DownloadItemView::GetTextColorForThemeProvider(GetThemeProvider());
360 }
361
362 bool DownloadShelfView::IsShowing() const { 360 bool DownloadShelfView::IsShowing() const {
363 return visible() && shelf_animation_.IsShowing(); 361 return visible() && shelf_animation_.IsShowing();
364 } 362 }
365 363
366 bool DownloadShelfView::IsClosing() const { 364 bool DownloadShelfView::IsClosing() const {
367 return shelf_animation_.IsClosing(); 365 return shelf_animation_.IsClosing();
368 } 366 }
369 367
370 void DownloadShelfView::DoOpen() { 368 void DownloadShelfView::DoOpen() {
371 SetVisible(true); 369 SetVisible(true);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 SetVisible(false); 423 SetVisible(false);
426 } 424 }
427 425
428 bool DownloadShelfView::CanAutoClose() { 426 bool DownloadShelfView::CanAutoClose() {
429 for (size_t i = 0; i < download_views_.size(); ++i) { 427 for (size_t i = 0; i < download_views_.size(); ++i) {
430 if (!download_views_[i]->download()->GetOpened()) 428 if (!download_views_[i]->download()->GetOpened())
431 return false; 429 return false;
432 } 430 }
433 return true; 431 return true;
434 } 432 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/download/download_shelf_view.h ('k') | chrome/browser/ui/views/find_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698