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 "ui/app_list/views/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "ui/app_list/app_list_constants.h" | 13 #include "ui/app_list/app_list_constants.h" |
14 #include "ui/app_list/app_list_folder_item.h" | 14 #include "ui/app_list/app_list_folder_item.h" |
15 #include "ui/app_list/app_list_item.h" | 15 #include "ui/app_list/app_list_item.h" |
16 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.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_drag_and_drop_host.h" | 18 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
19 #include "ui/app_list/views/app_list_folder_view.h" | 19 #include "ui/app_list/views/app_list_folder_view.h" |
20 #include "ui/app_list/views/app_list_item_view.h" | 20 #include "ui/app_list/views/app_list_item_view.h" |
21 #include "ui/app_list/views/apps_grid_view_delegate.h" | 21 #include "ui/app_list/views/apps_grid_view_delegate.h" |
| 22 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" |
22 #include "ui/app_list/views/page_switcher.h" | 23 #include "ui/app_list/views/page_switcher.h" |
23 #include "ui/app_list/views/pulsing_block_view.h" | 24 #include "ui/app_list/views/pulsing_block_view.h" |
24 #include "ui/app_list/views/top_icon_animation_view.h" | 25 #include "ui/app_list/views/top_icon_animation_view.h" |
25 #include "ui/compositor/scoped_layer_animation_settings.h" | 26 #include "ui/compositor/scoped_layer_animation_settings.h" |
26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
27 #include "ui/gfx/animation/animation.h" | 28 #include "ui/gfx/animation/animation.h" |
28 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
29 #include "ui/views/controls/webview/webview.h" | 30 #include "ui/views/controls/webview/webview.h" |
30 #include "ui/views/view_model_utils.h" | 31 #include "ui/views/view_model_utils.h" |
31 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 cols_ = cols; | 386 cols_ = cols; |
386 rows_per_page_ = rows_per_page; | 387 rows_per_page_ = rows_per_page; |
387 | 388 |
388 SetBorder(views::Border::CreateEmptyBorder( | 389 SetBorder(views::Border::CreateEmptyBorder( |
389 kTopPadding, kLeftRightPadding, 0, kLeftRightPadding)); | 390 kTopPadding, kLeftRightPadding, 0, kLeftRightPadding)); |
390 } | 391 } |
391 | 392 |
392 void AppsGridView::ResetForShowApps() { | 393 void AppsGridView::ResetForShowApps() { |
393 activated_folder_item_view_ = NULL; | 394 activated_folder_item_view_ = NULL; |
394 ClearDragState(); | 395 ClearDragState(); |
395 layer()->SetOpacity(1.0f); | 396 if (layer()) |
| 397 layer()->SetOpacity(1.0f); |
396 SetVisible(true); | 398 SetVisible(true); |
397 // Set all views to visible in case they weren't made visible again by an | 399 // Set all views to visible in case they weren't made visible again by an |
398 // incomplete animation. | 400 // incomplete animation. |
399 for (int i = 0; i < view_model_.view_size(); ++i) { | 401 for (int i = 0; i < view_model_.view_size(); ++i) { |
400 view_model_.view_at(i)->SetVisible(true); | 402 view_model_.view_at(i)->SetVisible(true); |
401 } | 403 } |
402 } | 404 } |
403 | 405 |
404 void AppsGridView::SetModel(AppListModel* model) { | 406 void AppsGridView::SetModel(AppListModel* model) { |
405 if (model_) | 407 if (model_) |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 for (int i = start; i < end; i++) { | 836 for (int i = start; i < end; i++) { |
835 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); | 837 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); |
836 v->Prerender(); | 838 v->Prerender(); |
837 } | 839 } |
838 } | 840 } |
839 | 841 |
840 bool AppsGridView::IsAnimatingView(views::View* view) { | 842 bool AppsGridView::IsAnimatingView(views::View* view) { |
841 return bounds_animator_.IsAnimating(view); | 843 return bounds_animator_.IsAnimating(view); |
842 } | 844 } |
843 | 845 |
| 846 const char* AppsGridView::GetClassName() const { |
| 847 return "GridView"; |
| 848 } |
| 849 |
844 gfx::Size AppsGridView::GetPreferredSize() const { | 850 gfx::Size AppsGridView::GetPreferredSize() const { |
845 const gfx::Insets insets(GetInsets()); | 851 const gfx::Insets insets(GetInsets()); |
846 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, | 852 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, |
847 kPreferredTileHeight); | 853 kPreferredTileHeight); |
848 const int page_switcher_height = | 854 const int page_switcher_height = |
849 page_switcher_view_->GetPreferredSize().height(); | 855 page_switcher_view_->GetPreferredSize().height(); |
850 return gfx::Size( | 856 return gfx::Size( |
851 tile_size.width() * cols_ + insets.width(), | 857 tile_size.width() * cols_ + insets.width(), |
852 tile_size.height() * rows_per_page_ + | 858 tile_size.height() * rows_per_page_ + |
853 page_switcher_height + insets.height()); | 859 page_switcher_height + insets.height()); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 } | 1002 } |
997 } | 1003 } |
998 | 1004 |
999 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { | 1005 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
1000 // The drag_view_ might be pending for deletion, therefore view_model_ | 1006 // The drag_view_ might be pending for deletion, therefore view_model_ |
1001 // may have one more item than item_list_. | 1007 // may have one more item than item_list_. |
1002 DCHECK_LE(index, item_list_->item_count()); | 1008 DCHECK_LE(index, item_list_->item_count()); |
1003 AppListItemView* view = new AppListItemView(this, | 1009 AppListItemView* view = new AppListItemView(this, |
1004 item_list_->item_at(index)); | 1010 item_list_->item_at(index)); |
1005 view->SetIconSize(icon_size_); | 1011 view->SetIconSize(icon_size_); |
1006 #if defined(USE_AURA) | |
1007 view->SetPaintToLayer(true); | 1012 view->SetPaintToLayer(true); |
1008 view->SetFillsBoundsOpaquely(false); | 1013 view->SetFillsBoundsOpaquely(false); |
1009 #endif | |
1010 return view; | 1014 return view; |
1011 } | 1015 } |
1012 | 1016 |
1013 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( | 1017 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( |
1014 int model_index) const { | 1018 int model_index) const { |
1015 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); | 1019 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); |
1016 } | 1020 } |
1017 | 1021 |
1018 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { | 1022 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { |
1019 return index.page * tiles_per_page() + index.slot; | 1023 return index.page * tiles_per_page() + index.slot; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 // Determine page of |current| and |target|. -1 means in the left invisible | 1229 // Determine page of |current| and |target|. -1 means in the left invisible |
1226 // page, 0 is the center visible page and 1 means in the right invisible page. | 1230 // page, 0 is the center visible page and 1 means in the right invisible page. |
1227 const int current_page = current.x() < 0 ? -1 : | 1231 const int current_page = current.x() < 0 ? -1 : |
1228 current.x() >= width() ? 1 : 0; | 1232 current.x() >= width() ? 1 : 0; |
1229 const int target_page = target.x() < 0 ? -1 : | 1233 const int target_page = target.x() < 0 ? -1 : |
1230 target.x() >= width() ? 1 : 0; | 1234 target.x() >= width() ? 1 : 0; |
1231 | 1235 |
1232 const int dir = current_page < target_page || | 1236 const int dir = current_page < target_page || |
1233 (current_page == target_page && current.y() < target.y()) ? 1 : -1; | 1237 (current_page == target_page && current.y() < target.y()) ? 1 : -1; |
1234 | 1238 |
1235 #if defined(USE_AURA) | |
1236 scoped_ptr<ui::Layer> layer; | 1239 scoped_ptr<ui::Layer> layer; |
1237 if (animate_current) { | 1240 if (animate_current) { |
1238 layer = view->RecreateLayer(); | 1241 layer = view->RecreateLayer(); |
1239 layer->SuppressPaint(); | 1242 layer->SuppressPaint(); |
1240 | 1243 |
1241 view->SetFillsBoundsOpaquely(false); | 1244 view->SetFillsBoundsOpaquely(false); |
1242 view->layer()->SetOpacity(0.f); | 1245 view->layer()->SetOpacity(0.f); |
1243 } | 1246 } |
1244 | 1247 |
1245 gfx::Rect current_out(current); | 1248 gfx::Rect current_out(current); |
1246 current_out.Offset(dir * kPreferredTileWidth, 0); | 1249 current_out.Offset(dir * kPreferredTileWidth, 0); |
1247 #endif | |
1248 | 1250 |
1249 gfx::Rect target_in(target); | 1251 gfx::Rect target_in(target); |
1250 if (animate_target) | 1252 if (animate_target) |
1251 target_in.Offset(-dir * kPreferredTileWidth, 0); | 1253 target_in.Offset(-dir * kPreferredTileWidth, 0); |
1252 view->SetBoundsRect(target_in); | 1254 view->SetBoundsRect(target_in); |
1253 bounds_animator_.AnimateViewTo(view, target); | 1255 bounds_animator_.AnimateViewTo(view, target); |
1254 | 1256 |
1255 #if defined(USE_AURA) | |
1256 bounds_animator_.SetAnimationDelegate( | 1257 bounds_animator_.SetAnimationDelegate( |
1257 view, | 1258 view, |
1258 new RowMoveAnimationDelegate(view, layer.release(), current_out), | 1259 new RowMoveAnimationDelegate(view, layer.release(), current_out), |
1259 true); | 1260 true); |
1260 #endif | |
1261 } | 1261 } |
1262 | 1262 |
1263 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event, | 1263 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event, |
1264 gfx::Point* drag_point) { | 1264 gfx::Point* drag_point) { |
1265 #if defined(USE_AURA) && !defined(OS_WIN) | 1265 #if defined(USE_AURA) && !defined(OS_WIN) |
1266 // Use root location of |event| instead of location in |drag_view_|'s | 1266 // Use root location of |event| instead of location in |drag_view_|'s |
1267 // coordinates because |drag_view_| has a scale transform and location | 1267 // coordinates because |drag_view_| has a scale transform and location |
1268 // could have integer round error and causes jitter. | 1268 // could have integer round error and causes jitter. |
1269 *drag_point = event.root_location(); | 1269 *drag_point = event.root_location(); |
1270 | 1270 |
1271 // GetWidget() could be NULL for tests. | 1271 // GetWidget() could be NULL for tests. |
1272 if (GetWidget()) { | 1272 if (GetWidget()) { |
1273 aura::Window::ConvertPointToTarget( | 1273 aura::Window::ConvertPointToTarget( |
1274 GetWidget()->GetNativeWindow()->GetRootWindow(), | 1274 GetWidget()->GetNativeWindow()->GetRootWindow(), |
1275 GetWidget()->GetNativeWindow(), | 1275 GetWidget()->GetNativeWindow(), |
1276 drag_point); | 1276 drag_point); |
1277 } | 1277 } |
1278 | 1278 |
1279 views::View::ConvertPointFromWidget(this, drag_point); | 1279 views::View::ConvertPointFromWidget(this, drag_point); |
1280 #else | 1280 #else |
1281 // For non-aura, root location is not clearly defined but |drag_view_| does | 1281 // For non-aura, root location is not clearly defined but |drag_view_| does |
1282 // not have the scale transform. So no round error would be introduced and | 1282 // not have the scale transform. So no round error would be introduced and |
1283 // it's okay to use View::ConvertPointToTarget. | 1283 // it's okay to use View::ConvertPointToTarget. |
| 1284 // TODO(tapted): Investigate round error. |
1284 *drag_point = event.location(); | 1285 *drag_point = event.location(); |
1285 views::View::ConvertPointToTarget(drag_view_, this, drag_point); | 1286 views::View::ConvertPointToTarget(drag_view_, this, drag_point); |
1286 #endif | 1287 #endif |
1287 } | 1288 } |
1288 | 1289 |
1289 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, | 1290 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, |
1290 bool use_page_button_hovering) { | 1291 bool use_page_button_hovering) { |
1291 if (EnableFolderDragDropUI()) { | 1292 if (EnableFolderDragDropUI()) { |
1292 CalculateDropTargetWithFolderEnabled(drag_point, use_page_button_hovering); | 1293 CalculateDropTargetWithFolderEnabled(drag_point, use_page_button_hovering); |
1293 return; | 1294 return; |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 Layout(); | 1942 Layout(); |
1942 } | 1943 } |
1943 | 1944 |
1944 void AppsGridView::OnAppListModelStatusChanged() { | 1945 void AppsGridView::OnAppListModelStatusChanged() { |
1945 UpdatePulsingBlockViews(); | 1946 UpdatePulsingBlockViews(); |
1946 Layout(); | 1947 Layout(); |
1947 SchedulePaint(); | 1948 SchedulePaint(); |
1948 } | 1949 } |
1949 | 1950 |
1950 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { | 1951 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { |
1951 #if defined(USE_AURA) | |
1952 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 1952 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
1953 animator.SetPreemptionStrategy( | 1953 animator.SetPreemptionStrategy( |
1954 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : | 1954 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : |
1955 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); | 1955 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); |
1956 view->layer()->SetOpacity(hide ? 0 : 1); | 1956 view->layer()->SetOpacity(hide ? 0 : 1); |
1957 #endif | |
1958 } | 1957 } |
1959 | 1958 |
1960 void AppsGridView::OnImplicitAnimationsCompleted() { | 1959 void AppsGridView::OnImplicitAnimationsCompleted() { |
1961 if (layer()->opacity() == 0.0f) | 1960 if (layer()->opacity() == 0.0f) |
1962 SetVisible(false); | 1961 SetVisible(false); |
1963 } | 1962 } |
1964 | 1963 |
1965 bool AppsGridView::EnableFolderDragDropUI() { | 1964 bool AppsGridView::EnableFolderDragDropUI() { |
1966 // Enable drag and drop folder UI only if it is at the app list root level | 1965 // Enable drag and drop folder UI only if it is at the app list root level |
1967 // and the switch is on and the target folder can still accept new items. | 1966 // and the switch is on and the target folder can still accept new items. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2147 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2149 bool is_target_folder) { | 2148 bool is_target_folder) { |
2150 AppListItemView* target_view = | 2149 AppListItemView* target_view = |
2151 static_cast<AppListItemView*>( | 2150 static_cast<AppListItemView*>( |
2152 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2151 GetViewAtSlotOnCurrentPage(target_index.slot)); |
2153 if (target_view) | 2152 if (target_view) |
2154 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2153 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2155 } | 2154 } |
2156 | 2155 |
2157 } // namespace app_list | 2156 } // namespace app_list |
OLD | NEW |