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/app_list_main_view.h" | 5 #include "ui/app_list/views/app_list_main_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.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_model.h" | 17 #include "ui/app_list/app_list_model.h" |
18 #include "ui/app_list/app_list_switches.h" | 18 #include "ui/app_list/app_list_switches.h" |
19 #include "ui/app_list/app_list_view_delegate.h" | 19 #include "ui/app_list/app_list_view_delegate.h" |
20 #include "ui/app_list/pagination_model.h" | 20 #include "ui/app_list/pagination_model.h" |
21 #include "ui/app_list/search_box_model.h" | 21 #include "ui/app_list/search_box_model.h" |
22 #include "ui/app_list/views/app_list_item_view.h" | 22 #include "ui/app_list/views/app_list_item_view.h" |
23 #include "ui/app_list/views/apps_container_view.h" | 23 #include "ui/app_list/views/apps_container_view.h" |
24 #include "ui/app_list/views/apps_grid_view.h" | |
24 #include "ui/app_list/views/contents_switcher_view.h" | 25 #include "ui/app_list/views/contents_switcher_view.h" |
25 #include "ui/app_list/views/contents_view.h" | 26 #include "ui/app_list/views/contents_view.h" |
26 #include "ui/app_list/views/search_box_view.h" | 27 #include "ui/app_list/views/search_box_view.h" |
27 #include "ui/views/controls/textfield/textfield.h" | 28 #include "ui/views/controls/textfield/textfield.h" |
28 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
30 | 31 |
31 namespace app_list { | 32 namespace app_list { |
32 | 33 |
33 namespace { | 34 namespace { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 AppListMainView* owner_; | 77 AppListMainView* owner_; |
77 AppListItem* item_; | 78 AppListItem* item_; |
78 | 79 |
79 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 80 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
80 }; | 81 }; |
81 | 82 |
82 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
83 // AppListMainView: | 84 // AppListMainView: |
84 | 85 |
85 AppListMainView::AppListMainView(AppListViewDelegate* delegate, | 86 AppListMainView::AppListMainView(AppListViewDelegate* delegate, |
86 PaginationModel* pagination_model, | |
87 gfx::NativeView parent) | 87 gfx::NativeView parent) |
88 : delegate_(delegate), | 88 : delegate_(delegate), |
89 pagination_model_(pagination_model), | 89 pagination_model_(NULL), |
90 model_(delegate->GetModel()), | 90 model_(delegate->GetModel()), |
91 search_box_view_(NULL), | 91 search_box_view_(NULL), |
92 contents_view_(NULL), | 92 contents_view_(NULL), |
93 weak_ptr_factory_(this) { | 93 weak_ptr_factory_(this) { |
94 // Starts icon loading early. | |
95 PreloadIcons(parent); | |
96 | |
97 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | 94 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
98 kInnerPadding, | 95 kInnerPadding, |
99 kInnerPadding, | 96 kInnerPadding, |
100 kInnerPadding)); | 97 kInnerPadding)); |
101 | 98 |
102 search_box_view_ = new SearchBoxView(this, delegate); | 99 search_box_view_ = new SearchBoxView(this, delegate); |
103 AddChildView(search_box_view_); | 100 AddChildView(search_box_view_); |
104 AddContentsView(); | 101 AddContentsView(); |
105 if (app_list::switches::IsExperimentalAppListEnabled()) | 102 if (app_list::switches::IsExperimentalAppListEnabled()) |
106 AddChildView(new ContentsSwitcherView(contents_view_)); | 103 AddChildView(new ContentsSwitcherView(contents_view_)); |
104 pagination_model_ = contents_view_->apps_container_view() | |
105 ->apps_grid_view() | |
106 ->GetPaginationModel(); | |
xiyuan
2014/05/30 15:47:47
Can we get rid of |pagination_model_| as a member
tapted
2014/06/02 04:02:21
hehe - that was going to be first comment too :).
Matt Giuca
2014/06/02 07:11:23
Done.
| |
107 | |
108 // Starts icon loading early. | |
109 PreloadIcons(parent); | |
107 } | 110 } |
108 | 111 |
109 void AppListMainView::AddContentsView() { | 112 void AppListMainView::AddContentsView() { |
110 contents_view_ = new ContentsView( | 113 contents_view_ = new ContentsView(this, model_, delegate_); |
111 this, pagination_model_, model_, delegate_); | |
112 AddChildViewAt(contents_view_, kContentsViewIndex); | 114 AddChildViewAt(contents_view_, kContentsViewIndex); |
113 | 115 |
114 search_box_view_->set_contents_view(contents_view_); | 116 search_box_view_->set_contents_view(contents_view_); |
115 | 117 |
118 pagination_model_ = contents_view_->apps_container_view() | |
119 ->apps_grid_view() | |
120 ->GetPaginationModel(); | |
121 | |
116 #if defined(USE_AURA) | 122 #if defined(USE_AURA) |
117 contents_view_->SetPaintToLayer(true); | 123 contents_view_->SetPaintToLayer(true); |
118 contents_view_->SetFillsBoundsOpaquely(false); | 124 contents_view_->SetFillsBoundsOpaquely(false); |
119 contents_view_->layer()->SetMasksToBounds(true); | 125 contents_view_->layer()->SetMasksToBounds(true); |
120 #endif | 126 #endif |
121 } | 127 } |
122 | 128 |
123 AppListMainView::~AppListMainView() { | 129 AppListMainView::~AppListMainView() { |
124 pending_icon_loaders_.clear(); | 130 pending_icon_loaders_.clear(); |
125 } | 131 } |
(...skipping 27 matching lines...) Expand all Loading... | |
153 } | 159 } |
154 | 160 |
155 void AppListMainView::Prerender() { | 161 void AppListMainView::Prerender() { |
156 contents_view_->Prerender(); | 162 contents_view_->Prerender(); |
157 } | 163 } |
158 | 164 |
159 void AppListMainView::ModelChanged() { | 165 void AppListMainView::ModelChanged() { |
160 pending_icon_loaders_.clear(); | 166 pending_icon_loaders_.clear(); |
161 model_ = delegate_->GetModel(); | 167 model_ = delegate_->GetModel(); |
162 search_box_view_->ModelChanged(); | 168 search_box_view_->ModelChanged(); |
169 pagination_model_->SelectPage(0, false /* animate */); | |
tapted
2014/06/02 04:02:21
this is perhaps not needed any more? Or, it needs
Matt Giuca
2014/06/02 07:11:23
Ah I see. The reason this was there before was bec
| |
163 delete contents_view_; | 170 delete contents_view_; |
164 contents_view_ = NULL; | 171 contents_view_ = NULL; |
165 pagination_model_->SelectPage(0, false /* animate */); | 172 pagination_model_ = NULL; |
166 AddContentsView(); | 173 AddContentsView(); |
167 Layout(); | 174 Layout(); |
168 } | 175 } |
169 | 176 |
170 void AppListMainView::OnContentsViewShowStateChanged() { | 177 void AppListMainView::OnContentsViewShowStateChanged() { |
171 search_box_view_->SetVisible(contents_view_->show_state() != | 178 search_box_view_->SetVisible(contents_view_->show_state() != |
172 ContentsView::SHOW_START_PAGE); | 179 ContentsView::SHOW_START_PAGE); |
173 } | 180 } |
174 | 181 |
175 void AppListMainView::OnStartPageSearchButtonPressed() { | 182 void AppListMainView::OnStartPageSearchButtonPressed() { |
(...skipping 11 matching lines...) Expand all Loading... | |
187 return delegate_->ShouldCenterWindow(); | 194 return delegate_->ShouldCenterWindow(); |
188 } | 195 } |
189 | 196 |
190 void AppListMainView::PreloadIcons(gfx::NativeView parent) { | 197 void AppListMainView::PreloadIcons(gfx::NativeView parent) { |
191 float scale_factor = 1.0f; | 198 float scale_factor = 1.0f; |
192 if (parent) | 199 if (parent) |
193 scale_factor = ui::GetScaleFactorForNativeView(parent); | 200 scale_factor = ui::GetScaleFactorForNativeView(parent); |
194 | 201 |
195 // |pagination_model| could have -1 as the initial selected page and | 202 // |pagination_model| could have -1 as the initial selected page and |
196 // assumes first page (i.e. index 0) will be used in this case. | 203 // assumes first page (i.e. index 0) will be used in this case. |
197 const int selected_page = std::max(0, pagination_model_->selected_page()); | 204 const int selected_page = std::max(0, pagination_model_->selected_page()); |
Matt Giuca
2014/06/02 07:11:23
Oh no... I just realised that this will be broken
tapted
2014/06/02 08:36:49
This function might even be missing an update for
xiyuan
2014/06/02 17:02:08
I would object to removing the code. It is importa
Matt Giuca
2014/06/03 01:52:36
Had a chat with tapted@ about this. We've decided
Matt Giuca
2014/06/03 03:58:26
Actually, it isn't *that* hard/messy to pass the p
xiyuan
2014/06/03 04:10:35
This not true for ChromeOS. The preload is needed
Matt Giuca
2014/06/03 06:51:43
Hi, good that I did it properly so this discussion
xiyuan
2014/06/03 16:10:35
You are right. I forgot that AppListView no longer
| |
198 | 205 |
199 const int tiles_per_page = kPreferredCols * kPreferredRows; | 206 const int tiles_per_page = kPreferredCols * kPreferredRows; |
200 const int start_model_index = selected_page * tiles_per_page; | 207 const int start_model_index = selected_page * tiles_per_page; |
201 const int end_model_index = | 208 const int end_model_index = |
202 std::min(static_cast<int>(model_->top_level_item_list()->item_count()), | 209 std::min(static_cast<int>(model_->top_level_item_list()->item_count()), |
203 start_model_index + tiles_per_page); | 210 start_model_index + tiles_per_page); |
204 | 211 |
205 pending_icon_loaders_.clear(); | 212 pending_icon_loaders_.clear(); |
206 for (int i = start_model_index; i < end_model_index; ++i) { | 213 for (int i = start_model_index; i < end_model_index; ++i) { |
207 AppListItem* item = model_->top_level_item_list()->item_at(i); | 214 AppListItem* item = model_->top_level_item_list()->item_at(i); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 // Resubmit the query via a posted task so that all observers for the | 278 // Resubmit the query via a posted task so that all observers for the |
272 // uninstall notification are notified. | 279 // uninstall notification are notified. |
273 base::MessageLoop::current()->PostTask( | 280 base::MessageLoop::current()->PostTask( |
274 FROM_HERE, | 281 FROM_HERE, |
275 base::Bind(&AppListMainView::QueryChanged, | 282 base::Bind(&AppListMainView::QueryChanged, |
276 weak_ptr_factory_.GetWeakPtr(), | 283 weak_ptr_factory_.GetWeakPtr(), |
277 search_box_view_)); | 284 search_box_view_)); |
278 } | 285 } |
279 | 286 |
280 } // namespace app_list | 287 } // namespace app_list |
OLD | NEW |