Commit 6692d4eb authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: ash/wm/

Bug: 772945
Change-Id: Iade9be1584a696fe14680b829085c02add99d64a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2502779
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821507}
parent bdd9d847
......@@ -19,8 +19,8 @@
namespace ash {
CloseDeskButton::CloseDeskButton(views::ButtonListener* listener)
: ImageButton(listener) {
CloseDeskButton::CloseDeskButton(PressedCallback callback)
: ImageButton(std::move(callback)) {
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
......
......@@ -20,7 +20,7 @@ namespace ash {
class ASH_EXPORT CloseDeskButton : public views::ImageButton,
public views::ViewTargeterDelegate {
public:
explicit CloseDeskButton(views::ButtonListener* listener);
explicit CloseDeskButton(PressedCallback callback);
~CloseDeskButton() override;
// The size of the close button.
......
......@@ -74,9 +74,14 @@ DeskMiniView::DeskMiniView(DesksBarView* owner_bar,
// TODO(afakhry): Tooltips.
desk_preview_ = AddChildView(std::make_unique<DeskPreviewView>(this));
desk_preview_ = AddChildView(std::make_unique<DeskPreviewView>(
base::BindRepeating(&DeskMiniView::OnDeskPreviewPressed,
base::Unretained(this)),
this));
desk_name_view_ = AddChildView(std::move(desk_name_view));
close_desk_button_ = AddChildView(std::make_unique<CloseDeskButton>(this));
close_desk_button_ =
AddChildView(std::make_unique<CloseDeskButton>(base::BindRepeating(
&DeskMiniView::OnCloseButtonPressed, base::Unretained(this))));
UpdateCloseButtonVisibility();
UpdateBorderColor();
......@@ -207,15 +212,6 @@ void DeskMiniView::OnThemeChanged() {
UpdateBorderColor();
}
void DeskMiniView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(desk_);
if (sender == close_desk_button_)
OnCloseButtonPressed();
else if (sender == desk_preview_)
OnDeskPreviewPressed();
}
void DeskMiniView::OnContentChanged() {
desk_preview_->RecreateDeskContentsMirrorLayers();
}
......
......@@ -29,7 +29,6 @@ class DesksBarView;
// supports desk activation and removal.
class ASH_EXPORT DeskMiniView
: public views::View,
public views::ButtonListener,
public Desk::Observer,
public OverviewHighlightController::OverviewHighlightableView,
public views::TextfieldController,
......@@ -76,9 +75,6 @@ class ASH_EXPORT DeskMiniView
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void OnThemeChanged() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Desk::Observer:
void OnContentChanged() override;
void OnDeskDestroyed(const Desk* desk) override;
......
......@@ -205,8 +205,9 @@ class DeskPreviewView::ShadowRenderer : public ui::LayerDelegate {
// -----------------------------------------------------------------------------
// DeskPreviewView
DeskPreviewView::DeskPreviewView(DeskMiniView* mini_view)
: views::Button(mini_view),
DeskPreviewView::DeskPreviewView(PressedCallback callback,
DeskMiniView* mini_view)
: views::Button(std::move(callback)),
mini_view_(mini_view),
wallpaper_preview_(new DeskWallpaperPreview),
desk_mirrored_contents_view_(new views::View),
......
......@@ -61,7 +61,7 @@ class WmHighlightItemBorder;
// descendant of the other. Otherwise, this will trigger a render surface.
class ASH_EXPORT DeskPreviewView : public views::Button {
public:
explicit DeskPreviewView(DeskMiniView* mini_view);
DeskPreviewView(PressedCallback callback, DeskMiniView* mini_view);
~DeskPreviewView() override;
// Returns the height of the DeskPreviewView based on whether the |compact|
......
......@@ -129,7 +129,7 @@ class DeskBarHoverObserver : public ui::EventObserver {
DesksBarView::DesksBarView(OverviewGrid* overview_grid)
: background_view_(new views::View),
new_desk_button_(new NewDeskButton(this)),
new_desk_button_(new NewDeskButton()),
overview_grid_(overview_grid) {
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
......@@ -311,12 +311,6 @@ bool DesksBarView::UsesCompactLayout() const {
width() <= min_width_to_fit_contents_;
}
void DesksBarView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == new_desk_button_)
new_desk_button_->OnButtonPressed();
}
void DesksBarView::OnDeskAdded(const Desk* desk) {
DeskNameView::CommitChanges(GetWidget());
UpdateNewMiniViews(/*animate=*/true);
......
......@@ -11,7 +11,7 @@
#include "ash/ash_export.h"
#include "ash/wm/desks/desks_controller.h"
#include "base/macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace ash {
......@@ -23,7 +23,6 @@ class OverviewGrid;
// A bar that resides at the top portion of the overview mode's ShieldView,
// which contains the virtual desks mini_views, as well as the new desk button.
class ASH_EXPORT DesksBarView : public views::View,
public views::ButtonListener,
public DesksController::Observer {
public:
explicit DesksBarView(OverviewGrid* overview_grid);
......@@ -96,9 +95,6 @@ class ASH_EXPORT DesksBarView : public views::View,
// both itself and its children.
bool UsesCompactLayout() const;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// DesksController::Observer:
void OnDeskAdded(const Desk* desk) override;
void OnDeskRemoved(const Desk* desk) override;
......
......@@ -36,8 +36,9 @@ constexpr int kCornerRadius = 16;
} // namespace
NewDeskButton::NewDeskButton(views::ButtonListener* listener)
: LabelButton(listener,
NewDeskButton::NewDeskButton()
: LabelButton(base::BindRepeating(&NewDeskButton::OnButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_ASH_DESKS_NEW_DESK_BUTTON)) {
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
......
......@@ -22,7 +22,7 @@ class ASH_EXPORT NewDeskButton
: public views::LabelButton,
public OverviewHighlightController::OverviewHighlightableView {
public:
explicit NewDeskButton(views::ButtonListener* listener);
NewDeskButton();
~NewDeskButton() override = default;
// Update the button's enable/disable state based on current desks state.
......
......@@ -902,18 +902,6 @@ void OverviewItem::OnHighlightedViewClosed() {
overview_session_->OnHighlightedItemClosed(this);
}
void OverviewItem::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK_EQ(sender, overview_item_view_->close_button());
base::RecordAction(
base::UserMetricsAction("WindowSelector_OverviewCloseButton"));
if (Shell::Get()->tablet_mode_controller()->InTabletMode()) {
base::RecordAction(
base::UserMetricsAction("Tablet_WindowCloseFromOverviewButton"));
}
CloseWindow();
}
void OverviewItem::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
......@@ -1227,7 +1215,10 @@ void OverviewItem::CreateItemWidget() {
overview_item_view_ =
item_widget_->SetContentsView(std::make_unique<OverviewItemView>(
this, GetWindow(), transform_window_.IsMinimized()));
this,
base::BindRepeating(&OverviewItem::CloseButtonPressed,
base::Unretained(this)),
GetWindow(), transform_window_.IsMinimized()));
item_widget_->Show();
item_widget_->SetOpacity(0.f);
item_widget_->GetLayer()->SetMasksToBounds(false);
......@@ -1290,6 +1281,16 @@ void OverviewItem::StartDrag() {
}
}
void OverviewItem::CloseButtonPressed() {
base::RecordAction(
base::UserMetricsAction("WindowSelector_OverviewCloseButton"));
if (Shell::Get()->tablet_mode_controller()->InTabletMode()) {
base::RecordAction(
base::UserMetricsAction("Tablet_WindowCloseFromOverviewButton"));
}
CloseWindow();
}
void OverviewItem::HandlePressEvent(const gfx::PointF& location_in_screen,
bool from_touch_gesture) {
// No need to start the drag again if already in a drag. This can happen if we
......
......@@ -35,8 +35,7 @@ class OverviewItemView;
class RoundedLabelWidget;
// This class represents an item in overview mode.
class ASH_EXPORT OverviewItem : public views::ButtonListener,
public aura::WindowObserver,
class ASH_EXPORT OverviewItem : public aura::WindowObserver,
public WindowStateObserver {
public:
OverviewItem(aura::Window* window,
......@@ -185,9 +184,6 @@ class ASH_EXPORT OverviewItem : public views::ButtonListener,
void OnHighlightedViewActivated();
void OnHighlightedViewClosed();
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
......@@ -310,6 +306,8 @@ class ASH_EXPORT OverviewItem : public views::ButtonListener,
// it visible while dragging around.
void StartDrag();
void CloseButtonPressed();
// TODO(sammiequon): Current events go from OverviewItemView to
// OverviewItem to OverviewSession to OverviewWindowDragController. We may be
// able to shorten this pipeline.
......
......@@ -102,8 +102,8 @@ void AnimateLayerOpacity(ui::Layer* layer, bool visible) {
// The close button for the overview item. It has a custom ink drop.
class OverviewCloseButton : public views::ImageButton {
public:
explicit OverviewCloseButton(views::ButtonListener* listener)
: views::ImageButton(listener) {
explicit OverviewCloseButton(PressedCallback callback)
: views::ImageButton(std::move(callback)) {
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
......@@ -152,9 +152,11 @@ class OverviewCloseButton : public views::ImageButton {
} // namespace
OverviewItemView::OverviewItemView(OverviewItem* overview_item,
aura::Window* window,
bool show_preview)
OverviewItemView::OverviewItemView(
OverviewItem* overview_item,
views::Button::PressedCallback close_callback,
aura::Window* window,
bool show_preview)
: WindowMiniView(window), overview_item_(overview_item) {
DCHECK(overview_item_);
// This should not be focusable. It's also to avoid accessibility error when
......@@ -162,7 +164,7 @@ OverviewItemView::OverviewItemView(OverviewItem* overview_item,
SetFocusBehavior(FocusBehavior::NEVER);
close_button_ = header_view()->AddChildView(
std::make_unique<OverviewCloseButton>(overview_item_));
std::make_unique<OverviewCloseButton>(std::move(close_callback)));
close_button_->SetPaintToLayer();
close_button_->layer()->SetFillsBoundsOpaquely(false);
// The button's image may be larger than |kHeaderHeightDp| due to added
......
......@@ -8,6 +8,7 @@
#include "ash/wm/overview/overview_highlight_controller.h"
#include "ash/wm/window_mini_view.h"
#include "base/macros.h"
#include "ui/views/controls/button/button.h"
namespace aura {
class Window;
......@@ -37,6 +38,7 @@ class ASH_EXPORT OverviewItemView
// If |show_preview| is true, this class will contain a child view which
// mirrors |window|.
OverviewItemView(OverviewItem* overview_item,
views::Button::PressedCallback close_callback,
aura::Window* window,
bool show_preview);
~OverviewItemView() override;
......
......@@ -94,7 +94,9 @@ TestChildModalParent::TestChildModalParent(aura::Window* context)
base::ASCIIToUTF16("modal parent window"));
modal_parent_->GetNativeView()->SetName("ModalParent");
auto button = std::make_unique<views::MdTextButton>(
this, base::ASCIIToUTF16("Show/Hide Child Modal Window"));
base::BindRepeating(&TestChildModalParent::ButtonPressed,
base::Unretained(this)),
base::ASCIIToUTF16("Show/Hide Child Modal Window"));
button_ = AddChildView(std::move(button));
AddChildView(textfield_);
AddChildView(host_);
......@@ -134,18 +136,16 @@ void TestChildModalParent::AddedToWidget() {
GetWidget()->GetNativeView()->SetName("Parent");
}
void TestChildModalParent::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK_EQ(sender, button_);
if (!modal_child_)
ShowModalChild();
else
modal_child_->Close();
}
void TestChildModalParent::OnWidgetDestroying(Widget* widget) {
DCHECK_EQ(modal_child_, widget);
modal_child_ = nullptr;
}
void TestChildModalParent::ButtonPressed() {
if (modal_child_)
modal_child_->Close();
else
ShowModalChild();
}
} // namespace ash
......@@ -23,7 +23,6 @@ namespace ash {
// Test window that can act as a parent for modal child windows.
class TestChildModalParent : public views::WidgetDelegateView,
public views::ButtonListener,
public views::WidgetObserver {
public:
// Create and show a top-level window that hosts a modal parent. Returns the
......@@ -44,12 +43,11 @@ class TestChildModalParent : public views::WidgetDelegateView,
void Layout() override;
void AddedToWidget() override;
// Overridden from ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overridden from WidgetObserver:
void OnWidgetDestroying(views::Widget* widget) override;
void ButtonPressed();
// The widget for the modal parent, a child of TestChildModalParent's Widget.
std::unique_ptr<views::Widget> modal_parent_;
......
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