| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } else { | 203 } else { |
| 204 // Drop down button is glued to the right of the download shelf. | 204 // Drop down button is glued to the right of the download shelf. |
| 205 drop_down_x_left_ = | 205 drop_down_x_left_ = |
| 206 size.width() - normal_drop_down_image_set_.top->width(); | 206 size.width() - normal_drop_down_image_set_.top->width(); |
| 207 drop_down_x_right_ = size.width(); | 207 drop_down_x_right_ = size.width(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 body_hover_animation_.reset(new ui::SlideAnimation(this)); | 210 body_hover_animation_.reset(new ui::SlideAnimation(this)); |
| 211 drop_hover_animation_.reset(new ui::SlideAnimation(this)); | 211 drop_hover_animation_.reset(new ui::SlideAnimation(this)); |
| 212 | 212 |
| 213 if (download->safety_state() == DownloadItem::DANGEROUS) { | 213 if (download->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 214 tooltip_text_.clear(); | 214 tooltip_text_.clear(); |
| 215 body_state_ = DANGEROUS; | 215 body_state_ = DANGEROUS; |
| 216 drop_down_state_ = DANGEROUS; | 216 drop_down_state_ = DANGEROUS; |
| 217 save_button_ = new views::NativeTextButton(this, | 217 save_button_ = new views::NativeTextButton(this, |
| 218 l10n_util::GetStringUTF16( | 218 l10n_util::GetStringUTF16( |
| 219 ChromeDownloadManagerDelegate::IsExtensionDownload(download) ? | 219 ChromeDownloadManagerDelegate::IsExtensionDownload(download) ? |
| 220 IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD)); | 220 IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD)); |
| 221 save_button_->set_ignore_minimum_size(true); | 221 save_button_->set_ignore_minimum_size(true); |
| 222 discard_button_ = new views::NativeTextButton( | 222 discard_button_ = new views::NativeTextButton( |
| 223 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); | 223 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); |
| 224 discard_button_->set_ignore_minimum_size(true); | 224 discard_button_->set_ignore_minimum_size(true); |
| 225 AddChildView(save_button_); | 225 AddChildView(save_button_); |
| 226 AddChildView(discard_button_); | 226 AddChildView(discard_button_); |
| 227 | 227 |
| 228 // Ensure the file name is not too long. | 228 // Ensure the file name is not too long. |
| 229 | 229 |
| 230 // Extract the file extension (if any). | 230 // Extract the file extension (if any). |
| 231 FilePath filename(download->target_name()); | 231 FilePath filename(download->GetTargetName()); |
| 232 #if defined(OS_POSIX) | 232 #if defined(OS_POSIX) |
| 233 string16 extension = WideToUTF16(base::SysNativeMBToWide( | 233 string16 extension = WideToUTF16(base::SysNativeMBToWide( |
| 234 filename.Extension())); | 234 filename.Extension())); |
| 235 #else | 235 #else |
| 236 string16 extension = filename.Extension(); | 236 string16 extension = filename.Extension(); |
| 237 #endif | 237 #endif |
| 238 | 238 |
| 239 // Remove leading '.' | 239 // Remove leading '.' |
| 240 if (extension.length() > 0) | 240 if (extension.length() > 0) |
| 241 extension = extension.substr(1); | 241 extension = extension.substr(1); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 329 } |
| 330 | 330 |
| 331 // DownloadObserver interface. | 331 // DownloadObserver interface. |
| 332 | 332 |
| 333 // Update the progress graphic on the icon and our text status label | 333 // Update the progress graphic on the icon and our text status label |
| 334 // to reflect our current bytes downloaded, time remaining. | 334 // to reflect our current bytes downloaded, time remaining. |
| 335 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { | 335 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { |
| 336 DCHECK(download == download_); | 336 DCHECK(download == download_); |
| 337 | 337 |
| 338 if (body_state_ == DANGEROUS && | 338 if (body_state_ == DANGEROUS && |
| 339 download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { | 339 download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) { |
| 340 // We have been approved. | 340 // We have been approved. |
| 341 ClearDangerousMode(); | 341 ClearDangerousMode(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 string16 status_text = model_->GetStatusText(); | 344 string16 status_text = model_->GetStatusText(); |
| 345 switch (download_->state()) { | 345 switch (download_->GetState()) { |
| 346 case DownloadItem::IN_PROGRESS: | 346 case DownloadItem::IN_PROGRESS: |
| 347 download_->is_paused() ? StopDownloadProgress() : StartDownloadProgress(); | 347 download_->IsPaused() ? StopDownloadProgress() : StartDownloadProgress(); |
| 348 LoadIconIfItemPathChanged(); | 348 LoadIconIfItemPathChanged(); |
| 349 break; | 349 break; |
| 350 case DownloadItem::INTERRUPTED: | 350 case DownloadItem::INTERRUPTED: |
| 351 StopDownloadProgress(); | 351 StopDownloadProgress(); |
| 352 complete_animation_.reset(new ui::SlideAnimation(this)); | 352 complete_animation_.reset(new ui::SlideAnimation(this)); |
| 353 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); | 353 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); |
| 354 complete_animation_->SetTweenType(ui::Tween::LINEAR); | 354 complete_animation_->SetTweenType(ui::Tween::LINEAR); |
| 355 complete_animation_->Show(); | 355 complete_animation_->Show(); |
| 356 SchedulePaint(); | 356 SchedulePaint(); |
| 357 LoadIcon(); | 357 LoadIcon(); |
| 358 break; | 358 break; |
| 359 case DownloadItem::COMPLETE: | 359 case DownloadItem::COMPLETE: |
| 360 if (download_->auto_opened()) { | 360 if (download_->GetAutoOpened()) { |
| 361 parent_->RemoveDownloadView(this); // This will delete us! | 361 parent_->RemoveDownloadView(this); // This will delete us! |
| 362 return; | 362 return; |
| 363 } | 363 } |
| 364 StopDownloadProgress(); | 364 StopDownloadProgress(); |
| 365 complete_animation_.reset(new ui::SlideAnimation(this)); | 365 complete_animation_.reset(new ui::SlideAnimation(this)); |
| 366 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); | 366 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); |
| 367 complete_animation_->SetTweenType(ui::Tween::LINEAR); | 367 complete_animation_->SetTweenType(ui::Tween::LINEAR); |
| 368 complete_animation_->Show(); | 368 complete_animation_->Show(); |
| 369 SchedulePaint(); | 369 SchedulePaint(); |
| 370 LoadIcon(); | 370 LoadIcon(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 if (context_menu_->download_item()) { | 626 if (context_menu_->download_item()) { |
| 627 drop_down_pressed_ = false; | 627 drop_down_pressed_ = false; |
| 628 // Showing the menu blocks. Here we revert the state. | 628 // Showing the menu blocks. Here we revert the state. |
| 629 SetState(NORMAL, NORMAL); | 629 SetState(NORMAL, NORMAL); |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 | 632 |
| 633 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 633 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 634 state->name = accessible_name_; | 634 state->name = accessible_name_; |
| 635 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 635 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 636 if (download_->safety_state() == DownloadItem::DANGEROUS) { | 636 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 637 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; | 637 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; |
| 638 } else { | 638 } else { |
| 639 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; | 639 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; |
| 640 } | 640 } |
| 641 } | 641 } |
| 642 | 642 |
| 643 void DownloadItemView::ButtonPressed( | 643 void DownloadItemView::ButtonPressed( |
| 644 views::Button* sender, const views::Event& event) { | 644 views::Button* sender, const views::Event& event) { |
| 645 if (sender == discard_button_) { | 645 if (sender == discard_button_) { |
| 646 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 646 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 void DownloadItemView::SetState(State body_state, State drop_down_state) { | 959 void DownloadItemView::SetState(State body_state, State drop_down_state) { |
| 960 if (body_state_ == body_state && drop_down_state_ == drop_down_state) | 960 if (body_state_ == body_state && drop_down_state_ == drop_down_state) |
| 961 return; | 961 return; |
| 962 | 962 |
| 963 body_state_ = body_state; | 963 body_state_ = body_state; |
| 964 drop_down_state_ = drop_down_state; | 964 drop_down_state_ = drop_down_state; |
| 965 SchedulePaint(); | 965 SchedulePaint(); |
| 966 } | 966 } |
| 967 | 967 |
| 968 void DownloadItemView::ClearDangerousMode() { | 968 void DownloadItemView::ClearDangerousMode() { |
| 969 DCHECK(download_->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED && | 969 DCHECK(download_->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED && |
| 970 body_state_ == DANGEROUS && drop_down_state_ == DANGEROUS); | 970 body_state_ == DANGEROUS && drop_down_state_ == DANGEROUS); |
| 971 | 971 |
| 972 body_state_ = NORMAL; | 972 body_state_ = NORMAL; |
| 973 drop_down_state_ = NORMAL; | 973 drop_down_state_ = NORMAL; |
| 974 | 974 |
| 975 // Remove the views used by the dangerous mode. | 975 // Remove the views used by the dangerous mode. |
| 976 RemoveChildView(save_button_); | 976 RemoveChildView(save_button_); |
| 977 delete save_button_; | 977 delete save_button_; |
| 978 save_button_ = NULL; | 978 save_button_ = NULL; |
| 979 RemoveChildView(discard_button_); | 979 RemoveChildView(discard_button_); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 } | 1091 } |
| 1092 | 1092 |
| 1093 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { | 1093 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { |
| 1094 if (x > drop_down_x_left_ && x < drop_down_x_right_) | 1094 if (x > drop_down_x_left_ && x < drop_down_x_right_) |
| 1095 return true; | 1095 return true; |
| 1096 return false; | 1096 return false; |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 void DownloadItemView::UpdateAccessibleName() { | 1099 void DownloadItemView::UpdateAccessibleName() { |
| 1100 string16 new_name; | 1100 string16 new_name; |
| 1101 if (download_->safety_state() == DownloadItem::DANGEROUS) { | 1101 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 1102 new_name = dangerous_download_label_->GetText(); | 1102 new_name = dangerous_download_label_->GetText(); |
| 1103 } else { | 1103 } else { |
| 1104 new_name = status_text_ + char16(' ') + | 1104 new_name = status_text_ + char16(' ') + |
| 1105 download_->GetFileNameToReportUser().LossyDisplayName(); | 1105 download_->GetFileNameToReportUser().LossyDisplayName(); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 // If the name has changed, notify assistive technology that the name | 1108 // If the name has changed, notify assistive technology that the name |
| 1109 // has changed so they can announce it immediately. | 1109 // has changed so they can announce it immediately. |
| 1110 if (new_name != accessible_name_) { | 1110 if (new_name != accessible_name_) { |
| 1111 accessible_name_ = new_name; | 1111 accessible_name_ = new_name; |
| 1112 if (GetWidget()) { | 1112 if (GetWidget()) { |
| 1113 GetWidget()->NotifyAccessibilityEvent( | 1113 GetWidget()->NotifyAccessibilityEvent( |
| 1114 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); | 1114 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); |
| 1115 } | 1115 } |
| 1116 } | 1116 } |
| 1117 } | 1117 } |
| OLD | NEW |