OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 11 #include "base/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/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/view_ids.h" | 15 #include "chrome/browser/ui/view_ids.h" |
16 #include "chrome/browser/ui/views/download/download_item_view.h" | 16 #include "chrome/browser/ui/views/download/download_item_view.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
18 #include "content/browser/download/download_item.h" | 18 #include "content/browser/download/download_item.h" |
| 19 #include "content/browser/download/download_stats.h" |
19 #include "content/browser/download/download_manager.h" | 20 #include "content/browser/download/download_manager.h" |
20 #include "content/browser/tab_contents/navigation_entry.h" | 21 #include "content/browser/tab_contents/navigation_entry.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
23 #include "grit/theme_resources_standard.h" | 24 #include "grit/theme_resources_standard.h" |
24 #include "ui/base/animation/slide_animation.h" | 25 #include "ui/base/animation/slide_animation.h" |
25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
27 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
28 #include "views/background.h" | 29 #include "views/background.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 82 |
82 int CenterPosition(int size, int target_size) { | 83 int CenterPosition(int size, int target_size) { |
83 return std::max((target_size - size) / 2, kTopBottomPadding); | 84 return std::max((target_size - size) / 2, kTopBottomPadding); |
84 } | 85 } |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) | 89 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) |
89 : browser_(browser), | 90 : browser_(browser), |
90 parent_(parent), | 91 parent_(parent), |
| 92 auto_closed_(true), |
91 ALLOW_THIS_IN_INITIALIZER_LIST( | 93 ALLOW_THIS_IN_INITIALIZER_LIST( |
92 mouse_watcher_(this, this, gfx::Insets())) { | 94 mouse_watcher_(this, this, gfx::Insets())) { |
93 mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS); | 95 mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS); |
94 set_id(VIEW_ID_DOWNLOAD_SHELF); | 96 set_id(VIEW_ID_DOWNLOAD_SHELF); |
95 parent->AddChildView(this); | 97 parent->AddChildView(this); |
96 Show(); | 98 Show(); |
97 } | 99 } |
98 | 100 |
99 DownloadShelfView::~DownloadShelfView() { | 101 DownloadShelfView::~DownloadShelfView() { |
100 parent_->RemoveChildView(this); | 102 parent_->RemoveChildView(this); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 void DownloadShelfView::OnThemeChanged() { | 366 void DownloadShelfView::OnThemeChanged() { |
365 UpdateButtonColors(); | 367 UpdateButtonColors(); |
366 } | 368 } |
367 | 369 |
368 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { | 370 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { |
369 browser_->ShowDownloadsTab(); | 371 browser_->ShowDownloadsTab(); |
370 } | 372 } |
371 | 373 |
372 void DownloadShelfView::ButtonPressed( | 374 void DownloadShelfView::ButtonPressed( |
373 views::Button* button, const views::Event& event) { | 375 views::Button* button, const views::Event& event) { |
| 376 auto_closed_ = false; |
374 Close(); | 377 Close(); |
375 } | 378 } |
376 | 379 |
377 bool DownloadShelfView::IsShowing() const { | 380 bool DownloadShelfView::IsShowing() const { |
378 return shelf_animation_->IsShowing(); | 381 return shelf_animation_->IsShowing(); |
379 } | 382 } |
380 | 383 |
381 bool DownloadShelfView::IsClosing() const { | 384 bool DownloadShelfView::IsClosing() const { |
382 return shelf_animation_->IsClosing(); | 385 return shelf_animation_->IsClosing(); |
383 } | 386 } |
384 | 387 |
385 void DownloadShelfView::Show() { | 388 void DownloadShelfView::Show() { |
386 shelf_animation_->Show(); | 389 shelf_animation_->Show(); |
387 } | 390 } |
388 | 391 |
389 void DownloadShelfView::Close() { | 392 void DownloadShelfView::Close() { |
| 393 int num_in_progress = 0; |
| 394 for (size_t i = 0; i < download_views_.size(); ++i) { |
| 395 if (download_views_[i]->download()->IsInProgress()) |
| 396 ++num_in_progress; |
| 397 } |
| 398 download_stats::RecordShelfClose( |
| 399 download_views_.size(), num_in_progress, auto_closed_); |
390 parent_->SetDownloadShelfVisible(false); | 400 parent_->SetDownloadShelfVisible(false); |
391 shelf_animation_->Hide(); | 401 shelf_animation_->Hide(); |
| 402 auto_closed_ = true; |
392 } | 403 } |
393 | 404 |
394 Browser* DownloadShelfView::browser() const { | 405 Browser* DownloadShelfView::browser() const { |
395 return browser_; | 406 return browser_; |
396 } | 407 } |
397 | 408 |
398 void DownloadShelfView::Closed() { | 409 void DownloadShelfView::Closed() { |
399 // When the close animation is complete, remove all completed downloads. | 410 // When the close animation is complete, remove all completed downloads. |
400 size_t i = 0; | 411 size_t i = 0; |
401 while (i < download_views_.size()) { | 412 while (i < download_views_.size()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 const DownloadItemView* download_item_view) { | 458 const DownloadItemView* download_item_view) { |
448 gfx::Rect bounds = download_item_view->bounds(); | 459 gfx::Rect bounds = download_item_view->bounds(); |
449 | 460 |
450 #if defined(TOOLKIT_VIEWS) | 461 #if defined(TOOLKIT_VIEWS) |
451 bounds.set_height(bounds.height() - 1); | 462 bounds.set_height(bounds.height() - 1); |
452 bounds.Offset(0, 3); | 463 bounds.Offset(0, 3); |
453 #endif | 464 #endif |
454 | 465 |
455 return bounds; | 466 return bounds; |
456 } | 467 } |
OLD | NEW |