OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "athena/home/public/home_card.h" |
| 6 |
| 7 #include "athena/home/home_card_delegate_view.h" |
| 8 #include "athena/screen/public/screen_manager.h" |
| 9 #include "ui/aura/layout_manager.h" |
| 10 #include "ui/aura/window.h" |
| 11 #include "ui/views/widget/widget.h" |
| 12 #include "ui/wm/core/visibility_controller.h" |
| 13 #include "ui/wm/core/window_animations.h" |
| 14 |
| 15 namespace athena { |
| 16 namespace { |
| 17 |
| 18 HomeCard* instance = NULL; |
| 19 |
| 20 class HomeCardLayoutManager : public aura::LayoutManager { |
| 21 public: |
| 22 explicit HomeCardLayoutManager(aura::Window* container) |
| 23 : container_(container) {} |
| 24 virtual ~HomeCardLayoutManager() {} |
| 25 |
| 26 private: |
| 27 // aura::LayoutManager: |
| 28 virtual void OnWindowResized() OVERRIDE { Layout(); } |
| 29 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } |
| 30 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 31 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
| 32 Layout(); |
| 33 } |
| 34 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 35 bool visible) OVERRIDE { |
| 36 Layout(); |
| 37 } |
| 38 virtual void SetChildBounds(aura::Window* child, |
| 39 const gfx::Rect& requested_bounds) OVERRIDE { |
| 40 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
| 41 } |
| 42 |
| 43 void Layout() { |
| 44 const int kHomeCardHeight = 50; |
| 45 const int kHomeCardHorizontalMargin = 50; |
| 46 if (container_->children().size() < 1) |
| 47 return; |
| 48 aura::Window* home_card = container_->children()[0]; |
| 49 if (!home_card->IsVisible()) |
| 50 return; |
| 51 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); |
| 52 gfx::Rect card_bounds = screen_bounds; |
| 53 card_bounds.Inset(kHomeCardHorizontalMargin, |
| 54 screen_bounds.height() - kHomeCardHeight, |
| 55 kHomeCardHorizontalMargin, |
| 56 0); |
| 57 SetChildBoundsDirect(home_card, card_bounds); |
| 58 } |
| 59 |
| 60 aura::Window* container_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
| 63 }; |
| 64 |
| 65 class HomeCardImpl : public HomeCard { |
| 66 public: |
| 67 HomeCardImpl(); |
| 68 virtual ~HomeCardImpl(); |
| 69 |
| 70 void Init(); |
| 71 |
| 72 private: |
| 73 views::Widget* home_card_widget_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
| 76 }; |
| 77 |
| 78 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { |
| 79 DCHECK(!instance); |
| 80 instance = this; |
| 81 } |
| 82 |
| 83 HomeCardImpl::~HomeCardImpl() { |
| 84 DCHECK(instance); |
| 85 home_card_widget_->CloseNow(); |
| 86 instance = NULL; |
| 87 } |
| 88 |
| 89 void HomeCardImpl::Init() { |
| 90 aura::Window* container = |
| 91 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
| 92 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
| 93 wm::SetChildWindowVisibilityChangesAnimated(container); |
| 94 |
| 95 views::Widget::InitParams params( |
| 96 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 97 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 98 params.delegate = new HomeCardDelegateView(); |
| 99 params.parent = container; |
| 100 |
| 101 home_card_widget_ = new views::Widget; |
| 102 home_card_widget_->Init(params); |
| 103 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); |
| 104 |
| 105 aura::Window* home_card_window = home_card_widget_->GetNativeView(); |
| 106 wm::SetWindowVisibilityAnimationType( |
| 107 home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 108 wm::SetWindowVisibilityAnimationTransition(home_card_window, |
| 109 wm::ANIMATE_BOTH); |
| 110 |
| 111 home_card_widget_->Show(); |
| 112 } |
| 113 |
| 114 } // namespace |
| 115 |
| 116 // static |
| 117 HomeCard* HomeCard::Create() { |
| 118 (new HomeCardImpl())->Init(); |
| 119 DCHECK(instance); |
| 120 return instance; |
| 121 } |
| 122 |
| 123 // static |
| 124 void HomeCard::Shutdown() { |
| 125 DCHECK(instance); |
| 126 delete instance; |
| 127 instance = NULL; |
| 128 } |
| 129 |
| 130 } // namespace athena |
OLD | NEW |