| Index: athena/home/home_card_impl.cc
|
| diff --git a/athena/home/home_card_impl.cc b/athena/home/home_card_impl.cc
|
| index 89852462c1b0315ee178a9abbb25586f91654d90..aa3767d1fd50033fa447b4678b54f113eca20403 100644
|
| --- a/athena/home/home_card_impl.cc
|
| +++ b/athena/home/home_card_impl.cc
|
| @@ -4,7 +4,10 @@
|
|
|
| #include "athena/home/public/home_card.h"
|
|
|
| +#include <limits>
|
| +
|
| #include "athena/home/app_list_view_delegate.h"
|
| +#include "athena/home/bottom_home_view.h"
|
| #include "athena/home/minimized_home.h"
|
| #include "athena/home/public/app_model_builder.h"
|
| #include "athena/input/public/accelerator_manager.h"
|
| @@ -13,10 +16,14 @@
|
| #include "athena/wm/public/window_manager_observer.h"
|
| #include "base/bind.h"
|
| #include "ui/app_list/search_provider.h"
|
| -#include "ui/app_list/views/app_list_view.h"
|
| +#include "ui/app_list/views/app_list_main_view.h"
|
| +#include "ui/app_list/views/contents_view.h"
|
| #include "ui/aura/layout_manager.h"
|
| #include "ui/aura/window.h"
|
| +#include "ui/views/background.h"
|
| #include "ui/views/layout/box_layout.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "ui/views/widget/widget_delegate.h"
|
| #include "ui/wm/core/visibility_controller.h"
|
| #include "ui/wm/core/window_animations.h"
|
|
|
| @@ -37,20 +44,30 @@ class HomeCardLayoutManager : public aura::LayoutManager {
|
|
|
| virtual int GetHorizontalMargin() const = 0;
|
|
|
| - // TODO(mukai): Remove this when bubble is no longer used for
|
| - // VISIBLE_CENTERED or VISIBLE_BOTTOM states.
|
| - virtual bool HasShadow() const = 0;
|
| -
|
| virtual aura::Window* GetNativeWindow() = 0;
|
| };
|
|
|
| explicit HomeCardLayoutManager(Delegate* delegate)
|
| : delegate_(delegate) {}
|
| +
|
| virtual ~HomeCardLayoutManager() {}
|
|
|
| - void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) {
|
| - virtual_keyboard_bounds_ = bounds;
|
| - Layout();
|
| + void Layout() {
|
| + aura::Window* home_card = delegate_->GetNativeWindow();
|
| + // |home_card| could be detached from the root window (e.g. when it is being
|
| + // destroyed).
|
| + if (!home_card || !home_card->GetRootWindow())
|
| + return;
|
| +
|
| + int height = delegate_->GetHomeCardHeight();
|
| + int horiz_margin = delegate_->GetHorizontalMargin();
|
| + gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
|
| + height = std::min(height, screen_bounds.height());
|
| + gfx::Rect card_bounds = screen_bounds;
|
| + card_bounds.Inset(horiz_margin, screen_bounds.height() - height,
|
| + horiz_margin, 0);
|
| +
|
| + SetChildBoundsDirect(home_card, card_bounds);
|
| }
|
|
|
| private:
|
| @@ -70,36 +87,66 @@ class HomeCardLayoutManager : public aura::LayoutManager {
|
| SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size()));
|
| }
|
|
|
| - void Layout() {
|
| - int height = delegate_->GetHomeCardHeight();
|
| - int horiz_margin = delegate_->GetHorizontalMargin();
|
| - aura::Window* home_card = delegate_->GetNativeWindow();
|
| - // |home_card| could be detached from the root window (e.g. when it is being
|
| - // destroyed).
|
| - if (!home_card || !home_card->GetRootWindow())
|
| - return;
|
| + Delegate* delegate_;
|
|
|
| - gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
|
| - if (!virtual_keyboard_bounds_.IsEmpty())
|
| - screen_bounds.set_height(virtual_keyboard_bounds_.y());
|
| - gfx::Rect card_bounds = screen_bounds;
|
| - card_bounds.Inset(horiz_margin, screen_bounds.height() - height,
|
| - horiz_margin, 0);
|
| + DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
|
| +};
|
| +
|
| +// The container view of home card contents of each state.
|
| +class HomeCardView : public views::WidgetDelegateView {
|
| + public:
|
| + HomeCardView(app_list::AppListViewDelegate* view_delegate,
|
| + aura::Window* container,
|
| + MinimizedHomeDragDelegate* minimized_delegate) {
|
| + set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
|
| +
|
| + bottom_view_ = new BottomHomeView(view_delegate);
|
| + AddChildView(bottom_view_);
|
|
|
| - if (delegate_->HasShadow()) {
|
| - // Currently the home card is provided as a bubble and the bounds has to
|
| - // be increased to cancel the shadow.
|
| - // TODO(mukai): stops using the bubble and remove this.
|
| - const int kHomeCardShadowWidth = 30;
|
| - card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth);
|
| + main_view_ = new app_list::AppListMainView(
|
| + view_delegate, 0 /* initial_apps_page */, container);
|
| + AddChildView(main_view_);
|
| +
|
| + minimized_view_ = CreateMinimizedHome(minimized_delegate);
|
| + AddChildView(minimized_view_);
|
| + }
|
| +
|
| + void SetState(HomeCard::State state) {
|
| + bottom_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM);
|
| + main_view_->SetVisible(state == HomeCard::VISIBLE_CENTERED);
|
| + minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED);
|
| + if (state == HomeCard::VISIBLE_CENTERED) {
|
| + app_list::ContentsView* contents_view = main_view_->contents_view();
|
| + contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage(
|
| + app_list::ContentsView::NAMED_PAGE_START));
|
| }
|
| - SetChildBoundsDirect(home_card, card_bounds);
|
| }
|
|
|
| - Delegate* delegate_;
|
| - gfx::Rect virtual_keyboard_bounds_;
|
| + // views::View:
|
| + virtual void Layout() OVERRIDE {
|
| + for (int i = 0; i < child_count(); ++i) {
|
| + views::View* child = child_at(i);
|
| + if (child->visible()) {
|
| + child->SetBoundsRect(bounds());
|
| + return;
|
| + }
|
| + }
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
|
| + // One of the child views has to be visible.
|
| + NOTREACHED();
|
| + }
|
| +
|
| + private:
|
| + // views::WidgetDelegate:
|
| + virtual views::View* GetContentsView() OVERRIDE {
|
| + return this;
|
| + }
|
| +
|
| + app_list::AppListMainView* main_view_;
|
| + BottomHomeView* bottom_view_;
|
| + views::View* minimized_view_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HomeCardView);
|
| };
|
|
|
| class HomeCardImpl : public HomeCard,
|
| @@ -142,33 +189,32 @@ class HomeCardImpl : public HomeCard,
|
| virtual int GetHomeCardHeight() const OVERRIDE {
|
| const int kHomeCardHeight = 150;
|
| const int kHomeCardMinimizedHeight = 8;
|
| - CHECK_NE(HIDDEN, state_);
|
| - return state_ == VISIBLE_MINIMIZED ? kHomeCardMinimizedHeight :
|
| - kHomeCardHeight;
|
| +
|
| + switch (state_) {
|
| + case VISIBLE_CENTERED:
|
| + // Span the screen fully.
|
| + return std::numeric_limits<int>::max();
|
| + case VISIBLE_BOTTOM:
|
| + return kHomeCardHeight;
|
| + case VISIBLE_MINIMIZED:
|
| + return kHomeCardMinimizedHeight;
|
| + case HIDDEN:
|
| + NOTREACHED();
|
| + return -1;
|
| + }
|
| }
|
|
|
| virtual int GetHorizontalMargin() const OVERRIDE {
|
| CHECK_NE(HIDDEN, state_);
|
| const int kHomeCardHorizontalMargin = 50;
|
| - return state_ == VISIBLE_MINIMIZED ? 0 : kHomeCardHorizontalMargin;
|
| - }
|
| -
|
| - virtual bool HasShadow() const OVERRIDE {
|
| - CHECK_NE(HIDDEN, state_);
|
| - return state_ != VISIBLE_MINIMIZED;
|
| + return state_ == VISIBLE_BOTTOM ? kHomeCardHorizontalMargin : 0;
|
| }
|
|
|
| virtual aura::Window* GetNativeWindow() OVERRIDE {
|
| - switch (state_) {
|
| - case HIDDEN:
|
| - return NULL;
|
| - case VISIBLE_MINIMIZED:
|
| - return minimized_widget_ ? minimized_widget_->GetNativeWindow() : NULL;
|
| - case VISIBLE_CENTERED:
|
| - case VISIBLE_BOTTOM:
|
| - return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
|
| - }
|
| - return NULL;
|
| + if (state_ == HIDDEN)
|
| + return NULL;
|
| +
|
| + return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
|
| }
|
|
|
| // MinimizedHomeDragDelegate:
|
| @@ -189,9 +235,13 @@ class HomeCardImpl : public HomeCard,
|
|
|
| HomeCard::State state_;
|
|
|
| + // original_state_ is the state which the home card should go back to after
|
| + // the virtual keyboard is hidden.
|
| + HomeCard::State original_state_;
|
| +
|
| views::Widget* home_card_widget_;
|
| - views::Widget* minimized_widget_;
|
| - AppListViewDelegate* view_delegate_;
|
| + HomeCardView* home_card_view_;
|
| + scoped_ptr<AppListViewDelegate> view_delegate_;
|
| HomeCardLayoutManager* layout_manager_;
|
|
|
| // Right now HomeCard allows only one search provider.
|
| @@ -204,8 +254,9 @@ class HomeCardImpl : public HomeCard,
|
| HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
|
| : model_builder_(model_builder),
|
| state_(VISIBLE_MINIMIZED),
|
| + original_state_(VISIBLE_MINIMIZED),
|
| home_card_widget_(NULL),
|
| - minimized_widget_(NULL),
|
| + home_card_view_(NULL),
|
| layout_manager_(NULL) {
|
| DCHECK(!instance);
|
| instance = this;
|
| @@ -216,8 +267,6 @@ HomeCardImpl::~HomeCardImpl() {
|
| DCHECK(instance);
|
| WindowManager::GetInstance()->RemoveObserver(this);
|
| home_card_widget_->CloseNow();
|
| - minimized_widget_->CloseNow();
|
| - view_delegate_ = NULL;
|
| instance = NULL;
|
| }
|
|
|
| @@ -225,20 +274,13 @@ void HomeCardImpl::SetState(HomeCard::State state) {
|
| // Update |state_| before changing the visibility of the widgets, so that
|
| // LayoutManager callbacks get the correct state.
|
| state_ = state;
|
| - switch (state_) {
|
| - case VISIBLE_MINIMIZED:
|
| - home_card_widget_->Hide();
|
| - minimized_widget_->Show();
|
| - break;
|
| - case HIDDEN:
|
| - home_card_widget_->Hide();
|
| - minimized_widget_->Hide();
|
| - break;
|
| - case VISIBLE_BOTTOM:
|
| - case VISIBLE_CENTERED:
|
| - home_card_widget_->Show();
|
| - minimized_widget_->Hide();
|
| - break;
|
| + original_state_ = state;
|
| + if (state_ == HIDDEN) {
|
| + home_card_widget_->Hide();
|
| + } else {
|
| + home_card_widget_->Show();
|
| + home_card_view_->SetState(state);
|
| + layout_manager_->Layout();
|
| }
|
| }
|
|
|
| @@ -251,13 +293,15 @@ void HomeCardImpl::RegisterSearchProvider(
|
|
|
| void HomeCardImpl::UpdateVirtualKeyboardBounds(
|
| const gfx::Rect& bounds) {
|
| - if (state_ == VISIBLE_MINIMIZED) {
|
| - if (bounds.IsEmpty())
|
| - minimized_widget_->Show();
|
| - else
|
| - minimized_widget_->Hide();
|
| + if (state_ == VISIBLE_MINIMIZED && !bounds.IsEmpty()) {
|
| + SetState(HIDDEN);
|
| + original_state_ = VISIBLE_MINIMIZED;
|
| + } else if (state_ == VISIBLE_BOTTOM && !bounds.IsEmpty()) {
|
| + SetState(VISIBLE_CENTERED);
|
| + original_state_ = VISIBLE_BOTTOM;
|
| + } else if (state_ != original_state_ && bounds.IsEmpty()) {
|
| + SetState(original_state_);
|
| }
|
| - layout_manager_->UpdateVirtualKeyboardBounds(bounds);
|
| }
|
|
|
| void HomeCardImpl::Init() {
|
| @@ -270,21 +314,21 @@ void HomeCardImpl::Init() {
|
| container->SetLayoutManager(layout_manager_);
|
| wm::SetChildWindowVisibilityChangesAnimated(container);
|
|
|
| - view_delegate_ = new AppListViewDelegate(model_builder_.get());
|
| + view_delegate_.reset(new AppListViewDelegate(model_builder_.get()));
|
| if (search_provider_)
|
| view_delegate_->RegisterSearchProvider(search_provider_.get());
|
| - app_list::AppListView* view = new app_list::AppListView(view_delegate_);
|
| - view->InitAsBubbleAtFixedLocation(
|
| - container,
|
| - 0 /* initial_apps_page */,
|
| - gfx::Point(),
|
| - views::BubbleBorder::FLOAT,
|
| - true /* border_accepts_events */);
|
| - home_card_widget_ = view->GetWidget();
|
| -
|
| - // Start off in the minimized state.
|
| - minimized_widget_ = CreateMinimizedHome(container, this);
|
| +
|
| + home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
|
| + home_card_widget_ = new views::Widget();
|
| + views::Widget::InitParams widget_params(
|
| + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
| + widget_params.parent = container;
|
| + widget_params.delegate = home_card_view_;
|
| + widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
|
| + home_card_widget_->Init(widget_params);
|
| +
|
| SetState(VISIBLE_MINIMIZED);
|
| + home_card_view_->Layout();
|
| }
|
|
|
| void HomeCardImpl::InstallAccelerators() {
|
|
|