Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // There is no reason to add these modal window in this container. | |
| 61 // DCHECK to avoid simple mistake. | |
|
James Cook
2016/06/27 00:33:43
optional: Maybe add a line to the header file clas
oshima
2016/06/27 02:26:07
Done.
| |
| 62 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_CHILD); | |
| 63 DCHECK_NE(child->GetProperty(aura::client::kModalKey), ui::MODAL_TYPE_WINDOW); | |
| 60 | 64 |
| 61 child->AddObserver(this); | 65 child->AddObserver(this); |
| 62 if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) | 66 if (child->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM && |
| 67 child->IsVisible()) { | |
| 63 AddModalWindow(child); | 68 AddModalWindow(child); |
| 69 } | |
| 64 } | 70 } |
| 65 | 71 |
| 66 void SystemModalContainerLayoutManager::OnWillRemoveWindowFromLayout( | 72 void SystemModalContainerLayoutManager::OnWillRemoveWindowFromLayout( |
| 67 aura::Window* child) { | 73 aura::Window* child) { |
| 68 child->RemoveObserver(this); | 74 child->RemoveObserver(this); |
| 69 if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) | 75 if (child->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM) |
| 70 RemoveModalWindow(child); | 76 RemoveModalWindow(child); |
| 71 } | 77 } |
| 72 | 78 |
| 73 void SystemModalContainerLayoutManager::SetChildBounds( | 79 void SystemModalContainerLayoutManager::SetChildBounds( |
| 74 aura::Window* child, | 80 aura::Window* child, |
| 75 const gfx::Rect& requested_bounds) { | 81 const gfx::Rect& requested_bounds) { |
| 76 SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds); | 82 SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds); |
| 77 child->SetProperty(kCenteredKey, DialogIsCentered(requested_bounds)); | 83 child->SetProperty(kCenteredKey, DialogIsCentered(requested_bounds)); |
| 78 } | 84 } |
| 79 | 85 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
| 81 // SystemModalContainerLayoutManager, aura::WindowObserver implementation: | 87 // SystemModalContainerLayoutManager, aura::WindowObserver implementation: |
| 82 | 88 |
| 83 void SystemModalContainerLayoutManager::OnWindowPropertyChanged( | 89 void SystemModalContainerLayoutManager::OnWindowPropertyChanged( |
| 84 aura::Window* window, | 90 aura::Window* window, |
| 85 const void* key, | 91 const void* key, |
| 86 intptr_t old) { | 92 intptr_t old) { |
| 87 if (key != aura::client::kModalKey) | 93 if (key != aura::client::kModalKey || !window->IsVisible()) |
| 88 return; | 94 return; |
| 89 | 95 |
| 90 ui::ModalType new_modal = window->GetProperty(aura::client::kModalKey); | 96 ui::ModalType new_modal = window->GetProperty(aura::client::kModalKey); |
| 91 if (static_cast<ui::ModalType>(old) == new_modal) | 97 if (static_cast<ui::ModalType>(old) == new_modal) |
| 92 return; | 98 return; |
| 93 | 99 |
| 94 if (new_modal != ui::MODAL_TYPE_NONE) { | 100 if (new_modal == ui::MODAL_TYPE_SYSTEM) { |
| 95 AddModalWindow(window); | 101 AddModalWindow(window); |
| 96 } else { | 102 } else { |
| 97 RemoveModalWindow(window); | 103 RemoveModalWindow(window); |
| 98 Shell::GetInstance()->OnModalWindowRemoved(window); | 104 Shell::GetInstance()->OnModalWindowRemoved(window); |
| 99 } | 105 } |
| 100 } | 106 } |
| 101 | 107 |
| 102 void SystemModalContainerLayoutManager::OnWindowDestroying( | 108 void SystemModalContainerLayoutManager::OnWindowDestroying( |
| 103 aura::Window* window) { | 109 aura::Window* window) { |
| 104 if (modal_background_ == window) { | 110 if (modal_background_ == window) { |
| 105 if (keyboard::KeyboardController::GetInstance()) | 111 if (keyboard::KeyboardController::GetInstance()) |
| 106 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | 112 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); |
| 107 modal_background_ = nullptr; | 113 modal_background_ = nullptr; |
| 108 } | 114 } |
| 109 } | 115 } |
| 110 | 116 |
| 117 void SystemModalContainerLayoutManager::OnWindowVisibilityChanged( | |
| 118 aura::Window* window, | |
| 119 bool visible) { | |
| 120 if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_SYSTEM) | |
| 121 return; | |
| 122 if (window->IsVisible()) { | |
| 123 AddModalWindow(window); | |
| 124 } else { | |
| 125 RemoveModalWindow(window); | |
| 126 Shell::GetInstance()->OnModalWindowRemoved(window); | |
| 127 } | |
| 128 } | |
| 129 | |
| 111 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
| 112 // SystemModalContainerLayoutManager, Keyboard::KeybaordControllerObserver | 131 // SystemModalContainerLayoutManager, Keyboard::KeybaordControllerObserver |
| 113 // implementation: | 132 // implementation: |
| 114 | 133 |
| 115 void SystemModalContainerLayoutManager::OnKeyboardBoundsChanging( | 134 void SystemModalContainerLayoutManager::OnKeyboardBoundsChanging( |
| 116 const gfx::Rect& new_bounds) { | 135 const gfx::Rect& new_bounds) { |
| 117 PositionDialogsAfterWorkAreaResize(); | 136 PositionDialogsAfterWorkAreaResize(); |
| 118 } | 137 } |
| 119 | 138 |
| 120 bool SystemModalContainerLayoutManager::IsPartOfActiveModalWindow( | 139 bool SystemModalContainerLayoutManager::IsPartOfActiveModalWindow( |
| 121 aura::Window* window) { | 140 aura::Window* window) { |
| 122 return modal_window() && wm::GetActivatableWindow(window) == modal_window(); | 141 return modal_window() && modal_window()->Contains(window); |
| 123 } | 142 } |
| 124 | 143 |
| 125 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() { | 144 bool SystemModalContainerLayoutManager::ActivateNextModalWindow() { |
| 126 if (modal_windows_.empty()) | 145 if (modal_windows_.empty()) |
| 127 return false; | 146 return false; |
| 128 wm::ActivateWindow(modal_window()); | 147 wm::ActivateWindow(modal_window()); |
| 129 return true; | 148 return true; |
| 130 } | 149 } |
| 131 | 150 |
| 132 void SystemModalContainerLayoutManager::CreateModalBackground() { | 151 void SystemModalContainerLayoutManager::CreateModalBackground() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 188 |
| 170 //////////////////////////////////////////////////////////////////////////////// | 189 //////////////////////////////////////////////////////////////////////////////// |
| 171 // SystemModalContainerLayoutManager, private: | 190 // SystemModalContainerLayoutManager, private: |
| 172 | 191 |
| 173 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) { | 192 void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) { |
| 174 if (modal_windows_.empty()) { | 193 if (modal_windows_.empty()) { |
| 175 aura::Window* capture_window = aura::client::GetCaptureWindow(container_); | 194 aura::Window* capture_window = aura::client::GetCaptureWindow(container_); |
| 176 if (capture_window) | 195 if (capture_window) |
| 177 capture_window->ReleaseCapture(); | 196 capture_window->ReleaseCapture(); |
| 178 } | 197 } |
| 198 DCHECK(window->IsVisible()); | |
|
James Cook
2016/06/27 00:33:43
Thanks for adding all the DCHECKs. It makes the co
| |
| 179 DCHECK(!ContainsValue(modal_windows_, window)); | 199 DCHECK(!ContainsValue(modal_windows_, window)); |
| 180 | 200 |
| 181 modal_windows_.push_back(window); | 201 modal_windows_.push_back(window); |
| 182 Shell::GetInstance()->CreateModalBackground(window); | 202 Shell::GetInstance()->CreateModalBackground(window); |
| 183 window->parent()->StackChildAtTop(window); | 203 window->parent()->StackChildAtTop(window); |
| 184 | 204 |
| 185 gfx::Rect target_bounds = window->bounds(); | 205 gfx::Rect target_bounds = window->bounds(); |
| 186 target_bounds.AdjustToFit(GetUsableDialogArea()); | 206 target_bounds.AdjustToFit(GetUsableDialogArea()); |
| 187 window->SetBounds(target_bounds); | 207 window->SetBounds(target_bounds); |
| 188 } | 208 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 bool SystemModalContainerLayoutManager::DialogIsCentered( | 266 bool SystemModalContainerLayoutManager::DialogIsCentered( |
| 247 const gfx::Rect& window_bounds) { | 267 const gfx::Rect& window_bounds) { |
| 248 gfx::Point window_center = window_bounds.CenterPoint(); | 268 gfx::Point window_center = window_bounds.CenterPoint(); |
| 249 gfx::Point container_center = GetUsableDialogArea().CenterPoint(); | 269 gfx::Point container_center = GetUsableDialogArea().CenterPoint(); |
| 250 return std::abs(window_center.x() - container_center.x()) < | 270 return std::abs(window_center.x() - container_center.x()) < |
| 251 kCenterPixelDelta && | 271 kCenterPixelDelta && |
| 252 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta; | 272 std::abs(window_center.y() - container_center.y()) < kCenterPixelDelta; |
| 253 } | 273 } |
| 254 | 274 |
| 255 } // namespace ash | 275 } // namespace ash |
| OLD | NEW |