Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / athena / system / power_button_controller.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
6 #define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
7
8 #include "base/time/time.h"
9 #include "chromeos/dbus/power_manager_client.h"
10 #include "ui/compositor/layer_animation_observer.h"
11 #include "ui/gfx/animation/tween.h"
12
13 namespace athena {
14
15 // Shuts down in response to the power button being pressed.
16 class PowerButtonController : public chromeos::PowerManagerClient::Observer,
17                               public ui::ImplicitAnimationObserver {
18  public:
19   PowerButtonController();
20   virtual ~PowerButtonController();
21
22  private:
23   enum State {
24     // The screen is animating prior to shutdown. Shutdown can be canceled.
25     STATE_PRE_SHUTDOWN_ANIMATION,
26
27     // A D-Bus shutdown request has been sent. Shutdown cannot be canceled.
28     STATE_SHUTDOWN_REQUESTED,
29
30     STATE_OTHER
31   };
32
33   // Animates the screen's grayscale and brightness to |target|.
34   void StartGrayscaleAndBrightnessAnimation(float target,
35                                             int duration_ms,
36                                             gfx::Tween::Type tween_type);
37
38   // chromeos::PowerManagerClient::Observer:
39   virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE;
40   virtual void PowerButtonEventReceived(
41       bool down,
42       const base::TimeTicks& timestamp) OVERRIDE;
43
44   // ui::ImplicitAnimationObserver:
45   virtual void OnImplicitAnimationsCompleted() OVERRIDE;
46
47   // Whether the screen brightness was reduced to 0%.
48   bool brightness_is_zero_;
49
50   // The last time at which the screen brightness was 0%.
51   base::TimeTicks zero_brightness_end_time_;
52
53   State state_;
54
55   DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
56 };
57
58 }  // namespace athena
59
60 #endif  // ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_