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

Remove DownloadItemView::State.

This is only ever used to track if the dropdown is pressed; replace it
with a bool.

Also removes SchedulePaint() calls around changing the dropdown image,
which should be done automatically and thus are redundant.

Bug: none
Change-Id: I457db5f1bc953d0c97cc51b77a13c433d80c6fd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2305373
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790201}
parent 2d4eb141
...@@ -475,7 +475,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender, ...@@ -475,7 +475,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender,
} }
if (sender == dropdown_button_) { if (sender == dropdown_button_) {
SetDropdownState(PUSHED); SetDropdownPressed(true);
ShowContextMenuImpl(dropdown_button_->GetBoundsInScreen(), ShowContextMenuImpl(dropdown_button_->GetBoundsInScreen(),
ui::GetMenuSourceTypeForEvent(event)); ui::GetMenuSourceTypeForEvent(event));
return; return;
...@@ -762,8 +762,7 @@ void DownloadItemView::OnThemeChanged() { ...@@ -762,8 +762,7 @@ void DownloadItemView::OnThemeChanged() {
shelf_->ConfigureButtonForTheme(discard_button_); shelf_->ConfigureButtonForTheme(discard_button_);
shelf_->ConfigureButtonForTheme(scan_button_); shelf_->ConfigureButtonForTheme(scan_button_);
SchedulePaint(); UpdateDropdownButtonImage();
UpdateDropdownButton();
} }
DownloadItemView::Mode DownloadItemView::GetDesiredMode() const { DownloadItemView::Mode DownloadItemView::GetDesiredMode() const {
...@@ -1222,22 +1221,20 @@ int DownloadItemView::GetLabelWidth(const views::StyledLabel& label) const { ...@@ -1222,22 +1221,20 @@ int DownloadItemView::GetLabelWidth(const views::StyledLabel& label) const {
std::move(lines_for_width)); std::move(lines_for_width));
} }
void DownloadItemView::SetDropdownState(State new_state) { void DownloadItemView::SetDropdownPressed(bool pressed) {
if (new_state != dropdown_state_) { if (dropdown_pressed_ != pressed) {
dropdown_button_->AnimateInkDrop(new_state == PUSHED dropdown_pressed_ = pressed;
dropdown_button_->AnimateInkDrop(dropdown_pressed_
? views::InkDropState::ACTIVATED ? views::InkDropState::ACTIVATED
: views::InkDropState::DEACTIVATED, : views::InkDropState::DEACTIVATED,
nullptr); nullptr);
dropdown_state_ = new_state; UpdateDropdownButtonImage();
UpdateDropdownButton();
SchedulePaint();
} }
} }
void DownloadItemView::UpdateDropdownButton() { void DownloadItemView::UpdateDropdownButtonImage() {
views::SetImageFromVectorIcon( views::SetImageFromVectorIcon(
dropdown_button_, dropdown_button_, dropdown_pressed_ ? kCaretDownIcon : kCaretUpIcon,
dropdown_state_ == PUSHED ? kCaretDownIcon : kCaretUpIcon,
GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
} }
...@@ -1279,7 +1276,7 @@ void DownloadItemView::ShowContextMenuImpl(const gfx::Rect& rect, ...@@ -1279,7 +1276,7 @@ void DownloadItemView::ShowContextMenuImpl(const gfx::Rect& rect,
if (!context_menu_.get()) if (!context_menu_.get())
context_menu_ = std::make_unique<DownloadShelfContextMenuView>(this); context_menu_ = std::make_unique<DownloadShelfContextMenuView>(this);
const auto release_dropdown = [](DownloadItemView* view) { const auto release_dropdown = [](DownloadItemView* view) {
view->SetDropdownState(NORMAL); view->SetDropdownPressed(false);
// Make sure any new status from activating a context menu option is read. // Make sure any new status from activating a context menu option is read.
view->announce_accessible_alert_soon_ = true; view->announce_accessible_alert_soon_ = true;
}; };
......
...@@ -116,8 +116,6 @@ class DownloadItemView : public views::View, ...@@ -116,8 +116,6 @@ class DownloadItemView : public views::View,
void OnThemeChanged() override; void OnThemeChanged() override;
private: private:
enum State { NORMAL = 0, HOT, PUSHED };
// Returns the mode that best reflects the current model state. // Returns the mode that best reflects the current model state.
Mode GetDesiredMode() const; Mode GetDesiredMode() const;
...@@ -188,10 +186,10 @@ class DownloadItemView : public views::View, ...@@ -188,10 +186,10 @@ class DownloadItemView : public views::View,
int GetLabelWidth(const views::StyledLabel& label) const; int GetLabelWidth(const views::StyledLabel& label) const;
// Sets the state and triggers a repaint. // Sets the state and triggers a repaint.
void SetDropdownState(State new_state); void SetDropdownPressed(bool pressed);
// Sets |dropdown_button_| to have the correct image for the current state. // Sets |dropdown_button_| to have the correct image for the current state.
void UpdateDropdownButton(); void UpdateDropdownButtonImage();
// Shows an appropriate prompt dialog when the user hits the "open" button // Shows an appropriate prompt dialog when the user hits the "open" button
// when not in normal mode. // when not in normal mode.
...@@ -269,8 +267,8 @@ class DownloadItemView : public views::View, ...@@ -269,8 +267,8 @@ class DownloadItemView : public views::View,
views::MdTextButton* scan_button_; views::MdTextButton* scan_button_;
views::ImageButton* dropdown_button_; views::ImageButton* dropdown_button_;
// The current state (normal, hot or pushed) of the body and drop-down. // Whether the dropdown is currently pressed.
State dropdown_state_ = NORMAL; bool dropdown_pressed_ = false;
std::unique_ptr<DownloadShelfContextMenuView> context_menu_; std::unique_ptr<DownloadShelfContextMenuView> context_menu_;
......
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