OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/contents_view.h" | 5 #include "ui/app_list/views/contents_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 76 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
77 ApplicationDragAndDropHost* drag_and_drop_host) { | 77 ApplicationDragAndDropHost* drag_and_drop_host) { |
78 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 78 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
79 } | 79 } |
80 | 80 |
81 void ContentsView::SetActivePage(int page_index) { | 81 void ContentsView::SetActivePage(int page_index) { |
82 if (active_page_ == page_index) | 82 if (active_page_ == page_index) |
83 return; | 83 return; |
84 | 84 |
85 active_page_ = page_index; | 85 SetActivePageInternal(page_index, false); |
86 ActivePageChanged(); | |
87 } | 86 } |
88 | 87 |
89 bool ContentsView::IsNamedPageActive(NamedPage named_page) const { | 88 bool ContentsView::IsNamedPageActive(NamedPage named_page) const { |
90 std::map<NamedPage, int>::const_iterator it = | 89 std::map<NamedPage, int>::const_iterator it = |
91 named_page_to_view_.find(named_page); | 90 named_page_to_view_.find(named_page); |
92 if (it == named_page_to_view_.end()) | 91 if (it == named_page_to_view_.end()) |
93 return false; | 92 return false; |
94 return it->second == active_page_; | 93 return it->second == active_page_; |
95 } | 94 } |
96 | 95 |
97 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { | 96 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { |
98 // Find the index of the view corresponding to the given named_page. | 97 // Find the index of the view corresponding to the given named_page. |
99 std::map<NamedPage, int>::const_iterator it = | 98 std::map<NamedPage, int>::const_iterator it = |
100 named_page_to_view_.find(named_page); | 99 named_page_to_view_.find(named_page); |
101 // GetPageIndexForNamedPage should never be called on a named_page that does | 100 // GetPageIndexForNamedPage should never be called on a named_page that does |
102 // not have a corresponding view. | 101 // not have a corresponding view. |
103 DCHECK(it != named_page_to_view_.end()); | 102 DCHECK(it != named_page_to_view_.end()); |
104 return it->second; | 103 return it->second; |
105 } | 104 } |
106 | 105 |
107 void ContentsView::ActivePageChanged() { | 106 void ContentsView::SetActivePageInternal(int page_index, |
| 107 bool show_search_results) { |
| 108 active_page_ = page_index; |
| 109 ActivePageChanged(show_search_results); |
| 110 } |
| 111 |
| 112 void ContentsView::ActivePageChanged(bool show_search_results) { |
108 // TODO(xiyuan): Highlight default match instead of the first. | 113 // TODO(xiyuan): Highlight default match instead of the first. |
109 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && | 114 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && |
110 search_results_view_->visible()) { | 115 search_results_view_->visible()) { |
111 search_results_view_->SetSelectedIndex(0); | 116 search_results_view_->SetSelectedIndex(0); |
112 } | 117 } |
113 if (search_results_view_) | 118 if (search_results_view_) |
114 search_results_view_->UpdateAutoLaunchState(); | 119 search_results_view_->UpdateAutoLaunchState(); |
115 | 120 |
116 if (IsNamedPageActive(NAMED_PAGE_START)) | 121 if (IsNamedPageActive(NAMED_PAGE_START)) { |
117 start_page_view_->Reset(); | 122 if (show_search_results) |
| 123 start_page_view_->ShowSearchResults(); |
| 124 else |
| 125 start_page_view_->Reset(); |
| 126 } |
118 | 127 |
119 // Notify parent AppListMainView of the page change. | 128 // Notify parent AppListMainView of the page change. |
120 app_list_main_view_->UpdateSearchBoxVisibility(); | 129 app_list_main_view_->UpdateSearchBoxVisibility(); |
121 | 130 |
122 AnimateToIdealBounds(); | 131 AnimateToIdealBounds(); |
123 } | 132 } |
124 | 133 |
125 void ContentsView::ShowSearchResults(bool show) { | 134 void ContentsView::ShowSearchResults(bool show) { |
126 NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS; | 135 NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS; |
127 if (app_list::switches::IsExperimentalAppListEnabled()) | 136 if (app_list::switches::IsExperimentalAppListEnabled()) |
128 new_named_page = NAMED_PAGE_START; | 137 new_named_page = NAMED_PAGE_START; |
129 | 138 |
130 SetActivePage(GetPageIndexForNamedPage(new_named_page)); | 139 SetActivePageInternal(GetPageIndexForNamedPage(new_named_page), show); |
131 | |
132 if (app_list::switches::IsExperimentalAppListEnabled()) { | |
133 if (show) | |
134 start_page_view_->ShowSearchResults(); | |
135 else | |
136 start_page_view_->Reset(); | |
137 app_list_main_view_->UpdateSearchBoxVisibility(); | |
138 } | |
139 } | 140 } |
140 | 141 |
141 bool ContentsView::IsShowingSearchResults() const { | 142 bool ContentsView::IsShowingSearchResults() const { |
142 return app_list::switches::IsExperimentalAppListEnabled() | 143 return app_list::switches::IsExperimentalAppListEnabled() |
143 ? IsNamedPageActive(NAMED_PAGE_START) && | 144 ? IsNamedPageActive(NAMED_PAGE_START) && |
144 start_page_view_->IsShowingSearchResults() | 145 start_page_view_->IsShowingSearchResults() |
145 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); | 146 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); |
146 } | 147 } |
147 | 148 |
148 void ContentsView::CalculateIdealBounds() { | 149 void ContentsView::CalculateIdealBounds() { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (std::abs(offset) > kMinScrollToSwitchPage) { | 310 if (std::abs(offset) > kMinScrollToSwitchPage) { |
310 if (!GetAppsPaginationModel()->has_transition()) { | 311 if (!GetAppsPaginationModel()->has_transition()) { |
311 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | 312 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
312 } | 313 } |
313 event->SetHandled(); | 314 event->SetHandled(); |
314 event->StopPropagation(); | 315 event->StopPropagation(); |
315 } | 316 } |
316 } | 317 } |
317 | 318 |
318 } // namespace app_list | 319 } // namespace app_list |
OLD | NEW |