Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/wm/container_finder.h" | 7 #include "ash/common/wm/container_finder.h" |
| 8 #include "ash/common/wm/window_dimmer.h" | 8 #include "ash/common/wm/window_dimmer.h" |
| 9 #include "ash/common/wm_shell.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 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(WindowDimmer, kWindowDimmerKey, nullptr); | |
| 20 | |
| 19 // Opacity when it's dimming the entire screen. | 21 // Opacity when it's dimming the entire screen. |
| 20 const float kDimmingLayerOpacityForRoot = 0.4f; | 22 const float kDimmingLayerOpacityForRoot = 0.4f; |
| 21 | 23 |
| 22 // Opacity for lock screen. | 24 // Opacity for lock screen. |
| 23 const float kDimmingLayerOpacityForLockScreen = 0.5f; | 25 const float kDimmingLayerOpacityForLockScreen = 0.5f; |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 ScreenDimmer::ScreenDimmer(Container container) | 29 ScreenDimmer::ScreenDimmer(Container container) |
| 28 : container_(container), | 30 : container_(container), is_dimming_(false), at_bottom_(false) { |
| 29 is_dimming_(false), | |
| 30 at_bottom_(false), | |
| 31 window_dimmers_(base::MakeUnique<WmWindowUserData<WindowDimmer>>()) { | |
| 32 Shell::GetInstance()->AddShellObserver(this); | 31 Shell::GetInstance()->AddShellObserver(this); |
| 33 } | 32 } |
| 34 | 33 |
| 35 ScreenDimmer::~ScreenDimmer() { | 34 ScreenDimmer::~ScreenDimmer() { |
| 36 // Usage in chrome results in ScreenDimmer outliving the shell. | 35 // Usage in chrome results in ScreenDimmer outliving the shell. |
| 37 if (Shell::HasInstance()) | 36 if (!Shell::HasInstance()) |
| 38 Shell::GetInstance()->RemoveShellObserver(this); | 37 return; |
| 38 | |
| 39 Shell::GetInstance()->RemoveShellObserver(this); | |
| 40 for (aura::Window* container : GetAllContainers()) | |
| 41 container->ClearProperty(kWindowDimmerKey); | |
| 39 } | 42 } |
| 40 | 43 |
| 41 void ScreenDimmer::SetDimming(bool should_dim) { | 44 void ScreenDimmer::SetDimming(bool should_dim) { |
| 42 if (should_dim == is_dimming_) | 45 if (should_dim == is_dimming_) |
| 43 return; | 46 return; |
| 44 is_dimming_ = should_dim; | 47 is_dimming_ = should_dim; |
| 45 | 48 |
| 46 Update(should_dim); | 49 Update(should_dim); |
| 47 } | 50 } |
| 48 | 51 |
| 49 std::vector<WmWindow*> ScreenDimmer::GetAllContainers() { | 52 // static |
| 53 WindowDimmer* ScreenDimmer::GetWindowDimmer(aura::Window* window) { | |
| 54 return window->GetProperty(kWindowDimmerKey); | |
| 55 } | |
| 56 | |
| 57 aura::Window::Windows ScreenDimmer::GetAllContainers() { | |
| 50 return container_ == Container::ROOT | 58 return container_ == Container::ROOT |
| 51 ? WmShell::Get()->GetAllRootWindows() | 59 ? Shell::GetAllRootWindows() |
| 52 : wm::GetContainersFromAllRootWindows( | 60 : wm::GetContainersFromAllRootWindows( |
| 53 ash::kShellWindowId_LockScreenContainersContainer); | 61 ash::kShellWindowId_LockScreenContainersContainer); |
| 54 } | 62 } |
| 55 | 63 |
| 56 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { | 64 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { |
| 57 Update(is_dimming_); | 65 Update(is_dimming_); |
| 58 } | 66 } |
| 59 | 67 |
| 60 void ScreenDimmer::Update(bool should_dim) { | 68 void ScreenDimmer::Update(bool should_dim) { |
| 61 for (WmWindow* container : GetAllContainers()) { | 69 for (aura::Window* container : GetAllContainers()) { |
| 62 WindowDimmer* window_dimmer = window_dimmers_->Get(container); | 70 WindowDimmer* window_dimmer = container->GetProperty(kWindowDimmerKey); |
| 63 if (should_dim) { | 71 if (should_dim) { |
| 64 if (!window_dimmer) { | 72 if (!window_dimmer) { |
| 65 window_dimmers_->Set(container, | 73 window_dimmer = new WindowDimmer(container); |
| 66 base::MakeUnique<WindowDimmer>(container)); | 74 container->SetProperty(kWindowDimmerKey, window_dimmer); |
|
James Cook
2017/03/09 18:39:27
Aside: It's kind of a bummer we don't have a SetOw
sky
2017/03/09 20:39:04
Agreed. I filed 687408 on that a while back.
| |
| 67 window_dimmer = window_dimmers_->Get(container); | |
| 68 window_dimmer->SetDimOpacity(container_ == Container::ROOT | 75 window_dimmer->SetDimOpacity(container_ == Container::ROOT |
| 69 ? kDimmingLayerOpacityForRoot | 76 ? kDimmingLayerOpacityForRoot |
| 70 : kDimmingLayerOpacityForLockScreen); | 77 : kDimmingLayerOpacityForLockScreen); |
| 71 } | 78 } |
| 72 if (at_bottom_) | 79 if (at_bottom_) |
| 73 container->StackChildAtBottom(window_dimmer->window()); | 80 container->StackChildAtBottom(window_dimmer->window()); |
| 74 else | 81 else |
| 75 container->StackChildAtTop(window_dimmer->window()); | 82 container->StackChildAtTop(window_dimmer->window()); |
| 76 window_dimmer->window()->Show(); | 83 window_dimmer->window()->Show(); |
| 77 } else if (window_dimmer) { | 84 } else if (window_dimmer) { |
| 78 window_dimmers_->Set(container, nullptr); | 85 container->ClearProperty(kWindowDimmerKey); |
| 79 } | 86 } |
| 80 } | 87 } |
| 81 } | 88 } |
| 82 | 89 |
| 83 } // namespace ash | 90 } // namespace ash |
| OLD | NEW |