| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "athena/home/app_list_view_delegate.h" | 9 #include "athena/home/app_list_view_delegate.h" |
| 10 #include "athena/home/bottom_home_view.h" | 10 #include "athena/home/bottom_home_view.h" |
| 11 #include "athena/home/minimized_home.h" | 11 #include "athena/home/minimized_home.h" |
| 12 #include "athena/home/public/app_model_builder.h" | 12 #include "athena/home/public/app_model_builder.h" |
| 13 #include "athena/input/public/accelerator_manager.h" | 13 #include "athena/input/public/accelerator_manager.h" |
| 14 #include "athena/screen/public/screen_manager.h" | 14 #include "athena/screen/public/screen_manager.h" |
| 15 #include "athena/wm/public/window_manager.h" | 15 #include "athena/wm/public/window_manager.h" |
| 16 #include "athena/wm/public/window_manager_observer.h" | 16 #include "athena/wm/public/window_manager_observer.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "ui/app_list/search_provider.h" | 18 #include "ui/app_list/search_provider.h" |
| 19 #include "ui/app_list/views/app_list_main_view.h" | 19 #include "ui/app_list/views/app_list_main_view.h" |
| 20 #include "ui/app_list/views/contents_view.h" | 20 #include "ui/app_list/views/contents_view.h" |
| 21 #include "ui/aura/layout_manager.h" | 21 #include "ui/aura/layout_manager.h" |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/views/background.h" | 23 #include "ui/views/background.h" |
| 24 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 26 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
| 27 #include "ui/wm/core/visibility_controller.h" | 27 #include "ui/wm/core/visibility_controller.h" |
| 28 #include "ui/wm/core/window_animations.h" | 28 #include "ui/wm/core/window_animations.h" |
| 29 #include "ui/wm/public/activation_change_observer.h" |
| 30 #include "ui/wm/public/activation_client.h" |
| 29 | 31 |
| 30 namespace athena { | 32 namespace athena { |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 HomeCard* instance = NULL; | 35 HomeCard* instance = NULL; |
| 34 | 36 |
| 35 // Makes sure the homecard is center-aligned horizontally and bottom-aligned | 37 // Makes sure the homecard is center-aligned horizontally and bottom-aligned |
| 36 // vertically. | 38 // vertically. |
| 37 class HomeCardLayoutManager : public aura::LayoutManager { | 39 class HomeCardLayoutManager : public aura::LayoutManager { |
| 38 public: | 40 public: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 BottomHomeView* bottom_view_; | 148 BottomHomeView* bottom_view_; |
| 147 views::View* minimized_view_; | 149 views::View* minimized_view_; |
| 148 | 150 |
| 149 DISALLOW_COPY_AND_ASSIGN(HomeCardView); | 151 DISALLOW_COPY_AND_ASSIGN(HomeCardView); |
| 150 }; | 152 }; |
| 151 | 153 |
| 152 class HomeCardImpl : public HomeCard, | 154 class HomeCardImpl : public HomeCard, |
| 153 public AcceleratorHandler, | 155 public AcceleratorHandler, |
| 154 public HomeCardLayoutManager::Delegate, | 156 public HomeCardLayoutManager::Delegate, |
| 155 public MinimizedHomeDragDelegate, | 157 public MinimizedHomeDragDelegate, |
| 156 public WindowManagerObserver { | 158 public WindowManagerObserver, |
| 159 public aura::client::ActivationChangeObserver { |
| 157 public: | 160 public: |
| 158 explicit HomeCardImpl(AppModelBuilder* model_builder); | 161 explicit HomeCardImpl(AppModelBuilder* model_builder); |
| 159 virtual ~HomeCardImpl(); | 162 virtual ~HomeCardImpl(); |
| 160 | 163 |
| 161 void Init(); | 164 void Init(); |
| 162 | 165 |
| 163 private: | 166 private: |
| 164 enum Command { | 167 enum Command { |
| 165 COMMAND_SHOW_HOME_CARD, | 168 COMMAND_SHOW_HOME_CARD, |
| 166 }; | 169 }; |
| 167 void InstallAccelerators(); | 170 void InstallAccelerators(); |
| 168 | 171 |
| 169 // Overridden from HomeCard: | 172 // Overridden from HomeCard: |
| 170 virtual void SetState(State state) OVERRIDE; | 173 virtual void SetState(State state) OVERRIDE; |
| 174 virtual State GetState() OVERRIDE; |
| 171 virtual void RegisterSearchProvider( | 175 virtual void RegisterSearchProvider( |
| 172 app_list::SearchProvider* search_provider) OVERRIDE; | 176 app_list::SearchProvider* search_provider) OVERRIDE; |
| 173 virtual void UpdateVirtualKeyboardBounds( | 177 virtual void UpdateVirtualKeyboardBounds( |
| 174 const gfx::Rect& bounds) OVERRIDE; | 178 const gfx::Rect& bounds) OVERRIDE; |
| 175 | 179 |
| 176 // AcceleratorHandler: | 180 // AcceleratorHandler: |
| 177 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | 181 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
| 178 virtual bool OnAcceleratorFired(int command_id, | 182 virtual bool OnAcceleratorFired(int command_id, |
| 179 const ui::Accelerator& accelerator) OVERRIDE { | 183 const ui::Accelerator& accelerator) OVERRIDE { |
| 180 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 184 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 229 |
| 226 // WindowManagerObserver: | 230 // WindowManagerObserver: |
| 227 virtual void OnOverviewModeEnter() OVERRIDE { | 231 virtual void OnOverviewModeEnter() OVERRIDE { |
| 228 SetState(VISIBLE_BOTTOM); | 232 SetState(VISIBLE_BOTTOM); |
| 229 } | 233 } |
| 230 | 234 |
| 231 virtual void OnOverviewModeExit() OVERRIDE { | 235 virtual void OnOverviewModeExit() OVERRIDE { |
| 232 SetState(VISIBLE_MINIMIZED); | 236 SetState(VISIBLE_MINIMIZED); |
| 233 } | 237 } |
| 234 | 238 |
| 239 // aura::client::ActivationChangeObserver: |
| 240 virtual void OnWindowActivated(aura::Window* gained_active, |
| 241 aura::Window* lost_active) OVERRIDE { |
| 242 if (gained_active != home_card_widget_->GetNativeWindow()) |
| 243 SetState(VISIBLE_MINIMIZED); |
| 244 } |
| 245 |
| 235 scoped_ptr<AppModelBuilder> model_builder_; | 246 scoped_ptr<AppModelBuilder> model_builder_; |
| 236 | 247 |
| 237 HomeCard::State state_; | 248 HomeCard::State state_; |
| 238 | 249 |
| 239 // original_state_ is the state which the home card should go back to after | 250 // original_state_ is the state which the home card should go back to after |
| 240 // the virtual keyboard is hidden. | 251 // the virtual keyboard is hidden. |
| 241 HomeCard::State original_state_; | 252 HomeCard::State original_state_; |
| 242 | 253 |
| 243 views::Widget* home_card_widget_; | 254 views::Widget* home_card_widget_; |
| 244 HomeCardView* home_card_view_; | 255 HomeCardView* home_card_view_; |
| 245 scoped_ptr<AppListViewDelegate> view_delegate_; | 256 scoped_ptr<AppListViewDelegate> view_delegate_; |
| 246 HomeCardLayoutManager* layout_manager_; | 257 HomeCardLayoutManager* layout_manager_; |
| 258 aura::client::ActivationClient* activation_client_; // Not owned |
| 247 | 259 |
| 248 // Right now HomeCard allows only one search provider. | 260 // Right now HomeCard allows only one search provider. |
| 249 // TODO(mukai): port app-list's SearchController and Mixer. | 261 // TODO(mukai): port app-list's SearchController and Mixer. |
| 250 scoped_ptr<app_list::SearchProvider> search_provider_; | 262 scoped_ptr<app_list::SearchProvider> search_provider_; |
| 251 | 263 |
| 252 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 264 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
| 253 }; | 265 }; |
| 254 | 266 |
| 255 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) | 267 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) |
| 256 : model_builder_(model_builder), | 268 : model_builder_(model_builder), |
| 257 state_(VISIBLE_MINIMIZED), | 269 state_(HIDDEN), |
| 258 original_state_(VISIBLE_MINIMIZED), | 270 original_state_(VISIBLE_MINIMIZED), |
| 259 home_card_widget_(NULL), | 271 home_card_widget_(NULL), |
| 260 home_card_view_(NULL), | 272 home_card_view_(NULL), |
| 261 layout_manager_(NULL) { | 273 layout_manager_(NULL), |
| 274 activation_client_(NULL) { |
| 262 DCHECK(!instance); | 275 DCHECK(!instance); |
| 263 instance = this; | 276 instance = this; |
| 264 WindowManager::GetInstance()->AddObserver(this); | 277 WindowManager::GetInstance()->AddObserver(this); |
| 265 } | 278 } |
| 266 | 279 |
| 267 HomeCardImpl::~HomeCardImpl() { | 280 HomeCardImpl::~HomeCardImpl() { |
| 268 DCHECK(instance); | 281 DCHECK(instance); |
| 269 WindowManager::GetInstance()->RemoveObserver(this); | 282 WindowManager::GetInstance()->RemoveObserver(this); |
| 283 if (activation_client_) |
| 284 activation_client_->RemoveObserver(this); |
| 270 home_card_widget_->CloseNow(); | 285 home_card_widget_->CloseNow(); |
| 271 instance = NULL; | 286 instance = NULL; |
| 272 } | 287 } |
| 273 | 288 |
| 274 void HomeCardImpl::SetState(HomeCard::State state) { | 289 void HomeCardImpl::SetState(HomeCard::State state) { |
| 290 if (state_ == state) |
| 291 return; |
| 292 |
| 275 // Update |state_| before changing the visibility of the widgets, so that | 293 // Update |state_| before changing the visibility of the widgets, so that |
| 276 // LayoutManager callbacks get the correct state. | 294 // LayoutManager callbacks get the correct state. |
| 277 state_ = state; | 295 state_ = state; |
| 278 original_state_ = state; | 296 original_state_ = state; |
| 279 if (state_ == HIDDEN) { | 297 if (state_ == HIDDEN) { |
| 280 home_card_widget_->Hide(); | 298 home_card_widget_->Hide(); |
| 281 } else { | 299 } else { |
| 282 home_card_widget_->Show(); | 300 home_card_widget_->Show(); |
| 283 home_card_view_->SetState(state); | 301 home_card_view_->SetState(state); |
| 284 layout_manager_->Layout(); | 302 layout_manager_->Layout(); |
| 285 } | 303 } |
| 286 } | 304 } |
| 287 | 305 |
| 306 HomeCard::State HomeCardImpl::GetState() { |
| 307 return state_; |
| 308 } |
| 309 |
| 288 void HomeCardImpl::RegisterSearchProvider( | 310 void HomeCardImpl::RegisterSearchProvider( |
| 289 app_list::SearchProvider* search_provider) { | 311 app_list::SearchProvider* search_provider) { |
| 290 DCHECK(!search_provider_); | 312 DCHECK(!search_provider_); |
| 291 search_provider_.reset(search_provider); | 313 search_provider_.reset(search_provider); |
| 292 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 314 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
| 293 } | 315 } |
| 294 | 316 |
| 295 void HomeCardImpl::UpdateVirtualKeyboardBounds( | 317 void HomeCardImpl::UpdateVirtualKeyboardBounds( |
| 296 const gfx::Rect& bounds) { | 318 const gfx::Rect& bounds) { |
| 297 if (state_ == VISIBLE_MINIMIZED && !bounds.IsEmpty()) { | 319 if (state_ == VISIBLE_MINIMIZED && !bounds.IsEmpty()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 323 home_card_widget_ = new views::Widget(); | 345 home_card_widget_ = new views::Widget(); |
| 324 views::Widget::InitParams widget_params( | 346 views::Widget::InitParams widget_params( |
| 325 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 347 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 326 widget_params.parent = container; | 348 widget_params.parent = container; |
| 327 widget_params.delegate = home_card_view_; | 349 widget_params.delegate = home_card_view_; |
| 328 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 350 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 329 home_card_widget_->Init(widget_params); | 351 home_card_widget_->Init(widget_params); |
| 330 | 352 |
| 331 SetState(VISIBLE_MINIMIZED); | 353 SetState(VISIBLE_MINIMIZED); |
| 332 home_card_view_->Layout(); | 354 home_card_view_->Layout(); |
| 355 |
| 356 activation_client_ = |
| 357 aura::client::GetActivationClient(container->GetRootWindow()); |
| 358 if (activation_client_) |
| 359 activation_client_->AddObserver(this); |
| 333 } | 360 } |
| 334 | 361 |
| 335 void HomeCardImpl::InstallAccelerators() { | 362 void HomeCardImpl::InstallAccelerators() { |
| 336 const AcceleratorData accelerator_data[] = { | 363 const AcceleratorData accelerator_data[] = { |
| 337 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 364 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
| 338 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 365 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
| 339 }; | 366 }; |
| 340 AcceleratorManager::Get()->RegisterAccelerators( | 367 AcceleratorManager::Get()->RegisterAccelerators( |
| 341 accelerator_data, arraysize(accelerator_data), this); | 368 accelerator_data, arraysize(accelerator_data), this); |
| 342 } | 369 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 357 instance = NULL; | 384 instance = NULL; |
| 358 } | 385 } |
| 359 | 386 |
| 360 // static | 387 // static |
| 361 HomeCard* HomeCard::Get() { | 388 HomeCard* HomeCard::Get() { |
| 362 DCHECK(instance); | 389 DCHECK(instance); |
| 363 return instance; | 390 return instance; |
| 364 } | 391 } |
| 365 | 392 |
| 366 } // namespace athena | 393 } // namespace athena |
| OLD | NEW |