summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjamescook <jamescook@chromium.org>2016-03-25 11:11:53 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-25 18:13:27 +0000
commitcac8709a0d06fee9d9f048b9e779ce59902673a5 (patch)
treef43374d99bd8f0310b9f26d39487b20354849678 /ash
parent260528431247b958483c9f7f2e1c6525aba077d7 (diff)
downloadchromium_src-cac8709a0d06fee9d9f048b9e779ce59902673a5.zip
chromium_src-cac8709a0d06fee9d9f048b9e779ce59902673a5.tar.gz
chromium_src-cac8709a0d06fee9d9f048b9e779ce59902673a5.tar.bz2
Mash: Show app icons in shelf based on the Widget's app icon
* Use the large icon from WidgetDelegate::GetWindowAppIcon(). * In the mojo app's NativeWidgetMus, serialize the icon's SkBitmap as a vector of bytes and set it as a shared window property. * In the window manager, pass the serialized icon to any UserWindowObservers. * In the system UI, deserialize the icon and use it on the shelf. * Set an icon in task_viewer as a demonstration. The window property serialization is handled by a custom TypeConverter for vector<uint8>, SkBitmap. In the future it would be nice to use the serialized form of the Skia Mojom struct skia.Bitmap, but that will require Mojo to generate a public API to read the serialized bytes. Also fixed an issue where the app's primary widget and the window manager's non-client-frame widget would fight over window titles. A screenshot of the shelf is attached to the bug. BUG=595850 TEST=launch mash, run mojo:task_viewer, note QuickLaunch shelf icon is default but TaskViewer icon is a gear Review URL: https://codereview.chromium.org/1824183002 Cr-Commit-Position: refs/heads/master@{#383312}
Diffstat (limited to 'ash')
-rw-r--r--ash/mus/shelf_delegate_mus.cc40
-rw-r--r--ash/mus/shelf_delegate_mus.h2
2 files changed, 39 insertions, 3 deletions
diff --git a/ash/mus/shelf_delegate_mus.cc b/ash/mus/shelf_delegate_mus.cc
index 510bb1b..5b06eda 100644
--- a/ash/mus/shelf_delegate_mus.cc
+++ b/ash/mus/shelf_delegate_mus.cc
@@ -19,6 +19,7 @@
#include "mojo/shell/public/cpp/connector.h"
#include "ui/aura/mus/mus_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/mus/window_manager_connection.h"
@@ -78,6 +79,25 @@ class ShelfItemDelegateMus : public ShelfItemDelegate {
DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus);
};
+// Returns an icon image from a serialized SkBitmap, or the default shelf icon
+// image if the bitmap is empty. Assumes the bitmap is a 1x icon.
+// TODO(jamescook): Support other scale factors.
+gfx::ImageSkia GetShelfIconFromBitmap(
+ const mojo::Array<uint8_t>& serialized_bitmap) {
+ // Convert the data to an ImageSkia.
+ SkBitmap bitmap = mojo::ConvertTo<SkBitmap, const std::vector<uint8_t>>(
+ serialized_bitmap.storage());
+ gfx::ImageSkia icon_image;
+ if (!bitmap.isNull()) {
+ icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+ } else {
+ // Use default icon.
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ icon_image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
+ }
+ return icon_image;
+}
+
} // namespace
ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model)
@@ -150,9 +170,7 @@ void ShelfDelegateMus::OnUserWindowAdded(
ShelfItem item;
item.type = TYPE_PLATFORM_APP;
item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING;
- // TODO(msw): Support actual window icons.
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
+ item.image = GetShelfIconFromBitmap(user_window->window_app_icon);
ShelfID shelf_id = model_->next_id();
window_id_to_shelf_id_.insert(
@@ -195,6 +213,22 @@ void ShelfDelegateMus::OnUserWindowTitleChanged(
model_->Set(index, *iter);
}
+void ShelfDelegateMus::OnUserWindowAppIconChanged(
+ uint32_t window_id,
+ mojo::Array<uint8_t> app_icon) {
+ // Find the shelf ID for this window.
+ DCHECK(window_id_to_shelf_id_.count(window_id));
+ ShelfID shelf_id = window_id_to_shelf_id_[window_id];
+ DCHECK_GT(shelf_id, 0);
+
+ // Update the icon in the ShelfItem.
+ int index = model_->ItemIndexByID(shelf_id);
+ DCHECK_GE(index, 0);
+ ShelfItem item = *model_->ItemByID(shelf_id);
+ item.image = GetShelfIconFromBitmap(app_icon);
+ model_->Set(index, item);
+}
+
void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id,
bool has_focus) {
DCHECK(window_id_to_shelf_id_.count(window_id));
diff --git a/ash/mus/shelf_delegate_mus.h b/ash/mus/shelf_delegate_mus.h
index 47364fc..333a84d 100644
--- a/ash/mus/shelf_delegate_mus.h
+++ b/ash/mus/shelf_delegate_mus.h
@@ -41,6 +41,8 @@ class ShelfDelegateMus : public ShelfDelegate,
void OnUserWindowRemoved(uint32_t window_id) override;
void OnUserWindowTitleChanged(uint32_t window_id,
const mojo::String& window_title) override;
+ void OnUserWindowAppIconChanged(uint32_t window_id,
+ mojo::Array<uint8_t> app_icon) override;
void OnUserWindowFocusChanged(uint32_t window_id, bool has_focus) override;
ShelfModel* model_;