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

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

Issue 463733003: Move the implementation of HomeCardImpl out of the class declaration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | 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 "athena/home/public/home_card.h" 5 #include "athena/home/public/home_card.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "athena/common/container_priorities.h" 10 #include "athena/common/container_priorities.h"
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 virtual void SetState(State state) OVERRIDE; 362 virtual void SetState(State state) OVERRIDE;
363 virtual State GetState() OVERRIDE; 363 virtual State GetState() OVERRIDE;
364 virtual void RegisterSearchProvider( 364 virtual void RegisterSearchProvider(
365 app_list::SearchProvider* search_provider) OVERRIDE; 365 app_list::SearchProvider* search_provider) OVERRIDE;
366 virtual void UpdateVirtualKeyboardBounds( 366 virtual void UpdateVirtualKeyboardBounds(
367 const gfx::Rect& bounds) OVERRIDE; 367 const gfx::Rect& bounds) OVERRIDE;
368 368
369 // AcceleratorHandler: 369 // AcceleratorHandler:
370 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } 370 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; }
371 virtual bool OnAcceleratorFired(int command_id, 371 virtual bool OnAcceleratorFired(int command_id,
372 const ui::Accelerator& accelerator) OVERRIDE { 372 const ui::Accelerator& accelerator) OVERRIDE;
373 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id);
374
375 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM)
376 SetState(VISIBLE_MINIMIZED);
377 else if (state_ == VISIBLE_MINIMIZED)
378 SetState(VISIBLE_CENTERED);
379 return true;
380 }
381 373
382 // HomeCardLayoutManager::Delegate: 374 // HomeCardLayoutManager::Delegate:
383 virtual aura::Window* GetNativeWindow() OVERRIDE { 375 virtual aura::Window* GetNativeWindow() OVERRIDE;
384 if (state_ == HIDDEN)
385 return NULL;
386
387 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
388 }
389 376
390 // HomeCardGestureManager::Delegate: 377 // HomeCardGestureManager::Delegate:
391 virtual void OnGestureEnded(State final_state) OVERRIDE { 378 virtual void OnGestureEnded(State final_state) OVERRIDE;
392 home_card_view_->ClearGesture();
393 if (state_ != final_state &&
394 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) {
395 WindowManager::GetInstance()->ToggleOverview();
396 } else {
397 state_ = final_state;
398 home_card_view_->SetState(final_state);
399 layout_manager_->Layout();
400 }
401 }
402
403 virtual void OnGestureProgressed( 379 virtual void OnGestureProgressed(
404 State from_state, State to_state, float progress) OVERRIDE { 380 State from_state, State to_state, float progress) OVERRIDE;
405 // Do not update |state_| but update the look of home_card_view.
406 // TODO(mukai): allow mixed visual of |from_state| and |to_state|.
407 home_card_view_->SetState(to_state);
408
409 gfx::Rect screen_bounds =
410 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds();
411 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween(
412 progress,
413 GetBoundsForState(screen_bounds, from_state),
414 GetBoundsForState(screen_bounds, to_state)));
415
416 // TODO(mukai): signals the update to the window manager so that it shows
417 // the intermediate visual state of overview mode.
418 }
419 381
420 // WindowManagerObserver: 382 // WindowManagerObserver:
421 virtual void OnOverviewModeEnter() OVERRIDE { 383 virtual void OnOverviewModeEnter() OVERRIDE;
422 SetState(VISIBLE_BOTTOM); 384 virtual void OnOverviewModeExit() OVERRIDE;
423 }
424
425 virtual void OnOverviewModeExit() OVERRIDE {
426 SetState(VISIBLE_MINIMIZED);
427 }
428 385
429 // aura::client::ActivationChangeObserver: 386 // aura::client::ActivationChangeObserver:
430 virtual void OnWindowActivated(aura::Window* gained_active, 387 virtual void OnWindowActivated(aura::Window* gained_active,
431 aura::Window* lost_active) OVERRIDE { 388 aura::Window* lost_active) OVERRIDE;
432 if (state_ != HIDDEN &&
433 gained_active != home_card_widget_->GetNativeWindow()) {
434 SetState(VISIBLE_MINIMIZED);
435 }
436 }
437 389
438 scoped_ptr<AppModelBuilder> model_builder_; 390 scoped_ptr<AppModelBuilder> model_builder_;
439 391
440 HomeCard::State state_; 392 HomeCard::State state_;
441 393
442 // original_state_ is the state which the home card should go back to after 394 // original_state_ is the state which the home card should go back to after
443 // the virtual keyboard is hidden. 395 // the virtual keyboard is hidden.
444 HomeCard::State original_state_; 396 HomeCard::State original_state_;
445 397
446 views::Widget* home_card_widget_; 398 views::Widget* home_card_widget_;
(...skipping 24 matching lines...) Expand all
471 423
472 HomeCardImpl::~HomeCardImpl() { 424 HomeCardImpl::~HomeCardImpl() {
473 DCHECK(instance); 425 DCHECK(instance);
474 WindowManager::GetInstance()->RemoveObserver(this); 426 WindowManager::GetInstance()->RemoveObserver(this);
475 if (activation_client_) 427 if (activation_client_)
476 activation_client_->RemoveObserver(this); 428 activation_client_->RemoveObserver(this);
477 home_card_widget_->CloseNow(); 429 home_card_widget_->CloseNow();
478 instance = NULL; 430 instance = NULL;
479 } 431 }
480 432
433 void HomeCardImpl::Init() {
434 InstallAccelerators();
435 ScreenManager::ContainerParams params("HomeCardContainer", CP_HOME_CARD);
436 params.can_activate_children = true;
437 aura::Window* container = ScreenManager::Get()->CreateContainer(params);
438 layout_manager_ = new HomeCardLayoutManager(this);
439
440 container->SetLayoutManager(layout_manager_);
441 wm::SetChildWindowVisibilityChangesAnimated(container);
442
443 view_delegate_.reset(new AppListViewDelegate(model_builder_.get()));
444 if (search_provider_)
445 view_delegate_->RegisterSearchProvider(search_provider_.get());
446
447 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
448 home_card_widget_ = new views::Widget();
449 views::Widget::InitParams widget_params(
450 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
451 widget_params.parent = container;
452 widget_params.delegate = home_card_view_;
453 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
454 home_card_widget_->Init(widget_params);
455
456 SetState(VISIBLE_MINIMIZED);
457 home_card_view_->Layout();
458
459 activation_client_ =
460 aura::client::GetActivationClient(container->GetRootWindow());
461 if (activation_client_)
462 activation_client_->AddObserver(this);
463 }
464
465 void HomeCardImpl::InstallAccelerators() {
466 const AcceleratorData accelerator_data[] = {
467 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN,
468 COMMAND_SHOW_HOME_CARD, AF_NONE},
469 };
470 AcceleratorManager::Get()->RegisterAccelerators(
471 accelerator_data, arraysize(accelerator_data), this);
472 }
473
481 void HomeCardImpl::SetState(HomeCard::State state) { 474 void HomeCardImpl::SetState(HomeCard::State state) {
482 if (state_ == state) 475 if (state_ == state)
483 return; 476 return;
484 477
485 // Update |state_| before changing the visibility of the widgets, so that 478 // Update |state_| before changing the visibility of the widgets, so that
486 // LayoutManager callbacks get the correct state. 479 // LayoutManager callbacks get the correct state.
487 state_ = state; 480 state_ = state;
488 original_state_ = state; 481 original_state_ = state;
489 if (state_ == HIDDEN) { 482 if (state_ == HIDDEN) {
490 home_card_widget_->Hide(); 483 home_card_widget_->Hide();
(...skipping 24 matching lines...) Expand all
515 SetState(HIDDEN); 508 SetState(HIDDEN);
516 original_state_ = VISIBLE_MINIMIZED; 509 original_state_ = VISIBLE_MINIMIZED;
517 } else if (state_ == VISIBLE_BOTTOM && !bounds.IsEmpty()) { 510 } else if (state_ == VISIBLE_BOTTOM && !bounds.IsEmpty()) {
518 SetState(VISIBLE_CENTERED); 511 SetState(VISIBLE_CENTERED);
519 original_state_ = VISIBLE_BOTTOM; 512 original_state_ = VISIBLE_BOTTOM;
520 } else if (state_ != original_state_ && bounds.IsEmpty()) { 513 } else if (state_ != original_state_ && bounds.IsEmpty()) {
521 SetState(original_state_); 514 SetState(original_state_);
522 } 515 }
523 } 516 }
524 517
525 void HomeCardImpl::Init() { 518 bool HomeCardImpl::OnAcceleratorFired(int command_id,
526 InstallAccelerators(); 519 const ui::Accelerator& accelerator) {
527 ScreenManager::ContainerParams params("HomeCardContainer", CP_HOME_CARD); 520 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id);
528 params.can_activate_children = true;
529 aura::Window* container = ScreenManager::Get()->CreateContainer(params);
530 layout_manager_ = new HomeCardLayoutManager(this);
531 521
532 container->SetLayoutManager(layout_manager_); 522 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM)
533 wm::SetChildWindowVisibilityChangesAnimated(container); 523 SetState(VISIBLE_MINIMIZED);
534 524 else if (state_ == VISIBLE_MINIMIZED)
535 view_delegate_.reset(new AppListViewDelegate(model_builder_.get())); 525 SetState(VISIBLE_CENTERED);
536 if (search_provider_) 526 return true;
537 view_delegate_->RegisterSearchProvider(search_provider_.get());
538
539 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
540 home_card_widget_ = new views::Widget();
541 views::Widget::InitParams widget_params(
542 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
543 widget_params.parent = container;
544 widget_params.delegate = home_card_view_;
545 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
546 home_card_widget_->Init(widget_params);
547
548 SetState(VISIBLE_MINIMIZED);
549 home_card_view_->Layout();
550
551 activation_client_ =
552 aura::client::GetActivationClient(container->GetRootWindow());
553 if (activation_client_)
554 activation_client_->AddObserver(this);
555 } 527 }
556 528
557 void HomeCardImpl::InstallAccelerators() { 529 aura::Window* HomeCardImpl::GetNativeWindow() {
558 const AcceleratorData accelerator_data[] = { 530 if (state_ == HIDDEN)
559 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, 531 return NULL;
560 COMMAND_SHOW_HOME_CARD, AF_NONE}, 532
561 }; 533 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
562 AcceleratorManager::Get()->RegisterAccelerators( 534 }
563 accelerator_data, arraysize(accelerator_data), this); 535
536 void HomeCardImpl::OnGestureEnded(State final_state) {
537 home_card_view_->ClearGesture();
538 if (state_ != final_state &&
539 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) {
540 WindowManager::GetInstance()->ToggleOverview();
541 } else {
542 state_ = final_state;
543 home_card_view_->SetState(final_state);
544 layout_manager_->Layout();
545 }
546 }
547
548 void HomeCardImpl::OnGestureProgressed(
549 State from_state, State to_state, float progress) {
550 // Do not update |state_| but update the look of home_card_view.
551 // TODO(mukai): allow mixed visual of |from_state| and |to_state|.
552 home_card_view_->SetState(to_state);
553
554 gfx::Rect screen_bounds =
555 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds();
556 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween(
557 progress,
558 GetBoundsForState(screen_bounds, from_state),
559 GetBoundsForState(screen_bounds, to_state)));
560
561 // TODO(mukai): signals the update to the window manager so that it shows the
562 // intermediate visual state of overview mode.
563 }
564
565 void HomeCardImpl::OnOverviewModeEnter() {
566 SetState(VISIBLE_BOTTOM);
567 }
568
569 void HomeCardImpl::OnOverviewModeExit() {
570 SetState(VISIBLE_MINIMIZED);
571 }
572
573 void HomeCardImpl::OnWindowActivated(aura::Window* gained_active,
574 aura::Window* lost_active) {
575 if (state_ != HIDDEN &&
576 gained_active != home_card_widget_->GetNativeWindow()) {
577 SetState(VISIBLE_MINIMIZED);
578 }
564 } 579 }
565 580
566 } // namespace 581 } // namespace
567 582
568 // static 583 // static
569 HomeCard* HomeCard::Create(AppModelBuilder* model_builder) { 584 HomeCard* HomeCard::Create(AppModelBuilder* model_builder) {
570 (new HomeCardImpl(model_builder))->Init(); 585 (new HomeCardImpl(model_builder))->Init();
571 DCHECK(instance); 586 DCHECK(instance);
572 return instance; 587 return instance;
573 } 588 }
574 589
575 // static 590 // static
576 void HomeCard::Shutdown() { 591 void HomeCard::Shutdown() {
577 DCHECK(instance); 592 DCHECK(instance);
578 delete instance; 593 delete instance;
579 instance = NULL; 594 instance = NULL;
580 } 595 }
581 596
582 // static 597 // static
583 HomeCard* HomeCard::Get() { 598 HomeCard* HomeCard::Get() {
584 DCHECK(instance); 599 DCHECK(instance);
585 return instance; 600 return instance;
586 } 601 }
587 602
588 } // namespace athena 603 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698