summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/slide_out_view.h
blob: 89962f2d317f40cb1f9be1a5f43e07179ae70725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_VIEWS_CONTROLS_SLIDE_OUT_VIEW_H_
#define UI_VIEWS_CONTROLS_SLIDE_OUT_VIEW_H_

#include "base/macros.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"

namespace views {

// A View that can be closed by a slide-out touch gesture.
class VIEWS_EXPORT SlideOutView : public views::View,
                                  public ui::ImplicitAnimationObserver {
 public:
  SlideOutView();
  ~SlideOutView() override;

  bool slide_out_enabled() { return is_slide_out_enabled_; }

 protected:
  // Called when user intends to close the View by sliding it out.
  virtual void OnSlideOut() = 0;

  // Overridden from views::View.
  void OnGestureEvent(ui::GestureEvent* event) override;

  void set_slide_out_enabled(bool is_slide_out_enabled) {
    is_slide_out_enabled_ = is_slide_out_enabled;
  }

 private:
  enum SlideDirection {
    SLIDE_LEFT,
    SLIDE_RIGHT,
  };

  // Restores the transform and opacity of the view.
  void RestoreVisualState();

  // Slides the view out and closes it after the animation.
  void SlideOutAndClose(SlideDirection direction);

  // Overridden from ImplicitAnimationObserver.
  void OnImplicitAnimationsCompleted() override;

  float gesture_amount_ = 0.f;
  bool is_slide_out_enabled_ = true;

  DISALLOW_COPY_AND_ASSIGN(SlideOutView);
};

}  // namespace views

#endif  // UI_VIEWS_CONTROLS_SLIDE_OUT_VIEW_H_