OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/download_item_view.h" | 5 #include "chrome/browser/views/download_item_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 drop_down_pressed_(false), | 120 drop_down_pressed_(false), |
121 dragging_(false), | 121 dragging_(false), |
122 starting_drag_(false), | 122 starting_drag_(false), |
123 model_(model), | 123 model_(model), |
124 save_button_(NULL), | 124 save_button_(NULL), |
125 discard_button_(NULL), | 125 discard_button_(NULL), |
126 dangerous_download_label_(NULL), | 126 dangerous_download_label_(NULL), |
127 dangerous_download_label_sized_(false), | 127 dangerous_download_label_sized_(false), |
128 disabled_while_opening_(false), | 128 disabled_while_opening_(false), |
129 creation_time_(base::Time::Now()), | 129 creation_time_(base::Time::Now()), |
130 ALLOW_THIS_IN_INITIALIZER_LIST(reenable_method_factory_(this)) { | 130 ALLOW_THIS_IN_INITIALIZER_LIST(reenable_method_factory_(this)), |
| 131 deleted_(NULL) { |
131 DCHECK(download_); | 132 DCHECK(download_); |
132 download_->AddObserver(this); | 133 download_->AddObserver(this); |
133 | 134 |
134 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 135 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
135 | 136 |
136 BodyImageSet normal_body_image_set = { | 137 BodyImageSet normal_body_image_set = { |
137 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), | 138 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), |
138 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), | 139 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), |
139 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), | 140 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), |
140 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), | 141 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 StartDownloadProgress(); | 300 StartDownloadProgress(); |
300 } | 301 } |
301 | 302 |
302 DownloadItemView::~DownloadItemView() { | 303 DownloadItemView::~DownloadItemView() { |
303 if (context_menu_.get()) { | 304 if (context_menu_.get()) { |
304 context_menu_->Stop(); | 305 context_menu_->Stop(); |
305 } | 306 } |
306 icon_consumer_.CancelAllRequests(); | 307 icon_consumer_.CancelAllRequests(); |
307 StopDownloadProgress(); | 308 StopDownloadProgress(); |
308 download_->RemoveObserver(this); | 309 download_->RemoveObserver(this); |
| 310 if (deleted_) |
| 311 *deleted_ = true; |
309 } | 312 } |
310 | 313 |
311 // Progress animation handlers. | 314 // Progress animation handlers. |
312 | 315 |
313 void DownloadItemView::UpdateDownloadProgress() { | 316 void DownloadItemView::UpdateDownloadProgress() { |
314 progress_angle_ = (progress_angle_ + | 317 progress_angle_ = (progress_angle_ + |
315 download_util::kUnknownIncrementDegrees) % | 318 download_util::kUnknownIncrementDegrees) % |
316 download_util::kMaxDegrees; | 319 download_util::kMaxDegrees; |
317 SchedulePaint(); | 320 SchedulePaint(); |
318 } | 321 } |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 point.set_y(height()); | 810 point.set_y(height()); |
808 if (base::i18n::IsRTL()) | 811 if (base::i18n::IsRTL()) |
809 point.set_x(drop_down_x_right_); | 812 point.set_x(drop_down_x_right_); |
810 else | 813 else |
811 point.set_x(drop_down_x_left_); | 814 point.set_x(drop_down_x_left_); |
812 | 815 |
813 views::View::ConvertPointToScreen(this, &point); | 816 views::View::ConvertPointToScreen(this, &point); |
814 | 817 |
815 if (!context_menu_.get()) | 818 if (!context_menu_.get()) |
816 context_menu_.reset(new DownloadShelfContextMenuWin(model_.get())); | 819 context_menu_.reset(new DownloadShelfContextMenuWin(model_.get())); |
| 820 // When we call the Run method on the menu, it runs an inner message loop |
| 821 // that might causes us to be deleted. |
| 822 bool deleted = false; |
| 823 deleted_ = &deleted; |
817 context_menu_->Run(point); | 824 context_menu_->Run(point); |
| 825 if (deleted) |
| 826 return true; // We have been deleted! Don't access 'this'. |
| 827 deleted_ = NULL; |
818 | 828 |
819 // If the menu action was to remove the download, this view will also be | 829 // If the menu action was to remove the download, this view will also be |
820 // invalid so we must not access 'this' in this case. | 830 // invalid so we must not access 'this' in this case. |
821 if (context_menu_->download()) { | 831 if (context_menu_->download()) { |
822 drop_down_pressed_ = false; | 832 drop_down_pressed_ = false; |
823 // Showing the menu blocks. Here we revert the state. | 833 // Showing the menu blocks. Here we revert the state. |
824 SetState(NORMAL, NORMAL); | 834 SetState(NORMAL, NORMAL); |
825 } | 835 } |
826 } | 836 } |
827 return true; | 837 return true; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 void DownloadItemView::Reenable() { | 1008 void DownloadItemView::Reenable() { |
999 disabled_while_opening_ = false; | 1009 disabled_while_opening_ = false; |
1000 SetEnabled(true); // Triggers a repaint. | 1010 SetEnabled(true); // Triggers a repaint. |
1001 } | 1011 } |
1002 | 1012 |
1003 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { | 1013 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { |
1004 if (x > drop_down_x_left_ && x < drop_down_x_right_) | 1014 if (x > drop_down_x_left_ && x < drop_down_x_right_) |
1005 return true; | 1015 return true; |
1006 return false; | 1016 return false; |
1007 } | 1017 } |
OLD | NEW |