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 14namespace ui { 15class Layer; 16} 17 18namespace ash { 19 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). 27class ASH_EXPORT ScreenDimmer : public aura::WindowObserver { 28 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 41 explicit ScreenDimmer(aura::Window* root_window); 42 virtual ~ScreenDimmer(); 43 44 // Dim or undim the root window. 45 void SetDimming(bool should_dim); 46 47 // aura::WindowObserver overrides: 48 virtual void OnWindowBoundsChanged(aura::Window* root_window, 49 const gfx::Rect& old_bounds, 50 const gfx::Rect& new_bounds) OVERRIDE; 51 52 private: 53 friend class TestApi; 54 55 aura::Window* root_window_; 56 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 67} // namespace ash 68 69#endif // ASH_WM_SCREEN_DIMMER_H_ 70