move image converter to gin (#19655)

This commit is contained in:
Micha Hanselmann 2019-08-14 19:18:34 -07:00 committed by Cheng Zhao
parent 27b2747b61
commit d0c7a91a50
6 changed files with 56 additions and 47 deletions

View file

@ -472,7 +472,8 @@ filenames = {
"shell/common/gin_converters/file_dialog_converter.h", "shell/common/gin_converters/file_dialog_converter.h",
"shell/common/gin_converters/file_path_converter.h", "shell/common/gin_converters/file_path_converter.h",
"shell/common/gin_converters/gurl_converter.h", "shell/common/gin_converters/gurl_converter.h",
"shell/common/gin_converters/image_converter_gin_adapter.h", "shell/common/gin_converters/image_converter.cc",
"shell/common/gin_converters/image_converter.h",
"shell/common/gin_converters/message_box_converter.cc", "shell/common/gin_converters/message_box_converter.cc",
"shell/common/gin_converters/message_box_converter.h", "shell/common/gin_converters/message_box_converter.h",
"shell/common/gin_converters/native_window_converter.h", "shell/common/gin_converters/native_window_converter.h",
@ -506,7 +507,6 @@ filenames = {
"shell/common/native_mate_converters/gfx_converter.cc", "shell/common/native_mate_converters/gfx_converter.cc",
"shell/common/native_mate_converters/gfx_converter.h", "shell/common/native_mate_converters/gfx_converter.h",
"shell/common/native_mate_converters/gurl_converter.h", "shell/common/native_mate_converters/gurl_converter.h",
"shell/common/native_mate_converters/image_converter.cc",
"shell/common/native_mate_converters/image_converter.h", "shell/common/native_mate_converters/image_converter.h",
"shell/common/native_mate_converters/map_converter.h", "shell/common/native_mate_converters/map_converter.h",
"shell/common/native_mate_converters/native_window_converter.h", "shell/common/native_mate_converters/native_window_converter.h",

View file

@ -1,14 +1,14 @@
// Copyright (c) 2014 GitHub, Inc. // Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "shell/common/native_mate_converters/image_converter.h" #include "shell/common/gin_converters/image_converter.h"
#include "shell/common/api/atom_api_native_image.h" #include "shell/common/api/atom_api_native_image.h"
#include "shell/common/native_mate_converters/file_path_converter.h" #include "shell/common/gin_converters/file_path_converter.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
namespace mate { namespace gin {
bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate, bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
@ -27,8 +27,9 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
if (val->IsNull()) if (val->IsNull())
return true; return true;
Handle<electron::api::NativeImage> native_image; // TODO(deermichel): remove mate:: after dropping mate
if (!ConvertFromV8(isolate, val, &native_image)) mate::Handle<electron::api::NativeImage> native_image;
if (!mate::ConvertFromV8(isolate, val, &native_image))
return false; return false;
*out = native_image->image(); *out = native_image->image();
@ -40,4 +41,4 @@ v8::Local<v8::Value> Converter<gfx::Image>::ToV8(v8::Isolate* isolate,
return ConvertToV8(isolate, electron::api::NativeImage::Create(isolate, val)); return ConvertToV8(isolate, electron::api::NativeImage::Create(isolate, val));
} }
} // namespace mate } // namespace gin

View file

@ -0,0 +1,34 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_H_
#include "gin/converter.h"
namespace gfx {
class Image;
class ImageSkia;
} // namespace gfx
namespace gin {
template <>
struct Converter<gfx::ImageSkia> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::ImageSkia* out);
};
template <>
struct Converter<gfx::Image> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::Image* out);
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Image& val);
};
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_H_

View file

@ -1,29 +0,0 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_GIN_ADAPTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_GIN_ADAPTER_H_
#include "gin/converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
// TODO(deermichel): replace adapter with real implementation after removing
// mate
// -- this adapter forwards all conversions to the existing mate converter --
// (other direction might be preferred, but this is safer for now :D)
namespace gin {
template <>
struct Converter<gfx::ImageSkia> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::ImageSkia* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_GIN_ADAPTER_H_

View file

@ -5,7 +5,7 @@
#include "shell/common/gin_converters/message_box_converter.h" #include "shell/common/gin_converters/message_box_converter.h"
#include "gin/dictionary.h" #include "gin/dictionary.h"
#include "shell/common/gin_converters/image_converter_gin_adapter.h" #include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_converters/native_window_converter.h" #include "shell/common/gin_converters/native_window_converter.h"
namespace gin { namespace gin {

View file

@ -6,11 +6,7 @@
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_ #define SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_
#include "native_mate/converter.h" #include "native_mate/converter.h"
#include "shell/common/gin_converters/image_converter.h"
namespace gfx {
class Image;
class ImageSkia;
} // namespace gfx
namespace mate { namespace mate {
@ -18,15 +14,22 @@ template <>
struct Converter<gfx::ImageSkia> { struct Converter<gfx::ImageSkia> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
gfx::ImageSkia* out); gfx::ImageSkia* out) {
return gin::ConvertFromV8(isolate, val, out);
}
}; };
template <> template <>
struct Converter<gfx::Image> { struct Converter<gfx::Image> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
gfx::Image* out); gfx::Image* out) {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Image& val); return gin::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const gfx::Image& val) {
return gin::ConvertToV8(isolate, val);
}
}; };
} // namespace mate } // namespace mate