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

Side by Side Diff: ui/views/corewm/window_modality_controller.cc

Issue 115453004: Moves management of transients out of Window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix MRUWindowTracker and MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest Created 7 years 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 | Annotate | Revision Log
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 "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"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura/window_property.h" 14 #include "ui/aura/window_property.h"
15 #include "ui/base/ui_base_types.h" 15 #include "ui/base/ui_base_types.h"
16 #include "ui/events/event.h" 16 #include "ui/events/event.h"
17 #include "ui/events/event_target.h" 17 #include "ui/events/event_target.h"
18 #include "ui/events/gestures/gesture_recognizer.h" 18 #include "ui/events/gestures/gesture_recognizer.h"
19 #include "ui/views/corewm/transient_window_manager.h"
19 #include "ui/views/corewm/window_animations.h" 20 #include "ui/views/corewm/window_animations.h"
20 #include "ui/views/corewm/window_util.h" 21 #include "ui/views/corewm/window_util.h"
21 22
22 namespace views { 23 namespace views {
23 namespace corewm { 24 namespace corewm {
24 25
25 // Transient child's modal parent. 26 // Transient child's modal parent.
26 extern const aura::WindowProperty<aura::Window*>* const kModalParentKey; 27 extern const aura::WindowProperty<aura::Window*>* const kModalParentKey;
27 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kModalParentKey, NULL); 28 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kModalParentKey, NULL);
28 29
(...skipping 27 matching lines...) Expand all
56 return transient->IsVisible() && 57 return transient->IsVisible() &&
57 (TransientChildIsWindowModal(transient) || 58 (TransientChildIsWindowModal(transient) ||
58 TransientChildIsSystemModal(transient) || 59 TransientChildIsSystemModal(transient) ||
59 (TransientChildIsChildModal(transient) && 60 (TransientChildIsChildModal(transient) &&
60 (HasAncestor(original, GetModalParent(transient))))); 61 (HasAncestor(original, GetModalParent(transient)))));
61 } 62 }
62 63
63 aura::Window* GetModalTransientChild( 64 aura::Window* GetModalTransientChild(
64 aura::Window* activatable, 65 aura::Window* activatable,
65 aura::Window* original) { 66 aura::Window* original) {
66 aura::Window::Windows::const_iterator it; 67 for (aura::Window::Windows::const_iterator it =
67 for (it = activatable->transient_children().begin(); 68 GetTransientChildren(activatable).begin();
68 it != activatable->transient_children().end(); 69 it != GetTransientChildren(activatable).end();
69 ++it) { 70 ++it) {
70 aura::Window* transient = *it; 71 aura::Window* transient = *it;
71 if (IsModalTransientChild(transient, original)) { 72 if (IsModalTransientChild(transient, original)) {
72 return transient->transient_children().empty() ? 73 return GetTransientChildren(transient).empty() ?
73 transient : GetModalTransientChild(transient, original); 74 transient : GetModalTransientChild(transient, original);
74 } 75 }
75 } 76 }
76 return NULL; 77 return NULL;
77 } 78 }
78 79
79 } // namespace 80 } // namespace
80 81
81 void SetModalParent(aura::Window* child, aura::Window* parent) { 82 void SetModalParent(aura::Window* child, aura::Window* parent) {
82 child->SetProperty(kModalParentKey, parent); 83 child->SetProperty(kModalParentKey, parent);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 147
147 void WindowModalityController::OnWindowPropertyChanged(aura::Window* window, 148 void WindowModalityController::OnWindowPropertyChanged(aura::Window* window,
148 const void* key, 149 const void* key,
149 intptr_t old) { 150 intptr_t old) {
150 // In tests, we sometimes create the modality relationship after a window is 151 // In tests, we sometimes create the modality relationship after a window is
151 // visible. 152 // visible.
152 if (key == aura::client::kModalKey && 153 if (key == aura::client::kModalKey &&
153 window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE && 154 window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE &&
154 window->IsVisible()) { 155 window->IsVisible()) {
155 ActivateWindow(window); 156 ActivateWindow(window);
156 ui::GestureRecognizer::Get()->TransferEventsTo( 157 ui::GestureRecognizer::Get()->TransferEventsTo(GetTransientParent(window),
157 window->transient_parent(), NULL); 158 NULL);
158 } 159 }
159 } 160 }
160 161
161 void WindowModalityController::OnWindowVisibilityChanged( 162 void WindowModalityController::OnWindowVisibilityChanged(
162 aura::Window* window, 163 aura::Window* window,
163 bool visible) { 164 bool visible) {
164 if (visible && window->GetProperty(aura::client::kModalKey) != 165 if (visible && window->GetProperty(aura::client::kModalKey) !=
165 ui::MODAL_TYPE_NONE) { 166 ui::MODAL_TYPE_NONE) {
166 ui::GestureRecognizer::Get()->TransferEventsTo( 167 ui::GestureRecognizer::Get()->TransferEventsTo(GetTransientParent(window),
167 window->transient_parent(), NULL); 168 NULL);
168 // Make sure no other window has capture, otherwise |window| won't get mouse 169 // Make sure no other window has capture, otherwise |window| won't get mouse
169 // events. 170 // events.
170 aura::Window* capture_window = aura::client::GetCaptureWindow(window); 171 aura::Window* capture_window = aura::client::GetCaptureWindow(window);
171 if (capture_window) 172 if (capture_window)
172 capture_window->ReleaseCapture(); 173 capture_window->ReleaseCapture();
173 } 174 }
174 } 175 }
175 176
176 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { 177 void WindowModalityController::OnWindowDestroyed(aura::Window* window) {
177 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); 178 windows_.erase(std::find(windows_.begin(), windows_.end(), window));
178 window->RemoveObserver(this); 179 window->RemoveObserver(this);
179 } 180 }
180 181
181 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, 182 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target,
182 ui::LocatedEvent* event) { 183 ui::LocatedEvent* event) {
183 if (event->handled()) 184 if (event->handled())
184 return false; 185 return false;
185 aura::Window* modal_transient_child = GetModalTransient(target); 186 aura::Window* modal_transient_child = GetModalTransient(target);
186 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || 187 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED ||
187 event->type() == ui::ET_TOUCH_PRESSED)) { 188 event->type() == ui::ET_TOUCH_PRESSED)) {
188 AnimateWindow(modal_transient_child, WINDOW_ANIMATION_TYPE_BOUNCE); 189 AnimateWindow(modal_transient_child, WINDOW_ANIMATION_TYPE_BOUNCE);
189 } 190 }
190 if (event->type() == ui::ET_TOUCH_CANCELLED) 191 if (event->type() == ui::ET_TOUCH_CANCELLED)
191 return false; 192 return false;
192 return !!modal_transient_child; 193 return !!modal_transient_child;
193 } 194 }
194 195
195 } // namespace corewm 196 } // namespace corewm
196 } // namespace views 197 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698