move image converter to gin (#19655)
This commit is contained in:
parent
27b2747b61
commit
d0c7a91a50
6 changed files with 56 additions and 47 deletions
|
@ -472,7 +472,8 @@ filenames = {
|
|||
"shell/common/gin_converters/file_dialog_converter.h",
|
||||
"shell/common/gin_converters/file_path_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.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.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/map_converter.h",
|
||||
"shell/common/native_mate_converters/native_window_converter.h",
|
||||
|
|
|
@ -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
|
||||
// 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/native_mate_converters/file_path_converter.h"
|
||||
#include "shell/common/gin_converters/file_path_converter.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
namespace mate {
|
||||
namespace gin {
|
||||
|
||||
bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
|
@ -27,8 +27,9 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
|
|||
if (val->IsNull())
|
||||
return true;
|
||||
|
||||
Handle<electron::api::NativeImage> native_image;
|
||||
if (!ConvertFromV8(isolate, val, &native_image))
|
||||
// TODO(deermichel): remove mate:: after dropping mate
|
||||
mate::Handle<electron::api::NativeImage> native_image;
|
||||
if (!mate::ConvertFromV8(isolate, val, &native_image))
|
||||
return false;
|
||||
|
||||
*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));
|
||||
}
|
||||
|
||||
} // namespace mate
|
||||
} // namespace gin
|
34
shell/common/gin_converters/image_converter.h
Normal file
34
shell/common/gin_converters/image_converter.h
Normal 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_
|
|
@ -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_
|
|
@ -5,7 +5,7 @@
|
|||
#include "shell/common/gin_converters/message_box_converter.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"
|
||||
|
||||
namespace gin {
|
||||
|
|
|
@ -6,11 +6,7 @@
|
|||
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_
|
||||
|
||||
#include "native_mate/converter.h"
|
||||
|
||||
namespace gfx {
|
||||
class Image;
|
||||
class ImageSkia;
|
||||
} // namespace gfx
|
||||
#include "shell/common/gin_converters/image_converter.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
|
@ -18,15 +14,22 @@ template <>
|
|||
struct Converter<gfx::ImageSkia> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
gfx::ImageSkia* out);
|
||||
gfx::ImageSkia* out) {
|
||||
return gin::ConvertFromV8(isolate, val, 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);
|
||||
gfx::Image* out) {
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue