Skip to content

Commit 01e15ee

Browse files
mohsenCommit bot
authored andcommitted
Add MD ink drop ripple to app list button
This also needed following changes: - Add AppListPresenter::IsVisible() (plus all necessary plumbing) to be able to determine whether pressing app list button is going to show or hide the app list; - Modify InkDropHostView::SetHasInkDrop() to get a 3-valued enum instead of a bool which lets us disable default gesture handling for ink drops; - Modify CustomButton to not reshow pending ink drop when mouse is dragged back onto the button if the button is notify-on-press. BUG=612567 Review-Url: https://codereview.chromium.org/2070143003 Cr-Commit-Position: refs/heads/master@{#403459}
1 parent 689f412 commit 01e15ee

37 files changed

+673
-180
lines changed

ash/app_list/app_list_presenter_delegate.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ash/display/window_tree_host_manager.h"
1212
#include "ash/root_window_controller.h"
1313
#include "ash/screen_util.h"
14+
#include "ash/shelf/app_list_button.h"
1415
#include "ash/shelf/shelf.h"
1516
#include "ash/shelf/shelf_layout_manager.h"
1617
#include "ash/shell.h"
@@ -152,8 +153,8 @@ void AppListPresenterDelegate::Init(app_list::AppListView* view,
152153
->GetRootWindowForDisplayId(display_id);
153154
aura::Window* container = GetRootWindowController(root_window)
154155
->GetContainer(kShellWindowId_AppListContainer);
155-
views::View* applist_button =
156-
Shelf::ForWindow(container)->GetAppListButtonView();
156+
AppListButton* applist_button =
157+
Shelf::ForWindow(container)->GetAppListButton();
157158
is_centered_ = view->ShouldCenterWindow();
158159
bool is_fullscreen = IsFullscreenAppListEnabled() &&
159160
Shell::GetInstance()
@@ -181,10 +182,10 @@ void AppListPresenterDelegate::Init(app_list::AppListView* view,
181182
ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds);
182183
view->InitAsBubbleAttachedToAnchor(
183184
container, current_apps_page,
184-
Shelf::ForWindow(container)->GetAppListButtonView(),
185+
Shelf::ForWindow(container)->GetAppListButton(),
185186
GetAnchorPositionOffsetToShelf(
186187
applist_button_bounds,
187-
Shelf::ForWindow(container)->GetAppListButtonView()->GetWidget()),
188+
Shelf::ForWindow(container)->GetAppListButton()->GetWidget()),
188189
GetBubbleArrow(container), true /* border_accepts_events */);
189190
view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
190191
}
@@ -209,7 +210,7 @@ void AppListPresenterDelegate::OnShown(int64_t display_id) {
209210
aura::Window* root_window = Shell::GetInstance()
210211
->window_tree_host_manager()
211212
->GetRootWindowForDisplayId(display_id);
212-
Shelf::ForWindow(root_window)->GetAppListButtonView()->SchedulePaint();
213+
Shelf::ForWindow(root_window)->GetAppListButton()->OnAppListShown();
213214
}
214215

