| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } else { | 204 } else { |
| 205 // Drop down button is glued to the right of the download shelf. | 205 // Drop down button is glued to the right of the download shelf. |
| 206 drop_down_x_left_ = | 206 drop_down_x_left_ = |
| 207 size.width() - normal_drop_down_image_set_.top->width(); | 207 size.width() - normal_drop_down_image_set_.top->width(); |
| 208 drop_down_x_right_ = size.width(); | 208 drop_down_x_right_ = size.width(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 body_hover_animation_.reset(new ui::SlideAnimation(this)); | 211 body_hover_animation_.reset(new ui::SlideAnimation(this)); |
| 212 drop_hover_animation_.reset(new ui::SlideAnimation(this)); | 212 drop_hover_animation_.reset(new ui::SlideAnimation(this)); |
| 213 | 213 |
| 214 if (download->safety_state() == DownloadItem::DANGEROUS) | 214 if (download->GetSafetyState() == DownloadItem::DANGEROUS) |
| 215 EnterDangerousMode(); | 215 EnterDangerousMode(); |
| 216 | 216 |
| 217 UpdateAccessibleName(); | 217 UpdateAccessibleName(); |
| 218 set_accessibility_focusable(true); | 218 set_accessibility_focusable(true); |
| 219 | 219 |
| 220 // Set up our animation. | 220 // Set up our animation. |
| 221 StartDownloadProgress(); | 221 StartDownloadProgress(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 DownloadItemView::~DownloadItemView() { | 224 DownloadItemView::~DownloadItemView() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 257 } |
| 258 | 258 |
| 259 // DownloadObserver interface. | 259 // DownloadObserver interface. |
| 260 | 260 |
| 261 // Update the progress graphic on the icon and our text status label | 261 // Update the progress graphic on the icon and our text status label |
| 262 // to reflect our current bytes downloaded, time remaining. | 262 // to reflect our current bytes downloaded, time remaining. |
| 263 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { | 263 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { |
| 264 DCHECK(download == download_); | 264 DCHECK(download == download_); |
| 265 | 265 |
| 266 if (body_state_ == DANGEROUS && | 266 if (body_state_ == DANGEROUS && |
| 267 download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { | 267 download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) { |
| 268 // We have been approved. | 268 // We have been approved. |
| 269 ClearDangerousMode(); | 269 ClearDangerousMode(); |
| 270 } else if (body_state_ != DANGEROUS && | 270 } else if (body_state_ != DANGEROUS && |
| 271 download->safety_state() == DownloadItem::DANGEROUS) { | 271 download->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 272 EnterDangerousMode(); | 272 EnterDangerousMode(); |
| 273 // Force the shelf to layout again as our size has changed. | 273 // Force the shelf to layout again as our size has changed. |
| 274 parent_->Layout(); | 274 parent_->Layout(); |
| 275 SchedulePaint(); | 275 SchedulePaint(); |
| 276 } else { | 276 } else { |
| 277 string16 status_text = model_->GetStatusText(); | 277 string16 status_text = model_->GetStatusText(); |
| 278 switch (download_->state()) { | 278 switch (download_->GetState()) { |
| 279 case DownloadItem::IN_PROGRESS: | 279 case DownloadItem::IN_PROGRESS: |
| 280 download_->is_paused() ? | 280 download_->IsPaused() ? |
| 281 StopDownloadProgress() : StartDownloadProgress(); | 281 StopDownloadProgress() : StartDownloadProgress(); |
| 282 LoadIconIfItemPathChanged(); | 282 LoadIconIfItemPathChanged(); |
| 283 break; | 283 break; |
| 284 case DownloadItem::INTERRUPTED: | 284 case DownloadItem::INTERRUPTED: |
| 285 StopDownloadProgress(); | 285 StopDownloadProgress(); |
| 286 complete_animation_.reset(new ui::SlideAnimation(this)); | 286 complete_animation_.reset(new ui::SlideAnimation(this)); |
| 287 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); | 287 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); |
| 288 complete_animation_->SetTweenType(ui::Tween::LINEAR); | 288 complete_animation_->SetTweenType(ui::Tween::LINEAR); |
| 289 complete_animation_->Show(); | 289 complete_animation_->Show(); |
| 290 SchedulePaint(); | 290 SchedulePaint(); |
| 291 LoadIcon(); | 291 LoadIcon(); |
| 292 break; | 292 break; |
| 293 case DownloadItem::COMPLETE: | 293 case DownloadItem::COMPLETE: |
| 294 if (download_->auto_opened()) { | 294 if (download_->GetAutoOpened()) { |
| 295 parent_->RemoveDownloadView(this); // This will delete us! | 295 parent_->RemoveDownloadView(this); // This will delete us! |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 StopDownloadProgress(); | 298 StopDownloadProgress(); |
| 299 complete_animation_.reset(new ui::SlideAnimation(this)); | 299 complete_animation_.reset(new ui::SlideAnimation(this)); |
| 300 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); | 300 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); |
| 301 complete_animation_->SetTweenType(ui::Tween::LINEAR); | 301 complete_animation_->SetTweenType(ui::Tween::LINEAR); |
| 302 complete_animation_->Show(); | 302 complete_animation_->Show(); |
| 303 SchedulePaint(); | 303 SchedulePaint(); |
| 304 LoadIcon(); | 304 LoadIcon(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 if (context_menu_->download_item()) { | 560 if (context_menu_->download_item()) { |
| 561 drop_down_pressed_ = false; | 561 drop_down_pressed_ = false; |
| 562 // Showing the menu blocks. Here we revert the state. | 562 // Showing the menu blocks. Here we revert the state. |
| 563 SetState(NORMAL, NORMAL); | 563 SetState(NORMAL, NORMAL); |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 | 566 |
| 567 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 567 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 568 state->name = accessible_name_; | 568 state->name = accessible_name_; |
| 569 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 569 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 570 if (download_->safety_state() == DownloadItem::DANGEROUS) { | 570 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 571 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; | 571 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; |
| 572 } else { | 572 } else { |
| 573 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; | 573 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 | 576 |
| 577 void DownloadItemView::ButtonPressed( | 577 void DownloadItemView::ButtonPressed( |
| 578 views::Button* sender, const views::Event& event) { | 578 views::Button* sender, const views::Event& event) { |
| 579 if (sender == discard_button_) { | 579 if (sender == discard_button_) { |
| 580 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 580 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 void DownloadItemView::SetState(State body_state, State drop_down_state) { | 893 void DownloadItemView::SetState(State body_state, State drop_down_state) { |
| 894 if (body_state_ == body_state && drop_down_state_ == drop_down_state) | 894 if (body_state_ == body_state && drop_down_state_ == drop_down_state) |
| 895 return; | 895 return; |
| 896 | 896 |
| 897 body_state_ = body_state; | 897 body_state_ = body_state; |
| 898 drop_down_state_ = drop_down_state; | 898 drop_down_state_ = drop_down_state; |
| 899 SchedulePaint(); | 899 SchedulePaint(); |
| 900 } | 900 } |
| 901 | 901 |
| 902 void DownloadItemView::ClearDangerousMode() { | 902 void DownloadItemView::ClearDangerousMode() { |
| 903 DCHECK(download_->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED && | 903 DCHECK(download_->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED && |
| 904 body_state_ == DANGEROUS && drop_down_state_ == DANGEROUS); | 904 body_state_ == DANGEROUS && drop_down_state_ == DANGEROUS); |
| 905 | 905 |
| 906 body_state_ = NORMAL; | 906 body_state_ = NORMAL; |
| 907 drop_down_state_ = NORMAL; | 907 drop_down_state_ = NORMAL; |
| 908 | 908 |
| 909 // Remove the views used by the dangerous mode. | 909 // Remove the views used by the dangerous mode. |
| 910 RemoveChildView(save_button_); | 910 RemoveChildView(save_button_); |
| 911 delete save_button_; | 911 delete save_button_; |
| 912 save_button_ = NULL; | 912 save_button_ = NULL; |
| 913 RemoveChildView(discard_button_); | 913 RemoveChildView(discard_button_); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 943 save_button_->set_ignore_minimum_size(true); | 943 save_button_->set_ignore_minimum_size(true); |
| 944 discard_button_ = new views::NativeTextButton( | 944 discard_button_ = new views::NativeTextButton( |
| 945 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); | 945 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); |
| 946 discard_button_->set_ignore_minimum_size(true); | 946 discard_button_->set_ignore_minimum_size(true); |
| 947 AddChildView(save_button_); | 947 AddChildView(save_button_); |
| 948 AddChildView(discard_button_); | 948 AddChildView(discard_button_); |
| 949 | 949 |
| 950 // Ensure the file name is not too long. | 950 // Ensure the file name is not too long. |
| 951 | 951 |
| 952 // Extract the file extension (if any). | 952 // Extract the file extension (if any). |
| 953 FilePath filename(download_->target_name()); | 953 FilePath filename(download_->GetTargetName()); |
| 954 #if defined(OS_POSIX) | 954 #if defined(OS_POSIX) |
| 955 string16 extension = WideToUTF16(base::SysNativeMBToWide( | 955 string16 extension = WideToUTF16(base::SysNativeMBToWide( |
| 956 filename.Extension())); | 956 filename.Extension())); |
| 957 #else | 957 #else |
| 958 string16 extension = filename.Extension(); | 958 string16 extension = filename.Extension(); |
| 959 #endif | 959 #endif |
| 960 | 960 |
| 961 // Remove leading '.' | 961 // Remove leading '.' |
| 962 if (extension.length() > 0) | 962 if (extension.length() > 0) |
| 963 extension = extension.substr(1); | 963 extension = extension.substr(1); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { | 1109 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { |
| 1110 if (x > drop_down_x_left_ && x < drop_down_x_right_) | 1110 if (x > drop_down_x_left_ && x < drop_down_x_right_) |
| 1111 return true; | 1111 return true; |
| 1112 return false; | 1112 return false; |
| 1113 } | 1113 } |
| 1114 | 1114 |
| 1115 void DownloadItemView::UpdateAccessibleName() { | 1115 void DownloadItemView::UpdateAccessibleName() { |
| 1116 string16 new_name; | 1116 string16 new_name; |
| 1117 if (download_->safety_state() == DownloadItem::DANGEROUS) { | 1117 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 1118 new_name = dangerous_download_label_->GetText(); | 1118 new_name = dangerous_download_label_->GetText(); |
| 1119 } else { | 1119 } else { |
| 1120 new_name = status_text_ + char16(' ') + | 1120 new_name = status_text_ + char16(' ') + |
| 1121 download_->GetFileNameToReportUser().LossyDisplayName(); | 1121 download_->GetFileNameToReportUser().LossyDisplayName(); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 // If the name has changed, notify assistive technology that the name | 1124 // If the name has changed, notify assistive technology that the name |
| 1125 // has changed so they can announce it immediately. | 1125 // has changed so they can announce it immediately. |
| 1126 if (new_name != accessible_name_) { | 1126 if (new_name != accessible_name_) { |
| 1127 accessible_name_ = new_name; | 1127 accessible_name_ = new_name; |
| 1128 if (GetWidget()) { | 1128 if (GetWidget()) { |
| 1129 GetWidget()->NotifyAccessibilityEvent( | 1129 GetWidget()->NotifyAccessibilityEvent( |
| 1130 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); | 1130 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); |
| 1131 } | 1131 } |
| 1132 } | 1132 } |
| 1133 } | 1133 } |
| OLD | NEW |