mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
120 lines
3.8 KiB
TypeScript
120 lines
3.8 KiB
TypeScript
|
|
/*
|
|
Copyright (c) 2017-2020 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.
|
|
*/
|
|
|
|
/**
|
|
* @category component/web-view
|
|
*/
|
|
|
|
import {legacyCC} from '../core/global-exports';
|
|
import {WebView} from './web-view';
|
|
import {EventType} from './web-view-enums';
|
|
import {UITransform} from '../core/components/ui-base';
|
|
|
|
export abstract class WebViewImpl {
|
|
protected _componentEventList: Map<number, Function> = new Map<number, Function>();
|
|
protected _state = EventType.NONE;
|
|
protected _warpper: any; // Fix iframe display problem in ios.
|
|
protected _webview: any;
|
|
|
|
protected _loaded = false;
|
|
protected _forceUpdate = false;
|
|
|
|
protected _component: WebView | null = null;
|
|
protected _uiTrans: UITransform | null = null;
|
|
|
|
protected _w = 0;
|
|
protected _h = 0;
|
|
protected _m00 = 0;
|
|
protected _m01 = 0;
|
|
protected _m04 = 0;
|
|
protected _m05 = 0;
|
|
protected _m12 = 0;
|
|
protected _m13 = 0;
|
|
|
|
constructor (component) {
|
|
this._component = component;
|
|
this._uiTrans = component.node.getComponent(UITransform);
|
|
this.reset();
|
|
this.createWebView();
|
|
}
|
|
|
|
public reset() {
|
|
this._warpper = null;
|
|
this._webview = null;
|
|
this._loaded = false;
|
|
this._w = 0;
|
|
this._h = 0;
|
|
this._m00 = 0;
|
|
this._m01 = 0;
|
|
this._m04 = 0;
|
|
this._m05 = 0;
|
|
this._m12 = 0;
|
|
this._m13 = 0;
|
|
this._state = EventType.NONE;
|
|
this._forceUpdate = false;
|
|
}
|
|
|
|
public abstract loadURL(url: string): void;
|
|
public abstract createWebView(): void;
|
|
public abstract removeWebView(): void;
|
|
public abstract enable(): void;
|
|
public abstract disable(): void;
|
|
public abstract syncMatrix(): void;
|
|
|
|
public abstract evaluateJS(str: string): void;
|
|
public abstract setOnJSCallback(callback: Function): void;
|
|
public abstract setJavascriptInterfaceScheme(scheme: string): void;
|
|
|
|
get loaded () { return this._loaded; }
|
|
get componentEventList () { return this._componentEventList; }
|
|
get webview () { return this._webview;}
|
|
get state () { return this._state; }
|
|
get UICamera () {
|
|
return this._uiTrans && this._uiTrans._canvas && this._uiTrans._canvas.camera;
|
|
}
|
|
|
|
protected dispatchEvent (key) {
|
|
const callback = this._componentEventList.get(key);
|
|
if (callback) {
|
|
this._state = key;
|
|
callback.call(this);
|
|
}
|
|
}
|
|
|
|
public destroy () {
|
|
this.removeWebView();
|
|
this._warpper = null;
|
|
this._webview = null;
|
|
this._loaded = false;
|
|
this._component = null;
|
|
this._uiTrans = null;
|
|
this._forceUpdate = false;
|
|
this._componentEventList.clear();
|
|
}
|
|
}
|
|
|
|
legacyCC.internal.WebViewImpl = WebViewImpl;
|