Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const electron = require('electron'); | ||
|
||
const { View } = electron; | ||
const { ImageView } = process.electronBinding('image_view'); | ||
|
||
Object.setPrototypeOf(ImageView.prototype, View.prototype); | ||
|
||
ImageView.prototype._init = function () { | ||
// Call parent class's _init. | ||
View.prototype._init.call(this); | ||
}; | ||
|
||
module.exports = ImageView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2020 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "shell/browser/api/views/electron_api_image_view.h" | ||
|
||
#include "shell/common/gin_converters/image_converter.h" | ||
#include "shell/common/gin_helper/constructor.h" | ||
#include "shell/common/gin_helper/dictionary.h" | ||
#include "shell/common/gin_helper/object_template_builder.h" | ||
#include "shell/common/node_includes.h" | ||
|
||
namespace electron { | ||
|
||
namespace api { | ||
|
||
ImageView::ImageView() : View(new views::ImageView()) { | ||
view()->set_owned_by_client(); | ||
} | ||
|
||
ImageView::~ImageView() {} | ||
|
||
void ImageView::SetImage(const gfx::Image& image) { | ||
image_view()->SetImage(image.AsImageSkia()); | ||
} | ||
|
||
// static | ||
gin_helper::WrappableBase* ImageView::New(gin_helper::Arguments* args) { | ||
// Constructor call. | ||
auto* view = new ImageView(); | ||
view->InitWithArgs(args); | ||
return view; | ||
} | ||
|
||
// static | ||
void ImageView::BuildPrototype(v8::Isolate* isolate, | ||
v8::Local<v8::FunctionTemplate> prototype) { | ||
prototype->SetClassName(gin::StringToV8(isolate, "ImageView")); | ||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) | ||
.SetMethod("setImage", &ImageView::SetImage); | ||
} | ||
|
||
} // namespace api | ||
|
||
} // namespace electron | ||
|
||
namespace { | ||
|
||
using electron::api::ImageView; | ||
|
||
void Initialize(v8::Local<v8::Object> exports, | ||
v8::Local<v8::Value> unused, | ||
v8::Local<v8::Context> context, | ||
void* priv) { | ||
v8::Isolate* isolate = context->GetIsolate(); | ||
gin_helper::Dictionary dict(isolate, exports); | ||
dict.Set("ImageView", gin_helper::CreateConstructor<ImageView>( | ||
isolate, base::BindRepeating(&ImageView::New))); | ||
} | ||
|
||
} // namespace | ||
|
||
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_image_view, Initialize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SHELL_BROWSER_API_VIEWS_ELECTRON_API_IMAGE_VIEW_H_ | ||
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_IMAGE_VIEW_H_ | ||
|
||
#include "gin/handle.h" | ||
#include "shell/browser/api/electron_api_view.h" | ||
#include "ui/gfx/image/image.h" | ||
#include "ui/views/controls/image_view.h" | ||
|
||
namespace electron { | ||
|
||
namespace api { | ||
|
||
class ImageView : public View { | ||
public: | ||
static gin_helper::WrappableBase* New(gin_helper::Arguments* args); | ||
|
||
static void BuildPrototype(v8::Isolate* isolate, | ||
v8::Local<v8::FunctionTemplate> prototype); | ||
|
||
void SetImage(const gfx::Image& image); | ||
|
||
protected: | ||
ImageView(); | ||
~ImageView() override; | ||
|
||
views::ImageView* image_view() const { | ||
return static_cast<views::ImageView*>(view()); | ||
} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(ImageView); | ||
}; | ||
|
||
} // namespace api | ||
|
||
} // namespace electron | ||
|
||
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_IMAGE_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters