mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2026-01-11 09:26:52 +00:00
初始化
This commit is contained in:
273
engine/cocos2d/webview/CCWebView.js
Normal file
273
engine/cocos2d/webview/CCWebView.js
Normal file
@@ -0,0 +1,273 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const WebViewImpl = require('./webview-impl');
|
||||
|
||||
/**
|
||||
* !#en WebView event type
|
||||
* !#zh 网页视图事件类型
|
||||
* @enum WebView.EventType
|
||||
*/
|
||||
const EventType = WebViewImpl.EventType;
|
||||
|
||||
|
||||
/**
|
||||
* !#en Web page Load completed.
|
||||
* !#zh 网页加载完成
|
||||
* @property {String} LOADED
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en Web page is loading.
|
||||
* !#zh 网页加载中
|
||||
* @property {String} LOADING
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en Web page error occurs when loading.
|
||||
* !#zh 网页加载出错
|
||||
* @property {String} ERROR
|
||||
*/
|
||||
|
||||
//
|
||||
function emptyCallback () { }
|
||||
|
||||
/**
|
||||
* !#en cc.WebView is a component for display web pages in the game. Because different platforms have different authorization, API and control methods for WebView component. And have not yet formed a unified standard, only Web, iOS, and Android platforms are currently supported.
|
||||
* !#zh WebView 组件,用于在游戏中显示网页。由于不同平台对于 WebView 组件的授权、API、控制方式都不同,还没有形成统一的标准,所以目前只支持 Web、iOS 和 Android 平台。
|
||||
* @class WebView
|
||||
* @extends Component
|
||||
*/
|
||||
let WebView = cc.Class({
|
||||
name: 'cc.WebView',
|
||||
extends: cc.Component,
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
menu: 'i18n:MAIN_MENU.component.ui/WebView',
|
||||
executeInEditMode: true
|
||||
},
|
||||
|
||||
properties: {
|
||||
_url: '',
|
||||
/**
|
||||
* !#en A given URL to be loaded by the WebView, it should have a http or https prefix.
|
||||
* !#zh 指定 WebView 加载的网址,它应该是一个 http 或者 https 开头的字符串
|
||||
* @property {String} url
|
||||
*/
|
||||
url: {
|
||||
type: cc.String,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.webview.url',
|
||||
get: function () {
|
||||
return this._url;
|
||||
},
|
||||
set: function (url) {
|
||||
this._url = url;
|
||||
let impl = this._impl;
|
||||
if (impl) {
|
||||
impl.loadURL(url);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en The webview's event callback , it will be triggered when certain webview event occurs.
|
||||
* !#zh WebView 的回调事件,当网页加载过程中,加载完成后或者加载出错时都会回调此函数
|
||||
* @property {Component.EventHandler[]} webviewLoadedEvents
|
||||
*/
|
||||
webviewEvents: {
|
||||
default: [],
|
||||
type: cc.Component.EventHandler,
|
||||
},
|
||||
},
|
||||
|
||||
statics: {
|
||||
EventType: EventType,
|
||||
// Impl will be overrided in the different platform.
|
||||
Impl: WebViewImpl
|
||||
},
|
||||
|
||||
ctor () {
|
||||
this._impl = new WebView.Impl();
|
||||
},
|
||||
|
||||
onRestore () {
|
||||
if (!this._impl) {
|
||||
this._impl = new WebView.Impl();
|
||||
}
|
||||
},
|
||||
|
||||
onEnable () {
|
||||
let impl = this._impl;
|
||||
impl.createDomElementIfNeeded(this.node.width, this.node.height);
|
||||
if (!CC_EDITOR) {
|
||||
impl.setEventListener(EventType.LOADED, this._onWebViewLoaded.bind(this));
|
||||
impl.setEventListener(EventType.LOADING, this._onWebViewLoading.bind(this));
|
||||
impl.setEventListener(EventType.ERROR, this._onWebViewLoadError.bind(this));
|
||||
}
|
||||
impl.loadURL(this._url);
|
||||
impl.setVisible(true);
|
||||
},
|
||||
|
||||
onDisable () {
|
||||
let impl = this._impl;
|
||||
impl.setVisible(false);
|
||||
if (!CC_EDITOR) {
|
||||
impl.setEventListener(EventType.LOADED, emptyCallback);
|
||||
impl.setEventListener(EventType.LOADING, emptyCallback);
|
||||
impl.setEventListener(EventType.ERROR, emptyCallback);
|
||||
}
|
||||
},
|
||||
|
||||
onDestroy () {
|
||||
if (this._impl) {
|
||||
this._impl.destroy();
|
||||
this._impl = null;
|
||||
}
|
||||
},
|
||||
|
||||
update (dt) {
|
||||
if (this._impl) {
|
||||
this._impl.updateMatrix(this.node);
|
||||
}
|
||||
},
|
||||
|
||||
_onWebViewLoaded () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.LOADED);
|
||||
this.node.emit('loaded', this);
|
||||
},
|
||||
|
||||
_onWebViewLoading () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.LOADING);
|
||||
this.node.emit('loading', this);
|
||||
return true;
|
||||
},
|
||||
|
||||
_onWebViewLoadError () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.ERROR);
|
||||
this.node.emit('error', this);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Set javascript interface scheme (see also setOnJSCallback). <br/>
|
||||
* Note: Supports only on the Android and iOS. For HTML5, please refer to the official documentation.<br/>
|
||||
* Please refer to the official documentation for more details.
|
||||
* !#zh
|
||||
* 设置 JavaScript 接口方案(与 'setOnJSCallback' 配套使用)。<br/>
|
||||
* 注意:只支持 Android 和 iOS ,Web 端用法请前往官方文档查看。<br/>
|
||||
* 详情请参阅官方文档
|
||||
* @method setJavascriptInterfaceScheme
|
||||
* @param {String} scheme
|
||||
*/
|
||||
setJavascriptInterfaceScheme (scheme) {
|
||||
if (this._impl) {
|
||||
this._impl.setJavascriptInterfaceScheme(scheme);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* This callback called when load URL that start with javascript
|
||||
* interface scheme (see also setJavascriptInterfaceScheme). <br/>
|
||||
* Note: Supports only on the Android and iOS. For HTML5, please refer to the official documentation.<br/>
|
||||
* Please refer to the official documentation for more details.
|
||||
* !#zh
|
||||
* 当加载 URL 以 JavaScript 接口方案开始时调用这个回调函数。<br/>
|
||||
* 注意:只支持 Android 和 iOS,Web 端用法请前往官方文档查看。
|
||||
* 详情请参阅官方文档
|
||||
* @method setOnJSCallback
|
||||
* @param {Function} callback
|
||||
*/
|
||||
setOnJSCallback (callback) {
|
||||
if (this._impl) {
|
||||
this._impl.setOnJSCallback(callback);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Evaluates JavaScript in the context of the currently displayed page. <br/>
|
||||
* Please refer to the official document for more details <br/>
|
||||
* Note: Cross domain issues need to be resolved by yourself <br/>
|
||||
* !#zh
|
||||
* 执行 WebView 内部页面脚本(详情请参阅官方文档) <br/>
|
||||
* 注意:需要自行解决跨域问题
|
||||
* @method evaluateJS
|
||||
* @param {String} str
|
||||
*/
|
||||
evaluateJS (str) {
|
||||
if (this._impl) {
|
||||
this._impl.evaluateJS(str);
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
cc.WebView = module.exports = WebView;
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event loaded
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {WebView} webView - The WebView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event loading
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {WebView} webView - The WebView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Note: This event is emitted from the node to which the component belongs.
|
||||
* !#zh
|
||||
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
|
||||
* @event error
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {WebView} webView - The WebView component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en if you don't need the WebView and it isn't in any running Scene, you should
|
||||
* call the destroy method on this component or the associated node explicitly.
|
||||
* Otherwise, the created DOM element won't be removed from web page.
|
||||
* !#zh
|
||||
* 如果你不再使用 WebView,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。
|
||||
* 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。
|
||||
* @example
|
||||
* webview.node.parent = null; // or webview.node.removeFromParent(false);
|
||||
* // when you don't need webview anymore
|
||||
* webview.node.destroy();
|
||||
* @method destroy
|
||||
* @return {Boolean} whether it is the first time the destroy being called
|
||||
*/
|
||||
426
engine/cocos2d/webview/webview-impl.js
Normal file
426
engine/cocos2d/webview/webview-impl.js
Normal file
@@ -0,0 +1,426 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const utils = require('../core/platform/utils');
|
||||
const sys = require('../core/platform/CCSys');
|
||||
|
||||
let _mat4_temp = cc.mat4();
|
||||
|
||||
let WebViewImpl = cc.Class({
|
||||
name: "WebViewImpl",
|
||||
|
||||
ctor () {
|
||||
// this.setContentSize(cc.size(300, 200));
|
||||
this._EventList = {};
|
||||
|
||||
this._visible = false;
|
||||
this._parent = null;
|
||||
this._div = null;
|
||||
this._iframe = null;
|
||||
this._listener = null;
|
||||
this._forceUpdate = false;
|
||||
|
||||
// update matrix cache
|
||||
this._m00 = 0;
|
||||
this._m01 = 0;
|
||||
this._m04 = 0;
|
||||
this._m05 = 0;
|
||||
this._m12 = 0;
|
||||
this._m13 = 0;
|
||||
this._w = 0;
|
||||
this._h = 0;
|
||||
//
|
||||
this.__eventListeners = {};
|
||||
},
|
||||
|
||||
_updateVisibility () {
|
||||
if (!this._div) return;
|
||||
let div = this._div;
|
||||
if (this._visible) {
|
||||
div.style.visibility = 'visible';
|
||||
}
|
||||
else {
|
||||
div.style.visibility = 'hidden';
|
||||
}
|
||||
},
|
||||
|
||||
_updateSize (w, h) {
|
||||
let div = this._div;
|
||||
if (div) {
|
||||
div.style.width = w + "px";
|
||||
div.style.height = h + "px";
|
||||
}
|
||||
},
|
||||
|
||||
_initEvent () {
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
let cbs = this.__eventListeners, self = this;
|
||||
cbs.load = function () {
|
||||
self._forceUpdate = true;
|
||||
self._dispatchEvent(WebViewImpl.EventType.LOADED);
|
||||
};
|
||||
cbs.error = function () {
|
||||
self._dispatchEvent(WebViewImpl.EventType.ERROR);
|
||||
};
|
||||
iframe.addEventListener("load", cbs.load);
|
||||
iframe.addEventListener("error", cbs.error);
|
||||
}
|
||||
},
|
||||
|
||||
_initStyle () {
|
||||
if (!this._div) return;
|
||||
let div = this._div;
|
||||
div.style.position = "absolute";
|
||||
div.style.bottom = "0px";
|
||||
div.style.left = "0px";
|
||||
},
|
||||
|
||||
_setOpacity (opacity) {
|
||||
let iframe = this._iframe;
|
||||
if (iframe && iframe.style) {
|
||||
iframe.style.opacity = opacity / 255;
|
||||
}
|
||||
},
|
||||
|
||||
_createDom (w, h) {
|
||||
if (WebViewImpl._polyfill.enableDiv) {
|
||||
this._div = document.createElement("div");
|
||||
this._div.style["-webkit-overflow"] = "auto";
|
||||
this._div.style["-webkit-overflow-scrolling"] = "touch";
|
||||
this._iframe = document.createElement("iframe");
|
||||
this._div.appendChild(this._iframe);
|
||||
this._iframe.style.width = "100%";
|
||||
this._iframe.style.height = "100%";
|
||||
}
|
||||
else {
|
||||
this._div = this._iframe = document.createElement("iframe");
|
||||
}
|
||||
|
||||
if (WebViewImpl._polyfill.enableBG)
|
||||
this._div.style["background"] = "#FFF";
|
||||
|
||||
this._div.style.height = h + "px";
|
||||
this._div.style.width = w + "px";
|
||||
this._div.style.overflow = "scroll";
|
||||
this._iframe.style.border = "none";
|
||||
|
||||
cc.game.container.appendChild(this._div);
|
||||
this._updateVisibility();
|
||||
},
|
||||
|
||||
_createNativeControl (w, h) {
|
||||
this._createDom(w, h);
|
||||
this._initStyle();
|
||||
this._initEvent();
|
||||
},
|
||||
|
||||
createDomElementIfNeeded: CC_EDITOR ? function (w, h) {
|
||||
this._div = document.createElement('div');
|
||||
this._div.style.background = 'rgba(255, 255, 255, 0.8)';
|
||||
this._div.style.color = 'rgb(51, 51, 51)';
|
||||
this._div.style.height = w + 'px';
|
||||
this._div.style.width = h + 'px';
|
||||
this._div.style.position = 'absolute';
|
||||
this._div.style.bottom = '0px';
|
||||
this._div.style.left = '0px';
|
||||
this._div.style['word-wrap'] = 'break-word';
|
||||
cc.game.container.appendChild(this._div);
|
||||
} : function (w, h) {
|
||||
if (!this._div) {
|
||||
this._createNativeControl(w, h);
|
||||
}
|
||||
else {
|
||||
this._updateSize(w, h);
|
||||
}
|
||||
},
|
||||
|
||||
removeDom () {
|
||||
let div = this._div;
|
||||
if (div) {
|
||||
let hasChild = utils.contains(cc.game.container, div);
|
||||
if (hasChild)
|
||||
cc.game.container.removeChild(div);
|
||||
|
||||
this._div = null;
|
||||
}
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
let cbs = this.__eventListeners;
|
||||
iframe.removeEventListener("load", cbs.load);
|
||||
iframe.removeEventListener("error", cbs.error);
|
||||
cbs.load = null;
|
||||
cbs.error = null;
|
||||
this._iframe = null;
|
||||
}
|
||||
},
|
||||
|
||||
setOnJSCallback (callback) {},
|
||||
setJavascriptInterfaceScheme (scheme) {},
|
||||
// private method
|
||||
loadData (data, MIMEType, encoding, baseURL) {},
|
||||
loadHTMLString (string, baseURL) {},
|
||||
|
||||
/**
|
||||
* Load an URL
|
||||
* @param {String} url
|
||||
*/
|
||||
loadURL: CC_EDITOR ? function (url) {
|
||||
this._div.innerText = url;
|
||||
} : function (url) {
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
iframe.src = url;
|
||||
let self = this;
|
||||
let cb = function () {
|
||||
self._loaded = true;
|
||||
self._updateVisibility();
|
||||
iframe.removeEventListener("load", cb);
|
||||
};
|
||||
iframe.addEventListener("load", cb);
|
||||
this._dispatchEvent(WebViewImpl.EventType.LOADING);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop loading
|
||||
*/
|
||||
stopLoading () {
|
||||
cc.logID(7800);
|
||||
},
|
||||
|
||||
/**
|
||||
* Reload the WebView
|
||||
*/
|
||||
reload () {
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
let win = iframe.contentWindow;
|
||||
if (win && win.location)
|
||||
win.location.reload();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine whether to go back
|
||||
*/
|
||||
canGoBack () {
|
||||
cc.logID(7801);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine whether to go forward
|
||||
*/
|
||||
canGoForward () {
|
||||
cc.logID(7802);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* go back
|
||||
*/
|
||||
goBack () {
|
||||
try {
|
||||
if (WebViewImpl._polyfill.closeHistory)
|
||||
return cc.logID(7803);
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
let win = iframe.contentWindow;
|
||||
if (win && win.location)
|
||||
win.history.back.call(win);
|
||||
}
|
||||
} catch (err) {
|
||||
cc.log(err);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* go forward
|
||||
*/
|
||||
goForward () {
|
||||
try {
|
||||
if (WebViewImpl._polyfill.closeHistory)
|
||||
return cc.logID(7804);
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
let win = iframe.contentWindow;
|
||||
if (win && win.location)
|
||||
win.history.forward.call(win);
|
||||
}
|
||||
} catch (err) {
|
||||
cc.log(err);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* In the webview execution within a period of js string
|
||||
* @param {String} str
|
||||
*/
|
||||
evaluateJS (str) {
|
||||
let iframe = this._iframe;
|
||||
if (iframe) {
|
||||
let win = iframe.contentWindow;
|
||||
try {
|
||||
win.eval(str);
|
||||
this._dispatchEvent(WebViewImpl.EventType.JS_EVALUATED);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Limited scale
|
||||
*/
|
||||
setScalesPageToFit () {
|
||||
cc.logID(7805);
|
||||
},
|
||||
|
||||
/**
|
||||
* The binding event
|
||||
* @param {WebViewImpl.EventType} event
|
||||
* @param {Function} callback
|
||||
*/
|
||||
setEventListener (event, callback) {
|
||||
this._EventList[event] = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete events
|
||||
* @param {WebViewImpl.EventType} event
|
||||
*/
|
||||
removeEventListener (event) {
|
||||
this._EventList[event] = null;
|
||||
},
|
||||
|
||||
_dispatchEvent (event) {
|
||||
let callback = this._EventList[event];
|
||||
if (callback)
|
||||
callback.call(this, this, this._iframe.src);
|
||||
},
|
||||
|
||||
_createRenderCmd () {
|
||||
return new WebViewImpl.RenderCmd(this);
|
||||
},
|
||||
|
||||
destroy () {
|
||||
this.removeDom();
|
||||
},
|
||||
|
||||
setVisible (visible) {
|
||||
if (this._visible !== visible) {
|
||||
this._visible = !!visible;
|
||||
this._updateVisibility();
|
||||
}
|
||||
},
|
||||
|
||||
updateMatrix (node) {
|
||||
if (!this._div || !this._visible) return;
|
||||
|
||||
node.getWorldMatrix(_mat4_temp);
|
||||
|
||||
let renderCamera = cc.Camera._findRendererCamera(node);
|
||||
if (renderCamera) {
|
||||
renderCamera.worldMatrixToScreen(_mat4_temp, _mat4_temp, cc.game.canvas.width, cc.game.canvas.height);
|
||||
}
|
||||
|
||||
let _mat4_tempm = _mat4_temp.m;
|
||||
if (!this._forceUpdate &&
|
||||
this._m00 === _mat4_tempm[0] && this._m01 === _mat4_tempm[1] &&
|
||||
this._m04 === _mat4_tempm[4] && this._m05 === _mat4_tempm[5] &&
|
||||
this._m12 === _mat4_tempm[12] && this._m13 === _mat4_tempm[13] &&
|
||||
this._w === node._contentSize.width && this._h === node._contentSize.height) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update matrix cache
|
||||
this._m00 = _mat4_tempm[0];
|
||||
this._m01 = _mat4_tempm[1];
|
||||
this._m04 = _mat4_tempm[4];
|
||||
this._m05 = _mat4_tempm[5];
|
||||
this._m12 = _mat4_tempm[12];
|
||||
this._m13 = _mat4_tempm[13];
|
||||
this._w = node._contentSize.width;
|
||||
this._h = node._contentSize.height;
|
||||
|
||||
let dpr = cc.view._devicePixelRatio;
|
||||
let scaleX = 1 / dpr;
|
||||
let scaleY = 1 / dpr;
|
||||
|
||||
let container = cc.game.container;
|
||||
let a = _mat4_tempm[0] * scaleX, b = _mat4_tempm[1], c = _mat4_tempm[4], d = _mat4_tempm[5] * scaleY;
|
||||
|
||||
let offsetX = container && container.style.paddingLeft ? parseInt(container.style.paddingLeft) : 0;
|
||||
let offsetY = container && container.style.paddingBottom ? parseInt(container.style.paddingBottom) : 0;
|
||||
this._updateSize(this._w, this._h);
|
||||
let w = this._w * scaleX;
|
||||
let h = this._h * scaleY;
|
||||
|
||||
let appx = (w * _mat4_tempm[0]) * node._anchorPoint.x;
|
||||
let appy = (h * _mat4_tempm[5]) * node._anchorPoint.y;
|
||||
|
||||
|
||||
let tx = _mat4_tempm[12] * scaleX - appx + offsetX, ty = _mat4_tempm[13] * scaleY - appy + offsetY;
|
||||
|
||||
let matrix = "matrix(" + a + "," + -b + "," + -c + "," + d + "," + tx + "," + -ty + ")";
|
||||
this._div.style['transform'] = matrix;
|
||||
this._div.style['-webkit-transform'] = matrix;
|
||||
this._div.style['transform-origin'] = '0px 100% 0px';
|
||||
this._div.style['-webkit-transform-origin'] = '0px 100% 0px';
|
||||
|
||||
// chagned iframe opacity
|
||||
this._setOpacity(node.opacity);
|
||||
this._forceUpdate = false;
|
||||
}
|
||||
});
|
||||
|
||||
WebViewImpl.EventType = {
|
||||
LOADING: 0,
|
||||
LOADED: 1,
|
||||
ERROR: 2,
|
||||
JS_EVALUATED: 3
|
||||
};
|
||||
|
||||
let polyfill = WebViewImpl._polyfill = {
|
||||
devicePixelRatio: false,
|
||||
enableDiv: false
|
||||
};
|
||||
|
||||
if (sys.os === sys.OS_IOS)
|
||||
polyfill.enableDiv = true;
|
||||
|
||||
if (sys.isMobile) {
|
||||
if (sys.browserType === sys.BROWSER_TYPE_FIREFOX) {
|
||||
polyfill.enableBG = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sys.browserType === sys.BROWSER_TYPE_IE) {
|
||||
polyfill.closeHistory = true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebViewImpl;
|
||||
Reference in New Issue
Block a user