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 | 8 |
9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_folder_item.h" | 10 #include "ui/app_list/app_list_folder_item.h" |
11 #include "ui/app_list/pagination_model.h" | 11 #include "ui/app_list/pagination_model.h" |
12 #include "ui/app_list/views/app_list_folder_view.h" | 12 #include "ui/app_list/views/app_list_folder_view.h" |
13 #include "ui/app_list/views/app_list_item_view.h" | 13 #include "ui/app_list/views/app_list_item_view.h" |
14 #include "ui/app_list/views/app_list_main_view.h" | 14 #include "ui/app_list/views/app_list_main_view.h" |
15 #include "ui/app_list/views/apps_grid_view.h" | 15 #include "ui/app_list/views/apps_grid_view.h" |
16 #include "ui/app_list/views/folder_background_view.h" | 16 #include "ui/app_list/views/folder_background_view.h" |
17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
18 | 18 |
19 namespace app_list { | 19 namespace app_list { |
20 | 20 |
21 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, | 21 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, |
22 PaginationModel* pagination_model, | 22 PaginationModel* pagination_model, |
23 AppListModel* model, | 23 AppListModel* model, |
24 content::WebContents* start_page_contents) | 24 content::WebContents* start_page_contents) |
25 : model_(model), | 25 : model_(model), |
26 show_state_(SHOW_APPS), | 26 show_state_(SHOW_APPS), |
27 top_icon_animation_pending_count_(0) { | 27 top_icon_animation_pending_count_(0), |
28 show_apps_with_animation_(false) { | |
28 apps_grid_view_ = new AppsGridView( | 29 apps_grid_view_ = new AppsGridView( |
29 app_list_main_view, pagination_model, start_page_contents); | 30 app_list_main_view, pagination_model, start_page_contents); |
30 apps_grid_view_->SetLayout(kPreferredIconDimension, | 31 apps_grid_view_->SetLayout(kPreferredIconDimension, |
31 kPreferredCols, | 32 kPreferredCols, |
32 kPreferredRows); | 33 kPreferredRows); |
33 AddChildView(apps_grid_view_); | 34 AddChildView(apps_grid_view_); |
34 | 35 |
35 folder_background_view_ = new FolderBackgroundView(); | 36 folder_background_view_ = new FolderBackgroundView(); |
36 AddChildView(folder_background_view_); | 37 AddChildView(folder_background_view_); |
37 | 38 |
38 app_list_folder_view_ = new AppListFolderView( | 39 app_list_folder_view_ = new AppListFolderView( |
39 this, | 40 this, |
40 model, | 41 model, |
41 app_list_main_view, | 42 app_list_main_view, |
42 start_page_contents); | 43 start_page_contents); |
43 AddChildView(app_list_folder_view_); | 44 AddChildView(app_list_folder_view_); |
44 | 45 |
45 apps_grid_view_->SetModel(model_); | 46 apps_grid_view_->SetModel(model_); |
46 apps_grid_view_->SetItemList(model_->item_list()); | 47 apps_grid_view_->SetItemList(model_->item_list()); |
47 } | 48 } |
48 | 49 |
49 AppsContainerView::~AppsContainerView() { | 50 AppsContainerView::~AppsContainerView() { |
50 } | 51 } |
51 | 52 |
52 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) { | 53 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) { |
53 app_list_folder_view_->SetAppListFolderItem(folder_item); | 54 app_list_folder_view_->SetAppListFolderItem(folder_item); |
54 SetShowState(SHOW_ACTIVE_FOLDER); | 55 SetShowState(SHOW_ACTIVE_FOLDER, false); |
55 | 56 |
56 CreateViewsForFolderTopItemsAnimation(folder_item, true); | 57 CreateViewsForFolderTopItemsAnimation(folder_item, true); |
57 } | 58 } |
58 | 59 |
59 void AppsContainerView::ShowApps(AppListFolderItem* folder_item) { | 60 void AppsContainerView::ShowApps(AppListFolderItem* folder_item) { |
60 PrepareToShowApps(folder_item); | 61 PrepareToShowApps(folder_item); |
61 SetShowState(SHOW_APPS); | 62 SetShowState(SHOW_APPS, true); |
62 } | 63 } |
63 | 64 |
64 void AppsContainerView::SetDragAndDropHostOfCurrentAppList( | 65 void AppsContainerView::SetDragAndDropHostOfCurrentAppList( |
65 ApplicationDragAndDropHost* drag_and_drop_host) { | 66 ApplicationDragAndDropHost* drag_and_drop_host) { |
66 apps_grid_view()->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 67 apps_grid_view()->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
67 app_list_folder_view()->items_grid_view()-> | 68 app_list_folder_view()->items_grid_view()-> |
68 SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 69 SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
69 } | 70 } |
70 | 71 |
71 void AppsContainerView::ReparentFolderItemTransit( | 72 void AppsContainerView::ReparentFolderItemTransit( |
72 AppListFolderItem* folder_item) { | 73 AppListFolderItem* folder_item) { |
73 PrepareToShowApps(folder_item); | 74 PrepareToShowApps(folder_item); |
74 SetShowState(SHOW_ITEM_REPARENT); | 75 SetShowState(SHOW_ITEM_REPARENT, false); |
75 } | 76 } |
76 | 77 |
77 gfx::Size AppsContainerView::GetPreferredSize() { | 78 gfx::Size AppsContainerView::GetPreferredSize() { |
78 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); | 79 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); |
79 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); | 80 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); |
80 | 81 |
81 int width = std::max(grid_size.width(), folder_view_size.width()); | 82 int width = std::max(grid_size.width(), folder_view_size.width()); |
82 int height = std::max(grid_size.height(), folder_view_size.height()); | 83 int height = std::max(grid_size.height(), folder_view_size.height()); |
83 return gfx::Size(width, height); | 84 return gfx::Size(width, height); |
84 } | 85 } |
85 | 86 |
86 void AppsContainerView::Layout() { | 87 void AppsContainerView::Layout() { |
87 gfx::Rect rect(GetContentsBounds()); | 88 gfx::Rect rect(GetContentsBounds()); |
88 if (rect.IsEmpty()) | 89 if (rect.IsEmpty()) |
89 return; | 90 return; |
90 | 91 |
91 switch (show_state_) { | 92 switch (show_state_) { |
92 case SHOW_APPS: | 93 case SHOW_APPS: |
93 folder_background_view_->SetVisible(false); | 94 folder_background_view_->SetVisible(false); |
94 app_list_folder_view_->ScheduleShowHideAnimation(false, false); | 95 if (show_apps_with_animation_) |
96 app_list_folder_view_->ScheduleShowHideAnimation(false, false); | |
97 else | |
98 app_list_folder_view_->HideViewImmediately(); | |
95 apps_grid_view_->SetBoundsRect(rect); | 99 apps_grid_view_->SetBoundsRect(rect); |
96 apps_grid_view_->ScheduleShowHideAnimation(true); | 100 if (show_apps_with_animation_) |
101 apps_grid_view_->ScheduleShowHideAnimation(true); | |
102 else | |
103 apps_grid_view_->SetVisible(true); | |
xiyuan
2014/02/13 22:53:42
Can we move the animation and show/hide code into
jennyz
2014/02/13 23:42:59
Done.
| |
97 break; | 104 break; |
98 case SHOW_ACTIVE_FOLDER: | 105 case SHOW_ACTIVE_FOLDER: |
99 folder_background_view_->SetBoundsRect(rect); | 106 folder_background_view_->SetBoundsRect(rect); |
100 folder_background_view_->SetVisible(true); | 107 folder_background_view_->SetVisible(true); |
101 apps_grid_view_->ScheduleShowHideAnimation(false); | 108 apps_grid_view_->ScheduleShowHideAnimation(false); |
102 app_list_folder_view_->SetBoundsRect(rect); | 109 app_list_folder_view_->SetBoundsRect(rect); |
103 app_list_folder_view_->ScheduleShowHideAnimation(true, false); | 110 app_list_folder_view_->ScheduleShowHideAnimation(true, false); |
104 break; | 111 break; |
105 case SHOW_ITEM_REPARENT: | 112 case SHOW_ITEM_REPARENT: |
106 folder_background_view_->SetVisible(false); | 113 folder_background_view_->SetVisible(false); |
(...skipping 22 matching lines...) Expand all Loading... | |
129 top_icon_views_.clear(); | 136 top_icon_views_.clear(); |
130 | 137 |
131 // Show the folder icon when closing the folder. | 138 // Show the folder icon when closing the folder. |
132 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && | 139 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && |
133 apps_grid_view_->activated_item_view()) { | 140 apps_grid_view_->activated_item_view()) { |
134 apps_grid_view_->activated_item_view()->SetVisible(true); | 141 apps_grid_view_->activated_item_view()->SetVisible(true); |
135 } | 142 } |
136 } | 143 } |
137 } | 144 } |
138 | 145 |
139 void AppsContainerView::SetShowState(ShowState show_state) { | 146 void AppsContainerView::SetShowState(ShowState show_state, |
147 bool show_apps_with_animation) { | |
140 if (show_state_ == show_state) | 148 if (show_state_ == show_state) |
141 return; | 149 return; |
142 | 150 |
143 show_state_ = show_state; | 151 show_state_ = show_state; |
152 show_apps_with_animation_ = show_apps_with_animation; | |
144 Layout(); | 153 Layout(); |
145 } | 154 } |
146 | 155 |
147 Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() { | 156 Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() { |
148 // Get the active folder's icon bounds relative to AppsContainerView. | 157 // Get the active folder's icon bounds relative to AppsContainerView. |
149 AppListItemView* folder_item_view = apps_grid_view_->activated_item_view(); | 158 AppListItemView* folder_item_view = apps_grid_view_->activated_item_view(); |
150 gfx::Rect to_grid_view = folder_item_view->ConvertRectToParent( | 159 gfx::Rect to_grid_view = folder_item_view->ConvertRectToParent( |
151 folder_item_view->GetIconBounds()); | 160 folder_item_view->GetIconBounds()); |
152 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view); | 161 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view); |
153 | 162 |
(...skipping 27 matching lines...) Expand all Loading... | |
181 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { | 190 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { |
182 if (folder_item) | 191 if (folder_item) |
183 CreateViewsForFolderTopItemsAnimation(folder_item, false); | 192 CreateViewsForFolderTopItemsAnimation(folder_item, false); |
184 | 193 |
185 // Hide the active folder item until the animation completes. | 194 // Hide the active folder item until the animation completes. |
186 if (apps_grid_view_->activated_item_view()) | 195 if (apps_grid_view_->activated_item_view()) |
187 apps_grid_view_->activated_item_view()->SetVisible(false); | 196 apps_grid_view_->activated_item_view()->SetVisible(false); |
188 } | 197 } |
189 | 198 |
190 } // namespace app_list | 199 } // namespace app_list |
OLD | NEW |