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

Side by Side Diff: chrome/browser/ui/ash/app_list/app_list_shower_ash.cc

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

Powered by Google App Engine
This is Rietveld 408576698