215216
void AppListPresenterDelegate::OnDismissed() {
@@ -226,8 +227,8 @@ void AppListPresenterDelegate::OnDismissed() {
226227

227228
// Update applist button status when app list visibility is changed.
228229
Shelf::ForWindow(view_->GetWidget()->GetNativeView())
229-
->GetAppListButtonView()
230-
->SchedulePaint();
230+
->GetAppListButton()
231+
->OnAppListDismissed();
231232
}
232233

233234
void AppListPresenterDelegate::UpdateBounds() {

ash/common/shelf/shelf_constants.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const int kShelfItemInset = 3;
1919
const SkColor kShelfBaseColor = SK_ColorBLACK;
2020
const SkColor kShelfButtonActivatedHighlightColor =
2121
SkColorSetA(SK_ColorWHITE, 100);
22+
const SkColor kShelfInkDropBaseColor = SK_ColorWHITE;
2223
const float kShelfInkDropVisibleOpacity = 0.2f;
2324
const SkColor kShelfIconColor = SK_ColorWHITE;
2425
const int kOverflowButtonSize = 32;

ash/common/shelf/shelf_constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ ASH_EXPORT extern const SkColor kShelfBaseColor;
6060
// using the material design ripple animation.
6161
ASH_EXPORT extern const SkColor kShelfButtonActivatedHighlightColor;
6262

63+
// Ink drop color for shelf items.
64+
extern const SkColor kShelfInkDropBaseColor;
65+
6366
// Opacity of the ink drop ripple for shelf items when the ripple is visible.
6467
extern const float kShelfInkDropVisibleOpacity;
6568

ash/first_run/first_run_helper_impl.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ash/first_run/first_run_helper_impl.h"
66

77
#include "ash/common/shell_window_ids.h"
8+
#include "ash/shelf/app_list_button.h"
89
#include "ash/shelf/shelf.h"
910
#include "ash/shell.h"
1011
#include "ash/system/tray/system_tray.h"
@@ -53,7 +54,7 @@ views::Widget* FirstRunHelperImpl::GetOverlayWidget() {
5354

5455
gfx::Rect FirstRunHelperImpl::GetAppListButtonBounds() {
5556
Shelf* shelf = Shelf::ForPrimaryDisplay();
56-
views::View* app_button = shelf->GetAppListButtonView();
57+
AppListButton* app_button = shelf->GetAppListButton();
5758
return app_button->GetBoundsInScreen();
5859
}
5960

ash/shelf/app_list_button.cc

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ui/gfx/canvas.h"
2727
#include "ui/gfx/paint_vector_icon.h"
2828
#include "ui/gfx/vector_icons_public.h"
29+
#include "ui/views/animation/square_ink_drop_ripple.h"
2930
#include "ui/views/painter.h"
3031

3132
namespace ash {
@@ -36,6 +37,11 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
3637
draw_background_as_active_(false),
3738
listener_(listener),
3839
shelf_view_(shelf_view) {
40+
if (ash::MaterialDesignController::IsShelfMaterial()) {
41+
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
42+
set_ink_drop_base_color(kShelfInkDropBaseColor);
43+
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
44+
}
3945
SetAccessibleName(
4046
app_list::switches::IsExperimentalAppListEnabled()
4147
? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
@@ -49,6 +55,14 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
4955

5056
AppListButton::~AppListButton() {}
5157

58+
void AppListButton::OnAppListShown() {
59+
AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr);
60+
}
61+
62+
void AppListButton::OnAppListDismissed() {
63+
AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr);
64+
}
65+
5266
bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
5367
ImageButton::OnMousePressed(event);
5468
shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event);
@@ -72,10 +86,15 @@ bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) {
7286
}
7387

7488
void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
89+
const bool is_material = ash::MaterialDesignController::IsShelfMaterial();
90+
const bool touch_feedback =
91+
!is_material && switches::IsTouchFeedbackEnabled();
7592
switch (event->type()) {
7693
case ui::ET_GESTURE_SCROLL_BEGIN:
77-
if (switches::IsTouchFeedbackEnabled())
94+
if (touch_feedback)
7895
SetDrawBackgroundAsActive(false);
96+
else if (is_material)
97+
AnimateInkDrop(views::InkDropState::HIDDEN, event);
7998
shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event);
8099
event->SetHandled();
81100
return;
@@ -89,13 +108,15 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
89108
event->SetHandled();
90109
return;
91110
case ui::ET_GESTURE_TAP_DOWN:
92-
if (switches::IsTouchFeedbackEnabled())
111+
if (touch_feedback)
93112
SetDrawBackgroundAsActive(true);
113+
else if (is_material && !Shell::GetInstance()->IsApplistVisible())
114+
AnimateInkDrop(views::InkDropState::ACTION_PENDING, event);
94115
ImageButton::OnGestureEvent(event);
95116
break;
96117
case ui::ET_GESTURE_TAP_CANCEL:
97118
case ui::ET_GESTURE_TAP:
98-
if (switches::IsTouchFeedbackEnabled())
119+
if (touch_feedback)
99120
SetDrawBackgroundAsActive(false);
100121
ImageButton::OnGestureEvent(event);
101122
break;
@@ -143,16 +164,8 @@ void AppListButton::PaintBackgroundMD(gfx::Canvas* canvas) {
143164
gfx::Point circle_center = GetContentsBounds().CenterPoint();
144165
if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment()))
145166
circle_center = gfx::Point(circle_center.y(), circle_center.x());
146-
canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint);
147167

148-
if (Shell::GetInstance()->GetAppListTargetVisibility() ||
149-
draw_background_as_active_) {
150-
SkPaint highlight_paint;
151-
highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
152-
highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
153-
highlight_paint.setStyle(SkPaint::kFill_Style);
154-
canvas->DrawCircle(circle_center, kAppListButtonRadius, highlight_paint);
155-
}
168+
canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint);
156169
}
157170

