Commit e7f46de8 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Refactor DownloadItemView state transitions, part 5.

* Moves calls to UpdateAccessibleName() into UpdateMode().  The
  unconditional call in OnDownloadUpdated() is now effectively called
  earlier, and conditionally, but it only had an effect in a subset of
  the cases where UpdateMode() is called, and is unrelated to the things
  that change in the meantime*, so this is fine.
  *Except: The other existing call in GetInProgressAccessibleAlertText()
  was necessary to ensure this _was_ updated in time in that case, and
  now that it's done earlier, is no longer needed.
* Inlines the contents of UpdateAccessibleName() since it's now only
  called once.
* Adds a new helper, UpdateAccessibleAlertAndTimersForNormalMode(),
  which handles everything UpdateMode() was doing specifically for the
  kNormal case.  Refactors the existing switch significantly to reduce
  duplication.
* Removes a call to StopDownloadProgress() from the destructor which had
  no effect (since the timers were about to be deleted anyway).
* Inlines StartDownloadProgress() and StopDownloadProgress() into the
  new helper since they're now each only called once.
* Sets up parameters for various timers in the constructor so this
  helper can largely just Reset() them to start them.
* Inlines ProgressTimerFired() as a lambda into the progress timer
  constructor.
* Renames various timer-related members in hopes of greater clarity.

Bug: none
Change-Id: Ida6a1f9d607d95f190be3908d7639de8bd515990
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2301209
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789535}
parent 69108334
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "chrome/browser/ui/tab_modal_confirm_dialog.h" #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "components/download/public/common/download_item.h" #include "components/download/public/common/download_item.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/views/animation/animation_delegate_views.h" #include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/context_menu_controller.h" #include "ui/views/context_menu_controller.h"
...@@ -44,7 +45,6 @@ class DownloadShelfContextMenuView; ...@@ -44,7 +45,6 @@ class DownloadShelfContextMenuView;
namespace gfx { namespace gfx {
class Image; class Image;
class ImageSkia; class ImageSkia;
class SlideAnimation;
} }
namespace views { namespace views {
...@@ -145,6 +145,9 @@ class DownloadItemView : public views::View, ...@@ -145,6 +145,9 @@ class DownloadItemView : public views::View,
// Updates the visible and enabled state of all buttons. // Updates the visible and enabled state of all buttons.
void UpdateButtons(); void UpdateButtons();
// Updates the accessible alert and timers for normal mode.
void UpdateAccessibleAlertAndTimersForNormalMode();
void OpenDownload(); void OpenDownload();
// Submits the downloaded file to the safebrowsing download feedback service. // Submits the downloaded file to the safebrowsing download feedback service.
...@@ -188,16 +191,6 @@ class DownloadItemView : public views::View, ...@@ -188,16 +191,6 @@ class DownloadItemView : public views::View,
// Releases drop down button after showing a context menu. // Releases drop down button after showing a context menu.
void ReleaseDropdown(); void ReleaseDropdown();
// Timer callback for handling animations
void StartDownloadProgress();
void StopDownloadProgress();
// Update the accessible name to reflect the current state of the control,
// so that screenreaders can access the filename, status text, and
// dangerous download warning message (if any). The name will be presented
// when the download item receives focus.
void UpdateAccessibleName();
// Update accessible status text. // Update accessible status text.
// If |is_last_update| is false, then a timer is used to notify screen readers // If |is_last_update| is false, then a timer is used to notify screen readers
// to speak the alert text on a regular interval. If |is_last_update| is true, // to speak the alert text on a regular interval. If |is_last_update| is true,
...@@ -230,9 +223,6 @@ class DownloadItemView : public views::View, ...@@ -230,9 +223,6 @@ class DownloadItemView : public views::View,
State to, State to,
gfx::SlideAnimation* animation); gfx::SlideAnimation* animation);
// Callback for |progress_timer_|.
void ProgressTimerFired();
// Returns the text and style to use for the status label. // Returns the text and style to use for the status label.
std::pair<base::string16, int> GetStatusTextAndStyle() const; std::pair<base::string16, int> GetStatusTextAndStyle() const;
...@@ -276,14 +266,6 @@ class DownloadItemView : public views::View, ...@@ -276,14 +266,6 @@ class DownloadItemView : public views::View,
// Mode of the download item view. // Mode of the download item view.
Mode mode_; Mode mode_;
// When download progress last began animating (pausing and resuming will
// update this). Used for downloads of unknown size.
base::TimeTicks progress_start_time_;
// Keeps the amount of time spent already animating. Used to keep track of
// total active time for downloads of unknown size.
base::TimeDelta previous_progress_elapsed_;
// Whether we are dragging the download button. // Whether we are dragging the download button.
bool dragging_; bool dragging_;
...@@ -296,12 +278,6 @@ class DownloadItemView : public views::View, ...@@ -296,12 +278,6 @@ class DownloadItemView : public views::View,
// A model class to control the status text we display. // A model class to control the status text we display.
DownloadUIModel::DownloadUIModelPtr model_; DownloadUIModel::DownloadUIModelPtr model_;
// Animation for download complete.
std::unique_ptr<gfx::SlideAnimation> complete_animation_;
// Progress animation
base::RepeatingTimer progress_timer_;
// The "open download" button. This button is visually transparent and fills // The "open download" button. This button is visually transparent and fills
// the entire bounds of the DownloadItemView, to make the DownloadItemView // the entire bounds of the DownloadItemView, to make the DownloadItemView
// itself seem to be clickable while not requiring DownloadItemView itself to // itself seem to be clickable while not requiring DownloadItemView itself to
...@@ -332,6 +308,17 @@ class DownloadItemView : public views::View, ...@@ -332,6 +308,17 @@ class DownloadItemView : public views::View,
// The currently running download context menu. // The currently running download context menu.
std::unique_ptr<DownloadShelfContextMenuView> context_menu_; std::unique_ptr<DownloadShelfContextMenuView> context_menu_;
base::RepeatingTimer indeterminate_progress_timer_;
// The start of the most recent active period of downloading a file of
// indeterminate size.
base::TimeTicks indeterminate_progress_start_time_;
// The total active time downloading a file of indeterminate size.
base::TimeDelta indeterminate_progress_time_elapsed_;
gfx::SlideAnimation complete_animation_{this};
// The name of this view as reported to assistive technology. // The name of this view as reported to assistive technology.
base::string16 accessible_name_; base::string16 accessible_name_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment