Commit 52113807 authored by mgiuca@chromium.org's avatar mgiuca@chromium.org

App List: Refactor ContentsSwitcherView so it doesn't hard-code pages.

Removed hard-coded addition of start page and apps buttons in the
ContentsSwitcherView constructor. Instead, adding a page to ContentsView
automatically adds the appropriate button to ContentsSwitcherView.

ContentsView and ContentsSwitcherView now include pointers to one
another (so initialization of ContentsView is split into a separate Init
phase). ContentsView::AddLauncherPage now takes a resource ID.

BUG=386004

Review URL: https://codereview.chromium.org/336313010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278674 0039d316-1c4b-4281-b951-d872f2087c98
parent ad8514c0
......@@ -109,12 +109,15 @@ AppListMainView::AppListMainView(AppListViewDelegate* delegate,
}
void AppListMainView::AddContentsViews() {
contents_view_ = new ContentsView(this, model_, delegate_);
AddChildView(contents_view_);
contents_view_ = new ContentsView(this);
if (app_list::switches::IsExperimentalAppListEnabled()) {
contents_switcher_view_ = new ContentsSwitcherView(contents_view_);
AddChildView(contents_switcher_view_);
contents_view_->set_contents_switcher_view(contents_switcher_view_);
}
contents_view_->InitNamedPages(model_, delegate_);
AddChildView(contents_view_);
if (contents_switcher_view_)
AddChildView(contents_switcher_view_);
search_box_view_->set_contents_view(contents_view_);
......
......@@ -4,10 +4,8 @@
#include "ui/app_list/views/contents_switcher_view.h"
#include "grit/ui_resources.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/views/contents_view.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/button/custom_button.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/layout/box_layout.h"
......@@ -27,23 +25,17 @@ ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view)
buttons_->SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing));
// TODO(mgiuca): Dynamically generate these buttons from the subviews of
// |contents_view|.
AddSwitcherButton(
IDR_APP_LIST_SEARCH_ICON,
contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_START));
AddSwitcherButton(
IDR_APP_LIST_APPS_ICON,
contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
}
ContentsSwitcherView::~ContentsSwitcherView() {}
void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) {
views::ImageButton* button = new views::ImageButton(this);
if (resource_id) {
button->SetImage(
views::CustomButton::STATE_NORMAL,
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id));
}
button->set_tag(page_index);
buttons_->AddChildView(button);
}
......
......@@ -22,11 +22,12 @@ class ContentsSwitcherView : public views::View, public views::ButtonListener {
ContentsView* contents_view() const { return contents_view_; }
private:
// Adds a switcher button using |resource_id| as the button's image and |tag|
// as the button's id.
void AddSwitcherButton(int resource_id, int tag);
// Adds a switcher button using |resource_id| as the button's image, which
// opens the page with index |page_index| in the ContentsView. |resource_id|
// is ignored if it is 0.
void AddSwitcherButton(int resource_id, int page_index);
private:
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE;
virtual void Layout() OVERRIDE;
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/logging.h"
#include "grit/ui_resources.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/app_list_view_delegate.h"
......@@ -14,8 +15,10 @@
#include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/apps_container_view.h"
#include "ui/app_list/views/apps_grid_view.h"
#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"
......@@ -32,34 +35,39 @@ const double kFinishTransitionThreshold = 0.33;
} // namespace
ContentsView::ContentsView(AppListMainView* app_list_main_view,
AppListModel* model,
AppListViewDelegate* view_delegate)
ContentsView::ContentsView(AppListMainView* app_list_main_view)
: search_results_view_(NULL),
start_page_view_(NULL),
app_list_main_view_(app_list_main_view),
contents_switcher_view_(NULL),
view_model_(new views::ViewModel) {
pagination_model_.AddObserver(this);
}
ContentsView::~ContentsView() {
pagination_model_.RemoveObserver(this);
}
void ContentsView::InitNamedPages(AppListModel* model,
AppListViewDelegate* view_delegate) {
DCHECK(model);
if (app_list::switches::IsExperimentalAppListEnabled()) {
start_page_view_ = new StartPageView(app_list_main_view, view_delegate);
AddLauncherPage(start_page_view_, NAMED_PAGE_START);
start_page_view_ = new StartPageView(app_list_main_view_, view_delegate);
AddLauncherPage(
start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START);
} else {
search_results_view_ =
new SearchResultListView(app_list_main_view, view_delegate);
AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS);
new SearchResultListView(app_list_main_view_, view_delegate);
AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS);
search_results_view_->SetResults(model->results());
}
apps_container_view_ = new AppsContainerView(app_list_main_view, model);
int apps_page_index = AddLauncherPage(apps_container_view_, NAMED_PAGE_APPS);
apps_container_view_ = new AppsContainerView(app_list_main_view_, model);
int apps_page_index = AddLauncherPage(
apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS);
pagination_model_.SelectPage(apps_page_index, false);
pagination_model_.AddObserver(this);
}
ContentsView::~ContentsView() {
pagination_model_.RemoveObserver(this);
}
void ContentsView::CancelDrag() {
......@@ -218,19 +226,23 @@ views::View* ContentsView::GetPageView(int index) {
}
void ContentsView::AddBlankPageForTesting() {
AddLauncherPage(new views::View);
AddLauncherPage(new views::View, 0);
}
int ContentsView::AddLauncherPage(views::View* view) {
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);
return page_index;
}
int ContentsView::AddLauncherPage(views::View* view, NamedPage named_page) {
int page_index = AddLauncherPage(view);
int ContentsView::AddLauncherPage(views::View* view,
int resource_id,
NamedPage named_page) {
int page_index = AddLauncherPage(view, resource_id);
named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index));
return page_index;
}
......
......@@ -28,6 +28,7 @@ class AppListMainView;
class AppListModel;
class AppListViewDelegate;
class AppsContainerView;
class ContentsSwitcherView;
class PaginationModel;
class SearchResultListView;
class StartPageView;
......@@ -48,11 +49,14 @@ class APP_LIST_EXPORT ContentsView : public views::View,
NAMED_PAGE_START,
};
ContentsView(AppListMainView* app_list_main_view,
AppListModel* model,
AppListViewDelegate* view_delegate);
ContentsView(AppListMainView* app_list_main_view);
virtual ~ContentsView();
// Initialize the named (special) pages of the launcher. In the experimental
// launcher, should be called after set_contents_switcher_view(), or switcher
// buttons will not be created.
void InitNamedPages(AppListModel* model, AppListViewDelegate* view_delegate);
// The app list gets closed and drag and drop operations need to be cancelled.
void CancelDrag();
......@@ -61,6 +65,11 @@ class APP_LIST_EXPORT ContentsView : public views::View,
void SetDragAndDropHostOfCurrentAppList(
ApplicationDragAndDropHost* drag_and_drop_host);
void set_contents_switcher_view(
ContentsSwitcherView* contents_switcher_view) {
contents_switcher_view_ = contents_switcher_view;
}
void ShowSearchResults(bool show);
void ShowFolderContent(AppListFolderItem* folder);
bool IsShowingSearchResults() const;
......@@ -114,14 +123,16 @@ class APP_LIST_EXPORT ContentsView : public views::View,
void UpdatePageBounds();
// Adds |view| as a new page to the end of the list of launcher pages. The
// view is inserted as a child of the ContentsView. There is no name
// view is inserted as a child of the ContentsView, and a button with
// |resource_id| is added to the ContentsSwitcherView. There is no name
// associated with the page. Returns the index of the new page.
int AddLauncherPage(views::View* view);
int AddLauncherPage(views::View* view, int resource_id);
// Adds |view| as a new page to the end of the list of launcher pages. The
// view is inserted as a child of the ContentsView. The page is associated
// view is inserted as a child of the ContentsView, and a button with
// |resource_id| is added to the ContentsSwitcherView. The page is associated
// with the name |named_page|. Returns the index of the new page.
int AddLauncherPage(views::View* view, NamedPage named_page);
int AddLauncherPage(views::View* view, int resource_id, NamedPage named_page);
// Gets the PaginationModel owned by the AppsGridView.
// Note: This is different to |pagination_model_|, which manages top-level
......@@ -138,6 +149,8 @@ class APP_LIST_EXPORT ContentsView : public views::View,
StartPageView* start_page_view_;
AppListMainView* app_list_main_view_; // Parent view, owns this.
// Sibling view, owned by |app_list_main_view_|.
ContentsSwitcherView* contents_switcher_view_;
scoped_ptr<views::ViewModel> view_model_;
// Maps NamedPage onto |view_model_| indices.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment