Commit c3709515 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

WorkbookView конструктор от Html элемента

init->_init
WorkbookView хранит теперь Html элементы
add _canResize
CellEditor конструктор от Html элемента
asc_CEventsController конструктор от Html элемента

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@53379 954022d7-b5bf-4e40-9824-e11837661b57
parent f7f8707a
......@@ -1731,7 +1731,7 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
this.wbModel,
this.controller,
this.handlers,
$("#" + this.HtmlElementName),
this.HtmlElement,
$("#" + this.topLineEditorName),
this,
this.collaborativeEditing,
......
......@@ -90,9 +90,11 @@
//---declaration---
this.canvasOuter = undefined;
this.canvasOuterStyle = undefined;
this.canvas = undefined;
this.canvasOverlay = undefined;
this.cursor = undefined;
this.cursorStyle = undefined;
this.cursorTID = undefined;
this.cursorPos = 0;
this.topLineIndex = 0;
......@@ -126,7 +128,7 @@
this.isUpdateValue = true; // Обновлять ли состояние строки при вводе в TextArea
//-----------------
this.init();
this._init();
return this;
}
......@@ -165,37 +167,36 @@
reFormula: /^([a-z_][a-z0-9_]*)/i,
init: function () {
_init: function () {
var t = this;
var z = parseInt(t.settings.canvasZindex);
t.canvasOuter = t.element.find("#ce-canvas-outer");
if (t.canvasOuter.length < 1) {
t.canvasOuter = $('<div id="ce-canvas-outer"/>')
.css("display", "none")
.css("z-index", z)
.appendTo(t.element);
t.canvas = $('<canvas id="ce-canvas"/>')
.css("z-index", z+1)
.appendTo(t.canvasOuter);
t.canvasOverlay = $('<canvas id="ce-canvas-overlay"/>')
.css("z-index", z+2)
.css("cursor", t.settings.cursorShape)
.appendTo(t.canvasOuter);
t.cursor = $('<div id="ce-cursor"/>')
.css("display", "none")
.css("z-index", z+3)
.appendTo(t.canvasOuter);
if (null != this.element) {
t.canvasOuter = document.createElement('div');
t.canvasOuter.id = "ce-canvas-outer";
t.canvasOuter.style.display = "none";
t.canvasOuter.style.zIndex = z;
var innerHTML = '<canvas id="ce-canvas" style="z-index: ' + (z+1) + '"></canvas>';
innerHTML += '<canvas id="ce-canvas-overlay" style="z-index: ' + (z+2) + '; cursor: ' + t.settings.cursorShape + '"></canvas>';
innerHTML += '<div id="ce-cursor" style="display: none; z-index: ' + (z+3) + '"></div>';
t.canvasOuter.innerHTML = innerHTML;
this.element.appendChild(t.canvasOuter);
t.canvasOuterStyle = t.canvasOuter.style;
t.canvas = document.getElementById("ce-canvas");
t.canvasOverlay = document.getElementById("ce-canvas-overlay");
t.cursor = document.getElementById("ce-cursor");
t.cursorStyle = t.cursor.style;
}
// create text render
t.drawingCtx = asc_DC({canvas: t.canvas[0], units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
t.overlayCtx = asc_DC({canvas: t.canvasOverlay[0], units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
t.drawingCtx = asc_DC({canvas: t.canvas, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
t.overlayCtx = asc_DC({canvas: t.canvasOverlay, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
t.textRender = asc_TR(t.drawingCtx);
t.textRender.setDefaultFont(t.settings.font.clone());
// bind event handlers
t.canvasOverlay
$(t.canvasOverlay)
.off("." + namespace)
.on("mousedown." + namespace, function () {return t._onMouseDown.apply(t, arguments);})
.on("mouseup." + namespace, function () {return t._onMouseUp.apply(t, arguments);})
......@@ -292,7 +293,8 @@
t.isTopLineActive = false;
t.input.removeClass("focused");
t._hideCursor();
t.canvasOuter.hide();
// hide
t.canvasOuterStyle.display = "none";
t.handlers.trigger("closed");
return true;
......@@ -966,19 +968,17 @@
var t = this;
var z = parseInt(t.settings.canvasZindex);
$(t.canvasOuter)
.css("display", "none")
.css("left", (t.left * t.kx) + "px")
.css("top", (t.top * t.ky) + "px")
.css("width", ((t.right - t.left) * t.kx - 1) + "px")
.css("height", ((t.bottom - t.top) * t.ky - 1) + "px")
.css("z-index", t.top <= 0 ? -1 : z);
t.canvasOuterStyle.left = (t.left * t.kx) + "px";
t.canvasOuterStyle.top = (t.top * t.ky) + "px";
t.canvasOuterStyle.width = ((t.right - t.left) * t.kx - 1) + "px";
t.canvasOuterStyle.height = ((t.bottom - t.top) * t.ky - 1) + "px";
t.canvasOuterStyle.zIndex = t.top <= 0 ? -1 : z;
$(t.canvas).add(t.canvasOverlay)
.attr("width", (t.right - t.left) * t.kx - 1)
.attr("height", (t.bottom - t.top) * t.ky - 1);
t.canvas.width = t.canvasOverlay.width = (t.right - t.left) * t.kx - 1;
t.canvas.height = t.canvasOverlay.height = (t.bottom - t.top) * t.ky - 1;
t.canvasOuter.show();
// show
t.canvasOuterStyle.display = "block";
},
_renderText: function (dy) {
......@@ -1046,19 +1046,24 @@
var t = this;
if (true === t.options.isHideCursor || t.isTopLineActive === true) {return;}
window.clearInterval(t.cursorTID);
t.cursor.show();
t.cursorTID = window.setInterval(function () {t.cursor.toggle();}, t.settings.blinkInterval);
t.cursorStyle.display = "block";
t.cursorTID = window.setInterval(function () {
if ("block" === t.cursorStyle.display)
t.cursorStyle.display = "none";
else
t.cursorStyle.display = "block";
}, t.settings.blinkInterval);
},
_hideCursor: function () {
var t = this;
window.clearInterval(t.cursorTID);
t.cursor.hide();
t.cursorStyle.display = "none";
},
_updateCursorPosition: function (redrawText) {
var t = this;
var h = t.canvas.innerHeight();
var h = t.canvas.height;
var y = - t.textRender.calcLineOffset(t.topLineIndex);
var cur = t.textRender.calcCharOffset(t.cursorPos);
var charsCount = t.textRender.getCharsCount();
......@@ -1088,10 +1093,9 @@
if (dy !== undefined || redrawText) {t._renderText(y);}
t.cursor
.css("left", curLeft + "px")
.css("top", curTop + "px")
.css("height", curHeight + "px");
t.cursorStyle.left = curLeft + "px";
t.cursorStyle.top = curTop + "px";
t.cursorStyle.height = curHeight + "px";
if (cur) {t.input.scrollTop(t.input.height() * cur.lineIndex);}
if (t.isTopLineActive && !t.skipTLUpdate) {t._updateTopLineCurPos();}
......@@ -1952,7 +1956,7 @@
/** @param event {jQuery.Event} */
_getCoordinates: function (event) {
var t = this;
var offs = t.canvasOverlay.offset();
var offs = $(t.canvasOverlay).offset();
var x = (event.pageX - offs.left) / t.kx;
var y = (event.pageY - offs.top) / t.ky;
return {x: x, y: y};
......
......@@ -130,42 +130,32 @@
this.element.onselectstart = function () {return false;};
}
this.element
$(this.element)
.on("mousedown", function () {return self._onMouseDown.apply(self, arguments);})
.on("mouseup", function () {return self._onMouseUp.apply(self, arguments);})
.on("mousemove", function () {return self._onMouseMove.apply(self, arguments);})
.on("mouseleave", function () {return self._onMouseLeave.apply(self, arguments);})
.on("mousewheel", function () {return self._onMouseWheel.apply(self, arguments);})
.on("dblclick", function () {return self._onMouseDblClick.apply(self, arguments);});
//.on("touchstart", function () {self._onMouseDown(arguments[0].originalEvent.touches[0]);return false;})
//.on("touchmove", function () {self._onMouseMove(arguments[0].originalEvent.touches[0]);return false;})
//.on("touchend", function () {self._onMouseUp(arguments[0].originalEvent.changedTouches[0]);return false;});
// Курсор для графических объектов. Определяем mousedown и mouseup для выделения текста.
var oShapeCursor = $("#id_target_cursor");
if ( oShapeCursor ) {
if (oShapeCursor) {
oShapeCursor
.on("mousedown", function () {
return self._onMouseDown.apply(self, arguments);
})
.on("mouseup", function () {
return self._onMouseUp.apply(self, arguments);
})
.on("mousemove", function () {
return self._onMouseMove.apply(self, arguments);
});
.on("mousedown", function () {return self._onMouseDown.apply(self, arguments);})
.on("mouseup", function () {return self._onMouseUp.apply(self, arguments);})
.on("mousemove", function () {return self._onMouseMove.apply(self, arguments);});
}
this.element[0].ontouchstart = function (e){
this.element.ontouchstart = function (e) {
self._onMouseDown(e.touches[0]);
return false;
};
this.element[0].ontouchmove = function (e){
this.element.ontouchmove = function (e) {
self._onMouseMove(e.touches[0]);
return false;
};
this.element[0].ontouchend = function (e){
this.element.ontouchend = function (e) {
self._onMouseUp(e.changedTouches[0]);
return false;
};
......@@ -291,7 +281,7 @@
// Мы изменяли размеры колонки/строки, не редактируем ячейку
t.isCellEditMode = false;
// Обновим состояние курсора
t.handlers.trigger("updateWorksheet", t.element[0], coord.x, coord.y, event.ctrlKey, function(info){t.targetInfo = info;});
t.handlers.trigger("updateWorksheet", t.element, coord.x, coord.y, event.ctrlKey, function(info){t.targetInfo = info;});
}
});
}, 100);
......@@ -311,11 +301,12 @@
_createScrollBars: function () {
var self = this, opt = this.settings;
var widget = $(this.widget);
// vertical scroll bar
this.vsb = this.widget.find("#ws-v-scrollbar");
this.vsb = widget.find("#ws-v-scrollbar");
if (this.vsb.length < 1) {
this.vsb = $('<div id="ws-v-scrollbar"><div id="ws-v-scroll-helper"/></div>').appendTo(this.widget);
this.vsb = $('<div id="ws-v-scrollbar"><div id="ws-v-scroll-helper"/></div>').appendTo(widget);
}
if (!this.vsbApi) {
this.vsbApi = new ScrollObject( this.vsb[0].id,opt);
......@@ -340,18 +331,18 @@
}
// horizontal scroll bar
this.hsb = this.widget.find("#ws-h-scrollbar");
this.hsb = widget.find("#ws-h-scrollbar");
if (this.hsb.length < 1) {
this.hsb = $('<div id="ws-h-scrollbar"><div id="ws-h-scroll-helper"/></div>').appendTo(this.widget);
this.hsb = $('<div id="ws-h-scrollbar"><div id="ws-h-scroll-helper"/></div>').appendTo(widget);
}
if (!this.hsbApi) {
this.hsbApi = new ScrollObject( this.hsb[0].id, $.extend(true, {}, opt, {wheelScrollLines: 1}));
this.hsbApi.bind("scrollhorizontal",function(evt){
self.handlers.trigger("scrollX", evt.scrollPositionX / opt.hscrollStep);
})
});
this.hsbApi.bind("scrollHEnd",function(evt){
self.handlers.trigger("addColumn",true);
})
});
this.hsbApi.onLockMouse = function(){
$(window)
.on("mousemove.scroll", function (e) {
......@@ -367,8 +358,8 @@
}
// right bottom corner
if (this.widget.find("#ws-scrollbar-corner").length < 1) {
$('<div id="ws-scrollbar-corner"/>').appendTo(this.widget);
if (widget.find("#ws-scrollbar-corner").length < 1) {
$('<div id="ws-scrollbar-corner"/>').appendTo(widget);
}
},
......@@ -1373,11 +1364,11 @@
if (asc["editor"].isStartAddShape || graphicsInfo) {
t.handlers.trigger("graphicObjectMouseMove", event, coord.x, coord.y);
t.handlers.trigger("updateWorksheet", t.element[0], coord.x, coord.y, event.ctrlKey, function(info){t.targetInfo = info;});
t.handlers.trigger("updateWorksheet", t.element, coord.x, coord.y, event.ctrlKey, function(info){t.targetInfo = info;});
return true;
}
t.handlers.trigger("updateWorksheet", t.element[0], coord.x, coord.y, event.ctrlKey, function(info){t.targetInfo = info;});
t.handlers.trigger("updateWorksheet", t.element, coord.x, coord.y, event.ctrlKey, function(info){t.targetInfo = info;});
return true;
},
......@@ -1387,7 +1378,7 @@
this.hasCursor = false;
if (!this.isSelectMode && !this.isResizeMode && !this.isMoveResizeRange) {
this.targetInfo = undefined;
this.handlers.trigger("updateWorksheet", this.element[0]);
this.handlers.trigger("updateWorksheet", this.element);
}
if (this.isMoveRangeMode) {
t.moveRangeTimerId = window.setTimeout(function(){t._moveRangeHandle2(event)},0);
......@@ -1411,7 +1402,7 @@
}
var self = this;
delta *= event.shiftKey ? 1 : this.settings.wheelScrollLines;
this.handlers.trigger("updateWorksheet", this.element[0], /*x*/undefined, /*y*/undefined, /*ctrlKey*/undefined,
this.handlers.trigger("updateWorksheet", this.element, /*x*/undefined, /*y*/undefined, /*ctrlKey*/undefined,
function () {
event.shiftKey ? self.scrollHorizontal(-delta,event) : self.scrollVertical(-delta,event);
self._onMouseMove(event);
......@@ -1439,7 +1430,7 @@
/** @param event {jQuery.Event} */
_getCoordinates: function (event) {
var offs = this.element.offset();
var offs = $(this.element).offset();
var x = event.pageX - offs.left;
var y = event.pageY - offs.top;
return {x: x, y: y};
......
......@@ -99,7 +99,7 @@
this.defaultFont = new asc_FP(this.model.getDefaultFont(), this.model.getDefaultSize());
//-----------------------
this.init(fontRenderingMode);
this._init(fontRenderingMode);
return this;
}
......@@ -110,48 +110,45 @@
constructor: WorkbookView,
defaults: {
worksheetDefaults: {}
worksheetDefaults: {},
scroll: {
widthPx : 16,
heightPx: 16
}
},
init: function (fontRenderingMode) {
_init: function (fontRenderingMode) {
var self = this;
// Init font managers rendering
// Изначально мы инициализируем c_oAscFontRenderingModeType.hintingAndSubpixeling
this.setFontRenderingMode(fontRenderingMode, /*isInit*/true);
// add style
var _head = document.getElementsByTagName('head')[0];
var style0 = document.createElement('style');
style0.type = 'text/css';
style0.innerHTML = ".block_elem { position:absolute;padding:0;margin:0; }";
_head.appendChild(style0);
if (!window["NATIVE_EDITOR_ENJINE"])
{
// create canvas
var outer = this.element.find("#ws-canvas-outer");
if (outer.length < 1) {
outer = $('<div id="ws-canvas-outer"><canvas id="ws-canvas"/><canvas id="ws-canvas-overlay"/><canvas id=\"id_target_cursor\" class=\"block_elem\" width=\"1\" height=\"1\" style=\"width:2px;height:13px;display:none;z-index:1004;\"></canvas></div>')
.appendTo(this.element);
}
this.canvas = this.element.find("#ws-canvas")
.attr("width", outer.width())
.attr("height", outer.height());
this.canvasOverlay = this.element.find("#ws-canvas-overlay")
.attr("width", outer.width())
.attr("height", outer.height());
}
else
{
this.canvas = new Array(); this.canvas.push(document.createElement("canvas"));
this.canvasOverlay = new Array(); this.canvasOverlay.push(document.createElement("canvas"));
// create canvas
if (null != this.element) {
this.element.innerHTML = '<div id="ws-canvas-outer">\
<canvas id="ws-canvas"></canvas>\
<canvas id="ws-canvas-overlay"></canvas>\
<canvas id="id_target_cursor" class="block_elem" width="1" height="1"\
style="width:2px;height:13px;display:none;z-index:1004;"></canvas>\
</div>';
this.canvas = document.getElementById("ws-canvas");
this.canvasOverlay = document.getElementById("ws-canvas-overlay");
//this._canResize(); ToDo должно отрабатывать, но нам приходит resize сверху
}
this.buffers.main = asc_DC({canvas: this.canvas[0], units: 1/*pt*/,
this.buffers.main = asc_DC({canvas: this.canvas, units: 1/*pt*/,
fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
this.buffers.overlay = asc_DC({canvas: this.canvasOverlay[0], units: 1/*pt*/,
this.buffers.overlay = asc_DC({canvas: this.canvasOverlay, units: 1/*pt*/,
fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
this.buffers.overlay.ctx.isOverlay = true; // Для разруливания _activateOverlayCtx / _deactivateOverlayCtx
......@@ -1148,26 +1145,26 @@
this.wsActive = -1;
},
/** @param event {jQuery.Event} */
resize: function (event) {
var outer = $("#ws-canvas-outer");
_canResize: function() {
var oldWidth = this.canvas.width;
var oldHeight = this.canvas.height;
var width = this.element.offsetWidth - this.defaults.scroll.widthPx;
var height = this.element.offsetHeight - this.defaults.scroll.heightPx;
var oldWidth = this.canvas.attr("width");
var oldHeight = this.canvas.attr("width");
var width = outer.width();
var height = outer.height();
if (oldWidth == width && oldHeight == height)
return;
if (oldWidth === width && oldHeight === height)
return false;
this.canvas
.attr("width", width)
.attr("height", height);
this.canvasOverlay
.attr("width", width)
.attr("height", height);
this.canvas.width = this.canvasOverlay.width = width;
this.canvas.height = this.canvasOverlay.height = height;
return true;
},
this.getWorksheet().resize();
this.showWorksheet(undefined, true);
/** @param event {jQuery.Event} */
resize: function (event) {
if (this._canResize()) {
this.getWorksheet().resize();
this.showWorksheet(undefined, true);
}
},
// Получаем свойство: редактируем мы сейчас или нет
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment