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

Side by Side Diff: ash/wm/system_modal_container_layout_manager.cc

Issue 2098183002: Make system modal check more strict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed cut Created 4 years, 5 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/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shell_window_ids.h" 10 #include "ash/common/shell_window_ids.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 void SystemModalContainerLayoutManager::OnWindowAddedToLayout( 52 void SystemModalContainerLayoutManager::OnWindowAddedToLayout(
53 aura::Window* child) { 53 aura::Window* child) {
54 DCHECK(child == modal_background_ || 54 DCHECK(child == modal_background_ ||
55 child->type() == ui::wm::WINDOW_TYPE_NORMAL || 55 child->type() == ui::wm::WINDOW_TYPE_NORMAL ||
56 child->type() == ui::wm::WINDOW_TYPE_POPUP); 56 child->type() == ui::wm::WINDOW_TYPE_POPUP);
57 DCHECK( 57 DCHECK(
58 container_->id() != kShellWindowId_LockSystemModalContainer || 58 container_->id() != kShellWindowId_LockSystemModalContainer ||
59 Shell::GetInstance()->session_state_delegate()->IsUserSessionBlocked()); 59 Shell::GetInstance()->session_state_delegate()->IsUserSessionBlocked());
60 // Since this is for SystemModal, there is no goodd reason to add
61 // these window other than MODAL_TYPE_NONE or MODAL_TYPE_SYSTEM.
62 // DCHECK to avoid simple mistake.
63 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_CHILD);
64 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_WINDOW);
60 65
61 child->AddObserver(this); 66 child->AddObserver(this);
62 if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) 67 if (child->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM &&
68 child->IsVisible()) {
63 AddModalWindow(child); 69 AddModalWindow(child);
70 }
64 } 71 }
65 72
66 void SystemModalContainerLayoutManager::OnWillRemoveWindowFromLayout( 73 void SystemModalContainerLayoutManager::OnWillRemoveWindowFromLayout(
67 aura::Window* child) { 74 aura::Window* child) {
68 child->RemoveObserver(this); 75 child->RemoveObserver(this);
69 if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) 76 if (child->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM)
70 RemoveModalWindow(child); 77 RemoveModalWindow(child);
71 } 78 }
72 79
73 void SystemModalContainerLayoutManager::SetChildBounds( 80 void SystemModalContainerLayoutManager::SetChildBounds(
74 aura::Window* child, 81 aura::Window* child,
75 const gfx::Rect& requested_bounds) { 82 const gfx::Rect& requested_bounds) {
76 SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds); 83 SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
77 child->SetProperty(kCenteredKey, DialogIsCentered(requested_bounds)); 84 child->SetProperty(kCenteredKey, DialogIsCentered(requested_bounds));
78 } 85 }
79 86
80 //////////////////////////////////////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////////////////
81 // SystemModalContainerLayoutManager, aura::WindowObserver implementation: 88 // SystemModalContainerLayoutManager, aura::WindowObserver implementation:
82 89
83 void SystemModalContainerLayoutManager::OnWindowPropertyChanged( 90 void SystemModalContainerLayoutManager::OnWindowPropertyChanged(
84 aura::Window* window, 91 aura::Window* window,
85 const void* key, 92 const void* key,
86 intptr_t old) { 93 intptr_t old) {
87 if (key != aura::client::kModalKey) 94 if (key != aura::client::kModalKey || !window->IsVisible())
88 return; 95 return;
89 96
90 ui::ModalType new_modal = window->GetProperty(aura::client::kModalKey); 97 ui::ModalType new_modal = window->GetProperty(aura::client::kModalKey);
91 if (static_cast<ui::ModalType>(old) == new_modal) 98 if (static_cast<ui::ModalType>(old) == new_modal)
92 return; 99 return;
93 100
94 if (new_modal != ui::MODAL_TYPE_NONE) { 101 if (new_modal == ui::MODAL_TYPE_SYSTEM) {
95 AddModalWindow(window); 102 AddModalWindow(window);
96 } else { 103 } else {
97 RemoveModalWindow(window); 104 RemoveModalWindow(window);
98 Shell::GetInstance()->OnModalWindowRemoved(window); 105 Shell::GetInstance()->OnModalWindowRemoved(window);
99 } 106 }
100 } 107 }
101 108
102 void SystemModalContainerLayoutManager::OnWindowDestroying( 109 void SystemModalContainerLayoutManager::OnWindowDestroying(
103 aura::Window* window) { 110 aura::Window* window) {
104 if (modal_background_ == window) { 111 if (modal_background_ == window) {
105 if (keyboard::KeyboardController::GetInstance()) 112 if (keyboard::KeyboardController::GetInstance())
106 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); 113 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
107 modal_background_ = nullptr; 114 modal_background_ = nullptr;
108 } 115 }
109 } 116 }
110 117
118 void SystemModalContainerLayoutManager::OnWindowVisibilityChanged(
119 aura::Window* window,
120 bool visible) {
121 if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_SYSTEM)
122 return;
123 if (window->IsVisible()) {
124 AddModalWindow(window);
125 } else {
126 RemoveModalWindow(window);
127 Shell::GetInstance()->OnModalWindowRemoved(window);
128 }
129 }
130
111 //////////////////////////////////////////////////////////////////////////////// 131 ////////////////////////////////////////////////////////////////////////////////
112 // SystemModalContainerLayoutManager, Keyboard::KeybaordControllerObserver 132 // SystemModalContainerLayoutManager, Keyboard::KeybaordControllerObserver
113 // implementation: 133 // implementation:
114 134
115 void SystemModalContainerLayoutManager::OnKeyboardBoundsChanging( 135 void SystemModalContainerLayoutManager::OnKeyboardBoundsChanging(
116 const gfx::Rect& new_bounds) { 136 const gfx::Rect& new_bounds) {
117 PositionDialogsAfterWorkAreaResize(); 137 PositionDialogsAfterWorkAreaResize();
118 } 138 }
119 139
120 bool SystemModalContainerLayoutManager::IsPartOfActiveModalWindow( 140 bool SystemModalContainerLayoutManager::IsPartOfActiveModalWindow(
121 aura::Window* window) { 141 aura::Window* window) {
122 return modal_window() && wm::GetActivatableWindow(window) == modal_window(); 142 return modal_window() && modal_window()->Contains(window);
123 } 143 }
124 144
125 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() { 145 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() {
126 if (modal_windows_.empty()) 146 if (modal_windows_.empty())
127 return false; 147 return false;
128 wm::ActivateWindow(modal_window()); 148 wm::ActivateWindow(modal_window());
129 return true; 149 return true;
130 } 150 }
131 151
132 void SystemModalContainerLayoutManager::CreateModalBackground() { 152 void SystemModalContainerLayoutManager::CreateModalBackground() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 189
170 //////////////////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////////////////
171 // SystemModalContainerLayoutManager, private: 191 // SystemModalContainerLayoutManager, private:
172 192
173 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) { 193 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) {
174 if (modal_windows_.empty()) { 194 if (modal_windows_.empty()) {
175 aura::Window* capture_window = aura::client::GetCaptureWindow(container_); 195 aura::Window* capture_window = aura::client::GetCaptureWindow(container_);
176 if (capture_window) 196 if (capture_window)
177 capture_window->ReleaseCapture(); 197 capture_window->ReleaseCapture();
178 } 198 }
199 DCHECK(window->IsVisible());
179 DCHECK(!ContainsValue(modal_windows_, window)); 200 DCHECK(!ContainsValue(modal_windows_, window));
180 201
181 modal_windows_.push_back(window); 202 modal_windows_.push_back(window);
182 Shell::GetInstance()->CreateModalBackground(window); 203 Shell::GetInstance()->CreateModalBackground(window);
183 window->parent()->StackChildAtTop(window); 204 window->parent()->StackChildAtTop(window);
184 205
185 gfx::Rect target_bounds = window->bounds(); 206 gfx::Rect target_bounds = window->bounds();
186 target_bounds.AdjustToFit(GetUsableDialogArea()); 207 target_bounds.AdjustToFit(GetUsableDialogArea());
187 window->SetBounds(target_bounds); 208 window->SetBounds(target_bounds);
188 } 209 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 bool SystemModalContainerLayoutManager::DialogIsCentered( 267 bool SystemModalContainerLayoutManager::DialogIsCentered(
247 const gfx::Rect& window_bounds) { 268 const gfx::Rect& window_bounds) {
248 gfx::Point window_center = window_bounds.CenterPoint(); 269 gfx::Point window_center = window_bounds.CenterPoint();
249 gfx::Point container_center = GetUsableDialogArea().CenterPoint(); 270 gfx::Point container_center = GetUsableDialogArea().CenterPoint();
250 return std::abs(window_center.x() - container_center.x()) < 271 return std::abs(window_center.x() - container_center.x()) <
251 kCenterPixelDelta && 272 kCenterPixelDelta &&
252 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta; 273 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta;
253 } 274 }
254 275
255 } // namespace ash 276 } // 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