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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 RemoveChildView(view); | 160 RemoveChildView(view); |
| 161 delete view; | 161 delete view; |
| 162 if (download_views_.empty()) | 162 if (download_views_.empty()) |
| 163 Close(AUTOMATIC); | 163 Close(AUTOMATIC); |
| 164 else if (CanAutoClose()) | 164 else if (CanAutoClose()) |
| 165 mouse_watcher_.Start(); | 165 mouse_watcher_.Start(); |
| 166 Layout(); | 166 Layout(); |
| 167 SchedulePaint(); | 167 SchedulePaint(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void DownloadShelfView::ConfigureButtonForTheme(views::MdTextButton* button) { | |
| 171 if (!GetThemeProvider()) | |
| 172 return; | |
| 173 | |
| 174 const SkColor bg_color = | |
| 175 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR); | |
| 176 set_background(views::Background::CreateSolidBackground(bg_color)); | |
|
msw
2016/10/20 21:54:05
Why would each call to ConfigureButtonForTheme cha
Evan Stade
2016/10/20 23:11:02
no reason, done
| |
| 177 button->SetEnabledTextColors( | |
| 178 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | |
| 179 if (ThemeServiceFactory::GetForProfile(browser_->profile()) | |
| 180 ->UsingDefaultTheme()) { | |
| 181 // For the normal theme, just use the default button bg color. | |
| 182 button->SetBgColorOverride(base::Optional<SkColor>()); | |
| 183 } else { | |
| 184 // For custom themes, we have to make up a background color for the | |
| 185 // button. Use a slight tint of the shelf background. | |
| 186 button->SetBgColorOverride( | |
| 187 color_utils::BlendTowardOppositeLuma(bg_color, 0x10)); | |
| 188 } | |
| 189 } | |
| 190 | |
| 170 views::View* DownloadShelfView::GetDefaultFocusableChild() { | 191 views::View* DownloadShelfView::GetDefaultFocusableChild() { |
| 171 if (!download_views_.empty()) | 192 if (!download_views_.empty()) |
| 172 return download_views_.back(); | 193 return download_views_.back(); |
| 173 | 194 |
| 174 return show_all_view_; | 195 return show_all_view_; |
| 175 } | 196 } |
| 176 | 197 |
| 177 void DownloadShelfView::OnPaintBorder(gfx::Canvas* canvas) { | 198 void DownloadShelfView::OnPaintBorder(gfx::Canvas* canvas) { |
| 178 canvas->FillRect(gfx::Rect(0, 0, width(), 1), kBorderColor); | 199 canvas->FillRect(gfx::Rect(0, 0, width(), 1), kBorderColor); |
| 179 } | 200 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 kCloseAndLinkPadding - show_all_size.width() - | 324 kCloseAndLinkPadding - show_all_size.width() - |
| 304 kStartPadding; | 325 kStartPadding; |
| 305 if (available_width <= 0) | 326 if (available_width <= 0) |
| 306 return false; | 327 return false; |
| 307 | 328 |
| 308 gfx::Size item_size = (*download_views_.rbegin())->GetPreferredSize(); | 329 gfx::Size item_size = (*download_views_.rbegin())->GetPreferredSize(); |
| 309 return item_size.width() < available_width; | 330 return item_size.width() < available_width; |
| 310 } | 331 } |
| 311 | 332 |
| 312 void DownloadShelfView::UpdateColorsFromTheme() { | 333 void DownloadShelfView::UpdateColorsFromTheme() { |
| 313 if (show_all_view_ && close_button_ && GetThemeProvider()) { | 334 if (show_all_view_) |
| 314 const SkColor bg_color = | 335 ConfigureButtonForTheme(show_all_view_); |
| 315 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR); | |
| 316 set_background(views::Background::CreateSolidBackground(bg_color)); | |
| 317 show_all_view_->SetEnabledTextColors( | |
| 318 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | |
| 319 if (ThemeServiceFactory::GetForProfile(browser_->profile()) | |
| 320 ->UsingDefaultTheme()) { | |
| 321 // For the normal theme, just use the default button bg color. | |
| 322 show_all_view_->SetBgColorOverride(base::Optional<SkColor>()); | |
| 323 } else { | |
| 324 // For custom themes, we have to make up a background color for the | |
| 325 // button. Use a slight tint of the shelf background. | |
| 326 show_all_view_->SetBgColorOverride( | |
| 327 color_utils::BlendTowardOppositeLuma(bg_color, 0x10)); | |
| 328 } | |
| 329 } | |
| 330 } | 336 } |
| 331 | 337 |
| 332 void DownloadShelfView::OnThemeChanged() { | 338 void DownloadShelfView::OnThemeChanged() { |
| 333 UpdateColorsFromTheme(); | 339 UpdateColorsFromTheme(); |
| 334 } | 340 } |
| 335 | 341 |
| 336 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { | 342 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { |
| 337 chrome::ShowDownloads(browser_); | 343 chrome::ShowDownloads(browser_); |
| 338 } | 344 } |
| 339 | 345 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 SetVisible(false); | 411 SetVisible(false); |
| 406 } | 412 } |
| 407 | 413 |
| 408 bool DownloadShelfView::CanAutoClose() { | 414 bool DownloadShelfView::CanAutoClose() { |
| 409 for (size_t i = 0; i < download_views_.size(); ++i) { | 415 for (size_t i = 0; i < download_views_.size(); ++i) { |
| 410 if (!download_views_[i]->download()->GetOpened()) | 416 if (!download_views_[i]->download()->GetOpened()) |
| 411 return false; | 417 return false; |
| 412 } | 418 } |
| 413 return true; | 419 return true; |
| 414 } | 420 } |
| OLD | NEW |