Skip to content

Commit

Permalink
Use callbacks instead of ButtonPressed overrides: apps/
Browse files Browse the repository at this point in the history
Bug: 772945
Change-Id: I56e6861493cf4c28f655c4eab277b4172911bf91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425152
Reviewed-by: Ben Wells <benwells@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809822}
  • Loading branch information
pkasting authored and Commit Bot committed Sep 23, 2020
1 parent 02c27a6 commit 93105ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
29 changes: 12 additions & 17 deletions apps/ui/views/app_window_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ AppWindowFrameView::~AppWindowFrameView() = default;
void AppWindowFrameView::Init() {
if (draw_frame_) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
auto close_button = std::make_unique<views::ImageButton>(this);
auto close_button = std::make_unique<views::ImageButton>();
close_button->set_callback(
base::BindRepeating(&views::Widget::Close, base::Unretained(widget_)));
close_button->SetImage(
views::Button::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia());
Expand All @@ -67,7 +69,9 @@ void AppWindowFrameView::Init() {
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
close_button_ = AddChildView(std::move(close_button));
// STATE_NORMAL images are set in SetButtonImagesForFrame, not here.
auto maximize_button = std::make_unique<views::ImageButton>(this);
auto maximize_button = std::make_unique<views::ImageButton>();
maximize_button->set_callback(base::BindRepeating(
&views::Widget::Maximize, base::Unretained(widget_)));
maximize_button->SetImage(
views::Button::STATE_HOVERED,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia());
Expand All @@ -80,7 +84,9 @@ void AppWindowFrameView::Init() {
maximize_button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
maximize_button_ = AddChildView(std::move(maximize_button));
auto restore_button = std::make_unique<views::ImageButton>(this);
auto restore_button = std::make_unique<views::ImageButton>();
restore_button->set_callback(base::BindRepeating(
&views::Widget::Restore, base::Unretained(widget_)));
restore_button->SetImage(
views::Button::STATE_HOVERED,
rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia());
Expand All @@ -90,7 +96,9 @@ void AppWindowFrameView::Init() {
restore_button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE));
restore_button_ = AddChildView(std::move(restore_button));
auto minimize_button = std::make_unique<views::ImageButton>(this);
auto minimize_button = std::make_unique<views::ImageButton>();
minimize_button->set_callback(base::BindRepeating(
&views::Widget::Minimize, base::Unretained(widget_)));
minimize_button->SetImage(
views::Button::STATE_HOVERED,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia());
Expand Down Expand Up @@ -345,19 +353,6 @@ gfx::Size AppWindowFrameView::GetMaximumSize() const {
return max_size;
}

void AppWindowFrameView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(draw_frame_);
if (sender == close_button_)
widget_->Close();
else if (sender == maximize_button_)
widget_->Maximize();
else if (sender == restore_button_)
widget_->Restore();
else if (sender == minimize_button_)
widget_->Minimize();
}

SkColor AppWindowFrameView::CurrentFrameColor() {
return widget_->IsActive() ? active_frame_color_ : inactive_frame_color_;
}
Expand Down
10 changes: 1 addition & 9 deletions apps/ui/views/app_window_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class Canvas;
class Point;
}

namespace ui {
class Event;
}

namespace views {
class ImageButton;
class Widget;
Expand All @@ -34,8 +30,7 @@ class Widget;
namespace apps {

// A frameless or non-Ash, non-panel NonClientFrameView for app windows.
class AppWindowFrameView : public views::NonClientFrameView,
public views::ButtonListener {
class AppWindowFrameView : public views::NonClientFrameView {
public:
static const char kViewClassName[];

Expand Down Expand Up @@ -81,9 +76,6 @@ class AppWindowFrameView : public views::NonClientFrameView,
gfx::Size GetMinimumSize() const override;
gfx::Size GetMaximumSize() const override;

// views::ButtonListener implementation.
void ButtonPressed(views::Button* sender, const ui::Event& event) override;

// Some button images we use depend on the color of the frame. This
// will set these images based on the color of the frame.
void SetButtonImagesForFrame();
Expand Down

0 comments on commit 93105ef

Please sign in to comment.