Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2528)

Unified Diff: ash/wm/screen_dimmer.cc

Issue 10263011: chromeos: Add support for dimming the screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/wm/screen_dimmer.h ('k') | ash/wm/screen_dimmer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/wm/screen_dimmer.cc
diff --git a/ash/wm/screen_dimmer.cc b/ash/wm/screen_dimmer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b902de0ea9eecf29635d498b45285c503c81d860
--- /dev/null
+++ b/ash/wm/screen_dimmer.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/wm/screen_dimmer.h"
+
+#include "ash/shell.h"
+#include "base/time.h"
+#include "ui/aura/root_window.h"
+#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/scoped_layer_animation_settings.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+// Opacity for |dimming_layer_| when it's dimming the screen.
+const float kDimmingLayerOpacity = 0.4f;
+
+// Duration for dimming animations, in milliseconds.
+const int kDimmingTransitionMs = 200;
+
+} // namespace
+
+ScreenDimmer::ScreenDimmer() : currently_dimming_(false) {
+ Shell::GetInstance()->GetRootWindow()->AddRootWindowObserver(this);
+}
+
+ScreenDimmer::~ScreenDimmer() {
+ Shell::GetInstance()->GetRootWindow()->RemoveRootWindowObserver(this);
+}
+
+void ScreenDimmer::SetDimming(bool should_dim) {
+ if (should_dim == currently_dimming_)
+ return;
+
+ if (!dimming_layer_.get()) {
+ dimming_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
+ dimming_layer_->SetColor(SK_ColorBLACK);
+ dimming_layer_->SetOpacity(0.0f);
+ ui::Layer* root_layer = Shell::GetRootWindow()->layer();
+ dimming_layer_->SetBounds(root_layer->bounds());
+ root_layer->Add(dimming_layer_.get());
+ root_layer->StackAtTop(dimming_layer_.get());
+ }
+
+ currently_dimming_ = should_dim;
+
+ ui::ScopedLayerAnimationSettings scoped_settings(
+ dimming_layer_->GetAnimator());
+ scoped_settings.SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(kDimmingTransitionMs));
+ dimming_layer_->SetOpacity(should_dim ? kDimmingLayerOpacity : 0.0f);
+}
+
+void ScreenDimmer::OnRootWindowResized(const aura::RootWindow* root,
+ const gfx::Size& old_size) {
+ if (dimming_layer_.get())
+ dimming_layer_->SetBounds(gfx::Rect(root->bounds().size()));
+}
+
+} // namespace internal
+} // namespace ash
« no previous file with comments | « ash/wm/screen_dimmer.h ('k') | ash/wm/screen_dimmer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698