blob: 9d581fa473f34b3bbe9d10b2393a089bb8bd6a01 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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/root_window_observer.h"
13
14namespace aura {
15class RootWindow;
16}
17
18namespace ui {
19class Layer;
20}
21
22namespace ash {
23namespace internal {
24
25// ScreenDimmer displays a partially-opaque layer above everything
26// else in the root window to darken the display. It shouldn't be used
27// for long-term brightness adjustments due to performance
28// considerations -- it's only intended for cases where we want to
29// briefly dim the screen (e.g. to indicate to the user that we're
30// about to suspend a machine that lacks an internal backlight that
31// can be adjusted).
32class ASH_EXPORT ScreenDimmer : public aura::RootWindowObserver {
33 public:
34 class TestApi {
35 public:
36 explicit TestApi(ScreenDimmer* dimmer) : dimmer_(dimmer) {}
37
38 ui::Layer* layer() { return dimmer_->dimming_layer_.get(); }
39
40 private:
41 ScreenDimmer* dimmer_; // not owned
42
43 DISALLOW_COPY_AND_ASSIGN(TestApi);
44 };
45
46 explicit ScreenDimmer(aura::RootWindow* root_window);
47 virtual ~ScreenDimmer();
48
49 // Dim or undim the root window.
50 void SetDimming(bool should_dim);
51
52 // aura::RootWindowObserver overrides:
53 virtual void OnRootWindowResized(const aura::RootWindow* root,
54 const gfx::Size& old_size) OVERRIDE;
55
56 private:
57 friend class TestApi;
58
59 aura::RootWindow* root_window_;
60
61 // Partially-opaque layer that's stacked above all of the root window's
62 // children and used to dim the screen. NULL until the first time we dim.
63 scoped_ptr<ui::Layer> dimming_layer_;
64
65 // Are we currently dimming the screen?
66 bool currently_dimming_;
67
68 DISALLOW_COPY_AND_ASSIGN(ScreenDimmer);
69};
70
71} // namespace internal
72} // namespace ash
73
74#endif // ASH_WM_SCREEN_DIMMER_H_