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

Side by Side Diff: ui/wm/core/window_modality_controller.cc

Issue 2172363002: Created min size for print preview dialog and modified to allow the Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix mac build error 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 "ui/wm/core/window_modality_controller.h" 5 #include "ui/wm/core/window_modality_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "ui/aura/client/aura_constants.h" 11 #include "ui/aura/client/aura_constants.h"
12 #include "ui/aura/client/capture_client.h" 12 #include "ui/aura/client/capture_client.h"
13 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h" 15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/aura/window_property.h" 16 #include "ui/aura/window_property.h"
17 #include "ui/base/ui_base_types.h" 17 #include "ui/base/ui_base_types.h"
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 #include "ui/events/event_target.h" 19 #include "ui/events/event_target.h"
20 #include "ui/events/gestures/gesture_recognizer.h" 20 #include "ui/events/gestures/gesture_recognizer.h"
21 #include "ui/wm/core/window_animations.h" 21 #include "ui/wm/core/window_animations.h"
22 #include "ui/wm/core/window_util.h" 22 #include "ui/wm/core/window_util.h"
23 23
24 namespace wm { 24 namespace wm {
25 25
26 const char kAllowTransientParentEventsKey[] = "__ALLOW_PARENT_EVENTS__";
27
26 // Transient child's modal parent. 28 // Transient child's modal parent.
27 extern const aura::WindowProperty<aura::Window*>* const kModalParentKey; 29 extern const aura::WindowProperty<aura::Window*>* const kModalParentKey;
28 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kModalParentKey, NULL); 30 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kModalParentKey, NULL);
29 31
30 namespace { 32 namespace {
31 33
32 bool HasAncestor(aura::Window* window, aura::Window* ancestor) { 34 bool HasAncestor(aura::Window* window, aura::Window* ancestor) {
33 if (!window) 35 if (!window)
34 return false; 36 return false;
35 if (window == ancestor) 37 if (window == ancestor)
(...skipping 11 matching lines...) Expand all
47 49
48 bool TransientChildIsChildModal(aura::Window* window) { 50 bool TransientChildIsChildModal(aura::Window* window) {
49 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_CHILD; 51 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_CHILD;
50 } 52 }
51 53
52 aura::Window* GetModalParent(aura::Window* window) { 54 aura::Window* GetModalParent(aura::Window* window) {
53 return window->GetProperty(kModalParentKey); 55 return window->GetProperty(kModalParentKey);
54 } 56 }
55 57
56 bool IsModalTransientChild(aura::Window* transient, aura::Window* original) { 58 bool IsModalTransientChild(aura::Window* transient, aura::Window* original) {
59 return (transient->IsVisible() &&
60 ((TransientChildIsWindowModal(transient) &&
61 !transient->GetNativeWindowProperty(kAllowTransientParentEventsKey))
62 || TransientChildIsSystemModal(transient)
63 || ((TransientChildIsChildModal(transient) ||
64 transient->GetNativeWindowProperty(kAllowTransientParentEventsKey))
65 && (HasAncestor(original, GetModalParent(transient))))));
66 }
67
68 bool IsModalTransientChildOld(aura::Window* transient, aura::Window* original) {
57 return transient->IsVisible() && 69 return transient->IsVisible() &&
58 (TransientChildIsWindowModal(transient) || 70 (TransientChildIsWindowModal(transient) ||
59 TransientChildIsSystemModal(transient) || 71 TransientChildIsSystemModal(transient) ||
60 (TransientChildIsChildModal(transient) && 72 (TransientChildIsChildModal(transient) &&
61 (HasAncestor(original, GetModalParent(transient))))); 73 (HasAncestor(original, GetModalParent(transient)))));
62 } 74 }
63 75
64 aura::Window* GetModalTransientChild( 76 aura::Window* GetModalTransientChild(
65 aura::Window* activatable, 77 aura::Window* activatable,
66 aura::Window* original) { 78 aura::Window* original) {
67 for (aura::Window::Windows::const_iterator it = 79 for (aura::Window::Windows::const_iterator it =
68 GetTransientChildren(activatable).begin(); 80 GetTransientChildren(activatable).begin();
69 it != GetTransientChildren(activatable).end(); 81 it != GetTransientChildren(activatable).end();
70 ++it) { 82 ++it) {
71 aura::Window* transient = *it; 83 aura::Window* transient = *it;
72 if (IsModalTransientChild(transient, original)) { 84 if (IsModalTransientChild(transient, original)) {
73 if (GetTransientChildren(transient).empty()) 85 if (GetTransientChildren(transient).empty())
74 return transient; 86 return transient;
75 87
76 aura::Window* modal_child = GetModalTransientChild(transient, original); 88 aura::Window* modal_child = GetModalTransientChild(transient, original);
77 return modal_child ? modal_child : transient; 89 return modal_child ? modal_child : transient;
78 } 90 }
79 } 91 }
80 return NULL; 92 return NULL;
81 } 93 }
82 94
95 aura::Window* GetModalTransientChildOld(
96 aura::Window* activatable,
97 aura::Window* original) {
98 for (aura::Window::Windows::const_iterator it =
99 GetTransientChildren(activatable).begin();
100 it != GetTransientChildren(activatable).end();
101 ++it) {
102 aura::Window* transient = *it;
103 if (IsModalTransientChildOld(transient, original)) {
104 if (GetTransientChildren(transient).empty())
105 return transient;
106
107 aura::Window* modal_child =
108 GetModalTransientChildOld(transient, original);
109 return modal_child ? modal_child : transient;
110 }
111 }
112 return NULL;
113 }
114
83 } // namespace 115 } // namespace
84 116
85 void SetModalParent(aura::Window* child, aura::Window* parent) { 117 void SetModalParent(aura::Window* child, aura::Window* parent) {
86 child->SetProperty(kModalParentKey, parent); 118 child->SetProperty(kModalParentKey, parent);
87 } 119 }
88 120
89 aura::Window* GetModalTransient(aura::Window* window) { 121 aura::Window* GetModalTransient(aura::Window* window) {
90 if (!window) 122 if (!window)
91 return NULL; 123 return NULL;
92 124
93 // We always want to check the for the transient child of the toplevel window. 125 // We always want to check the for the transient child of the toplevel window.
94 aura::Window* toplevel = GetToplevelWindow(window); 126 aura::Window* toplevel = GetToplevelWindow(window);
95 if (!toplevel) 127 if (!toplevel)
96 return NULL; 128 return NULL;
97 129
98 return GetModalTransientChild(toplevel, window); 130 return GetModalTransientChild(toplevel, window);
99 } 131 }
100 132
133 aura::Window* HasWindowModalTransient(aura::Window* window) {
134 if (!window)
135 return NULL;
136
137 aura::Window* toplevel = GetToplevelWindow(window);
138 if (!toplevel)
139 return NULL;
140
141 return GetModalTransientChildOld(toplevel, window);
142 }
143
101 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
102 // WindowModalityController, public: 145 // WindowModalityController, public:
103 146
104 WindowModalityController::WindowModalityController( 147 WindowModalityController::WindowModalityController(
105 ui::EventTarget* event_target) 148 ui::EventTarget* event_target)
106 : event_target_(event_target) { 149 : event_target_(event_target) {
107 aura::Env::GetInstance()->AddObserver(this); 150 aura::Env::GetInstance()->AddObserver(this);
108 DCHECK(event_target->IsPreTargetListEmpty()); 151 DCHECK(event_target->IsPreTargetListEmpty());
109 event_target_->AddPreTargetHandler(this); 152 event_target_->AddPreTargetHandler(this);
110 } 153 }
(...skipping 10 matching lines...) Expand all
121 164
122 void WindowModalityController::OnKeyEvent(ui::KeyEvent* event) { 165 void WindowModalityController::OnKeyEvent(ui::KeyEvent* event) {
123 aura::Window* target = static_cast<aura::Window*>(event->target()); 166 aura::Window* target = static_cast<aura::Window*>(event->target());
124 if (GetModalTransient(target)) 167 if (GetModalTransient(target))
125 event->SetHandled(); 168 event->SetHandled();
126 } 169 }
127 170
128 void WindowModalityController::OnMouseEvent(ui::MouseEvent* event) { 171 void WindowModalityController::OnMouseEvent(ui::MouseEvent* event) {
129 aura::Window* target = static_cast<aura::Window*>(event->target()); 172 aura::Window* target = static_cast<aura::Window*>(event->target());
130 if (ProcessLocatedEvent(target, event)) 173 if (ProcessLocatedEvent(target, event))
131 event->SetHandled(); 174 event->SetHandled();
132 } 175 }
133 176
134 void WindowModalityController::OnTouchEvent(ui::TouchEvent* event) { 177 void WindowModalityController::OnTouchEvent(ui::TouchEvent* event) {
135 aura::Window* target = static_cast<aura::Window*>(event->target()); 178 aura::Window* target = static_cast<aura::Window*>(event->target());
136 if (ProcessLocatedEvent(target, event)) 179 if (ProcessLocatedEvent(target, event))
137 event->SetHandled(); 180 event->SetHandled();
138 } 181 }
139 182
140 //////////////////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////////////////
141 // WindowModalityController, aura::EnvObserver implementation: 184 // WindowModalityController, aura::EnvObserver implementation:
(...skipping 23 matching lines...) Expand all
165 aura::Window* window, 208 aura::Window* window,
166 bool visible) { 209 bool visible) {
167 if (visible && 210 if (visible &&
168 window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) { 211 window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) {
169 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); 212 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
170 // Make sure no other window has capture, otherwise |window| won't get mouse 213 // Make sure no other window has capture, otherwise |window| won't get mouse
171 // events. 214 // events.
172 aura::Window* capture_window = aura::client::GetCaptureWindow(window); 215 aura::Window* capture_window = aura::client::GetCaptureWindow(window);
173 if (capture_window) { 216 if (capture_window) {
174 bool should_release_capture = true; 217 bool should_release_capture = true;
175 if (window->GetProperty(aura::client::kModalKey) == 218 if (((window->GetProperty(aura::client::kModalKey) ==
176 ui::MODAL_TYPE_CHILD && 219 ui::MODAL_TYPE_CHILD) ||
220 (window->GetProperty(aura::client::kModalKey) ==
221 ui::MODAL_TYPE_WINDOW &&
222 window->GetNativeWindowProperty(kAllowTransientParentEventsKey))) &&
177 !HasAncestor(capture_window, GetModalParent(window))) { 223 !HasAncestor(capture_window, GetModalParent(window))) {
178 // For child modal windows we only need ensure capture is not on a 224 // For child modal windows we only need ensure capture is not on a
179 // descendant of the modal parent. This way we block events to the 225 // descendant of the modal parent. This way we block events to the
180 // parents subtree appropriately. 226 // parents subtree appropriately.
181 should_release_capture = false; 227 should_release_capture = false;
182 } 228 }
183 229
184 if (should_release_capture) 230 if (should_release_capture)
185 capture_window->ReleaseCapture(); 231 capture_window->ReleaseCapture();
186 } 232 }
187 } 233 }
188 } 234 }
189 235
190 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { 236 void WindowModalityController::OnWindowDestroyed(aura::Window* window) {
191 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); 237 windows_.erase(std::find(windows_.begin(), windows_.end(), window));
192 window->RemoveObserver(this); 238 window->RemoveObserver(this);
193 } 239 }
194 240
195 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, 241 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target,
196 ui::LocatedEvent* event) { 242 ui::LocatedEvent* event) {
197 if (event->handled()) 243 if (event->handled())
198 return false; 244 return false;
199 aura::Window* modal_transient_child = GetModalTransient(target); 245 aura::Window* modal_transient_child = GetModalTransient(target);
200 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || 246 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED ||
201 event->type() == ui::ET_TOUCH_PRESSED)) { 247 event->type() == ui::ET_TOUCH_PRESSED)) {
202 // Activate top window if transient child window is window modal. 248 // Activate top window if transient child window is window modal.
203 if (TransientChildIsWindowModal(modal_transient_child)) { 249 if (TransientChildIsWindowModal(modal_transient_child) &&
250 !modal_transient_child->GetNativeWindowProperty(
251 kAllowTransientParentEventsKey)) {
204 aura::Window* toplevel = GetToplevelWindow(target); 252 aura::Window* toplevel = GetToplevelWindow(target);
205 DCHECK(toplevel); 253 DCHECK(toplevel);
206 ActivateWindow(toplevel); 254 ActivateWindow(toplevel);
207 } 255 }
208 256
209 AnimateWindow(modal_transient_child, WINDOW_ANIMATION_TYPE_BOUNCE); 257 AnimateWindow(modal_transient_child, WINDOW_ANIMATION_TYPE_BOUNCE);
210 } 258 }
211 if (event->type() == ui::ET_TOUCH_CANCELLED) 259 if (event->type() == ui::ET_TOUCH_CANCELLED)
212 return false; 260 return false;
213 return !!modal_transient_child; 261 return !!modal_transient_child;
214 } 262 }
215 263
216 } // namespace wm 264 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698