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

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

Issue 2735983006: Renames WmWindowUserData and converts to using aura (Closed)
Patch Set: ownership comments Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/wm/screen_dimmer.h" 5 #include "ash/common/wm/screen_dimmer.h"
6 6
7 #include "ash/common/window_user_data.h"
7 #include "ash/common/wm/container_finder.h" 8 #include "ash/common/wm/container_finder.h"
8 #include "ash/common/wm/window_dimmer.h" 9 #include "ash/common/wm/window_dimmer.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.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" 11 #include "ash/public/cpp/shell_window_ids.h"
13 #include "ash/shell.h" 12 #include "ash/shell.h"
14 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "ui/aura/window.h"
15 15
16 namespace ash { 16 namespace ash {
17 namespace { 17 namespace {
18 18
19 // Opacity when it's dimming the entire screen. 19 // Opacity when it's dimming the entire screen.
20 const float kDimmingLayerOpacityForRoot = 0.4f; 20 const float kDimmingLayerOpacityForRoot = 0.4f;
21 21
22 // Opacity for lock screen. 22 // Opacity for lock screen.
23 const float kDimmingLayerOpacityForLockScreen = 0.5f; 23 const float kDimmingLayerOpacityForLockScreen = 0.5f;
24 24
25 } // namespace 25 } // namespace
26 26
27 ScreenDimmer::ScreenDimmer(Container container) 27 ScreenDimmer::ScreenDimmer(Container container)
28 : container_(container), 28 : container_(container),
29 is_dimming_(false), 29 is_dimming_(false),
30 at_bottom_(false), 30 at_bottom_(false),
31 window_dimmers_(base::MakeUnique<WmWindowUserData<WindowDimmer>>()) { 31 window_dimmers_(base::MakeUnique<WindowUserData<WindowDimmer>>()) {
32 Shell::GetInstance()->AddShellObserver(this); 32 Shell::GetInstance()->AddShellObserver(this);
33 } 33 }
34 34
35 ScreenDimmer::~ScreenDimmer() { 35 ScreenDimmer::~ScreenDimmer() {
36 // Usage in chrome results in ScreenDimmer outliving the shell. 36 // Usage in chrome results in ScreenDimmer outliving the shell.
37 if (Shell::HasInstance()) 37 if (Shell::HasInstance())
38 Shell::GetInstance()->RemoveShellObserver(this); 38 Shell::GetInstance()->RemoveShellObserver(this);
39 } 39 }
40 40
41 void ScreenDimmer::SetDimming(bool should_dim) { 41 void ScreenDimmer::SetDimming(bool should_dim) {
42 if (should_dim == is_dimming_) 42 if (should_dim == is_dimming_)
43 return; 43 return;
44 is_dimming_ = should_dim; 44 is_dimming_ = should_dim;
45 45
46 Update(should_dim); 46 Update(should_dim);
47 } 47 }
48 48
49 std::vector<WmWindow*> ScreenDimmer::GetAllContainers() { 49 aura::Window::Windows ScreenDimmer::GetAllContainers() {
50 return container_ == Container::ROOT 50 return container_ == Container::ROOT
51 ? WmShell::Get()->GetAllRootWindows() 51 ? Shell::GetAllRootWindows()
52 : wm::GetContainersFromAllRootWindows( 52 : wm::GetContainersFromAllRootWindows(
53 ash::kShellWindowId_LockScreenContainersContainer); 53 ash::kShellWindowId_LockScreenContainersContainer);
54 } 54 }
55 55
56 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { 56 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) {
57 Update(is_dimming_); 57 Update(is_dimming_);
58 } 58 }
59 59
60 void ScreenDimmer::Update(bool should_dim) { 60 void ScreenDimmer::Update(bool should_dim) {
61 for (WmWindow* container : GetAllContainers()) { 61 for (aura::Window* container : GetAllContainers()) {
62 WindowDimmer* window_dimmer = window_dimmers_->Get(container); 62 WindowDimmer* window_dimmer = window_dimmers_->Get(container);
63 if (should_dim) { 63 if (should_dim) {
64 if (!window_dimmer) { 64 if (!window_dimmer) {
65 window_dimmers_->Set(container, 65 window_dimmers_->Set(container,
66 base::MakeUnique<WindowDimmer>(container)); 66 base::MakeUnique<WindowDimmer>(container));
67 window_dimmer = window_dimmers_->Get(container); 67 window_dimmer = window_dimmers_->Get(container);
68 window_dimmer->SetDimOpacity(container_ == Container::ROOT 68 window_dimmer->SetDimOpacity(container_ == Container::ROOT
69 ? kDimmingLayerOpacityForRoot 69 ? kDimmingLayerOpacityForRoot
70 : kDimmingLayerOpacityForLockScreen); 70 : kDimmingLayerOpacityForLockScreen);
71 } 71 }
72 if (at_bottom_) 72 if (at_bottom_)
73 container->StackChildAtBottom(window_dimmer->window()); 73 container->StackChildAtBottom(window_dimmer->window());
74 else 74 else
75 container->StackChildAtTop(window_dimmer->window()); 75 container->StackChildAtTop(window_dimmer->window());
76 window_dimmer->window()->Show(); 76 window_dimmer->window()->Show();
77 } else if (window_dimmer) { 77 } else if (window_dimmer) {
78 window_dimmers_->Set(container, nullptr); 78 window_dimmers_->Set(container, nullptr);
79 } 79 }
80 } 80 }
81 } 81 }
82 82
83 } // namespace ash 83 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698