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

Side by Side Diff: ash/wm/system_modal_container_layout_manager.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
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/system_modal_container_layout_manager.h" 5 #include "ash/wm/system_modal_container_layout_manager.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ash/aura/wm_window_aura.h"
9 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
12 #include "ash/common/wm/window_dimmer.h"
11 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
12 #include "ash/shell.h" 14 #include "ash/shell.h"
13 #include "ash/wm/dim_window.h"
14 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/client/capture_client.h" 18 #include "ui/aura/client/capture_client.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/aura/window_property.h" 20 #include "ui/aura/window_property.h"
20 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
21 #include "ui/keyboard/keyboard_controller.h" 22 #include "ui/keyboard/keyboard_controller.h"
22 #include "ui/wm/core/window_util.h" 23 #include "ui/wm/core/window_util.h"
23 24
24 namespace ash { 25 namespace ash {
25 namespace { 26 namespace {
26 27
27 // The center point of the window can diverge this much from the center point 28 // The center point of the window can diverge this much from the center point
28 // If this is set to true, the window will get centered. 29 // If this is set to true, the window will get centered.
29 DEFINE_WINDOW_PROPERTY_KEY(bool, kCenteredKey, false); 30 DEFINE_WINDOW_PROPERTY_KEY(bool, kCenteredKey, false);
30 31
31 // The center point of the window can diverge this much from the center point 32 // The center point of the window can diverge this much from the center point
32 // of the container to be kept centered upon resizing operations. 33 // of the container to be kept centered upon resizing operations.
33 const int kCenterPixelDelta = 32; 34 const int kCenterPixelDelta = 32;
34 } 35 }
35 36
36 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
37 // SystemModalContainerLayoutManager, public: 38 // SystemModalContainerLayoutManager, public:
38 39
39 SystemModalContainerLayoutManager::SystemModalContainerLayoutManager( 40 SystemModalContainerLayoutManager::SystemModalContainerLayoutManager(
40 aura::Window* container) 41 aura::Window* container)
41 : SnapToPixelLayoutManager(container), 42 : SnapToPixelLayoutManager(container), container_(container) {}
42 container_(container),
43 modal_background_(nullptr) {}
44 43
45 SystemModalContainerLayoutManager::~SystemModalContainerLayoutManager() {} 44 SystemModalContainerLayoutManager::~SystemModalContainerLayoutManager() {}
46 45
47 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
48 // SystemModalContainerLayoutManager, aura::LayoutManager implementation: 47 // SystemModalContainerLayoutManager, aura::LayoutManager implementation:
49 48
50 void SystemModalContainerLayoutManager::OnWindowResized() { 49 void SystemModalContainerLayoutManager::OnWindowResized() {
51 PositionDialogsAfterWorkAreaResize(); 50 PositionDialogsAfterWorkAreaResize();
52 } 51 }
53 52
54 void SystemModalContainerLayoutManager::OnWindowAddedToLayout( 53 void SystemModalContainerLayoutManager::OnWindowAddedToLayout(
55 aura::Window* child) { 54 aura::Window* child) {
56 DCHECK(child == modal_background_ || 55 DCHECK(child->type() == ui::wm::WINDOW_TYPE_NORMAL ||
57 child->type() == ui::wm::WINDOW_TYPE_NORMAL ||
58 child->type() == ui::wm::WINDOW_TYPE_POPUP); 56 child->type() == ui::wm::WINDOW_TYPE_POPUP);
59 DCHECK( 57 DCHECK(
60 container_->id() != kShellWindowId_LockSystemModalContainer || 58 container_->id() != kShellWindowId_LockSystemModalContainer ||
61 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()); 59 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked());
62 // Since this is for SystemModal, there is no goodd reason to add 60 // Since this is for SystemModal, there is no goodd reason to add
63 // these window other than MODAL_TYPE_NONE or MODAL_TYPE_SYSTEM. 61 // these window other than MODAL_TYPE_NONE or MODAL_TYPE_SYSTEM.
64 // DCHECK to avoid simple mistake. 62 // DCHECK to avoid simple mistake.
65 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_CHILD); 63 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_CHILD);
66 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_WINDOW); 64 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_WINDOW);
67 65
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return; 99 return;
102 100
103 if (new_modal == ui::MODAL_TYPE_SYSTEM) { 101 if (new_modal == ui::MODAL_TYPE_SYSTEM) {
104 AddModalWindow(window); 102 AddModalWindow(window);
105 } else { 103 } else {
106 RemoveModalWindow(window); 104 RemoveModalWindow(window);
107 Shell::GetInstance()->OnModalWindowRemoved(window); 105 Shell::GetInstance()->OnModalWindowRemoved(window);
108 } 106 }
109 } 107 }
110 108
111 void SystemModalContainerLayoutManager::OnWindowDestroying(
112 aura::Window* window) {
113 if (modal_background_ == window) {
114 if (keyboard::KeyboardController::GetInstance())
115 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
116 modal_background_ = nullptr;
117 }
118 }
119
120 void SystemModalContainerLayoutManager::OnWindowVisibilityChanged( 109 void SystemModalContainerLayoutManager::OnWindowVisibilityChanged(
121 aura::Window* window, 110 aura::Window* window,
122 bool visible) { 111 bool visible) {
123 if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_SYSTEM) 112 if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_SYSTEM)
124 return; 113 return;
125 if (window->IsVisible()) { 114 if (window->IsVisible()) {
126 AddModalWindow(window); 115 AddModalWindow(window);
127 } else { 116 } else {
128 RemoveModalWindow(window); 117 RemoveModalWindow(window);
129 Shell::GetInstance()->OnModalWindowRemoved(window); 118 Shell::GetInstance()->OnModalWindowRemoved(window);
(...skipping 18 matching lines...) Expand all
148 } 137 }
149 138
150 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() { 139 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() {
151 if (modal_windows_.empty()) 140 if (modal_windows_.empty())
152 return false; 141 return false;
153 wm::ActivateWindow(modal_window()); 142 wm::ActivateWindow(modal_window());
154 return true; 143 return true;
155 } 144 }
156 145
157 void SystemModalContainerLayoutManager::CreateModalBackground() { 146 void SystemModalContainerLayoutManager::CreateModalBackground() {
158 if (!modal_background_) { 147 if (!window_dimmer_) {
159 modal_background_ = new DimWindow(container_); 148 window_dimmer_ =
160 modal_background_->SetName( 149 base::MakeUnique<WindowDimmer>(WmWindowAura::Get(container_));
150 window_dimmer_->window()->SetName(
161 "SystemModalContainerLayoutManager.ModalBackground"); 151 "SystemModalContainerLayoutManager.ModalBackground");
162 // There isn't always a keyboard controller. 152 // There isn't always a keyboard controller.
163 if (keyboard::KeyboardController::GetInstance()) 153 if (keyboard::KeyboardController::GetInstance())
164 keyboard::KeyboardController::GetInstance()->AddObserver(this); 154 keyboard::KeyboardController::GetInstance()->AddObserver(this);
165 } 155 }
166 modal_background_->Show(); 156 window_dimmer_->window()->Show();
167 } 157 }
168 158
169 void SystemModalContainerLayoutManager::DestroyModalBackground() { 159 void SystemModalContainerLayoutManager::DestroyModalBackground() {
170 // modal_background_ can be NULL when a root window is shutting down. 160 if (!window_dimmer_)
171 if (modal_background_) { 161 return;
172 if (keyboard::KeyboardController::GetInstance()) 162
173 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); 163 if (keyboard::KeyboardController::GetInstance())
174 modal_background_->Hide(); 164 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
175 // Explicitly delete instead of using scoped_ptr as the owner of the 165 window_dimmer_.reset();
176 // window is its parent.
177 delete modal_background_;
178 modal_background_ = nullptr;
179 }
180 } 166 }
181 167
182 // static 168 // static
183 bool SystemModalContainerLayoutManager::IsModalBackground( 169 bool SystemModalContainerLayoutManager::IsModalBackground(
184 aura::Window* window) { 170 aura::Window* window) {
185 int id = window->parent()->id(); 171 int id = window->parent()->id();
186 if (id != kShellWindowId_SystemModalContainer && 172 if (id != kShellWindowId_SystemModalContainer &&
187 id != kShellWindowId_LockSystemModalContainer) 173 id != kShellWindowId_LockSystemModalContainer)
188 return false; 174 return false;
189 SystemModalContainerLayoutManager* layout_manager = 175 SystemModalContainerLayoutManager* layout_manager =
190 static_cast<SystemModalContainerLayoutManager*>( 176 static_cast<SystemModalContainerLayoutManager*>(
191 window->parent()->layout_manager()); 177 window->parent()->layout_manager());
192 return layout_manager->modal_background_ == window; 178 return layout_manager->window_dimmer_ &&
179 layout_manager->window_dimmer_->window() == WmWindowAura::Get(window);
193 } 180 }
194 181
195 //////////////////////////////////////////////////////////////////////////////// 182 ////////////////////////////////////////////////////////////////////////////////
196 // SystemModalContainerLayoutManager, private: 183 // SystemModalContainerLayoutManager, private:
197 184
198 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) { 185 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) {
199 if (modal_windows_.empty()) { 186 if (modal_windows_.empty()) {
200 aura::Window* capture_window = aura::client::GetCaptureWindow(container_); 187 aura::Window* capture_window = aura::client::GetCaptureWindow(container_);
201 if (capture_window) 188 if (capture_window)
202 capture_window->ReleaseCapture(); 189 capture_window->ReleaseCapture();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 bool SystemModalContainerLayoutManager::DialogIsCentered( 259 bool SystemModalContainerLayoutManager::DialogIsCentered(
273 const gfx::Rect& window_bounds) { 260 const gfx::Rect& window_bounds) {
274 gfx::Point window_center = window_bounds.CenterPoint(); 261 gfx::Point window_center = window_bounds.CenterPoint();
275 gfx::Point container_center = GetUsableDialogArea().CenterPoint(); 262 gfx::Point container_center = GetUsableDialogArea().CenterPoint();
276 return std::abs(window_center.x() - container_center.x()) < 263 return std::abs(window_center.x() - container_center.x()) <
277 kCenterPixelDelta && 264 kCenterPixelDelta &&
278 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta; 265 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta;
279 } 266 }
280 267
281 } // namespace ash 268 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/system_modal_container_layout_manager.h ('k') | ash/wm/system_modal_container_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698