| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/location.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/sys_string_conversions.h" | 20 #include "base/strings/sys_string_conversions.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 23 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 23 #include "chrome/browser/download/download_item_model.h" | 24 #include "chrome/browser/download/download_item_model.h" |
| 24 #include "chrome/browser/download/download_stats.h" | 25 #include "chrome/browser/download/download_stats.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 shelf_->SchedulePaint(); | 344 shelf_->SchedulePaint(); |
| 344 } | 345 } |
| 345 | 346 |
| 346 void DownloadItemView::OnDownloadDestroyed(DownloadItem* download) { | 347 void DownloadItemView::OnDownloadDestroyed(DownloadItem* download) { |
| 347 shelf_->RemoveDownloadView(this); // This will delete us! | 348 shelf_->RemoveDownloadView(this); // This will delete us! |
| 348 } | 349 } |
| 349 | 350 |
| 350 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { | 351 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { |
| 351 disabled_while_opening_ = true; | 352 disabled_while_opening_ = true; |
| 352 SetEnabled(false); | 353 SetEnabled(false); |
| 353 base::MessageLoop::current()->PostDelayedTask( | 354 base::MessageLoop::current()->task_runner()->PostDelayedTask( |
| 354 FROM_HERE, | 355 FROM_HERE, |
| 355 base::Bind(&DownloadItemView::Reenable, weak_ptr_factory_.GetWeakPtr()), | 356 base::Bind(&DownloadItemView::Reenable, weak_ptr_factory_.GetWeakPtr()), |
| 356 base::TimeDelta::FromMilliseconds(kDisabledOnOpenDuration)); | 357 base::TimeDelta::FromMilliseconds(kDisabledOnOpenDuration)); |
| 357 | 358 |
| 358 // Notify our parent. | 359 // Notify our parent. |
| 359 shelf_->OpenedDownload(this); | 360 shelf_->OpenedDownload(this); |
| 360 } | 361 } |
| 361 | 362 |
| 362 // View overrides | 363 // View overrides |
| 363 | 364 |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 if (source_type != ui::MENU_SOURCE_MOUSE && | 1008 if (source_type != ui::MENU_SOURCE_MOUSE && |
| 1008 source_type != ui::MENU_SOURCE_TOUCH) { | 1009 source_type != ui::MENU_SOURCE_TOUCH) { |
| 1009 drop_down_pressed_ = true; | 1010 drop_down_pressed_ = true; |
| 1010 SetState(NORMAL, PUSHED); | 1011 SetState(NORMAL, PUSHED); |
| 1011 point.SetPoint(drop_down_x_left_, box_y_); | 1012 point.SetPoint(drop_down_x_left_, box_y_); |
| 1012 size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_); | 1013 size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_); |
| 1013 } | 1014 } |
| 1014 // Post a task to release the button. When we call the Run method on the menu | 1015 // Post a task to release the button. When we call the Run method on the menu |
| 1015 // below, it runs an inner message loop that might cause us to be deleted. | 1016 // below, it runs an inner message loop that might cause us to be deleted. |
| 1016 // Posting a task with a WeakPtr lets us safely handle the button release. | 1017 // Posting a task with a WeakPtr lets us safely handle the button release. |
| 1017 base::MessageLoop::current()->PostNonNestableTask( | 1018 base::MessageLoop::current()->task_runner()->PostNonNestableTask( |
| 1018 FROM_HERE, | 1019 FROM_HERE, base::Bind(&DownloadItemView::ReleaseDropDown, |
| 1019 base::Bind(&DownloadItemView::ReleaseDropDown, | 1020 weak_ptr_factory_.GetWeakPtr())); |
| 1020 weak_ptr_factory_.GetWeakPtr())); | |
| 1021 views::View::ConvertPointToScreen(this, &point); | 1021 views::View::ConvertPointToScreen(this, &point); |
| 1022 | 1022 |
| 1023 if (!context_menu_.get()) | 1023 if (!context_menu_.get()) |
| 1024 context_menu_.reset(new DownloadShelfContextMenuView(download())); | 1024 context_menu_.reset(new DownloadShelfContextMenuView(download())); |
| 1025 | 1025 |
| 1026 context_menu_->Run(GetWidget()->GetTopLevelWidget(), | 1026 context_menu_->Run(GetWidget()->GetTopLevelWidget(), |
| 1027 gfx::Rect(point, size), source_type); | 1027 gfx::Rect(point, size), source_type); |
| 1028 // We could be deleted now. | 1028 // We could be deleted now. |
| 1029 } | 1029 } |
| 1030 | 1030 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 void DownloadItemView::AnimateStateTransition(State from, State to, | 1382 void DownloadItemView::AnimateStateTransition(State from, State to, |
| 1383 gfx::SlideAnimation* animation) { | 1383 gfx::SlideAnimation* animation) { |
| 1384 if (from == NORMAL && to == HOT) { | 1384 if (from == NORMAL && to == HOT) { |
| 1385 animation->Show(); | 1385 animation->Show(); |
| 1386 } else if (from == HOT && to == NORMAL) { | 1386 } else if (from == HOT && to == NORMAL) { |
| 1387 animation->Hide(); | 1387 animation->Hide(); |
| 1388 } else if (from != to) { | 1388 } else if (from != to) { |
| 1389 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1389 animation->Reset((to == HOT) ? 1.0 : 0.0); |
| 1390 } | 1390 } |
| 1391 } | 1391 } |
| OLD | NEW |