| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "ui/views/layout/fill_layout.h" | 35 #include "ui/views/layout/fill_layout.h" |
| 36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 37 | 37 |
| 38 namespace app_list { | 38 namespace app_list { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // The maximum allowed time to wait for icon loading in milliseconds. | 42 // The maximum allowed time to wait for icon loading in milliseconds. |
| 43 const int kMaxIconLoadingWaitTimeInMs = 50; | 43 const int kMaxIconLoadingWaitTimeInMs = 50; |
| 44 | 44 |
| 45 // Button for the custom page click zone. Receives click events when the user | |
| 46 // clicks on the custom page, and in response, switches to the custom page. | |
| 47 class CustomPageButton : public views::CustomButton, | |
| 48 public views::ButtonListener { | |
| 49 public: | |
| 50 explicit CustomPageButton(AppListMainView* app_list_main_view); | |
| 51 | |
| 52 // ButtonListener overrides: | |
| 53 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 54 | |
| 55 private: | |
| 56 AppListMainView* app_list_main_view_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(CustomPageButton); | |
| 59 }; | |
| 60 | |
| 61 CustomPageButton::CustomPageButton(AppListMainView* app_list_main_view) | |
| 62 : views::CustomButton(this), app_list_main_view_(app_list_main_view) { | |
| 63 } | |
| 64 | |
| 65 void CustomPageButton::ButtonPressed(views::Button* sender, | |
| 66 const ui::Event& event) { | |
| 67 // Switch to the custom page. | |
| 68 ContentsView* contents_view = app_list_main_view_->contents_view(); | |
| 69 int custom_page_index = contents_view->GetPageIndexForState( | |
| 70 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | |
| 71 contents_view->SetActivePage(custom_page_index); | |
| 72 } | |
| 73 | |
| 74 } // namespace | 45 } // namespace |
| 75 | 46 |
| 76 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 77 // AppListMainView::IconLoader | 48 // AppListMainView::IconLoader |
| 78 | 49 |
| 79 class AppListMainView::IconLoader : public AppListItemObserver { | 50 class AppListMainView::IconLoader : public AppListItemObserver { |
| 80 public: | 51 public: |
| 81 IconLoader(AppListMainView* owner, | 52 IconLoader(AppListMainView* owner, |
| 82 AppListItem* item, | 53 AppListItem* item, |
| 83 float scale) | 54 float scale) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 }; | 76 }; |
| 106 | 77 |
| 107 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 108 // AppListMainView: | 79 // AppListMainView: |
| 109 | 80 |
| 110 AppListMainView::AppListMainView(AppListViewDelegate* delegate) | 81 AppListMainView::AppListMainView(AppListViewDelegate* delegate) |
| 111 : delegate_(delegate), | 82 : delegate_(delegate), |
| 112 model_(delegate->GetModel()), | 83 model_(delegate->GetModel()), |
| 113 search_box_view_(nullptr), | 84 search_box_view_(nullptr), |
| 114 contents_view_(nullptr), | 85 contents_view_(nullptr), |
| 115 custom_page_clickzone_(nullptr), | |
| 116 weak_ptr_factory_(this) { | 86 weak_ptr_factory_(this) { |
| 117 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 87 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 118 model_->AddObserver(this); | 88 model_->AddObserver(this); |
| 119 } | 89 } |
| 120 | 90 |
| 121 AppListMainView::~AppListMainView() { | 91 AppListMainView::~AppListMainView() { |
| 122 pending_icon_loaders_.clear(); | 92 pending_icon_loaders_.clear(); |
| 123 model_->RemoveObserver(this); | 93 model_->RemoveObserver(this); |
| 124 } | 94 } |
| 125 | 95 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 model_->RemoveObserver(this); | 165 model_->RemoveObserver(this); |
| 196 model_ = delegate_->GetModel(); | 166 model_ = delegate_->GetModel(); |
| 197 model_->AddObserver(this); | 167 model_->AddObserver(this); |
| 198 search_box_view_->ModelChanged(); | 168 search_box_view_->ModelChanged(); |
| 199 delete contents_view_; | 169 delete contents_view_; |
| 200 contents_view_ = NULL; | 170 contents_view_ = NULL; |
| 201 AddContentsViews(); | 171 AddContentsViews(); |
| 202 Layout(); | 172 Layout(); |
| 203 } | 173 } |
| 204 | 174 |
| 205 views::Widget* AppListMainView::GetCustomPageClickzone() const { | |
| 206 // During shutdown, the widgets may be deleted, which means | |
| 207 // |custom_page_clickzone_| will be a dangling pointer. Therefore, always | |
| 208 // check that the main app list widget (its parent) is still alive before | |
| 209 // returning the pointer. | |
| 210 if (!GetWidget()) | |
| 211 return nullptr; | |
| 212 | |
| 213 return custom_page_clickzone_; | |
| 214 } | |
| 215 | |
| 216 void AppListMainView::SetDragAndDropHostOfCurrentAppList( | 175 void AppListMainView::SetDragAndDropHostOfCurrentAppList( |
| 217 ApplicationDragAndDropHost* drag_and_drop_host) { | 176 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 218 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 177 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 219 } | 178 } |
| 220 | 179 |
| 221 bool AppListMainView::ShouldCenterWindow() const { | 180 bool AppListMainView::ShouldCenterWindow() const { |
| 222 return delegate_->ShouldCenterWindow(); | 181 return delegate_->ShouldCenterWindow(); |
| 223 } | 182 } |
| 224 | 183 |
| 225 PaginationModel* AppListMainView::GetAppsPaginationModel() { | 184 PaginationModel* AppListMainView::GetAppsPaginationModel() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 234 } |
| 276 | 235 |
| 277 void AppListMainView::NotifySearchBoxVisibilityChanged() { | 236 void AppListMainView::NotifySearchBoxVisibilityChanged() { |
| 278 // Repaint the AppListView's background which will repaint the background for | 237 // Repaint the AppListView's background which will repaint the background for |
| 279 // the search box. This is needed because this view paints to a layer and | 238 // the search box. This is needed because this view paints to a layer and |
| 280 // won't propagate paints upward. | 239 // won't propagate paints upward. |
| 281 if (parent()) | 240 if (parent()) |
| 282 parent()->SchedulePaint(); | 241 parent()->SchedulePaint(); |
| 283 } | 242 } |
| 284 | 243 |
| 285 void AppListMainView::InitWidgets() { | |
| 286 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | |
| 287 tracked_objects::ScopedTracker tracking_profile( | |
| 288 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 AppListMainView::InitWidgets")); | |
| 289 | |
| 290 // The widget that receives click events to transition to the custom page. | |
| 291 views::Widget::InitParams custom_page_clickzone_params( | |
| 292 views::Widget::InitParams::TYPE_CONTROL); | |
| 293 | |
| 294 custom_page_clickzone_params.parent = GetWidget()->GetNativeView(); | |
| 295 custom_page_clickzone_params.layer_type = aura::WINDOW_LAYER_NOT_DRAWN; | |
| 296 | |
| 297 gfx::Rect custom_page_bounds = contents_view_->GetCustomPageCollapsedBounds(); | |
| 298 custom_page_bounds.Intersect(contents_view_->bounds()); | |
| 299 custom_page_bounds = contents_view_->ConvertRectToWidget(custom_page_bounds); | |
| 300 custom_page_clickzone_params.bounds = custom_page_bounds; | |
| 301 | |
| 302 // Create a widget for the custom page click zone. This widget masks click | |
| 303 // events from the WebContents that rests underneath it. (It has to be a | |
| 304 // widget, not an ordinary view, so that it can be placed in front of the | |
| 305 // WebContents.) | |
| 306 custom_page_clickzone_ = new views::Widget; | |
| 307 custom_page_clickzone_->Init(custom_page_clickzone_params); | |
| 308 custom_page_clickzone_->SetContentsView(new CustomPageButton(this)); | |
| 309 // The widget is shown by default. If the ContentsView determines that we do | |
| 310 // not need a clickzone upon startup, hide it. | |
| 311 if (!contents_view_->ShouldShowCustomPageClickzone()) | |
| 312 custom_page_clickzone_->Hide(); | |
| 313 } | |
| 314 | |
| 315 void AppListMainView::OnCustomLauncherPageEnabledStateChanged(bool enabled) { | 244 void AppListMainView::OnCustomLauncherPageEnabledStateChanged(bool enabled) { |
| 316 if (enabled) { | 245 if (enabled) { |
| 317 // Make the custom page view visible again. | 246 // Make the custom page view visible again. |
| 318 contents_view_->custom_page_view()->SetVisible(true); | 247 contents_view_->custom_page_view()->SetVisible(true); |
| 319 } else if (contents_view_->IsStateActive( | 248 } else if (contents_view_->IsStateActive( |
| 320 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { | 249 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
| 321 // Animate to the start page if currently on the custom page view. The view | 250 // Animate to the start page if currently on the custom page view. The view |
| 322 // will hide on animation completion. | 251 // will hide on animation completion. |
| 323 contents_view_->SetActivePage( | 252 contents_view_->SetActivePage( |
| 324 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); | 253 contents_view_->GetPageIndexForState(AppListModel::STATE_START)); |
| 325 } else { | 254 } else { |
| 326 // Hide the view immediately otherwise. | 255 // Hide the view immediately otherwise. |
| 327 contents_view_->custom_page_view()->SetVisible(false); | 256 contents_view_->custom_page_view()->SetVisible(false); |
| 328 } | 257 } |
| 329 // Allow the start page to update |custom_page_clickzone_|. | |
| 330 contents_view_->start_page_view()->UpdateCustomPageClickzoneVisibility(); | |
| 331 } | 258 } |
| 332 | 259 |
| 333 void AppListMainView::ActivateApp(AppListItem* item, int event_flags) { | 260 void AppListMainView::ActivateApp(AppListItem* item, int event_flags) { |
| 334 // TODO(jennyz): Activate the folder via AppListModel notification. | 261 // TODO(jennyz): Activate the folder via AppListModel notification. |
| 335 if (item->GetItemType() == AppListFolderItem::kItemType) | 262 if (item->GetItemType() == AppListFolderItem::kItemType) |
| 336 contents_view_->ShowFolderContent(static_cast<AppListFolderItem*>(item)); | 263 contents_view_->ShowFolderContent(static_cast<AppListFolderItem*>(item)); |
| 337 else | 264 else |
| 338 item->Activate(event_flags); | 265 item->Activate(event_flags); |
| 339 } | 266 } |
| 340 | 267 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 364 contents_view_->Back(); | 291 contents_view_->Back(); |
| 365 } | 292 } |
| 366 | 293 |
| 367 void AppListMainView::OnResultInstalled(SearchResult* result) { | 294 void AppListMainView::OnResultInstalled(SearchResult* result) { |
| 368 // Clears the search to show the apps grid. The last installed app | 295 // Clears the search to show the apps grid. The last installed app |
| 369 // should be highlighted and made visible already. | 296 // should be highlighted and made visible already. |
| 370 search_box_view_->ClearSearch(); | 297 search_box_view_->ClearSearch(); |
| 371 } | 298 } |
| 372 | 299 |
| 373 } // namespace app_list | 300 } // namespace app_list |
| OLD | NEW |