Chromium Code Reviews| 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 || |
|
James Cook
2017/05/04 16:38:49
super nit: is there anything special about the ord
msw
2017/05/04 19:05:57
I put the two icons together to wrap a bit nicer,
| |
| 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->IsEmpty()); |
| 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); | |
|
James Cook
2017/05/04 16:38:49
Nice that we don't have to wipe the shelf ID anymo
msw
2017/05/04 19:05:57
Agreed.
| |
| 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. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 218 | 215 |
| 219 // Update an existing ShelfItem for |window| when a property has changed. | 216 // Update an existing ShelfItem for |window| when a property has changed. |
| 220 int index = GetShelfItemIndexForWindow(window); | 217 int index = GetShelfItemIndexForWindow(window); |
| 221 if (index > 0) { | 218 if (index > 0) { |
| 222 ShelfItem item = model_->items()[index]; | 219 ShelfItem item = model_->items()[index]; |
| 223 UpdateShelfItemForWindow(&item, window); | 220 UpdateShelfItemForWindow(&item, window); |
| 224 model_->Set(index, item); | 221 model_->Set(index, item); |
| 225 return; | 222 return; |
| 226 } | 223 } |
| 227 | 224 |
| 228 // Creates a new ShelfItem for |window|. | 225 // Creates a new ShelfItem for |window| if it has a non-empty ShelfID. |
| 229 AddShelfItem(window); | 226 if (window->GetProperty(kShelfIDKey)) |
|
James Cook
2017/05/04 16:38:49
maybe move this up and/or into the test for TYPE_U
msw
2017/05/04 19:05:57
Yeah, I guess if the id is cleared we should proba
| |
| 227 AddShelfItem(window); | |
| 230 } | 228 } |
| 231 | 229 |
| 232 void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason, | 230 void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason, |
| 233 aura::Window* gained_active, | 231 aura::Window* gained_active, |
| 234 aura::Window* lost_active) { | 232 aura::Window* lost_active) { |
| 235 if (gained_active && user_windows_with_items_.count(gained_active) > 0) | 233 if (gained_active && user_windows_with_items_.count(gained_active) > 0) |
| 236 OnUserWindowPropertyChanged(gained_active); | 234 OnUserWindowPropertyChanged(gained_active); |
| 237 if (lost_active && user_windows_with_items_.count(lost_active) > 0) | 235 if (lost_active && user_windows_with_items_.count(lost_active) > 0) |
| 238 OnUserWindowPropertyChanged(lost_active); | 236 OnUserWindowPropertyChanged(lost_active); |
| 239 } | 237 } |
| (...skipping 21 matching lines...) Expand all 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 |