OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/screen/modal_window_controller.h" | 5 #include "athena/screen/modal_window_controller.h" |
6 | 6 |
7 #include "athena/screen/public/screen_manager.h" | 7 #include "athena/screen/public/screen_manager.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura/window_property.h" | 10 #include "ui/aura/window_property.h" |
11 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
12 #include "ui/compositor/layer_animation_observer.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
13 #include "ui/compositor/scoped_layer_animation_settings.h" | 13 #include "ui/compositor/scoped_layer_animation_settings.h" |
14 #include "ui/wm/core/window_animations.h" | 14 #include "ui/wm/core/window_animations.h" |
15 | 15 |
16 namespace athena { | 16 namespace athena { |
17 namespace { | 17 namespace { |
18 | 18 |
19 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ModalWindowController, | 19 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ModalWindowController, |
20 kModalWindowControllerKey, | 20 kModalWindowControllerKey, |
21 NULL); | 21 nullptr); |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 // static | 25 // static |
26 ModalWindowController* ModalWindowController::Get(aura::Window* container) { | 26 ModalWindowController* ModalWindowController::Get(aura::Window* container) { |
27 ModalWindowController* controller = | 27 ModalWindowController* controller = |
28 container->GetProperty(kModalWindowControllerKey); | 28 container->GetProperty(kModalWindowControllerKey); |
29 CHECK(controller); | 29 CHECK(controller); |
30 return controller; | 30 return controller; |
31 } | 31 } |
32 | 32 |
33 ModalWindowController::ModalWindowController(int priority) | 33 ModalWindowController::ModalWindowController(int priority) |
34 : modal_container_(NULL), | 34 : modal_container_(nullptr), |
35 dimmer_window_(new aura::Window(NULL)), | 35 dimmer_window_(new aura::Window(nullptr)), |
36 dimmed_(false) { | 36 dimmed_(false) { |
37 ScreenManager::ContainerParams params("ModalContainer", priority); | 37 ScreenManager::ContainerParams params("ModalContainer", priority); |
38 params.can_activate_children = true; | 38 params.can_activate_children = true; |
39 params.block_events = true; | 39 params.block_events = true; |
40 modal_container_ = ScreenManager::Get()->CreateContainer(params); | 40 modal_container_ = ScreenManager::Get()->CreateContainer(params); |
41 modal_container_->SetProperty(kModalWindowControllerKey, this); | 41 modal_container_->SetProperty(kModalWindowControllerKey, this); |
42 | 42 |
43 dimmer_window_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 43 dimmer_window_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
44 dimmer_window_->Init(aura::WINDOW_LAYER_SOLID_COLOR); | 44 dimmer_window_->Init(aura::WINDOW_LAYER_SOLID_COLOR); |
45 dimmer_window_->layer()->SetColor(SK_ColorBLACK); | 45 dimmer_window_->layer()->SetColor(SK_ColorBLACK); |
46 dimmer_window_->layer()->SetOpacity(0.0f); | 46 dimmer_window_->layer()->SetOpacity(0.0f); |
47 dimmer_window_->Show(); | 47 dimmer_window_->Show(); |
48 | 48 |
49 modal_container_->AddChild(dimmer_window_); | 49 modal_container_->AddChild(dimmer_window_); |
50 modal_container_->AddObserver(this); | 50 modal_container_->AddObserver(this); |
51 | 51 |
52 UpdateDimmerWindowBounds(); | 52 UpdateDimmerWindowBounds(); |
53 } | 53 } |
54 | 54 |
55 ModalWindowController::~ModalWindowController() { | 55 ModalWindowController::~ModalWindowController() { |
56 if (modal_container_) | 56 if (modal_container_) |
57 modal_container_->RemoveObserver(this); | 57 modal_container_->RemoveObserver(this); |
58 } | 58 } |
59 | 59 |
60 void ModalWindowController::OnWindowAdded(aura::Window* child) { | 60 void ModalWindowController::OnWindowAdded(aura::Window* child) { |
61 DCHECK_NE(child, dimmer_window_); | 61 DCHECK_NE(child, dimmer_window_); |
62 if (IsChildWindow(child)) { | 62 if (IsChildWindow(child)) { |
63 child->AddObserver(this); | 63 child->AddObserver(this); |
64 UpdateDimming(NULL); | 64 UpdateDimming(nullptr); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 void ModalWindowController::OnWindowVisibilityChanged(aura::Window* window, | 68 void ModalWindowController::OnWindowVisibilityChanged(aura::Window* window, |
69 bool visible) { | 69 bool visible) { |
70 if (IsChildWindow(window)) | 70 if (IsChildWindow(window)) |
71 UpdateDimming(NULL); | 71 UpdateDimming(nullptr); |
72 } | 72 } |
73 | 73 |
74 void ModalWindowController::OnWindowBoundsChanged(aura::Window* window, | 74 void ModalWindowController::OnWindowBoundsChanged(aura::Window* window, |
75 const gfx::Rect& old_bounds, | 75 const gfx::Rect& old_bounds, |
76 const gfx::Rect& new_bounds) { | 76 const gfx::Rect& new_bounds) { |
77 if (window == modal_container_) | 77 if (window == modal_container_) |
78 UpdateDimmerWindowBounds(); | 78 UpdateDimmerWindowBounds(); |
79 } | 79 } |
80 | 80 |
81 void ModalWindowController::OnWindowDestroyed(aura::Window* window) { | 81 void ModalWindowController::OnWindowDestroyed(aura::Window* window) { |
(...skipping 24 matching lines...) Expand all Loading... |
106 } | 106 } |
107 SetDimmed(false); | 107 SetDimmed(false); |
108 | 108 |
109 if (should_delete) { | 109 if (should_delete) { |
110 // Remove the container from root so that the container becomes | 110 // Remove the container from root so that the container becomes |
111 // invisible, but don't delete it until next event execution | 111 // invisible, but don't delete it until next event execution |
112 // because the call stack may still have and use the pointer. | 112 // because the call stack may still have and use the pointer. |
113 modal_container_->RemoveObserver(this); | 113 modal_container_->RemoveObserver(this); |
114 modal_container_->parent()->RemoveChild(modal_container_); | 114 modal_container_->parent()->RemoveChild(modal_container_); |
115 base::MessageLoopForUI::current()->DeleteSoon(FROM_HERE, modal_container_); | 115 base::MessageLoopForUI::current()->DeleteSoon(FROM_HERE, modal_container_); |
116 modal_container_ = NULL; | 116 modal_container_ = nullptr; |
117 dimmer_window_ = NULL; | 117 dimmer_window_ = nullptr; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 void ModalWindowController::SetDimmed(bool dimmed) { | 121 void ModalWindowController::SetDimmed(bool dimmed) { |
122 const float kDimmedOpacity = 0.4f; | 122 const float kDimmedOpacity = 0.4f; |
123 | 123 |
124 if (!dimmer_window_ || dimmed_ == dimmed) | 124 if (!dimmer_window_ || dimmed_ == dimmed) |
125 return; | 125 return; |
126 dimmed_ = dimmed; | 126 dimmed_ = dimmed; |
127 | 127 |
128 const int kDimmAnimationDurationMs = 500; | 128 const int kDimmAnimationDurationMs = 500; |
129 if (dimmed) { | 129 if (dimmed) { |
130 ui::ScopedLayerAnimationSettings settings( | 130 ui::ScopedLayerAnimationSettings settings( |
131 dimmer_window_->layer()->GetAnimator()); | 131 dimmer_window_->layer()->GetAnimator()); |
132 settings.SetTransitionDuration( | 132 settings.SetTransitionDuration( |
133 base::TimeDelta::FromMilliseconds(kDimmAnimationDurationMs)); | 133 base::TimeDelta::FromMilliseconds(kDimmAnimationDurationMs)); |
134 dimmer_window_->layer()->SetOpacity(kDimmedOpacity); | 134 dimmer_window_->layer()->SetOpacity(kDimmedOpacity); |
135 } else { | 135 } else { |
136 // ScopedHidingAnimationSettings will detach the animating and | 136 // ScopedHidingAnimationSettings will detach the animating and |
137 // recreate layers for the container so that animation can continue | 137 // recreate layers for the container so that animation can continue |
138 // even if the container is removed immediately. | 138 // even if the container is removed immediately. |
139 wm::ScopedHidingAnimationSettings settings(modal_container_); | 139 wm::ScopedHidingAnimationSettings settings(modal_container_); |
140 settings.layer_animation_settings()->SetTransitionDuration( | 140 settings.layer_animation_settings()->SetTransitionDuration( |
141 base::TimeDelta::FromMilliseconds(kDimmAnimationDurationMs)); | 141 base::TimeDelta::FromMilliseconds(kDimmAnimationDurationMs)); |
142 modal_container_->layer()->SetOpacity(0.0f); | 142 modal_container_->layer()->SetOpacity(0.0f); |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 } // namespace athena | 146 } // namespace athena |
OLD | NEW |