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

Unified Diff: ui/aura/mus/property_converter.cc

Issue 2519583002: Add gfx::ImageSkia and icon support to aura::PropertyConverter. (Closed)
Patch Set: Fix ConvertPropertyForTransport; add unit test. Created 4 years, 1 month 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 | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/property_converter.cc
diff --git a/ui/aura/mus/property_converter.cc b/ui/aura/mus/property_converter.cc
index 6837d506e425d91130e572d0c882a4647ebecb31..151e480c776112bb72b6e06fa9c81226bfa9973b 100644
--- a/ui/aura/mus/property_converter.cc
+++ b/ui/aura/mus/property_converter.cc
@@ -54,6 +54,20 @@ bool PropertyConverter::ConvertPropertyForTransport(
if (transport_name->empty())
return false;
+ auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key);
+ if (image_properties_.count(image_key) > 0) {
+ const gfx::ImageSkia* value = window->GetProperty(image_key);
+ if (value) {
+ // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
+ SkBitmap bitmap = value->GetRepresentation(1.f).sk_bitmap();
+ *transport_value = base::MakeUnique<std::vector<uint8_t>>(
+ mojo::ConvertTo<std::vector<uint8_t>>(bitmap));
+ } else {
+ *transport_value = base::MakeUnique<std::vector<uint8_t>>();
+ }
+ return true;
+ }
+
auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key);
if (rect_properties_.count(rect_key) > 0) {
*transport_value = GetArray(window, rect_key);
@@ -85,6 +99,10 @@ std::string PropertyConverter::GetTransportNameForPropertyKey(const void* key) {
if (primitive_properties_.count(key) > 0)
return primitive_properties_[key].second;
+ auto image_key = static_cast<const WindowProperty<gfx::ImageSkia*>*>(key);
+ if (image_properties_.count(image_key) > 0)
+ return image_properties_[image_key];
+
auto rect_key = static_cast<const WindowProperty<gfx::Rect*>*>(key);
if (rect_properties_.count(rect_key) > 0)
return rect_properties_[rect_key];
@@ -120,6 +138,17 @@ void PropertyConverter::SetPropertyFromTransportValue(
}
}
+ for (const auto& image_property : image_properties_) {
+ if (image_property.second == transport_name) {
+ // TODO(msw): Validate the data somehow, before trying to convert?
+ // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
+ const SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(*data);
+ const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+ window->SetProperty(image_property.first, new gfx::ImageSkia(image));
+ return;
+ }
+ }
+
for (const auto& rect_property : rect_properties_) {
if (rect_property.second == transport_name) {
if (data->size() != 16u) {
@@ -154,6 +183,12 @@ void PropertyConverter::SetPropertyFromTransportValue(
}
void PropertyConverter::RegisterProperty(
+ const WindowProperty<gfx::ImageSkia*>* property,
+ const char* transport_name) {
+ image_properties_[property] = transport_name;
+}
+
+void PropertyConverter::RegisterProperty(
const WindowProperty<gfx::Rect*>* property,
const char* transport_name) {
rect_properties_[property] = transport_name;
« no previous file with comments | « ui/aura/mus/property_converter.h ('k') | ui/aura/mus/property_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698