Chromium Code Reviews| 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/minimized_home.h" | |
| 8 #include "athena/home/public/app_model_builder.h" | 9 #include "athena/home/public/app_model_builder.h" |
| 9 #include "athena/input/public/accelerator_manager.h" | 10 #include "athena/input/public/accelerator_manager.h" |
| 10 #include "athena/screen/public/screen_manager.h" | 11 #include "athena/screen/public/screen_manager.h" |
| 12 #include "athena/wm/public/window_manager.h" | |
| 13 #include "athena/wm/public/window_manager_observer.h" | |
| 14 #include "base/bind.h" | |
| 11 #include "ui/app_list/search_provider.h" | 15 #include "ui/app_list/search_provider.h" |
| 12 #include "ui/app_list/views/app_list_view.h" | 16 #include "ui/app_list/views/app_list_view.h" |
| 13 #include "ui/aura/layout_manager.h" | 17 #include "ui/aura/layout_manager.h" |
| 14 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 19 #include "ui/views/layout/box_layout.h" | |
| 15 #include "ui/wm/core/visibility_controller.h" | 20 #include "ui/wm/core/visibility_controller.h" |
| 16 #include "ui/wm/core/window_animations.h" | 21 #include "ui/wm/core/window_animations.h" |
| 17 | 22 |
| 18 namespace athena { | 23 namespace athena { |
| 19 namespace { | 24 namespace { |
| 20 | 25 |
| 21 HomeCard* instance = NULL; | 26 HomeCard* instance = NULL; |
| 22 | 27 |
| 28 // Makes sure the homecard is center-aligned horizontally and bottom-aligned | |
| 29 // vertically. | |
| 23 class HomeCardLayoutManager : public aura::LayoutManager { | 30 class HomeCardLayoutManager : public aura::LayoutManager { |
| 24 public: | 31 public: |
| 25 explicit HomeCardLayoutManager(aura::Window* container) | 32 class Delegate { |
| 26 : container_(container) {} | 33 public: |
| 34 virtual ~Delegate() {} | |
| 35 | |
| 36 virtual int GetHomeCardHeight() const = 0; | |
| 37 | |
| 38 virtual int GetHorizontalMargin() const = 0; | |
| 39 | |
| 40 // TODO(mukai): Remove this when bubble is no longer used for | |
| 41 // VISIBLE_CENTERED or VISIBLE_BOTTOM states. | |
| 42 virtual bool HasShadow() const = 0; | |
| 43 }; | |
| 44 | |
| 45 HomeCardLayoutManager(Delegate* delegate, aura::Window* container) | |
| 46 : delegate_(delegate), container_(container) {} | |
| 27 virtual ~HomeCardLayoutManager() {} | 47 virtual ~HomeCardLayoutManager() {} |
| 28 | 48 |
| 29 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { | 49 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { |
| 30 virtual_keyboard_bounds_ = bounds; | 50 virtual_keyboard_bounds_ = bounds; |
| 31 Layout(); | 51 Layout(); |
| 32 } | 52 } |
| 33 | 53 |
| 34 private: | 54 private: |
| 35 // aura::LayoutManager: | 55 // aura::LayoutManager: |
| 36 virtual void OnWindowResized() OVERRIDE { Layout(); } | 56 virtual void OnWindowResized() OVERRIDE { Layout(); } |
| 37 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } | 57 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } |
| 38 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | 58 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 39 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | 59 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
| 40 Layout(); | 60 Layout(); |
| 41 } | 61 } |
| 42 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 62 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 43 bool visible) OVERRIDE { | 63 bool visible) OVERRIDE { |
| 44 Layout(); | 64 Layout(); |
| 45 } | 65 } |
| 46 virtual void SetChildBounds(aura::Window* child, | 66 virtual void SetChildBounds(aura::Window* child, |
| 47 const gfx::Rect& requested_bounds) OVERRIDE { | 67 const gfx::Rect& requested_bounds) OVERRIDE { |
| 48 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); | 68 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
| 49 } | 69 } |
| 50 | 70 |
| 51 void Layout() { | 71 void Layout() { |
| 52 const int kHomeCardHeight = 150; | 72 int height = delegate_->GetHomeCardHeight(); |
| 53 const int kHomeCardHorizontalMargin = 50; | 73 int horiz_margin = delegate_->GetHorizontalMargin(); |
| 54 // Currently the home card is provided as a bubble and the bounds has to be | |
| 55 // increased to cancel the shadow. | |
| 56 // TODO(mukai): stops using the bubble and remove this. | |
| 57 const int kHomeCardShadowWidth = 30; | |
| 58 if (container_->children().size() < 1) | 74 if (container_->children().size() < 1) |
| 59 return; | 75 return; |
| 60 aura::Window* home_card = container_->children()[0]; | 76 |
| 61 if (!home_card->IsVisible()) | 77 aura::Window* home_card = instance->GetNativeWindow(); |
| 78 if (!home_card) | |
| 62 return; | 79 return; |
| 63 | 80 |
| 64 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); | 81 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); |
| 65 if (!virtual_keyboard_bounds_.IsEmpty()) | 82 if (!virtual_keyboard_bounds_.IsEmpty()) |
| 66 screen_bounds.set_height(virtual_keyboard_bounds_.y()); | 83 screen_bounds.set_height(virtual_keyboard_bounds_.y()); |
| 67 gfx::Rect card_bounds = screen_bounds; | 84 gfx::Rect card_bounds = screen_bounds; |
| 68 card_bounds.Inset(kHomeCardHorizontalMargin, | 85 card_bounds.Inset(horiz_margin, screen_bounds.height() - height, |
| 69 screen_bounds.height() - kHomeCardHeight, | 86 horiz_margin, 0); |
| 70 kHomeCardHorizontalMargin, | 87 |
| 71 0); | 88 if (delegate_->HasShadow()) { |
| 72 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | 89 // Currently the home card is provided as a bubble and the bounds has to |
| 90 // be increased to cancel the shadow. | |
| 91 // TODO(mukai): stops using the bubble and remove this. | |
| 92 const int kHomeCardShadowWidth = 30; | |
| 93 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | |
| 94 } | |
| 73 SetChildBoundsDirect(home_card, card_bounds); | 95 SetChildBoundsDirect(home_card, card_bounds); |
| 74 } | 96 } |
| 75 | 97 |
| 98 Delegate* delegate_; | |
| 76 aura::Window* container_; | 99 aura::Window* container_; |
|
oshima
2014/07/16 19:10:38
I believe you can remove this.
sadrul
2014/07/16 19:32:58
Yep. cool. done.
| |
| 77 gfx::Rect virtual_keyboard_bounds_; | 100 gfx::Rect virtual_keyboard_bounds_; |
| 78 | 101 |
| 79 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 102 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
| 80 }; | 103 }; |
| 81 | 104 |
| 82 class HomeCardImpl : public HomeCard, public AcceleratorHandler { | 105 class HomeCardImpl : public HomeCard, |
| 106 public AcceleratorHandler, | |
| 107 public HomeCardLayoutManager::Delegate, | |
| 108 public MinimizedHomeDragDelegate, | |
| 109 public WindowManagerObserver { | |
| 83 public: | 110 public: |
| 84 explicit HomeCardImpl(AppModelBuilder* model_builder); | 111 explicit HomeCardImpl(AppModelBuilder* model_builder); |
| 85 virtual ~HomeCardImpl(); | 112 virtual ~HomeCardImpl(); |
| 86 | 113 |
| 87 void Init(); | 114 void Init(); |
| 88 | 115 |
| 89 private: | 116 private: |
| 90 enum Command { | 117 enum Command { |
| 91 COMMAND_SHOW_HOME_CARD, | 118 COMMAND_SHOW_HOME_CARD, |
| 92 }; | 119 }; |
| 93 void InstallAccelerators(); | 120 void InstallAccelerators(); |
| 94 | 121 |
| 95 // Overridden from HomeCard: | 122 // Overridden from HomeCard: |
| 96 virtual void SetState(State state) OVERRIDE; | 123 virtual void SetState(State state) OVERRIDE; |
| 97 virtual void RegisterSearchProvider( | 124 virtual void RegisterSearchProvider( |
| 98 app_list::SearchProvider* search_provider) OVERRIDE; | 125 app_list::SearchProvider* search_provider) OVERRIDE; |
| 99 virtual void UpdateVirtualKeyboardBounds( | 126 virtual void UpdateVirtualKeyboardBounds( |
| 100 const gfx::Rect& bounds) OVERRIDE; | 127 const gfx::Rect& bounds) OVERRIDE; |
| 128 virtual aura::Window* GetNativeWindow() OVERRIDE; | |
| 101 | 129 |
| 102 // AcceleratorHandler: | 130 // AcceleratorHandler: |
| 103 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | 131 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
| 104 virtual bool OnAcceleratorFired(int command_id, | 132 virtual bool OnAcceleratorFired(int command_id, |
| 105 const ui::Accelerator& accelerator) OVERRIDE { | 133 const ui::Accelerator& accelerator) OVERRIDE { |
| 106 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 134 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
| 107 if (state_ == HIDDEN) | 135 if (state_ == HIDDEN) |
| 108 SetState(VISIBLE_CENTERED); | 136 SetState(VISIBLE_CENTERED); |
| 109 else | 137 else |
| 110 SetState(HIDDEN); | 138 SetState(HIDDEN); |
| 111 return true; | 139 return true; |
| 112 } | 140 } |
| 113 | 141 |
| 142 // HomeCardLayoutManager::Delegate: | |
| 143 virtual int GetHomeCardHeight() const OVERRIDE { | |
| 144 const int kHomeCardHeight = 150; | |
| 145 const int kHomeCardMinimizedHeight = 8; | |
| 146 CHECK_NE(HIDDEN, state_); | |
| 147 return state_ == VISIBLE_MINIMIZED ? kHomeCardMinimizedHeight : | |
| 148 kHomeCardHeight; | |
| 149 } | |
| 150 | |
| 151 virtual int GetHorizontalMargin() const OVERRIDE { | |
| 152 CHECK_NE(HIDDEN, state_); | |
| 153 const int kHomeCardHorizontalMargin = 50; | |
| 154 return state_ == VISIBLE_MINIMIZED ? 0 : kHomeCardHorizontalMargin; | |
| 155 } | |
| 156 | |
| 157 virtual bool HasShadow() const OVERRIDE { | |
| 158 CHECK_NE(HIDDEN, state_); | |
| 159 return state_ != VISIBLE_MINIMIZED; | |
| 160 } | |
| 161 | |
| 162 // MinimizedHomeDragDelegate: | |
| 163 virtual void OnDragUpCompleted() OVERRIDE { | |
| 164 WindowManager::GetInstance()->ToggleOverview(); | |
| 165 } | |
| 166 | |
| 167 // WindowManagerObserver: | |
| 168 virtual void OnOverviewModeEnter() OVERRIDE { | |
| 169 SetState(VISIBLE_BOTTOM); | |
| 170 } | |
| 171 | |
| 172 virtual void OnOverviewModeExit() OVERRIDE { | |
| 173 SetState(VISIBLE_MINIMIZED); | |
| 174 } | |
| 175 | |
| 114 scoped_ptr<AppModelBuilder> model_builder_; | 176 scoped_ptr<AppModelBuilder> model_builder_; |
| 115 | 177 |
| 116 HomeCard::State state_; | 178 HomeCard::State state_; |
| 117 | 179 |
| 118 views::Widget* home_card_widget_; | 180 views::Widget* home_card_widget_; |
| 181 views::Widget* minimized_widget_; | |
| 119 AppListViewDelegate* view_delegate_; | 182 AppListViewDelegate* view_delegate_; |
| 120 HomeCardLayoutManager* layout_manager_; | 183 HomeCardLayoutManager* layout_manager_; |
| 121 | 184 |
| 122 // Right now HomeCard allows only one search provider. | 185 // Right now HomeCard allows only one search provider. |
| 123 // TODO(mukai): port app-list's SearchController and Mixer. | 186 // TODO(mukai): port app-list's SearchController and Mixer. |
| 124 scoped_ptr<app_list::SearchProvider> search_provider_; | 187 scoped_ptr<app_list::SearchProvider> search_provider_; |
| 125 | 188 |
| 126 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 189 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
| 127 }; | 190 }; |
| 128 | 191 |
| 129 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) | 192 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) |
| 130 : model_builder_(model_builder), | 193 : model_builder_(model_builder), |
| 131 state_(HIDDEN), | 194 state_(VISIBLE_MINIMIZED), |
| 132 home_card_widget_(NULL), | 195 home_card_widget_(NULL), |
| 196 minimized_widget_(NULL), | |
| 133 layout_manager_(NULL) { | 197 layout_manager_(NULL) { |
| 134 DCHECK(!instance); | 198 DCHECK(!instance); |
| 135 instance = this; | 199 instance = this; |
| 200 WindowManager::GetInstance()->AddObserver(this); | |
| 136 } | 201 } |
| 137 | 202 |
| 138 HomeCardImpl::~HomeCardImpl() { | 203 HomeCardImpl::~HomeCardImpl() { |
| 139 DCHECK(instance); | 204 DCHECK(instance); |
| 205 WindowManager::GetInstance()->RemoveObserver(this); | |
| 140 home_card_widget_->CloseNow(); | 206 home_card_widget_->CloseNow(); |
| 207 minimized_widget_->CloseNow(); | |
| 141 view_delegate_ = NULL; | 208 view_delegate_ = NULL; |
| 142 instance = NULL; | 209 instance = NULL; |
| 143 } | 210 } |
| 144 | 211 |
| 145 void HomeCardImpl::SetState(HomeCard::State state) { | 212 void HomeCardImpl::SetState(HomeCard::State state) { |
| 146 if (state == HIDDEN) | 213 // Update |state_| before changing the visibility of the widgets, so that |
| 147 home_card_widget_->Hide(); | 214 // LayoutManager callbacks get the correct state. |
| 148 else | |
| 149 home_card_widget_->Show(); | |
| 150 state_ = state; | 215 state_ = state; |
| 216 switch (state_) { | |
| 217 case VISIBLE_MINIMIZED: | |
| 218 home_card_widget_->Hide(); | |
| 219 minimized_widget_->Show(); | |
| 220 break; | |
| 221 case HIDDEN: | |
| 222 home_card_widget_->Hide(); | |
| 223 minimized_widget_->Hide(); | |
| 224 break; | |
| 225 case VISIBLE_BOTTOM: | |
| 226 case VISIBLE_CENTERED: | |
| 227 home_card_widget_->Show(); | |
| 228 minimized_widget_->Hide(); | |
| 229 break; | |
| 230 } | |
| 151 } | 231 } |
| 152 | 232 |
| 153 void HomeCardImpl::RegisterSearchProvider( | 233 void HomeCardImpl::RegisterSearchProvider( |
| 154 app_list::SearchProvider* search_provider) { | 234 app_list::SearchProvider* search_provider) { |
| 155 DCHECK(!search_provider_); | 235 DCHECK(!search_provider_); |
| 156 search_provider_.reset(search_provider); | 236 search_provider_.reset(search_provider); |
| 157 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 237 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
| 158 } | 238 } |
| 159 | 239 |
| 160 void HomeCardImpl::UpdateVirtualKeyboardBounds( | 240 void HomeCardImpl::UpdateVirtualKeyboardBounds( |
| 161 const gfx::Rect& bounds) { | 241 const gfx::Rect& bounds) { |
| 242 if (state_ == VISIBLE_MINIMIZED) { | |
| 243 if (bounds.IsEmpty()) | |
| 244 minimized_widget_->Show(); | |
| 245 else | |
| 246 minimized_widget_->Hide(); | |
| 247 } | |
| 162 layout_manager_->UpdateVirtualKeyboardBounds(bounds); | 248 layout_manager_->UpdateVirtualKeyboardBounds(bounds); |
| 163 } | 249 } |
| 164 | 250 |
| 251 aura::Window* HomeCardImpl::GetNativeWindow() { | |
| 252 switch (state_) { | |
| 253 case HIDDEN: | |
| 254 return NULL; | |
| 255 case VISIBLE_MINIMIZED: | |
| 256 return minimized_widget_ ? minimized_widget_->GetNativeWindow() : NULL; | |
| 257 case VISIBLE_CENTERED: | |
| 258 case VISIBLE_BOTTOM: | |
| 259 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; | |
| 260 } | |
| 261 } | |
| 262 | |
| 165 void HomeCardImpl::Init() { | 263 void HomeCardImpl::Init() { |
| 166 InstallAccelerators(); | 264 InstallAccelerators(); |
| 167 | 265 |
| 168 aura::Window* container = | 266 aura::Window* container = |
| 169 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 267 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
| 170 layout_manager_ = new HomeCardLayoutManager(container); | 268 layout_manager_ = new HomeCardLayoutManager(this, container); |
| 171 container->SetLayoutManager(layout_manager_); | 269 container->SetLayoutManager(layout_manager_); |
| 172 wm::SetChildWindowVisibilityChangesAnimated(container); | 270 wm::SetChildWindowVisibilityChangesAnimated(container); |
| 173 | 271 |
| 174 view_delegate_ = new AppListViewDelegate(model_builder_.get()); | 272 view_delegate_ = new AppListViewDelegate(model_builder_.get()); |
| 175 if (search_provider_) | 273 if (search_provider_) |
| 176 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 274 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
| 177 app_list::AppListView* view = new app_list::AppListView(view_delegate_); | 275 app_list::AppListView* view = new app_list::AppListView(view_delegate_); |
| 178 view->InitAsBubbleAtFixedLocation( | 276 view->InitAsBubbleAtFixedLocation( |
| 179 container, | 277 container, |
| 180 0 /* initial_apps_page */, | 278 0 /* initial_apps_page */, |
| 181 gfx::Point(), | 279 gfx::Point(), |
| 182 views::BubbleBorder::FLOAT, | 280 views::BubbleBorder::FLOAT, |
| 183 true /* border_accepts_events */); | 281 true /* border_accepts_events */); |
| 184 home_card_widget_ = view->GetWidget(); | 282 home_card_widget_ = view->GetWidget(); |
| 185 // TODO: the initial value might not be visible. | 283 |
| 186 state_ = VISIBLE_CENTERED; | 284 // Start off in the minimized state. |
| 187 view->ShowWhenReady(); | 285 minimized_widget_ = CreateMinimizedHome(container, this); |
| 286 SetState(VISIBLE_MINIMIZED); | |
| 188 } | 287 } |
| 189 | 288 |
| 190 void HomeCardImpl::InstallAccelerators() { | 289 void HomeCardImpl::InstallAccelerators() { |
| 191 const AcceleratorData accelerator_data[] = { | 290 const AcceleratorData accelerator_data[] = { |
| 192 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 291 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
| 193 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 292 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
| 194 }; | 293 }; |
| 195 AcceleratorManager::Get()->RegisterAccelerators( | 294 AcceleratorManager::Get()->RegisterAccelerators( |
| 196 accelerator_data, arraysize(accelerator_data), this); | 295 accelerator_data, arraysize(accelerator_data), this); |
| 197 } | 296 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 212 instance = NULL; | 311 instance = NULL; |
| 213 } | 312 } |
| 214 | 313 |
| 215 // static | 314 // static |
| 216 HomeCard* HomeCard::Get() { | 315 HomeCard* HomeCard::Get() { |
| 217 DCHECK(instance); | 316 DCHECK(instance); |
| 218 return instance; | 317 return instance; |
| 219 } | 318 } |
| 220 | 319 |
| 221 } // namespace athena | 320 } // namespace athena |
| OLD | NEW |