| 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/bar_control_button.h" | 
| 18 #include "chrome/browser/ui/views/download/download_item_view.h" | 19 #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/download/download_item_view_md.h" | 
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" | 
| 21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" | 
| 22 #include "content/public/browser/download_item.h" | 23 #include "content/public/browser/download_item.h" | 
| 23 #include "content/public/browser/download_manager.h" | 24 #include "content/public/browser/download_manager.h" | 
| 24 #include "content/public/browser/page_navigator.h" | 25 #include "content/public/browser/page_navigator.h" | 
| 25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" | 
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" | 
| 27 #include "ui/base/resource/material_design/material_design_controller.h" | 28 #include "ui/base/resource/material_design/material_design_controller.h" | 
| 28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" | 
| 29 #include "ui/base/theme_provider.h" | 30 #include "ui/base/theme_provider.h" | 
| 30 #include "ui/gfx/animation/slide_animation.h" | 31 #include "ui/gfx/animation/slide_animation.h" | 
| 31 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" | 
| 32 #include "ui/gfx/color_palette.h" |  | 
| 33 #include "ui/gfx/paint_vector_icon.h" |  | 
| 34 #include "ui/gfx/vector_icons_public.h" | 33 #include "ui/gfx/vector_icons_public.h" | 
| 35 #include "ui/resources/grit/ui_resources.h" | 34 #include "ui/resources/grit/ui_resources.h" | 
| 36 #include "ui/views/background.h" | 35 #include "ui/views/background.h" | 
| 37 #include "ui/views/border.h" | 36 #include "ui/views/border.h" | 
| 38 #include "ui/views/controls/button/image_button.h" | 37 #include "ui/views/controls/button/image_button.h" | 
| 39 #include "ui/views/controls/button/label_button.h" | 38 #include "ui/views/controls/button/label_button.h" | 
| 40 #include "ui/views/controls/image_view.h" | 39 #include "ui/views/controls/image_view.h" | 
| 41 #include "ui/views/controls/link.h" | 40 #include "ui/views/controls/link.h" | 
| 42 #include "ui/views/mouse_watcher_view_host.h" | 41 #include "ui/views/mouse_watcher_view_host.h" | 
| 43 | 42 | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 136                      this) { | 135                      this) { | 
| 137   mouse_watcher_.set_notify_on_exit_time( | 136   mouse_watcher_.set_notify_on_exit_time( | 
| 138       base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS)); | 137       base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS)); | 
| 139   set_id(VIEW_ID_DOWNLOAD_SHELF); | 138   set_id(VIEW_ID_DOWNLOAD_SHELF); | 
| 140   parent->AddChildView(this); | 139   parent->AddChildView(this); | 
| 141 | 140 | 
| 142   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 141   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 
| 143 | 142 | 
| 144   arrow_image_ = new views::ImageView(); | 143   arrow_image_ = new views::ImageView(); | 
| 145   AddChildView(arrow_image_); | 144   AddChildView(arrow_image_); | 
| 146   close_button_ = new views::ImageButton(this); |  | 
| 147   close_button_->SetAccessibleName( |  | 
| 148       l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |  | 
| 149   if (!ui::MaterialDesignController::IsModeMaterial()) { | 145   if (!ui::MaterialDesignController::IsModeMaterial()) { | 
| 150     arrow_image_->SetImage(rb.GetImageSkiaNamed(IDR_DOWNLOADS_FAVICON)); | 146     arrow_image_->SetImage(rb.GetImageSkiaNamed(IDR_DOWNLOADS_FAVICON)); | 
| 151 | 147 | 
| 152     views::Link* show_all_view = | 148     views::Link* show_all_view = | 
| 153         new views::Link(l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); | 149         new views::Link(l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); | 
| 154     show_all_view->set_listener(this); | 150     show_all_view->set_listener(this); | 
| 155     show_all_view_ = show_all_view; | 151     show_all_view_ = show_all_view; | 
| 156 | 152 | 
|  | 153     close_button_ = new views::ImageButton(this); | 
| 157     close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 154     close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 
| 158                             rb.GetImageSkiaNamed(IDR_CLOSE_1)); | 155                             rb.GetImageSkiaNamed(IDR_CLOSE_1)); | 
| 159     close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 156     close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 
| 160                             rb.GetImageSkiaNamed(IDR_CLOSE_1_H)); | 157                             rb.GetImageSkiaNamed(IDR_CLOSE_1_H)); | 
| 161     close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 158     close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 
| 162                             rb.GetImageSkiaNamed(IDR_CLOSE_1_P)); | 159                             rb.GetImageSkiaNamed(IDR_CLOSE_1_P)); | 
| 163   } else { | 160   } else { | 
| 164     views::LabelButton* show_all_view = new views::LabelButton( | 161     views::LabelButton* show_all_view = new views::LabelButton( | 
| 165         this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS_MD)); | 162         this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS_MD)); | 
| 166     show_all_view->SetFocusable(true); | 163     show_all_view->SetFocusable(true); | 
| 167     show_all_view->SetStyle(views::Button::STYLE_BUTTON); | 164     show_all_view->SetStyle(views::Button::STYLE_BUTTON); | 
| 168     show_all_view_ = show_all_view; | 165     show_all_view_ = show_all_view; | 
| 169 | 166 | 
| 170     // TODO(estade): share this button init code with the find in page bar; | 167     BarControlButton* close_button = new BarControlButton(this); | 
| 171     // also fix theming. | 168     close_button->SetIcon(gfx::VectorIconId::BAR_CLOSE, | 
| 172     close_button_->SetBorder(views::Border::CreateEmptyBorder(4, 4, 4, 4)); | 169                           base::Bind(&DownloadShelfView::GetTextColorForIconMd, | 
| 173     close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 170                                      base::Unretained(this))); | 
| 174                                      views::ImageButton::ALIGN_MIDDLE); | 171     close_button_ = close_button; | 
| 175     gfx::ImageSkia image = gfx::CreateVectorIcon(gfx::VectorIconId::BAR_CLOSE, |  | 
| 176                                                  16, gfx::kChromeIconGrey); |  | 
| 177     close_button_->SetImage(views::CustomButton::STATE_NORMAL, &image); |  | 
| 178   } | 172   } | 
|  | 173   close_button_->SetAccessibleName( | 
|  | 174       l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 
| 179   AddChildView(show_all_view_); | 175   AddChildView(show_all_view_); | 
| 180   AddChildView(close_button_); | 176   AddChildView(close_button_); | 
| 181 | 177 | 
| 182   new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs); | 178   new_item_animation_.SetSlideDuration(kNewItemAnimationDurationMs); | 
| 183   shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs); | 179   shelf_animation_.SetSlideDuration(kShelfAnimationDurationMs); | 
| 184 } | 180 } | 
| 185 | 181 | 
| 186 DownloadShelfView::~DownloadShelfView() { | 182 DownloadShelfView::~DownloadShelfView() { | 
| 187   parent_->RemoveChildView(this); | 183   parent_->RemoveChildView(this); | 
| 188 } | 184 } | 
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 390 void DownloadShelfView::UpdateColorsFromTheme() { | 386 void DownloadShelfView::UpdateColorsFromTheme() { | 
| 391   if (show_all_view_ && close_button_ && GetThemeProvider()) { | 387   if (show_all_view_ && close_button_ && GetThemeProvider()) { | 
| 392     set_background(views::Background::CreateSolidBackground( | 388     set_background(views::Background::CreateSolidBackground( | 
| 393         GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); | 389         GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); | 
| 394 | 390 | 
| 395     if (!ui::MaterialDesignController::IsModeMaterial()) { | 391     if (!ui::MaterialDesignController::IsModeMaterial()) { | 
| 396       views::Link* show_all_view = static_cast<views::Link*>(show_all_view_); | 392       views::Link* show_all_view = static_cast<views::Link*>(show_all_view_); | 
| 397       show_all_view->SetBackgroundColor(background()->get_color()); | 393       show_all_view->SetBackgroundColor(background()->get_color()); | 
| 398       show_all_view->SetEnabledColor( | 394       show_all_view->SetEnabledColor( | 
| 399           GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | 395           GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | 
|  | 396 | 
|  | 397       ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 
|  | 398       close_button_->SetBackground( | 
|  | 399           GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | 
|  | 400           rb.GetImageSkiaNamed(IDR_CLOSE_1), | 
|  | 401           rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | 
| 400     } | 402     } | 
| 401 |  | 
| 402     ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |  | 
| 403     set_background(views::Background::CreateSolidBackground( |  | 
| 404         GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); |  | 
| 405     close_button_->SetBackground( |  | 
| 406         GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), |  | 
| 407         rb.GetImageSkiaNamed(IDR_CLOSE_1), |  | 
| 408         rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |  | 
| 409   } | 403   } | 
| 410 } | 404 } | 
| 411 | 405 | 
| 412 void DownloadShelfView::OnThemeChanged() { | 406 void DownloadShelfView::OnThemeChanged() { | 
| 413   UpdateColorsFromTheme(); | 407   UpdateColorsFromTheme(); | 
| 414 } | 408 } | 
| 415 | 409 | 
| 416 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { | 410 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { | 
| 417   chrome::ShowDownloads(browser_); | 411   chrome::ShowDownloads(browser_); | 
| 418 } | 412 } | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 487       return false; | 481       return false; | 
| 488   } | 482   } | 
| 489   return true; | 483   return true; | 
| 490 } | 484 } | 
| 491 | 485 | 
| 492 content::DownloadItem* DownloadShelfView::GetDownloadItemForView(size_t i) { | 486 content::DownloadItem* DownloadShelfView::GetDownloadItemForView(size_t i) { | 
| 493   if (ui::MaterialDesignController::IsModeMaterial()) | 487   if (ui::MaterialDesignController::IsModeMaterial()) | 
| 494     return static_cast<DownloadItemViewMd*>(download_views_[i])->download(); | 488     return static_cast<DownloadItemViewMd*>(download_views_[i])->download(); | 
| 495   return static_cast<DownloadItemView*>(download_views_[i])->download(); | 489   return static_cast<DownloadItemView*>(download_views_[i])->download(); | 
| 496 } | 490 } | 
|  | 491 | 
|  | 492 SkColor DownloadShelfView::GetTextColorForIconMd() { | 
|  | 493   return DownloadItemViewMd::GetTextColorForThemeProvider(GetThemeProvider()); | 
|  | 494 } | 
| OLD | NEW | 
|---|