Commit 26c4cb3e authored by jonross's avatar jonross Committed by Commit bot

AppLauncher Touch Feedback

Add visual feedback to AppListButton. The background will draw active in response to touch downs.

TEST=ShelfViewTest.AppListButtonTouchFeedback, ShelfViewTest.AppListButtonTouchFeedbackCancellation
BUG=398398

Review URL: https://codereview.chromium.org/558703002

Cr-Commit-Position: refs/heads/master@{#294814}
parent 6283bb93
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/command_line.h"
#include "grit/ash_resources.h" #include "grit/ash_resources.h"
#include "grit/ash_strings.h" #include "grit/ash_strings.h"
#include "ui/accessibility/ax_view_state.h" #include "ui/accessibility/ax_view_state.h"
...@@ -35,6 +36,9 @@ AppListButton::AppListButton(views::ButtonListener* listener, ...@@ -35,6 +36,9 @@ AppListButton::AppListButton(views::ButtonListener* listener,
ShelfButtonHost* host, ShelfButtonHost* host,
ShelfWidget* shelf_widget) ShelfWidget* shelf_widget)
: views::ImageButton(listener), : views::ImageButton(listener),
draw_background_as_active_(false),
touch_feedback_enabled_(CommandLine::ForCurrentProcess()->
HasSwitch(switches::kAshEnableTouchViewTouchFeedback)),
host_(host), host_(host),
shelf_widget_(shelf_widget) { shelf_widget_(shelf_widget) {
SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
...@@ -86,6 +90,8 @@ void AppListButton::OnMouseExited(const ui::MouseEvent& event) { ...@@ -86,6 +90,8 @@ void AppListButton::OnMouseExited(const ui::MouseEvent& event) {
void AppListButton::OnGestureEvent(ui::GestureEvent* event) { void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) { switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN: case ui::ET_GESTURE_SCROLL_BEGIN:
if (touch_feedback_enabled_)
SetDrawBackgroundAsActive(false);
host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event);
event->SetHandled(); event->SetHandled();
return; return;
...@@ -98,6 +104,17 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) { ...@@ -98,6 +104,17 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false);
event->SetHandled(); event->SetHandled();
return; return;
case ui::ET_GESTURE_TAP_DOWN:
if (touch_feedback_enabled_)
SetDrawBackgroundAsActive(true);
ImageButton::OnGestureEvent(event);
break;
case ui::ET_GESTURE_TAP_CANCEL:
case ui::ET_GESTURE_TAP:
if (touch_feedback_enabled_)
SetDrawBackgroundAsActive(false);
ImageButton::OnGestureEvent(event);
break;
default: default:
ImageButton::OnGestureEvent(event); ImageButton::OnGestureEvent(event);
return; return;
...@@ -109,7 +126,8 @@ void AppListButton::OnPaint(gfx::Canvas* canvas) { ...@@ -109,7 +126,8 @@ void AppListButton::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas); View::OnPaint(canvas);
int background_image_id = 0; int background_image_id = 0;
if (Shell::GetInstance()->GetAppListTargetVisibility()) { if (Shell::GetInstance()->GetAppListTargetVisibility() ||
draw_background_as_active_) {
background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
} else { } else {
if (shelf_widget_->GetDimsShelf()) if (shelf_widget_->GetDimsShelf())
...@@ -166,4 +184,12 @@ void AppListButton::GetAccessibleState(ui::AXViewState* state) { ...@@ -166,4 +184,12 @@ void AppListButton::GetAccessibleState(ui::AXViewState* state) {
state->name = host_->GetAccessibleName(this); state->name = host_->GetAccessibleName(this);
} }
void AppListButton::SetDrawBackgroundAsActive(
bool draw_background_as_active) {
if (draw_background_as_active_ == draw_background_as_active)
return;
draw_background_as_active_ = draw_background_as_active;
SchedulePaint();
}
} // namespace ash } // namespace ash
...@@ -22,6 +22,10 @@ class AppListButton : public views::ImageButton { ...@@ -22,6 +22,10 @@ class AppListButton : public views::ImageButton {
ShelfWidget* shelf_widget); ShelfWidget* shelf_widget);
virtual ~AppListButton(); virtual ~AppListButton();
bool draw_background_as_active() {
return draw_background_as_active_;
}
protected: protected:
// views::ImageButton overrides: // views::ImageButton overrides:
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
...@@ -38,6 +42,17 @@ class AppListButton : public views::ImageButton { ...@@ -38,6 +42,17 @@ class AppListButton : public views::ImageButton {
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
private: private:
// Toggles the active state for painting the background and schedules a paint.
void SetDrawBackgroundAsActive(bool draw_background_as_active);
// True if the background should render as active, regardless of the state of
// the application list.
bool draw_background_as_active_;
// True if touch view feedback command line flag has been enabled. When
// enabled touch gestures will toggle rendering the background as active.
bool touch_feedback_enabled_;
ShelfButtonHost* host_; ShelfButtonHost* host_;
// Reference to the shelf widget containing this button, owned by the // Reference to the shelf widget containing this button, owned by the
// root window controller. // root window controller.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/ash_switches.h" #include "ash/ash_switches.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/shelf/app_list_button.h"
#include "ash/shelf/overflow_bubble.h" #include "ash/shelf/overflow_bubble.h"
#include "ash/shelf/overflow_bubble_view.h" #include "ash/shelf/overflow_bubble_view.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
...@@ -295,6 +296,8 @@ class ShelfViewTest : public AshTestBase { ...@@ -295,6 +296,8 @@ class ShelfViewTest : public AshTestBase {
virtual ~ShelfViewTest() {} virtual ~ShelfViewTest() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTouchViewTouchFeedback);
AshTestBase::SetUp(); AshTestBase::SetUp();
test::ShellTestApi test_api(Shell::GetInstance()); test::ShellTestApi test_api(Shell::GetInstance());
model_ = test_api.shelf_model(); model_ = test_api.shelf_model();
...@@ -1670,6 +1673,53 @@ TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) { ...@@ -1670,6 +1673,53 @@ TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) {
TestDraggingAnItemFromOverflowToShelf(true); TestDraggingAnItemFromOverflowToShelf(true);
} }
// Tests that the AppListButton renders as active in response to touches.
TEST_F(ShelfViewTest, AppListButtonTouchFeedback) {
AppListButton* app_list_button =
static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
EXPECT_FALSE(app_list_button->draw_background_as_active());
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.set_current_location(app_list_button->
GetBoundsInScreen().CenterPoint());
generator.PressTouch();
RunAllPendingInMessageLoop();
EXPECT_TRUE(app_list_button->draw_background_as_active());
generator.ReleaseTouch();
RunAllPendingInMessageLoop();
EXPECT_FALSE(app_list_button->draw_background_as_active());
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
}
// Tests that a touch that slides out of the bounds of the AppListButton leads
// to the end of rendering an active state.
TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) {
AppListButton* app_list_button =
static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
EXPECT_FALSE(app_list_button->draw_background_as_active());
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.set_current_location(app_list_button->
GetBoundsInScreen().CenterPoint());
generator.PressTouch();
RunAllPendingInMessageLoop();
EXPECT_TRUE(app_list_button->draw_background_as_active());
gfx::Point moved_point(app_list_button->GetBoundsInScreen().right() + 1,
app_list_button->
GetBoundsInScreen().CenterPoint().y());
generator.MoveTouch(moved_point);
RunAllPendingInMessageLoop();
EXPECT_FALSE(app_list_button->draw_background_as_active());
generator.set_current_location(moved_point);
generator.ReleaseTouch();
RunAllPendingInMessageLoop();
EXPECT_FALSE(app_list_button->draw_background_as_active());
EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
}
class ShelfViewVisibleBoundsTest : public ShelfViewTest, class ShelfViewVisibleBoundsTest : public ShelfViewTest,
public testing::WithParamInterface<bool> { public testing::WithParamInterface<bool> {
public: public:
......
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