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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 delete save_button_; | 1157 delete save_button_; |
1158 save_button_ = NULL; | 1158 save_button_ = NULL; |
1159 } | 1159 } |
1160 RemoveChildView(discard_button_); | 1160 RemoveChildView(discard_button_); |
1161 delete discard_button_; | 1161 delete discard_button_; |
1162 discard_button_ = NULL; | 1162 discard_button_ = NULL; |
1163 RemoveChildView(dangerous_download_label_); | 1163 RemoveChildView(dangerous_download_label_); |
1164 delete dangerous_download_label_; | 1164 delete dangerous_download_label_; |
1165 dangerous_download_label_ = NULL; | 1165 dangerous_download_label_ = NULL; |
1166 dangerous_download_label_sized_ = false; | 1166 dangerous_download_label_sized_ = false; |
1167 cached_button_size_.SetSize(0,0); | |
1168 | 1167 |
1169 // We need to load the icon now that the download has the real path. | 1168 // We need to load the icon now that the download has the real path. |
1170 LoadIcon(); | 1169 LoadIcon(); |
1171 } | 1170 } |
1172 | 1171 |
1173 void DownloadItemView::ShowWarningDialog() { | 1172 void DownloadItemView::ShowWarningDialog() { |
1174 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); | 1173 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); |
1175 time_download_warning_shown_ = base::Time::Now(); | 1174 time_download_warning_shown_ = base::Time::Now(); |
1176 content::DownloadDangerType danger_type = download()->GetDangerType(); | 1175 content::DownloadDangerType danger_type = download()->GetDangerType(); |
1177 RecordDangerousDownloadWarningShown(danger_type); | 1176 RecordDangerousDownloadWarningShown(danger_type); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 dangerous_download_label_ = new views::Label(dangerous_label); | 1233 dangerous_download_label_ = new views::Label(dangerous_label); |
1235 dangerous_download_label_->SetMultiLine(true); | 1234 dangerous_download_label_->SetMultiLine(true); |
1236 dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1235 dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
1237 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); | 1236 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); |
1238 AddChildView(dangerous_download_label_); | 1237 AddChildView(dangerous_download_label_); |
1239 SizeLabelToMinWidth(); | 1238 SizeLabelToMinWidth(); |
1240 } | 1239 } |
1241 | 1240 |
1242 gfx::Size DownloadItemView::GetButtonSize() const { | 1241 gfx::Size DownloadItemView::GetButtonSize() const { |
1243 DCHECK(discard_button_ && (mode_ == MALICIOUS_MODE || save_button_)); | 1242 DCHECK(discard_button_ && (mode_ == MALICIOUS_MODE || save_button_)); |
1244 gfx::Size size; | 1243 gfx::Size size = discard_button_->GetPreferredSize(); |
1245 | |
1246 // We cache the size when successfully retrieved, not for performance reasons | |
1247 // but because if this DownloadItemView is being animated while the tab is | |
1248 // not showing, the native buttons are not parented and their preferred size | |
1249 // is 0, messing-up the layout. | |
1250 if (cached_button_size_.width() != 0) | |
1251 return cached_button_size_; | |
1252 | |
1253 if (save_button_) | 1244 if (save_button_) |
1254 size = save_button_->GetMinimumSize(); | 1245 size.SetToMax(save_button_->GetPreferredSize()); |
1255 gfx::Size discard_size = discard_button_->GetMinimumSize(); | |
1256 | |
1257 size.SetSize(std::max(size.width(), discard_size.width()), | |
1258 std::max(size.height(), discard_size.height())); | |
1259 | |
1260 if (size.width() != 0) | |
1261 cached_button_size_ = size; | |
1262 | |
1263 return size; | 1246 return size; |
1264 } | 1247 } |
1265 | 1248 |
1266 // This method computes the minimum width of the label for displaying its text | 1249 // This method computes the minimum width of the label for displaying its text |
1267 // on 2 lines. It just breaks the string in 2 lines on the spaces and keeps the | 1250 // on 2 lines. It just breaks the string in 2 lines on the spaces and keeps the |
1268 // configuration with minimum width. | 1251 // configuration with minimum width. |
1269 void DownloadItemView::SizeLabelToMinWidth() { | 1252 void DownloadItemView::SizeLabelToMinWidth() { |
1270 if (dangerous_download_label_sized_) | 1253 if (dangerous_download_label_sized_) |
1271 return; | 1254 return; |
1272 | 1255 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1368 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1386 } | 1369 } |
1387 } | 1370 } |
1388 | 1371 |
1389 void DownloadItemView::ProgressTimerFired() { | 1372 void DownloadItemView::ProgressTimerFired() { |
1390 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only | 1373 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only |
1391 // when there's an update notified via OnDownloadUpdated(). | 1374 // when there's an update notified via OnDownloadUpdated(). |
1392 if (model_.PercentComplete() < 0) | 1375 if (model_.PercentComplete() < 0) |
1393 SchedulePaint(); | 1376 SchedulePaint(); |
1394 } | 1377 } |
OLD | NEW |