2014-06-16 06:27:57 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/renderer/api/atom_api_web_view.h"
|
|
|
|
|
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "native_mate/object_template_builder.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebView.h"
|
|
|
|
|
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
WebKit::WebView* GetCurrentWebView() {
|
|
|
|
WebKit::WebFrame* frame = WebKit::WebFrame::frameForCurrentContext();
|
|
|
|
if (!frame)
|
|
|
|
return NULL;
|
|
|
|
return frame->view();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
WebView::WebView() : web_view_(GetCurrentWebView()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView::~WebView() {
|
|
|
|
}
|
|
|
|
|
2014-06-16 06:39:29 +00:00
|
|
|
double WebView::SetZoomLevel(double level) {
|
|
|
|
return web_view_->setZoomLevel(level);
|
2014-06-16 06:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double WebView::GetZoomLevel() const {
|
|
|
|
return web_view_->zoomLevel();
|
|
|
|
}
|
|
|
|
|
2014-06-16 06:39:29 +00:00
|
|
|
double WebView::SetZoomFactor(double factor) {
|
|
|
|
return WebKit::WebView::zoomLevelToZoomFactor(SetZoomLevel(
|
|
|
|
WebKit::WebView::zoomFactorToZoomLevel(factor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
double WebView::GetZoomFactor() const {
|
|
|
|
return WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel());
|
|
|
|
}
|
|
|
|
|
2014-06-16 06:27:57 +00:00
|
|
|
mate::ObjectTemplateBuilder WebView::GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
return mate::ObjectTemplateBuilder(isolate)
|
|
|
|
.SetMethod("setZoomLevel", &WebView::SetZoomLevel)
|
2014-06-16 06:39:29 +00:00
|
|
|
.SetMethod("getZoomLevel", &WebView::GetZoomLevel)
|
|
|
|
.SetMethod("setZoomFactor", &WebView::SetZoomFactor)
|
|
|
|
.SetMethod("getZoomFactor", &WebView::GetZoomFactor);
|
2014-06-16 06:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
mate::Handle<WebView> WebView::Create(v8::Isolate* isolate) {
|
|
|
|
return CreateHandle(isolate, new WebView);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void Initialize(v8::Handle<v8::Object> exports) {
|
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
|
|
|
dict.Set("webView", atom::api::WebView::Create(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
NODE_MODULE(atom_renderer_web_view, Initialize)
|