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

Side by Side Diff: ash/wm/screen_dimmer.cc

Issue 2334013003: Moves ScreenDimmer to ash/common (Closed)
Patch Set: Created 4 years, 3 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "ash/wm/screen_dimmer.h"
6
7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wm/container_finder.h"
9 #include "ash/common/wm/window_dimmer.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h"
12 #include "ash/common/wm_window_user_data.h"
13 #include "base/memory/ptr_util.h"
14
15 namespace ash {
16 namespace {
17
18 // Opacity when it's dimming the entire screen.
19 const float kDimmingLayerOpacityForRoot = 0.4f;
20
21 // Opacity for lock screen.
22 const float kDimmingLayerOpacityForLockScreen = 0.5f;
23
24 } // namespace
25
26 ScreenDimmer::ScreenDimmer(Container container)
27 : container_(container),
28 is_dimming_(false),
29 at_bottom_(false),
30 window_dimmers_(base::MakeUnique<WmWindowUserData<WindowDimmer>>()) {
31 WmShell::Get()->AddShellObserver(this);
32 }
33
34 ScreenDimmer::~ScreenDimmer() {
35 WmShell::Get()->RemoveShellObserver(this);
36 }
37
38 void ScreenDimmer::SetDimming(bool should_dim) {
39 if (should_dim == is_dimming_)
40 return;
41 is_dimming_ = should_dim;
42
43 Update(should_dim);
44 }
45
46 std::vector<WmWindow*> ScreenDimmer::GetAllContainers() {
47 return container_ == Container::ROOT
48 ? WmShell::Get()->GetAllRootWindows()
49 : wm::GetContainersFromAllRootWindows(
50 ash::kShellWindowId_LockScreenContainersContainer);
51 }
52
53 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) {
54 Update(is_dimming_);
55 }
56
57 void ScreenDimmer::Update(bool should_dim) {
58 for (WmWindow* container : GetAllContainers()) {
59 WindowDimmer* window_dimmer = window_dimmers_->Get(container);
60 if (should_dim) {
61 if (!window_dimmer) {
62 window_dimmers_->Set(container,
63 base::MakeUnique<WindowDimmer>(container));
64 window_dimmer = window_dimmers_->Get(container);
65 window_dimmer->SetDimOpacity(container_ == Container::ROOT
66 ? kDimmingLayerOpacityForRoot
67 : kDimmingLayerOpacityForLockScreen);
68 }
69 if (at_bottom_)
70 container->StackChildAtBottom(window_dimmer->window());
71 else
72 container->StackChildAtTop(window_dimmer->window());
73 window_dimmer->window()->Show();
74 } else if (window_dimmer) {
75 window_dimmers_->Set(container, nullptr);
76 }
77 }
78 }
79
80 } // namespace ash
OLDNEW
« 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