| Index: chrome/browser/ui/views/download/download_item_view_md.cc
|
| diff --git a/chrome/browser/ui/views/download/download_item_view_md.cc b/chrome/browser/ui/views/download/download_item_view_md.cc
|
| index 1fbd1304bc0bf058f54d7b44eed775fc87507d40..5707d2729994c48f2b064afbb9573877677a548e 100644
|
| --- a/chrome/browser/ui/views/download/download_item_view_md.cc
|
| +++ b/chrome/browser/ui/views/download/download_item_view_md.cc
|
| @@ -155,7 +155,7 @@ DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item,
|
| model_(download_item),
|
| save_button_(nullptr),
|
| discard_button_(nullptr),
|
| - dropdown_button_(nullptr),
|
| + dropdown_button_(new BarControlButton(this)),
|
| dangerous_download_label_(nullptr),
|
| dangerous_download_label_sized_(false),
|
| disabled_while_opening_(false),
|
| @@ -167,6 +167,8 @@ DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item,
|
| download()->AddObserver(this);
|
| set_context_menu_controller(this);
|
|
|
| + AddChildView(dropdown_button_);
|
| +
|
| LoadIcon();
|
|
|
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| @@ -182,8 +184,6 @@ DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item,
|
|
|
| OnDownloadUpdated(download());
|
|
|
| - dropdown_button_ = new BarControlButton(this);
|
| - AddChildView(dropdown_button_);
|
| SetDropdownState(NORMAL);
|
| UpdateColorsFromTheme();
|
| }
|
| @@ -205,10 +205,10 @@ void DownloadItemViewMd::StartDownloadProgress() {
|
| if (progress_timer_.IsRunning())
|
| return;
|
| progress_start_time_ = base::TimeTicks::Now();
|
| - progress_timer_.Start(
|
| - FROM_HERE,
|
| - base::TimeDelta::FromMilliseconds(DownloadShelf::kProgressRateMs),
|
| - base::Bind(&DownloadItemViewMd::SchedulePaint, base::Unretained(this)));
|
| + progress_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
|
| + DownloadShelf::kProgressRateMs),
|
| + base::Bind(&DownloadItemViewMd::ProgressTimerFired,
|
| + base::Unretained(this)));
|
| }
|
|
|
| void DownloadItemViewMd::StopDownloadProgress() {
|
| @@ -243,16 +243,9 @@ void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) {
|
| return;
|
| }
|
|
|
| - if (IsShowingWarningDialog() && !model_.IsDangerous()) {
|
| - // We have been approved.
|
| - ClearWarningDialog();
|
| - } else if (!IsShowingWarningDialog() && model_.IsDangerous()) {
|
| - ShowWarningDialog();
|
| - // Force the shelf to layout again as our size has changed.
|
| - shelf_->Layout();
|
| - SchedulePaint();
|
| + if (IsShowingWarningDialog() != model_.IsDangerous()) {
|
| + ToggleWarningDialog();
|
| } else {
|
| - base::string16 status_text = model_.GetStatusText();
|
| switch (download()->GetState()) {
|
| case DownloadItem::IN_PROGRESS:
|
| download()->IsPaused() ? StopDownloadProgress()
|
| @@ -265,7 +258,6 @@ void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) {
|
| complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs);
|
| complete_animation_->SetTweenType(gfx::Tween::LINEAR);
|
| complete_animation_->Show();
|
| - SchedulePaint();
|
| LoadIcon();
|
| break;
|
| case DownloadItem::COMPLETE:
|
| @@ -278,7 +270,6 @@ void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) {
|
| complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
|
| complete_animation_->SetTweenType(gfx::Tween::LINEAR);
|
| complete_animation_->Show();
|
| - SchedulePaint();
|
| LoadIcon();
|
| break;
|
| case DownloadItem::CANCELLED:
|
| @@ -290,7 +281,8 @@ void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) {
|
| default:
|
| NOTREACHED();
|
| }
|
| - status_text_ = status_text;
|
| + status_text_ = model_.GetStatusText();
|
| + SchedulePaint();
|
| }
|
|
|
| base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth);
|
| @@ -300,11 +292,6 @@ void DownloadItemViewMd::OnDownloadUpdated(DownloadItem* download_item) {
|
| }
|
|
|
| UpdateAccessibleName();
|
| -
|
| - // We use the parent's (DownloadShelfView's) SchedulePaint, since there
|
| - // are spaces between each DownloadItemViewMd that the parent is responsible
|
| - // for painting.
|
| - shelf_->SchedulePaint();
|
| }
|
|
|
| void DownloadItemViewMd::OnDownloadDestroyed(DownloadItem* download) {
|
| @@ -491,7 +478,7 @@ void DownloadItemViewMd::ShowContextMenuForView(
|
|
|
| void DownloadItemViewMd::ButtonPressed(views::Button* sender,
|
| const ui::Event& event) {
|
| - if (dropdown_button_ && sender == dropdown_button_) {
|
| + if (sender == dropdown_button_) {
|
| // TODO(estade): this is copied from ToolbarActionView but should be shared
|
| // one way or another.
|
| ui::MenuSourceType type = ui::MENU_SOURCE_NONE;
|
| @@ -832,6 +819,20 @@ void DownloadItemViewMd::SetDropdownState(State new_state) {
|
| SchedulePaint();
|
| }
|
|
|
| +void DownloadItemViewMd::ToggleWarningDialog() {
|
| + if (model_.IsDangerous())
|
| + ShowWarningDialog();
|
| + else
|
| + ClearWarningDialog();
|
| +
|
| + // We need to load the icon now that the download has the real path.
|
| + LoadIcon();
|
| +
|
| + // Force the shelf to layout again as our size has changed.
|
| + shelf_->Layout();
|
| + shelf_->SchedulePaint();
|
| +}
|
| +
|
| void DownloadItemViewMd::ClearWarningDialog() {
|
| DCHECK(download()->GetDangerType() ==
|
| content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED);
|
| @@ -860,18 +861,10 @@ void DownloadItemViewMd::ClearWarningDialog() {
|
| dangerous_download_label_sized_ = false;
|
| cached_button_size_.SetSize(0, 0);
|
|
|
| - // Set the accessible name back to the status and filename instead of the
|
| - // download warning.
|
| - UpdateAccessibleName();
|
| -
|
| // We need to load the icon now that the download has the real path.
|
| LoadIcon();
|
|
|
| - // Force the shelf to layout again as our size has changed.
|
| - shelf_->Layout();
|
| - shelf_->SchedulePaint();
|
| -
|
| - TooltipTextChanged();
|
| + dropdown_button_->SetVisible(true);
|
| }
|
|
|
| void DownloadItemViewMd::ShowWarningDialog() {
|
| @@ -918,7 +911,8 @@ void DownloadItemViewMd::ShowWarningDialog() {
|
| dangerous_download_label_->SetAutoColorReadabilityEnabled(false);
|
| AddChildView(dangerous_download_label_);
|
| SizeLabelToMinWidth();
|
| - TooltipTextChanged();
|
| +
|
| + dropdown_button_->SetVisible(false);
|
| }
|
|
|
| gfx::ImageSkia DownloadItemViewMd::GetWarningIcon() {
|
| @@ -1075,6 +1069,13 @@ void DownloadItemViewMd::AnimateStateTransition(
|
| }
|
| }
|
|
|
| +void DownloadItemViewMd::ProgressTimerFired() {
|
| + // Only repaint for the indeterminate size case. Otherwise, we'll repaint only
|
| + // when there's an update notified via OnDownloadUpdated().
|
| + if (model_.PercentComplete() < 0)
|
| + SchedulePaint();
|
| +}
|
| +
|
| SkColor DownloadItemViewMd::GetTextColor() {
|
| return GetTextColorForThemeProvider(GetThemeProvider());
|
| }
|
|
|