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

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

Issue 2320273002: Refactors DimWindow and moves to ash/common (Closed)
Patch Set: git add wm_window 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 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
22 const char kWindowDimmerKey[] = "window_dimmer_key";
23
25 } // namespace 24 } // namespace
26 25
26 struct WindowDimmer::Data : public base::SupportsUserData::Data {
27 ~Data() override { delete window_dimmer; }
James Cook 2016/09/09 00:03:35 So is the point of all this userdata to ensure tha
sky 2016/09/09 03:50:04 The main motivation for user data is the same as t
28
29 WindowDimmer* window_dimmer;
30 };
31
27 // static 32 // static
28 DimWindow* DimWindow::Get(aura::Window* container) { 33 WindowDimmer* WindowDimmer::Get(WmWindow* container) {
29 return container->GetProperty(kDimWindowKey); 34 Data* data = static_cast<Data*>(
35 container->GetUserData()->GetUserData(kWindowDimmerKey));
36 return data ? data->window_dimmer : nullptr;
30 } 37 }
31 38
32 DimWindow::DimWindow(aura::Window* parent) 39 WindowDimmer::WindowDimmer(WmWindow* parent)
33 : aura::Window(nullptr), parent_(parent) { 40 : parent_(parent),
34 SetType(ui::wm::WINDOW_TYPE_NORMAL); 41 window_(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL,
35 Init(ui::LAYER_SOLID_COLOR); 42 ui::LAYER_SOLID_COLOR)) {
36 wm::SetWindowVisibilityChangesAnimated(this); 43 window_->SetVisibilityChangesAnimated();
37 wm::SetWindowVisibilityAnimationType( 44 window_->SetVisibilityAnimationType(
38 this, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 45 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
39 wm::SetWindowVisibilityAnimationDuration( 46 window_->SetVisibilityAnimationDuration(
40 this, base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs)); 47 base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs));
41 48
42 SetDimOpacity(kDefaultDimOpacity); 49 SetDimOpacity(kDefaultDimOpacity);
43 50
44 parent->AddChild(this); 51 parent->AddChild(window_);
45 parent->AddObserver(this); 52 parent->AddObserver(this);
46 parent->SetProperty(kDimWindowKey, this); 53 parent->StackChildAtTop(window_);
47 parent->StackChildAtTop(this);
48 54
49 SetBounds(parent->bounds()); 55 window_->SetBounds(gfx::Rect(parent_->GetBounds().size()));
56
57 Data* data = new Data;
58 data->window_dimmer = this;
59 parent->GetUserData()->SetUserData(kWindowDimmerKey, data);
50 } 60 }
51 61
52 DimWindow::~DimWindow() { 62 void WindowDimmer::Destroy() {
53 if (parent_) { 63 window_->Destroy();
54 parent_->ClearProperty(kDimWindowKey); 64 parent_->RemoveObserver(this);
55 parent_->RemoveObserver(this); 65 // RemoveUserData() riggers deleting this.
James Cook 2016/09/09 00:03:35 nit: triggers
sky 2016/09/09 03:50:04 Done.
56 parent_ = nullptr; 66 parent_->GetUserData()->RemoveUserData(kWindowDimmerKey);
57 }
58 } 67 }
59 68
60 void DimWindow::SetDimOpacity(float target_opacity) { 69 void WindowDimmer::SetDimOpacity(float target_opacity) {
61 layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity)); 70 window_->GetLayer()->SetColor(
71 SkColorSetA(SK_ColorBLACK, 255 * target_opacity));
62 } 72 }
63 73
64 void DimWindow::OnWindowBoundsChanged(aura::Window* window, 74 void WindowDimmer::OnWindowBoundsChanged(WmWindow* window,
65 const gfx::Rect& old_bounds, 75 const gfx::Rect& old_bounds,
66 const gfx::Rect& new_bounds) { 76 const gfx::Rect& new_bounds) {
67 if (window == parent_) 77 DCHECK_EQ(window, parent_);
68 SetBounds(new_bounds); 78 window_->SetBounds(gfx::Rect(new_bounds.size()));
69 } 79 }
70 80
71 void DimWindow::OnWindowDestroying(Window* window) { 81 WindowDimmer::~WindowDimmer() {
72 if (window == parent_) { 82 parent_->RemoveObserver(this);
73 window->ClearProperty(kDimWindowKey);
74 window->RemoveObserver(this);
75 parent_ = nullptr;
76 }
77 } 83 }
78 84
79 } // namespace ash 85 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698