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 "ui/views/corewm/window_modality_controller.h" | 5 #include "ui/views/corewm/window_modality_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
10 #include "ui/aura/client/capture_client.h" | 10 #include "ui/aura/client/capture_client.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return transient->IsVisible() && | 56 return transient->IsVisible() && |
57 (TransientChildIsWindowModal(transient) || | 57 (TransientChildIsWindowModal(transient) || |
58 TransientChildIsSystemModal(transient) || | 58 TransientChildIsSystemModal(transient) || |
59 (TransientChildIsChildModal(transient) && | 59 (TransientChildIsChildModal(transient) && |
60 (HasAncestor(original, GetModalParent(transient))))); | 60 (HasAncestor(original, GetModalParent(transient))))); |
61 } | 61 } |
62 | 62 |
63 aura::Window* GetModalTransientChild( | 63 aura::Window* GetModalTransientChild( |
64 aura::Window* activatable, | 64 aura::Window* activatable, |
65 aura::Window* original) { | 65 aura::Window* original) { |
66 aura::Window::Windows::const_iterator it; | 66 for (aura::Window::Windows::const_iterator it = |
67 for (it = activatable->transient_children().begin(); | 67 GetTransientChildren(activatable).begin(); |
68 it != activatable->transient_children().end(); | 68 it != GetTransientChildren(activatable).end(); |
69 ++it) { | 69 ++it) { |
70 aura::Window* transient = *it; | 70 aura::Window* transient = *it; |
71 if (IsModalTransientChild(transient, original)) { | 71 if (IsModalTransientChild(transient, original)) { |
72 return transient->transient_children().empty() ? | 72 return GetTransientChildren(transient).empty() ? |
73 transient : GetModalTransientChild(transient, original); | 73 transient : GetModalTransientChild(transient, original); |
74 } | 74 } |
75 } | 75 } |
76 return NULL; | 76 return NULL; |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 void SetModalParent(aura::Window* child, aura::Window* parent) { | 81 void SetModalParent(aura::Window* child, aura::Window* parent) { |
82 child->SetProperty(kModalParentKey, parent); | 82 child->SetProperty(kModalParentKey, parent); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 void WindowModalityController::OnWindowPropertyChanged(aura::Window* window, | 147 void WindowModalityController::OnWindowPropertyChanged(aura::Window* window, |
148 const void* key, | 148 const void* key, |
149 intptr_t old) { | 149 intptr_t old) { |
150 // In tests, we sometimes create the modality relationship after a window is | 150 // In tests, we sometimes create the modality relationship after a window is |
151 // visible. | 151 // visible. |
152 if (key == aura::client::kModalKey && | 152 if (key == aura::client::kModalKey && |
153 window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE && | 153 window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE && |
154 window->IsVisible()) { | 154 window->IsVisible()) { |
155 ActivateWindow(window); | 155 ActivateWindow(window); |
156 ui::GestureRecognizer::Get()->TransferEventsTo( | 156 ui::GestureRecognizer::Get()->TransferEventsTo(GetTransientParent(window), |
157 window->transient_parent(), NULL); | 157 NULL); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 void WindowModalityController::OnWindowVisibilityChanged( | 161 void WindowModalityController::OnWindowVisibilityChanged( |
162 aura::Window* window, | 162 aura::Window* window, |
163 bool visible) { | 163 bool visible) { |
164 if (visible && window->GetProperty(aura::client::kModalKey) != | 164 if (visible && window->GetProperty(aura::client::kModalKey) != |
165 ui::MODAL_TYPE_NONE) { | 165 ui::MODAL_TYPE_NONE) { |
166 ui::GestureRecognizer::Get()->TransferEventsTo( | 166 ui::GestureRecognizer::Get()->TransferEventsTo(GetTransientParent(window), |
167 window->transient_parent(), NULL); | 167 NULL); |
168 // Make sure no other window has capture, otherwise |window| won't get mouse | 168 // Make sure no other window has capture, otherwise |window| won't get mouse |
169 // events. | 169 // events. |
170 aura::Window* capture_window = aura::client::GetCaptureWindow(window); | 170 aura::Window* capture_window = aura::client::GetCaptureWindow(window); |
171 if (capture_window) | 171 if (capture_window) |
172 capture_window->ReleaseCapture(); | 172 capture_window->ReleaseCapture(); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { | 176 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { |
177 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); | 177 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
178 window->RemoveObserver(this); | 178 window->RemoveObserver(this); |
179 } | 179 } |
180 | 180 |
181 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, | 181 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, |
182 ui::LocatedEvent* event) { | 182 ui::LocatedEvent* event) { |
183 if (event->handled()) | 183 if (event->handled()) |
184 return false; | 184 return false; |
185 aura::Window* modal_transient_child = GetModalTransient(target); | 185 aura::Window* modal_transient_child = GetModalTransient(target); |
186 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || | 186 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || |
187 event->type() == ui::ET_TOUCH_PRESSED)) { | 187 event->type() == ui::ET_TOUCH_PRESSED)) { |
188 AnimateWindow(modal_transient_child, WINDOW_ANIMATION_TYPE_BOUNCE); | 188 AnimateWindow(modal_transient_child, WINDOW_ANIMATION_TYPE_BOUNCE); |
189 } | 189 } |
190 if (event->type() == ui::ET_TOUCH_CANCELLED) | 190 if (event->type() == ui::ET_TOUCH_CANCELLED) |
191 return false; | 191 return false; |
192 return !!modal_transient_child; | 192 return !!modal_transient_child; |
193 } | 193 } |
194 | 194 |
195 } // namespace corewm | 195 } // namespace corewm |
196 } // namespace views | 196 } // namespace views |
OLD | NEW |