OLD | NEW |
| (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/common/wm/screen_dimmer.h" | |
6 | |
7 #include "ash/common/wm/container_finder.h" | |
8 #include "ash/common/wm/window_dimmer.h" | |
9 #include "ash/common/wm_shell.h" | |
10 #include "ash/common/wm_window.h" | |
11 #include "ash/common/wm_window_user_data.h" | |
12 #include "ash/public/cpp/shell_window_ids.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 // Usage in chrome results in ScreenDimmer outliving the shell. | |
36 if (WmShell::HasInstance()) | |
37 WmShell::Get()->RemoveShellObserver(this); | |
38 } | |
39 | |
40 void ScreenDimmer::SetDimming(bool should_dim) { | |
41 if (should_dim == is_dimming_) | |
42 return; | |
43 is_dimming_ = should_dim; | |
44 | |
45 Update(should_dim); | |
46 } | |
47 | |
48 std::vector<WmWindow*> ScreenDimmer::GetAllContainers() { | |
49 return container_ == Container::ROOT | |
50 ? WmShell::Get()->GetAllRootWindows() | |
51 : wm::GetContainersFromAllRootWindows( | |
52 ash::kShellWindowId_LockScreenContainersContainer); | |
53 } | |
54 | |
55 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { | |
56 Update(is_dimming_); | |
57 } | |
58 | |
59 void ScreenDimmer::Update(bool should_dim) { | |
60 for (WmWindow* container : GetAllContainers()) { | |
61 WindowDimmer* window_dimmer = window_dimmers_->Get(container); | |
62 if (should_dim) { | |
63 if (!window_dimmer) { | |
64 window_dimmers_->Set(container, | |
65 base::MakeUnique<WindowDimmer>(container)); | |
66 window_dimmer = window_dimmers_->Get(container); | |
67 window_dimmer->SetDimOpacity(container_ == Container::ROOT | |
68 ? kDimmingLayerOpacityForRoot | |
69 : kDimmingLayerOpacityForLockScreen); | |
70 } | |
71 if (at_bottom_) | |
72 container->StackChildAtBottom(window_dimmer->window()); | |
73 else | |
74 container->StackChildAtTop(window_dimmer->window()); | |
75 window_dimmer->window()->Show(); | |
76 } else if (window_dimmer) { | |
77 window_dimmers_->Set(container, nullptr); | |
78 } | |
79 } | |
80 } | |
81 | |
82 } // namespace ash | |
OLD | NEW |