158171
void AppListButton::PaintForegroundMD(gfx::Canvas* canvas,
@@ -234,12 +247,33 @@ void AppListButton::GetAccessibleState(ui::AXViewState* state) {
234247
state->name = shelf_view_->GetTitleForView(this);
235248
}
236249

250+
std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple()
251+
const {
252+
// TODO(mohsen): A circular SquareInkDropRipple is created with equal small
253+
// and large sizes to mimic a circular flood fill. Replace with an actual
254+
// flood fill when circular flood fills are implemented.
255+
gfx::Size ripple_size(2 * kAppListButtonRadius, 2 * kAppListButtonRadius);
256+
auto ink_drop_ripple = new views::SquareInkDropRipple(
257+
ripple_size, 0, ripple_size, 0, GetContentsBounds().CenterPoint(),
258+
GetInkDropBaseColor(), ink_drop_visible_opacity());
259+
ink_drop_ripple->set_activated_shape(views::SquareInkDropRipple::CIRCLE);
260+
return base::WrapUnique(ink_drop_ripple);
261+
}
262+
237263
void AppListButton::NotifyClick(const ui::Event& event) {
238264
ImageButton::NotifyClick(event);
239265
if (listener_)
240266
listener_->ButtonPressed(this, event, ink_drop());
241267
}
242268

269+
bool AppListButton::ShouldEnterPushedState(const ui::Event& event) {
270+
return !Shell::GetInstance()->IsApplistVisible();
271+
}
272+
273+
bool AppListButton::ShouldShowInkDropHighlight() const {
274+
return false;
275+
}
276+
243277
void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) {
244278
if (draw_background_as_active_ == draw_background_as_active)
245279
return;

ash/shelf/app_list_button.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef ASH_SHELF_APP_LIST_BUTTON_H_
66
#define ASH_SHELF_APP_LIST_BUTTON_H_
77

8+
#include "ash/ash_export.h"
89
#include "base/macros.h"
910
#include "ui/views/controls/button/image_button.h"
1011

@@ -13,12 +14,15 @@ class InkDropButtonListener;
1314
class ShelfView;
1415

1516
// Button used for the AppList icon on the shelf.
16-
class AppListButton : public views::ImageButton {
17+
class ASH_EXPORT AppListButton : public views::ImageButton {
1718
public:
1819
explicit AppListButton(InkDropButtonListener* listener,
1920
ShelfView* shelf_view);
2021
~AppListButton() override;
2122

23+
void OnAppListShown();
24+
void OnAppListDismissed();
25+
2226
bool draw_background_as_active() { return draw_background_as_active_; }
2327

2428
protected:
@@ -29,7 +33,10 @@ class AppListButton : public views::ImageButton {
2933
bool OnMouseDragged(const ui::MouseEvent& event) override;
3034
void OnPaint(gfx::Canvas* canvas) override;
3135
void GetAccessibleState(ui::AXViewState* state) override;
36+
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
3237
void NotifyClick(const ui::Event& event) override;
38+
bool ShouldEnterPushedState(const ui::Event& event) override;
39+
bool ShouldShowInkDropHighlight() const override;
3340

3441
// ui::EventHandler overrides:
3542
void OnGestureEvent(ui::GestureEvent* event) override;

ash/shelf/shelf.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ void Shelf::SchedulePaint() {
180180
shelf_view_->SchedulePaintForAllButtons();
181181
}
182182

183-
views::View* Shelf::GetAppListButtonView() const {
184-
return shelf_view_->GetAppListButtonView();
183+
AppListButton* Shelf::GetAppListButton() const {
184+
return shelf_view_->GetAppListButton();
185185
}
186186

187187
void Shelf::LaunchAppIndexAt(int item_index) {

ash/shelf/shelf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class View;
3535
}
3636

3737
namespace ash {
38+
class AppListButton;
3839
class FocusCycler;
3940
class ShelfDelegate;
4041
class ShelfIconObserver;
@@ -132,7 +133,7 @@ class ASH_EXPORT Shelf {
132133

133134
void SchedulePaint();
134135

135-
views::View* GetAppListButtonView() const;
136+
AppListButton* GetAppListButton() const;
136137

137138
// Launch a 0-indexed shelf item in the shelf.
138139
// A negative index launches the last shelf item in the shelf.

ash/shelf/shelf_button.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const int kIndicatorCanvasScale = 5;
5555
const int kInkDropSmallSize = 48;
5656
const int kInkDropLargeSize = 60;
5757
const int kInkDropLargeCornerRadius = 4;
58-
const SkColor kInkDropBaseColor = SK_ColorWHITE;
5958

6059
// Paints an activity indicator on |canvas| whose |size| is specified in DIP.
6160
void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) {
@@ -256,8 +255,8 @@ ShelfButton::ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view)
256255
destroyed_flag_(nullptr) {
257256
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
258257
if (ash::MaterialDesignController::IsShelfMaterial()) {
259-
SetHasInkDrop(true);
260-
set_ink_drop_base_color(kInkDropBaseColor);
258+
SetInkDropMode(InkDropMode::ON);
259+
set_ink_drop_base_color(kShelfInkDropBaseColor);
261260
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
262261
}
263262

0 commit comments

Comments
 (0)