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

Side by Side Diff: ash/wm/app_list_controller.cc

Issue 115113006: Rename Launcher to Shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « ash/test/test_shelf_delegate.cc ('k') | ash/wm/base_layout_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/wm/app_list_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher.h"
9 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
10 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.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 "base/command_line.h" 15 #include "base/command_line.h"
16 #include "ui/app_list/app_list_constants.h" 16 #include "ui/app_list/app_list_constants.h"
17 #include "ui/app_list/pagination_model.h" 17 #include "ui/app_list/pagination_model.h"
18 #include "ui/app_list/views/app_list_view.h" 18 #include "ui/app_list/views/app_list_view.h"
19 #include "ui/aura/client/focus_client.h" 19 #include "ui/aura/client/focus_client.h"
20 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
21 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
22 #include "ui/compositor/layer.h" 22 #include "ui/compositor/layer.h"
23 #include "ui/compositor/scoped_layer_animation_settings.h" 23 #include "ui/compositor/scoped_layer_animation_settings.h"
24 #include "ui/events/event.h" 24 #include "ui/events/event.h"
25 #include "ui/gfx/transform_util.h" 25 #include "ui/gfx/transform_util.h"
26 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
27 27
28 namespace ash { 28 namespace ash {
29 namespace internal { 29 namespace internal {
30 30
31 namespace { 31 namespace {
32 32
33 // Duration for show/hide animation in milliseconds. 33 // Duration for show/hide animation in milliseconds.
34 const int kAnimationDurationMs = 200; 34 const int kAnimationDurationMs = 200;
35 35
36 // Offset in pixels to animation away/towards the launcher. 36 // Offset in pixels to animation away/towards the shelf.
37 const int kAnimationOffset = 8; 37 const int kAnimationOffset = 8;
38 38
39 // The maximum shift in pixels when over-scroll happens. 39 // The maximum shift in pixels when over-scroll happens.
40 const int kMaxOverScrollShift = 48; 40 const int kMaxOverScrollShift = 48;
41 41
42 // The minimal anchor position offset to make sure that the bubble is still on 42 // The minimal anchor position offset to make sure that the bubble is still on
43 // the screen with 8 pixels spacing on the left / right. This constant is a 43 // the screen with 8 pixels spacing on the left / right. This constant is a
44 // result of minimal bubble arrow sizes and offsets. 44 // result of minimal bubble arrow sizes and offsets.
45 const int kMinimalAnchorPositionOffset = 57; 45 const int kMinimalAnchorPositionOffset = 57;
46 46
47 ui::Layer* GetLayer(views::Widget* widget) { 47 ui::Layer* GetLayer(views::Widget* widget) {
48 return widget->GetNativeView()->layer(); 48 return widget->GetNativeView()->layer();
49 } 49 }
50 50
51 // Gets arrow location based on shelf alignment. 51 // Gets arrow location based on shelf alignment.
52 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { 52 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) {
53 DCHECK(Shell::HasInstance()); 53 DCHECK(Shell::HasInstance());
54 return ShelfLayoutManager::ForLauncher(window)-> 54 return ShelfLayoutManager::ForShelf(window)->
55 SelectValueForShelfAlignment( 55 SelectValueForShelfAlignment(
56 views::BubbleBorder::BOTTOM_CENTER, 56 views::BubbleBorder::BOTTOM_CENTER,
57 views::BubbleBorder::LEFT_CENTER, 57 views::BubbleBorder::LEFT_CENTER,
58 views::BubbleBorder::RIGHT_CENTER, 58 views::BubbleBorder::RIGHT_CENTER,
59 views::BubbleBorder::TOP_CENTER); 59 views::BubbleBorder::TOP_CENTER);
60 } 60 }
61 61
62 // Offset given |rect| towards shelf. 62 // Offset given |rect| towards shelf.
63 gfx::Rect OffsetTowardsShelf(const gfx::Rect& rect, views::Widget* widget) { 63 gfx::Rect OffsetTowardsShelf(const gfx::Rect& rect, views::Widget* widget) {
64 DCHECK(Shell::HasInstance()); 64 DCHECK(Shell::HasInstance());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ScheduleAnimation(); 160 ScheduleAnimation();
161 } else if (is_visible_) { 161 } else if (is_visible_) {
162 // AppListModel and AppListViewDelegate are owned by AppListView. They 162 // AppListModel and AppListViewDelegate are owned by AppListView. They
163 // will be released with AppListView on close. 163 // will be released with AppListView on close.
164 app_list::AppListView* view = new app_list::AppListView( 164 app_list::AppListView* view = new app_list::AppListView(
165 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); 165 Shell::GetInstance()->delegate()->CreateAppListViewDelegate());
166 aura::Window* root_window = window->GetRootWindow(); 166 aura::Window* root_window = window->GetRootWindow();
167 aura::Window* container = GetRootWindowController(root_window)-> 167 aura::Window* container = GetRootWindowController(root_window)->
168 GetContainer(kShellWindowId_AppListContainer); 168 GetContainer(kShellWindowId_AppListContainer);
169 if (ash::switches::UseAlternateShelfLayout()) { 169 if (ash::switches::UseAlternateShelfLayout()) {
170 gfx::Rect applist_button_bounds = Launcher::ForWindow(container)-> 170 gfx::Rect applist_button_bounds = Shelf::ForWindow(container)->
171 GetAppListButtonView()->GetBoundsInScreen(); 171 GetAppListButtonView()->GetBoundsInScreen();
172 // We need the location of the button within the local screen. 172 // We need the location of the button within the local screen.
173 applist_button_bounds = ash::ScreenAsh::ConvertRectFromScreen( 173 applist_button_bounds = ash::ScreenAsh::ConvertRectFromScreen(
174 root_window, 174 root_window,
175 applist_button_bounds); 175 applist_button_bounds);
176 view->InitAsBubbleAttachedToAnchor( 176 view->InitAsBubbleAttachedToAnchor(
177 container, 177 container,
178 pagination_model_.get(), 178 pagination_model_.get(),
179 Launcher::ForWindow(container)->GetAppListButtonView(), 179 Shelf::ForWindow(container)->GetAppListButtonView(),
180 GetAnchorPositionOffsetToShelf(applist_button_bounds, 180 GetAnchorPositionOffsetToShelf(applist_button_bounds,
181 Launcher::ForWindow(container)->GetAppListButtonView()-> 181 Shelf::ForWindow(container)->GetAppListButtonView()->
182 GetWidget()), 182 GetWidget()),
183 GetBubbleArrow(container), 183 GetBubbleArrow(container),
184 true /* border_accepts_events */); 184 true /* border_accepts_events */);
185 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 185 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
186 } else { 186 } else {
187 view->InitAsBubbleAttachedToAnchor( 187 view->InitAsBubbleAttachedToAnchor(
188 container, 188 container,
189 pagination_model_.get(), 189 pagination_model_.get(),
190 Launcher::ForWindow(container)->GetAppListButtonView(), 190 Shelf::ForWindow(container)->GetAppListButtonView(),
191 gfx::Vector2d(), 191 gfx::Vector2d(),
192 GetBubbleArrow(container), 192 GetBubbleArrow(container),
193 true /* border_accepts_events */); 193 true /* border_accepts_events */);
194 } 194 }
195 SetView(view); 195 SetView(view);
196 // By setting us as DnD recipient, the app list knows that we can 196 // By setting us as DnD recipient, the app list knows that we can
197 // handle items. 197 // handle items.
198 if (!CommandLine::ForCurrentProcess()->HasSwitch( 198 if (!CommandLine::ForCurrentProcess()->HasSwitch(
199 ash::switches::kAshDisableDragAndDropAppListToLauncher)) { 199 ash::switches::kAshDisableDragAndDropAppListToLauncher)) {
200 SetDragAndDropHostOfCurrentAppList( 200 SetDragAndDropHostOfCurrentAppList(
201 Launcher::ForWindow(window)->GetDragAndDropHostForAppList()); 201 Shelf::ForWindow(window)->GetDragAndDropHostForAppList());
202 } 202 }
203 } 203 }
204 // Update applist button status when app list visibility is changed. 204 // Update applist button status when app list visibility is changed.
205 Launcher::ForWindow(window)->GetAppListButtonView()->SchedulePaint(); 205 Shelf::ForWindow(window)->GetAppListButtonView()->SchedulePaint();
206 } 206 }
207 207
208 bool AppListController::IsVisible() const { 208 bool AppListController::IsVisible() const {
209 return view_ && view_->GetWidget()->IsVisible(); 209 return view_ && view_->GetWidget()->IsVisible();
210 } 210 }
211 211
212 aura::Window* AppListController::GetWindow() { 212 aura::Window* AppListController::GetWindow() {
213 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; 213 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL;
214 } 214 }
215 215
216 //////////////////////////////////////////////////////////////////////////////// 216 ////////////////////////////////////////////////////////////////////////////////
217 // AppListController, private: 217 // AppListController, private:
218 218
219 void AppListController::SetDragAndDropHostOfCurrentAppList( 219 void AppListController::SetDragAndDropHostOfCurrentAppList(
220 app_list::ApplicationDragAndDropHost* drag_and_drop_host) { 220 app_list::ApplicationDragAndDropHost* drag_and_drop_host) {
221 if (view_ && is_visible_) 221 if (view_ && is_visible_)
222 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 222 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
223 } 223 }
224 224
225 void AppListController::SetView(app_list::AppListView* view) { 225 void AppListController::SetView(app_list::AppListView* view) {
226 DCHECK(view_ == NULL); 226 DCHECK(view_ == NULL);
227 DCHECK(is_visible_); 227 DCHECK(is_visible_);
228 228
229 view_ = view; 229 view_ = view;
230 views::Widget* widget = view_->GetWidget(); 230 views::Widget* widget = view_->GetWidget();
231 widget->AddObserver(this); 231 widget->AddObserver(this);
232 Shell::GetInstance()->AddPreTargetHandler(this); 232 Shell::GetInstance()->AddPreTargetHandler(this);
233 Launcher::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); 233 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this);
234 widget->GetNativeView()->GetRootWindow()->AddObserver(this); 234 widget->GetNativeView()->GetRootWindow()->AddObserver(this);
235 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); 235 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this);
236 236
237 view_->ShowWhenReady(); 237 view_->ShowWhenReady();
238 } 238 }
239 239
240 void AppListController::ResetView() { 240 void AppListController::ResetView() {
241 if (!view_) 241 if (!view_)
242 return; 242 return;
243 243
244 views::Widget* widget = view_->GetWidget(); 244 views::Widget* widget = view_->GetWidget();
245 widget->RemoveObserver(this); 245 widget->RemoveObserver(this);
246 GetLayer(widget)->GetAnimator()->RemoveObserver(this); 246 GetLayer(widget)->GetAnimator()->RemoveObserver(this);
247 Shell::GetInstance()->RemovePreTargetHandler(this); 247 Shell::GetInstance()->RemovePreTargetHandler(this);
248 Launcher::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); 248 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this);
249 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); 249 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this);
250 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); 250 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this);
251 view_ = NULL; 251 view_ = NULL;
252 } 252 }
253 253
254 void AppListController::ScheduleAnimation() { 254 void AppListController::ScheduleAnimation() {
255 // Stop observing previous animation. 255 // Stop observing previous animation.
256 StopObservingImplicitAnimations(); 256 StopObservingImplicitAnimations();
257 257
258 views::Widget* widget = view_->GetWidget(); 258 views::Widget* widget = view_->GetWidget();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 should_snap_back_ = false; 430 should_snap_back_ = false;
431 ui::ScopedLayerAnimationSettings animation(widget_animator); 431 ui::ScopedLayerAnimationSettings animation(widget_animator);
432 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 432 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
433 app_list::kOverscrollPageTransitionDurationMs)); 433 app_list::kOverscrollPageTransitionDurationMs));
434 widget->SetBounds(view_bounds_); 434 widget->SetBounds(view_bounds_);
435 } 435 }
436 } 436 }
437 437
438 } // namespace internal 438 } // namespace internal
439 } // namespace ash 439 } // namespace ash
OLDNEW
« no previous file with comments | « ash/test/test_shelf_delegate.cc ('k') | ash/wm/base_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698