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/app_list_controller.h" | 5 #include "ui/app_list/app_list_shower_impl.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | |
8 #include "ash/root_window_controller.h" | |
9 #include "ash/screen_util.h" | |
10 #include "ash/shelf/shelf.h" | |
11 #include "ash/shelf/shelf_layout_manager.h" | |
12 #include "ash/shell.h" | |
13 #include "ash/shell_delegate.h" | |
14 #include "ash/shell_window_ids.h" | |
15 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
16 #include "base/command_line.h" | |
17 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
8 #include "ui/app_list/app_list_shower_delegate_factory.h" | |
18 #include "ui/app_list/app_list_switches.h" | 9 #include "ui/app_list/app_list_switches.h" |
19 #include "ui/app_list/pagination_model.h" | 10 #include "ui/app_list/pagination_model.h" |
20 #include "ui/app_list/views/app_list_view.h" | 11 #include "ui/app_list/views/app_list_view.h" |
21 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
22 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
23 #include "ui/aura/window_event_dispatcher.h" | |
24 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
25 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
26 #include "ui/events/event.h" | |
27 #include "ui/gfx/transform_util.h" | |
28 #include "ui/keyboard/keyboard_controller.h" | 16 #include "ui/keyboard/keyboard_controller.h" |
29 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
30 | 18 |
31 namespace ash { | 19 namespace app_list { |
32 namespace { | 20 namespace { |
33 | 21 |
34 // Duration for show/hide animation in milliseconds. | 22 // Duration for show/hide animation in milliseconds. |
35 const int kAnimationDurationMs = 200; | 23 const int kAnimationDurationMs = 200; |
36 | 24 |
37 // Offset in pixels to animation away/towards the shelf. | |
38 const int kAnimationOffset = 8; | |
39 | |
40 // The maximum shift in pixels when over-scroll happens. | 25 // The maximum shift in pixels when over-scroll happens. |
41 const int kMaxOverScrollShift = 48; | 26 const int kMaxOverScrollShift = 48; |
42 | 27 |
43 // The minimal anchor position offset to make sure that the bubble is still on | |
44 // the screen with 8 pixels spacing on the left / right. This constant is a | |
45 // result of minimal bubble arrow sizes and offsets. | |
46 const int kMinimalAnchorPositionOffset = 57; | |
47 | |
48 // The minimal margin (in pixels) around the app list when in centered mode. | |
49 const int kMinimalCenteredAppListMargin = 10; | |
50 | |
51 ui::Layer* GetLayer(views::Widget* widget) { | 28 ui::Layer* GetLayer(views::Widget* widget) { |
52 return widget->GetNativeView()->layer(); | 29 return widget->GetNativeView()->layer(); |
53 } | 30 } |
54 | 31 |
55 // Gets arrow location based on shelf alignment. | 32 } // namespace |
56 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { | 33 |
57 DCHECK(Shell::HasInstance()); | 34 AppListShowerImpl::AppListShowerImpl(AppListShowerDelegateFactory* factory) |
58 return Shelf::ForWindow(window)->SelectValueForShelfAlignment( | 35 : factory_(factory), |
59 views::BubbleBorder::BOTTOM_CENTER, views::BubbleBorder::LEFT_CENTER, | 36 view_delegate_(nullptr), |
60 views::BubbleBorder::RIGHT_CENTER, views::BubbleBorder::TOP_CENTER); | 37 is_visible_(false), |
38 view_(nullptr), | |
39 current_apps_page_(-1), | |
40 should_snap_back_(false) { | |
41 DCHECK(factory); | |
61 } | 42 } |
62 | 43 |
63 // Offset given |rect| towards shelf. | 44 AppListShowerImpl::~AppListShowerImpl() { |
64 gfx::Rect OffsetTowardsShelf(const gfx::Rect& rect, views::Widget* widget) { | 45 shower_delegate_.reset(); |
65 DCHECK(Shell::HasInstance()); | |
66 ShelfAlignment shelf_alignment = Shell::GetInstance()->GetShelfAlignment( | |
67 widget->GetNativeView()->GetRootWindow()); | |
68 gfx::Rect offseted(rect); | |
69 switch (shelf_alignment) { | |
70 case SHELF_ALIGNMENT_BOTTOM: | |
71 offseted.Offset(0, kAnimationOffset); | |
72 break; | |
73 case SHELF_ALIGNMENT_LEFT: | |
74 offseted.Offset(-kAnimationOffset, 0); | |
75 break; | |
76 case SHELF_ALIGNMENT_RIGHT: | |
77 offseted.Offset(kAnimationOffset, 0); | |
78 break; | |
79 case SHELF_ALIGNMENT_TOP: | |
80 offseted.Offset(0, -kAnimationOffset); | |
81 break; | |
82 } | |
83 | |
84 return offseted; | |
85 } | |
86 | |
87 // Using |button_bounds|, determine the anchor offset so that the bubble gets | |
88 // shown above the shelf (used for the alternate shelf theme). | |
89 gfx::Vector2d GetAnchorPositionOffsetToShelf( | |
90 const gfx::Rect& button_bounds, views::Widget* widget) { | |
91 DCHECK(Shell::HasInstance()); | |
92 ShelfAlignment shelf_alignment = Shell::GetInstance()->GetShelfAlignment( | |
93 widget->GetNativeView()->GetRootWindow()); | |
94 gfx::Point anchor(button_bounds.CenterPoint()); | |
95 switch (shelf_alignment) { | |
96 case SHELF_ALIGNMENT_TOP: | |
97 case SHELF_ALIGNMENT_BOTTOM: | |
98 if (base::i18n::IsRTL()) { | |
99 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); | |
100 return gfx::Vector2d( | |
101 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(), | |
102 0), 0); | |
103 } | |
104 return gfx::Vector2d( | |
105 std::max(kMinimalAnchorPositionOffset - anchor.x(), 0), 0); | |
106 case SHELF_ALIGNMENT_LEFT: | |
107 return gfx::Vector2d( | |
108 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | |
109 case SHELF_ALIGNMENT_RIGHT: | |
110 return gfx::Vector2d( | |
111 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | |
112 default: | |
113 NOTREACHED(); | |
114 return gfx::Vector2d(); | |
115 } | |
116 } | |
117 | |
118 // Gets the point at the center of the display that a particular view is on. | |
119 // This calculation excludes the virtual keyboard area. If the height of the | |
120 // display area is less than |minimum_height|, its bottom will be extended to | |
121 // that height (so that the app list never starts above the top of the screen). | |
122 gfx::Point GetCenterOfDisplayForView(const views::View* view, | |
123 int minimum_height) { | |
124 aura::Window* window = view->GetWidget()->GetNativeView(); | |
125 gfx::Rect bounds = ScreenUtil::GetShelfDisplayBoundsInRoot(window); | |
126 bounds = ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), bounds); | |
127 | |
128 // If the virtual keyboard is active, subtract it from the display bounds, so | |
129 // that the app list is centered in the non-keyboard area of the display. | |
130 // (Note that work_area excludes the keyboard, but it doesn't get updated | |
131 // until after this function is called.) | |
132 keyboard::KeyboardController* keyboard_controller = | |
133 keyboard::KeyboardController::GetInstance(); | |
134 if (keyboard_controller && keyboard_controller->keyboard_visible()) | |
135 bounds.Subtract(keyboard_controller->current_keyboard_bounds()); | |
136 | |
137 // Apply the |minimum_height|. | |
138 if (bounds.height() < minimum_height) | |
139 bounds.set_height(minimum_height); | |
140 | |
141 return bounds.CenterPoint(); | |
142 } | |
143 | |
144 // Gets the minimum height of the rectangle to center the app list in. | |
145 int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) { | |
146 return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin; | |
147 } | |
148 | |
149 bool IsFullscreenAppListEnabled() { | |
150 #if defined(OS_CHROMEOS) | |
151 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
152 switches::kAshEnableFullscreenAppList) && | |
153 app_list::switches::IsExperimentalAppListEnabled(); | |
154 #else | |
155 return false; | |
156 #endif | |
157 } | |
158 | |
159 } // namespace | |
160 | |
161 //////////////////////////////////////////////////////////////////////////////// | |
162 // AppListController, public: | |
163 | |
164 AppListController::AppListController() | |
165 : is_visible_(false), | |
166 is_centered_(false), | |
167 view_(NULL), | |
168 current_apps_page_(-1), | |
169 should_snap_back_(false) { | |
170 Shell::GetInstance()->AddShellObserver(this); | |
171 } | |
172 | |
173 AppListController::~AppListController() { | |
174 // Ensures app list view goes before the controller since pagination model | 46 // Ensures app list view goes before the controller since pagination model |
175 // lives in the controller and app list view would access it on destruction. | 47 // lives in the controller and app list view would access it on destruction. |
176 if (view_) { | 48 if (view_) { |
177 view_->GetAppsPaginationModel()->RemoveObserver(this); | 49 view_->GetAppsPaginationModel()->RemoveObserver(this); |
178 if (view_->GetWidget()) | 50 if (view_->GetWidget()) |
179 view_->GetWidget()->CloseNow(); | 51 view_->GetWidget()->CloseNow(); |
180 } | 52 } |
181 | |
182 Shell::GetInstance()->RemoveShellObserver(this); | |
183 } | 53 } |
184 | 54 |
185 void AppListController::Show(aura::Window* window) { | 55 aura::Window* AppListShowerImpl::GetWindow() { |
56 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : nullptr; | |
57 } | |
58 | |
59 void AppListShowerImpl::Show(aura::Window* window) { | |
186 if (is_visible_) | 60 if (is_visible_) |
187 return; | 61 return; |
188 | 62 |
63 DCHECK(view_delegate_); | |
189 is_visible_ = true; | 64 is_visible_ = true; |
190 | 65 |
191 // App list needs to know the new shelf layout in order to calculate its | 66 aura::Window* root_window = window->GetRootWindow(); |
192 // UI layout when AppListView visibility changes. | |
193 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> | |
194 UpdateAutoHideState(); | |
195 | |
196 if (view_) { | 67 if (view_) { |
197 ScheduleAnimation(); | 68 ScheduleAnimation(); |
198 } else { | 69 } else { |
199 // Note the AppListViewDelegate outlives the AppListView. For Ash, the view | 70 // Note the AppListViewDelegate outlives the AppListView. For Ash, the view |
200 // is destroyed when dismissed. | 71 // is destroyed when dismissed. |
201 app_list::AppListView* view = new app_list::AppListView( | 72 AppListView* view = new AppListView(view_delegate_); |
202 Shell::GetInstance()->delegate()->GetAppListViewDelegate()); | 73 shower_delegate_ = factory_->GetDelegate(this); |
203 aura::Window* root_window = window->GetRootWindow(); | 74 shower_delegate_->Init(view, root_window, current_apps_page_); |
204 aura::Window* container = GetRootWindowController(root_window)-> | |
205 GetContainer(kShellWindowId_AppListContainer); | |
206 views::View* applist_button = | |
207 Shelf::ForWindow(container)->GetAppListButtonView(); | |
208 is_centered_ = view->ShouldCenterWindow(); | |
209 bool is_fullscreen = IsFullscreenAppListEnabled() && | |
210 Shell::GetInstance() | |
211 ->maximize_mode_controller() | |
212 ->IsMaximizeModeWindowManagerEnabled(); | |
213 if (is_fullscreen) { | |
214 view->InitAsFramelessWindow( | |
215 container, current_apps_page_, | |
216 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); | |
217 } else if (is_centered_) { | |
218 // Note: We can't center the app list until we have its dimensions, so we | |
219 // init at (0, 0) and then reset its anchor point. | |
220 view->InitAsBubbleAtFixedLocation(container, | |
221 current_apps_page_, | |
222 gfx::Point(), | |
223 views::BubbleBorder::FLOAT, | |
224 true /* border_accepts_events */); | |
225 // The experimental app list is centered over the display of the app list | |
226 // button that was pressed (if triggered via keyboard, this is the display | |
227 // with the currently focused window). | |
228 view->SetAnchorPoint(GetCenterOfDisplayForView( | |
229 applist_button, GetMinimumBoundsHeightForAppList(view))); | |
230 } else { | |
231 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); | |
232 // We need the location of the button within the local screen. | |
233 applist_button_bounds = ScreenUtil::ConvertRectFromScreen( | |
234 root_window, | |
235 applist_button_bounds); | |
236 view->InitAsBubbleAttachedToAnchor( | |
237 container, | |
238 current_apps_page_, | |
239 Shelf::ForWindow(container)->GetAppListButtonView(), | |
240 GetAnchorPositionOffsetToShelf( | |
241 applist_button_bounds, | |
242 Shelf::ForWindow(container)->GetAppListButtonView()->GetWidget()), | |
243 GetBubbleArrow(container), | |
244 true /* border_accepts_events */); | |
245 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | |
246 } | |
247 SetView(view); | 75 SetView(view); |
248 // By setting us as DnD recipient, the app list knows that we can | |
249 // handle items. | |
250 SetDragAndDropHostOfCurrentAppList( | |
251 Shelf::ForWindow(window)->GetDragAndDropHostForAppList()); | |
252 } | 76 } |
253 // Update applist button status when app list visibility is changed. | 77 shower_delegate_->OnShown(root_window); |
254 Shelf::ForWindow(window)->GetAppListButtonView()->SchedulePaint(); | |
255 } | 78 } |
256 | 79 |
257 void AppListController::Dismiss() { | 80 void AppListShowerImpl::Dismiss() { |
258 if (!is_visible_) | 81 if (!is_visible_) |
259 return; | 82 return; |
260 | 83 |
261 // If the app list is currently visible, there should be an existing view. | 84 // If the app list is currently visible, there should be an existing view. |
262 DCHECK(view_); | 85 DCHECK(view_); |
263 | 86 |
264 is_visible_ = false; | 87 is_visible_ = false; |
265 | 88 |
266 // App list needs to know the new shelf layout in order to calculate its | |
267 // UI layout when AppListView visibility changes. | |
268 Shell::GetPrimaryRootWindowController() | |
269 ->GetShelfLayoutManager() | |
270 ->UpdateAutoHideState(); | |
271 | |
272 // Our widget is currently active. When the animation completes we'll hide | 89 // Our widget is currently active. When the animation completes we'll hide |
273 // the widget, changing activation. If a menu is shown before the animation | 90 // the widget, changing activation. If a menu is shown before the animation |
274 // completes then the activation change triggers the menu to close. By | 91 // completes then the activation change triggers the menu to close. By |
275 // deactivating now we ensure there is no activation change when the | 92 // deactivating now we ensure there is no activation change when the |
276 // animation completes and any menus stay open. | 93 // animation completes and any menus stay open. |
277 view_->GetWidget()->Deactivate(); | 94 view_->GetWidget()->Deactivate(); |
95 | |
96 shower_delegate_->OnDismissed(); | |
278 ScheduleAnimation(); | 97 ScheduleAnimation(); |
279 | |
280 // Update applist button status when app list visibility is changed. | |
281 Shelf::ForWindow(view_->GetWidget()->GetNativeView()) | |
282 ->GetAppListButtonView() | |
283 ->SchedulePaint(); | |
284 } | 98 } |
285 | 99 |
286 bool AppListController::IsVisible() const { | 100 bool AppListShowerImpl::IsVisible() const { |
287 return view_ && view_->GetWidget()->IsVisible(); | 101 return view_ && view_->GetWidget()->IsVisible(); |
288 } | 102 } |
289 | 103 |
290 aura::Window* AppListController::GetWindow() { | 104 bool AppListShowerImpl::GetTargetVisibility() const { |
291 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; | 105 return is_visible_; |
292 } | 106 } |
293 | 107 |
294 //////////////////////////////////////////////////////////////////////////////// | 108 //////////////////////////////////////////////////////////////////////////////// |
295 // AppListController, private: | 109 // AppListShowerImpl, private: |
296 | 110 |
297 void AppListController::SetDragAndDropHostOfCurrentAppList( | 111 void AppListShowerImpl::SetView(AppListView* view) { |
298 app_list::ApplicationDragAndDropHost* drag_and_drop_host) { | 112 DCHECK(view_ == nullptr); |
299 if (view_ && is_visible_) | |
300 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | |
301 } | |
302 | |
303 void AppListController::SetView(app_list::AppListView* view) { | |
304 DCHECK(view_ == NULL); | |
305 DCHECK(is_visible_); | 113 DCHECK(is_visible_); |
306 | 114 |
307 view_ = view; | 115 view_ = view; |
308 views::Widget* widget = view_->GetWidget(); | 116 views::Widget* widget = view_->GetWidget(); |
309 widget->AddObserver(this); | 117 widget->AddObserver(this); |
310 keyboard::KeyboardController* keyboard_controller = | 118 keyboard::KeyboardController* keyboard_controller = |
311 keyboard::KeyboardController::GetInstance(); | 119 keyboard::KeyboardController::GetInstance(); |
312 if (keyboard_controller) | 120 if (keyboard_controller) |
313 keyboard_controller->AddObserver(this); | 121 keyboard_controller->AddObserver(this); |
314 Shell::GetInstance()->AddPreTargetHandler(this); | |
315 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); | |
316 widget->GetNativeView()->GetRootWindow()->AddObserver(this); | 122 widget->GetNativeView()->GetRootWindow()->AddObserver(this); |
317 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); | 123 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); |
318 | |
319 view_->GetAppsPaginationModel()->AddObserver(this); | 124 view_->GetAppsPaginationModel()->AddObserver(this); |
320 | |
321 view_->ShowWhenReady(); | 125 view_->ShowWhenReady(); |
322 } | 126 } |
323 | 127 |
324 void AppListController::ResetView() { | 128 void AppListShowerImpl::ResetView() { |
325 if (!view_) | 129 if (!view_) |
326 return; | 130 return; |
327 | 131 |
328 views::Widget* widget = view_->GetWidget(); | 132 views::Widget* widget = view_->GetWidget(); |
329 widget->RemoveObserver(this); | 133 widget->RemoveObserver(this); |
330 GetLayer(widget)->GetAnimator()->RemoveObserver(this); | 134 GetLayer(widget)->GetAnimator()->RemoveObserver(this); |
331 keyboard::KeyboardController* keyboard_controller = | 135 keyboard::KeyboardController* keyboard_controller = |
332 keyboard::KeyboardController::GetInstance(); | 136 keyboard::KeyboardController::GetInstance(); |
333 if (keyboard_controller) | 137 if (keyboard_controller) |
334 keyboard_controller->RemoveObserver(this); | 138 keyboard_controller->RemoveObserver(this); |
335 Shell::GetInstance()->RemovePreTargetHandler(this); | 139 // Don't keep the layout delegate around when we don't need it - this way |
336 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); | 140 // we don't need to worry about what listeners the layout delegate registers, |
141 // and shutting them down in the proper order during shell shutdown. | |
142 shower_delegate_.reset(); | |
xiyuan
2016/03/24 20:31:11
We still need to worry about shutdown owner becaus
mfomitchev
2016/03/29 17:33:31
When we have a shutdown with app list window open,
xiyuan
2016/03/29 17:44:34
I am fine as long as the shutdown case is tested.
| |
337 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); | 143 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); |
338 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); | 144 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); |
339 | 145 |
340 view_->GetAppsPaginationModel()->RemoveObserver(this); | 146 view_->GetAppsPaginationModel()->RemoveObserver(this); |
341 | 147 |
342 view_ = NULL; | 148 view_ = nullptr; |
343 } | 149 } |
344 | 150 |
345 void AppListController::ScheduleAnimation() { | 151 void AppListShowerImpl::ScheduleAnimation() { |
346 // Stop observing previous animation. | 152 // Stop observing previous animation. |
347 StopObservingImplicitAnimations(); | 153 StopObservingImplicitAnimations(); |
348 | 154 |
349 views::Widget* widget = view_->GetWidget(); | 155 views::Widget* widget = view_->GetWidget(); |
350 ui::Layer* layer = GetLayer(widget); | 156 ui::Layer* layer = GetLayer(widget); |
351 layer->GetAnimator()->StopAnimating(); | 157 layer->GetAnimator()->StopAnimating(); |
352 | 158 |
353 gfx::Rect target_bounds; | 159 gfx::Rect target_bounds; |
160 gfx::Vector2d offset = shower_delegate_->GetVisibilityAnimationOffset( | |
161 widget->GetNativeView()->GetRootWindow()); | |
354 if (is_visible_) { | 162 if (is_visible_) { |
355 target_bounds = widget->GetWindowBoundsInScreen(); | 163 target_bounds = widget->GetWindowBoundsInScreen(); |
356 widget->SetBounds(OffsetTowardsShelf(target_bounds, widget)); | 164 gfx::Rect start_bounds = gfx::Rect(target_bounds); |
165 start_bounds.Offset(offset); | |
166 widget->SetBounds(start_bounds); | |
357 } else { | 167 } else { |
358 target_bounds = OffsetTowardsShelf(widget->GetWindowBoundsInScreen(), | 168 target_bounds = widget->GetWindowBoundsInScreen(); |
359 widget); | 169 target_bounds.Offset(offset); |
360 } | 170 } |
361 | 171 |
362 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | 172 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); |
363 animation.SetTransitionDuration( | 173 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
364 base::TimeDelta::FromMilliseconds( | 174 is_visible_ ? 0 : kAnimationDurationMs)); |
365 is_visible_ ? 0 : kAnimationDurationMs)); | |
366 animation.AddObserver(this); | 175 animation.AddObserver(this); |
367 | 176 |
368 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 177 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
369 widget->SetBounds(target_bounds); | 178 widget->SetBounds(target_bounds); |
370 } | 179 } |
371 | 180 |
372 void AppListController::ProcessLocatedEvent(ui::LocatedEvent* event) { | 181 //////////////////////////////////////////////////////////////////////////////// |
373 if (!view_ || !is_visible_) | 182 // AppListShowerImpl, aura::client::FocusChangeObserver implementation: |
374 return; | |
375 | 183 |
376 // If the event happened on a menu, then the event should not close the app | 184 void AppListShowerImpl::OnWindowFocused(aura::Window* gained_focus, |
377 // list. | |
378 aura::Window* target = static_cast<aura::Window*>(event->target()); | |
379 if (target) { | |
380 RootWindowController* root_controller = | |
381 GetRootWindowController(target->GetRootWindow()); | |
382 if (root_controller) { | |
383 aura::Window* menu_container = | |
384 root_controller->GetContainer(kShellWindowId_MenuContainer); | |
385 if (menu_container->Contains(target)) | |
386 return; | |
387 aura::Window* keyboard_container = root_controller->GetContainer( | |
388 kShellWindowId_VirtualKeyboardContainer); | |
389 if (keyboard_container->Contains(target)) | |
390 return; | |
391 } | |
392 } | |
393 | |
394 aura::Window* window = view_->GetWidget()->GetNativeView()->parent(); | |
395 if (!window->Contains(target) && | |
396 !app_list::switches::ShouldNotDismissOnBlur()) { | |
397 Dismiss(); | |
398 } | |
399 } | |
400 | |
401 void AppListController::UpdateBounds() { | |
402 if (!view_ || !is_visible_) | |
403 return; | |
404 | |
405 view_->UpdateBounds(); | |
406 | |
407 if (is_centered_) | |
408 view_->SetAnchorPoint(GetCenterOfDisplayForView( | |
409 view_, GetMinimumBoundsHeightForAppList(view_))); | |
410 } | |
411 | |
412 //////////////////////////////////////////////////////////////////////////////// | |
413 // AppListController, aura::EventFilter implementation: | |
414 | |
415 void AppListController::OnMouseEvent(ui::MouseEvent* event) { | |
416 if (event->type() == ui::ET_MOUSE_PRESSED) | |
417 ProcessLocatedEvent(event); | |
418 } | |
419 | |
420 void AppListController::OnGestureEvent(ui::GestureEvent* event) { | |
421 if (event->type() == ui::ET_GESTURE_TAP_DOWN) | |
422 ProcessLocatedEvent(event); | |
423 } | |
424 | |
425 //////////////////////////////////////////////////////////////////////////////// | |
426 // AppListController, aura::FocusObserver implementation: | |
427 | |
428 void AppListController::OnWindowFocused(aura::Window* gained_focus, | |
429 aura::Window* lost_focus) { | 185 aura::Window* lost_focus) { |
430 if (view_ && is_visible_) { | 186 if (view_ && is_visible_) { |
431 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); | 187 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); |
432 aura::Window* applist_container = applist_window->parent(); | 188 aura::Window* applist_container = applist_window->parent(); |
433 | |
434 if (applist_container->Contains(lost_focus) && | 189 if (applist_container->Contains(lost_focus) && |
435 (!gained_focus || !applist_container->Contains(gained_focus)) && | 190 (!gained_focus || !applist_container->Contains(gained_focus)) && |
436 !app_list::switches::ShouldNotDismissOnBlur()) { | 191 !switches::ShouldNotDismissOnBlur()) { |
437 Dismiss(); | 192 Dismiss(); |
438 } | 193 } |
439 } | 194 } |
440 } | 195 } |
441 | 196 |
442 //////////////////////////////////////////////////////////////////////////////// | 197 //////////////////////////////////////////////////////////////////////////////// |
443 // AppListController, aura::WindowObserver implementation: | 198 // AppListShowerImpl, aura::WindowObserver implementation: |
444 void AppListController::OnWindowBoundsChanged(aura::Window* root, | 199 void AppListShowerImpl::OnWindowBoundsChanged(aura::Window* root, |
445 const gfx::Rect& old_bounds, | 200 const gfx::Rect& old_bounds, |
446 const gfx::Rect& new_bounds) { | 201 const gfx::Rect& new_bounds) { |
447 UpdateBounds(); | 202 if (shower_delegate_) |
203 shower_delegate_->UpdateBounds(); | |
448 } | 204 } |
449 | 205 |
450 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// |
451 // AppListController, ui::ImplicitAnimationObserver implementation: | 207 // AppListShowerImpl, ui::ImplicitAnimationObserver implementation: |
452 | 208 |
453 void AppListController::OnImplicitAnimationsCompleted() { | 209 void AppListShowerImpl::OnImplicitAnimationsCompleted() { |
454 if (is_visible_ ) | 210 if (is_visible_) |
455 view_->GetWidget()->Activate(); | 211 view_->GetWidget()->Activate(); |
456 else | 212 else |
457 view_->GetWidget()->Close(); | 213 view_->GetWidget()->Close(); |
458 } | 214 } |
459 | 215 |
460 //////////////////////////////////////////////////////////////////////////////// | 216 //////////////////////////////////////////////////////////////////////////////// |
461 // AppListController, views::WidgetObserver implementation: | 217 // AppListShowerImpl, views::WidgetObserver implementation: |
462 | 218 |
463 void AppListController::OnWidgetDestroying(views::Widget* widget) { | 219 void AppListShowerImpl::OnWidgetDestroying(views::Widget* widget) { |
464 DCHECK(view_->GetWidget() == widget); | 220 DCHECK(view_->GetWidget() == widget); |
465 if (is_visible_) | 221 if (is_visible_) |
466 Dismiss(); | 222 Dismiss(); |
467 ResetView(); | 223 ResetView(); |
468 } | 224 } |
469 | 225 |
470 //////////////////////////////////////////////////////////////////////////////// | 226 //////////////////////////////////////////////////////////////////////////////// |
471 // AppListController, keyboard::KeyboardControllerObserver implementation: | 227 // AppListShowerImpl, keyboard::KeyboardControllerObserver implementation: |
472 | 228 |
473 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 229 void AppListShowerImpl::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
474 UpdateBounds(); | 230 if (shower_delegate_) |
231 shower_delegate_->UpdateBounds(); | |
475 } | 232 } |
476 | 233 |
477 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
478 // AppListController, ShellObserver implementation: | 235 // AppListShowerImpl, PaginationModelObserver implementation: |
479 void AppListController::OnShelfAlignmentChanged(aura::Window* root_window) { | |
480 if (view_) | |
481 view_->SetBubbleArrow(GetBubbleArrow(view_->GetWidget()->GetNativeView())); | |
482 } | |
483 | 236 |
484 void AppListController::OnMaximizeModeStarted() { | 237 void AppListShowerImpl::TotalPagesChanged() {} |
485 // The "fullscreen" app-list is initialized as in a different type of window, | |
486 // therefore we can't switch between the fullscreen status and the normal | |
487 // app-list bubble. App-list should be dismissed for the transition between | |
488 // maximize mode (touch-view mode) and non-maximize mode, otherwise the app | |
489 // list tries to behave as a bubble which leads to a crash. crbug.com/510062 | |
490 if (IsFullscreenAppListEnabled() && is_visible_) | |
491 Dismiss(); | |
492 } | |
493 | 238 |
494 void AppListController::OnMaximizeModeEnded() { | 239 void AppListShowerImpl::SelectedPageChanged(int old_selected, |
495 // See the comments of OnMaximizeModeStarted(). | |
496 if (IsFullscreenAppListEnabled() && is_visible_) | |
497 Dismiss(); | |
498 } | |
499 | |
500 //////////////////////////////////////////////////////////////////////////////// | |
501 // AppListController, ShelfIconObserver implementation: | |
502 | |
503 void AppListController::OnShelfIconPositionsChanged() { | |
504 UpdateBounds(); | |
505 } | |
506 | |
507 //////////////////////////////////////////////////////////////////////////////// | |
508 // AppListController, PaginationModelObserver implementation: | |
509 | |
510 void AppListController::TotalPagesChanged() { | |
511 } | |
512 | |
513 void AppListController::SelectedPageChanged(int old_selected, | |
514 int new_selected) { | 240 int new_selected) { |
515 current_apps_page_ = new_selected; | 241 current_apps_page_ = new_selected; |
516 } | 242 } |
517 | 243 |
518 void AppListController::TransitionStarted() { | 244 void AppListShowerImpl::TransitionStarted() {} |
519 } | |
520 | 245 |
521 void AppListController::TransitionChanged() { | 246 void AppListShowerImpl::TransitionChanged() { |
522 // |view_| could be NULL when app list is closed with a running transition. | 247 // |view_| could be NULL when app list is closed with a running transition. |
523 if (!view_) | 248 if (!view_) |
524 return; | 249 return; |
525 | 250 |
526 app_list::PaginationModel* pagination_model = view_->GetAppsPaginationModel(); | 251 PaginationModel* pagination_model = view_->GetAppsPaginationModel(); |
527 | 252 |
528 const app_list::PaginationModel::Transition& transition = | 253 const PaginationModel::Transition& transition = |
529 pagination_model->transition(); | 254 pagination_model->transition(); |
530 if (pagination_model->is_valid_page(transition.target_page)) | 255 if (pagination_model->is_valid_page(transition.target_page)) |
531 return; | 256 return; |
532 | 257 |
533 views::Widget* widget = view_->GetWidget(); | 258 views::Widget* widget = view_->GetWidget(); |
534 ui::LayerAnimator* widget_animator = GetLayer(widget)->GetAnimator(); | 259 ui::LayerAnimator* widget_animator = |
260 widget->GetNativeView()->layer()->GetAnimator(); | |
535 if (!pagination_model->IsRevertingCurrentTransition()) { | 261 if (!pagination_model->IsRevertingCurrentTransition()) { |
536 // Update cached |view_bounds_| if it is the first over-scroll move and | 262 // Update cached |view_bounds_| if it is the first over-scroll move and |
537 // widget does not have running animations. | 263 // widget does not have running animations. |
538 if (!should_snap_back_ && !widget_animator->is_animating()) | 264 if (!should_snap_back_ && !widget_animator->is_animating()) |
539 view_bounds_ = widget->GetWindowBoundsInScreen(); | 265 view_bounds_ = widget->GetWindowBoundsInScreen(); |
540 | 266 |
541 const int current_page = pagination_model->selected_page(); | 267 const int current_page = pagination_model->selected_page(); |
542 const int dir = transition.target_page > current_page ? -1 : 1; | 268 const int dir = transition.target_page > current_page ? -1 : 1; |
543 | 269 |
544 const double progress = 1.0 - pow(1.0 - transition.progress, 4); | 270 const double progress = 1.0 - pow(1.0 - transition.progress, 4); |
545 const int shift = kMaxOverScrollShift * progress * dir; | 271 const int shift = kMaxOverScrollShift * progress * dir; |
546 | 272 |
547 gfx::Rect shifted(view_bounds_); | 273 gfx::Rect shifted(view_bounds_); |
548 shifted.set_x(shifted.x() + shift); | 274 shifted.set_x(shifted.x() + shift); |
549 | 275 |
550 widget->SetBounds(shifted); | 276 widget->SetBounds(shifted); |
551 | 277 |
552 should_snap_back_ = true; | 278 should_snap_back_ = true; |
553 } else if (should_snap_back_) { | 279 } else if (should_snap_back_) { |
554 should_snap_back_ = false; | 280 should_snap_back_ = false; |
555 ui::ScopedLayerAnimationSettings animation(widget_animator); | 281 ui::ScopedLayerAnimationSettings animation(widget_animator); |
556 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 282 animation.SetTransitionDuration( |
557 app_list::kOverscrollPageTransitionDurationMs)); | 283 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); |
558 widget->SetBounds(view_bounds_); | 284 widget->SetBounds(view_bounds_); |
559 } | 285 } |
560 } | 286 } |
561 | 287 |
562 } // namespace ash | 288 } // namespace app_list |
OLD | NEW |