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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // ExperienceSampling: If the user took no action to remove the warning | 192 // ExperienceSampling: If the user took no action to remove the warning |
193 // before it disappeared, then the user effectively dismissed the download | 193 // before it disappeared, then the user effectively dismissed the download |
194 // without keeping it. | 194 // without keeping it. |
195 if (sampling_event_.get()) | 195 if (sampling_event_.get()) |
196 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); | 196 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); |
197 } | 197 } |
198 | 198 |
199 // Progress animation handlers. | 199 // Progress animation handlers. |
200 | 200 |
201 void DownloadItemViewMd::StartDownloadProgress() { | 201 void DownloadItemViewMd::StartDownloadProgress() { |
202 if (progress_timer_.IsRunning()) | 202 if (progress_start_time_ != base::TimeTicks()) |
203 return; | 203 return; |
204 progress_start_time_ = base::TimeTicks::Now(); | 204 progress_start_time_ = base::TimeTicks::Now(); |
205 progress_timer_.Start( | |
206 FROM_HERE, | |
207 base::TimeDelta::FromMilliseconds(DownloadShelf::kProgressRateMs), | |
208 base::Bind(&DownloadItemViewMd::SchedulePaint, base::Unretained(this))); | |
209 } | 205 } |
210 | 206 |
211 void DownloadItemViewMd::StopDownloadProgress() { | 207 void DownloadItemViewMd::StopDownloadProgress() { |
212 if (!progress_timer_.IsRunning()) | 208 if (progress_start_time_ == base::TimeTicks()) |
213 return; | 209 return; |
214 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; | 210 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; |
215 progress_start_time_ = base::TimeTicks(); | 211 progress_start_time_ = base::TimeTicks(); |
216 progress_timer_.Stop(); | |
217 } | 212 } |
218 | 213 |
219 // static | 214 // static |
220 SkColor DownloadItemViewMd::GetTextColorForThemeProvider( | 215 SkColor DownloadItemViewMd::GetTextColorForThemeProvider( |
221 const ui::ThemeProvider* theme) { | 216 const ui::ThemeProvider* theme) { |
222 return theme ? theme->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT) | 217 return theme ? theme->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT) |
223 : gfx::kPlaceholderColor; | 218 : gfx::kPlaceholderColor; |
224 } | 219 } |
225 | 220 |
226 void DownloadItemViewMd::OnExtractIconComplete(gfx::Image* icon_bitmap) { | 221 void DownloadItemViewMd::OnExtractIconComplete(gfx::Image* icon_bitmap) { |
(...skipping 20 matching lines...) Expand all Loading... |
247 ShowWarningDialog(); | 242 ShowWarningDialog(); |
248 // Force the shelf to layout again as our size has changed. | 243 // Force the shelf to layout again as our size has changed. |
249 shelf_->Layout(); | 244 shelf_->Layout(); |
250 SchedulePaint(); | 245 SchedulePaint(); |
251 } else { | 246 } else { |
252 base::string16 status_text = model_.GetStatusText(); | 247 base::string16 status_text = model_.GetStatusText(); |
253 switch (download()->GetState()) { | 248 switch (download()->GetState()) { |
254 case DownloadItem::IN_PROGRESS: | 249 case DownloadItem::IN_PROGRESS: |
255 download()->IsPaused() ? StopDownloadProgress() | 250 download()->IsPaused() ? StopDownloadProgress() |
256 : StartDownloadProgress(); | 251 : StartDownloadProgress(); |
| 252 SchedulePaint(); |
257 LoadIconIfItemPathChanged(); | 253 LoadIconIfItemPathChanged(); |
258 break; | 254 break; |
259 case DownloadItem::INTERRUPTED: | 255 case DownloadItem::INTERRUPTED: |
260 StopDownloadProgress(); | 256 StopDownloadProgress(); |
261 complete_animation_.reset(new gfx::SlideAnimation(this)); | 257 complete_animation_.reset(new gfx::SlideAnimation(this)); |
262 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); | 258 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); |
263 complete_animation_->SetTweenType(gfx::Tween::LINEAR); | 259 complete_animation_->SetTweenType(gfx::Tween::LINEAR); |
264 complete_animation_->Show(); | 260 complete_animation_->Show(); |
265 SchedulePaint(); | 261 SchedulePaint(); |
266 LoadIcon(); | 262 LoadIcon(); |
(...skipping 23 matching lines...) Expand all Loading... |
290 status_text_ = status_text; | 286 status_text_ = status_text; |
291 } | 287 } |
292 | 288 |
293 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth); | 289 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth); |
294 if (new_tip != tooltip_text_) { | 290 if (new_tip != tooltip_text_) { |
295 tooltip_text_ = new_tip; | 291 tooltip_text_ = new_tip; |
296 TooltipTextChanged(); | 292 TooltipTextChanged(); |
297 } | 293 } |
298 | 294 |
299 UpdateAccessibleName(); | 295 UpdateAccessibleName(); |
300 | |
301 // We use the parent's (DownloadShelfView's) SchedulePaint, since there | |
302 // are spaces between each DownloadItemViewMd that the parent is responsible | |
303 // for painting. | |
304 shelf_->SchedulePaint(); | |
305 } | 296 } |
306 | 297 |
307 void DownloadItemViewMd::OnDownloadDestroyed(DownloadItem* download) { | 298 void DownloadItemViewMd::OnDownloadDestroyed(DownloadItem* download) { |
308 shelf_->RemoveDownloadView(this); // This will delete us! | 299 shelf_->RemoveDownloadView(this); // This will delete us! |
309 } | 300 } |
310 | 301 |
311 void DownloadItemViewMd::OnDownloadOpened(DownloadItem* download) { | 302 void DownloadItemViewMd::OnDownloadOpened(DownloadItem* download) { |
312 disabled_while_opening_ = true; | 303 disabled_while_opening_ = true; |
313 SetEnabled(false); | 304 SetEnabled(false); |
314 base::MessageLoop::current()->task_runner()->PostDelayedTask( | 305 base::MessageLoop::current()->task_runner()->PostDelayedTask( |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 } | 1063 } |
1073 } | 1064 } |
1074 | 1065 |
1075 SkColor DownloadItemViewMd::GetTextColor() { | 1066 SkColor DownloadItemViewMd::GetTextColor() { |
1076 return GetTextColorForThemeProvider(GetThemeProvider()); | 1067 return GetTextColorForThemeProvider(GetThemeProvider()); |
1077 } | 1068 } |
1078 | 1069 |
1079 SkColor DownloadItemViewMd::GetDimmedTextColor() { | 1070 SkColor DownloadItemViewMd::GetDimmedTextColor() { |
1080 return SkColorSetA(GetTextColor(), 0xC7); | 1071 return SkColorSetA(GetTextColor(), 0xC7); |
1081 } | 1072 } |
OLD | NEW |