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