Commit 367a1bee authored by jonross's avatar jonross Committed by Commit bot

Adds touch feedback to tray icons in touchview when...

Adds touch feedback to tray icons in touchview when --ash-enable-touchview-touch-feedback flag is passed.

TEST=WebNotificationTrayTest.MAYBE_NoTouchFeedback, WebNotificationTrayTest.MAYBE_MaximizeModeTouchFeedback, WebNotificationTrayTest.MAYBE_TouchFeedbackCancellation
BUG=398398

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

Cr-Commit-Position: refs/heads/master@{#293608}
parent abc62302
......@@ -66,6 +66,10 @@ const char kAshEnableSoftwareMirroring[] = "ash-enable-software-mirroring";
// flag is removed.
const char kAshEnableTouchViewTesting[] = "ash-enable-touch-view-testing";
// Enables additional visual feedback to touch input.
const char kAshEnableTouchViewTouchFeedback[] =
"ash-enable-touch-view-touch-feedback";
// When this flag is set, system sounds will be played whether the
// ChromeVox is enabled or not.
const char kAshEnableSystemSounds[] = "ash-enable-system-sounds";
......
......@@ -33,6 +33,7 @@ ASH_EXPORT extern const char kAshDisableTextFilteringInOverviewMode[];
ASH_EXPORT extern const char kAshEnableSoftwareMirroring[];
ASH_EXPORT extern const char kAshEnableSystemSounds[];
ASH_EXPORT extern const char kAshEnableTouchViewTesting[];
ASH_EXPORT extern const char kAshEnableTouchViewTouchFeedback[];
ASH_EXPORT extern const char kAshEnableTrayDragging[];
ASH_EXPORT extern const char kAshGuestWallpaperLarge[];
ASH_EXPORT extern const char kAshGuestWallpaperSmall[];
......
......@@ -54,7 +54,10 @@ void OverviewButtonTray::UpdateAfterLoginStatusChange(
}
bool OverviewButtonTray::PerformAction(const ui::Event& event) {
Shell::GetInstance()->window_selector_controller()->ToggleOverview();
WindowSelectorController* controller =
Shell::GetInstance()->window_selector_controller();
controller->ToggleOverview();
SetDrawBackgroundAsActive(controller->IsSelecting());
return true;
}
......
......@@ -17,6 +17,7 @@
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_event_filter.h"
#include "ash/wm/window_animations.h"
#include "base/command_line.h"
#include "grit/ash_resources.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/aura/window.h"
......@@ -25,6 +26,7 @@
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_element.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
......@@ -308,6 +310,7 @@ TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget)
kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha),
hovered_(false),
draw_background_as_active_(false),
touch_feedback_enabled_(false),
widget_observer_(new TrayWidgetObserver(this)) {
set_notify_enter_exit_on_child(true);
......@@ -325,6 +328,11 @@ TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget)
SetFillsBoundsOpaquely(false);
// Start the tray items not visible, because visibility changes are animated.
views::View::SetVisible(false);
if (CommandLine::ForCurrentProcess()->
HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) {
touch_feedback_enabled_ = true;
}
}
TrayBackgroundView::~TrayBackgroundView() {
......@@ -426,6 +434,18 @@ gfx::Rect TrayBackgroundView::GetFocusBounds() {
return GetContentsBounds();
}
void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
if (touch_feedback_enabled_) {
if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
SetDrawBackgroundAsActive(true);
} else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
event->type() == ui::ET_GESTURE_TAP_CANCEL) {
SetDrawBackgroundAsActive(false);
}
}
ActionableView::OnGestureEvent(event);
}
void TrayBackgroundView::UpdateBackground(int alpha) {
// The animator should never fire when the alternate shelf layout is used.
if (!background_ || draw_background_as_active_)
......@@ -628,6 +648,8 @@ TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const {
}
void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) {
if (draw_background_as_active_ == visible)
return;
draw_background_as_active_ = visible;
if (!background_)
return;
......
......@@ -77,6 +77,7 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// ActionableView:
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
virtual gfx::Rect GetFocusBounds() OVERRIDE;
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
// BackgroundAnimatorDelegate:
virtual void UpdateBackground(int alpha) OVERRIDE;
......@@ -185,6 +186,10 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// differently if set to true.
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_;
scoped_ptr<TrayWidgetObserver> widget_observer_;
scoped_ptr<TrayEventFilter> tray_event_filter_;
......
......@@ -6,6 +6,7 @@
#include <vector>
#include "ash/ash_switches.h"
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
......@@ -19,12 +20,16 @@
#include "ash/test/status_area_widget_test_helper.h"
#include "ash/test/test_system_tray_delegate.h"
#include "ash/wm/window_state.h"
#include "base/command_line.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/message_center_tray.h"
......@@ -90,6 +95,12 @@ class WebNotificationTrayTest : public test::AshTestBase {
WebNotificationTrayTest() {}
virtual ~WebNotificationTrayTest() {}
virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTouchViewTouchFeedback);
test::AshTestBase::SetUp();
}
virtual void TearDown() OVERRIDE {
GetMessageCenter()->RemoveAllNotifications(false);
test::AshTestBase::TearDown();
......@@ -467,4 +478,74 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) {
EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray()));
}
// TODO(jonross): Replace manually creating TouchEvent with
// EventGenerator.PressTouch/ReleaseTouch. Currently they set a width on the
// touch event causing the gesture recognizer to target a different view.
#if defined(OS_CHROMEOS)
// Tests that there is visual feedback for touch presses.
TEST_F(WebNotificationTrayTest, TouchFeedback) {
AddNotification("test_id");
RunAllPendingInMessageLoop();
WebNotificationTray* tray = GetTray();
EXPECT_TRUE(tray->visible());
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
const int touch_id = 0;
gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id,
generator.Now());
generator.Dispatch(&press);
RunAllPendingInMessageLoop();
EXPECT_TRUE(tray->draw_background_as_active());
ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center_point, touch_id,
press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
generator.Dispatch(&release);
RunAllPendingInMessageLoop();
EXPECT_TRUE(tray->draw_background_as_active());
EXPECT_TRUE(tray->IsMessageCenterBubbleVisible());
generator.GestureTapAt(center_point);
RunAllPendingInMessageLoop();
EXPECT_FALSE(tray->draw_background_as_active());
EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
}
// Tests that while touch presses trigger visual feedback, that subsequent non
// tap gestures cancel the feedback without triggering the message center.
TEST_F(WebNotificationTrayTest, TouchFeedbackCancellation) {
AddNotification("test_id");
RunAllPendingInMessageLoop();
WebNotificationTray* tray = GetTray();
EXPECT_TRUE(tray->visible());
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
const int touch_id = 0;
gfx::Rect bounds = tray->GetBoundsInScreen();
gfx::Point center_point = bounds.CenterPoint();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id,
generator.Now());
generator.Dispatch(&press);
RunAllPendingInMessageLoop();
EXPECT_TRUE(tray->draw_background_as_active());
gfx::Point out_of_bounds(bounds.x() - 1, center_point.y());
ui::TouchEvent move(ui::ET_TOUCH_MOVED, out_of_bounds, touch_id,
press.time_stamp()+base::TimeDelta::FromMilliseconds(50));
generator.Dispatch(&move);
RunAllPendingInMessageLoop();
EXPECT_FALSE(tray->draw_background_as_active());
ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id,
move.time_stamp()+base::TimeDelta::FromMilliseconds(50));
generator.Dispatch(&release);
RunAllPendingInMessageLoop();
EXPECT_FALSE(tray->draw_background_as_active());
EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
}
#endif // OS_CHROMEOS
} // namespace ash
......@@ -5912,6 +5912,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_ASH_ENABLE_TOUCH_VIEW_TESTING_DESCRIPTION" desc="Description for the flag to enable the TouchView testing mode.">
Enable Ctrl+Alt+Shift+8 to toggle the TouchView maximizing mode.
</message>
<message name="IDS_FLAGS_ASH_ENABLE_TOUCH_VIEW_TOUCH_FEEDBACK_NAME" desc="Title for the flag to enable additional visual feedback for touch.">
Enable additional touch feedback on UI components.
</message>
<message name="IDS_FLAGS_ASH_ENABLE_TOUCH_VIEW_TOUCH_FEEDBACK_DESCRIPTION" desc="Description for the flag to enable additional visual feedback for touch.">
Certain UI components will display visual feedback upon touch interactions.
</message>
<message name="IDS_FLAGS_ASH_DISABLE_TEXT_FILTERING_IN_OVERVIEW_MODE_NAME" desc="Title for the flag to disable window filtering in overview mode by inputing text">
Disable text filtering in Overview Mode.
</message>
......
......@@ -1028,13 +1028,20 @@ const Experiment kExperiments[] = {
kOsCrOS,
SINGLE_VALUE_TYPE(ash::switches::kAshEnableTouchViewTesting),
},
{
"ash-enable-touch-view-touch-feedback",
IDS_FLAGS_ASH_ENABLE_TOUCH_VIEW_TOUCH_FEEDBACK_NAME,
IDS_FLAGS_ASH_ENABLE_TOUCH_VIEW_TOUCH_FEEDBACK_DESCRIPTION,
kOsCrOS,
SINGLE_VALUE_TYPE(ash::switches::kAshEnableTouchViewTouchFeedback),
},
{ "ash-disable-text-filtering-in-overview-mode",
IDS_FLAGS_ASH_DISABLE_TEXT_FILTERING_IN_OVERVIEW_MODE_NAME,
IDS_FLAGS_ASH_DISABLE_TEXT_FILTERING_IN_OVERVIEW_MODE_DESCRIPTION,
kOsCrOS,
SINGLE_VALUE_TYPE(ash::switches::kAshDisableTextFilteringInOverviewMode),
},
#endif
#endif // defined(USE_ASH)
#if defined(OS_CHROMEOS)
{
"enable-carrier-switching",
......
......@@ -44415,6 +44415,7 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="1139226452" label="enable-nacl-debug"/>
<int value="1142515376" label="enable-nacl"/>
<int value="1150622273" label="enable-apps-file-associations"/>
<int value="1163255347" label="ash-enable-touch-view-touch-feedback"/>
<int value="1196644408" label="performance-monitor-gathering"/>
<int value="1205849612" label="enable-sync-synced-notifications"/>
<int value="1210343926" label="enable-drop-sync-credential"/>
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