 Chromium Code Reviews
 Chromium Code Reviews Issue 2462753002:
  Use Ash's ShelfWindowWatcher for app panel windows.  (Closed)
    
  
    Issue 2462753002:
  Use Ash's ShelfWindowWatcher for app panel windows.  (Closed) 
  | Index: ash/common/shelf/shelf_window_watcher.cc | 
| diff --git a/ash/common/shelf/shelf_window_watcher.cc b/ash/common/shelf/shelf_window_watcher.cc | 
| index 22a6e7f7fd86e2605c68e3955c04eec728704a3f..757b5aff52eeed3f42b7ba5c23dda9cf105d241f 100644 | 
| --- a/ash/common/shelf/shelf_window_watcher.cc | 
| +++ b/ash/common/shelf/shelf_window_watcher.cc | 
| @@ -19,6 +19,7 @@ | 
| #include "ui/display/display.h" | 
| #include "ui/display/screen.h" | 
| #include "ui/gfx/image/image_skia.h" | 
| +#include "ui/resources/grit/ui_resources.h" | 
| namespace ash { | 
| namespace { | 
| @@ -27,8 +28,17 @@ namespace { | 
| void UpdateShelfItemForWindow(ShelfItem* item, WmWindow* window) { | 
| item->type = static_cast<ShelfItemType>( | 
| window->GetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE)); | 
| - const int icon = | 
| - window->GetIntProperty(WmWindowProperty::SHELF_ICON_RESOURCE_ID); | 
| + | 
| + // Prefer app icons over window icons, they're typically larger. | 
| + gfx::ImageSkia image = window->GetAppIcon(); | 
| + if (image.isNull()) | 
| + image = window->GetWindowIcon(); | 
| + if (!image.isNull()) { | 
| + item->image = image; | 
| + return; | 
| + } | 
| + | 
| + int icon = window->GetIntProperty(WmWindowProperty::SHELF_ICON_RESOURCE_ID); | 
| if (icon != kInvalidImageResourceID) | 
| item->image = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon); | 
| } | 
| @@ -52,8 +62,10 @@ void ShelfWindowWatcher::ContainerWindowObserver::OnWindowTreeChanged( | 
| WmWindow* window, | 
| const TreeChangeParams& params) { | 
| if (!params.old_parent && params.new_parent && | 
| - params.new_parent->GetShellWindowId() == | 
| - kShellWindowId_DefaultContainer) { | 
| + (params.new_parent->GetShellWindowId() == | 
| + kShellWindowId_DefaultContainer || | 
| + params.new_parent->GetShellWindowId() == | 
| + kShellWindowId_PanelContainer)) { | 
| // A new window was created in the default container. | 
| 
James Cook
2016/11/02 17:53:43
nit: update comment
 
msw
2016/11/10 21:07:46
Done.
 | 
| window_watcher_->OnUserWindowAdded(params.target); | 
| } | 
| @@ -75,8 +87,10 @@ ShelfWindowWatcher::UserWindowObserver::~UserWindowObserver() {} | 
| void ShelfWindowWatcher::UserWindowObserver::OnWindowPropertyChanged( | 
| WmWindow* window, | 
| WmWindowProperty property) { | 
| - if (property == WmWindowProperty::SHELF_ITEM_TYPE || | 
| - property == WmWindowProperty::SHELF_ICON_RESOURCE_ID) { | 
| + if (property == WmWindowProperty::APP_ICON || | 
| + property == WmWindowProperty::SHELF_ITEM_TYPE || | 
| + property == WmWindowProperty::SHELF_ICON_RESOURCE_ID || | 
| + property == WmWindowProperty::WINDOW_ICON) { | 
| window_watcher_->OnUserWindowPropertyChanged(window); | 
| } | 
| } | 
| @@ -98,6 +112,8 @@ ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model) | 
| for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { | 
| observed_container_windows_.Add( | 
| root->GetChildByShellWindowId(kShellWindowId_DefaultContainer)); | 
| + observed_container_windows_.Add( | 
| + root->GetChildByShellWindowId(kShellWindowId_PanelContainer)); | 
| } | 
| display::Screen::GetScreen()->AddObserver(this); | 
| @@ -109,18 +125,20 @@ ShelfWindowWatcher::~ShelfWindowWatcher() { | 
| } | 
| void ShelfWindowWatcher::AddShelfItem(WmWindow* window) { | 
| + managed_user_windows_.insert(window); | 
| ShelfItem item; | 
| ShelfID id = model_->next_id(); | 
| item.status = window->IsActive() ? STATUS_ACTIVE : STATUS_RUNNING; | 
| UpdateShelfItemForWindow(&item, window); | 
| window->SetIntProperty(WmWindowProperty::SHELF_ID, id); | 
| std::unique_ptr<ShelfItemDelegate> item_delegate( | 
| - new ShelfWindowWatcherItemDelegate(window)); | 
| + new ShelfWindowWatcherItemDelegate(id, window)); | 
| model_->SetShelfItemDelegate(id, std::move(item_delegate)); | 
| model_->Add(item); | 
| } | 
| void ShelfWindowWatcher::RemoveShelfItem(WmWindow* window) { | 
| + managed_user_windows_.erase(window); | 
| int shelf_id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | 
| DCHECK_NE(shelf_id, kInvalidShelfID); | 
| int index = model_->ItemIndexByID(shelf_id); | 
| @@ -175,9 +193,11 @@ void ShelfWindowWatcher::OnUserWindowDestroying(WmWindow* window) { | 
| void ShelfWindowWatcher::OnUserWindowPropertyChanged(WmWindow* window) { | 
| if (window->GetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE) == | 
| TYPE_UNDEFINED) { | 
| - // Removes ShelfItem for |window| when it has a ShelfItem. | 
| - if (window->GetIntProperty(WmWindowProperty::SHELF_ID) != kInvalidShelfID) | 
| + // Remove |window|'s ShelfItem if it was added by this ShelfWindowWatcher. | 
| + if (window->GetIntProperty(WmWindowProperty::SHELF_ID) != kInvalidShelfID && | 
| + managed_user_windows_.count(window) > 0) { | 
| RemoveShelfItem(window); | 
| + } | 
| return; | 
| } | 
| @@ -208,10 +228,14 @@ void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) { | 
| // When the primary root window's display get removed, the existing root | 
| // window is taken over by the new display and the observer is already set. | 
| - WmWindow* container = | 
| + WmWindow* default_container = | 
| root->GetChildByShellWindowId(kShellWindowId_DefaultContainer); | 
| - if (!observed_container_windows_.IsObserving(container)) | 
| - observed_container_windows_.Add(container); | 
| + if (!observed_container_windows_.IsObserving(default_container)) | 
| + observed_container_windows_.Add(default_container); | 
| + WmWindow* panel_container = | 
| + root->GetChildByShellWindowId(kShellWindowId_PanelContainer); | 
| + if (!observed_container_windows_.IsObserving(panel_container)) | 
| + observed_container_windows_.Add(panel_container); | 
| } | 
| void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |