Commit 40f90812 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Refactor common shelf control logic into base class

Change-Id: If497956bc179864957dd21b8b88c8db354dd96af
Reviewed-on: https://chromium-review.googlesource.com/c/1325069Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606645}
parent e2eeedb8
...@@ -585,6 +585,8 @@ component("ash") { ...@@ -585,6 +585,8 @@ component("ash") {
"shelf/shelf_constants.h", "shelf/shelf_constants.h",
"shelf/shelf_context_menu_model.cc", "shelf/shelf_context_menu_model.cc",
"shelf/shelf_context_menu_model.h", "shelf/shelf_context_menu_model.h",
"shelf/shelf_control_button.cc",
"shelf/shelf_control_button.h",
"shelf/shelf_controller.cc", "shelf/shelf_controller.cc",
"shelf/shelf_controller.h", "shelf/shelf_controller.h",
"shelf/shelf_layout_manager.cc", "shelf/shelf_layout_manager.cc",
......
...@@ -65,7 +65,7 @@ bool IsHomeLauncherShown() { ...@@ -65,7 +65,7 @@ bool IsHomeLauncherShown() {
AppListButton::AppListButton(InkDropButtonListener* listener, AppListButton::AppListButton(InkDropButtonListener* listener,
ShelfView* shelf_view, ShelfView* shelf_view,
Shelf* shelf) Shelf* shelf)
: views::ImageButton(nullptr), : ShelfControlButton(),
listener_(listener), listener_(listener),
shelf_view_(shelf_view), shelf_view_(shelf_view),
shelf_(shelf), shelf_(shelf),
...@@ -79,14 +79,10 @@ AppListButton::AppListButton(InkDropButtonListener* listener, ...@@ -79,14 +79,10 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
mojom::VoiceInteractionObserverPtr ptr; mojom::VoiceInteractionObserverPtr ptr;
voice_interaction_binding_.Bind(mojo::MakeRequest(&ptr)); voice_interaction_binding_.Bind(mojo::MakeRequest(&ptr));
Shell::Get()->voice_interaction_controller()->AddObserver(std::move(ptr)); Shell::Get()->voice_interaction_controller()->AddObserver(std::move(ptr));
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
set_ink_drop_base_color(kShelfInkDropBaseColor);
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
SetAccessibleName( SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)); l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE));
SetSize(gfx::Size(kShelfControlSize, kShelfControlSize));
SetFocusPainter(TrayPopupUtils::CreateFocusPainter());
set_notify_action(Button::NOTIFY_ON_PRESS); set_notify_action(Button::NOTIFY_ON_PRESS);
set_has_ink_drop_action_on_click(false);
// Initialize voice interaction overlay and sync the flags if active user // Initialize voice interaction overlay and sync the flags if active user
// session has already started. This could happen when an external monitor // session has already started. This could happen when an external monitor
...@@ -213,7 +209,7 @@ void AppListButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -213,7 +209,7 @@ void AppListButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple() std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple()
const { const {
const int app_list_button_radius = ShelfConstants::app_list_button_radius(); const int app_list_button_radius = ShelfConstants::control_border_radius();
gfx::Point center = GetCenterPoint(); gfx::Point center = GetCenterPoint();
gfx::Rect bounds(center.x() - app_list_button_radius, gfx::Rect bounds(center.x() - app_list_button_radius,
center.y() - app_list_button_radius, center.y() - app_list_button_radius,
...@@ -247,7 +243,7 @@ std::unique_ptr<views::InkDrop> AppListButton::CreateInkDrop() { ...@@ -247,7 +243,7 @@ std::unique_ptr<views::InkDrop> AppListButton::CreateInkDrop() {
std::unique_ptr<views::InkDropMask> AppListButton::CreateInkDropMask() const { std::unique_ptr<views::InkDropMask> AppListButton::CreateInkDropMask() const {
return std::make_unique<views::CircleInkDropMask>( return std::make_unique<views::CircleInkDropMask>(
size(), GetCenterPoint(), ShelfConstants::app_list_button_radius()); size(), GetCenterPoint(), ShelfConstants::control_border_radius());
} }
void AppListButton::PaintButtonContents(gfx::Canvas* canvas) { void AppListButton::PaintButtonContents(gfx::Canvas* canvas) {
...@@ -299,27 +295,6 @@ void AppListButton::PaintButtonContents(gfx::Canvas* canvas) { ...@@ -299,27 +295,6 @@ void AppListButton::PaintButtonContents(gfx::Canvas* canvas) {
} }
} }
gfx::Point AppListButton::GetCenterPoint() const {
// For a bottom-aligned shelf, the button bounds could have a larger height
// than width (in the case of touch-dragging the shelf upwards) or a larger
// width than height (in the case of a shelf hide/show animation), so adjust
// the y-position of the circle's center to ensure correct layout. Similarly
// adjust the x-position for a left- or right-aligned shelf.
const int x_mid = width() / 2.f;
const int y_mid = height() / 2.f;
const ShelfAlignment alignment = shelf_->alignment();
if (alignment == SHELF_ALIGNMENT_BOTTOM ||
alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) {
return gfx::Point(x_mid, x_mid);
} else if (alignment == SHELF_ALIGNMENT_RIGHT) {
return gfx::Point(y_mid, y_mid);
} else {
DCHECK_EQ(alignment, SHELF_ALIGNMENT_LEFT);
return gfx::Point(width() - y_mid, y_mid);
}
}
void AppListButton::OnAppListVisibilityChanged(bool shown, void AppListButton::OnAppListVisibilityChanged(bool shown,
aura::Window* root_window) { aura::Window* root_window) {
aura::Window* window = GetWidget() ? GetWidget()->GetNativeWindow() : nullptr; aura::Window* window = GetWidget() ? GetWidget()->GetNativeWindow() : nullptr;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/public/cpp/assistant/default_voice_interaction_observer.h" #include "ash/public/cpp/assistant/default_voice_interaction_observer.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h" #include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "ash/session/session_observer.h" #include "ash/session/session_observer.h"
#include "ash/shelf/shelf_control_button.h"
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
...@@ -29,7 +30,7 @@ class Shelf; ...@@ -29,7 +30,7 @@ class Shelf;
class ShelfView; class ShelfView;
// Button used for the AppList icon on the shelf. // Button used for the AppList icon on the shelf.
class ASH_EXPORT AppListButton : public views::ImageButton, class ASH_EXPORT AppListButton : public ShelfControlButton,
public ShellObserver, public ShellObserver,
public SessionObserver, public SessionObserver,
public DefaultVoiceInteractionObserver { public DefaultVoiceInteractionObserver {
...@@ -47,10 +48,6 @@ class ASH_EXPORT AppListButton : public views::ImageButton, ...@@ -47,10 +48,6 @@ class ASH_EXPORT AppListButton : public views::ImageButton,
// views::ImageButton: // views::ImageButton:
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
// Get the center point of the app list button circle used to draw its
// background and ink drops.
gfx::Point GetCenterPoint() const;
protected: protected:
// views::ImageButton: // views::ImageButton:
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
......
...@@ -27,27 +27,12 @@ ...@@ -27,27 +27,12 @@
namespace ash { namespace ash {
BackButton::BackButton() : views::ImageButton(nullptr) { BackButton::BackButton() : ShelfControlButton() {
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
set_has_ink_drop_action_on_click(true);
set_ink_drop_base_color(kShelfInkDropBaseColor);
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_BACK_BUTTON_TITLE)); SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_BACK_BUTTON_TITLE));
SetSize(gfx::Size(kShelfControlSize, kShelfControlSize));
SetFocusPainter(TrayPopupUtils::CreateFocusPainter());
} }
BackButton::~BackButton() = default; BackButton::~BackButton() = default;
gfx::Point BackButton::GetCenterPoint() const {
// The button bounds could have a larger height than width (in the case of
// touch-dragging the shelf upwards) or a larger width than height (in the
// case of a shelf hide/show animation), so adjust the y-position of the
// button's center to ensure correct layout.
return gfx::Point(width() / 2.f, width() / 2.f);
}
void BackButton::OnGestureEvent(ui::GestureEvent* event) { void BackButton::OnGestureEvent(ui::GestureEvent* event) {
ImageButton::OnGestureEvent(event); ImageButton::OnGestureEvent(event);
if (event->type() == ui::ET_GESTURE_TAP || if (event->type() == ui::ET_GESTURE_TAP ||
...@@ -67,27 +52,6 @@ void BackButton::OnMouseReleased(const ui::MouseEvent& event) { ...@@ -67,27 +52,6 @@ void BackButton::OnMouseReleased(const ui::MouseEvent& event) {
GenerateAndSendBackEvent(event.type()); GenerateAndSendBackEvent(event.type());
} }
std::unique_ptr<views::InkDropRipple> BackButton::CreateInkDropRipple() const {
return std::make_unique<views::FloodFillInkDropRipple>(
size(),
gfx::Insets(ShelfConstants::button_size() / 2 -
ShelfConstants::app_list_button_radius()),
GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
ink_drop_visible_opacity());
}
std::unique_ptr<views::InkDrop> BackButton::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop =
Button::CreateDefaultInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
return std::move(ink_drop);
}
std::unique_ptr<views::InkDropMask> BackButton::CreateInkDropMask() const {
return std::make_unique<views::CircleInkDropMask>(
size(), GetCenterPoint(), ShelfConstants::app_list_button_radius());
}
void BackButton::PaintButtonContents(gfx::Canvas* canvas) { void BackButton::PaintButtonContents(gfx::Canvas* canvas) {
// Use PaintButtonContents instead of SetImage so the icon gets drawn at // Use PaintButtonContents instead of SetImage so the icon gets drawn at
// |GetCenterPoint| coordinates instead of always in the center. // |GetCenterPoint| coordinates instead of always in the center.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/shelf_control_button.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
...@@ -16,23 +17,16 @@ namespace ash { ...@@ -16,23 +17,16 @@ namespace ash {
// The back button shown on the shelf when tablet mode is enabled. Its opacity // The back button shown on the shelf when tablet mode is enabled. Its opacity
// and visiblity are handled by its parent, ShelfView, to ensure the fade // and visiblity are handled by its parent, ShelfView, to ensure the fade
// in/out of the icon matches the movement of ShelfView's items. // in/out of the icon matches the movement of ShelfView's items.
class ASH_EXPORT BackButton : public views::ImageButton { class ASH_EXPORT BackButton : public ShelfControlButton {
public: public:
BackButton(); BackButton();
~BackButton() override; ~BackButton() override;
// Get the center point of the back button used to draw its background and ink
// drops.
gfx::Point GetCenterPoint() const;
protected: protected:
// views::ImageButton: // views::ImageButton:
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
void PaintButtonContents(gfx::Canvas* canvas) override; void PaintButtonContents(gfx::Canvas* canvas) override;
private: private:
......
...@@ -17,24 +17,15 @@ ...@@ -17,24 +17,15 @@
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/skbitmap_operations.h" #include "ui/gfx/skbitmap_operations.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
namespace ash { namespace ash {
OverflowButton::OverflowButton(ShelfView* shelf_view, Shelf* shelf) OverflowButton::OverflowButton(ShelfView* shelf_view, Shelf* shelf)
: Button(nullptr), : ShelfControlButton(), shelf_view_(shelf_view), shelf_(shelf) {
shelf_view_(shelf_view),
shelf_(shelf),
background_color_(kShelfDefaultBaseColor) {
DCHECK(shelf_view_); DCHECK(shelf_view_);
SetInkDropMode(InkDropMode::ON);
set_ink_drop_base_color(kShelfInkDropBaseColor);
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
set_hide_ink_drop_when_showing_context_menu(false); set_hide_ink_drop_when_showing_context_menu(false);
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
...@@ -44,28 +35,11 @@ OverflowButton::OverflowButton(ShelfView* shelf_view, Shelf* shelf) ...@@ -44,28 +35,11 @@ OverflowButton::OverflowButton(ShelfView* shelf_view, Shelf* shelf)
horizontal_dots_image_view_->SetImage( horizontal_dots_image_view_->SetImage(
gfx::CreateVectorIcon(kShelfOverflowHorizontalDotsIcon, kShelfIconColor)); gfx::CreateVectorIcon(kShelfOverflowHorizontalDotsIcon, kShelfIconColor));
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
background_color_ = kShelfControlPermanentHighlightBackground;
AddChildView(horizontal_dots_image_view_); AddChildView(horizontal_dots_image_view_);
} }
OverflowButton::~OverflowButton() = default; OverflowButton::~OverflowButton() = default;
std::unique_ptr<views::InkDrop> OverflowButton::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop =
CreateDefaultFloodFillInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
ink_drop->SetAutoHighlightMode(views::InkDropImpl::AutoHighlightMode::NONE);
return std::move(ink_drop);
}
std::unique_ptr<views::InkDropRipple> OverflowButton::CreateInkDropRipple()
const {
gfx::Insets insets = GetLocalBounds().InsetsFrom(CalculateButtonBounds());
return std::make_unique<views::FloodFillInkDropRipple>(
size(), insets, GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
ink_drop_visible_opacity());
}
bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) { bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) {
if (shelf_view_->IsShowingOverflowBubble()) if (shelf_view_->IsShowingOverflowBubble())
return false; return false;
...@@ -74,14 +48,7 @@ bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) { ...@@ -74,14 +48,7 @@ bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) {
} }
void OverflowButton::NotifyClick(const ui::Event& event) { void OverflowButton::NotifyClick(const ui::Event& event) {
Button::NotifyClick(event); shelf_view_->ButtonPressed(this, event, nullptr);
shelf_view_->ButtonPressed(this, event, GetInkDrop());
}
std::unique_ptr<views::InkDropMask> OverflowButton::CreateInkDropMask() const {
gfx::Insets insets = GetLocalBounds().InsetsFrom(CalculateButtonBounds());
return std::make_unique<views::RoundRectInkDropMask>(
size(), insets, ShelfConstants::overflow_button_corner_radius());
} }
void OverflowButton::PaintButtonContents(gfx::Canvas* canvas) { void OverflowButton::PaintButtonContents(gfx::Canvas* canvas) {
...@@ -89,27 +56,17 @@ void OverflowButton::PaintButtonContents(gfx::Canvas* canvas) { ...@@ -89,27 +56,17 @@ void OverflowButton::PaintButtonContents(gfx::Canvas* canvas) {
PaintBackground(canvas, bounds); PaintBackground(canvas, bounds);
} }
void OverflowButton::PaintBackground(gfx::Canvas* canvas,
const gfx::Rect& bounds) {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(background_color_);
canvas->DrawRoundRect(bounds, ShelfConstants::overflow_button_corner_radius(),
flags);
}
gfx::Rect OverflowButton::CalculateButtonBounds() const { gfx::Rect OverflowButton::CalculateButtonBounds() const {
const int overflow_button_size = ShelfConstants::overflow_button_size();
ShelfAlignment alignment = shelf_->alignment(); ShelfAlignment alignment = shelf_->alignment();
gfx::Rect content_bounds = GetContentsBounds(); gfx::Rect content_bounds = GetContentsBounds();
// Align the button to the top of a bottom-aligned shelf, to the right edge // Align the button to the top of a bottom-aligned shelf, to the right edge
// a left-aligned shelf, and to the left edge of a right-aligned shelf. // a left-aligned shelf, and to the left edge of a right-aligned shelf.
const int inset = (ShelfConstants::shelf_size() - overflow_button_size) / 2; const int inset = (ShelfConstants::shelf_size() - kShelfControlSize) / 2;
const int x = alignment == SHELF_ALIGNMENT_LEFT const int x = alignment == SHELF_ALIGNMENT_LEFT
? content_bounds.right() - inset - overflow_button_size ? content_bounds.right() - inset - kShelfControlSize
: content_bounds.x() + inset; : content_bounds.x() + inset;
return gfx::Rect(x, content_bounds.y() + inset, overflow_button_size, return gfx::Rect(x, content_bounds.y() + inset, kShelfControlSize,
overflow_button_size); kShelfControlSize);
} }
} // namespace ash } // namespace ash
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define ASH_SHELF_OVERFLOW_BUTTON_H_ #define ASH_SHELF_OVERFLOW_BUTTON_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/shelf_control_button.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
...@@ -21,7 +22,7 @@ class Shelf; ...@@ -21,7 +22,7 @@ class Shelf;
class ShelfView; class ShelfView;
// Shelf overflow button. // Shelf overflow button.
class ASH_EXPORT OverflowButton : public views::Button { class ASH_EXPORT OverflowButton : public ShelfControlButton {
public: public:
// |shelf_view| is the view containing this button. // |shelf_view| is the view containing this button.
OverflowButton(ShelfView* shelf_view, Shelf* shelf); OverflowButton(ShelfView* shelf_view, Shelf* shelf);
...@@ -31,30 +32,19 @@ class ASH_EXPORT OverflowButton : public views::Button { ...@@ -31,30 +32,19 @@ class ASH_EXPORT OverflowButton : public views::Button {
friend class OverflowButtonTestApi; friend class OverflowButtonTestApi;
// views::Button: // views::Button:
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
bool ShouldEnterPushedState(const ui::Event& event) override; bool ShouldEnterPushedState(const ui::Event& event) override;
void NotifyClick(const ui::Event& event) override; void NotifyClick(const ui::Event& event) override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
void PaintButtonContents(gfx::Canvas* canvas) override; void PaintButtonContents(gfx::Canvas* canvas) override;
// Helper function to paint the background of the button at |bounds|. // Calculates the bounds of the control button based on the shelf alignment.
void PaintBackground(gfx::Canvas* canvas, const gfx::Rect& bounds);
// Calculates the bounds of the overflow button based on the shelf alignment
// and overflow shelf visibility.
gfx::Rect CalculateButtonBounds() const; gfx::Rect CalculateButtonBounds() const;
// The icon in the new UI: horizontal dots.
const gfx::ImageSkia horizontal_dots_image_; const gfx::ImageSkia horizontal_dots_image_;
views::ImageView* horizontal_dots_image_view_; views::ImageView* horizontal_dots_image_view_;
ShelfView* shelf_view_; ShelfView* shelf_view_;
Shelf* shelf_; Shelf* shelf_;
// Color used to paint the background.
SkColor background_color_;
DISALLOW_COPY_AND_ASSIGN(OverflowButton); DISALLOW_COPY_AND_ASSIGN(OverflowButton);
}; };
......
...@@ -108,17 +108,6 @@ class ShelfConstants { ...@@ -108,17 +108,6 @@ class ShelfConstants {
// Size of the icons within shelf buttons. // Size of the icons within shelf buttons.
static int button_icon_size() { return kShelfButtonIconSize; } static int button_icon_size() { return kShelfButtonIconSize; }
// The width and height of the material design overflow button.
static int overflow_button_size() { return kShelfControlSize; }
// The radius of the rounded corners of the overflow button.
static int overflow_button_corner_radius() {
return overflow_button_size() / 2;
}
// The radius of the circular material design app list button.
static int app_list_button_radius() { return control_border_radius(); }
// The radius of shelf control buttons. // The radius of shelf control buttons.
static int control_border_radius() { return kShelfControlSize / 2; } static int control_border_radius() { return kShelfControlSize / 2; }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_control_button.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/widget/widget.h"
namespace ash {
ShelfControlButton::ShelfControlButton() : views::ImageButton(nullptr) {
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
set_has_ink_drop_action_on_click(true);
set_ink_drop_base_color(kShelfInkDropBaseColor);
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
SetSize(gfx::Size(kShelfControlSize, kShelfControlSize));
SetFocusPainter(TrayPopupUtils::CreateFocusPainter());
}
ShelfControlButton::~ShelfControlButton() = default;
gfx::Point ShelfControlButton::GetCenterPoint() const {
return gfx::Point(width() / 2.f, width() / 2.f);
}
std::unique_ptr<views::InkDropRipple> ShelfControlButton::CreateInkDropRipple()
const {
return std::make_unique<views::FloodFillInkDropRipple>(
size(),
gfx::Insets(ShelfConstants::button_size() / 2 -
ShelfConstants::control_border_radius()),
GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
ink_drop_visible_opacity());
}
std::unique_ptr<views::InkDrop> ShelfControlButton::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop =
Button::CreateDefaultInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
return std::move(ink_drop);
}
std::unique_ptr<views::InkDropMask> ShelfControlButton::CreateInkDropMask()
const {
return std::make_unique<views::CircleInkDropMask>(
size(), GetCenterPoint(), ShelfConstants::control_border_radius());
}
void ShelfControlButton::PaintBackground(gfx::Canvas* canvas,
const gfx::Rect& bounds) {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(kShelfControlPermanentHighlightBackground);
canvas->DrawRoundRect(bounds, ShelfConstants::control_border_radius(), flags);
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_SHELF_CONTROL_BUTTON_H_
#define ASH_SHELF_SHELF_CONTROL_BUTTON_H_
#include <memory>
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/views/controls/button/image_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 {
public:
ShelfControlButton();
~ShelfControlButton() override;
// Get the center point of the button used to draw its background and ink
// drops.
gfx::Point GetCenterPoint() const;
protected:
// views::ImageButton:
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
void PaintBackground(gfx::Canvas* canvas, const gfx::Rect& bounds);
DISALLOW_COPY_AND_ASSIGN(ShelfControlButton);
};
} // namespace ash
#endif // ASH_SHELF_SHELF_CONTROL_BUTTON_H_
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