Remove hasRepresentation and just use 1x png result
authorKevin Sawicki <kevinsawicki@gmail.com>
Mon, 6 Mar 2017 22:55:57 +0000 (14:55 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 7 Mar 2017 20:27:55 +0000 (12:27 -0800)
atom/common/api/atom_api_native_image.cc
atom/common/api/atom_api_native_image.h
spec/api-native-image-spec.js

index b68ddda592c6900f80e2cfcea07314f131378a7f..7437090111a11dd1d3d3447d9d70a4411f927470 100644 (file)
@@ -231,8 +231,8 @@ HICON NativeImage::GetHICON(int size) {
 #endif
 
 v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
-  if (HasRepresentation(1.0)) {
-    scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+  scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+  if (IsEmpty() || png->size() > 0) {
     const char* data = reinterpret_cast<const char*>(png->front());
     const size_t length = static_cast<size_t>(png->size());
     return node::Buffer::Copy(isolate, data, length).ToLocalChecked();
@@ -264,12 +264,11 @@ v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
 }
 
 std::string NativeImage::ToDataURL() {
-  if (HasRepresentation(1.0)) {
-    scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+  scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+  if (IsEmpty() || png->size() > 0)
     return webui::GetPngDataUrl(png->front(), png->size());
-  } else {
+  else
     return webui::GetBitmapDataUrl(image_.AsBitmap());
-  }
 }
 
 v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
@@ -304,10 +303,6 @@ bool NativeImage::IsEmpty() {
   return image_.IsEmpty();
 }
 
-bool NativeImage::HasRepresentation(float scale_factor) {
-  return image_.AsImageSkia().HasRepresentation(scale_factor);
-}
-
 gfx::Size NativeImage::GetSize() {
   return image_.Size();
 }
@@ -479,7 +474,6 @@ void NativeImage::BuildPrototype(
       .SetMethod("resize", &NativeImage::Resize)
       .SetMethod("crop", &NativeImage::Crop)
       .SetMethod("getAspectRatio", &NativeImage::GetAspectRatio)
-      .SetMethod("hasRepresentation", &NativeImage::HasRepresentation)
       // TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
       .SetMethod("toPng", &NativeImage::ToPNG)
       .SetMethod("toJpeg", &NativeImage::ToJPEG);
index a653f15e0a71deb27580a2199539333b5d6fc10c..ee1b5f5d4b815560b9f08a3c50ec3961fa84da1b 100644 (file)
@@ -83,7 +83,6 @@ class NativeImage : public mate::Wrappable<NativeImage> {
                                  const gfx::Rect& rect);
   std::string ToDataURL();
   bool IsEmpty();
-  bool HasRepresentation(float scale_factor);
   gfx::Size GetSize();
   float GetAspectRatio();
 
index fd6aee9f1eabf6a25cd7b000fd7ee8e4f92dd0d7..7e32fef56123e9ed31065b9f269e45318ad5e5a2 100644 (file)
@@ -9,7 +9,6 @@ describe('nativeImage module', () => {
     it('returns an empty image', () => {
       const empty = nativeImage.createEmpty()
       assert.equal(empty.isEmpty(), true)
-      assert.equal(empty.hasRepresentation(1.0), false)
       assert.equal(empty.getAspectRatio(), 1)
       assert.equal(empty.toDataURL(), 'data:image/png;base64,')
       assert.deepEqual(empty.getSize(), {width: 0, height: 0})
@@ -94,12 +93,9 @@ describe('nativeImage module', () => {
         scaleFactor: 2.0
       })
       assert.deepEqual(imageB.getSize(), {width: 269, height: 95})
-      assert.equal(imageB.hasRepresentation(1.0), false)
-      assert.equal(imageB.hasRepresentation(2.0), true)
 
       const imageC = nativeImage.createFromDataURL(imageB.toDataURL())
       assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
-      assert.equal(imageC.hasRepresentation(1.0), false)
       assert(imageB.toBitmap().equals(imageC.toBitmap()))
     })
   })
@@ -113,12 +109,9 @@ describe('nativeImage module', () => {
         scaleFactor: 2.0
       })
       assert.deepEqual(imageB.getSize(), {width: 269, height: 95})
-      assert.equal(imageB.hasRepresentation(1.0), false)
-      assert.equal(imageB.hasRepresentation(2.0), true)
 
       const imageC = nativeImage.createFromBuffer(imageB.toPNG())
       assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
-      assert.equal(imageC.hasRepresentation(1.0), true)
       assert(imageB.toBitmap().equals(imageC.toBitmap()))
     })
   })