OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/immersive_fullscreen_controller.h" | 5 #include "ash/wm/immersive_fullscreen_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/wm/resize_handle_window_targeter.h" | 11 #include "ash/wm/resize_handle_window_targeter.h" |
12 #include "ash/wm/window_state.h" | 12 #include "ash/wm/window_state.h" |
13 #include "ash/wm/window_state_aura.h" | 13 #include "ash/wm/window_state_aura.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
16 #include "ui/aura/client/capture_client.h" | 16 #include "ui/aura/client/capture_client.h" |
17 #include "ui/aura/client/cursor_client.h" | 17 #include "ui/aura/client/cursor_client.h" |
18 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
19 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
20 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
21 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
22 #include "ui/gfx/animation/slide_animation.h" | 22 #include "ui/gfx/animation/slide_animation.h" |
23 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
24 #include "ui/gfx/geometry/point.h" | 24 #include "ui/gfx/geometry/point.h" |
25 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
26 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
27 #include "ui/views/bubble/bubble_delegate.h" | |
28 #include "ui/views/bubble/bubble_dialog_delegate.h" | 27 #include "ui/views/bubble/bubble_dialog_delegate.h" |
29 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
30 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
31 #include "ui/wm/core/transient_window_manager.h" | 30 #include "ui/wm/core/transient_window_manager.h" |
32 #include "ui/wm/core/window_util.h" | 31 #include "ui/wm/core/window_util.h" |
33 #include "ui/wm/public/activation_client.h" | 32 #include "ui/wm/public/activation_client.h" |
34 | 33 |
35 using views::View; | 34 using views::View; |
36 | 35 |
37 namespace ash { | 36 namespace ash { |
(...skipping 19 matching lines...) Expand all Loading... |
57 // vertical. This is used to make sure that gesture is close to vertical instead | 56 // vertical. This is used to make sure that gesture is close to vertical instead |
58 // of just more vertical then horizontal. | 57 // of just more vertical then horizontal. |
59 const int kSwipeVerticalThresholdMultiplier = 3; | 58 const int kSwipeVerticalThresholdMultiplier = 3; |
60 | 59 |
61 // The height in pixels of the region above the top edge of the display which | 60 // The height in pixels of the region above the top edge of the display which |
62 // hosts the immersive fullscreen window in which mouse events are ignored | 61 // hosts the immersive fullscreen window in which mouse events are ignored |
63 // (cannot reveal or unreveal the top-of-window views). | 62 // (cannot reveal or unreveal the top-of-window views). |
64 // See ShouldIgnoreMouseEventAtLocation() for more details. | 63 // See ShouldIgnoreMouseEventAtLocation() for more details. |
65 const int kHeightOfDeadRegionAboveTopContainer = 10; | 64 const int kHeightOfDeadRegionAboveTopContainer = 10; |
66 | 65 |
67 // Returns the BubbleDelegateView corresponding to |maybe_bubble| if | |
68 // |maybe_bubble| is a bubble. TODO(estade): remove this when all bubbles are | |
69 // BubbleDialogDelegateViews, or create a common interface for the two bubble | |
70 // types. | |
71 views::BubbleDelegateView* AsBubbleDelegate(aura::Window* maybe_bubble) { | |
72 if (!maybe_bubble) | |
73 return nullptr; | |
74 views::Widget* widget = views::Widget::GetWidgetForNativeView(maybe_bubble); | |
75 if (!widget) | |
76 return nullptr; | |
77 return widget->widget_delegate()->AsBubbleDelegate(); | |
78 } | |
79 | |
80 // Returns the BubbleDialogDelegateView corresponding to |maybe_bubble| if | 66 // Returns the BubbleDialogDelegateView corresponding to |maybe_bubble| if |
81 // |maybe_bubble| is a bubble. | 67 // |maybe_bubble| is a bubble. |
82 views::BubbleDialogDelegateView* AsBubbleDialogDelegate( | 68 views::BubbleDialogDelegateView* AsBubbleDialogDelegate( |
83 aura::Window* maybe_bubble) { | 69 aura::Window* maybe_bubble) { |
84 if (!maybe_bubble) | 70 if (!maybe_bubble) |
85 return nullptr; | 71 return nullptr; |
86 views::Widget* widget = views::Widget::GetWidgetForNativeView(maybe_bubble); | 72 views::Widget* widget = views::Widget::GetWidgetForNativeView(maybe_bubble); |
87 if (!widget) | 73 if (!widget) |
88 return nullptr; | 74 return nullptr; |
89 return widget->widget_delegate()->AsBubbleDialogDelegate(); | 75 return widget->widget_delegate()->AsBubbleDialogDelegate(); |
90 } | 76 } |
91 | 77 |
92 views::View* GetAnchorView(aura::Window* maybe_bubble) { | 78 views::View* GetAnchorView(aura::Window* maybe_bubble) { |
93 views::BubbleDelegateView* bubble = AsBubbleDelegate(maybe_bubble); | |
94 if (bubble) | |
95 return bubble->GetAnchorView(); | |
96 | |
97 views::BubbleDialogDelegateView* bubble_dialog = | 79 views::BubbleDialogDelegateView* bubble_dialog = |
98 AsBubbleDialogDelegate(maybe_bubble); | 80 AsBubbleDialogDelegate(maybe_bubble); |
99 return bubble_dialog ? bubble_dialog->GetAnchorView() : nullptr; | 81 return bubble_dialog ? bubble_dialog->GetAnchorView() : nullptr; |
100 } | 82 } |
101 | 83 |
102 // Returns true if |maybe_transient| is a transient child of |toplevel|. | 84 // Returns true if |maybe_transient| is a transient child of |toplevel|. |
103 bool IsWindowTransientChildOf(aura::Window* maybe_transient, | 85 bool IsWindowTransientChildOf(aura::Window* maybe_transient, |
104 aura::Window* toplevel) { | 86 aura::Window* toplevel) { |
105 if (!maybe_transient || !toplevel) | 87 if (!maybe_transient || !toplevel) |
106 return false; | 88 return false; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 std::unique_ptr<ImmersiveRevealedLock> revealed_lock_; | 163 std::unique_ptr<ImmersiveRevealedLock> revealed_lock_; |
182 | 164 |
183 DISALLOW_COPY_AND_ASSIGN(BubbleObserver); | 165 DISALLOW_COPY_AND_ASSIGN(BubbleObserver); |
184 }; | 166 }; |
185 | 167 |
186 ImmersiveFullscreenController::BubbleObserver::BubbleObserver( | 168 ImmersiveFullscreenController::BubbleObserver::BubbleObserver( |
187 ImmersiveFullscreenController* controller) | 169 ImmersiveFullscreenController* controller) |
188 : controller_(controller) {} | 170 : controller_(controller) {} |
189 | 171 |
190 ImmersiveFullscreenController::BubbleObserver::~BubbleObserver() { | 172 ImmersiveFullscreenController::BubbleObserver::~BubbleObserver() { |
191 for (std::set<aura::Window*>::const_iterator it = bubbles_.begin(); | 173 for (aura::Window* bubble : bubbles_) |
192 it != bubbles_.end(); ++it) { | 174 bubble->RemoveObserver(this); |
193 (*it)->RemoveObserver(this); | |
194 } | |
195 } | 175 } |
196 | 176 |
197 void ImmersiveFullscreenController::BubbleObserver::StartObserving( | 177 void ImmersiveFullscreenController::BubbleObserver::StartObserving( |
198 aura::Window* bubble) { | 178 aura::Window* bubble) { |
199 if (bubbles_.insert(bubble).second) { | 179 if (bubbles_.insert(bubble).second) { |
200 bubble->AddObserver(this); | 180 bubble->AddObserver(this); |
201 UpdateRevealedLock(); | 181 UpdateRevealedLock(); |
202 } | 182 } |
203 } | 183 } |
204 | 184 |
205 void ImmersiveFullscreenController::BubbleObserver::StopObserving( | 185 void ImmersiveFullscreenController::BubbleObserver::StopObserving( |
206 aura::Window* bubble) { | 186 aura::Window* bubble) { |
207 if (bubbles_.erase(bubble)) { | 187 if (bubbles_.erase(bubble)) { |
208 bubble->RemoveObserver(this); | 188 bubble->RemoveObserver(this); |
209 UpdateRevealedLock(); | 189 UpdateRevealedLock(); |
210 } | 190 } |
211 } | 191 } |
212 | 192 |
213 void ImmersiveFullscreenController::BubbleObserver::UpdateRevealedLock() { | 193 void ImmersiveFullscreenController::BubbleObserver::UpdateRevealedLock() { |
214 bool has_visible_bubble = false; | 194 bool has_visible_bubble = false; |
215 for (std::set<aura::Window*>::const_iterator it = bubbles_.begin(); | 195 for (aura::Window* bubble : bubbles_) { |
216 it != bubbles_.end(); ++it) { | 196 if (bubble->IsVisible()) { |
217 if ((*it)->IsVisible()) { | |
218 has_visible_bubble = true; | 197 has_visible_bubble = true; |
219 break; | 198 break; |
220 } | 199 } |
221 } | 200 } |
222 | 201 |
223 bool was_revealed = controller_->IsRevealed(); | 202 bool was_revealed = controller_->IsRevealed(); |
224 if (has_visible_bubble) { | 203 if (has_visible_bubble) { |
225 if (!revealed_lock_.get()) { | 204 if (!revealed_lock_.get()) { |
226 // Reveal the top-of-window views without animating because it looks | 205 // Reveal the top-of-window views without animating because it looks |
227 // weird for the top-of-window views to animate and the bubble not to | 206 // weird for the top-of-window views to animate and the bubble not to |
228 // animate along with the top-of-window views. | 207 // animate along with the top-of-window views. |
229 revealed_lock_.reset(controller_->GetRevealedLock( | 208 revealed_lock_.reset(controller_->GetRevealedLock( |
230 ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); | 209 ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); |
231 } | 210 } |
232 } else { | 211 } else { |
233 revealed_lock_.reset(); | 212 revealed_lock_.reset(); |
234 } | 213 } |
235 | 214 |
236 if (!was_revealed && revealed_lock_.get()) { | 215 if (!was_revealed && revealed_lock_.get()) { |
237 // Currently, there is no nice way for bubbles to reposition themselves | 216 // Currently, there is no nice way for bubbles to reposition themselves |
238 // whenever the anchor view moves. Tell the bubbles to reposition themselves | 217 // whenever the anchor view moves. Tell the bubbles to reposition themselves |
239 // explicitly instead. The hidden bubbles are also repositioned because | 218 // explicitly instead. The hidden bubbles are also repositioned because |
240 // BubbleDelegateView does not reposition its widget as a result of a | 219 // BubbleDialogDelegateView does not reposition its widget as a result of a |
241 // visibility change. | 220 // visibility change. |
242 for (std::set<aura::Window*>::const_iterator it = bubbles_.begin(); | 221 for (aura::Window* bubble : bubbles_) |
243 it != bubbles_.end(); ++it) { | 222 AsBubbleDialogDelegate(bubble)->OnAnchorBoundsChanged(); |
244 views::BubbleDelegateView* bubble = AsBubbleDelegate(*it); | |
245 if (bubble) | |
246 bubble->OnAnchorBoundsChanged(); | |
247 else | |
248 AsBubbleDialogDelegate(*it)->OnAnchorBoundsChanged(); | |
249 } | |
250 } | 223 } |
251 } | 224 } |
252 | 225 |
253 void ImmersiveFullscreenController::BubbleObserver::OnWindowVisibilityChanged( | 226 void ImmersiveFullscreenController::BubbleObserver::OnWindowVisibilityChanged( |
254 aura::Window*, | 227 aura::Window*, |
255 bool visible) { | 228 bool visible) { |
256 UpdateRevealedLock(); | 229 UpdateRevealedLock(); |
257 } | 230 } |
258 | 231 |
259 void ImmersiveFullscreenController::BubbleObserver::OnWindowDestroying( | 232 void ImmersiveFullscreenController::BubbleObserver::OnWindowDestroying( |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 ::wm::GetTransientChildren(native_window_); | 937 ::wm::GetTransientChildren(native_window_); |
965 for (size_t i = 0; i < transient_children.size(); ++i) { | 938 for (size_t i = 0; i < transient_children.size(); ++i) { |
966 aura::Window* transient_child = transient_children[i]; | 939 aura::Window* transient_child = transient_children[i]; |
967 views::View* anchor_view = GetAnchorView(transient_child); | 940 views::View* anchor_view = GetAnchorView(transient_child); |
968 if (anchor_view && top_container_->Contains(anchor_view)) | 941 if (anchor_view && top_container_->Contains(anchor_view)) |
969 bubble_observer_->StartObserving(transient_child); | 942 bubble_observer_->StartObserving(transient_child); |
970 } | 943 } |
971 } | 944 } |
972 | 945 |
973 } // namespace ash | 946 } // namespace ash |
OLD | NEW |