| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/views/apps_container_view.h" | 5 #include "ui/app_list/views/apps_container_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
| 12 #include "ui/app_list/app_list_folder_item.h" | 12 #include "ui/app_list/app_list_folder_item.h" |
| 13 #include "ui/app_list/app_list_switches.h" | 13 #include "ui/app_list/app_list_switches.h" |
| 14 #include "ui/app_list/pagination_model.h" |
| 14 #include "ui/app_list/views/app_list_folder_view.h" | 15 #include "ui/app_list/views/app_list_folder_view.h" |
| 15 #include "ui/app_list/views/app_list_item_view.h" | 16 #include "ui/app_list/views/app_list_item_view.h" |
| 16 #include "ui/app_list/views/app_list_main_view.h" | 17 #include "ui/app_list/views/app_list_main_view.h" |
| 17 #include "ui/app_list/views/apps_grid_view.h" | 18 #include "ui/app_list/views/apps_grid_view.h" |
| 18 #include "ui/app_list/views/folder_background_view.h" | 19 #include "ui/app_list/views/folder_background_view.h" |
| 19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 20 | 21 |
| 21 namespace app_list { | 22 namespace app_list { |
| 22 | 23 |
| 24 namespace { |
| 25 |
| 26 const int kMinMouseWheelToSwitchPage = 20; |
| 27 const int kMinScrollToSwitchPage = 20; |
| 28 const int kMinHorizVelocityToSwitchPage = 800; |
| 29 |
| 30 const double kFinishTransitionThreshold = 0.33; |
| 31 |
| 32 } // namespace |
| 33 |
| 23 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, | 34 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, |
| 24 AppListModel* model) | 35 AppListModel* model) |
| 25 : model_(model), | 36 : model_(model), |
| 26 show_state_(SHOW_NONE), | 37 show_state_(SHOW_NONE), |
| 27 top_icon_animation_pending_count_(0) { | 38 top_icon_animation_pending_count_(0) { |
| 28 apps_grid_view_ = new AppsGridView(app_list_main_view); | 39 apps_grid_view_ = new AppsGridView(app_list_main_view); |
| 29 int cols = kPreferredCols; | 40 int cols = kPreferredCols; |
| 30 int rows = kPreferredRows; | 41 int rows = kPreferredRows; |
| 31 // ShouldCenterWindow also implies that it is wide instead of tall. | 42 // ShouldCenterWindow also implies that it is wide instead of tall. |
| 32 if (app_list_main_view->ShouldCenterWindow()) { | 43 if (app_list_main_view->ShouldCenterWindow()) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 141 } |
| 131 } | 142 } |
| 132 | 143 |
| 133 bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) { | 144 bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) { |
| 134 if (show_state_ == SHOW_APPS) | 145 if (show_state_ == SHOW_APPS) |
| 135 return apps_grid_view_->OnKeyPressed(event); | 146 return apps_grid_view_->OnKeyPressed(event); |
| 136 else | 147 else |
| 137 return app_list_folder_view_->OnKeyPressed(event); | 148 return app_list_folder_view_->OnKeyPressed(event); |
| 138 } | 149 } |
| 139 | 150 |
| 151 bool AppsContainerView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 152 int offset; |
| 153 if (abs(event.x_offset()) > abs(event.y_offset())) |
| 154 offset = event.x_offset(); |
| 155 else |
| 156 offset = event.y_offset(); |
| 157 |
| 158 if (abs(offset) > kMinMouseWheelToSwitchPage) { |
| 159 if (!GetPaginationModel()->has_transition()) { |
| 160 GetPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
| 161 } |
| 162 return true; |
| 163 } |
| 164 |
| 165 return false; |
| 166 } |
| 167 |
| 168 void AppsContainerView::OnGestureEvent(ui::GestureEvent* event) { |
| 169 switch (event->type()) { |
| 170 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 171 GetPaginationModel()->StartScroll(); |
| 172 event->SetHandled(); |
| 173 return; |
| 174 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 175 // event->details.scroll_x() > 0 means moving contents to right. That is, |
| 176 // transitioning to previous page. |
| 177 GetPaginationModel()->UpdateScroll(event->details().scroll_x() / |
| 178 GetContentsBounds().width()); |
| 179 event->SetHandled(); |
| 180 return; |
| 181 case ui::ET_GESTURE_SCROLL_END: |
| 182 GetPaginationModel()->EndScroll( |
| 183 GetPaginationModel()->transition().progress < |
| 184 kFinishTransitionThreshold); |
| 185 event->SetHandled(); |
| 186 return; |
| 187 case ui::ET_SCROLL_FLING_START: { |
| 188 GetPaginationModel()->EndScroll(true); |
| 189 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { |
| 190 GetPaginationModel()->SelectPageRelative( |
| 191 event->details().velocity_x() < 0 ? 1 : -1, true); |
| 192 } |
| 193 event->SetHandled(); |
| 194 return; |
| 195 } |
| 196 default: |
| 197 break; |
| 198 } |
| 199 } |
| 200 |
| 201 void AppsContainerView::OnScrollEvent(ui::ScrollEvent* event) { |
| 202 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) |
| 203 return; |
| 204 |
| 205 float offset; |
| 206 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) |
| 207 offset = event->x_offset(); |
| 208 else |
| 209 offset = event->y_offset(); |
| 210 |
| 211 if (std::abs(offset) > kMinScrollToSwitchPage) { |
| 212 if (!GetPaginationModel()->has_transition()) { |
| 213 GetPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
| 214 } |
| 215 event->SetHandled(); |
| 216 event->StopPropagation(); |
| 217 } |
| 218 } |
| 219 |
| 140 void AppsContainerView::OnTopIconAnimationsComplete() { | 220 void AppsContainerView::OnTopIconAnimationsComplete() { |
| 141 --top_icon_animation_pending_count_; | 221 --top_icon_animation_pending_count_; |
| 142 | 222 |
| 143 if (!top_icon_animation_pending_count_) { | 223 if (!top_icon_animation_pending_count_) { |
| 144 // Clean up the transitional views used for top item icon animation. | 224 // Clean up the transitional views used for top item icon animation. |
| 145 top_icon_views_.clear(); | 225 top_icon_views_.clear(); |
| 146 | 226 |
| 147 // Show the folder icon when closing the folder. | 227 // Show the folder icon when closing the folder. |
| 148 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && | 228 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && |
| 149 apps_grid_view_->activated_folder_item_view()) { | 229 apps_grid_view_->activated_folder_item_view()) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // Get the active folder's icon bounds relative to AppsContainerView. | 273 // Get the active folder's icon bounds relative to AppsContainerView. |
| 194 AppListItemView* folder_item_view = | 274 AppListItemView* folder_item_view = |
| 195 apps_grid_view_->activated_folder_item_view(); | 275 apps_grid_view_->activated_folder_item_view(); |
| 196 gfx::Rect to_grid_view = folder_item_view->ConvertRectToParent( | 276 gfx::Rect to_grid_view = folder_item_view->ConvertRectToParent( |
| 197 folder_item_view->GetIconBounds()); | 277 folder_item_view->GetIconBounds()); |
| 198 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view); | 278 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view); |
| 199 | 279 |
| 200 return AppListFolderItem::GetTopIconsBounds(to_container); | 280 return AppListFolderItem::GetTopIconsBounds(to_container); |
| 201 } | 281 } |
| 202 | 282 |
| 283 PaginationModel* AppsContainerView::GetPaginationModel() { |
| 284 return apps_grid_view_->pagination_model(); |
| 285 } |
| 286 |
| 203 void AppsContainerView::CreateViewsForFolderTopItemsAnimation( | 287 void AppsContainerView::CreateViewsForFolderTopItemsAnimation( |
| 204 AppListFolderItem* active_folder, | 288 AppListFolderItem* active_folder, |
| 205 bool open_folder) { | 289 bool open_folder) { |
| 206 top_icon_views_.clear(); | 290 top_icon_views_.clear(); |
| 207 std::vector<gfx::Rect> top_items_bounds = | 291 std::vector<gfx::Rect> top_items_bounds = |
| 208 GetTopItemIconBoundsInActiveFolder(); | 292 GetTopItemIconBoundsInActiveFolder(); |
| 209 top_icon_animation_pending_count_ = | 293 top_icon_animation_pending_count_ = |
| 210 std::min(kNumFolderTopItems, active_folder->item_list()->item_count()); | 294 std::min(kNumFolderTopItems, active_folder->item_list()->item_count()); |
| 211 for (size_t i = 0; i < top_icon_animation_pending_count_; ++i) { | 295 for (size_t i = 0; i < top_icon_animation_pending_count_; ++i) { |
| 212 if (active_folder->GetTopIcon(i).isNull()) | 296 if (active_folder->GetTopIcon(i).isNull()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 230 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { | 314 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { |
| 231 if (folder_item) | 315 if (folder_item) |
| 232 CreateViewsForFolderTopItemsAnimation(folder_item, false); | 316 CreateViewsForFolderTopItemsAnimation(folder_item, false); |
| 233 | 317 |
| 234 // Hide the active folder item until the animation completes. | 318 // Hide the active folder item until the animation completes. |
| 235 if (apps_grid_view_->activated_folder_item_view()) | 319 if (apps_grid_view_->activated_folder_item_view()) |
| 236 apps_grid_view_->activated_folder_item_view()->SetVisible(false); | 320 apps_grid_view_->activated_folder_item_view()->SetVisible(false); |
| 237 } | 321 } |
| 238 | 322 |
| 239 } // namespace app_list | 323 } // namespace app_list |
| OLD | NEW |