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

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

Issue 2320273002: Refactors DimWindow and moves to ash/common (Closed)
Patch Set: feedback and member initializer ordering 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
« no previous file with comments | « ash/common/wm/window_dimmer.h ('k') | ash/common/wm_root_window_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/dim_window.h" 5 #include "ash/common/wm/window_dimmer.h"
6
7 #include <memory>
8
9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h"
6 #include "base/time/time.h" 11 #include "base/time/time.h"
7 #include "ui/aura/client/aura_constants.h"
8 #include "ui/aura/window_property.h"
9 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h"
11 #include "ui/wm/core/visibility_controller.h"
12 #include "ui/wm/core/window_animations.h" 13 #include "ui/wm/core/window_animations.h"
13 14
14 DECLARE_WINDOW_PROPERTY_TYPE(ash::DimWindow*);
15
16 namespace ash { 15 namespace ash {
17 namespace { 16 namespace {
18 17
19 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(DimWindow*, kDimWindowKey, nullptr);
20
21 const int kDefaultDimAnimationDurationMs = 200; 18 const int kDefaultDimAnimationDurationMs = 200;
22 19
23 const float kDefaultDimOpacity = 0.5f; 20 const float kDefaultDimOpacity = 0.5f;
24 21
25 } // namespace 22 } // namespace
26 23
27 // static 24 WindowDimmer::WindowDimmer(WmWindow* parent)
28 DimWindow* DimWindow::Get(aura::Window* container) { 25 : parent_(parent),
29 return container->GetProperty(kDimWindowKey); 26 window_(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL,
30 } 27 ui::LAYER_SOLID_COLOR)) {
31 28 window_->SetVisibilityChangesAnimated();
32 DimWindow::DimWindow(aura::Window* parent) 29 window_->SetVisibilityAnimationType(
33 : aura::Window(nullptr), parent_(parent) { 30 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
34 SetType(ui::wm::WINDOW_TYPE_NORMAL); 31 window_->SetVisibilityAnimationDuration(
35 Init(ui::LAYER_SOLID_COLOR); 32 base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs));
36 wm::SetWindowVisibilityChangesAnimated(this); 33 window_->AddObserver(this);
37 wm::SetWindowVisibilityAnimationType(
38 this, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
39 wm::SetWindowVisibilityAnimationDuration(
40 this, base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs));
41 34
42 SetDimOpacity(kDefaultDimOpacity); 35 SetDimOpacity(kDefaultDimOpacity);
43 36
44 parent->AddChild(this); 37 parent->AddChild(window_);
45 parent->AddObserver(this); 38 parent->AddObserver(this);
46 parent->SetProperty(kDimWindowKey, this); 39 parent->StackChildAtTop(window_);
47 parent->StackChildAtTop(this);
48 40
49 SetBounds(parent->bounds()); 41 window_->SetBounds(gfx::Rect(parent_->GetBounds().size()));
50 } 42 }
51 43
52 DimWindow::~DimWindow() { 44 WindowDimmer::~WindowDimmer() {
53 if (parent_) { 45 if (parent_)
54 parent_->ClearProperty(kDimWindowKey);
55 parent_->RemoveObserver(this); 46 parent_->RemoveObserver(this);
56 parent_ = nullptr; 47 if (window_) {
48 window_->RemoveObserver(this);
49 window_->Destroy();
57 } 50 }
58 } 51 }
59 52
60 void DimWindow::SetDimOpacity(float target_opacity) { 53 void WindowDimmer::SetDimOpacity(float target_opacity) {
61 layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity)); 54 DCHECK(window_);
55 window_->GetLayer()->SetColor(
56 SkColorSetA(SK_ColorBLACK, 255 * target_opacity));
62 } 57 }
63 58
64 void DimWindow::OnWindowBoundsChanged(aura::Window* window, 59 void WindowDimmer::OnWindowBoundsChanged(WmWindow* window,
65 const gfx::Rect& old_bounds, 60 const gfx::Rect& old_bounds,
66 const gfx::Rect& new_bounds) { 61 const gfx::Rect& new_bounds) {
67 if (window == parent_) 62 if (window == parent_)
68 SetBounds(new_bounds); 63 window_->SetBounds(gfx::Rect(new_bounds.size()));
69 } 64 }
70 65
71 void DimWindow::OnWindowDestroying(Window* window) { 66 void WindowDimmer::OnWindowDestroying(WmWindow* window) {
72 if (window == parent_) { 67 if (window == parent_) {
73 window->ClearProperty(kDimWindowKey); 68 parent_->RemoveObserver(this);
74 window->RemoveObserver(this);
75 parent_ = nullptr; 69 parent_ = nullptr;
70 } else {
71 DCHECK_EQ(window_, window);
72 window_->RemoveObserver(this);
73 window_ = nullptr;
76 } 74 }
77 } 75 }
78 76
77 void WindowDimmer::OnWindowTreeChanging(WmWindow* window,
78 const TreeChangeParams& params) {
79 if (window == window_ && params.target == window) {
80 // This may happen on a display change or some unexpected condition. Hide
81 // the window to ensure it isn't obscuring the wrong thing.
82 window_->Hide();
83 }
84 }
85
79 } // namespace ash 86 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/window_dimmer.h ('k') | ash/common/wm_root_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698