Skip to content

Commit

Permalink
Add MD ink drop ripple to app list button
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
mohsen authored and Commit bot committed Jul 1, 2016
1 parent 689f412 commit 01e15ee
Show file tree
Hide file tree
Showing 37 changed files with 673 additions and 180 deletions.
15 changes: 8 additions & 7 deletions ash/app_list/app_list_presenter_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ash/display/window_tree_host_manager.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/app_list_button.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
Expand Down Expand Up @@ -152,8 +153,8 @@ void AppListPresenterDelegate::Init(app_list::AppListView* view,
->GetRootWindowForDisplayId(display_id);
aura::Window* container = GetRootWindowController(root_window)
->GetContainer(kShellWindowId_AppListContainer);
views::View* applist_button =
Shelf::ForWindow(container)->GetAppListButtonView();
AppListButton* applist_button =
Shelf::ForWindow(container)->GetAppListButton();
is_centered_ = view->ShouldCenterWindow();
bool is_fullscreen = IsFullscreenAppListEnabled() &&
Shell::GetInstance()
Expand Down Expand Up @@ -181,10 +182,10 @@ void AppListPresenterDelegate::Init(app_list::AppListView* view,
ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds);
view->InitAsBubbleAttachedToAnchor(
container, current_apps_page,
Shelf::ForWindow(container)->GetAppListButtonView(),
Shelf::ForWindow(container)->GetAppListButton(),
GetAnchorPositionOffsetToShelf(
applist_button_bounds,
Shelf::ForWindow(container)->GetAppListButtonView()->GetWidget()),
Shelf::ForWindow(container)->GetAppListButton()->GetWidget()),
GetBubbleArrow(container), true /* border_accepts_events */);
view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
}
Expand All @@ -209,7 +210,7 @@ void AppListPresenterDelegate::OnShown(int64_t display_id) {
aura::Window* root_window = Shell::GetInstance()
->window_tree_host_manager()
->GetRootWindowForDisplayId(display_id);
Shelf::ForWindow(root_window)->GetAppListButtonView()->SchedulePaint();
Shelf::ForWindow(root_window)->GetAppListButton()->OnAppListShown();
}

void AppListPresenterDelegate::OnDismissed() {
Expand All @@ -226,8 +227,8 @@ void AppListPresenterDelegate::OnDismissed() {

// Update applist button status when app list visibility is changed.
Shelf::ForWindow(view_->GetWidget()->GetNativeView())
->GetAppListButtonView()
->SchedulePaint();
->GetAppListButton()
->OnAppListDismissed();
}

void AppListPresenterDelegate::UpdateBounds() {
Expand Down
1 change: 1 addition & 0 deletions ash/common/shelf/shelf_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const int kShelfItemInset = 3;
const SkColor kShelfBaseColor = SK_ColorBLACK;
const SkColor kShelfButtonActivatedHighlightColor =
SkColorSetA(SK_ColorWHITE, 100);
const SkColor kShelfInkDropBaseColor = SK_ColorWHITE;
const float kShelfInkDropVisibleOpacity = 0.2f;
const SkColor kShelfIconColor = SK_ColorWHITE;
const int kOverflowButtonSize = 32;
Expand Down
3 changes: 3 additions & 0 deletions ash/common/shelf/shelf_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ ASH_EXPORT extern const SkColor kShelfBaseColor;
// using the material design ripple animation.
ASH_EXPORT extern const SkColor kShelfButtonActivatedHighlightColor;

// Ink drop color for shelf items.
extern const SkColor kShelfInkDropBaseColor;

// Opacity of the ink drop ripple for shelf items when the ripple is visible.
extern const float kShelfInkDropVisibleOpacity;

Expand Down
3 changes: 2 additions & 1 deletion ash/first_run/first_run_helper_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/first_run/first_run_helper_impl.h"

#include "ash/common/shell_window_ids.h"
#include "ash/shelf/app_list_button.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ views::Widget* FirstRunHelperImpl::GetOverlayWidget() {

gfx::Rect FirstRunHelperImpl::GetAppListButtonBounds() {
Shelf* shelf = Shelf::ForPrimaryDisplay();
views::View* app_button = shelf->GetAppListButtonView();
AppListButton* app_button = shelf->GetAppListButton();
return app_button->GetBoundsInScreen();
}

Expand Down
58 changes: 46 additions & 12 deletions ash/shelf/app_list_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
#include "ui/views/painter.h"

namespace ash {
Expand All @@ -36,6 +37,11 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
draw_background_as_active_(false),
listener_(listener),
shelf_view_(shelf_view) {
if (ash::MaterialDesignController::IsShelfMaterial()) {
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
set_ink_drop_base_color(kShelfInkDropBaseColor);
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
}
SetAccessibleName(
app_list::switches::IsExperimentalAppListEnabled()
? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
Expand All @@ -49,6 +55,14 @@ AppListButton::AppListButton(InkDropButtonListener* listener,

AppListButton::~AppListButton() {}

void AppListButton::OnAppListShown() {
AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr);
}

void AppListButton::OnAppListDismissed() {
AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr);
}

bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
ImageButton::OnMousePressed(event);
shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event);
Expand All @@ -72,10 +86,15 @@ bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) {
}

void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
const bool is_material = ash::MaterialDesignController::IsShelfMaterial();
const bool touch_feedback =
!is_material && switches::IsTouchFeedbackEnabled();
switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN:
if (switches::IsTouchFeedbackEnabled())
if (touch_feedback)
SetDrawBackgroundAsActive(false);
else if (is_material)
AnimateInkDrop(views::InkDropState::HIDDEN, event);
shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event);
event->SetHandled();
return;
Expand All @@ -89,13 +108,15 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
event->SetHandled();
return;
case ui::ET_GESTURE_TAP_DOWN:
if (switches::IsTouchFeedbackEnabled())
if (touch_feedback)
SetDrawBackgroundAsActive(true);
else if (is_material && !Shell::GetInstance()->IsApplistVisible())
AnimateInkDrop(views::InkDropState::ACTION_PENDING, event);
ImageButton::OnGestureEvent(event);
break;
case ui::ET_GESTURE_TAP_CANCEL:
case ui::ET_GESTURE_TAP:
if (switches::IsTouchFeedbackEnabled())
if (touch_feedback)
SetDrawBackgroundAsActive(false);
ImageButton::OnGestureEvent(event);
break;
Expand Down Expand Up @@ -143,16 +164,8 @@ void AppListButton::PaintBackgroundMD(gfx::Canvas* canvas) {
gfx::Point circle_center = GetContentsBounds().CenterPoint();
if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment()))
circle_center = gfx::Point(circle_center.y(), circle_center.x());
canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint);

