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/home_card_impl.h" | 5 #include "athena/home/home_card_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "athena/env/public/athena_env.h" | 10 #include "athena/env/public/athena_env.h" |
(...skipping 10 matching lines...) Expand all Loading... |
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/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
25 #include "ui/gfx/animation/tween.h" | 25 #include "ui/gfx/animation/tween.h" |
26 #include "ui/views/layout/fill_layout.h" | 26 #include "ui/views/layout/fill_layout.h" |
27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
28 #include "ui/views/widget/widget_delegate.h" | 28 #include "ui/views/widget/widget_delegate.h" |
29 #include "ui/wm/core/shadow_types.h" | 29 #include "ui/wm/core/shadow_types.h" |
30 #include "ui/wm/core/visibility_controller.h" | 30 #include "ui/wm/core/visibility_controller.h" |
31 #include "ui/wm/public/activation_client.h" | |
32 | 31 |
33 namespace athena { | 32 namespace athena { |
34 namespace { | 33 namespace { |
35 | 34 |
36 HomeCard* instance = NULL; | 35 HomeCard* instance = NULL; |
37 | 36 |
38 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, | 37 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, |
39 HomeCard::State state) { | 38 HomeCard::State state) { |
40 switch (state) { | 39 switch (state) { |
41 case HomeCard::HIDDEN: | 40 case HomeCard::HIDDEN: |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 }; | 221 }; |
223 | 222 |
224 HomeCardImpl::HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder, | 223 HomeCardImpl::HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder, |
225 scoped_ptr<SearchControllerFactory> search_factory) | 224 scoped_ptr<SearchControllerFactory> search_factory) |
226 : model_builder_(model_builder.Pass()), | 225 : model_builder_(model_builder.Pass()), |
227 search_factory_(search_factory.Pass()), | 226 search_factory_(search_factory.Pass()), |
228 state_(HIDDEN), | 227 state_(HIDDEN), |
229 original_state_(VISIBLE_MINIMIZED), | 228 original_state_(VISIBLE_MINIMIZED), |
230 home_card_widget_(NULL), | 229 home_card_widget_(NULL), |
231 home_card_view_(NULL), | 230 home_card_view_(NULL), |
232 layout_manager_(NULL), | 231 layout_manager_(NULL) { |
233 activation_client_(NULL) { | |
234 DCHECK(!instance); | 232 DCHECK(!instance); |
235 instance = this; | 233 instance = this; |
236 WindowManager::Get()->AddObserver(this); | 234 WindowManager::Get()->AddObserver(this); |
237 } | 235 } |
238 | 236 |
239 HomeCardImpl::~HomeCardImpl() { | 237 HomeCardImpl::~HomeCardImpl() { |
240 DCHECK(instance); | 238 DCHECK(instance); |
241 WindowManager::Get()->RemoveObserver(this); | 239 WindowManager::Get()->RemoveObserver(this); |
242 if (activation_client_) | |
243 activation_client_->RemoveObserver(this); | |
244 home_card_widget_->CloseNow(); | 240 home_card_widget_->CloseNow(); |
245 | 241 |
246 // Reset the view delegate first as it access search provider during | 242 // Reset the view delegate first as it access search provider during |
247 // shutdown. | 243 // shutdown. |
248 view_delegate_.reset(); | 244 view_delegate_.reset(); |
249 instance = NULL; | 245 instance = NULL; |
250 } | 246 } |
251 | 247 |
252 void HomeCardImpl::Init() { | 248 void HomeCardImpl::Init() { |
253 InstallAccelerators(); | 249 InstallAccelerators(); |
(...skipping 18 matching lines...) Expand all Loading... |
272 home_card_widget_->Init(widget_params); | 268 home_card_widget_->Init(widget_params); |
273 | 269 |
274 minimized_home_ = CreateMinimizedHome(); | 270 minimized_home_ = CreateMinimizedHome(); |
275 container->layer()->Add(minimized_home_->layer()); | 271 container->layer()->Add(minimized_home_->layer()); |
276 container->layer()->StackAtTop(minimized_home_->layer()); | 272 container->layer()->StackAtTop(minimized_home_->layer()); |
277 layout_manager_->SetMinimizedLayer(minimized_home_->layer()); | 273 layout_manager_->SetMinimizedLayer(minimized_home_->layer()); |
278 | 274 |
279 SetState(VISIBLE_MINIMIZED); | 275 SetState(VISIBLE_MINIMIZED); |
280 home_card_view_->Layout(); | 276 home_card_view_->Layout(); |
281 | 277 |
282 activation_client_ = | |
283 aura::client::GetActivationClient(container->GetRootWindow()); | |
284 if (activation_client_) | |
285 activation_client_->AddObserver(this); | |
286 | |
287 AthenaEnv::Get()->SetDisplayWorkAreaInsets( | 278 AthenaEnv::Get()->SetDisplayWorkAreaInsets( |
288 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0)); | 279 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0)); |
289 } | 280 } |
290 | 281 |
291 aura::Window* HomeCardImpl::GetHomeCardWindowForTest() const { | 282 aura::Window* HomeCardImpl::GetHomeCardWindowForTest() const { |
292 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; | 283 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; |
293 } | 284 } |
294 | 285 |
295 void HomeCardImpl::InstallAccelerators() { | 286 void HomeCardImpl::InstallAccelerators() { |
296 const AcceleratorData accelerator_data[] = { | 287 const AcceleratorData accelerator_data[] = { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 void HomeCardImpl::OnOverviewModeExit() { | 410 void HomeCardImpl::OnOverviewModeExit() { |
420 SetState(VISIBLE_MINIMIZED); | 411 SetState(VISIBLE_MINIMIZED); |
421 } | 412 } |
422 | 413 |
423 void HomeCardImpl::OnSplitViewModeEnter() { | 414 void HomeCardImpl::OnSplitViewModeEnter() { |
424 } | 415 } |
425 | 416 |
426 void HomeCardImpl::OnSplitViewModeExit() { | 417 void HomeCardImpl::OnSplitViewModeExit() { |
427 } | 418 } |
428 | 419 |
429 void HomeCardImpl::OnWindowActivated(aura::Window* gained_active, | |
430 aura::Window* lost_active) { | |
431 if (state_ != HIDDEN && | |
432 gained_active != home_card_widget_->GetNativeWindow()) { | |
433 SetState(VISIBLE_MINIMIZED); | |
434 } | |
435 } | |
436 | |
437 // static | 420 // static |
438 HomeCard* HomeCard::Create(scoped_ptr<AppModelBuilder> model_builder, | 421 HomeCard* HomeCard::Create(scoped_ptr<AppModelBuilder> model_builder, |
439 scoped_ptr<SearchControllerFactory> search_factory) { | 422 scoped_ptr<SearchControllerFactory> search_factory) { |
440 (new HomeCardImpl(model_builder.Pass(), search_factory.Pass()))->Init(); | 423 (new HomeCardImpl(model_builder.Pass(), search_factory.Pass()))->Init(); |
441 DCHECK(instance); | 424 DCHECK(instance); |
442 return instance; | 425 return instance; |
443 } | 426 } |
444 | 427 |
445 // static | 428 // static |
446 void HomeCard::Shutdown() { | 429 void HomeCard::Shutdown() { |
447 DCHECK(instance); | 430 DCHECK(instance); |
448 delete instance; | 431 delete instance; |
449 instance = NULL; | 432 instance = NULL; |
450 } | 433 } |
451 | 434 |
452 // static | 435 // static |
453 HomeCard* HomeCard::Get() { | 436 HomeCard* HomeCard::Get() { |
454 DCHECK(instance); | 437 DCHECK(instance); |
455 return instance; | 438 return instance; |
456 } | 439 } |
457 | 440 |
458 } // namespace athena | 441 } // namespace athena |
OLD | NEW |