| OLD | NEW |
| 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 "athena/home/app_list_view_delegate.h" | 7 #include "athena/home/app_list_view_delegate.h" |
| 8 #include "athena/home/minimized_home.h" | |
| 9 #include "athena/home/public/app_model_builder.h" | 8 #include "athena/home/public/app_model_builder.h" |
| 10 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
| 11 #include "athena/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
| 12 #include "athena/wm/public/window_manager.h" | |
| 13 #include "athena/wm/public/window_manager_observer.h" | |
| 14 #include "base/bind.h" | |
| 15 #include "ui/app_list/search_provider.h" | 11 #include "ui/app_list/search_provider.h" |
| 16 #include "ui/app_list/views/app_list_view.h" | 12 #include "ui/app_list/views/app_list_view.h" |
| 17 #include "ui/aura/layout_manager.h" | 13 #include "ui/aura/layout_manager.h" |
| 18 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 19 #include "ui/views/layout/box_layout.h" | |
| 20 #include "ui/wm/core/visibility_controller.h" | 15 #include "ui/wm/core/visibility_controller.h" |
| 21 #include "ui/wm/core/window_animations.h" | 16 #include "ui/wm/core/window_animations.h" |
| 22 | 17 |
| 23 namespace athena { | 18 namespace athena { |
| 24 namespace { | 19 namespace { |
| 25 | 20 |
| 26 HomeCard* instance = NULL; | 21 HomeCard* instance = NULL; |
| 27 | 22 |
| 28 // Makes sure the homecard is center-aligned horizontally and bottom-aligned | |
| 29 // vertically. | |
| 30 class HomeCardLayoutManager : public aura::LayoutManager { | 23 class HomeCardLayoutManager : public aura::LayoutManager { |
| 31 public: | 24 public: |
| 32 class Delegate { | 25 explicit HomeCardLayoutManager(aura::Window* container) |
| 33 public: | 26 : container_(container) {} |
| 34 virtual ~Delegate() {} | |
| 35 | |
| 36 virtual int GetHomeCardHeight() const = 0; | |
| 37 | |
| 38 virtual int GetHorizontalMargin() const = 0; | |
| 39 | |
| 40 // TODO(mukai): Remove this when bubble is no longer used for | |
| 41 // VISIBLE_CENTERED or VISIBLE_BOTTOM states. | |
| 42 virtual bool HasShadow() const = 0; | |
| 43 | |
| 44 virtual aura::Window* GetNativeWindow() = 0; | |
| 45 }; | |
| 46 | |
| 47 explicit HomeCardLayoutManager(Delegate* delegate) | |
| 48 : delegate_(delegate) {} | |
| 49 virtual ~HomeCardLayoutManager() {} | 27 virtual ~HomeCardLayoutManager() {} |
| 50 | 28 |
| 51 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { | 29 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { |
| 52 virtual_keyboard_bounds_ = bounds; | 30 virtual_keyboard_bounds_ = bounds; |
| 53 Layout(); | 31 Layout(); |
| 54 } | 32 } |
| 55 | 33 |
| 56 private: | 34 private: |
| 57 // aura::LayoutManager: | 35 // aura::LayoutManager: |
| 58 virtual void OnWindowResized() OVERRIDE { Layout(); } | 36 virtual void OnWindowResized() OVERRIDE { Layout(); } |
| 59 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } | 37 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } |
| 60 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | 38 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 61 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | 39 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
| 62 Layout(); | 40 Layout(); |
| 63 } | 41 } |
| 64 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 42 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 65 bool visible) OVERRIDE { | 43 bool visible) OVERRIDE { |
| 66 Layout(); | 44 Layout(); |
| 67 } | 45 } |
| 68 virtual void SetChildBounds(aura::Window* child, | 46 virtual void SetChildBounds(aura::Window* child, |
| 69 const gfx::Rect& requested_bounds) OVERRIDE { | 47 const gfx::Rect& requested_bounds) OVERRIDE { |
| 70 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); | 48 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
| 71 } | 49 } |
| 72 | 50 |
| 73 void Layout() { | 51 void Layout() { |
| 74 int height = delegate_->GetHomeCardHeight(); | 52 const int kHomeCardHeight = 150; |
| 75 int horiz_margin = delegate_->GetHorizontalMargin(); | 53 const int kHomeCardHorizontalMargin = 50; |
| 76 aura::Window* home_card = delegate_->GetNativeWindow(); | 54 // Currently the home card is provided as a bubble and the bounds has to be |
| 77 if (!home_card) | 55 // increased to cancel the shadow. |
| 56 // TODO(mukai): stops using the bubble and remove this. |
| 57 const int kHomeCardShadowWidth = 30; |
| 58 if (container_->children().size() < 1) |
| 59 return; |
| 60 aura::Window* home_card = container_->children()[0]; |
| 61 if (!home_card->IsVisible()) |
| 78 return; | 62 return; |
| 79 | 63 |
| 80 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); | 64 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); |
| 81 if (!virtual_keyboard_bounds_.IsEmpty()) | 65 if (!virtual_keyboard_bounds_.IsEmpty()) |
| 82 screen_bounds.set_height(virtual_keyboard_bounds_.y()); | 66 screen_bounds.set_height(virtual_keyboard_bounds_.y()); |
| 83 gfx::Rect card_bounds = screen_bounds; | 67 gfx::Rect card_bounds = screen_bounds; |
| 84 card_bounds.Inset(horiz_margin, screen_bounds.height() - height, | 68 card_bounds.Inset(kHomeCardHorizontalMargin, |
| 85 horiz_margin, 0); | 69 screen_bounds.height() - kHomeCardHeight, |
| 86 | 70 kHomeCardHorizontalMargin, |
| 87 if (delegate_->HasShadow()) { | 71 0); |
| 88 // Currently the home card is provided as a bubble and the bounds has to | 72 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); |
| 89 // be increased to cancel the shadow. | |
| 90 // TODO(mukai): stops using the bubble and remove this. | |
| 91 const int kHomeCardShadowWidth = 30; | |
| 92 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | |
| 93 } | |
| 94 SetChildBoundsDirect(home_card, card_bounds); | 73 SetChildBoundsDirect(home_card, card_bounds); |
| 95 } | 74 } |
| 96 | 75 |
| 97 Delegate* delegate_; | 76 aura::Window* container_; |
| 98 gfx::Rect virtual_keyboard_bounds_; | 77 gfx::Rect virtual_keyboard_bounds_; |
| 99 | 78 |
| 100 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 79 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
| 101 }; | 80 }; |
| 102 | 81 |
| 103 class HomeCardImpl : public HomeCard, | 82 class HomeCardImpl : public HomeCard, public AcceleratorHandler { |
| 104 public AcceleratorHandler, | |
| 105 public HomeCardLayoutManager::Delegate, | |
| 106 public MinimizedHomeDragDelegate, | |
| 107 public WindowManagerObserver { | |
| 108 public: | 83 public: |
| 109 explicit HomeCardImpl(AppModelBuilder* model_builder); | 84 explicit HomeCardImpl(AppModelBuilder* model_builder); |
| 110 virtual ~HomeCardImpl(); | 85 virtual ~HomeCardImpl(); |
| 111 | 86 |
| 112 void Init(); | 87 void Init(); |
| 113 | 88 |
| 114 private: | 89 private: |
| 115 enum Command { | 90 enum Command { |
| 116 COMMAND_SHOW_HOME_CARD, | 91 COMMAND_SHOW_HOME_CARD, |
| 117 }; | 92 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 virtual bool OnAcceleratorFired(int command_id, | 104 virtual bool OnAcceleratorFired(int command_id, |
| 130 const ui::Accelerator& accelerator) OVERRIDE { | 105 const ui::Accelerator& accelerator) OVERRIDE { |
| 131 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 106 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
| 132 if (state_ == HIDDEN) | 107 if (state_ == HIDDEN) |
| 133 SetState(VISIBLE_CENTERED); | 108 SetState(VISIBLE_CENTERED); |
| 134 else | 109 else |
| 135 SetState(HIDDEN); | 110 SetState(HIDDEN); |
| 136 return true; | 111 return true; |
| 137 } | 112 } |
| 138 | 113 |
| 139 // HomeCardLayoutManager::Delegate: | |
| 140 virtual int GetHomeCardHeight() const OVERRIDE { | |
| 141 const int kHomeCardHeight = 150; | |
| 142 const int kHomeCardMinimizedHeight = 8; | |
| 143 CHECK_NE(HIDDEN, state_); | |
| 144 return state_ == VISIBLE_MINIMIZED ? kHomeCardMinimizedHeight : | |
| 145 kHomeCardHeight; | |
| 146 } | |
| 147 | |
| 148 virtual int GetHorizontalMargin() const OVERRIDE { | |
| 149 CHECK_NE(HIDDEN, state_); | |
| 150 const int kHomeCardHorizontalMargin = 50; | |
| 151 return state_ == VISIBLE_MINIMIZED ? 0 : kHomeCardHorizontalMargin; | |
| 152 } | |
| 153 | |
| 154 virtual bool HasShadow() const OVERRIDE { | |
| 155 CHECK_NE(HIDDEN, state_); | |
| 156 return state_ != VISIBLE_MINIMIZED; | |
| 157 } | |
| 158 | |
| 159 virtual aura::Window* GetNativeWindow() OVERRIDE { | |
| 160 switch (state_) { | |
| 161 case HIDDEN: | |
| 162 return NULL; | |
| 163 case VISIBLE_MINIMIZED: | |
| 164 return minimized_widget_ ? minimized_widget_->GetNativeWindow() : NULL; | |
| 165 case VISIBLE_CENTERED: | |
| 166 case VISIBLE_BOTTOM: | |
| 167 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; | |
| 168 } | |
| 169 return NULL; | |
| 170 } | |
| 171 | |
| 172 // MinimizedHomeDragDelegate: | |
| 173 virtual void OnDragUpCompleted() OVERRIDE { | |
| 174 WindowManager::GetInstance()->ToggleOverview(); | |
| 175 } | |
| 176 | |
| 177 // WindowManagerObserver: | |
| 178 virtual void OnOverviewModeEnter() OVERRIDE { | |
| 179 SetState(VISIBLE_BOTTOM); | |
| 180 } | |
| 181 | |
| 182 virtual void OnOverviewModeExit() OVERRIDE { | |
| 183 SetState(VISIBLE_MINIMIZED); | |
| 184 } | |
| 185 | |
| 186 scoped_ptr<AppModelBuilder> model_builder_; | 114 scoped_ptr<AppModelBuilder> model_builder_; |
| 187 | 115 |
| 188 HomeCard::State state_; | 116 HomeCard::State state_; |
| 189 | 117 |
| 190 views::Widget* home_card_widget_; | 118 views::Widget* home_card_widget_; |
| 191 views::Widget* minimized_widget_; | |
| 192 AppListViewDelegate* view_delegate_; | 119 AppListViewDelegate* view_delegate_; |
| 193 HomeCardLayoutManager* layout_manager_; | 120 HomeCardLayoutManager* layout_manager_; |
| 194 | 121 |
| 195 // Right now HomeCard allows only one search provider. | 122 // Right now HomeCard allows only one search provider. |
| 196 // TODO(mukai): port app-list's SearchController and Mixer. | 123 // TODO(mukai): port app-list's SearchController and Mixer. |
| 197 scoped_ptr<app_list::SearchProvider> search_provider_; | 124 scoped_ptr<app_list::SearchProvider> search_provider_; |
| 198 | 125 |
| 199 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 126 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
| 200 }; | 127 }; |
| 201 | 128 |
| 202 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) | 129 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) |
| 203 : model_builder_(model_builder), | 130 : model_builder_(model_builder), |
| 204 state_(VISIBLE_MINIMIZED), | 131 state_(HIDDEN), |
| 205 home_card_widget_(NULL), | 132 home_card_widget_(NULL), |
| 206 minimized_widget_(NULL), | |
| 207 layout_manager_(NULL) { | 133 layout_manager_(NULL) { |
| 208 DCHECK(!instance); | 134 DCHECK(!instance); |
| 209 instance = this; | 135 instance = this; |
| 210 WindowManager::GetInstance()->AddObserver(this); | |
| 211 } | 136 } |
| 212 | 137 |
| 213 HomeCardImpl::~HomeCardImpl() { | 138 HomeCardImpl::~HomeCardImpl() { |
| 214 DCHECK(instance); | 139 DCHECK(instance); |
| 215 WindowManager::GetInstance()->RemoveObserver(this); | |
| 216 home_card_widget_->CloseNow(); | 140 home_card_widget_->CloseNow(); |
| 217 minimized_widget_->CloseNow(); | |
| 218 view_delegate_ = NULL; | 141 view_delegate_ = NULL; |
| 219 instance = NULL; | 142 instance = NULL; |
| 220 } | 143 } |
| 221 | 144 |
| 222 void HomeCardImpl::SetState(HomeCard::State state) { | 145 void HomeCardImpl::SetState(HomeCard::State state) { |
| 223 // Update |state_| before changing the visibility of the widgets, so that | 146 if (state == HIDDEN) |
| 224 // LayoutManager callbacks get the correct state. | 147 home_card_widget_->Hide(); |
| 148 else |
| 149 home_card_widget_->Show(); |
| 225 state_ = state; | 150 state_ = state; |
| 226 switch (state_) { | |
| 227 case VISIBLE_MINIMIZED: | |
| 228 home_card_widget_->Hide(); | |
| 229 minimized_widget_->Show(); | |
| 230 break; | |
| 231 case HIDDEN: | |
| 232 home_card_widget_->Hide(); | |
| 233 minimized_widget_->Hide(); | |
| 234 break; | |
| 235 case VISIBLE_BOTTOM: | |
| 236 case VISIBLE_CENTERED: | |
| 237 home_card_widget_->Show(); | |
| 238 minimized_widget_->Hide(); | |
| 239 break; | |
| 240 } | |
| 241 } | 151 } |
| 242 | 152 |
| 243 void HomeCardImpl::RegisterSearchProvider( | 153 void HomeCardImpl::RegisterSearchProvider( |
| 244 app_list::SearchProvider* search_provider) { | 154 app_list::SearchProvider* search_provider) { |
| 245 DCHECK(!search_provider_); | 155 DCHECK(!search_provider_); |
| 246 search_provider_.reset(search_provider); | 156 search_provider_.reset(search_provider); |
| 247 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 157 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
| 248 } | 158 } |
| 249 | 159 |
| 250 void HomeCardImpl::UpdateVirtualKeyboardBounds( | 160 void HomeCardImpl::UpdateVirtualKeyboardBounds( |
| 251 const gfx::Rect& bounds) { | 161 const gfx::Rect& bounds) { |
| 252 if (state_ == VISIBLE_MINIMIZED) { | |
| 253 if (bounds.IsEmpty()) | |
| 254 minimized_widget_->Show(); | |
| 255 else | |
| 256 minimized_widget_->Hide(); | |
| 257 } | |
| 258 layout_manager_->UpdateVirtualKeyboardBounds(bounds); | 162 layout_manager_->UpdateVirtualKeyboardBounds(bounds); |
| 259 } | 163 } |
| 260 | 164 |
| 261 void HomeCardImpl::Init() { | 165 void HomeCardImpl::Init() { |
| 262 InstallAccelerators(); | 166 InstallAccelerators(); |
| 263 | 167 |
| 264 aura::Window* container = | 168 aura::Window* container = |
| 265 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 169 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
| 266 layout_manager_ = new HomeCardLayoutManager(this); | 170 layout_manager_ = new HomeCardLayoutManager(container); |
| 267 container->SetLayoutManager(layout_manager_); | 171 container->SetLayoutManager(layout_manager_); |
| 268 wm::SetChildWindowVisibilityChangesAnimated(container); | 172 wm::SetChildWindowVisibilityChangesAnimated(container); |
| 269 | 173 |
| 270 view_delegate_ = new AppListViewDelegate(model_builder_.get()); | 174 view_delegate_ = new AppListViewDelegate(model_builder_.get()); |
| 271 if (search_provider_) | 175 if (search_provider_) |
| 272 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 176 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
| 273 app_list::AppListView* view = new app_list::AppListView(view_delegate_); | 177 app_list::AppListView* view = new app_list::AppListView(view_delegate_); |
| 274 view->InitAsBubbleAtFixedLocation( | 178 view->InitAsBubbleAtFixedLocation( |
| 275 container, | 179 container, |
| 276 0 /* initial_apps_page */, | 180 0 /* initial_apps_page */, |
| 277 gfx::Point(), | 181 gfx::Point(), |
| 278 views::BubbleBorder::FLOAT, | 182 views::BubbleBorder::FLOAT, |
| 279 true /* border_accepts_events */); | 183 true /* border_accepts_events */); |
| 280 home_card_widget_ = view->GetWidget(); | 184 home_card_widget_ = view->GetWidget(); |
| 281 | 185 // TODO: the initial value might not be visible. |
| 282 // Start off in the minimized state. | 186 state_ = VISIBLE_CENTERED; |
| 283 minimized_widget_ = CreateMinimizedHome(container, this); | 187 view->ShowWhenReady(); |
| 284 SetState(VISIBLE_MINIMIZED); | |
| 285 } | 188 } |
| 286 | 189 |
| 287 void HomeCardImpl::InstallAccelerators() { | 190 void HomeCardImpl::InstallAccelerators() { |
| 288 const AcceleratorData accelerator_data[] = { | 191 const AcceleratorData accelerator_data[] = { |
| 289 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 192 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
| 290 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 193 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
| 291 }; | 194 }; |
| 292 AcceleratorManager::Get()->RegisterAccelerators( | 195 AcceleratorManager::Get()->RegisterAccelerators( |
| 293 accelerator_data, arraysize(accelerator_data), this); | 196 accelerator_data, arraysize(accelerator_data), this); |
| 294 } | 197 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 309 instance = NULL; | 212 instance = NULL; |
| 310 } | 213 } |
| 311 | 214 |
| 312 // static | 215 // static |
| 313 HomeCard* HomeCard::Get() { | 216 HomeCard* HomeCard::Get() { |
| 314 DCHECK(instance); | 217 DCHECK(instance); |
| 315 return instance; | 218 return instance; |
| 316 } | 219 } |
| 317 | 220 |
| 318 } // namespace athena | 221 } // namespace athena |
| OLD | NEW |