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

Side by Side Diff: ash/wm/system_modal_container_layout_manager.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 (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((window_dimmer_ &&
56 WmWindowAura::Get(child) == window_dimmer_->window()) ||
57 child->type() == ui::wm::WINDOW_TYPE_NORMAL || 57 child->type() == ui::wm::WINDOW_TYPE_NORMAL ||
58 child->type() == ui::wm::WINDOW_TYPE_POPUP); 58 child->type() == ui::wm::WINDOW_TYPE_POPUP);
59 DCHECK( 59 DCHECK(
60 container_->id() != kShellWindowId_LockSystemModalContainer || 60 container_->id() != kShellWindowId_LockSystemModalContainer ||
61 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()); 61 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked());
62 // Since this is for SystemModal, there is no goodd reason to add 62 // Since this is for SystemModal, there is no goodd reason to add
63 // these window other than MODAL_TYPE_NONE or MODAL_TYPE_SYSTEM. 63 // these window other than MODAL_TYPE_NONE or MODAL_TYPE_SYSTEM.
64 // DCHECK to avoid simple mistake. 64 // DCHECK to avoid simple mistake.
65 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_CHILD); 65 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_CHILD);
66 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_WINDOW); 66 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_WINDOW);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (new_modal == ui::MODAL_TYPE_SYSTEM) { 103 if (new_modal == ui::MODAL_TYPE_SYSTEM) {
104 AddModalWindow(window); 104 AddModalWindow(window);
105 } else { 105 } else {
106 RemoveModalWindow(window); 106 RemoveModalWindow(window);
107 Shell::GetInstance()->OnModalWindowRemoved(window); 107 Shell::GetInstance()->OnModalWindowRemoved(window);
108 } 108 }
109 } 109 }
110 110
111 void SystemModalContainerLayoutManager::OnWindowDestroying( 111 void SystemModalContainerLayoutManager::OnWindowDestroying(
112 aura::Window* window) { 112 aura::Window* window) {
113 if (modal_background_ == window) { 113 if (!window_dimmer_ || window_dimmer_->window() != WmWindowAura::Get(window))
114 if (keyboard::KeyboardController::GetInstance()) 114 return;
115 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); 115
116 modal_background_ = nullptr; 116 if (keyboard::KeyboardController::GetInstance())
117 } 117 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
118 window_dimmer_ = nullptr;
118 } 119 }
119 120
120 void SystemModalContainerLayoutManager::OnWindowVisibilityChanged( 121 void SystemModalContainerLayoutManager::OnWindowVisibilityChanged(
121 aura::Window* window, 122 aura::Window* window,
122 bool visible) { 123 bool visible) {
123 if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_SYSTEM) 124 if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_SYSTEM)
124 return; 125 return;
125 if (window->IsVisible()) { 126 if (window->IsVisible()) {
126 AddModalWindow(window); 127 AddModalWindow(window);
127 } else { 128 } else {
(...skipping 20 matching lines...) Expand all
148 } 149 }
149 150
150 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() { 151 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() {
151 if (modal_windows_.empty()) 152 if (modal_windows_.empty())
152 return false; 153 return false;
153 wm::ActivateWindow(modal_window()); 154 wm::ActivateWindow(modal_window());
154 return true; 155 return true;
155 } 156 }
156 157
157 void SystemModalContainerLayoutManager::CreateModalBackground() { 158 void SystemModalContainerLayoutManager::CreateModalBackground() {
158 if (!modal_background_) { 159 if (!window_dimmer_) {
159 modal_background_ = new DimWindow(container_); 160 window_dimmer_ = new WindowDimmer(WmWindowAura::Get(container_));
160 modal_background_->SetName( 161 window_dimmer_->window()->SetName(
161 "SystemModalContainerLayoutManager.ModalBackground"); 162 "SystemModalContainerLayoutManager.ModalBackground");
162 // There isn't always a keyboard controller. 163 // There isn't always a keyboard controller.
163 if (keyboard::KeyboardController::GetInstance()) 164 if (keyboard::KeyboardController::GetInstance())
164 keyboard::KeyboardController::GetInstance()->AddObserver(this); 165 keyboard::KeyboardController::GetInstance()->AddObserver(this);
165 } 166 }
166 modal_background_->Show(); 167 window_dimmer_->window()->Show();
167 } 168 }
168 169
169 void SystemModalContainerLayoutManager::DestroyModalBackground() { 170 void SystemModalContainerLayoutManager::DestroyModalBackground() {
170 // modal_background_ can be NULL when a root window is shutting down. 171 // |window_dimmer_| can be null when a root window is shutting down.
171 if (modal_background_) { 172 if (!window_dimmer_)
172 if (keyboard::KeyboardController::GetInstance()) 173 return;
173 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); 174
174 modal_background_->Hide(); 175 if (keyboard::KeyboardController::GetInstance())
175 // Explicitly delete instead of using scoped_ptr as the owner of the 176 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
176 // window is its parent. 177 // Destroy() triggers deletion.
177 delete modal_background_; 178 window_dimmer_->Destroy();
178 modal_background_ = nullptr; 179 DCHECK(!window_dimmer_);
179 }
180 } 180 }
181 181
182 // static 182 // static
183 bool SystemModalContainerLayoutManager::IsModalBackground( 183 bool SystemModalContainerLayoutManager::IsModalBackground(
184 aura::Window* window) { 184 aura::Window* window) {
185 int id = window->parent()->id(); 185 int id = window->parent()->id();
186 if (id != kShellWindowId_SystemModalContainer && 186 if (id != kShellWindowId_SystemModalContainer &&
187 id != kShellWindowId_LockSystemModalContainer) 187 id != kShellWindowId_LockSystemModalContainer)
188 return false; 188 return false;
189 SystemModalContainerLayoutManager* layout_manager = 189 SystemModalContainerLayoutManager* layout_manager =
190 static_cast<SystemModalContainerLayoutManager*>( 190 static_cast<SystemModalContainerLayoutManager*>(
191 window->parent()->layout_manager()); 191 window->parent()->layout_manager());
192 return layout_manager->modal_background_ == window; 192 return layout_manager->window_dimmer_ &&
193 layout_manager->window_dimmer_->window() == WmWindowAura::Get(window);
193 } 194 }
194 195
195 //////////////////////////////////////////////////////////////////////////////// 196 ////////////////////////////////////////////////////////////////////////////////
196 // SystemModalContainerLayoutManager, private: 197 // SystemModalContainerLayoutManager, private:
197 198
198 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) { 199 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) {
199 if (modal_windows_.empty()) { 200 if (modal_windows_.empty()) {
200 aura::Window* capture_window = aura::client::GetCaptureWindow(container_); 201 aura::Window* capture_window = aura::client::GetCaptureWindow(container_);
201 if (capture_window) 202 if (capture_window)
202 capture_window->ReleaseCapture(); 203 capture_window->ReleaseCapture();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 bool SystemModalContainerLayoutManager::DialogIsCentered( 273 bool SystemModalContainerLayoutManager::DialogIsCentered(
273 const gfx::Rect& window_bounds) { 274 const gfx::Rect& window_bounds) {
274 gfx::Point window_center = window_bounds.CenterPoint(); 275 gfx::Point window_center = window_bounds.CenterPoint();
275 gfx::Point container_center = GetUsableDialogArea().CenterPoint(); 276 gfx::Point container_center = GetUsableDialogArea().CenterPoint();
276 return std::abs(window_center.x() - container_center.x()) < 277 return std::abs(window_center.x() - container_center.x()) <
277 kCenterPixelDelta && 278 kCenterPixelDelta &&
278 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta; 279 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta;
279 } 280 }
280 281
281 } // namespace ash 282 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698