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

Unified Diff: ash/common/wm/screen_dimmer.cc

Issue 2735983006: Renames WmWindowUserData and converts to using aura (Closed)
Patch Set: moor aura 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/wm/screen_dimmer.cc
diff --git a/ash/common/wm/screen_dimmer.cc b/ash/common/wm/screen_dimmer.cc
index 8304d118252ea8ee4d09c263390d74121adde646..f5917edf5cdd95a90371431542d415bde80100ad 100644
--- a/ash/common/wm/screen_dimmer.cc
+++ b/ash/common/wm/screen_dimmer.cc
@@ -8,14 +8,16 @@
#include "ash/common/wm/window_dimmer.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
-#include "ash/common/wm_window_user_data.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "base/memory/ptr_util.h"
+#include "ui/aura/window.h"
namespace ash {
namespace {
+DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(WindowDimmer, kWindowDimmerKey, nullptr);
+
// Opacity when it's dimming the entire screen.
const float kDimmingLayerOpacityForRoot = 0.4f;
@@ -25,17 +27,18 @@ const float kDimmingLayerOpacityForLockScreen = 0.5f;
} // namespace
ScreenDimmer::ScreenDimmer(Container container)
- : container_(container),
- is_dimming_(false),
- at_bottom_(false),
- window_dimmers_(base::MakeUnique<WmWindowUserData<WindowDimmer>>()) {
+ : container_(container), is_dimming_(false), at_bottom_(false) {
Shell::GetInstance()->AddShellObserver(this);
}
ScreenDimmer::~ScreenDimmer() {
// Usage in chrome results in ScreenDimmer outliving the shell.
- if (Shell::HasInstance())
- Shell::GetInstance()->RemoveShellObserver(this);
+ if (!Shell::HasInstance())
+ return;
+
+ Shell::GetInstance()->RemoveShellObserver(this);
+ for (aura::Window* container : GetAllContainers())
+ container->ClearProperty(kWindowDimmerKey);
}
void ScreenDimmer::SetDimming(bool should_dim) {
@@ -46,9 +49,14 @@ void ScreenDimmer::SetDimming(bool should_dim) {
Update(should_dim);
}
-std::vector<WmWindow*> ScreenDimmer::GetAllContainers() {
+// static
+WindowDimmer* ScreenDimmer::GetWindowDimmer(aura::Window* window) {
+ return window->GetProperty(kWindowDimmerKey);
+}
+
+aura::Window::Windows ScreenDimmer::GetAllContainers() {
return container_ == Container::ROOT
- ? WmShell::Get()->GetAllRootWindows()
+ ? Shell::GetAllRootWindows()
: wm::GetContainersFromAllRootWindows(
ash::kShellWindowId_LockScreenContainersContainer);
}
@@ -58,13 +66,12 @@ void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) {
}
void ScreenDimmer::Update(bool should_dim) {
- for (WmWindow* container : GetAllContainers()) {
- WindowDimmer* window_dimmer = window_dimmers_->Get(container);
+ for (aura::Window* container : GetAllContainers()) {
+ WindowDimmer* window_dimmer = container->GetProperty(kWindowDimmerKey);
if (should_dim) {
if (!window_dimmer) {
- window_dimmers_->Set(container,
- base::MakeUnique<WindowDimmer>(container));
- window_dimmer = window_dimmers_->Get(container);
+ window_dimmer = new WindowDimmer(container);
+ container->SetProperty(kWindowDimmerKey, window_dimmer);
window_dimmer->SetDimOpacity(container_ == Container::ROOT
? kDimmingLayerOpacityForRoot
: kDimmingLayerOpacityForLockScreen);
@@ -75,7 +82,7 @@ void ScreenDimmer::Update(bool should_dim) {
container->StackChildAtTop(window_dimmer->window());
window_dimmer->window()->Show();
} else if (window_dimmer) {
- window_dimmers_->Set(container, nullptr);
+ container->ClearProperty(kWindowDimmerKey);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698