15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASH_WM_GESTURES_LONG_PRESS_AFFORDANCE_HANDLER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_WM_GESTURES_LONG_PRESS_AFFORDANCE_HANDLER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/timer/timer.h"
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/aura/window_observer.h"
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/linear_animation.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/point.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class GestureEvent;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SystemGestureEventFilterTest;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LongPressAffordanceHandler displays an animated affordance that is shown
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// on a TAP_DOWN gesture. The animation sequence consists of two parts:
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The first part is a grow animation that starts at semi-long-press and
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// completes on a long-press gesture. The affordance animates to full size
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// during grow animation.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The second part is a shrink animation that start after grow and shrinks the
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// affordance out of view.
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class LongPressAffordanceHandler : public gfx::LinearAnimation,
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                   public aura::WindowObserver {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LongPressAffordanceHandler();
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~LongPressAffordanceHandler();
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Displays or removes long press affordance according to the |event|.
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void ProcessEvent(aura::Window* target, ui::GestureEvent* event);
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ash::test::SystemGestureEventFilterTest;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  class LongPressAffordanceView;
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum LongPressAnimationType {
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NONE,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GROW_ANIMATION,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SHRINK_ANIMATION,
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StartAnimation();
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void StopAffordance();
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SetTapDownTarget(aura::Window* target);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Overridden from gfx::LinearAnimation.
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AnimateToState(double state) OVERRIDE;
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void AnimationStopped() OVERRIDE;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Overridden from aura::WindowObserver.
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<LongPressAffordanceView> view_;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Point tap_down_location_;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::OneShotTimer<LongPressAffordanceHandler> timer_;
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window* tap_down_target_;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LongPressAnimationType current_animation_type_;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(LongPressAffordanceHandler);
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace internal
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // ASH_WM_GESTURES_LONG_PRESS_AFFORDANCE_HANDLER_H_
76