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 "ash/shelf/shelf.h" | 7 #include "ash/shelf/shelf.h" |
8 #include "ash/shelf/shelf_item_delegate.h" | 8 #include "ash/shelf/shelf_item_delegate.h" |
9 #include "ash/shelf/shelf_item_delegate_manager.h" | 9 #include "ash/shelf/shelf_item_delegate_manager.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
11 #include "ash/shelf/shelf_model.h" | 11 #include "ash/shelf/shelf_model.h" |
12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "components/mus/public/cpp/property_type_converters.h" | 15 #include "components/mus/public/cpp/property_type_converters.h" |
16 #include "components/mus/public/cpp/window.h" | 16 #include "components/mus/public/cpp/window.h" |
17 #include "components/mus/public/cpp/window_property.h" | 17 #include "components/mus/public/cpp/window_property.h" |
18 #include "mojo/common/common_type_converters.h" | 18 #include "mojo/common/common_type_converters.h" |
19 #include "mojo/shell/public/cpp/connector.h" | 19 #include "mojo/shell/public/cpp/connector.h" |
20 #include "ui/aura/mus/mus_util.h" | 20 #include "ui/aura/mus/mus_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/image/image_skia.h" |
22 #include "ui/resources/grit/ui_resources.h" | 23 #include "ui/resources/grit/ui_resources.h" |
23 #include "ui/views/mus/window_manager_connection.h" | 24 #include "ui/views/mus/window_manager_connection.h" |
24 | 25 |
25 using mash::wm::mojom::UserWindowController; | 26 using mash::wm::mojom::UserWindowController; |
26 | 27 |
27 namespace ash { | 28 namespace ash { |
28 namespace sysui { | 29 namespace sysui { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 void Close() override { NOTIMPLEMENTED(); } | 72 void Close() override { NOTIMPLEMENTED(); } |
72 | 73 |
73 // TODO(msw): Support multiple open windows per button. | 74 // TODO(msw): Support multiple open windows per button. |
74 uint32_t window_id_; | 75 uint32_t window_id_; |
75 base::string16 title_; | 76 base::string16 title_; |
76 UserWindowController* user_window_controller_; | 77 UserWindowController* user_window_controller_; |
77 | 78 |
78 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); | 79 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); |
79 }; | 80 }; |
80 | 81 |
| 82 // Returns an icon image from a serialized SkBitmap, or the default shelf icon |
| 83 // image if the bitmap is empty. Assumes the bitmap is a 1x icon. |
| 84 // TODO(jamescook): Support other scale factors. |
| 85 gfx::ImageSkia GetShelfIconFromBitmap( |
| 86 const mojo::Array<uint8_t>& serialized_bitmap) { |
| 87 // Convert the data to an ImageSkia. |
| 88 SkBitmap bitmap = mojo::ConvertTo<SkBitmap, const std::vector<uint8_t>>( |
| 89 serialized_bitmap.storage()); |
| 90 gfx::ImageSkia icon_image; |
| 91 if (!bitmap.isNull()) { |
| 92 icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 93 } else { |
| 94 // Use default icon. |
| 95 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 96 icon_image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); |
| 97 } |
| 98 return icon_image; |
| 99 } |
| 100 |
81 } // namespace | 101 } // namespace |
82 | 102 |
83 ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model) | 103 ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model) |
84 : model_(model), binding_(this) { | 104 : model_(model), binding_(this) { |
85 mojo::Connector* connector = | 105 mojo::Connector* connector = |
86 views::WindowManagerConnection::Get()->connector(); | 106 views::WindowManagerConnection::Get()->connector(); |
87 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_); | 107 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_); |
88 user_window_controller_->AddUserWindowObserver( | 108 user_window_controller_->AddUserWindowObserver( |
89 binding_.CreateInterfacePtrAndBind()); | 109 binding_.CreateInterfacePtrAndBind()); |
90 } | 110 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { | 163 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { |
144 for (size_t i = 0; i < user_windows.size(); ++i) | 164 for (size_t i = 0; i < user_windows.size(); ++i) |
145 OnUserWindowAdded(std::move(user_windows[i])); | 165 OnUserWindowAdded(std::move(user_windows[i])); |
146 } | 166 } |
147 | 167 |
148 void ShelfDelegateMus::OnUserWindowAdded( | 168 void ShelfDelegateMus::OnUserWindowAdded( |
149 mash::wm::mojom::UserWindowPtr user_window) { | 169 mash::wm::mojom::UserWindowPtr user_window) { |
150 ShelfItem item; | 170 ShelfItem item; |
151 item.type = TYPE_PLATFORM_APP; | 171 item.type = TYPE_PLATFORM_APP; |
152 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; | 172 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; |
153 // TODO(msw): Support actual window icons. | 173 item.image = GetShelfIconFromBitmap(user_window->window_app_icon); |
154 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
155 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); | |
156 | 174 |
157 ShelfID shelf_id = model_->next_id(); | 175 ShelfID shelf_id = model_->next_id(); |
158 window_id_to_shelf_id_.insert( | 176 window_id_to_shelf_id_.insert( |
159 std::make_pair(user_window->window_id, shelf_id)); | 177 std::make_pair(user_window->window_id, shelf_id)); |
160 model_->Add(item); | 178 model_->Add(item); |
161 | 179 |
162 ShelfItemDelegateManager* manager = | 180 ShelfItemDelegateManager* manager = |
163 Shell::GetInstance()->shelf_item_delegate_manager(); | 181 Shell::GetInstance()->shelf_item_delegate_manager(); |
164 scoped_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus( | 182 scoped_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus( |
165 user_window->window_id, user_window->window_title.To<base::string16>(), | 183 user_window->window_id, user_window->window_title.To<base::string16>(), |
(...skipping 22 matching lines...) Expand all Loading... |
188 // There's nothing in the ShelfItem that needs to be updated. But we still | 206 // There's nothing in the ShelfItem that needs to be updated. But we still |
189 // need to update the ShelfModel so that the observers can pick up any | 207 // need to update the ShelfModel so that the observers can pick up any |
190 // changes. | 208 // changes. |
191 int index = model_->ItemIndexByID(shelf_id); | 209 int index = model_->ItemIndexByID(shelf_id); |
192 DCHECK_GE(index, 0); | 210 DCHECK_GE(index, 0); |
193 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); | 211 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); |
194 DCHECK(iter != model_->items().end()); | 212 DCHECK(iter != model_->items().end()); |
195 model_->Set(index, *iter); | 213 model_->Set(index, *iter); |
196 } | 214 } |
197 | 215 |
| 216 void ShelfDelegateMus::OnUserWindowAppIconChanged( |
| 217 uint32_t window_id, |
| 218 mojo::Array<uint8_t> app_icon) { |
| 219 // Find the shelf ID for this window. |
| 220 DCHECK(window_id_to_shelf_id_.count(window_id)); |
| 221 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; |
| 222 DCHECK_GT(shelf_id, 0); |
| 223 |
| 224 // Update the icon in the ShelfItem. |
| 225 int index = model_->ItemIndexByID(shelf_id); |
| 226 DCHECK_GE(index, 0); |
| 227 ShelfItem item = *model_->ItemByID(shelf_id); |
| 228 item.image = GetShelfIconFromBitmap(app_icon); |
| 229 model_->Set(index, item); |
| 230 } |
| 231 |
198 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id, | 232 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id, |
199 bool has_focus) { | 233 bool has_focus) { |
200 DCHECK(window_id_to_shelf_id_.count(window_id)); | 234 DCHECK(window_id_to_shelf_id_.count(window_id)); |
201 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; | 235 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; |
202 int index = model_->ItemIndexByID(shelf_id); | 236 int index = model_->ItemIndexByID(shelf_id); |
203 DCHECK_GE(index, 0); | 237 DCHECK_GE(index, 0); |
204 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); | 238 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); |
205 DCHECK(iter != model_->items().end()); | 239 DCHECK(iter != model_->items().end()); |
206 ShelfItem item = *iter; | 240 ShelfItem item = *iter; |
207 item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING; | 241 item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING; |
208 model_->Set(index, item); | 242 model_->Set(index, item); |
209 } | 243 } |
210 | 244 |
211 } // namespace sysui | 245 } // namespace sysui |
212 } // namespace ash | 246 } // namespace ash |
OLD | NEW |