OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/mus/shelf_delegate_mus.h" | 5 #include "ash/mus/shelf_delegate_mus.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_item_delegate.h" | 10 #include "ash/shelf/shelf_item_delegate.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 shelf->auto_hide_behavior()); | 209 shelf->auto_hide_behavior()); |
210 shelf_layout_->SetAutoHideBehavior(behavior); | 210 shelf_layout_->SetAutoHideBehavior(behavior); |
211 | 211 |
212 observers_.ForAllPtrs( | 212 observers_.ForAllPtrs( |
213 [behavior](mash::shelf::mojom::ShelfObserver* observer) { | 213 [behavior](mash::shelf::mojom::ShelfObserver* observer) { |
214 observer->OnAutoHideBehaviorChanged(behavior); | 214 observer->OnAutoHideBehaviorChanged(behavior); |
215 }); | 215 }); |
216 } | 216 } |
217 | 217 |
218 ShelfID ShelfDelegateMus::GetShelfIDForAppID(const std::string& app_id) { | 218 ShelfID ShelfDelegateMus::GetShelfIDForAppID(const std::string& app_id) { |
219 NOTIMPLEMENTED(); | 219 if (app_id_to_shelf_id_.count(app_id)) |
| 220 return app_id_to_shelf_id_[app_id]; |
220 return 0; | 221 return 0; |
221 } | 222 } |
222 | 223 |
223 bool ShelfDelegateMus::HasShelfIDToAppIDMapping(ShelfID id) const { | 224 bool ShelfDelegateMus::HasShelfIDToAppIDMapping(ShelfID id) const { |
224 NOTIMPLEMENTED(); | 225 return shelf_id_to_app_id_.count(id) != 0; |
225 return false; | |
226 } | 226 } |
227 | 227 |
228 const std::string& ShelfDelegateMus::GetAppIDForShelfID(ShelfID id) { | 228 const std::string& ShelfDelegateMus::GetAppIDForShelfID(ShelfID id) { |
229 NOTIMPLEMENTED(); | 229 if (shelf_id_to_app_id_.count(id)) |
| 230 return shelf_id_to_app_id_[id]; |
230 return base::EmptyString(); | 231 return base::EmptyString(); |
231 } | 232 } |
232 | 233 |
233 void ShelfDelegateMus::PinAppWithID(const std::string& app_id) { | 234 void ShelfDelegateMus::PinAppWithID(const std::string& app_id) { |
234 NOTIMPLEMENTED(); | 235 NOTIMPLEMENTED(); |
235 } | 236 } |
236 | 237 |
237 bool ShelfDelegateMus::IsAppPinned(const std::string& app_id) { | 238 bool ShelfDelegateMus::IsAppPinned(const std::string& app_id) { |
238 NOTIMPLEMENTED(); | 239 NOTIMPLEMENTED(); |
239 return false; | 240 return false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 std::string app_id(item->app_id.To<std::string>()); | 276 std::string app_id(item->app_id.To<std::string>()); |
276 if (app_id_to_shelf_id_.count(app_id)) { | 277 if (app_id_to_shelf_id_.count(app_id)) { |
277 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 278 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
278 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 279 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
279 item_delegate->set_pinned(true); | 280 item_delegate->set_pinned(true); |
280 return; | 281 return; |
281 } | 282 } |
282 | 283 |
283 ShelfID shelf_id = model_->next_id(); | 284 ShelfID shelf_id = model_->next_id(); |
284 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); | 285 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); |
| 286 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); |
285 | 287 |
286 ShelfItem shelf_item; | 288 ShelfItem shelf_item; |
287 shelf_item.type = TYPE_APP_SHORTCUT; | 289 shelf_item.type = TYPE_APP_SHORTCUT; |
288 shelf_item.status = STATUS_CLOSED; | 290 shelf_item.status = STATUS_CLOSED; |
289 shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); | 291 shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); |
290 model_->Add(shelf_item); | 292 model_->Add(shelf_item); |
291 | 293 |
292 std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 294 std::unique_ptr<ShelfItemDelegateMus> item_delegate( |
293 new ShelfItemDelegateMus(user_window_controller_.get())); | 295 new ShelfItemDelegateMus(user_window_controller_.get())); |
294 item_delegate->set_pinned(true); | 296 item_delegate->set_pinned(true); |
295 item_delegate->set_title(item->app_title.To<base::string16>()); | 297 item_delegate->set_title(item->app_title.To<base::string16>()); |
296 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( | 298 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( |
297 shelf_id, std::move(item_delegate)); | 299 shelf_id, std::move(item_delegate)); |
298 } | 300 } |
299 | 301 |
300 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { | 302 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { |
301 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) | 303 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) |
302 return; | 304 return; |
303 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; | 305 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; |
304 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 306 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
305 DCHECK(item_delegate->pinned()); | 307 DCHECK(item_delegate->pinned()); |
306 item_delegate->set_pinned(false); | 308 item_delegate->set_pinned(false); |
307 if (item_delegate->window_id_to_title().empty()) | 309 if (item_delegate->window_id_to_title().empty()) { |
308 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); | 310 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); |
| 311 app_id_to_shelf_id_.erase(app_id.To<std::string>()); |
| 312 shelf_id_to_app_id_.erase(shelf_id); |
| 313 } |
309 } | 314 } |
310 | 315 |
311 void ShelfDelegateMus::OnUserWindowObserverAdded( | 316 void ShelfDelegateMus::OnUserWindowObserverAdded( |
312 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { | 317 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { |
313 for (size_t i = 0; i < user_windows.size(); ++i) | 318 for (size_t i = 0; i < user_windows.size(); ++i) |
314 OnUserWindowAdded(std::move(user_windows[i])); | 319 OnUserWindowAdded(std::move(user_windows[i])); |
315 } | 320 } |
316 | 321 |
317 void ShelfDelegateMus::OnUserWindowAdded( | 322 void ShelfDelegateMus::OnUserWindowAdded( |
318 mash::wm::mojom::UserWindowPtr user_window) { | 323 mash::wm::mojom::UserWindowPtr user_window) { |
319 DCHECK(!window_id_to_shelf_id_.count(user_window->window_id)); | 324 DCHECK(!window_id_to_shelf_id_.count(user_window->window_id)); |
320 | 325 |
321 std::string app_id(user_window->window_app_id.To<std::string>()); | 326 std::string app_id(user_window->window_app_id.To<std::string>()); |
322 if (app_id_to_shelf_id_.count(app_id)) { | 327 if (app_id_to_shelf_id_.count(app_id)) { |
323 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 328 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
324 window_id_to_shelf_id_.insert( | 329 window_id_to_shelf_id_.insert( |
325 std::make_pair(user_window->window_id, shelf_id)); | 330 std::make_pair(user_window->window_id, shelf_id)); |
326 | 331 |
327 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 332 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
328 item_delegate->AddWindow(user_window->window_id, | 333 item_delegate->AddWindow(user_window->window_id, |
329 user_window->window_title.To<base::string16>()); | 334 user_window->window_title.To<base::string16>()); |
330 return; | 335 return; |
331 } | 336 } |
332 | 337 |
333 ShelfID shelf_id = model_->next_id(); | 338 ShelfID shelf_id = model_->next_id(); |
334 window_id_to_shelf_id_.insert( | 339 window_id_to_shelf_id_.insert( |
335 std::make_pair(user_window->window_id, shelf_id)); | 340 std::make_pair(user_window->window_id, shelf_id)); |
336 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); | 341 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); |
| 342 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); |
337 | 343 |
338 ShelfItem item; | 344 ShelfItem item; |
339 item.type = TYPE_PLATFORM_APP; | 345 item.type = TYPE_PLATFORM_APP; |
340 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; | 346 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; |
341 item.image = GetShelfIconFromSerializedBitmap(user_window->window_app_icon); | 347 item.image = GetShelfIconFromSerializedBitmap(user_window->window_app_icon); |
342 model_->Add(item); | 348 model_->Add(item); |
343 | 349 |
344 std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 350 std::unique_ptr<ShelfItemDelegateMus> item_delegate( |
345 new ShelfItemDelegateMus(user_window_controller_.get())); | 351 new ShelfItemDelegateMus(user_window_controller_.get())); |
346 item_delegate->AddWindow(user_window->window_id, | 352 item_delegate->AddWindow(user_window->window_id, |
347 user_window->window_title.To<base::string16>()); | 353 user_window->window_title.To<base::string16>()); |
348 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( | 354 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( |
349 shelf_id, std::move(item_delegate)); | 355 shelf_id, std::move(item_delegate)); |
350 } | 356 } |
351 | 357 |
352 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) { | 358 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) { |
353 DCHECK(window_id_to_shelf_id_.count(window_id)); | 359 DCHECK(window_id_to_shelf_id_.count(window_id)); |
354 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 360 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; |
355 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 361 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
356 item_delegate->RemoveWindow(window_id); | 362 item_delegate->RemoveWindow(window_id); |
357 window_id_to_shelf_id_.erase(window_id); | 363 window_id_to_shelf_id_.erase(window_id); |
358 if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) | 364 if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) { |
359 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); | 365 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); |
| 366 const std::string& app_id = shelf_id_to_app_id_[shelf_id]; |
| 367 app_id_to_shelf_id_.erase(app_id); |
| 368 shelf_id_to_app_id_.erase(shelf_id); |
| 369 } |
360 } | 370 } |
361 | 371 |
362 void ShelfDelegateMus::OnUserWindowTitleChanged( | 372 void ShelfDelegateMus::OnUserWindowTitleChanged( |
363 uint32_t window_id, | 373 uint32_t window_id, |
364 const mojo::String& window_title) { | 374 const mojo::String& window_title) { |
365 DCHECK(window_id_to_shelf_id_.count(window_id)); | 375 DCHECK(window_id_to_shelf_id_.count(window_id)); |
366 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 376 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; |
367 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 377 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
368 item_delegate->SetWindowTitle(window_id, window_title.To<base::string16>()); | 378 item_delegate->SetWindowTitle(window_id, window_title.To<base::string16>()); |
369 | 379 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 StatusAreaWidget* status_widget = widget->status_area_widget(); | 427 StatusAreaWidget* status_widget = widget->status_area_widget(); |
418 mus::Window* status_window = | 428 mus::Window* status_window = |
419 aura::GetMusWindow(status_widget->GetNativeWindow()); | 429 aura::GetMusWindow(status_widget->GetNativeWindow()); |
420 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); | 430 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); |
421 status_window->SetSharedProperty<gfx::Size>( | 431 status_window->SetSharedProperty<gfx::Size>( |
422 mus::mojom::WindowManager::kPreferredSize_Property, status_size); | 432 mus::mojom::WindowManager::kPreferredSize_Property, status_size); |
423 } | 433 } |
424 | 434 |
425 } // namespace sysui | 435 } // namespace sysui |
426 } // namespace ash | 436 } // namespace ash |
OLD | NEW |