| 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/wm/screen_dimmer.h" | 5 #include "ash/wm/screen_dimmer.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.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_shell.h" |
| 11 #include "ash/common/wm_window.h" |
| 10 #include "ash/common/wm_window_user_data.h" | 12 #include "ash/common/wm_window_user_data.h" |
| 11 #include "ash/shell.h" | 13 #include "base/memory/ptr_util.h" |
| 12 #include "base/time/time.h" | 14 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_event_dispatcher.h" | |
| 14 #include "ui/aura/window_property.h" | 15 #include "ui/aura/window_property.h" |
| 15 #include "ui/compositor/layer.h" | |
| 16 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | |
| 18 #include "ui/gfx/geometry/size.h" | |
| 19 | 16 |
| 20 DECLARE_WINDOW_PROPERTY_TYPE(ash::ScreenDimmer*); | 17 DECLARE_WINDOW_PROPERTY_TYPE(ash::ScreenDimmer*); |
| 21 | 18 |
| 22 namespace ash { | 19 namespace ash { |
| 23 namespace { | 20 namespace { |
| 24 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenDimmer, kScreenDimmerKey, nullptr); | 21 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenDimmer, kScreenDimmerKey, nullptr); |
| 25 | 22 |
| 26 // Opacity when it's dimming the entire screen. | 23 // Opacity when it's dimming the entire screen. |
| 27 const float kDimmingLayerOpacityForRoot = 0.4f; | 24 const float kDimmingLayerOpacityForRoot = 0.4f; |
| 28 | 25 |
| 26 // Id used to indicate the root window. |
| 29 const int kRootWindowMagicId = -100; | 27 const int kRootWindowMagicId = -100; |
| 30 | 28 |
| 31 std::vector<aura::Window*> GetAllContainers(int container_id) { | 29 std::vector<WmWindow*> GetAllContainers(int container_id) { |
| 32 return container_id == kRootWindowMagicId | 30 return container_id == kRootWindowMagicId |
| 33 ? Shell::GetAllRootWindows() | 31 ? WmShell::Get()->GetAllRootWindows() |
| 34 : Shell::GetContainersFromAllRootWindows(container_id, nullptr); | 32 : wm::GetContainersFromAllRootWindows(container_id); |
| 33 } |
| 34 |
| 35 WmWindow* FindContainer(int container_id) { |
| 36 WmWindow* primary = WmShell::Get()->GetPrimaryRootWindow(); |
| 37 return container_id == kRootWindowMagicId |
| 38 ? primary |
| 39 : primary->GetChildByShellWindowId(container_id); |
| 35 } | 40 } |
| 36 | 41 |
| 37 } // namespace | 42 } // namespace |
| 38 | 43 |
| 39 // static | 44 // static |
| 40 ScreenDimmer* ScreenDimmer::GetForContainer(int container_id) { | 45 ScreenDimmer* ScreenDimmer::GetForContainer(int container_id) { |
| 41 aura::Window* primary_container = FindContainer(container_id); | 46 aura::Window* primary_container = |
| 47 WmWindowAura::GetAuraWindow(FindContainer(container_id)); |
| 42 ScreenDimmer* dimmer = primary_container->GetProperty(kScreenDimmerKey); | 48 ScreenDimmer* dimmer = primary_container->GetProperty(kScreenDimmerKey); |
| 43 if (!dimmer) { | 49 if (!dimmer) { |
| 44 dimmer = new ScreenDimmer(container_id); | 50 dimmer = new ScreenDimmer(container_id); |
| 45 primary_container->SetProperty(kScreenDimmerKey, dimmer); | 51 primary_container->SetProperty(kScreenDimmerKey, dimmer); |
| 46 } | 52 } |
| 47 return dimmer; | 53 return dimmer; |
| 48 } | 54 } |
| 49 | 55 |
| 50 // static | 56 // static |
| 51 ScreenDimmer* ScreenDimmer::GetForRoot() { | 57 ScreenDimmer* ScreenDimmer::GetForRoot() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 } | 75 } |
| 70 | 76 |
| 71 void ScreenDimmer::SetDimming(bool should_dim) { | 77 void ScreenDimmer::SetDimming(bool should_dim) { |
| 72 if (should_dim == is_dimming_) | 78 if (should_dim == is_dimming_) |
| 73 return; | 79 return; |
| 74 is_dimming_ = should_dim; | 80 is_dimming_ = should_dim; |
| 75 | 81 |
| 76 Update(should_dim); | 82 Update(should_dim); |
| 77 } | 83 } |
| 78 | 84 |
| 85 // static |
| 79 ScreenDimmer* ScreenDimmer::FindForTest(int container_id) { | 86 ScreenDimmer* ScreenDimmer::FindForTest(int container_id) { |
| 80 return FindContainer(container_id)->GetProperty(kScreenDimmerKey); | 87 return WmWindowAura::GetAuraWindow(FindContainer(container_id)) |
| 81 } | 88 ->GetProperty(kScreenDimmerKey); |
| 82 | |
| 83 // static | |
| 84 aura::Window* ScreenDimmer::FindContainer(int container_id) { | |
| 85 aura::Window* primary = Shell::GetPrimaryRootWindow(); | |
| 86 return container_id == kRootWindowMagicId | |
| 87 ? primary | |
| 88 : primary->GetChildById(container_id); | |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { | 91 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { |
| 92 Update(is_dimming_); | 92 Update(is_dimming_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ScreenDimmer::Update(bool should_dim) { | 95 void ScreenDimmer::Update(bool should_dim) { |
| 96 for (aura::Window* aura_container : GetAllContainers(container_id_)) { | 96 for (WmWindow* container : GetAllContainers(container_id_)) { |
| 97 WmWindow* container = WmWindowAura::Get(aura_container); | |
| 98 WindowDimmer* window_dimmer = window_dimmers_->Get(container); | 97 WindowDimmer* window_dimmer = window_dimmers_->Get(container); |
| 99 if (should_dim) { | 98 if (should_dim) { |
| 100 if (!window_dimmer) { | 99 if (!window_dimmer) { |
| 101 window_dimmers_->Set(container, | 100 window_dimmers_->Set(container, |
| 102 base::MakeUnique<WindowDimmer>(container)); | 101 base::MakeUnique<WindowDimmer>(container)); |
| 103 window_dimmer = window_dimmers_->Get(container); | 102 window_dimmer = window_dimmers_->Get(container); |
| 104 window_dimmer->SetDimOpacity(target_opacity_); | 103 window_dimmer->SetDimOpacity(target_opacity_); |
| 105 } | 104 } |
| 106 if (at_bottom_) | 105 if (at_bottom_) |
| 107 container->StackChildAtBottom(window_dimmer->window()); | 106 container->StackChildAtBottom(window_dimmer->window()); |
| 108 else | 107 else |
| 109 container->StackChildAtTop(window_dimmer->window()); | 108 container->StackChildAtTop(window_dimmer->window()); |
| 110 window_dimmer->window()->Show(); | 109 window_dimmer->window()->Show(); |
| 111 } else if (window_dimmer) { | 110 } else if (window_dimmer) { |
| 112 window_dimmers_->Set(container, nullptr); | 111 window_dimmers_->Set(container, nullptr); |
| 113 } | 112 } |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 } // namespace ash | 116 } // namespace ash |
| OLD | NEW |