Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / contents_view.cc
index 1b4e124..a2418e0 100644 (file)
@@ -5,6 +5,7 @@
 #include "ui/app_list/views/contents_view.h"
 
 #include <algorithm>
+#include <vector>
 
 #include "base/logging.h"
 #include "grit/ui_resources.h"
@@ -18,7 +19,6 @@
 #include "ui/app_list/views/contents_switcher_view.h"
 #include "ui/app_list/views/search_result_list_view.h"
 #include "ui/app_list/views/start_page_view.h"
-#include "ui/base/resource/resource_bundle.h"
 #include "ui/events/event.h"
 #include "ui/views/view_model.h"
 #include "ui/views/view_model_utils.h"
@@ -40,12 +40,15 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view)
       start_page_view_(NULL),
       app_list_main_view_(app_list_main_view),
       contents_switcher_view_(NULL),
-      view_model_(new views::ViewModel) {
+      view_model_(new views::ViewModel),
+      page_before_search_(0) {
   pagination_model_.AddObserver(this);
 }
 
 ContentsView::~ContentsView() {
   pagination_model_.RemoveObserver(this);
+  if (contents_switcher_view_)
+    pagination_model_.RemoveObserver(contents_switcher_view_);
 }
 
 void ContentsView::InitNamedPages(AppListModel* model,
@@ -53,6 +56,15 @@ void ContentsView::InitNamedPages(AppListModel* model,
   DCHECK(model);
 
   if (app_list::switches::IsExperimentalAppListEnabled()) {
+    std::vector<views::View*> custom_page_views =
+        view_delegate->CreateCustomPageWebViews(GetLocalBounds().size());
+    for (std::vector<views::View*>::const_iterator it =
+             custom_page_views.begin();
+         it != custom_page_views.end();
+         ++it) {
+      AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON);
+    }
+
     start_page_view_ = new StartPageView(app_list_main_view_, view_delegate);
     AddLauncherPage(
         start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START);
@@ -64,10 +76,17 @@ void ContentsView::InitNamedPages(AppListModel* model,
   }
 
   apps_container_view_ = new AppsContainerView(app_list_main_view_, model);
-  int apps_page_index = AddLauncherPage(
+
+  int initial_page_index = AddLauncherPage(
       apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS);
+  if (app_list::switches::IsExperimentalAppListEnabled())
+    initial_page_index = GetPageIndexForNamedPage(NAMED_PAGE_START);
+
+  page_before_search_ = initial_page_index;
+  pagination_model_.SelectPage(initial_page_index, false);
 
-  pagination_model_.SelectPage(apps_page_index, false);
+  // Needed to update the main search box visibility.
+  ActivePageChanged(false);
 }
 
 void ContentsView::CancelDrag() {
@@ -86,6 +105,14 @@ void ContentsView::SetDragAndDropHostOfCurrentAppList(
   apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
 }
 
+void ContentsView::SetContentsSwitcherView(
+    ContentsSwitcherView* contents_switcher_view) {
+  DCHECK(!contents_switcher_view_);
+  contents_switcher_view_ = contents_switcher_view;
+  if (contents_switcher_view_)
+    pagination_model_.AddObserver(contents_switcher_view_);
+}
+
 void ContentsView::SetActivePage(int page_index) {
   if (GetActivePageIndex() == page_index)
     return;
@@ -122,6 +149,8 @@ int ContentsView::NumLauncherPages() const {
 
 void ContentsView::SetActivePageInternal(int page_index,
                                          bool show_search_results) {
+  if (!show_search_results)
+    page_before_search_ = page_index;
   // Start animating to the new page.
   pagination_model_.SelectPage(page_index, true);
   ActivePageChanged(show_search_results);
@@ -148,11 +177,12 @@ void ContentsView::ActivePageChanged(bool show_search_results) {
 }
 
 void ContentsView::ShowSearchResults(bool show) {
-  NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS;
-  if (app_list::switches::IsExperimentalAppListEnabled())
-    new_named_page = NAMED_PAGE_START;
+  int search_page = GetPageIndexForNamedPage(
+      app_list::switches::IsExperimentalAppListEnabled()
+          ? NAMED_PAGE_START
+          : NAMED_PAGE_SEARCH_RESULTS);
 
-  SetActivePageInternal(GetPageIndexForNamedPage(new_named_page), show);
+  SetActivePageInternal(show ? search_page : page_before_search_, show);
 }
 
 bool ContentsView::IsShowingSearchResults() const {
@@ -233,9 +263,9 @@ int ContentsView::AddLauncherPage(views::View* view, int resource_id) {
   int page_index = view_model_->view_size();
   AddChildView(view);
   view_model_->Add(view, page_index);
-  pagination_model_.SetTotalPages(view_model_->view_size());
   if (contents_switcher_view_)
     contents_switcher_view_->AddSwitcherButton(resource_id, page_index);
+  pagination_model_.SetTotalPages(view_model_->view_size());
   return page_index;
 }