Commit 5a26939a authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Use callbacks instead of ButtonPressed overrides: c/b/ui/views/download/

Bug: 772945
Change-Id: Ie796f6598a821ba63596efecdb7683fbadbeac08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429259Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811570}
parent a05c1cbe
......@@ -145,7 +145,7 @@ class TransparentButton : public views::Button {
public:
METADATA_HEADER(TransparentButton);
explicit TransparentButton(DownloadItemView* parent) : Button(parent) {
explicit TransparentButton(DownloadItemView* parent) : Button(nullptr) {
SetFocusForPlatform();
views::InstallRectHighlightPathGenerator(this);
SetInkDropMode(InkDropMode::ON);
......@@ -256,6 +256,8 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr model,
// views to localize functionality and simplify this class.
open_button_ = AddChildView(std::make_unique<TransparentButton>(this));
open_button_->set_callback(base::BindRepeating(
&DownloadItemView::OpenButtonPressed, base::Unretained(this)));
file_name_label_ = AddChildView(std::make_unique<views::StyledLabel>());
file_name_label_->SetTextContext(CONTEXT_DOWNLOAD_SHELF);
......@@ -278,17 +280,27 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr model,
deep_scanning_label_->set_can_process_events_within_subtree(false);
open_now_button_ = AddChildView(std::make_unique<views::MdTextButton>(
this, l10n_util::GetStringUTF16(IDS_OPEN_DOWNLOAD_NOW)));
base::BindRepeating(&DownloadItemView::OpenDownloadDuringAsyncScanning,
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_OPEN_DOWNLOAD_NOW)));
save_button_ = AddChildView(std::make_unique<views::MdTextButton>(this));
save_button_ = AddChildView(std::make_unique<views::MdTextButton>(
base::BindRepeating(&DownloadItemView::SaveOrDiscardButtonPressed,
base::Unretained(this), DownloadCommands::KEEP)));
discard_button_ = AddChildView(std::make_unique<views::MdTextButton>(
this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)));
base::BindRepeating(&DownloadItemView::SaveOrDiscardButtonPressed,
base::Unretained(this), DownloadCommands::DISCARD),
l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)));
scan_button_ = AddChildView(std::make_unique<views::MdTextButton>(
this, l10n_util::GetStringUTF16(IDS_SCAN_DOWNLOAD)));
base::BindRepeating(&DownloadItemView::ExecuteCommand,
base::Unretained(this), DownloadCommands::DEEP_SCAN),
l10n_util::GetStringUTF16(IDS_SCAN_DOWNLOAD)));
dropdown_button_ = AddChildView(views::CreateVectorImageButton(this));
dropdown_button_ =
AddChildView(views::CreateVectorImageButton(base::BindRepeating(
&DownloadItemView::DropdownButtonPressed, base::Unretained(this))));
dropdown_button_->SetAccessibleName(l10n_util::GetStringUTF16(
IDS_DOWNLOAD_ITEM_DROPDOWN_BUTTON_ACCESSIBLE_TEXT));
dropdown_button_->SetBorder(views::CreateEmptyBorder(gfx::Insets(10)));
......@@ -405,37 +417,6 @@ void DownloadItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetDescription(base::string16());
}
void DownloadItemView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == open_button_) {
if (mode_ == Mode::kNormal) {
complete_animation_.End();
announce_accessible_alert_soon_ = true;
model_->OpenDownload();
// WARNING: |this| may be deleted!
} else {
ShowOpenDialog(
shelf_->browser()->tab_strip_model()->GetActiveWebContents());
}
} else if (sender == open_now_button_) {
OpenDownloadDuringAsyncScanning();
} else if (sender == scan_button_) {
ExecuteCommand(DownloadCommands::DEEP_SCAN);
} else if (sender == dropdown_button_) {
SetDropdownPressed(true);
ShowContextMenuImpl(dropdown_button_->GetBoundsInScreen(),
ui::GetMenuSourceTypeForEvent(event));
} else {
const auto command = (sender == save_button_) ? DownloadCommands::KEEP
: DownloadCommands::DISCARD;
if (is_mixed_content(mode_))
ExecuteCommand(command);
else
MaybeSubmitDownloadToFeedbackService(command);
// WARNING: |this| may be deleted!
}
}
void DownloadItemView::ShowContextMenuForViewImpl(
View* source,
const gfx::Point& point,
......@@ -1141,6 +1122,33 @@ void DownloadItemView::UpdateDropdownButtonImage() {
GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
}
void DownloadItemView::OpenButtonPressed() {
if (mode_ == Mode::kNormal) {
complete_animation_.End();
announce_accessible_alert_soon_ = true;
model_->OpenDownload();
// WARNING: |this| may be deleted!
} else {
ShowOpenDialog(
shelf_->browser()->tab_strip_model()->GetActiveWebContents());
}
}
void DownloadItemView::SaveOrDiscardButtonPressed(
DownloadCommands::Command command) {
if (is_mixed_content(mode_))
ExecuteCommand(command);
else
MaybeSubmitDownloadToFeedbackService(command);
// WARNING: |this| may be deleted!
}
void DownloadItemView::DropdownButtonPressed(const ui::Event& event) {
SetDropdownPressed(true);
ShowContextMenuImpl(dropdown_button_->GetBoundsInScreen(),
ui::GetMenuSourceTypeForEvent(event));
}
void DownloadItemView::ShowOpenDialog(content::WebContents* web_contents) {
if (mode_ == Mode::kDeepScanning) {
TabModalConfirmDialog::Create(
......
......@@ -63,7 +63,6 @@ class StyledLabel;
// The DownloadItemView lives in the Browser, and has a corresponding
// DownloadController that receives / writes data which lives in the Renderer.
class DownloadItemView : public views::View,
public views::ButtonListener,
public views::ContextMenuController,
public DownloadUIModel::Observer,
public views::AnimationDelegateViews {
......@@ -84,9 +83,6 @@ class DownloadItemView : public views::View,
base::string16 GetTooltipText(const gfx::Point& p) const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::ContextMenuController:
void ShowContextMenuForViewImpl(View* source,
const gfx::Point& point,
......@@ -196,6 +192,11 @@ class DownloadItemView : public views::View,
// Sets |dropdown_button_| to have the correct image for the current state.
void UpdateDropdownButtonImage();
// Called when various buttons are pressed.
void OpenButtonPressed();
void SaveOrDiscardButtonPressed(DownloadCommands::Command command);
void DropdownButtonPressed(const ui::Event& event);
// Shows an appropriate prompt dialog when the user hits the "open" button
// when not in normal mode.
void ShowOpenDialog(content::WebContents* web_contents);
......
......@@ -72,10 +72,12 @@ DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent)
SetVisible(false);
show_all_view_ = AddChildView(std::make_unique<views::MdTextButton>(
this, l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)));
base::BindRepeating(&chrome::ShowDownloads, browser),
l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)));
show_all_view_->SizeToPreferredSize();
close_button_ = AddChildView(views::CreateVectorImageButton(this));
close_button_ = AddChildView(views::CreateVectorImageButton(
base::BindRepeating(&DownloadShelf::Close, base::Unretained(this))));
close_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
close_button_->SetFocusForPlatform();
......@@ -235,16 +237,6 @@ void DownloadShelfView::AnimationEnded(const gfx::Animation* animation) {
SetVisible(false);
}
void DownloadShelfView::ButtonPressed(views::Button* button,
const ui::Event& event) {
if (button == close_button_) {
Close();
} else {
DCHECK_EQ(show_all_view_, button);
chrome::ShowDownloads(browser());
}
}
void DownloadShelfView::MouseMovedOutOfHost() {
Close();
}
......
......@@ -34,7 +34,6 @@ class MdTextButton;
class DownloadShelfView : public DownloadShelf,
public views::AccessiblePaneView,
public views::AnimationDelegateViews,
public views::ButtonListener,
public views::MouseWatcherListener {
public:
DownloadShelfView(Browser* browser, BrowserView* parent);
......@@ -55,9 +54,6 @@ class DownloadShelfView : public DownloadShelf,
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationEnded(const gfx::Animation* animation) override;
// views::ButtonListener:
void ButtonPressed(views::Button* button, const ui::Event& event) override;
// views::MouseWatcherListener:
void MouseMovedOutOfHost() override;
......
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