| 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" | |
| 11 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/public/cpp/window_properties.h" | 11 #include "ash/public/cpp/window_properties.h" |
| 13 #include "ash/shelf/shelf_constants.h" | 12 #include "ash/shelf/shelf_constants.h" |
| 14 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
| 15 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 14 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 16 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 17 #include "ash/shell_port.h" | 16 #include "ash/shell_port.h" |
| 18 #include "ash/wm/window_state.h" | 17 #include "ash/wm/window_state.h" |
| 19 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
| 20 #include "ash/wm_window.h" | 19 #include "ash/wm_window.h" |
| 21 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 22 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/display/display.h" | 24 #include "ui/display/display.h" |
| 26 #include "ui/display/screen.h" | 25 #include "ui/display/screen.h" |
| 27 #include "ui/resources/grit/ui_resources.h" | 26 #include "ui/resources/grit/ui_resources.h" |
| 28 #include "ui/wm/public/activation_client.h" | 27 #include "ui/wm/public/activation_client.h" |
| 29 | 28 |
| 30 namespace ash { | 29 namespace ash { |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 // Returns the shelf item type, with special temporary behavior for Mash: | 32 // Returns the window's shelf item type property value. |
| 34 // Mash provides a default shelf item type (TYPE_APP) for non-ignored windows. | |
| 35 ShelfItemType GetShelfItemType(aura::Window* window) { | 33 ShelfItemType GetShelfItemType(aura::Window* window) { |
| 36 // TODO(msw): Remove Mash default ShelfItemType assignment. crbug.com/722496 | |
| 37 if (Shell::GetAshConfig() == Config::MASH && | |
| 38 window->GetProperty(kShelfItemTypeKey) == TYPE_UNDEFINED && | |
| 39 !wm::GetWindowState(window)->ignored_by_shelf()) { | |
| 40 return TYPE_APP; | |
| 41 } | |
| 42 return static_cast<ShelfItemType>(window->GetProperty(kShelfItemTypeKey)); | 34 return static_cast<ShelfItemType>(window->GetProperty(kShelfItemTypeKey)); |
| 43 } | 35 } |
| 44 | 36 |
| 45 // Returns the shelf id, with special temporary behavior for Mash: | 37 // Returns the window's shelf id property value. |
| 46 // Mash provides a default shelf ids for non-ignored windows. | |
| 47 ShelfID GetShelfID(aura::Window* window) { | 38 ShelfID GetShelfID(aura::Window* window) { |
| 48 // TODO(msw): Remove Mash default ShelfID assignment. crbug.com/722496 | |
| 49 if (Shell::GetAshConfig() == Config::MASH && | |
| 50 !window->GetProperty(kShelfIDKey) && | |
| 51 !wm::GetWindowState(window)->ignored_by_shelf()) { | |
| 52 static int id = 0; | |
| 53 const ash::ShelfID shelf_id(base::IntToString(id++)); | |
| 54 window->SetProperty(kShelfIDKey, new std::string(shelf_id.Serialize())); | |
| 55 return shelf_id; | |
| 56 } | |
| 57 return ShelfID::Deserialize(window->GetProperty(kShelfIDKey)); | 39 return ShelfID::Deserialize(window->GetProperty(kShelfIDKey)); |
| 58 } | 40 } |
| 59 | 41 |
| 60 // Update the ShelfItem from relevant window properties. | 42 // Update the ShelfItem from relevant window properties. |
| 61 void UpdateShelfItemForWindow(ShelfItem* item, aura::Window* window) { | 43 void UpdateShelfItemForWindow(ShelfItem* item, aura::Window* window) { |
| 44 DCHECK(item->id.IsNull() || item->id == GetShelfID(window)); |
| 62 item->id = GetShelfID(window); | 45 item->id = GetShelfID(window); |
| 63 item->type = GetShelfItemType(window); | 46 item->type = GetShelfItemType(window); |
| 64 | 47 |
| 65 item->status = STATUS_RUNNING; | 48 item->status = STATUS_RUNNING; |
| 66 if (wm::IsActiveWindow(window)) | 49 if (wm::IsActiveWindow(window)) |
| 67 item->status = STATUS_ACTIVE; | 50 item->status = STATUS_ACTIVE; |
| 68 else if (window->GetProperty(aura::client::kDrawAttentionKey)) | 51 else if (window->GetProperty(aura::client::kDrawAttentionKey)) |
| 69 item->status = STATUS_ATTENTION; | 52 item->status = STATUS_ATTENTION; |
| 70 | 53 |
| 71 // Prefer app icons over window icons, they're typically larger. | 54 // Prefer app icons over window icons, they're typically larger. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 ShelfWindowWatcher::UserWindowObserver::UserWindowObserver( | 97 ShelfWindowWatcher::UserWindowObserver::UserWindowObserver( |
| 115 ShelfWindowWatcher* window_watcher) | 98 ShelfWindowWatcher* window_watcher) |
| 116 : window_watcher_(window_watcher) {} | 99 : window_watcher_(window_watcher) {} |
| 117 | 100 |
| 118 ShelfWindowWatcher::UserWindowObserver::~UserWindowObserver() {} | 101 ShelfWindowWatcher::UserWindowObserver::~UserWindowObserver() {} |
| 119 | 102 |
| 120 void ShelfWindowWatcher::UserWindowObserver::OnWindowPropertyChanged( | 103 void ShelfWindowWatcher::UserWindowObserver::OnWindowPropertyChanged( |
| 121 aura::Window* window, | 104 aura::Window* window, |
| 122 const void* key, | 105 const void* key, |
| 123 intptr_t old) { | 106 intptr_t old) { |
| 124 // ShelfIDs should never change except when replacing Mash temporary defaults. | |
| 125 // TODO(msw): Remove Mash default ShelfID handling. crbug.com/722496 | |
| 126 if (Shell::GetAshConfig() == Config::MASH && key == kShelfIDKey) { | |
| 127 ShelfID old_id = ShelfID::Deserialize(reinterpret_cast<std::string*>(old)); | |
| 128 ShelfID new_id = ShelfID::Deserialize(window->GetProperty(kShelfIDKey)); | |
| 129 if (old_id != new_id && !old_id.IsNull() && !new_id.IsNull()) { | |
| 130 // Id changing is not supported; remove the item and it will be re-added. | |
| 131 window_watcher_->user_windows_with_items_.erase(window); | |
| 132 const int index = window_watcher_->model_->ItemIndexByID(old_id); | |
| 133 window_watcher_->model_->RemoveItemAt(index); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 if (key == aura::client::kAppIconKey || key == aura::client::kWindowIconKey || | 107 if (key == aura::client::kAppIconKey || key == aura::client::kWindowIconKey || |
| 138 key == aura::client::kDrawAttentionKey || key == kPanelAttachedKey || | 108 key == aura::client::kDrawAttentionKey || key == kPanelAttachedKey || |
| 139 key == kShelfItemTypeKey || key == kShelfIDKey) { | 109 key == kShelfItemTypeKey || key == kShelfIDKey) { |
| 140 window_watcher_->OnUserWindowPropertyChanged(window); | 110 window_watcher_->OnUserWindowPropertyChanged(window); |
| 141 } | 111 } |
| 142 } | 112 } |
| 143 | 113 |
| 144 void ShelfWindowWatcher::UserWindowObserver::OnWindowDestroying( | 114 void ShelfWindowWatcher::UserWindowObserver::OnWindowDestroying( |
| 145 aura::Window* window) { | 115 aura::Window* window) { |
| 146 window_watcher_->OnUserWindowDestroying(window); | 116 window_watcher_->OnUserWindowDestroying(window); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 ShelfWindowWatcher::~ShelfWindowWatcher() { | 150 ShelfWindowWatcher::~ShelfWindowWatcher() { |
| 181 display::Screen::GetScreen()->RemoveObserver(this); | 151 display::Screen::GetScreen()->RemoveObserver(this); |
| 182 Shell::Get()->activation_client()->RemoveObserver(this); | 152 Shell::Get()->activation_client()->RemoveObserver(this); |
| 183 } | 153 } |
| 184 | 154 |
| 185 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { | 155 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { |
| 186 user_windows_with_items_.insert(window); | 156 user_windows_with_items_.insert(window); |
| 187 ShelfItem item; | 157 ShelfItem item; |
| 188 UpdateShelfItemForWindow(&item, window); | 158 UpdateShelfItemForWindow(&item, window); |
| 189 | 159 |
| 190 // ShelfWindowWatcher[ItemDelegate] doesn't support multiple windows per item, | |
| 191 // but this can happen in Mash (eg. when multiple browser windows are open). | |
| 192 // Assign a unique launch id in this case to avoid crashing on DCHECKs. | |
| 193 // TODO(msw): Remove Mash duplicate ShelfID handling. crbug.com/722496 | |
| 194 if (Shell::GetAshConfig() == Config::MASH && | |
| 195 model_->ItemIndexByID(item.id) > 0) { | |
| 196 static int id = 0; | |
| 197 item.id.launch_id = base::IntToString(id++); | |
| 198 } | |
| 199 | |
| 200 model_->SetShelfItemDelegate(item.id, | 160 model_->SetShelfItemDelegate(item.id, |
| 201 base::MakeUnique<ShelfWindowWatcherItemDelegate>( | 161 base::MakeUnique<ShelfWindowWatcherItemDelegate>( |
| 202 item.id, WmWindow::Get(window))); | 162 item.id, WmWindow::Get(window))); |
| 203 // Panels are inserted on the left so as not to push all existing panels over. | 163 // Panels are inserted on the left so as not to push all existing panels over. |
| 204 model_->AddAt(item.type == TYPE_APP_PANEL ? 0 : model_->item_count(), item); | 164 model_->AddAt(item.type == TYPE_APP_PANEL ? 0 : model_->item_count(), item); |
| 205 } | 165 } |
| 206 | 166 |
| 207 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { | 167 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { |
| 208 user_windows_with_items_.erase(window); | 168 user_windows_with_items_.erase(window); |
| 209 const ShelfID shelf_id = GetShelfID(window); | 169 const ShelfID shelf_id = GetShelfID(window); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 255 } |
| 296 } | 256 } |
| 297 | 257 |
| 298 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { | 258 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |
| 299 } | 259 } |
| 300 | 260 |
| 301 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, | 261 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, |
| 302 uint32_t) {} | 262 uint32_t) {} |
| 303 | 263 |
| 304 } // namespace ash | 264 } // namespace ash |
| OLD | NEW |