abbb0a5b1abbd98c0339e6f043e2ce96fbad569f
[platform/framework/web/crosswalk.git] / src / ash / wm / screen_dimmer.h
1 // Copyright (c) 2012 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 ASH_WM_SCREEN_DIMMER_H_
6 #define ASH_WM_SCREEN_DIMMER_H_
7
8 #include "ash/ash_export.h"
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/aura/window_observer.h"
13
14 namespace ui {
15 class Layer;
16 }
17
18 namespace ash {
19 namespace internal {
20
21 // ScreenDimmer displays a partially-opaque layer above everything
22 // else in the root window to darken the display.  It shouldn't be used
23 // for long-term brightness adjustments due to performance
24 // considerations -- it's only intended for cases where we want to
25 // briefly dim the screen (e.g. to indicate to the user that we're
26 // about to suspend a machine that lacks an internal backlight that
27 // can be adjusted).
28 class ASH_EXPORT ScreenDimmer : public aura::WindowObserver {
29  public:
30   class TestApi {
31    public:
32     explicit TestApi(ScreenDimmer* dimmer) : dimmer_(dimmer) {}
33
34     ui::Layer* layer() { return dimmer_->dimming_layer_.get(); }
35
36    private:
37     ScreenDimmer* dimmer_;  // not owned
38
39     DISALLOW_COPY_AND_ASSIGN(TestApi);
40   };
41
42   explicit ScreenDimmer(aura::Window* root_window);
43   virtual ~ScreenDimmer();
44
45   // Dim or undim the root window.
46   void SetDimming(bool should_dim);
47
48   // aura::WindowObserver overrides:
49   virtual void OnWindowBoundsChanged(aura::Window* root_window,
50                                      const gfx::Rect& old_bounds,
51                                      const gfx::Rect& new_bounds) OVERRIDE;
52
53  private:
54   friend class TestApi;
55
56   aura::Window* root_window_;
57
58   // Partially-opaque layer that's stacked above all of the root window's
59   // children and used to dim the screen.  NULL until the first time we dim.
60   scoped_ptr<ui::Layer> dimming_layer_;
61
62   // Are we currently dimming the screen?
63   bool currently_dimming_;
64
65   DISALLOW_COPY_AND_ASSIGN(ScreenDimmer);
66 };
67
68 }  // namespace internal
69 }  // namespace ash
70
71 #endif  // ASH_WM_SCREEN_DIMMER_H_