| 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_item_view.h" | 5 #include "chrome/browser/ui/views/download/download_item_view.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 89 | 89 | 
| 90 // How long we keep the item disabled after the user clicked it to open the | 90 // How long we keep the item disabled after the user clicked it to open the | 
| 91 // downloaded item. | 91 // downloaded item. | 
| 92 static const int kDisabledOnOpenDuration = 3000; | 92 static const int kDisabledOnOpenDuration = 3000; | 
| 93 | 93 | 
| 94 // Darken light-on-dark download status text by 20% before drawing, thus | 94 // Darken light-on-dark download status text by 20% before drawing, thus | 
| 95 // creating a "muted" version of title text for both dark-on-light and | 95 // creating a "muted" version of title text for both dark-on-light and | 
| 96 // light-on-dark themes. | 96 // light-on-dark themes. | 
| 97 static const double kDownloadItemLuminanceMod = 0.8; | 97 static const double kDownloadItemLuminanceMod = 0.8; | 
| 98 | 98 | 
| 99 namespace { |  | 
| 100 |  | 
| 101 // Callback for DownloadShelf paint functions to mirror the progress animation |  | 
| 102 // in RTL locales. |  | 
| 103 void RTLMirrorXForView(views::View* containing_view, gfx::Rect* bounds) { |  | 
| 104   bounds->set_x(containing_view->GetMirroredXForRect(*bounds)); |  | 
| 105 } |  | 
| 106 |  | 
| 107 }  // namespace |  | 
| 108 |  | 
| 109 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 99 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 
| 110     DownloadShelfView* parent) | 100     DownloadShelfView* parent) | 
| 111   : warning_icon_(NULL), | 101   : warning_icon_(NULL), | 
| 112     shelf_(parent), | 102     shelf_(parent), | 
| 113     status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 103     status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 
| 114     body_state_(NORMAL), | 104     body_state_(NORMAL), | 
| 115     drop_down_state_(NORMAL), | 105     drop_down_state_(NORMAL), | 
| 116     mode_(NORMAL_MODE), | 106     mode_(NORMAL_MODE), | 
| 117     progress_angle_(DownloadShelf::kStartAngleDegrees), |  | 
| 118     drop_down_pressed_(false), | 107     drop_down_pressed_(false), | 
| 119     dragging_(false), | 108     dragging_(false), | 
| 120     starting_drag_(false), | 109     starting_drag_(false), | 
| 121     model_(download_item), | 110     model_(download_item), | 
| 122     save_button_(NULL), | 111     save_button_(NULL), | 
| 123     discard_button_(NULL), | 112     discard_button_(NULL), | 
| 124     dangerous_download_label_(NULL), | 113     dangerous_download_label_(NULL), | 
| 125     dangerous_download_label_sized_(false), | 114     dangerous_download_label_sized_(false), | 
| 126     disabled_while_opening_(false), | 115     disabled_while_opening_(false), | 
| 127     creation_time_(base::Time::Now()), | 116     creation_time_(base::Time::Now()), | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 237 | 226 | 
| 238   // ExperienceSampling: If the user took no action to remove the warning | 227   // ExperienceSampling: If the user took no action to remove the warning | 
| 239   // before it disappeared, then the user effectively dismissed the download | 228   // before it disappeared, then the user effectively dismissed the download | 
| 240   // without keeping it. | 229   // without keeping it. | 
| 241   if (sampling_event_.get()) | 230   if (sampling_event_.get()) | 
| 242     sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); | 231     sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); | 
| 243 } | 232 } | 
| 244 | 233 | 
| 245 // Progress animation handlers. | 234 // Progress animation handlers. | 
| 246 | 235 | 
| 247 void DownloadItemView::UpdateDownloadProgress() { |  | 
| 248   progress_angle_ = |  | 
| 249       (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) % |  | 
| 250       DownloadShelf::kMaxDegrees; |  | 
| 251   SchedulePaint(); |  | 
| 252 } |  | 
| 253 |  | 
| 254 void DownloadItemView::StartDownloadProgress() { | 236 void DownloadItemView::StartDownloadProgress() { | 
| 255   if (progress_timer_.IsRunning()) | 237   if (progress_timer_.IsRunning()) | 
| 256     return; | 238     return; | 
| 257   progress_timer_.Start(FROM_HERE, | 239   progress_start_time_ = base::TimeTicks::Now(); | 
| 258       base::TimeDelta::FromMilliseconds(DownloadShelf::kProgressRateMs), this, | 240   progress_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( | 
| 259       &DownloadItemView::UpdateDownloadProgress); | 241                                        DownloadShelf::kProgressRateMs), | 
|  | 242                         this, &DownloadItemView::SchedulePaint); | 
| 260 } | 243 } | 
| 261 | 244 | 
| 262 void DownloadItemView::StopDownloadProgress() { | 245 void DownloadItemView::StopDownloadProgress() { | 
| 263   progress_timer_.Stop(); | 246   progress_timer_.Stop(); | 
| 264 } | 247 } | 
| 265 | 248 | 
| 266 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { | 249 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { | 
| 267   if (icon_bitmap) | 250   if (icon_bitmap) | 
| 268     shelf_->SchedulePaint(); | 251     shelf_->SchedulePaint(); | 
| 269 } | 252 } | 
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 863     icon = image->ToImageSkia(); | 846     icon = image->ToImageSkia(); | 
| 864 | 847 | 
| 865   // We count on the fact that the icon manager will cache the icons and if one | 848   // We count on the fact that the icon manager will cache the icons and if one | 
| 866   // is available, it will be cached here. We *don't* want to request the icon | 849   // is available, it will be cached here. We *don't* want to request the icon | 
| 867   // to be loaded here, since this will also get called if the icon can't be | 850   // to be loaded here, since this will also get called if the icon can't be | 
| 868   // loaded, in which case LookupIcon will always be NULL. The loading will be | 851   // loaded, in which case LookupIcon will always be NULL. The loading will be | 
| 869   // triggered only when we think the status might change. | 852   // triggered only when we think the status might change. | 
| 870   if (icon) { | 853   if (icon) { | 
| 871     if (!IsShowingWarningDialog()) { | 854     if (!IsShowingWarningDialog()) { | 
| 872       DownloadItem::DownloadState state = download()->GetState(); | 855       DownloadItem::DownloadState state = download()->GetState(); | 
| 873       DownloadShelf::BoundsAdjusterCallback rtl_mirror = | 856       canvas->Save(); | 
| 874           base::Bind(&RTLMirrorXForView, base::Unretained(this)); | 857       if (base::i18n::IsRTL()) | 
|  | 858         canvas->Translate( | 
|  | 859             gfx::Vector2d(width() - DownloadShelf::kSmallProgressIconSize, 0)); | 
|  | 860 | 
| 875       if (state == DownloadItem::IN_PROGRESS) { | 861       if (state == DownloadItem::IN_PROGRESS) { | 
| 876         DownloadShelf::PaintDownloadProgress(canvas, rtl_mirror, 0, 0, | 862         DownloadShelf::PaintDownloadProgress(canvas, progress_start_time_, | 
| 877                                              progress_angle_, |  | 
| 878                                              model_.PercentComplete()); | 863                                              model_.PercentComplete()); | 
| 879       } else if (complete_animation_.get() && | 864       } else if (complete_animation_.get() && | 
| 880                  complete_animation_->is_animating()) { | 865                  complete_animation_->is_animating()) { | 
| 881         if (state == DownloadItem::INTERRUPTED) { | 866         if (state == DownloadItem::INTERRUPTED) { | 
| 882           DownloadShelf::PaintDownloadInterrupted( | 867           DownloadShelf::PaintDownloadInterrupted( | 
| 883               canvas, rtl_mirror, 0, 0, complete_animation_->GetCurrentValue()); | 868               canvas, complete_animation_->GetCurrentValue()); | 
| 884         } else { | 869         } else { | 
| 885           DCHECK_EQ(DownloadItem::COMPLETE, state); | 870           DCHECK_EQ(DownloadItem::COMPLETE, state); | 
| 886           DownloadShelf::PaintDownloadComplete( | 871           DownloadShelf::PaintDownloadComplete( | 
| 887               canvas, rtl_mirror, 0, 0, complete_animation_->GetCurrentValue()); | 872               canvas, complete_animation_->GetCurrentValue()); | 
| 888         } | 873         } | 
| 889       } | 874       } | 
|  | 875       canvas->Restore(); | 
| 890     } | 876     } | 
| 891 | 877 | 
| 892     // Draw the icon image. | 878     // Draw the icon image. | 
| 893     int icon_x, icon_y; | 879     int icon_x, icon_y; | 
| 894 | 880 | 
| 895     if (IsShowingWarningDialog()) { | 881     if (IsShowingWarningDialog()) { | 
| 896       icon_x = kLeftPadding + body_image_set->top_left->width(); | 882       icon_x = kLeftPadding + body_image_set->top_left->width(); | 
| 897       icon_y = (height() - icon->height()) / 2; | 883       icon_y = (height() - icon->height()) / 2; | 
| 898     } else { | 884     } else { | 
| 899       icon_x = DownloadShelf::kSmallProgressIconOffset; | 885       icon_x = DownloadShelf::kSmallProgressIconOffset; | 
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1382 void DownloadItemView::AnimateStateTransition(State from, State to, | 1368 void DownloadItemView::AnimateStateTransition(State from, State to, | 
| 1383                                               gfx::SlideAnimation* animation) { | 1369                                               gfx::SlideAnimation* animation) { | 
| 1384   if (from == NORMAL && to == HOT) { | 1370   if (from == NORMAL && to == HOT) { | 
| 1385     animation->Show(); | 1371     animation->Show(); | 
| 1386   } else if (from == HOT && to == NORMAL) { | 1372   } else if (from == HOT && to == NORMAL) { | 
| 1387     animation->Hide(); | 1373     animation->Hide(); | 
| 1388   } else if (from != to) { | 1374   } else if (from != to) { | 
| 1389     animation->Reset((to == HOT) ? 1.0 : 0.0); | 1375     animation->Reset((to == HOT) ? 1.0 : 0.0); | 
| 1390   } | 1376   } | 
| 1391 } | 1377 } | 
| OLD | NEW | 
|---|