| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 340 void ShelfDelegateMus::OnUserWindowObserverAdded( | 340 void ShelfDelegateMus::OnUserWindowObserverAdded( | 
| 341     mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { | 341     mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { | 
| 342   for (size_t i = 0; i < user_windows.size(); ++i) | 342   for (size_t i = 0; i < user_windows.size(); ++i) | 
| 343     OnUserWindowAdded(std::move(user_windows[i])); | 343     OnUserWindowAdded(std::move(user_windows[i])); | 
| 344 } | 344 } | 
| 345 | 345 | 
| 346 void ShelfDelegateMus::OnUserWindowAdded( | 346 void ShelfDelegateMus::OnUserWindowAdded( | 
| 347     mash::wm::mojom::UserWindowPtr user_window) { | 347     mash::wm::mojom::UserWindowPtr user_window) { | 
| 348   DCHECK(!window_id_to_shelf_id_.count(user_window->window_id)); | 348   DCHECK(!window_id_to_shelf_id_.count(user_window->window_id)); | 
| 349 | 349 | 
|  | 350   if (user_window->ignored_by_shelf) | 
|  | 351     return; | 
|  | 352 | 
| 350   std::string app_id(user_window->window_app_id.To<std::string>()); | 353   std::string app_id(user_window->window_app_id.To<std::string>()); | 
| 351   if (app_id_to_shelf_id_.count(app_id)) { | 354   if (app_id_to_shelf_id_.count(app_id)) { | 
| 352     ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 355     ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 
| 353     window_id_to_shelf_id_.insert( | 356     window_id_to_shelf_id_.insert( | 
| 354         std::make_pair(user_window->window_id, shelf_id)); | 357         std::make_pair(user_window->window_id, shelf_id)); | 
| 355 | 358 | 
| 356     ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 359     ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 
| 357     item_delegate->AddWindow(user_window->window_id, | 360     item_delegate->AddWindow(user_window->window_id, | 
| 358                              user_window->window_title.To<base::string16>()); | 361                              user_window->window_title.To<base::string16>()); | 
| 359     return; | 362     return; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 373 | 376 | 
| 374   std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 377   std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 
| 375       new ShelfItemDelegateMus(user_window_controller_.get())); | 378       new ShelfItemDelegateMus(user_window_controller_.get())); | 
| 376   item_delegate->AddWindow(user_window->window_id, | 379   item_delegate->AddWindow(user_window->window_id, | 
| 377                            user_window->window_title.To<base::string16>()); | 380                            user_window->window_title.To<base::string16>()); | 
| 378   Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( | 381   Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( | 
| 379       shelf_id, std::move(item_delegate)); | 382       shelf_id, std::move(item_delegate)); | 
| 380 } | 383 } | 
| 381 | 384 | 
| 382 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) { | 385 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) { | 
| 383   DCHECK(window_id_to_shelf_id_.count(window_id)); | 386   if (!window_id_to_shelf_id_.count(window_id)) | 
|  | 387     return; | 
| 384   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 388   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 
| 385   ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 389   ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 
| 386   item_delegate->RemoveWindow(window_id); | 390   item_delegate->RemoveWindow(window_id); | 
| 387   window_id_to_shelf_id_.erase(window_id); | 391   window_id_to_shelf_id_.erase(window_id); | 
| 388   if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) { | 392   if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) { | 
| 389     model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); | 393     model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); | 
| 390     const std::string& app_id = shelf_id_to_app_id_[shelf_id]; | 394     const std::string& app_id = shelf_id_to_app_id_[shelf_id]; | 
| 391     app_id_to_shelf_id_.erase(app_id); | 395     app_id_to_shelf_id_.erase(app_id); | 
| 392     shelf_id_to_app_id_.erase(shelf_id); | 396     shelf_id_to_app_id_.erase(shelf_id); | 
| 393   } | 397   } | 
| 394 } | 398 } | 
| 395 | 399 | 
| 396 void ShelfDelegateMus::OnUserWindowTitleChanged( | 400 void ShelfDelegateMus::OnUserWindowTitleChanged( | 
| 397     uint32_t window_id, | 401     uint32_t window_id, | 
| 398     const mojo::String& window_title) { | 402     const mojo::String& window_title) { | 
| 399   DCHECK(window_id_to_shelf_id_.count(window_id)); | 403   if (!window_id_to_shelf_id_.count(window_id)) | 
|  | 404     return; | 
| 400   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 405   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 
| 401   ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 406   ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 
| 402   item_delegate->SetWindowTitle(window_id, window_title.To<base::string16>()); | 407   item_delegate->SetWindowTitle(window_id, window_title.To<base::string16>()); | 
| 403 | 408 | 
| 404   // There's nothing in the ShelfItem that needs to be updated. But we still | 409   // There's nothing in the ShelfItem that needs to be updated. But we still | 
| 405   // need to update the ShelfModel so that the observers can pick up any | 410   // need to update the ShelfModel so that the observers can pick up any | 
| 406   // changes. | 411   // changes. | 
| 407   int index = model_->ItemIndexByID(shelf_id); | 412   int index = model_->ItemIndexByID(shelf_id); | 
| 408   DCHECK_GE(index, 0); | 413   DCHECK_GE(index, 0); | 
| 409   ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); | 414   ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); | 
| 410   DCHECK(iter != model_->items().end()); | 415   DCHECK(iter != model_->items().end()); | 
| 411   model_->Set(index, *iter); | 416   model_->Set(index, *iter); | 
| 412 } | 417 } | 
| 413 | 418 | 
| 414 void ShelfDelegateMus::OnUserWindowAppIconChanged( | 419 void ShelfDelegateMus::OnUserWindowAppIconChanged( | 
| 415     uint32_t window_id, | 420     uint32_t window_id, | 
| 416     mojo::Array<uint8_t> app_icon) { | 421     mojo::Array<uint8_t> app_icon) { | 
|  | 422   if (!window_id_to_shelf_id_.count(window_id)) | 
|  | 423     return; | 
| 417   // Find the shelf ID for this window. | 424   // Find the shelf ID for this window. | 
| 418   DCHECK(window_id_to_shelf_id_.count(window_id)); |  | 
| 419   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 425   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 
| 420   DCHECK_GT(shelf_id, 0); | 426   DCHECK_GT(shelf_id, 0); | 
| 421 | 427 | 
| 422   // Update the icon in the ShelfItem. | 428   // Update the icon in the ShelfItem. | 
| 423   int index = model_->ItemIndexByID(shelf_id); | 429   int index = model_->ItemIndexByID(shelf_id); | 
| 424   DCHECK_GE(index, 0); | 430   DCHECK_GE(index, 0); | 
| 425   ShelfItem item = *model_->ItemByID(shelf_id); | 431   ShelfItem item = *model_->ItemByID(shelf_id); | 
| 426   item.image = GetShelfIconFromSerializedBitmap(app_icon); | 432   item.image = GetShelfIconFromSerializedBitmap(app_icon); | 
| 427   model_->Set(index, item); | 433   model_->Set(index, item); | 
| 428 } | 434 } | 
| 429 | 435 | 
| 430 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id, | 436 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id, | 
| 431                                                 bool has_focus) { | 437                                                 bool has_focus) { | 
| 432   DCHECK(window_id_to_shelf_id_.count(window_id)); | 438   if (!window_id_to_shelf_id_.count(window_id)) | 
|  | 439     return; | 
| 433   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 440   ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 
| 434   int index = model_->ItemIndexByID(shelf_id); | 441   int index = model_->ItemIndexByID(shelf_id); | 
| 435   DCHECK_GE(index, 0); | 442   DCHECK_GE(index, 0); | 
| 436   ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); | 443   ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); | 
| 437   DCHECK(iter != model_->items().end()); | 444   DCHECK(iter != model_->items().end()); | 
| 438   ShelfItem item = *iter; | 445   ShelfItem item = *iter; | 
| 439   item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING; | 446   item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING; | 
| 440   model_->Set(index, item); | 447   model_->Set(index, item); | 
| 441 } | 448 } | 
| 442 | 449 | 
| 443 void ShelfDelegateMus::SetShelfPreferredSizes(Shelf* shelf) { | 450 void ShelfDelegateMus::SetShelfPreferredSizes(Shelf* shelf) { | 
| 444   ShelfWidget* widget = shelf->shelf_widget(); | 451   ShelfWidget* widget = shelf->shelf_widget(); | 
| 445   ShelfLayoutManager* layout_manager = widget->shelf_layout_manager(); | 452   ShelfLayoutManager* layout_manager = widget->shelf_layout_manager(); | 
| 446   mus::Window* window = aura::GetMusWindow(widget->GetNativeWindow()); | 453   mus::Window* window = aura::GetMusWindow(widget->GetNativeWindow()); | 
| 447   gfx::Size size = layout_manager->GetIdealBounds().size(); | 454   gfx::Size size = layout_manager->GetIdealBounds().size(); | 
| 448   window->SetSharedProperty<gfx::Size>( | 455   window->SetSharedProperty<gfx::Size>( | 
| 449       mus::mojom::WindowManager::kPreferredSize_Property, size); | 456       mus::mojom::WindowManager::kPreferredSize_Property, size); | 
| 450 | 457 | 
| 451   StatusAreaWidget* status_widget = widget->status_area_widget(); | 458   StatusAreaWidget* status_widget = widget->status_area_widget(); | 
| 452   mus::Window* status_window = | 459   mus::Window* status_window = | 
| 453       aura::GetMusWindow(status_widget->GetNativeWindow()); | 460       aura::GetMusWindow(status_widget->GetNativeWindow()); | 
| 454   gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); | 461   gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); | 
| 455   status_window->SetSharedProperty<gfx::Size>( | 462   status_window->SetSharedProperty<gfx::Size>( | 
| 456       mus::mojom::WindowManager::kPreferredSize_Property, status_size); | 463       mus::mojom::WindowManager::kPreferredSize_Property, status_size); | 
| 457 } | 464 } | 
| 458 | 465 | 
| 459 }  // namespace sysui | 466 }  // namespace sysui | 
| 460 }  // namespace ash | 467 }  // namespace ash | 
| OLD | NEW | 
|---|