| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/shelf_window_watcher.h" | 5 #include "ash/shelf/shelf_window_watcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/public/cpp/config.h" | 10 #include "ash/public/cpp/config.h" |
| 11 #include "ash/public/cpp/shell_window_ids.h" | 11 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/public/cpp/window_properties.h" | 12 #include "ash/public/cpp/window_properties.h" |
| 13 #include "ash/shelf/shelf_constants.h" | 13 #include "ash/shelf/shelf_constants.h" |
| 14 #include "ash/shelf/shelf_model.h" | 14 #include "ash/shelf/shelf_model.h" |
| 15 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 15 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/shell_port.h" | 17 #include "ash/shell_port.h" |
| 18 #include "ash/wm/window_properties.h" | |
| 19 #include "ash/wm/window_state.h" | 18 #include "ash/wm/window_state.h" |
| 20 #include "ash/wm/window_state_aura.h" | 19 #include "ash/wm/window_state_aura.h" |
| 21 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 22 #include "ash/wm_window.h" | 21 #include "ash/wm_window.h" |
| 23 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 24 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/display/display.h" | 25 #include "ui/display/display.h" |
| 27 #include "ui/display/screen.h" | 26 #include "ui/display/screen.h" |
| 28 #include "ui/resources/grit/ui_resources.h" | 27 #include "ui/resources/grit/ui_resources.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 45 // Update the ShelfItem from relevant window properties. | 44 // Update the ShelfItem from relevant window properties. |
| 46 void UpdateShelfItemForWindow(ShelfItem* item, aura::Window* window) { | 45 void UpdateShelfItemForWindow(ShelfItem* item, aura::Window* window) { |
| 47 item->type = GetShelfItemType(window); | 46 item->type = GetShelfItemType(window); |
| 48 | 47 |
| 49 item->status = STATUS_RUNNING; | 48 item->status = STATUS_RUNNING; |
| 50 if (wm::IsActiveWindow(window)) | 49 if (wm::IsActiveWindow(window)) |
| 51 item->status = STATUS_ACTIVE; | 50 item->status = STATUS_ACTIVE; |
| 52 else if (window->GetProperty(aura::client::kDrawAttentionKey)) | 51 else if (window->GetProperty(aura::client::kDrawAttentionKey)) |
| 53 item->status = STATUS_ATTENTION; | 52 item->status = STATUS_ATTENTION; |
| 54 | 53 |
| 55 const std::string* app_id = window->GetProperty(aura::client::kAppIdKey); | 54 const ShelfID* shelf_id = window->GetProperty(kShelfIDKey); |
| 56 item->app_launch_id = app_id ? AppLaunchId(*app_id) : AppLaunchId(); | 55 item->id = shelf_id ? *shelf_id : ShelfID(); |
| 57 | 56 |
| 58 // Prefer app icons over window icons, they're typically larger. | 57 // Prefer app icons over window icons, they're typically larger. |
| 59 gfx::ImageSkia* image = window->GetProperty(aura::client::kAppIconKey); | 58 gfx::ImageSkia* image = window->GetProperty(aura::client::kAppIconKey); |
| 60 if (!image || image->isNull()) | 59 if (!image || image->isNull()) |
| 61 image = window->GetProperty(aura::client::kWindowIconKey); | 60 image = window->GetProperty(aura::client::kWindowIconKey); |
| 62 if (!image || image->isNull()) { | 61 if (!image || image->isNull()) { |
| 63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 62 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 64 item->image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32).AsImageSkia(); | 63 item->image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32).AsImageSkia(); |
| 65 } else { | 64 } else { |
| 66 item->image = *image; | 65 item->image = *image; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ShelfWindowWatcher::UserWindowObserver::UserWindowObserver( | 100 ShelfWindowWatcher::UserWindowObserver::UserWindowObserver( |
| 102 ShelfWindowWatcher* window_watcher) | 101 ShelfWindowWatcher* window_watcher) |
| 103 : window_watcher_(window_watcher) {} | 102 : window_watcher_(window_watcher) {} |
| 104 | 103 |
| 105 ShelfWindowWatcher::UserWindowObserver::~UserWindowObserver() {} | 104 ShelfWindowWatcher::UserWindowObserver::~UserWindowObserver() {} |
| 106 | 105 |
| 107 void ShelfWindowWatcher::UserWindowObserver::OnWindowPropertyChanged( | 106 void ShelfWindowWatcher::UserWindowObserver::OnWindowPropertyChanged( |
| 108 aura::Window* window, | 107 aura::Window* window, |
| 109 const void* key, | 108 const void* key, |
| 110 intptr_t old) { | 109 intptr_t old) { |
| 111 if (key == aura::client::kAppIconKey || key == aura::client::kAppIdKey || | 110 if (key == aura::client::kAppIconKey || key == aura::client::kWindowIconKey || |
| 112 key == aura::client::kDrawAttentionKey || | 111 key == aura::client::kDrawAttentionKey || key == kPanelAttachedKey || |
| 113 key == aura::client::kWindowIconKey || key == kPanelAttachedKey || | 112 key == kShelfItemTypeKey || key == kShelfIDKey) { |
| 114 key == kShelfItemTypeKey) { | |
| 115 window_watcher_->OnUserWindowPropertyChanged(window); | 113 window_watcher_->OnUserWindowPropertyChanged(window); |
| 116 } | 114 } |
| 117 } | 115 } |
| 118 | 116 |
| 119 void ShelfWindowWatcher::UserWindowObserver::OnWindowDestroying( | 117 void ShelfWindowWatcher::UserWindowObserver::OnWindowDestroying( |
| 120 aura::Window* window) { | 118 aura::Window* window) { |
| 121 window_watcher_->OnUserWindowDestroying(window); | 119 window_watcher_->OnUserWindowDestroying(window); |
| 122 } | 120 } |
| 123 | 121 |
| 124 void ShelfWindowWatcher::UserWindowObserver::OnWindowVisibilityChanged( | 122 void ShelfWindowWatcher::UserWindowObserver::OnWindowVisibilityChanged( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 153 } | 151 } |
| 154 | 152 |
| 155 ShelfWindowWatcher::~ShelfWindowWatcher() { | 153 ShelfWindowWatcher::~ShelfWindowWatcher() { |
| 156 display::Screen::GetScreen()->RemoveObserver(this); | 154 display::Screen::GetScreen()->RemoveObserver(this); |
| 157 Shell::Get()->activation_client()->RemoveObserver(this); | 155 Shell::Get()->activation_client()->RemoveObserver(this); |
| 158 } | 156 } |
| 159 | 157 |
| 160 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { | 158 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { |
| 161 user_windows_with_items_.insert(window); | 159 user_windows_with_items_.insert(window); |
| 162 ShelfItem item; | 160 ShelfItem item; |
| 163 ShelfID id = model_->next_id(); | |
| 164 UpdateShelfItemForWindow(&item, window); | 161 UpdateShelfItemForWindow(&item, window); |
| 165 window->SetProperty(kShelfIDKey, id); | 162 model_->SetShelfItemDelegate(item.id, |
| 166 model_->SetShelfItemDelegate(id, | |
| 167 base::MakeUnique<ShelfWindowWatcherItemDelegate>( | 163 base::MakeUnique<ShelfWindowWatcherItemDelegate>( |
| 168 id, WmWindow::Get(window))); | 164 item.id, WmWindow::Get(window))); |
| 169 // Panels are inserted on the left so as not to push all existing panels over. | 165 // Panels are inserted on the left so as not to push all existing panels over. |
| 170 model_->AddAt(item.type == TYPE_APP_PANEL ? 0 : model_->item_count(), item); | 166 model_->AddAt(item.type == TYPE_APP_PANEL ? 0 : model_->item_count(), item); |
| 171 } | 167 } |
| 172 | 168 |
| 173 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { | 169 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { |
| 174 user_windows_with_items_.erase(window); | 170 user_windows_with_items_.erase(window); |
| 175 ShelfID shelf_id = window->GetProperty(kShelfIDKey); | 171 ShelfID* shelf_id = window->GetProperty(kShelfIDKey); |
| 176 DCHECK_NE(shelf_id, kInvalidShelfID); | 172 DCHECK(shelf_id); |
| 177 int index = model_->ItemIndexByID(shelf_id); | 173 DCHECK(!shelf_id->IsNull()); |
| 174 int index = model_->ItemIndexByID(*shelf_id); |
| 178 DCHECK_GE(index, 0); | 175 DCHECK_GE(index, 0); |
| 179 model_->RemoveItemAt(index); | 176 model_->RemoveItemAt(index); |
| 180 window->SetProperty(kShelfIDKey, kInvalidShelfID); | |
| 181 } | 177 } |
| 182 | 178 |
| 183 void ShelfWindowWatcher::OnContainerWindowDestroying(aura::Window* container) { | 179 void ShelfWindowWatcher::OnContainerWindowDestroying(aura::Window* container) { |
| 184 observed_container_windows_.Remove(container); | 180 observed_container_windows_.Remove(container); |
| 185 } | 181 } |
| 186 | 182 |
| 187 int ShelfWindowWatcher::GetShelfItemIndexForWindow(aura::Window* window) const { | 183 int ShelfWindowWatcher::GetShelfItemIndexForWindow(aura::Window* window) const { |
| 188 return model_->ItemIndexByID(window->GetProperty(kShelfIDKey)); | 184 ShelfID* shelf_id = window->GetProperty(kShelfIDKey); |
| 185 return shelf_id ? model_->ItemIndexByID(*shelf_id) : -1; |
| 189 } | 186 } |
| 190 | 187 |
| 191 void ShelfWindowWatcher::OnUserWindowAdded(aura::Window* window) { | 188 void ShelfWindowWatcher::OnUserWindowAdded(aura::Window* window) { |
| 192 // The window may already be tracked from a prior display or parent container. | 189 // The window may already be tracked from a prior display or parent container. |
| 193 if (observed_user_windows_.IsObserving(window)) | 190 if (observed_user_windows_.IsObserving(window)) |
| 194 return; | 191 return; |
| 195 | 192 |
| 196 observed_user_windows_.Add(window); | 193 observed_user_windows_.Add(window); |
| 197 | 194 |
| 198 // Add, update, or remove a ShelfItem for |window|, as needed. | 195 // Add, update, or remove a ShelfItem for |window|, as needed. |
| 199 OnUserWindowPropertyChanged(window); | 196 OnUserWindowPropertyChanged(window); |
| 200 } | 197 } |
| 201 | 198 |
| 202 void ShelfWindowWatcher::OnUserWindowDestroying(aura::Window* window) { | 199 void ShelfWindowWatcher::OnUserWindowDestroying(aura::Window* window) { |
| 203 if (observed_user_windows_.IsObserving(window)) | 200 if (observed_user_windows_.IsObserving(window)) |
| 204 observed_user_windows_.Remove(window); | 201 observed_user_windows_.Remove(window); |
| 205 | 202 |
| 206 if (user_windows_with_items_.count(window) > 0) | 203 if (user_windows_with_items_.count(window) > 0) |
| 207 RemoveShelfItem(window); | 204 RemoveShelfItem(window); |
| 208 DCHECK_EQ(0u, user_windows_with_items_.count(window)); | 205 DCHECK_EQ(0u, user_windows_with_items_.count(window)); |
| 209 } | 206 } |
| 210 | 207 |
| 211 void ShelfWindowWatcher::OnUserWindowPropertyChanged(aura::Window* window) { | 208 void ShelfWindowWatcher::OnUserWindowPropertyChanged(aura::Window* window) { |
| 212 if (GetShelfItemType(window) == TYPE_UNDEFINED) { | 209 if (GetShelfItemType(window) == TYPE_UNDEFINED || |
| 210 !window->GetProperty(kShelfIDKey)) { |
| 213 // Remove |window|'s ShelfItem if it was added by this ShelfWindowWatcher. | 211 // Remove |window|'s ShelfItem if it was added by this ShelfWindowWatcher. |
| 214 if (user_windows_with_items_.count(window) > 0) | 212 if (user_windows_with_items_.count(window) > 0) |
| 215 RemoveShelfItem(window); | 213 RemoveShelfItem(window); |
| 216 return; | 214 return; |
| 217 } | 215 } |
| 218 | 216 |
| 219 // Update an existing ShelfItem for |window| when a property has changed. | 217 // Update an existing ShelfItem for |window| when a property has changed. |
| 220 int index = GetShelfItemIndexForWindow(window); | 218 int index = GetShelfItemIndexForWindow(window); |
| 221 if (index > 0) { | 219 if (index > 0) { |
| 222 ShelfItem item = model_->items()[index]; | 220 ShelfItem item = model_->items()[index]; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 } | 259 } |
| 262 } | 260 } |
| 263 | 261 |
| 264 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { | 262 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |
| 265 } | 263 } |
| 266 | 264 |
| 267 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, | 265 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, |
| 268 uint32_t) {} | 266 uint32_t) {} |
| 269 | 267 |
| 270 } // namespace ash | 268 } // namespace ash |
| OLD | NEW |