| 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/public/app_model_builder.h" |
| 8 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
| 9 #include "athena/input/public/input_manager.h" | 10 #include "athena/input/public/input_manager.h" |
| 10 #include "athena/screen/public/screen_manager.h" | 11 #include "athena/screen/public/screen_manager.h" |
| 11 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
| 12 #include "ui/app_list/views/app_list_view.h" | 13 #include "ui/app_list/views/app_list_view.h" |
| 13 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/wm/core/visibility_controller.h" | 16 #include "ui/wm/core/visibility_controller.h" |
| 16 #include "ui/wm/core/window_animations.h" | 17 #include "ui/wm/core/window_animations.h" |
| 17 | 18 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 SetChildBoundsDirect(home_card, card_bounds); | 66 SetChildBoundsDirect(home_card, card_bounds); |
| 66 } | 67 } |
| 67 | 68 |
| 68 aura::Window* container_; | 69 aura::Window* container_; |
| 69 | 70 |
| 70 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 71 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 class HomeCardImpl : public HomeCard, public AcceleratorHandler { | 74 class HomeCardImpl : public HomeCard, public AcceleratorHandler { |
| 74 public: | 75 public: |
| 75 HomeCardImpl(); | 76 explicit HomeCardImpl(AppModelBuilder* model_builder); |
| 76 virtual ~HomeCardImpl(); | 77 virtual ~HomeCardImpl(); |
| 77 | 78 |
| 78 void Init(); | 79 void Init(); |
| 79 | 80 |
| 80 private: | 81 private: |
| 81 enum Command { | 82 enum Command { |
| 82 COMMAND_SHOW_HOME_CARD, | 83 COMMAND_SHOW_HOME_CARD, |
| 83 }; | 84 }; |
| 84 void InstallAccelerators(); | 85 void InstallAccelerators(); |
| 85 | 86 |
| 86 // AcceleratorHandler: | 87 // AcceleratorHandler: |
| 87 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | 88 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
| 88 virtual bool OnAcceleratorFired(int command_id, | 89 virtual bool OnAcceleratorFired(int command_id, |
| 89 const ui::Accelerator& accelerator) OVERRIDE { | 90 const ui::Accelerator& accelerator) OVERRIDE { |
| 90 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 91 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
| 91 home_card_widget_->Show(); | 92 home_card_widget_->Show(); |
| 92 return true; | 93 return true; |
| 93 } | 94 } |
| 94 | 95 |
| 96 scoped_ptr<AppModelBuilder> model_builder_; |
| 97 |
| 95 views::Widget* home_card_widget_; | 98 views::Widget* home_card_widget_; |
| 96 | 99 |
| 97 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 100 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
| 98 }; | 101 }; |
| 99 | 102 |
| 100 HomeCardImpl::HomeCardImpl() | 103 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) |
| 101 : home_card_widget_(NULL) { | 104 : model_builder_(model_builder), |
| 105 home_card_widget_(NULL) { |
| 102 DCHECK(!instance); | 106 DCHECK(!instance); |
| 103 instance = this; | 107 instance = this; |
| 104 } | 108 } |
| 105 | 109 |
| 106 HomeCardImpl::~HomeCardImpl() { | 110 HomeCardImpl::~HomeCardImpl() { |
| 107 DCHECK(instance); | 111 DCHECK(instance); |
| 108 home_card_widget_->CloseNow(); | 112 home_card_widget_->CloseNow(); |
| 109 instance = NULL; | 113 instance = NULL; |
| 110 } | 114 } |
| 111 | 115 |
| 112 void HomeCardImpl::Init() { | 116 void HomeCardImpl::Init() { |
| 113 InstallAccelerators(); | 117 InstallAccelerators(); |
| 114 | 118 |
| 115 aura::Window* container = | 119 aura::Window* container = |
| 116 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 120 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
| 117 container->SetLayoutManager(new HomeCardLayoutManager(container)); | 121 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
| 118 wm::SetChildWindowVisibilityChangesAnimated(container); | 122 wm::SetChildWindowVisibilityChangesAnimated(container); |
| 119 | 123 |
| 120 app_list::AppListView* view = new app_list::AppListView( | 124 app_list::AppListView* view = new app_list::AppListView( |
| 121 new AppListViewDelegate); | 125 new AppListViewDelegate(model_builder_.get())); |
| 122 view->InitAsBubbleAtFixedLocation( | 126 view->InitAsBubbleAtFixedLocation( |
| 123 container, | 127 container, |
| 124 0 /* initial_apps_page */, | 128 0 /* initial_apps_page */, |
| 125 gfx::Point(), | 129 gfx::Point(), |
| 126 views::BubbleBorder::FLOAT, | 130 views::BubbleBorder::FLOAT, |
| 127 true /* border_accepts_events */); | 131 true /* border_accepts_events */); |
| 128 home_card_widget_ = view->GetWidget(); | 132 home_card_widget_ = view->GetWidget(); |
| 129 view->ShowWhenReady(); | 133 view->ShowWhenReady(); |
| 130 } | 134 } |
| 131 | 135 |
| 132 void HomeCardImpl::InstallAccelerators() { | 136 void HomeCardImpl::InstallAccelerators() { |
| 133 const AcceleratorData accelerator_data[] = { | 137 const AcceleratorData accelerator_data[] = { |
| 134 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 138 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
| 135 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 139 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
| 136 }; | 140 }; |
| 137 InputManager::Get()->GetAcceleratorManager()->RegisterAccelerators( | 141 InputManager::Get()->GetAcceleratorManager()->RegisterAccelerators( |
| 138 accelerator_data, arraysize(accelerator_data), this); | 142 accelerator_data, arraysize(accelerator_data), this); |
| 139 } | 143 } |
| 140 | 144 |
| 141 } // namespace | 145 } // namespace |
| 142 | 146 |
| 143 // static | 147 // static |
| 144 HomeCard* HomeCard::Create() { | 148 HomeCard* HomeCard::Create(AppModelBuilder* model_builder) { |
| 145 (new HomeCardImpl())->Init(); | 149 (new HomeCardImpl(model_builder))->Init(); |
| 146 DCHECK(instance); | 150 DCHECK(instance); |
| 147 return instance; | 151 return instance; |
| 148 } | 152 } |
| 149 | 153 |
| 150 // static | 154 // static |
| 151 void HomeCard::Shutdown() { | 155 void HomeCard::Shutdown() { |
| 152 DCHECK(instance); | 156 DCHECK(instance); |
| 153 delete instance; | 157 delete instance; |
| 154 instance = NULL; | 158 instance = NULL; |
| 155 } | 159 } |
| 156 | 160 |
| 157 } // namespace athena | 161 } // namespace athena |
| OLD | NEW |