laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
128 lines (127 loc) • 3.87 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HTMLDivElement = void 0;
const HTMLDivParser_1 = require("./HTMLDivParser");
const Sprite_1 = require("../../display/Sprite");
const Event_1 = require("../../events/Event");
const Handler_1 = require("../../utils/Handler");
const IHtml_1 = require("../utils/IHtml");
const HTMLParse_1 = require("../utils/HTMLParse");
class HTMLDivElement extends Sprite_1.Sprite {
constructor() {
super();
this._recList = [];
this._repaintState = 0;
this._element = new HTMLDivParser_1.HTMLDivParser();
this._element.repaintHandler = new Handler_1.Handler(this, this._htmlDivRepaint);
this.mouseEnabled = true;
this.on(Event_1.Event.CLICK, this, this._onMouseClick);
}
destroy(destroyChild = true) {
if (this._element)
this._element.reset();
this._element = null;
this._doClears();
super.destroy(destroyChild);
}
_htmlDivRepaint(recreate = false) {
if (recreate) {
if (this._repaintState < 2)
this._repaintState = 2;
}
else {
if (this._repaintState < 1)
this._repaintState = 1;
}
if (this._repaintState > 0)
this._setGraphicDirty();
}
_updateGraphicWork() {
switch (this._repaintState) {
case 1:
this._updateGraphic();
break;
case 2:
this._refresh();
break;
}
}
_setGraphicDirty() {
this.callLater(this._updateGraphicWork);
}
_doClears() {
if (!this._recList)
return;
var i, len = this._recList.length;
var tRec;
for (i = 0; i < len; i++) {
tRec = this._recList[i];
tRec.recover();
}
this._recList.length = 0;
}
_updateGraphic() {
this._doClears();
this.graphics.clear(true);
this._repaintState = 0;
this._element.drawToGraphic(this.graphics, -this._element.x, -this._element.y, this._recList);
var bounds = this._element.getBounds();
if (bounds)
this.setSelfBounds(bounds);
this.size(bounds.width, bounds.height);
}
get style() {
return this._element.style;
}
set innerHTML(text) {
if (this._innerHTML == text)
return;
this._repaintState = 1;
this._innerHTML = text;
this._element.innerHTML = text;
this._setGraphicDirty();
}
_refresh() {
this._repaintState = 1;
if (this._innerHTML)
this._element.innerHTML = this._innerHTML;
this._setGraphicDirty();
}
set width(value) {
this._element.width = value;
}
get width() {
return this._element.width;
}
set height(value) {
this._element.height = value;
}
get height() {
return this._element.height;
}
get contextWidth() {
return this._element.contextWidth;
}
get contextHeight() {
return this._element.contextHeight;
}
_onMouseClick() {
var tX = this.mouseX;
var tY = this.mouseY;
var i, len;
var tHit;
len = this._recList.length;
for (i = 0; i < len; i++) {
tHit = this._recList[i];
if (tHit.rec.contains(tX, tY)) {
this._eventLink(tHit.href);
}
}
}
_eventLink(href) {
this.event(Event_1.Event.LINK, [href]);
}
}
exports.HTMLDivElement = HTMLDivElement;
IHtml_1.IHtml.HTMLDivElement = HTMLDivElement;
IHtml_1.IHtml.HTMLParse = HTMLParse_1.HTMLParse;