#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_box_view.h"
#include "ui/app_list/views/search_result_list_view.h"
#include "ui/app_list/views/start_page_view.h"
#include "ui/events/event.h"
pagination_model_.RemoveObserver(contents_switcher_view_);
}
-void ContentsView::InitNamedPages(AppListModel* model,
- AppListViewDelegate* view_delegate) {
+void ContentsView::Init(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_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START);
+ start_page_view_, IDR_APP_LIST_SEARCH_ICON, AppListModel::STATE_START);
} else {
search_results_view_ =
new SearchResultListView(app_list_main_view_, view_delegate);
- AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS);
+ AddLauncherPage(
+ search_results_view_, 0, AppListModel::STATE_SEARCH_RESULTS);
search_results_view_->SetResults(model->results());
}
apps_container_view_ = new AppsContainerView(app_list_main_view_, model);
AddLauncherPage(
- apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS);
+ apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS);
int initial_page_index = app_list::switches::IsExperimentalAppListEnabled()
- ? GetPageIndexForNamedPage(NAMED_PAGE_START)
- : GetPageIndexForNamedPage(NAMED_PAGE_APPS);
+ ? GetPageIndexForState(AppListModel::STATE_START)
+ : GetPageIndexForState(AppListModel::STATE_APPS);
DCHECK_GE(initial_page_index, 0);
page_before_search_ = initial_page_index;
pagination_model_.SelectPage(initial_page_index, false);
-
- // Needed to update the main search box visibility.
ActivePageChanged(false);
}
return pagination_model_.SelectedTargetPage();
}
-bool ContentsView::IsNamedPageActive(NamedPage named_page) const {
+bool ContentsView::IsStateActive(AppListModel::State state) const {
int active_page_index = GetActivePageIndex();
return active_page_index >= 0 &&
- GetPageIndexForNamedPage(named_page) == active_page_index;
+ GetPageIndexForState(state) == active_page_index;
}
-int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const {
- // Find the index of the view corresponding to the given named_page.
- std::map<NamedPage, int>::const_iterator it =
- named_page_to_view_.find(named_page);
- if (it == named_page_to_view_.end())
+int ContentsView::GetPageIndexForState(AppListModel::State state) const {
+ // Find the index of the view corresponding to the given state.
+ std::map<AppListModel::State, int>::const_iterator it =
+ state_to_view_.find(state);
+ if (it == state_to_view_.end())
return -1;
return it->second;
}
void ContentsView::ActivePageChanged(bool show_search_results) {
+ AppListModel::State state = AppListModel::INVALID_STATE;
+
+ // TODO(calamity): This does not report search results being shown in the
+ // experimental app list as a boolean is currently used to indicate whether
+ // search results are showing. See http://crbug.com/427787/.
+ std::map<int, AppListModel::State>::const_iterator it =
+ view_to_state_.find(pagination_model_.SelectedTargetPage());
+ if (it != view_to_state_.end())
+ state = it->second;
+
+ app_list_main_view_->model()->SetState(state);
+
// TODO(xiyuan): Highlight default match instead of the first.
- if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) &&
+ if (IsStateActive(AppListModel::STATE_SEARCH_RESULTS) &&
search_results_view_->visible()) {
search_results_view_->SetSelectedIndex(0);
}
if (search_results_view_)
search_results_view_->UpdateAutoLaunchState();
- if (IsNamedPageActive(NAMED_PAGE_START)) {
+ if (IsStateActive(AppListModel::STATE_START)) {
if (show_search_results)
start_page_view_->ShowSearchResults();
else
}
void ContentsView::ShowSearchResults(bool show) {
- int search_page = GetPageIndexForNamedPage(
- app_list::switches::IsExperimentalAppListEnabled()
- ? NAMED_PAGE_START
- : NAMED_PAGE_SEARCH_RESULTS);
+ int search_page =
+ GetPageIndexForState(app_list::switches::IsExperimentalAppListEnabled()
+ ? AppListModel::STATE_START
+ : AppListModel::STATE_SEARCH_RESULTS);
DCHECK_GE(search_page, 0);
SetActivePageInternal(show ? search_page : page_before_search_, show);
bool ContentsView::IsShowingSearchResults() const {
return app_list::switches::IsExperimentalAppListEnabled()
- ? IsNamedPageActive(NAMED_PAGE_START) &&
+ ? IsStateActive(AppListModel::STATE_START) &&
start_page_view_->IsShowingSearchResults()
- : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS);
+ : IsStateActive(AppListModel::STATE_SEARCH_RESULTS);
}
gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const {
// are below.
int page_height = bounds.height();
bool origin_above =
- GetPageIndexForNamedPage(NAMED_PAGE_START) == page_index ||
- GetPageIndexForNamedPage(NAMED_PAGE_SEARCH_RESULTS) == page_index;
+ GetPageIndexForState(AppListModel::STATE_START) == page_index ||
+ GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index;
bounds.set_y(origin_above ? -page_height : page_height);
return bounds;
}
// Move |current_page| from 0 to its origin. Move |target_page| from its
// origin to 0.
- gfx::Rect on_screen(GetContentsBounds());
+ gfx::Rect on_screen(GetDefaultContentsBounds());
gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page));
gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page));
gfx::Rect current_page_rect(
int ContentsView::AddLauncherPage(views::View* view,
int resource_id,
- NamedPage named_page) {
+ AppListModel::State state) {
int page_index = AddLauncherPage(view, resource_id);
- named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index));
+ bool success =
+ state_to_view_.insert(std::make_pair(state, page_index)).second;
+ success = success &&
+ view_to_state_.insert(std::make_pair(page_index, state)).second;
+
+ // There shouldn't be duplicates in either map.
+ DCHECK(success);
return page_index;
}
-gfx::Size ContentsView::GetPreferredSize() const {
+gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const {
+ gfx::Rect search_box_bounds(
+ 0,
+ 0,
+ GetDefaultContentsSize().width(),
+ app_list_main_view_->search_box_view()->GetPreferredSize().height());
+ if (switches::IsExperimentalAppListEnabled()) {
+ search_box_bounds.set_y(kExperimentalWindowPadding);
+ search_box_bounds.Inset(kExperimentalWindowPadding, 0);
+ }
+ return search_box_bounds;
+}
+
+gfx::Rect ContentsView::GetDefaultContentsBounds() const {
+ gfx::Rect bounds(gfx::Point(0, GetDefaultSearchBoxBounds().bottom()),
+ GetDefaultContentsSize());
+ return bounds;
+}
+
+gfx::Size ContentsView::GetDefaultContentsSize() const {
const gfx::Size container_size =
apps_container_view_->apps_grid_view()->GetPreferredSize();
const gfx::Size results_size = search_results_view_
return gfx::Size(width, height);
}
+gfx::Size ContentsView::GetPreferredSize() const {
+ gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds();
+ gfx::Rect default_contents_bounds = GetDefaultContentsBounds();
+ gfx::Vector2d bottom_right =
+ search_box_bounds.bottom_right().OffsetFromOrigin();
+ bottom_right.SetToMax(
+ default_contents_bounds.bottom_right().OffsetFromOrigin());
+ return gfx::Size(bottom_right.x(), bottom_right.y());
+}
+
void ContentsView::Layout() {
// Immediately finish all current animations.
pagination_model_.FinishAnimation();
// Move the current view onto the screen, and all other views off screen to
// the left. (Since we are not animating, we don't need to be careful about
// which side we place the off-screen views onto.)
- gfx::Rect rect(GetContentsBounds());
+ gfx::Rect rect(GetDefaultContentsBounds());
if (rect.IsEmpty())
return;