Commit f23588bc authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS shelf: make control buttons inherit from Button, not ImageButton

This is the first step of an effort to de-duplicate some code between
ShelfButton, AppListButton, BackButton, ShelfControlButton.

This makes the class inheritance of ShelfControlButton a lot closer to
ShelfButton. None of the functionality of ImageButton is used anyway,
so inheriting from plain Button directly makes more sense.

Bug: 714781
Change-Id: I20cdc87b39a82ea70813ca7492df79890a255126
Reviewed-on: https://chromium-review.googlesource.com/c/1395565Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619992}
parent 3976fa0c
......@@ -124,10 +124,10 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
if (!Shell::Get()->app_list_controller()->IsVisible() || IsTabletMode())
AnimateInkDrop(views::InkDropState::ACTION_TRIGGERED, event);
ImageButton::OnGestureEvent(event);
Button::OnGestureEvent(event);
return;
case ui::ET_GESTURE_TAP_DOWN:
// If |!ShouldEnterPushedState|, ImageButton::OnGestureEvent will not set
// If |!ShouldEnterPushedState|, Button::OnGestureEvent will not set
// the event to be handled. This will cause the |ET_GESTURE_TAP| or
// |ET_GESTURE_TAP_CANCEL| not to be sent to |app_list_button|, therefore
// leaving the assistant overlay ripple stays visible.
......@@ -145,7 +145,7 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
if (!Shell::Get()->app_list_controller()->IsVisible() || IsTabletMode())
AnimateInkDrop(views::InkDropState::ACTION_PENDING, event);
ImageButton::OnGestureEvent(event);
Button::OnGestureEvent(event);
// If assistant overlay animation starts, we need to make sure the event
// is handled in order to end the animation in |ET_GESTURE_TAP| or
// |ET_GESTURE_TAP_CANCEL|.
......@@ -166,7 +166,7 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
Shell::Get()->app_list_controller()->StartVoiceInteractionSession();
}
} else {
ImageButton::OnGestureEvent(event);
Button::OnGestureEvent(event);
}
return;
case ui::ET_GESTURE_LONG_TAP:
......@@ -177,33 +177,33 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
AnimateInkDrop(views::InkDropState::HIDDEN, event);
event->SetHandled();
} else {
ImageButton::OnGestureEvent(event);
Button::OnGestureEvent(event);
}
return;
default:
ImageButton::OnGestureEvent(event);
Button::OnGestureEvent(event);
return;
}
}
bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
ImageButton::OnMousePressed(event);
Button::OnMousePressed(event);
shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event);
return true;
}
void AppListButton::OnMouseReleased(const ui::MouseEvent& event) {
ImageButton::OnMouseReleased(event);
Button::OnMouseReleased(event);
shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false);
}
void AppListButton::OnMouseCaptureLost() {
shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true);
ImageButton::OnMouseCaptureLost();
Button::OnMouseCaptureLost();
}
bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) {
ImageButton::OnMouseDragged(event);
Button::OnMouseDragged(event);
shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event);
return true;
}
......@@ -227,7 +227,7 @@ std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple()
}
void AppListButton::NotifyClick(const ui::Event& event) {
ImageButton::NotifyClick(event);
Button::NotifyClick(event);
if (listener_)
listener_->ButtonPressed(this, event, GetInkDrop());
}
......@@ -235,7 +235,7 @@ void AppListButton::NotifyClick(const ui::Event& event) {
bool AppListButton::ShouldEnterPushedState(const ui::Event& event) {
if (!shelf_view_->ShouldEventActivateButton(this, event))
return false;
return views::ImageButton::ShouldEnterPushedState(event);
return views::Button::ShouldEnterPushedState(event);
}
std::unique_ptr<views::InkDrop> AppListButton::CreateInkDrop() {
......
......@@ -15,7 +15,6 @@
#include "ash/shell_observer.h"
#include "base/macros.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/views/controls/button/image_button.h"
namespace base {
class OneShotTimer;
......
......@@ -34,7 +34,7 @@ BackButton::BackButton() : ShelfControlButton() {
BackButton::~BackButton() = default;
void BackButton::OnGestureEvent(ui::GestureEvent* event) {
ImageButton::OnGestureEvent(event);
Button::OnGestureEvent(event);
if (event->type() == ui::ET_GESTURE_TAP ||
event->type() == ui::ET_GESTURE_TAP_DOWN) {
GenerateAndSendBackEvent(event->type());
......@@ -42,13 +42,13 @@ void BackButton::OnGestureEvent(ui::GestureEvent* event) {
}
bool BackButton::OnMousePressed(const ui::MouseEvent& event) {
ImageButton::OnMousePressed(event);
Button::OnMousePressed(event);
GenerateAndSendBackEvent(event.type());
return true;
}
void BackButton::OnMouseReleased(const ui::MouseEvent& event) {
ImageButton::OnMouseReleased(event);
Button::OnMouseReleased(event);
GenerateAndSendBackEvent(event.type());
}
......
......@@ -10,7 +10,6 @@
#include "ash/ash_export.h"
#include "ash/shelf/shelf_control_button.h"
#include "base/macros.h"
#include "ui/views/controls/button/image_button.h"
namespace ash {
......@@ -23,7 +22,7 @@ class ASH_EXPORT BackButton : public ShelfControlButton {
~BackButton() override;
protected:
// views::ImageButton:
// views::Button:
void OnGestureEvent(ui::GestureEvent* event) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
......
......@@ -17,7 +17,7 @@
namespace ash {
ShelfControlButton::ShelfControlButton() : views::ImageButton(nullptr) {
ShelfControlButton::ShelfControlButton() : views::Button(nullptr) {
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
set_has_ink_drop_action_on_click(true);
set_ink_drop_base_color(kShelfInkDropBaseColor);
......
......@@ -9,13 +9,13 @@
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/button.h"
namespace ash {
// Base class for controls shown on the shelf that are not app shortcuts, such
// as the app list, back, and overflow buttons.
class ASH_EXPORT ShelfControlButton : public views::ImageButton {
class ASH_EXPORT ShelfControlButton : public views::Button {
public:
ShelfControlButton();
~ShelfControlButton() override;
......@@ -25,7 +25,7 @@ class ASH_EXPORT ShelfControlButton : public views::ImageButton {
gfx::Point GetCenterPoint() const;
protected:
// views::ImageButton:
// views::Button:
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const 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