Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: ui/app_list/views/start_page_view.cc

Issue 730343008: Add keyboard navigation for start page tiles in experimental app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_search_box_widget_layout
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/start_page_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void StartPageView::UpdateForTesting() { 139 void StartPageView::UpdateForTesting() {
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 UpdateCustomPageClickzoneVisibility(); 148 UpdateCustomPageClickzoneVisibility();
149 ClearSelectedIndex();
149 } 150 }
150 151
151 void StartPageView::OnHide() { 152 void StartPageView::OnHide() {
152 UpdateCustomPageClickzoneVisibility(); 153 UpdateCustomPageClickzoneVisibility();
153 } 154 }
154 155
155 void StartPageView::Layout() { 156 void StartPageView::Layout() {
156 gfx::Rect bounds(GetContentsBounds()); 157 gfx::Rect bounds(GetContentsBounds());
157 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); 158 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width()));
158 instant_container_->SetBoundsRect(bounds); 159 instant_container_->SetBoundsRect(bounds);
159 160
160 // Tiles begin where the instant container ends. 161 // Tiles begin where the instant container ends.
161 bounds.set_y(bounds.bottom()); 162 bounds.set_y(bounds.bottom());
162 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); 163 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width()));
163 tiles_container_->SetBoundsRect(bounds); 164 tiles_container_->SetBoundsRect(bounds);
164 } 165 }
165 166
167 bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) {
168 if (selected_index() >= 0 &&
169 tiles_container_->child_at(selected_index())->OnKeyPressed(event))
Matt Giuca 2014/12/09 08:02:01 Question: Does this mean the all apps button will
calamity 2014/12/10 04:39:46 Yes.
Matt Giuca 2014/12/10 07:04:28 OK I will do it.
170 return true;
171
172 int dir = 0;
173 switch (event.key_code()) {
174 case ui::VKEY_LEFT:
175 dir = -1;
176 break;
177 case ui::VKEY_RIGHT:
178 dir = 1;
179 break;
180 case ui::VKEY_DOWN:
181 dir = 1;
182 break;
183 case ui::VKEY_TAB:
184 dir = event.IsShiftDown() ? -1 : 1;
185 break;
186 default:
187 break;
188 }
189
190 if (dir == 0)
191 return false;
192
193 if (!IsValidSelectionIndex(selected_index())) {
194 OnContainerSelected(dir == -1);
Matt Giuca 2014/12/09 08:02:01 I don't really get why you use OnContainerSelected
calamity 2014/12/10 04:39:46 Eh. This is a bit of a semantic choice. I guess we
195 return true;
196 }
197
198 int selection_index = selected_index() + dir;
199 if (IsValidSelectionIndex(selection_index)) {
200 SetSelectedIndex(selection_index);
201 return true;
202 }
203
204 return false;
205 }
206
166 void StartPageView::OnContainerSelected(bool from_bottom) { 207 void StartPageView::OnContainerSelected(bool from_bottom) {
208 SetSelectedIndex(from_bottom ? num_results() - 1 : 0);
167 } 209 }
168 210
169 gfx::Rect StartPageView::GetSearchBoxBounds() const { 211 gfx::Rect StartPageView::GetSearchBoxBounds() const {
170 return search_box_spacer_view_->bounds(); 212 return search_box_spacer_view_->bounds();
171 } 213 }
172 214
173 void StartPageView::UpdateCustomPageClickzoneVisibility() { 215 void StartPageView::UpdateCustomPageClickzoneVisibility() {
174 // This can get called before InitWidgets(), so we cannot guarantee that 216 // This can get called before InitWidgets(), so we cannot guarantee that
175 // custom_page_clickzone_ will not be null. 217 // custom_page_clickzone_ will not be null.
176 views::Widget* custom_page_clickzone = 218 views::Widget* custom_page_clickzone =
(...skipping 17 matching lines...) Expand all
194 // Update the tile item results. 236 // Update the tile item results.
195 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { 237 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) {
196 SearchResult* item = NULL; 238 SearchResult* item = NULL;
197 if (i < display_results.size()) 239 if (i < display_results.size())
198 item = display_results[i]; 240 item = display_results[i];
199 search_result_tile_views_[i]->SetSearchResult(item); 241 search_result_tile_views_[i]->SetSearchResult(item);
200 } 242 }
201 243
202 tiles_container_->Layout(); 244 tiles_container_->Layout();
203 Layout(); 245 Layout();
204 return display_results.size(); 246 // Add 1 to the results size to account for the all apps button.
247 return display_results.size() + 1;
Matt Giuca 2014/12/09 08:02:01 Is this result unrelated?
calamity 2014/12/10 04:39:46 Nope. Necessary to allow the all_apps_button_ to b
205 } 248 }
206 249
207 void StartPageView::UpdateSelectedIndex(int old_selected, int new_selected) { 250 void StartPageView::UpdateSelectedIndex(int old_selected, int new_selected) {
251 if (old_selected >= 0) {
252 tiles_container_->child_at(old_selected)->set_background(nullptr);
253 tiles_container_->child_at(old_selected)->SchedulePaint();
254 }
255
256 if (new_selected >= 0) {
257 tiles_container_->child_at(new_selected)
258 ->set_background(
259 views::Background::CreateSolidBackground(kSelectedColor));
260 tiles_container_->child_at(new_selected)->SchedulePaint();
261 }
208 } 262 }
209 263
210 } // namespace app_list 264 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/start_page_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698