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 "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "ui/app_list/app_list_constants.h" | 14 #include "ui/app_list/app_list_constants.h" |
15 #include "ui/app_list/app_list_folder_item.h" | 15 #include "ui/app_list/app_list_folder_item.h" |
16 #include "ui/app_list/app_list_item.h" | 16 #include "ui/app_list/app_list_item.h" |
17 #include "ui/app_list/app_list_switches.h" | 17 #include "ui/app_list/app_list_switches.h" |
18 #include "ui/app_list/pagination_model.h" | 18 #include "ui/app_list/pagination_model.h" |
19 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 19 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
20 #include "ui/app_list/views/app_list_folder_view.h" | 20 //#include "ui/app_list/views/app_list_folder_view.h" |
21 #include "ui/app_list/views/app_list_item_view.h" | 21 #include "ui/app_list/views/app_list_item_view.h" |
22 #include "ui/app_list/views/apps_grid_view_delegate.h" | 22 #include "ui/app_list/views/apps_grid_view_delegate.h" |
| 23 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" |
23 #include "ui/app_list/views/page_switcher.h" | 24 #include "ui/app_list/views/page_switcher.h" |
24 #include "ui/app_list/views/pulsing_block_view.h" | 25 //#include "ui/app_list/views/pulsing_block_view.h" |
25 #include "ui/app_list/views/top_icon_animation_view.h" | 26 #include "ui/app_list/views/top_icon_animation_view.h" |
26 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
27 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
28 #include "ui/gfx/animation/animation.h" | 29 #include "ui/gfx/animation/animation.h" |
29 #include "ui/views/border.h" | 30 #include "ui/views/border.h" |
30 #include "ui/views/controls/webview/webview.h" | 31 #include "ui/views/controls/webview/webview.h" |
31 #include "ui/views/view_model_utils.h" | 32 #include "ui/views/view_model_utils.h" |
32 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
33 | 34 |
34 #if defined(USE_AURA) | 35 #if defined(USE_AURA) |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 gfx::Point drag_view_offset_; | 306 gfx::Point drag_view_offset_; |
306 bool has_shortcut_path_; | 307 bool has_shortcut_path_; |
307 base::FilePath shortcut_path_; | 308 base::FilePath shortcut_path_; |
308 bool running_; | 309 bool running_; |
309 bool canceled_; | 310 bool canceled_; |
310 | 311 |
311 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag); | 312 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag); |
312 }; | 313 }; |
313 #endif // defined(OS_WIN) | 314 #endif // defined(OS_WIN) |
314 | 315 |
| 316 const char AppsGridView::kViewClassName[] = "AppsGridView"; |
| 317 |
315 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate, | 318 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate, |
316 PaginationModel* pagination_model) | 319 PaginationModel* pagination_model) |
317 : model_(NULL), | 320 : model_(NULL), |
318 item_list_(NULL), | 321 item_list_(NULL), |
319 delegate_(delegate), | 322 delegate_(delegate), |
320 folder_delegate_(NULL), | 323 folder_delegate_(NULL), |
321 pagination_model_(pagination_model), | 324 pagination_model_(pagination_model), |
322 page_switcher_view_(new PageSwitcher(pagination_model)), | 325 page_switcher_view_(new PageSwitcher(pagination_model)), |
323 cols_(0), | 326 cols_(0), |
324 rows_per_page_(0), | 327 rows_per_page_(0), |
325 selected_view_(NULL), | 328 selected_view_(NULL), |
326 drag_view_(NULL), | 329 drag_view_(NULL), |
327 drag_start_page_(-1), | 330 drag_start_page_(-1), |
328 drag_pointer_(NONE), | 331 drag_pointer_(NONE), |
329 drop_attempt_(DROP_FOR_NONE), | 332 drop_attempt_(DROP_FOR_NONE), |
330 drag_and_drop_host_(NULL), | 333 drag_and_drop_host_(NULL), |
331 forward_events_to_drag_and_drop_host_(false), | 334 forward_events_to_drag_and_drop_host_(false), |
332 page_flip_target_(-1), | 335 page_flip_target_(-1), |
333 page_flip_delay_in_ms_(kPageFlipDelayInMs), | 336 page_flip_delay_in_ms_(kPageFlipDelayInMs), |
334 bounds_animator_(this), | 337 bounds_animator_(this), |
335 activated_item_view_(NULL), | 338 activated_item_view_(NULL), |
336 dragging_for_reparent_item_(false), | 339 dragging_for_reparent_item_(false), |
337 weak_factory_(this) { | 340 weak_factory_(this) { |
| 341 #if defined(USE_AURA) |
338 SetPaintToLayer(true); | 342 SetPaintToLayer(true); |
| 343 #endif |
339 SetFillsBoundsOpaquely(false); | 344 SetFillsBoundsOpaquely(false); |
340 | 345 |
341 pagination_model_->AddObserver(this); | 346 pagination_model_->AddObserver(this); |
342 AddChildView(page_switcher_view_); | 347 AddChildView(page_switcher_view_); |
343 } | 348 } |
344 | 349 |
345 AppsGridView::~AppsGridView() { | 350 AppsGridView::~AppsGridView() { |
346 // Coming here |drag_view_| should already be canceled since otherwise the | 351 // Coming here |drag_view_| should already be canceled since otherwise the |
347 // drag would disappear after the app list got animated away and closed, | 352 // drag would disappear after the app list got animated away and closed, |
348 // which would look odd. | 353 // which would look odd. |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 Layout(); | 771 Layout(); |
767 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); | 772 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); |
768 int end = std::min(view_model_.view_size(), | 773 int end = std::min(view_model_.view_size(), |
769 (page_index + 1 + kPrerenderPages) * tiles_per_page()); | 774 (page_index + 1 + kPrerenderPages) * tiles_per_page()); |
770 for (int i = start; i < end; i++) { | 775 for (int i = start; i < end; i++) { |
771 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); | 776 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); |
772 v->Prerender(); | 777 v->Prerender(); |
773 } | 778 } |
774 } | 779 } |
775 | 780 |
| 781 const char* AppsGridView::GetClassName() const { |
| 782 return kViewClassName; |
| 783 } |
| 784 |
776 gfx::Size AppsGridView::GetPreferredSize() { | 785 gfx::Size AppsGridView::GetPreferredSize() { |
777 const gfx::Insets insets(GetInsets()); | 786 const gfx::Insets insets(GetInsets()); |
778 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, | 787 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, |
779 kPreferredTileHeight); | 788 kPreferredTileHeight); |
780 const int page_switcher_height = | 789 const int page_switcher_height = |
781 page_switcher_view_->GetPreferredSize().height(); | 790 page_switcher_view_->GetPreferredSize().height(); |
782 return gfx::Size( | 791 return gfx::Size( |
783 tile_size.width() * cols_ + insets.width(), | 792 tile_size.width() * cols_ + insets.width(), |
784 tile_size.height() * rows_per_page_ + | 793 tile_size.height() * rows_per_page_ + |
785 page_switcher_height + insets.height()); | 794 page_switcher_height + insets.height()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 | 885 |
877 bounds_animator_.StopAnimatingView(details.child); | 886 bounds_animator_.StopAnimatingView(details.child); |
878 } | 887 } |
879 } | 888 } |
880 | 889 |
881 void AppsGridView::Update() { | 890 void AppsGridView::Update() { |
882 DCHECK(!selected_view_ && !drag_view_); | 891 DCHECK(!selected_view_ && !drag_view_); |
883 view_model_.Clear(); | 892 view_model_.Clear(); |
884 if (!item_list_ || !item_list_->item_count()) | 893 if (!item_list_ || !item_list_->item_count()) |
885 return; | 894 return; |
| 895 DLOG(INFO) << "AppsGridView::Update(n=" << item_list_->item_count() << ")"; |
886 for (size_t i = 0; i < item_list_->item_count(); ++i) { | 896 for (size_t i = 0; i < item_list_->item_count(); ++i) { |
887 views::View* view = CreateViewForItemAtIndex(i); | 897 views::View* view = CreateViewForItemAtIndex(i); |
888 view_model_.Add(view, i); | 898 view_model_.Add(view, i); |
889 AddChildView(view); | 899 AddChildView(view); |
890 } | 900 } |
891 UpdatePaging(); | 901 UpdatePaging(); |
892 UpdatePulsingBlockViews(); | 902 UpdatePulsingBlockViews(); |
893 Layout(); | 903 Layout(); |
894 SchedulePaint(); | 904 SchedulePaint(); |
895 } | 905 } |
(...skipping 16 matching lines...) Expand all Loading... |
912 if (pulsing_blocks_model_.view_size() == desired) | 922 if (pulsing_blocks_model_.view_size() == desired) |
913 return; | 923 return; |
914 | 924 |
915 while (pulsing_blocks_model_.view_size() > desired) { | 925 while (pulsing_blocks_model_.view_size() > desired) { |
916 views::View* view = pulsing_blocks_model_.view_at(0); | 926 views::View* view = pulsing_blocks_model_.view_at(0); |
917 pulsing_blocks_model_.Remove(0); | 927 pulsing_blocks_model_.Remove(0); |
918 delete view; | 928 delete view; |
919 } | 929 } |
920 | 930 |
921 while (pulsing_blocks_model_.view_size() < desired) { | 931 while (pulsing_blocks_model_.view_size() < desired) { |
| 932 NOTREACHED(); |
| 933 #ifdef FIXME |
922 views::View* view = new PulsingBlockView( | 934 views::View* view = new PulsingBlockView( |
923 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true); | 935 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true); |
924 pulsing_blocks_model_.Add(view, 0); | 936 pulsing_blocks_model_.Add(view, 0); |
925 AddChildView(view); | 937 AddChildView(view); |
| 938 #endif |
926 } | 939 } |
927 } | 940 } |
928 | 941 |
929 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { | 942 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
930 // The drag_view_ might be pending for deletion, therefore view_model_ | 943 // The drag_view_ might be pending for deletion, therefore view_model_ |
931 // may have one more item than item_list_. | 944 // may have one more item than item_list_. |
932 DCHECK_LE(index, item_list_->item_count()); | 945 DCHECK_LE(index, item_list_->item_count()); |
933 AppListItemView* view = new AppListItemView(this, | 946 AppListItemView* view = new AppListItemView(this, |
934 item_list_->item_at(index)); | 947 item_list_->item_at(index)); |
935 view->SetIconSize(icon_size_); | 948 view->SetIconSize(icon_size_); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1295 |
1283 void AppsGridView::OnReorderTimer() { | 1296 void AppsGridView::OnReorderTimer() { |
1284 if (drop_attempt_ == DROP_FOR_REORDER) | 1297 if (drop_attempt_ == DROP_FOR_REORDER) |
1285 AnimateToIdealBounds(); | 1298 AnimateToIdealBounds(); |
1286 } | 1299 } |
1287 | 1300 |
1288 void AppsGridView::OnFolderItemReparentTimer() { | 1301 void AppsGridView::OnFolderItemReparentTimer() { |
1289 DCHECK(folder_delegate_); | 1302 DCHECK(folder_delegate_); |
1290 if (drag_out_of_folder_container_) { | 1303 if (drag_out_of_folder_container_) { |
1291 folder_delegate_->ReparentItem(drag_view_, last_drag_point_); | 1304 folder_delegate_->ReparentItem(drag_view_, last_drag_point_); |
1292 | |
1293 // Set the flag in the folder's grid view. | 1305 // Set the flag in the folder's grid view. |
1294 dragging_for_reparent_item_ = true; | 1306 dragging_for_reparent_item_ = true; |
1295 | 1307 |
1296 // Do not observe any data change since it is going to be hidden. | 1308 // Do not observe any data change since it is going to be hidden. |
1297 item_list_->RemoveObserver(this); | 1309 item_list_->RemoveObserver(this); |
1298 item_list_ = NULL; | 1310 item_list_ = NULL; |
1299 } | 1311 } |
1300 } | 1312 } |
1301 | 1313 |
1302 void AppsGridView::OnFolderDroppingTimer() { | 1314 void AppsGridView::OnFolderDroppingTimer() { |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2110 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2099 bool is_target_folder) { | 2111 bool is_target_folder) { |
2100 AppListItemView* target_view = | 2112 AppListItemView* target_view = |
2101 static_cast<AppListItemView*>( | 2113 static_cast<AppListItemView*>( |
2102 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2114 GetViewAtSlotOnCurrentPage(target_index.slot)); |
2103 if (target_view) | 2115 if (target_view) |
2104 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2116 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2105 } | 2117 } |
2106 | 2118 |
2107 } // namespace app_list | 2119 } // namespace app_list |
OLD | NEW |