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

Side by Side Diff: ash/app_list/app_list_shower_delegate.cc

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

Powered by Google App Engine
This is Rietveld 408576698