OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/start_page_view.h" | 5 #include "ui/app_list/views/start_page_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/app_list/app_list_constants.h" | 8 #include "ui/app_list/app_list_constants.h" |
9 #include "ui/app_list/app_list_item.h" | 9 #include "ui/app_list/app_list_item.h" |
10 #include "ui/app_list/app_list_model.h" | 10 #include "ui/app_list/app_list_model.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 Update(); | 140 Update(); |
141 } | 141 } |
142 | 142 |
143 TileItemView* StartPageView::all_apps_button() const { | 143 TileItemView* StartPageView::all_apps_button() const { |
144 return all_apps_button_; | 144 return all_apps_button_; |
145 } | 145 } |
146 | 146 |
147 void StartPageView::OnShow() { | 147 void StartPageView::OnShow() { |
148 DCHECK(app_list_main_view_->contents_view()->ShouldShowCustomPageClickzone()); | 148 DCHECK(app_list_main_view_->contents_view()->ShouldShowCustomPageClickzone()); |
149 UpdateCustomPageClickzoneVisibility(); | 149 UpdateCustomPageClickzoneVisibility(); |
| 150 ClearSelectedIndex(); |
150 } | 151 } |
151 | 152 |
152 void StartPageView::OnHide() { | 153 void StartPageView::OnHide() { |
153 DCHECK( | 154 DCHECK( |
154 !app_list_main_view_->contents_view()->ShouldShowCustomPageClickzone()); | 155 !app_list_main_view_->contents_view()->ShouldShowCustomPageClickzone()); |
155 UpdateCustomPageClickzoneVisibility(); | 156 UpdateCustomPageClickzoneVisibility(); |
156 } | 157 } |
157 | 158 |
158 void StartPageView::Layout() { | 159 void StartPageView::Layout() { |
159 gfx::Rect bounds(GetContentsBounds()); | 160 gfx::Rect bounds(GetContentsBounds()); |
160 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); | 161 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); |
161 instant_container_->SetBoundsRect(bounds); | 162 instant_container_->SetBoundsRect(bounds); |
162 | 163 |
163 // Tiles begin where the instant container ends. | 164 // Tiles begin where the instant container ends. |
164 bounds.set_y(bounds.bottom()); | 165 bounds.set_y(bounds.bottom()); |
165 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); | 166 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); |
166 tiles_container_->SetBoundsRect(bounds); | 167 tiles_container_->SetBoundsRect(bounds); |
167 } | 168 } |
168 | 169 |
| 170 bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) { |
| 171 if (selected_index() >= 0 && |
| 172 tiles_container_->child_at(selected_index())->OnKeyPressed(event)) |
| 173 return true; |
| 174 |
| 175 int dir = 0; |
| 176 switch (event.key_code()) { |
| 177 case ui::VKEY_LEFT: |
| 178 dir = -1; |
| 179 break; |
| 180 case ui::VKEY_RIGHT: |
| 181 dir = 1; |
| 182 break; |
| 183 case ui::VKEY_DOWN: |
| 184 // Down selects the first tile if nothing is selected. |
| 185 if (!IsValidSelectionIndex(selected_index())) |
| 186 dir = 1; |
| 187 break; |
| 188 case ui::VKEY_TAB: |
| 189 dir = event.IsShiftDown() ? -1 : 1; |
| 190 break; |
| 191 default: |
| 192 break; |
| 193 } |
| 194 |
| 195 if (dir == 0) |
| 196 return false; |
| 197 |
| 198 if (!IsValidSelectionIndex(selected_index())) { |
| 199 SetSelectedIndex(dir == -1 ? num_results() - 1 : 0); |
| 200 return true; |
| 201 } |
| 202 |
| 203 int selection_index = selected_index() + dir; |
| 204 if (IsValidSelectionIndex(selection_index)) { |
| 205 SetSelectedIndex(selection_index); |
| 206 return true; |
| 207 } |
| 208 |
| 209 return false; |
| 210 } |
| 211 |
169 void StartPageView::OnContainerSelected(bool from_bottom) { | 212 void StartPageView::OnContainerSelected(bool from_bottom) { |
170 } | 213 } |
171 | 214 |
172 gfx::Rect StartPageView::GetSearchBoxBounds() const { | 215 gfx::Rect StartPageView::GetSearchBoxBounds() const { |
173 return search_box_spacer_view_->bounds(); | 216 return search_box_spacer_view_->bounds(); |
174 } | 217 } |
175 | 218 |
176 void StartPageView::UpdateCustomPageClickzoneVisibility() { | 219 void StartPageView::UpdateCustomPageClickzoneVisibility() { |
177 // This can get called before InitWidgets(), so we cannot guarantee that | 220 // This can get called before InitWidgets(), so we cannot guarantee that |
178 // custom_page_clickzone_ will not be null. | 221 // custom_page_clickzone_ will not be null. |
(...skipping 18 matching lines...) Expand all Loading... |
197 // Update the tile item results. | 240 // Update the tile item results. |
198 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 241 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { |
199 SearchResult* item = NULL; | 242 SearchResult* item = NULL; |
200 if (i < display_results.size()) | 243 if (i < display_results.size()) |
201 item = display_results[i]; | 244 item = display_results[i]; |
202 search_result_tile_views_[i]->SetSearchResult(item); | 245 search_result_tile_views_[i]->SetSearchResult(item); |
203 } | 246 } |
204 | 247 |
205 tiles_container_->Layout(); | 248 tiles_container_->Layout(); |
206 Layout(); | 249 Layout(); |
207 return display_results.size(); | 250 // Add 1 to the results size to account for the all apps button. |
| 251 return display_results.size() + 1; |
208 } | 252 } |
209 | 253 |
210 void StartPageView::UpdateSelectedIndex(int old_selected, int new_selected) { | 254 void StartPageView::UpdateSelectedIndex(int old_selected, int new_selected) { |
| 255 if (old_selected >= 0) { |
| 256 tiles_container_->child_at(old_selected)->set_background(nullptr); |
| 257 tiles_container_->child_at(old_selected)->SchedulePaint(); |
| 258 } |
| 259 |
| 260 if (new_selected >= 0) { |
| 261 tiles_container_->child_at(new_selected) |
| 262 ->set_background( |
| 263 views::Background::CreateSolidBackground(kSelectedColor)); |
| 264 tiles_container_->child_at(new_selected)->SchedulePaint(); |
| 265 } |
211 } | 266 } |
212 | 267 |
213 } // namespace app_list | 268 } // namespace app_list |
OLD | NEW |