if (Shell::GetInstance()->GetAppListTargetVisibility() ||
draw_background_as_active_) {
SkPaint highlight_paint;
highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
highlight_paint.setStyle(SkPaint::kFill_Style);
canvas->DrawCircle(circle_center, kAppListButtonRadius, highlight_paint);
}
canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint);
}

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

std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple()
const {
// TODO(mohsen): A circular SquareInkDropRipple is created with equal small
// and large sizes to mimic a circular flood fill. Replace with an actual
// flood fill when circular flood fills are implemented.
gfx::Size ripple_size(2 * kAppListButtonRadius, 2 * kAppListButtonRadius);
auto ink_drop_ripple = new views::SquareInkDropRipple(
ripple_size, 0, ripple_size, 0, GetContentsBounds().CenterPoint(),
GetInkDropBaseColor(), ink_drop_visible_opacity());
ink_drop_ripple->set_activated_shape(views::SquareInkDropRipple::CIRCLE);
return base::WrapUnique(ink_drop_ripple);
}

void AppListButton::NotifyClick(const ui::Event& event) {
ImageButton::NotifyClick(event);
if (listener_)
listener_->ButtonPressed(this, event, ink_drop());
}

bool AppListButton::ShouldEnterPushedState(const ui::Event& event) {
return !Shell::GetInstance()->IsApplistVisible();
}

bool AppListButton::ShouldShowInkDropHighlight() const {
return false;
}

void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) {
if (draw_background_as_active_ == draw_background_as_active)
return;
Expand Down
9 changes: 8 additions & 1 deletion ash/shelf/app_list_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef ASH_SHELF_APP_LIST_BUTTON_H_
#define ASH_SHELF_APP_LIST_BUTTON_H_

#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/views/controls/button/image_button.h"

Expand All @@ -13,12 +14,15 @@ class InkDropButtonListener;
class ShelfView;

// Button used for the AppList icon on the shelf.
class AppListButton : public views::ImageButton {
class ASH_EXPORT AppListButton : public views::ImageButton {
public:
explicit AppListButton(InkDropButtonListener* listener,
ShelfView* shelf_view);
~AppListButton() override;

void OnAppListShown();
void OnAppListDismissed();

bool draw_background_as_active() { return draw_background_as_active_; }

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

// ui::EventHandler overrides:
void OnGestureEvent(ui::GestureEvent* event) override;
Expand Down
4 changes: 2 additions & 2 deletions ash/shelf/shelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ void Shelf::SchedulePaint() {
shelf_view_->SchedulePaintForAllButtons();
}

views::View* Shelf::GetAppListButtonView() const {
return shelf_view_->GetAppListButtonView();
AppListButton* Shelf::GetAppListButton() const {
return shelf_view_->GetAppListButton();
}

void Shelf::LaunchAppIndexAt(int item_index) {
Expand Down
3 changes: 2 additions & 1 deletion ash/shelf/shelf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class View;
}

namespace ash {
class AppListButton;
class FocusCycler;
class ShelfDelegate;
class ShelfIconObserver;
Expand Down Expand Up @@ -132,7 +133,7 @@ class ASH_EXPORT Shelf {

void SchedulePaint();

views::View* GetAppListButtonView() const;
AppListButton* GetAppListButton() const;

// Launch a 0-indexed shelf item in the shelf.
// A negative index launches the last shelf item in the shelf.
Expand Down
5 changes: 2 additions & 3 deletions ash/shelf/shelf_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const int kIndicatorCanvasScale = 5;
const int kInkDropSmallSize = 48;
const int kInkDropLargeSize = 60;
const int kInkDropLargeCornerRadius = 4;
const SkColor kInkDropBaseColor = SK_ColorWHITE;

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

Expand Down
Loading

0 comments on commit 01e15ee

Please sign in to comment.