blob: 1d6e205d887b7217614356051d12695197ce5f95 [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"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010012#include "ui/aura/window_observer.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014namespace ui {
15class Layer;
16}
17
18namespace ash {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019
20// ScreenDimmer displays a partially-opaque layer above everything
21// else in the root window to darken the display. It shouldn't be used
22// for long-term brightness adjustments due to performance
23// considerations -- it's only intended for cases where we want to
24// briefly dim the screen (e.g. to indicate to the user that we're
25// about to suspend a machine that lacks an internal backlight that
26// can be adjusted).
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010027class ASH_EXPORT ScreenDimmer : public aura::WindowObserver {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000028 public:
29 class TestApi {
30 public:
31 explicit TestApi(ScreenDimmer* dimmer) : dimmer_(dimmer) {}
32
33 ui::Layer* layer() { return dimmer_->dimming_layer_.get(); }
34
35 private:
36 ScreenDimmer* dimmer_; // not owned
37
38 DISALLOW_COPY_AND_ASSIGN(TestApi);
39 };
40
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000041 explicit ScreenDimmer(aura::Window* root_window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000042 virtual ~ScreenDimmer();
43
44 // Dim or undim the root window.
45 void SetDimming(bool should_dim);
46
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010047 // aura::WindowObserver overrides:
48 virtual void OnWindowBoundsChanged(aura::Window* root_window,
49 const gfx::Rect& old_bounds,
50 const gfx::Rect& new_bounds) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000051
52 private:
53 friend class TestApi;
54
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000055 aura::Window* root_window_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000056
57 // Partially-opaque layer that's stacked above all of the root window's
58 // children and used to dim the screen. NULL until the first time we dim.
59 scoped_ptr<ui::Layer> dimming_layer_;
60
61 // Are we currently dimming the screen?
62 bool currently_dimming_;
63
64 DISALLOW_COPY_AND_ASSIGN(ScreenDimmer);
65};
66
Torne (Richard Coles)58218062012-11-14 11:43:16 +000067} // namespace ash
68
69#endif // ASH_WM_SCREEN_DIMMER_H_