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

Side by Side Diff: athena/home/athena_start_page_view.cc

Issue 483033003: [Athena] Add status icons and system time to the centered home card (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months 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 | Annotate | Revision Log
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 "athena/home/athena_start_page_view.h" 5 #include "athena/home/athena_start_page_view.h"
6 6
7 #include "athena/home/home_card_constants.h" 7 #include "athena/home/home_card_constants.h"
8 #include "athena/system/public/system_ui.h"
8 #include "base/bind.h" 9 #include "base/bind.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "third_party/skia/include/core/SkPaint.h" 11 #include "third_party/skia/include/core/SkPaint.h"
11 #include "third_party/skia/include/core/SkPath.h" 12 #include "third_party/skia/include/core/SkPath.h"
12 #include "ui/app_list/app_list_item.h" 13 #include "ui/app_list/app_list_item.h"
13 #include "ui/app_list/app_list_item_list.h" 14 #include "ui/app_list/app_list_item_list.h"
14 #include "ui/app_list/app_list_model.h" 15 #include "ui/app_list/app_list_model.h"
15 #include "ui/app_list/app_list_view_delegate.h" 16 #include "ui/app_list/app_list_view_delegate.h"
16 #include "ui/app_list/search_box_model.h" 17 #include "ui/app_list/search_box_model.h"
17 #include "ui/app_list/views/search_box_view.h" 18 #include "ui/app_list/views/search_box_view.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 }; 149 };
149 150
150 } // namespace 151 } // namespace
151 152
152 namespace athena { 153 namespace athena {
153 154
154 // static 155 // static
155 const char AthenaStartPageView::kViewClassName[] = "AthenaStartPageView"; 156 const char AthenaStartPageView::kViewClassName[] = "AthenaStartPageView";
156 157
157 AthenaStartPageView::LayoutData::LayoutData() 158 AthenaStartPageView::LayoutData::LayoutData()
158 : logo_opacity(1.0f), 159 : top_view_opacity(1.0f),
160 logo_opacity(1.0f),
159 background_opacity(1.0f) { 161 background_opacity(1.0f) {
160 } 162 }
161 163
162 AthenaStartPageView::AthenaStartPageView( 164 AthenaStartPageView::AthenaStartPageView(
163 app_list::AppListViewDelegate* view_delegate) 165 app_list::AppListViewDelegate* view_delegate)
164 : delegate_(view_delegate), 166 : delegate_(view_delegate),
165 layout_state_(0.0f), 167 layout_state_(0.0f),
166 weak_factory_(this) { 168 weak_factory_(this) {
167 background_ = new views::View(); 169 background_ = new views::View();
168 background_->set_background( 170 background_->set_background(
169 views::Background::CreateSolidBackground(SK_ColorWHITE)); 171 views::Background::CreateSolidBackground(SK_ColorWHITE));
170 background_->SetPaintToLayer(true); 172 background_->SetPaintToLayer(true);
171 background_->SetFillsBoundsOpaquely(false); 173 background_->SetFillsBoundsOpaquely(false);
172 AddChildView(background_); 174 AddChildView(background_);
173 175
176 time_view_ = SystemUI::Get()->CreateTimeView(SystemUI::COLOR_SCHEME_DARK);
177 time_view_->SetPaintToLayer(true);
178 // Set a background on the view because painting text on a transparent layer
179 // looks bad. |time_view_|'s background animating at a different rate than
sadrul 2014/09/02 15:11:14 I think you can set some attrib on the Label so th
pkotwicz 2014/09/02 19:47:49 Disabling subpixel rendering does the trick. Thank
180 // |background_| is not noticeable in practice.
181 time_view_->set_background(
182 views::Background::CreateSolidBackground(SK_ColorWHITE));
183 AddChildView(time_view_);
184
185 status_icon_view_ =
186 SystemUI::Get()->CreateStatusIconView(SystemUI::COLOR_SCHEME_DARK);
187 status_icon_view_->set_background(
188 views::Background::CreateSolidBackground(SK_ColorWHITE));
189 status_icon_view_->SetPaintToLayer(true);
190 AddChildView(status_icon_view_);
191
174 logo_ = view_delegate->CreateStartPageWebView( 192 logo_ = view_delegate->CreateStartPageWebView(
175 gfx::Size(kWebViewWidth, kWebViewHeight)); 193 gfx::Size(kWebViewWidth, kWebViewHeight));
176 logo_->SetPaintToLayer(true); 194 logo_->SetPaintToLayer(true);
177 logo_->SetFillsBoundsOpaquely(false); 195 logo_->SetFillsBoundsOpaquely(false);
178 logo_->SetSize(gfx::Size(kWebViewWidth, kWebViewHeight)); 196 logo_->SetSize(gfx::Size(kWebViewWidth, kWebViewHeight));
179 AddChildView(logo_); 197 AddChildView(logo_);
180 198
181 search_results_view_ = new app_list::SearchResultListView( 199 search_results_view_ = new app_list::SearchResultListView(
182 NULL, view_delegate); 200 NULL, view_delegate);
183 // search_results_view_'s size will shrink after settings results. 201 // search_results_view_'s size will shrink after settings results.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void AthenaStartPageView::RequestFocusOnSearchBox() { 245 void AthenaStartPageView::RequestFocusOnSearchBox() {
228 search_box_view_->search_box()->RequestFocus(); 246 search_box_view_->search_box()->RequestFocus();
229 } 247 }
230 248
231 void AthenaStartPageView::SetLayoutState(float layout_state) { 249 void AthenaStartPageView::SetLayoutState(float layout_state) {
232 layout_state_ = layout_state; 250 layout_state_ = layout_state;
233 Layout(); 251 Layout();
234 } 252 }
235 253
236 void AthenaStartPageView::SetLayoutStateWithAnimation(float layout_state) { 254 void AthenaStartPageView::SetLayoutStateWithAnimation(float layout_state) {
255 ui::ScopedLayerAnimationSettings time(
256 time_view_->layer()->GetAnimator());
257 ui::ScopedLayerAnimationSettings status_icon(
258 status_icon_view_->layer()->GetAnimator());
237 ui::ScopedLayerAnimationSettings logo(logo_->layer()->GetAnimator()); 259 ui::ScopedLayerAnimationSettings logo(logo_->layer()->GetAnimator());
238 ui::ScopedLayerAnimationSettings search_box( 260 ui::ScopedLayerAnimationSettings search_box(
239 search_box_container_->layer()->GetAnimator()); 261 search_box_container_->layer()->GetAnimator());
240 ui::ScopedLayerAnimationSettings icons( 262 ui::ScopedLayerAnimationSettings icons(
241 app_icon_container_->layer()->GetAnimator()); 263 app_icon_container_->layer()->GetAnimator());
242 ui::ScopedLayerAnimationSettings controls( 264 ui::ScopedLayerAnimationSettings controls(
243 control_icon_container_->layer()->GetAnimator()); 265 control_icon_container_->layer()->GetAnimator());
244 266
267 time.SetTweenType(gfx::Tween::EASE_IN_OUT);
268 status_icon.SetTweenType(gfx::Tween::EASE_IN_OUT);
245 logo.SetTweenType(gfx::Tween::EASE_IN_OUT); 269 logo.SetTweenType(gfx::Tween::EASE_IN_OUT);
246 search_box.SetTweenType(gfx::Tween::EASE_IN_OUT); 270 search_box.SetTweenType(gfx::Tween::EASE_IN_OUT);
247 icons.SetTweenType(gfx::Tween::EASE_IN_OUT); 271 icons.SetTweenType(gfx::Tween::EASE_IN_OUT);
248 controls.SetTweenType(gfx::Tween::EASE_IN_OUT); 272 controls.SetTweenType(gfx::Tween::EASE_IN_OUT);
249 273
250 SetLayoutState(layout_state); 274 SetLayoutState(layout_state);
251 } 275 }
252 276
253 AthenaStartPageView::LayoutData AthenaStartPageView::CreateBottomBounds( 277 AthenaStartPageView::LayoutData AthenaStartPageView::CreateBottomBounds(
254 int width) { 278 int width) {
255 LayoutData state; 279 LayoutData state;
256 state.icons.set_size(app_icon_container_->size()); 280 state.icons.set_size(app_icon_container_->size());
257 state.icons.set_x(kIconMargin); 281 state.icons.set_x(kIconMargin);
258 state.icons.set_y(kIconMargin); 282 state.icons.set_y(kIconMargin);
259 283
260 state.controls.set_size(control_icon_container_->size()); 284 state.controls.set_size(control_icon_container_->size());
261 state.controls.set_x(width - kIconMargin - state.controls.width()); 285 state.controls.set_x(width - kIconMargin - state.controls.width());
262 state.controls.set_y(kIconMargin); 286 state.controls.set_y(kIconMargin);
263 287
264 int search_box_max_width = 288 int search_box_max_width =
265 state.controls.x() - state.icons.right() - kIconMargin * 2; 289 state.controls.x() - state.icons.right() - kIconMargin * 2;
266 state.search_box.set_width(std::min(search_box_max_width, kSearchBoxWidth)); 290 state.search_box.set_width(std::min(search_box_max_width, kSearchBoxWidth));
267 state.search_box.set_height(search_box_container_->height()); 291 state.search_box.set_height(search_box_container_->height());
268 state.search_box.set_x((width - state.search_box.width()) / 2); 292 state.search_box.set_x((width - state.search_box.width()) / 2);
269 state.search_box.set_y((kHomeCardHeight - state.search_box.height()) / 2); 293 state.search_box.set_y((kHomeCardHeight - state.search_box.height()) / 2);
270 294
295 state.top_view_opacity = 0.0f;
271 state.logo_opacity = 0.0f; 296 state.logo_opacity = 0.0f;
272 state.background_opacity = 0.9f; 297 state.background_opacity = 0.9f;
273 return state; 298 return state;
274 } 299 }
275 300
276 AthenaStartPageView::LayoutData AthenaStartPageView::CreateCenteredBounds( 301 AthenaStartPageView::LayoutData AthenaStartPageView::CreateCenteredBounds(
277 int width) { 302 int width) {
278 LayoutData state; 303 LayoutData state;
279 304
280 state.search_box.set_size(search_box_container_->GetPreferredSize()); 305 state.search_box.set_size(search_box_container_->GetPreferredSize());
281 state.search_box.set_x((width - state.search_box.width()) / 2); 306 state.search_box.set_x((width - state.search_box.width()) / 2);
282 state.search_box.set_y(logo_->bounds().bottom() + kInstantContainerSpacing); 307 state.search_box.set_y(logo_->bounds().bottom() + kInstantContainerSpacing);
283 308
284 state.icons.set_size(app_icon_container_->size()); 309 state.icons.set_size(app_icon_container_->size());
285 state.icons.set_x(width / 2 - state.icons.width() - kIconMargin / 2); 310 state.icons.set_x(width / 2 - state.icons.width() - kIconMargin / 2);
286 state.icons.set_y(state.search_box.bottom() + kInstantContainerSpacing); 311 state.icons.set_y(state.search_box.bottom() + kInstantContainerSpacing);
287 312
288 state.controls.set_size(control_icon_container_->size()); 313 state.controls.set_size(control_icon_container_->size());
289 state.controls.set_x(width / 2 + kIconMargin / 2 + kIconMargin % 2); 314 state.controls.set_x(width / 2 + kIconMargin / 2 + kIconMargin % 2);
290 state.controls.set_y(state.icons.y()); 315 state.controls.set_y(state.icons.y());
291 316
317 state.top_view_opacity = 1.0f;
292 state.logo_opacity = 1.0f; 318 state.logo_opacity = 1.0f;
293 state.background_opacity = 1.0f; 319 state.background_opacity = 1.0f;
294 return state; 320 return state;
295 } 321 }
296 322
297 void AthenaStartPageView::LayoutSearchResults(bool should_show_search_results) { 323 void AthenaStartPageView::LayoutSearchResults(bool should_show_search_results) {
298 if (should_show_search_results == 324 if (should_show_search_results ==
299 search_results_view_->layer()->GetTargetVisibility()) { 325 search_results_view_->layer()->GetTargetVisibility()) {
300 return; 326 return;
301 } 327 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 383 }
358 384
359 void AthenaStartPageView::OnSearchResultLayoutAnimationCompleted( 385 void AthenaStartPageView::OnSearchResultLayoutAnimationCompleted(
360 bool should_show_search_results) { 386 bool should_show_search_results) {
361 logo_->SetVisible(!should_show_search_results); 387 logo_->SetVisible(!should_show_search_results);
362 search_results_view_->SetVisible(should_show_search_results); 388 search_results_view_->SetVisible(should_show_search_results);
363 } 389 }
364 390
365 void AthenaStartPageView::Layout() { 391 void AthenaStartPageView::Layout() {
366 search_results_view_->SetVisible(false); 392 search_results_view_->SetVisible(false);
393
394 // The time goes in the top left corner.
395 time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize()));
396
397 // The status icons go in the top right corner.
398 gfx::Size status_icon_view_preferred_size =
399 status_icon_view_->GetPreferredSize();
400 status_icon_view_->SetBoundsRect(
401 gfx::Rect(width() - status_icon_view_preferred_size.width(),
402 0,
403 status_icon_view_preferred_size.width(),
404 status_icon_view_preferred_size.height()));
405
367 gfx::Rect logo_bounds(x() + width() / 2 - kWebViewWidth / 2, y() + kTopMargin, 406 gfx::Rect logo_bounds(x() + width() / 2 - kWebViewWidth / 2, y() + kTopMargin,
368 kWebViewWidth, kWebViewHeight); 407 kWebViewWidth, kWebViewHeight);
369 logo_->SetBoundsRect(logo_bounds); 408 logo_->SetBoundsRect(logo_bounds);
370 409
371 LayoutData bottom_bounds = CreateBottomBounds(width()); 410 LayoutData bottom_bounds = CreateBottomBounds(width());
372 LayoutData centered_bounds = CreateCenteredBounds(width()); 411 LayoutData centered_bounds = CreateCenteredBounds(width());
373 412
413 float top_view_opacity = gfx::Tween::FloatValueBetween(
414 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN_2, layout_state_),
415 bottom_bounds.top_view_opacity, centered_bounds.top_view_opacity);
416 time_view_->layer()->SetOpacity(top_view_opacity);
417 time_view_->SetVisible(time_view_->layer()->GetTargetOpacity() != 0.0f);
418 status_icon_view_->layer()->SetOpacity(top_view_opacity);
419 status_icon_view_->SetVisible(
420 status_icon_view_->layer()->GetTargetOpacity() != 0.0f);
421
374 logo_->layer()->SetOpacity(gfx::Tween::FloatValueBetween( 422 logo_->layer()->SetOpacity(gfx::Tween::FloatValueBetween(
375 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN_2, layout_state_), 423 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN_2, layout_state_),
376 bottom_bounds.logo_opacity, centered_bounds.logo_opacity)); 424 bottom_bounds.logo_opacity, centered_bounds.logo_opacity));
377 logo_->SetVisible(logo_->layer()->GetTargetOpacity() != 0.0f); 425 logo_->SetVisible(logo_->layer()->GetTargetOpacity() != 0.0f);
378 426
379 app_icon_container_->SetBoundsRect(gfx::Tween::RectValueBetween( 427 app_icon_container_->SetBoundsRect(gfx::Tween::RectValueBetween(
380 layout_state_, bottom_bounds.icons, centered_bounds.icons)); 428 layout_state_, bottom_bounds.icons, centered_bounds.icons));
381 control_icon_container_->SetBoundsRect(gfx::Tween::RectValueBetween( 429 control_icon_container_->SetBoundsRect(gfx::Tween::RectValueBetween(
382 layout_state_, bottom_bounds.controls, centered_bounds.controls)); 430 layout_state_, bottom_bounds.controls, centered_bounds.controls));
383 search_box_container_->SetBoundsRect(gfx::Tween::RectValueBetween( 431 search_box_container_->SetBoundsRect(gfx::Tween::RectValueBetween(
384 layout_state_, bottom_bounds.search_box, centered_bounds.search_box)); 432 layout_state_, bottom_bounds.search_box, centered_bounds.search_box));
385 433
386 background_->SetBoundsRect(bounds()); 434 background_->SetBoundsRect(bounds());
387 background_->layer()->SetOpacity(gfx::Tween::FloatValueBetween( 435 background_->layer()->SetOpacity(gfx::Tween::FloatValueBetween(
388 layout_state_, 436 layout_state_,
389 bottom_bounds.background_opacity, 437 bottom_bounds.background_opacity,
390 centered_bounds.background_opacity)); 438 centered_bounds.background_opacity));
391 } 439 }
392 440
393 bool AthenaStartPageView::OnKeyPressed(const ui::KeyEvent& key_event) { 441 bool AthenaStartPageView::OnKeyPressed(const ui::KeyEvent& key_event) {
394 return search_results_view_->visible() && 442 return search_results_view_->visible() &&
395 search_results_view_->OnKeyPressed(key_event); 443 search_results_view_->OnKeyPressed(key_event);
396 } 444 }
397 445
446 void AthenaStartPageView::ChildPreferredSizeChanged(views::View* view) {
447 // Relayout when |status_icon_view_| changes its preferred size.
448 Layout();
449 }
450
398 void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) { 451 void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) {
399 delegate_->StartSearch(); 452 delegate_->StartSearch();
400 453
401 base::string16 query; 454 base::string16 query;
402 base::TrimWhitespace( 455 base::TrimWhitespace(
403 delegate_->GetModel()->search_box()->text(), base::TRIM_ALL, &query); 456 delegate_->GetModel()->search_box()->text(), base::TRIM_ALL, &query);
404 457
405 if (!query.empty()) 458 if (!query.empty())
406 search_results_view_->SetSelectedIndex(0); 459 search_results_view_->SetSelectedIndex(0);
407 460
408 LayoutSearchResults(!query.empty()); 461 LayoutSearchResults(!query.empty());
409 } 462 }
410 463
411 } // namespace athena 464 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698