| 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_md.h" | 5 #include "chrome/browser/ui/views/download/download_item_view_md.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 if (sampling_event_.get()) | 198 if (sampling_event_.get()) |
| 199 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); | 199 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Progress animation handlers. | 202 // Progress animation handlers. |
| 203 | 203 |
| 204 void DownloadItemViewMd::StartDownloadProgress() { | 204 void DownloadItemViewMd::StartDownloadProgress() { |
| 205 if (progress_timer_.IsRunning()) | 205 if (progress_timer_.IsRunning()) |
| 206 return; | 206 return; |
| 207 progress_start_time_ = base::TimeTicks::Now(); | 207 progress_start_time_ = base::TimeTicks::Now(); |
| 208 progress_timer_.Start( | 208 progress_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( |
| 209 FROM_HERE, | 209 DownloadShelf::kProgressRateMs), |
| 210 base::TimeDelta::FromMilliseconds(DownloadShelf::kProgressRateMs), | 210 base::Bind(&DownloadItemViewMd::ProgressTimerFired, |
| 211 base::Bind(&DownloadItemViewMd::SchedulePaint, base::Unretained(this))); | 211 base::Unretained(this))); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void DownloadItemViewMd::StopDownloadProgress() { | 214 void DownloadItemViewMd::StopDownloadProgress() { |
| 215 if (!progress_timer_.IsRunning()) | 215 if (!progress_timer_.IsRunning()) |
| 216 return; | 216 return; |
| 217 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; | 217 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; |
| 218 progress_start_time_ = base::TimeTicks(); | 218 progress_start_time_ = base::TimeTicks(); |
| 219 progress_timer_.Stop(); | 219 progress_timer_.Stop(); |
| 220 } | 220 } |
| 221 | 221 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 250 ShowWarningDialog(); | 250 ShowWarningDialog(); |
| 251 // Force the shelf to layout again as our size has changed. | 251 // Force the shelf to layout again as our size has changed. |
| 252 shelf_->Layout(); | 252 shelf_->Layout(); |
| 253 SchedulePaint(); | 253 SchedulePaint(); |
| 254 } else { | 254 } else { |
| 255 base::string16 status_text = model_.GetStatusText(); | 255 base::string16 status_text = model_.GetStatusText(); |
| 256 switch (download()->GetState()) { | 256 switch (download()->GetState()) { |
| 257 case DownloadItem::IN_PROGRESS: | 257 case DownloadItem::IN_PROGRESS: |
| 258 download()->IsPaused() ? StopDownloadProgress() | 258 download()->IsPaused() ? StopDownloadProgress() |
| 259 : StartDownloadProgress(); | 259 : StartDownloadProgress(); |
| 260 SchedulePaint(); |
| 260 LoadIconIfItemPathChanged(); | 261 LoadIconIfItemPathChanged(); |
| 261 break; | 262 break; |
| 262 case DownloadItem::INTERRUPTED: | 263 case DownloadItem::INTERRUPTED: |
| 263 StopDownloadProgress(); | 264 StopDownloadProgress(); |
| 264 complete_animation_.reset(new gfx::SlideAnimation(this)); | 265 complete_animation_.reset(new gfx::SlideAnimation(this)); |
| 265 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); | 266 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); |
| 266 complete_animation_->SetTweenType(gfx::Tween::LINEAR); | 267 complete_animation_->SetTweenType(gfx::Tween::LINEAR); |
| 267 complete_animation_->Show(); | 268 complete_animation_->Show(); |
| 268 SchedulePaint(); | 269 SchedulePaint(); |
| 269 LoadIcon(); | 270 LoadIcon(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 293 status_text_ = status_text; | 294 status_text_ = status_text; |
| 294 } | 295 } |
| 295 | 296 |
| 296 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth); | 297 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth); |
| 297 if (new_tip != tooltip_text_) { | 298 if (new_tip != tooltip_text_) { |
| 298 tooltip_text_ = new_tip; | 299 tooltip_text_ = new_tip; |
| 299 TooltipTextChanged(); | 300 TooltipTextChanged(); |
| 300 } | 301 } |
| 301 | 302 |
| 302 UpdateAccessibleName(); | 303 UpdateAccessibleName(); |
| 303 | |
| 304 // We use the parent's (DownloadShelfView's) SchedulePaint, since there | |
| 305 // are spaces between each DownloadItemViewMd that the parent is responsible | |
| 306 // for painting. | |
| 307 shelf_->SchedulePaint(); | |
| 308 } | 304 } |
| 309 | 305 |
| 310 void DownloadItemViewMd::OnDownloadDestroyed(DownloadItem* download) { | 306 void DownloadItemViewMd::OnDownloadDestroyed(DownloadItem* download) { |
| 311 shelf_->RemoveDownloadView(this); // This will delete us! | 307 shelf_->RemoveDownloadView(this); // This will delete us! |
| 312 } | 308 } |
| 313 | 309 |
| 314 void DownloadItemViewMd::OnDownloadOpened(DownloadItem* download) { | 310 void DownloadItemViewMd::OnDownloadOpened(DownloadItem* download) { |
| 315 disabled_while_opening_ = true; | 311 disabled_while_opening_ = true; |
| 316 SetEnabled(false); | 312 SetEnabled(false); |
| 317 base::MessageLoop::current()->task_runner()->PostDelayedTask( | 313 base::MessageLoop::current()->task_runner()->PostDelayedTask( |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 gfx::SlideAnimation* animation) { | 1064 gfx::SlideAnimation* animation) { |
| 1069 if (from == NORMAL && to == HOT) { | 1065 if (from == NORMAL && to == HOT) { |
| 1070 animation->Show(); | 1066 animation->Show(); |
| 1071 } else if (from == HOT && to == NORMAL) { | 1067 } else if (from == HOT && to == NORMAL) { |
| 1072 animation->Hide(); | 1068 animation->Hide(); |
| 1073 } else if (from != to) { | 1069 } else if (from != to) { |
| 1074 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1070 animation->Reset((to == HOT) ? 1.0 : 0.0); |
| 1075 } | 1071 } |
| 1076 } | 1072 } |
| 1077 | 1073 |
| 1074 void DownloadItemViewMd::ProgressTimerFired() { |
| 1075 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only |
| 1076 // when there's an update notified via OnDownloadUpdated(). |
| 1077 if (model_.PercentComplete() < 0) |
| 1078 SchedulePaint(); |
| 1079 } |
| 1080 |
| 1078 SkColor DownloadItemViewMd::GetTextColor() { | 1081 SkColor DownloadItemViewMd::GetTextColor() { |
| 1079 return GetTextColorForThemeProvider(GetThemeProvider()); | 1082 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1080 } | 1083 } |
| 1081 | 1084 |
| 1082 SkColor DownloadItemViewMd::GetDimmedTextColor() { | 1085 SkColor DownloadItemViewMd::GetDimmedTextColor() { |
| 1083 return SkColorSetA(GetTextColor(), 0xC7); | 1086 return SkColorSetA(GetTextColor(), 0xC7); |
| 1084 } | 1087 } |
| OLD | NEW |