| 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_controller.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // Duration for show/hide animation in milliseconds. | 32 // Duration for show/hide animation in milliseconds. |
| 33 const int kAnimationDurationMs = 200; | 33 const int kAnimationDurationMs = 200; |
| 34 | 34 |
| 35 // Offset in pixels to animation away/towards the launcher. | 35 // Offset in pixels to animation away/towards the launcher. |
| 36 const int kAnimationOffset = 8; | 36 const int kAnimationOffset = 8; |
| 37 | 37 |
| 38 // The maximum shift in pixels when over-scroll happens. | 38 // The maximum shift in pixels when over-scroll happens. |
| 39 const int kMaxOverScrollShift = 48; | 39 const int kMaxOverScrollShift = 48; |
| 40 | 40 |
| 41 // The alternate shelf style adjusts the bubble to be flush with the shelf | |
| 42 // when there is no bubble-tip. This is the tip height which needs to be | |
| 43 // offsetted. | |
| 44 const int kArrowTipHeight = 10; | |
| 45 | |
| 46 // The minimal anchor position offset to make sure that the bubble is still on | 41 // The minimal anchor position offset to make sure that the bubble is still on |
| 47 // the screen with 8 pixels spacing on the left / right. This constant is a | 42 // the screen with 8 pixels spacing on the left / right. This constant is a |
| 48 // result of minimal bubble arrow sizes and offsets. | 43 // result of minimal bubble arrow sizes and offsets. |
| 49 const int kMinimalAnchorPositionOffset = 57; | 44 const int kMinimalAnchorPositionOffset = 57; |
| 50 | 45 |
| 51 ui::Layer* GetLayer(views::Widget* widget) { | 46 ui::Layer* GetLayer(views::Widget* widget) { |
| 52 return widget->GetNativeView()->layer(); | 47 return widget->GetNativeView()->layer(); |
| 53 } | 48 } |
| 54 | 49 |
| 55 // Gets arrow location based on shelf alignment. | 50 // Gets arrow location based on shelf alignment. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 80 offseted.Offset(kAnimationOffset, 0); | 75 offseted.Offset(kAnimationOffset, 0); |
| 81 break; | 76 break; |
| 82 case SHELF_ALIGNMENT_TOP: | 77 case SHELF_ALIGNMENT_TOP: |
| 83 offseted.Offset(0, -kAnimationOffset); | 78 offseted.Offset(0, -kAnimationOffset); |
| 84 break; | 79 break; |
| 85 } | 80 } |
| 86 | 81 |
| 87 return offseted; | 82 return offseted; |
| 88 } | 83 } |
| 89 | 84 |
| 90 // Using |button_bounds|, determine the anchor so that the bubble gets shown | 85 // Using |button_bounds|, determine the anchor offset so that the bubble gets |
| 91 // above the shelf (used for the alternate shelf theme). | 86 // shown above the shelf (used for the alternate shelf theme). |
| 92 gfx::Point GetAdjustAnchorPositionToShelf( | 87 gfx::Vector2d GetAnchorPositionOffsetToShelf( |
| 93 const gfx::Rect& button_bounds, views::Widget* widget) { | 88 const gfx::Rect& button_bounds, views::Widget* widget) { |
| 94 DCHECK(Shell::HasInstance()); | 89 DCHECK(Shell::HasInstance()); |
| 95 ShelfAlignment shelf_alignment = Shell::GetInstance()->GetShelfAlignment( | 90 ShelfAlignment shelf_alignment = Shell::GetInstance()->GetShelfAlignment( |
| 96 widget->GetNativeView()->GetRootWindow()); | 91 widget->GetNativeView()->GetRootWindow()); |
| 97 gfx::Point anchor(button_bounds.CenterPoint()); | 92 gfx::Point anchor(button_bounds.CenterPoint()); |
| 98 switch (shelf_alignment) { | 93 switch (shelf_alignment) { |
| 99 case SHELF_ALIGNMENT_TOP: | 94 case SHELF_ALIGNMENT_TOP: |
| 100 case SHELF_ALIGNMENT_BOTTOM: | 95 case SHELF_ALIGNMENT_BOTTOM: |
| 101 { | 96 if (base::i18n::IsRTL()) { |
| 102 if (base::i18n::IsRTL()) { | 97 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); |
| 103 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); | 98 return gfx::Vector2d( |
| 104 anchor.set_x(std::min(screen_width - kMinimalAnchorPositionOffset, | 99 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(), |
| 105 anchor.x())); | 100 0), 0); |
| 106 } else { | |
| 107 anchor.set_x(std::max(kMinimalAnchorPositionOffset, anchor.x())); | |
| 108 } | |
| 109 int offset = button_bounds.height() / 2 - kArrowTipHeight; | |
| 110 if (shelf_alignment == SHELF_ALIGNMENT_TOP) | |
| 111 offset = -offset; | |
| 112 anchor.set_y(anchor.y() - offset); | |
| 113 } | 101 } |
| 114 break; | 102 return gfx::Vector2d( |
| 103 std::max(kMinimalAnchorPositionOffset - anchor.x(), 0), 0); |
| 115 case SHELF_ALIGNMENT_LEFT: | 104 case SHELF_ALIGNMENT_LEFT: |
| 116 anchor.set_x(button_bounds.right() - kArrowTipHeight); | 105 return gfx::Vector2d( |
| 117 anchor.set_y(std::max(kMinimalAnchorPositionOffset, anchor.y())); | 106 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); |
| 118 break; | |
| 119 case SHELF_ALIGNMENT_RIGHT: | 107 case SHELF_ALIGNMENT_RIGHT: |
| 120 anchor.set_x(button_bounds.x() + kArrowTipHeight); | 108 return gfx::Vector2d( |
| 121 anchor.set_y(std::max(kMinimalAnchorPositionOffset, anchor.y())); | 109 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); |
| 122 break; | 110 default: |
| 111 NOTREACHED(); |
| 112 return gfx::Vector2d(); |
| 123 } | 113 } |
| 124 | |
| 125 return anchor; | |
| 126 } | 114 } |
| 127 | 115 |
| 128 } // namespace | 116 } // namespace |
| 129 | 117 |
| 130 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
| 131 // AppListController, public: | 119 // AppListController, public: |
| 132 | 120 |
| 133 AppListController::AppListController() | 121 AppListController::AppListController() |
| 134 : pagination_model_(new app_list::PaginationModel), | 122 : pagination_model_(new app_list::PaginationModel), |
| 135 is_visible_(false), | 123 is_visible_(false), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 165 } else if (is_visible_) { | 153 } else if (is_visible_) { |
| 166 // AppListModel and AppListViewDelegate are owned by AppListView. They | 154 // AppListModel and AppListViewDelegate are owned by AppListView. They |
| 167 // will be released with AppListView on close. | 155 // will be released with AppListView on close. |
| 168 app_list::AppListView* view = new app_list::AppListView( | 156 app_list::AppListView* view = new app_list::AppListView( |
| 169 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); | 157 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); |
| 170 aura::Window* container = GetRootWindowController(window->GetRootWindow())-> | 158 aura::Window* container = GetRootWindowController(window->GetRootWindow())-> |
| 171 GetContainer(kShellWindowId_AppListContainer); | 159 GetContainer(kShellWindowId_AppListContainer); |
| 172 if (ash::switches::UseAlternateShelfLayout()) { | 160 if (ash::switches::UseAlternateShelfLayout()) { |
| 173 gfx::Rect applist_button_bounds = Launcher::ForWindow(container)-> | 161 gfx::Rect applist_button_bounds = Launcher::ForWindow(container)-> |
| 174 GetAppListButtonView()->GetBoundsInScreen(); | 162 GetAppListButtonView()->GetBoundsInScreen(); |
| 175 view->InitAsBubble( | 163 view->InitAsBubbleAttachedToAnchor( |
| 176 container, | 164 container, |
| 177 pagination_model_.get(), | 165 pagination_model_.get(), |
| 178 NULL, | 166 Launcher::ForWindow(container)->GetAppListButtonView(), |
| 179 GetAdjustAnchorPositionToShelf(applist_button_bounds, | 167 GetAnchorPositionOffsetToShelf(applist_button_bounds, |
| 180 Launcher::ForWindow(container)->GetAppListButtonView()-> | 168 Launcher::ForWindow(container)->GetAppListButtonView()-> |
| 181 GetWidget()), | 169 GetWidget()), |
| 182 GetBubbleArrow(container), | 170 GetBubbleArrow(container), |
| 183 true /* border_accepts_events */); | 171 true /* border_accepts_events */); |
| 184 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 172 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 185 } else { | 173 } else { |
| 186 view->InitAsBubble( | 174 view->InitAsBubbleAttachedToAnchor( |
| 187 container, | 175 container, |
| 188 pagination_model_.get(), | 176 pagination_model_.get(), |
| 189 Launcher::ForWindow(container)->GetAppListButtonView(), | 177 Launcher::ForWindow(container)->GetAppListButtonView(), |
| 190 gfx::Point(), | 178 gfx::Vector2d(), |
| 191 GetBubbleArrow(container), | 179 GetBubbleArrow(container), |
| 192 true /* border_accepts_events */); | 180 true /* border_accepts_events */); |
| 193 } | 181 } |
| 194 SetView(view); | 182 SetView(view); |
| 195 // By setting us as DnD recipient, the app list knows that we can | 183 // By setting us as DnD recipient, the app list knows that we can |
| 196 // handle items. | 184 // handle items. |
| 197 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 185 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 ash::switches::kAshDisableDragAndDropAppListToLauncher)) { | 186 ash::switches::kAshDisableDragAndDropAppListToLauncher)) { |
| 199 SetDragAndDropHostOfCurrentAppList( | 187 SetDragAndDropHostOfCurrentAppList( |
| 200 Launcher::ForWindow(window)->GetDragAndDropHostForAppList()); | 188 Launcher::ForWindow(window)->GetDragAndDropHostForAppList()); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 should_snap_back_ = false; | 409 should_snap_back_ = false; |
| 422 ui::ScopedLayerAnimationSettings animation(widget_animator); | 410 ui::ScopedLayerAnimationSettings animation(widget_animator); |
| 423 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 411 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 424 app_list::kOverscrollPageTransitionDurationMs)); | 412 app_list::kOverscrollPageTransitionDurationMs)); |
| 425 widget->SetBounds(view_bounds_); | 413 widget->SetBounds(view_bounds_); |
| 426 } | 414 } |
| 427 } | 415 } |
| 428 | 416 |
| 429 } // namespace internal | 417 } // namespace internal |
| 430 } // namespace ash | 418 } // namespace ash |
| OLD | NEW |