Commit 61978b11 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Refactor on ScrollArrowView

In this CL, ScrollArrowView inherits the ShelfButton. It improves the
code readability and also makes Shelf code coherent: in current code
base all of buttons in Shelf are ShelfButtons.

Bug: 973481
Change-Id: I73aab558948b4ef32f79fa6e4ce243e9eba269a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1772293Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690918}
parent 34880fe9
......@@ -61,8 +61,12 @@ class OverflowBubbleView::OverflowScrollArrowView : public ScrollArrowView {
public:
OverflowScrollArrowView(ArrowType arrow_type,
bool is_horizontal_alignment,
views::ButtonListener* button_lister)
: ScrollArrowView(arrow_type, is_horizontal_alignment, button_lister) {}
Shelf* shelf,
ShelfButtonDelegate* button_delegate)
: ScrollArrowView(arrow_type,
is_horizontal_alignment,
shelf,
button_delegate) {}
~OverflowScrollArrowView() override = default;
// views::View:
......@@ -241,11 +245,13 @@ OverflowBubbleView::OverflowBubbleView(ShelfView* shelf_view,
// Initialize the left arrow button.
left_arrow_ = AddChildView(std::make_unique<OverflowScrollArrowView>(
ScrollArrowView::kLeft, GetShelf()->IsHorizontalAlignment(), this));
ScrollArrowView::kLeft, GetShelf()->IsHorizontalAlignment(), GetShelf(),
this));
// Initialize the right arrow button.
right_arrow_ = AddChildView(std::make_unique<OverflowScrollArrowView>(
ScrollArrowView::kRight, GetShelf()->IsHorizontalAlignment(), this));
ScrollArrowView::kRight, GetShelf()->IsHorizontalAlignment(), GetShelf(),
this));
// Initialize the shelf container view.
shelf_container_view_ = AddChildView(
......@@ -550,8 +556,13 @@ const char* OverflowBubbleView::GetClassName() const {
return "OverflowBubbleView";
}
void OverflowBubbleView::OnShelfButtonAboutToRequestFocusFromTabTraversal(
ShelfButton* button,
bool reverse) {}
void OverflowBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
const ui::Event& event,
views::InkDrop* ink_drop) {
// Verfies that |sender| is either |left_arrow_| or |right_arrow_|.
views::View* sender_view = sender;
DCHECK((sender_view == left_arrow_) || (sender_view == right_arrow_));
......
......@@ -7,6 +7,7 @@
#include "ash/ash_export.h"
#include "ash/shelf/shelf_bubble.h"
#include "ash/shelf/shelf_button_delegate.h"
#include "base/macros.h"
#include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/controls/button/button.h"
......@@ -18,7 +19,7 @@ class ShelfView;
// OverflowBubbleView hosts a ShelfView to display overflown items.
// Exports to access this class from OverflowBubbleViewTestAPI.
class ASH_EXPORT OverflowBubbleView : public ShelfBubble,
public views::ButtonListener {
public ShelfButtonDelegate {
public:
enum LayoutStrategy {
// The arrow buttons are not shown. It means that there is enough space to
......@@ -108,8 +109,12 @@ class ASH_EXPORT OverflowBubbleView : public ShelfBubble,
bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
const char* GetClassName() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// ShelfButtonDelegate:
void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button,
bool reverse) override;
void ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) override;
// ui::EventHandler:
void OnScrollEvent(ui::ScrollEvent* event) override;
......
......@@ -5,6 +5,7 @@
#include "ash/shelf/scroll_arrow_view.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf_button_delegate.h"
#include "ash/shelf/shelf_constants.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h"
......@@ -19,17 +20,22 @@ namespace ash {
ScrollArrowView::ScrollArrowView(ArrowType arrow_type,
bool is_horizontal_alignment,
views::ButtonListener* button_listener)
: Button(button_listener),
Shelf* shelf,
ShelfButtonDelegate* shelf_button_delegate)
: ShelfButton(shelf, shelf_button_delegate),
arrow_type_(arrow_type),
is_horizontal_alignment_(is_horizontal_alignment) {
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
set_has_ink_drop_action_on_click(true);
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
}
ScrollArrowView::~ScrollArrowView() = default;
void ScrollArrowView::NotifyClick(const ui::Event& event) {
Button::NotifyClick(event);
shelf_button_delegate()->ButtonPressed(/*sender=*/this, event, GetInkDrop());
}
void ScrollArrowView::PaintButtonContents(gfx::Canvas* canvas) {
const bool show_left_arrow = (arrow_type_ == kLeft && !base::i18n::IsRTL()) ||
(arrow_type_ == kRight && base::i18n::IsRTL());
......@@ -52,12 +58,6 @@ const char* ScrollArrowView::GetClassName() const {
return "ScrollArrowView";
}
std::unique_ptr<views::InkDrop> ScrollArrowView::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
return std::move(ink_drop);
}
std::unique_ptr<views::InkDropMask> ScrollArrowView::CreateInkDropMask() const {
gfx::Point center_point = gfx::Rect(size()).CenterPoint();
return std::make_unique<views::CircleInkDropMask>(size(), center_point,
......
......@@ -6,28 +6,33 @@
#define ASH_SHELF_SCROLL_ARROW_VIEW_H_
#include "ash/ash_export.h"
#include "ui/views/controls/button/button.h"
#include "ash/shelf/shelf_button.h"
namespace ash {
class Shelf;
class ShelfButtonDelegate;
class ASH_EXPORT ScrollArrowView : public views::Button {
class ASH_EXPORT ScrollArrowView : public ShelfButton {
public:
enum ArrowType { kLeft, kRight };
ScrollArrowView(ArrowType arrow_type,
bool is_horizontal_alignment,
views::ButtonListener* button_listener);
Shelf* shelf,
ShelfButtonDelegate* button_listener);
~ScrollArrowView() override;
void set_is_horizontal_alignment(bool is_horizontal_alignment) {
is_horizontal_alignment_ = is_horizontal_alignment;
}
// views::Button:
void NotifyClick(const ui::Event& event) override;
// views::View:
void PaintButtonContents(gfx::Canvas* canvas) override;
const char* GetClassName() const override;
// views::InkDropHost:
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
......
......@@ -162,11 +162,13 @@ void ScrollableShelfView::Init() {
// Initialize the left arrow button.
left_arrow_ = AddChildView(std::make_unique<ScrollArrowView>(
ScrollArrowView::kLeft, GetShelf()->IsHorizontalAlignment(), this));
ScrollArrowView::kLeft, GetShelf()->IsHorizontalAlignment(), GetShelf(),
this));
// Initialize the right arrow button.
right_arrow_ = AddChildView(std::make_unique<ScrollArrowView>(
ScrollArrowView::kRight, GetShelf()->IsHorizontalAlignment(), this));
ScrollArrowView::kRight, GetShelf()->IsHorizontalAlignment(), GetShelf(),
this));
// Initialize the shelf container view.
shelf_container_view_ =
......@@ -401,8 +403,13 @@ const char* ScrollableShelfView::GetClassName() const {
return "ScrollableShelfView";
}
void ScrollableShelfView::OnShelfButtonAboutToRequestFocusFromTabTraversal(
ShelfButton* button,
bool reverse) {}
void ScrollableShelfView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
const ui::Event& event,
views::InkDrop* ink_drop) {
// Verfies that |sender| is either |left_arrow_| or |right_arrow_|.
views::View* sender_view = sender;
DCHECK((sender_view == left_arrow_) || (sender_view == right_arrow_));
......
......@@ -9,6 +9,7 @@
#include "ash/public/cpp/shelf_model.h"
#include "ash/shelf/scroll_arrow_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_button_delegate.h"
#include "ash/shelf/shelf_container_view.h"
#include "ash/shelf/shelf_view.h"
#include "ui/views/animation/ink_drop_host_view.h"
......@@ -18,7 +19,7 @@ namespace ash {
class ASH_EXPORT ScrollableShelfView : public views::View,
public ShellObserver,
public views::ButtonListener {
public ShelfButtonDelegate {
public:
enum LayoutStrategy {
// The arrow buttons are not shown. It means that there is enough space to
......@@ -97,8 +98,12 @@ class ASH_EXPORT ScrollableShelfView : public views::View,
void OnMouseEvent(ui::MouseEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// ShelfButtonDelegate:
void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button,
bool reverse) override;
void ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) override;
// Overridden from ShellObserver:
void OnShelfAlignmentChanged(aura::Window* root_window) 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