Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1867)

Unified Diff: ash/mus/shelf_delegate_mus.cc

Issue 1824183002: Mash: Show app icons in shelf based on the Widget's app icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more review comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/mus/shelf_delegate_mus.h ('k') | components/mus/public/cpp/lib/property_type_converters.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/mus/shelf_delegate_mus.cc
diff --git a/ash/mus/shelf_delegate_mus.cc b/ash/mus/shelf_delegate_mus.cc
index 510bb1b79d9409f3db96dcf5151a07bd0ac458a4..5b06edaa1e699bd4fa827ec5b90e30cd4d540f05 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));
« no previous file with comments | « ash/mus/shelf_delegate_mus.h ('k') | components/mus/public/cpp/lib/property_type_converters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698