Chromium Code Reviews| 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; | |
|
Mr4D (OOO till 08-26)
2014/05/22 20:53:28
maybe gInstance? Or better make it a static member
oshima
2014/05/22 21:23:05
g_ is for global variable, while this is a file sc
Mr4D (OOO till 08-26)
2014/05/22 22:19:15
"g_" Right. "static member": I was asked by other
oshima
2014/05/23 14:54:37
You can redirect to me, and I can explain why priv
| |
| 19 | |
| 20 class HomeCardLayoutManager : public aura::LayoutManager { | |
|
Albert Bodenhamer
2014/05/22 19:22:02
Will we want the home card's layout manager to be
oshima
2014/05/22 21:23:05
This class most likely stay small.
| |
| 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 if (container_->children().size() < 1) | |
| 45 return; | |
| 46 aura::Window* home_card = container_->children()[0]; | |
| 47 if (!home_card->IsVisible()) | |
| 48 return; | |
| 49 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); | |
| 50 gfx::Rect card_bounds = screen_bounds; | |
| 51 card_bounds.Inset(50, screen_bounds.height() - 50, 50, 0); | |
|
Albert Bodenhamer
2014/05/22 19:22:02
I know this is expected to change but can we pull
oshima
2014/05/22 21:23:05
Done.
| |
| 52 SetChildBoundsDirect(home_card, card_bounds); | |
| 53 } | |
| 54 | |
| 55 aura::Window* container_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | |
| 58 }; | |
| 59 | |
| 60 class HomeCardImpl : public HomeCard { | |
| 61 public: | |
| 62 HomeCardImpl(); | |
| 63 virtual ~HomeCardImpl(); | |
| 64 | |
| 65 void Init(); | |
| 66 | |
| 67 private: | |
| 68 views::Widget* home_card_widget_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | |
| 71 }; | |
| 72 | |
| 73 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { | |
| 74 DCHECK(!instance); | |
| 75 instance = this; | |
| 76 } | |
| 77 | |
| 78 HomeCardImpl::~HomeCardImpl() { | |
| 79 DCHECK(instance); | |
| 80 home_card_widget_->CloseNow(); | |
| 81 instance = NULL; | |
| 82 } | |
| 83 | |
| 84 void HomeCardImpl::Init() { | |
| 85 aura::Window* container = | |
| 86 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | |
| 87 container->SetLayoutManager(new HomeCardLayoutManager(container)); | |
| 88 wm::SetChildWindowVisibilityChangesAnimated(container); | |
| 89 | |
| 90 views::Widget::InitParams params( | |
| 91 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 92 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 93 params.delegate = new HomeCardDelegateView(); | |
| 94 params.parent = container; | |
| 95 | |
| 96 home_card_widget_ = new views::Widget; | |
| 97 home_card_widget_->Init(params); | |
| 98 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); | |
| 99 | |
| 100 aura::Window* home_card_window = home_card_widget_->GetNativeView(); | |
| 101 wm::SetWindowVisibilityAnimationType( | |
| 102 home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
| 103 wm::SetWindowVisibilityAnimationTransition(home_card_window, | |
| 104 wm::ANIMATE_BOTH); | |
| 105 | |
| 106 home_card_widget_->Show(); | |
| 107 } | |
| 108 | |
| 109 } // namespace | |
| 110 | |
| 111 // static | |
| 112 HomeCard* HomeCard::Create() { | |
| 113 (new HomeCardImpl())->Init(); | |
| 114 DCHECK(instance); | |
| 115 return instance; | |
| 116 } | |
| 117 | |
| 118 // static | |
| 119 void HomeCard::Shutdown() { | |
| 120 DCHECK(instance); | |
| 121 delete instance; | |
| 122 instance = NULL; | |
| 123 } | |
| 124 | |
| 125 } // namespace athena | |
| OLD | NEW |