This source file includes following definitions.
- currently_dimming_
- SetDimming
- OnWindowBoundsChanged
#include "ash/wm/screen_dimmer.h"
#include "ash/shell.h"
#include "base/time/time.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace ash {
namespace {
const float kDimmingLayerOpacity = 0.4f;
const int kDimmingTransitionMs = 200;
}
ScreenDimmer::ScreenDimmer(aura::Window* root_window)
: root_window_(root_window),
currently_dimming_(false) {
root_window_->AddObserver(this);
}
ScreenDimmer::~ScreenDimmer() {
root_window_->RemoveObserver(this);
}
void ScreenDimmer::SetDimming(bool should_dim) {
if (should_dim == currently_dimming_)
return;
if (!dimming_layer_) {
dimming_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
dimming_layer_->SetColor(SK_ColorBLACK);
dimming_layer_->SetOpacity(0.0f);
ui::Layer* root_layer = root_window_->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::OnWindowBoundsChanged(aura::Window* root,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
if (dimming_layer_)
dimming_layer_->SetBounds(gfx::Rect(root->bounds().size()));
}
}