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

Unified Diff: athena/home/home_card_impl.cc

Issue 394043002: athena: Add a minimized state for the home-card. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: athena/home/home_card_impl.cc
diff --git a/athena/home/home_card_impl.cc b/athena/home/home_card_impl.cc
index 5edf5de4ff1fd7603c83474b232f6fe00fa962d0..843f681933fc28c048be228c1fefc4054513a66d 100644
--- a/athena/home/home_card_impl.cc
+++ b/athena/home/home_card_impl.cc
@@ -5,13 +5,18 @@
#include "athena/home/public/home_card.h"
#include "athena/home/app_list_view_delegate.h"
+#include "athena/home/minimized_home.h"
#include "athena/home/public/app_model_builder.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/public/screen_manager.h"
+#include "athena/wm/public/window_manager.h"
+#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/aura/layout_manager.h"
#include "ui/aura/window.h"
+#include "ui/views/layout/box_layout.h"
#include "ui/wm/core/visibility_controller.h"
#include "ui/wm/core/window_animations.h"
@@ -20,10 +25,25 @@ namespace {
HomeCard* instance = NULL;
+// Makes sure the homecard is center-aligned horizontally and bottom-aligned
+// vertically.
class HomeCardLayoutManager : public aura::LayoutManager {
public:
- explicit HomeCardLayoutManager(aura::Window* container)
- : container_(container) {}
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ virtual int GetHomeCardHeight() const = 0;
+
+ 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;
+ };
+
+ HomeCardLayoutManager(Delegate* delegate, aura::Window* container)
+ : delegate_(delegate), container_(container) {}
virtual ~HomeCardLayoutManager() {}
void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) {
@@ -49,37 +69,44 @@ class HomeCardLayoutManager : public aura::LayoutManager {
}
void Layout() {
- const int kHomeCardHeight = 150;
- const int kHomeCardHorizontalMargin = 50;
- // 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;
+ int height = delegate_->GetHomeCardHeight();
+ int horiz_margin = delegate_->GetHorizontalMargin();
if (container_->children().size() < 1)
return;
- aura::Window* home_card = container_->children()[0];
- if (!home_card->IsVisible())
+
+ aura::Window* home_card = instance->GetNativeWindow();
+ if (!home_card)
return;
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(kHomeCardHorizontalMargin,
- screen_bounds.height() - kHomeCardHeight,
- kHomeCardHorizontalMargin,
- 0);
- card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth);
+ card_bounds.Inset(horiz_margin, screen_bounds.height() - height,
+ horiz_margin, 0);
+
+ 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);
+ }
SetChildBoundsDirect(home_card, card_bounds);
}
+ Delegate* delegate_;
aura::Window* container_;
oshima 2014/07/16 19:10:38 I believe you can remove this.
sadrul 2014/07/16 19:32:58 Yep. cool. done.
gfx::Rect virtual_keyboard_bounds_;
DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
};
-class HomeCardImpl : public HomeCard, public AcceleratorHandler {
+class HomeCardImpl : public HomeCard,
+ public AcceleratorHandler,
+ public HomeCardLayoutManager::Delegate,
+ public MinimizedHomeDragDelegate,
+ public WindowManagerObserver {
public:
explicit HomeCardImpl(AppModelBuilder* model_builder);
virtual ~HomeCardImpl();
@@ -98,6 +125,7 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
app_list::SearchProvider* search_provider) OVERRIDE;
virtual void UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) OVERRIDE;
+ virtual aura::Window* GetNativeWindow() OVERRIDE;
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; }
@@ -111,11 +139,46 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
return true;
}
+ // HomeCardLayoutManager::Delegate:
+ virtual int GetHomeCardHeight() const OVERRIDE {
+ const int kHomeCardHeight = 150;
+ const int kHomeCardMinimizedHeight = 8;
+ CHECK_NE(HIDDEN, state_);
+ return state_ == VISIBLE_MINIMIZED ? kHomeCardMinimizedHeight :
+ kHomeCardHeight;
+ }
+
+ 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;
+ }
+
+ // MinimizedHomeDragDelegate:
+ virtual void OnDragUpCompleted() OVERRIDE {
+ WindowManager::GetInstance()->ToggleOverview();
+ }
+
+ // WindowManagerObserver:
+ virtual void OnOverviewModeEnter() OVERRIDE {
+ SetState(VISIBLE_BOTTOM);
+ }
+
+ virtual void OnOverviewModeExit() OVERRIDE {
+ SetState(VISIBLE_MINIMIZED);
+ }
+
scoped_ptr<AppModelBuilder> model_builder_;
HomeCard::State state_;
views::Widget* home_card_widget_;
+ views::Widget* minimized_widget_;
AppListViewDelegate* view_delegate_;
HomeCardLayoutManager* layout_manager_;
@@ -128,26 +191,43 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
: model_builder_(model_builder),
- state_(HIDDEN),
+ state_(VISIBLE_MINIMIZED),
home_card_widget_(NULL),
+ minimized_widget_(NULL),
layout_manager_(NULL) {
DCHECK(!instance);
instance = this;
+ WindowManager::GetInstance()->AddObserver(this);
}
HomeCardImpl::~HomeCardImpl() {
DCHECK(instance);
+ WindowManager::GetInstance()->RemoveObserver(this);
home_card_widget_->CloseNow();
+ minimized_widget_->CloseNow();
view_delegate_ = NULL;
instance = NULL;
}
void HomeCardImpl::SetState(HomeCard::State state) {
- if (state == HIDDEN)
- home_card_widget_->Hide();
- else
- home_card_widget_->Show();
+ // 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;
+ }
}
void HomeCardImpl::RegisterSearchProvider(
@@ -159,15 +239,33 @@ void HomeCardImpl::RegisterSearchProvider(
void HomeCardImpl::UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) {
+ if (state_ == VISIBLE_MINIMIZED) {
+ if (bounds.IsEmpty())
+ minimized_widget_->Show();
+ else
+ minimized_widget_->Hide();
+ }
layout_manager_->UpdateVirtualKeyboardBounds(bounds);
}
+aura::Window* HomeCardImpl::GetNativeWindow() {
+ 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;
+ }
+}
+
void HomeCardImpl::Init() {
InstallAccelerators();
aura::Window* container =
ScreenManager::Get()->CreateContainer("HomeCardContainer");
- layout_manager_ = new HomeCardLayoutManager(container);
+ layout_manager_ = new HomeCardLayoutManager(this, container);
container->SetLayoutManager(layout_manager_);
wm::SetChildWindowVisibilityChangesAnimated(container);
@@ -182,9 +280,10 @@ void HomeCardImpl::Init() {
views::BubbleBorder::FLOAT,
true /* border_accepts_events */);
home_card_widget_ = view->GetWidget();
- // TODO: the initial value might not be visible.
- state_ = VISIBLE_CENTERED;
- view->ShowWhenReady();
+
+ // Start off in the minimized state.
+ minimized_widget_ = CreateMinimizedHome(container, this);
+ SetState(VISIBLE_MINIMIZED);
}
void HomeCardImpl::InstallAccelerators() {
« no previous file with comments | « athena/home/DEPS ('k') | athena/home/minimized_home.h » ('j') | athena/home/public/home_card.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698