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

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

Issue 2320273002: Refactors DimWindow and moves to ash/common (Closed)
Patch Set: WmWindowUserData test Created 4 years, 3 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/wm/screen_dimmer.h" 5 #include "ash/wm/screen_dimmer.h"
6 6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/wm/window_dimmer.h"
7 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window_user_data.h"
8 #include "ash/shell.h" 11 #include "ash/shell.h"
9 #include "ash/wm/dim_window.h"
10 #include "base/time/time.h" 12 #include "base/time/time.h"
11 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/aura/window_property.h" 14 #include "ui/aura/window_property.h"
13 #include "ui/compositor/layer.h" 15 #include "ui/compositor/layer.h"
14 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/compositor/scoped_layer_animation_settings.h"
15 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
17 19
18 DECLARE_WINDOW_PROPERTY_TYPE(ash::ScreenDimmer*); 20 DECLARE_WINDOW_PROPERTY_TYPE(ash::ScreenDimmer*);
19 21
(...skipping 30 matching lines...) Expand all
50 ScreenDimmer* dimmer = GetForContainer(kRootWindowMagicId); 52 ScreenDimmer* dimmer = GetForContainer(kRootWindowMagicId);
51 // Root window's dimmer 53 // Root window's dimmer
52 dimmer->target_opacity_ = kDimmingLayerOpacityForRoot; 54 dimmer->target_opacity_ = kDimmingLayerOpacityForRoot;
53 return dimmer; 55 return dimmer;
54 } 56 }
55 57
56 ScreenDimmer::ScreenDimmer(int container_id) 58 ScreenDimmer::ScreenDimmer(int container_id)
57 : container_id_(container_id), 59 : container_id_(container_id),
58 target_opacity_(0.5f), 60 target_opacity_(0.5f),
59 is_dimming_(false), 61 is_dimming_(false),
60 at_bottom_(false) { 62 at_bottom_(false),
63 window_dimmers_(base::MakeUnique<WmWindowUserData<WindowDimmer>>()) {
61 WmShell::Get()->AddShellObserver(this); 64 WmShell::Get()->AddShellObserver(this);
62 } 65 }
63 66
64 ScreenDimmer::~ScreenDimmer() { 67 ScreenDimmer::~ScreenDimmer() {
65 WmShell::Get()->RemoveShellObserver(this); 68 WmShell::Get()->RemoveShellObserver(this);
66 } 69 }
67 70
68 void ScreenDimmer::SetDimming(bool should_dim) { 71 void ScreenDimmer::SetDimming(bool should_dim) {
69 if (should_dim == is_dimming_) 72 if (should_dim == is_dimming_)
70 return; 73 return;
(...skipping 12 matching lines...) Expand all
83 return container_id == kRootWindowMagicId 86 return container_id == kRootWindowMagicId
84 ? primary 87 ? primary
85 : primary->GetChildById(container_id); 88 : primary->GetChildById(container_id);
86 } 89 }
87 90
88 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) { 91 void ScreenDimmer::OnRootWindowAdded(WmWindow* root_window) {
89 Update(is_dimming_); 92 Update(is_dimming_);
90 } 93 }
91 94
92 void ScreenDimmer::Update(bool should_dim) { 95 void ScreenDimmer::Update(bool should_dim) {
93 for (aura::Window* container : GetAllContainers(container_id_)) { 96 for (aura::Window* aura_container : GetAllContainers(container_id_)) {
94 DimWindow* dim = DimWindow::Get(container); 97 WmWindow* container = WmWindowAura::Get(aura_container);
98 WindowDimmer* window_dimmer = window_dimmers_->Get(container);
James Cook 2016/09/09 21:33:37 WDYT of WmWindowUserData::Get() being named either
sky 2016/09/09 21:50:45 I view WmWindowUserData close to a map, in which c
95 if (should_dim) { 99 if (should_dim) {
96 if (!dim) { 100 if (!window_dimmer) {
97 dim = new DimWindow(container); 101 window_dimmers_->Set(container,
98 dim->SetDimOpacity(target_opacity_); 102 base::MakeUnique<WindowDimmer>(container));
103 window_dimmer = window_dimmers_->Get(container);
104 window_dimmer->SetDimOpacity(target_opacity_);
99 } 105 }
100 if (at_bottom_) 106 if (at_bottom_)
101 dim->parent()->StackChildAtBottom(dim); 107 container->StackChildAtBottom(window_dimmer->window());
102 else 108 else
103 dim->parent()->StackChildAtTop(dim); 109 container->StackChildAtTop(window_dimmer->window());
104 dim->Show(); 110 window_dimmer->window()->Show();
105 } else { 111 } else if (window_dimmer) {
106 if (dim) { 112 window_dimmers_->Set(container, nullptr);
107 dim->Hide();
108 delete dim;
109 }
110 } 113 }
111 } 114 }
112 } 115 }
113 116
114 } // namespace ash 117 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698