Commit fd5b30c2 authored by Oleg Korshul's avatar Oleg Korshul

1) touch bugs

2) scroll with browser
parent 35680836
...@@ -34,7 +34,9 @@ ...@@ -34,7 +34,9 @@
(function(window, undefined) (function(window, undefined)
{ {
AscCommon.isTouch = false;
AscCommon.isTouchMove = false;
AscCommon.TouchStartTime = -1;
// Import // Import
var AscBrowser = AscCommon.AscBrowser; var AscBrowser = AscCommon.AscBrowser;
var global_MatrixTransformer = AscCommon.global_MatrixTransformer; var global_MatrixTransformer = AscCommon.global_MatrixTransformer;
...@@ -301,7 +303,7 @@ ...@@ -301,7 +303,7 @@
global_keyboardEvent.CtrlKey = global_mouseEvent.CtrlKey; global_keyboardEvent.CtrlKey = global_mouseEvent.CtrlKey;
global_mouseEvent.Type = g_mouse_event_type_up; global_mouseEvent.Type = g_mouse_event_type_up;
global_mouseEvent.Button = e.button; global_mouseEvent.Button = (e.button !== undefined) ? e.button : 0;
var lockedElement = null; var lockedElement = null;
...@@ -362,7 +364,7 @@ ...@@ -362,7 +364,7 @@
global_keyboardEvent.CtrlKey = global_mouseEvent.CtrlKey; global_keyboardEvent.CtrlKey = global_mouseEvent.CtrlKey;
global_mouseEvent.Type = g_mouse_event_type_down; global_mouseEvent.Type = g_mouse_event_type_down;
global_mouseEvent.Button = e.button; global_mouseEvent.Button = (e.button !== undefined) ? e.button : 0;
global_mouseEvent.Sender = (e.srcElement) ? e.srcElement : e.target; global_mouseEvent.Sender = (e.srcElement) ? e.srcElement : e.target;
...@@ -620,6 +622,70 @@ ...@@ -620,6 +622,70 @@
} }
} }
function emulateKeyDown(_code, _element)
{
var oEvent = document.createEvent('KeyboardEvent');
// Chromium Hack
Object.defineProperty(oEvent, 'keyCode', {
get : function()
{
return this.keyCodeVal;
}
});
Object.defineProperty(oEvent, 'which', {
get : function()
{
return this.keyCodeVal;
}
});
Object.defineProperty(oEvent, 'shiftKey', {
get : function()
{
return false;
}
});
Object.defineProperty(oEvent, 'altKey', {
get : function()
{
return false;
}
});
Object.defineProperty(oEvent, 'metaKey', {
get : function()
{
return false;
}
});
Object.defineProperty(oEvent, 'ctrlKey', {
get : function()
{
return false;
}
});
if (AscCommon.AscBrowser.isIE)
{
oEvent.preventDefault = function () {
Object.defineProperty(this, "defaultPrevented", {get: function () {return true;}});
};
}
if (oEvent.initKeyboardEvent)
{
oEvent.initKeyboardEvent("keydown", true, true, window, false, false, false, false, _code, _code);
}
else
{
oEvent.initKeyEvent("keydown", true, true, window, false, false, false, false, _code, 0);
}
oEvent.keyCodeVal = _code;
_element.dispatchEvent(oEvent);
return oEvent.defaultPrevented;
}
function CTouchManager() function CTouchManager()
{ {
this.touches = []; this.touches = [];
...@@ -2881,4 +2947,6 @@ ...@@ -2881,4 +2947,6 @@
window['AscCommon'].button_eventHandlers = button_eventHandlers; window['AscCommon'].button_eventHandlers = button_eventHandlers;
window['AscCommon'].CMobileTouchManager = CMobileTouchManager; window['AscCommon'].CMobileTouchManager = CMobileTouchManager;
window['AscCommon'].CReaderTouchManager = CReaderTouchManager; window['AscCommon'].CReaderTouchManager = CReaderTouchManager;
window['AscCommon'].emulateKeyDown = emulateKeyDown;
})(window); })(window);
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
* @param {undefined} undefined * @param {undefined} undefined
*/ */
function (window, undefined) { function (window, undefined) {
window['AscCommon'] = window['AscCommon'] || {};
var AscCommon = window['AscCommon'];
var debug = false; var debug = false;
var ScrollArrowType = { var ScrollArrowType = {
...@@ -1784,8 +1788,9 @@ ScrollObject.prototype = { ...@@ -1784,8 +1788,9 @@ ScrollObject.prototype = {
} }
// return relative mouse position // return relative mouse position
var mouseX = evt.clientX - left + window.pageXOffset; var mouseX = ((evt.clientX * AscCommon.AscBrowser.zoom) >> 0) - left + window.pageXOffset;
var mouseY = evt.clientY - top + window.pageYOffset; var mouseY = ((evt.clientY * AscCommon.AscBrowser.zoom) >> 0) - top + window.pageYOffset;
return { return {
x:mouseX, x:mouseX,
y:mouseY y:mouseY
...@@ -3352,6 +3357,5 @@ ScrollObject.prototype = { ...@@ -3352,6 +3357,5 @@ ScrollObject.prototype = {
}; };
//---------------------------------------------------------export--------------------------------------------------- //---------------------------------------------------------export---------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
window["AscCommon"].ScrollObject = ScrollObject; window["AscCommon"].ScrollObject = ScrollObject;
})(window); })(window);
...@@ -1773,7 +1773,6 @@ function CDrawingDocument() ...@@ -1773,7 +1773,6 @@ function CDrawingDocument()
if (false === this.m_bIsSelection) if (false === this.m_bIsSelection)
{ {
this.SelectClear(); this.SelectClear();
this.m_oWordControl.CheckUnShowOverlay();
this.m_oWordControl.OnUpdateOverlay(); this.m_oWordControl.OnUpdateOverlay();
this.m_oWordControl.m_oOverlayApi.m_oContext.globalAlpha = 1.0; this.m_oWordControl.m_oOverlayApi.m_oContext.globalAlpha = 1.0;
} }
......
...@@ -537,10 +537,10 @@ function CEditorPage(api) ...@@ -537,10 +537,10 @@ function CEditorPage(api)
this.m_oDrawingDocument.TargetHtmlElement = document.getElementById('id_target_cursor'); this.m_oDrawingDocument.TargetHtmlElement = document.getElementById('id_target_cursor');
this.UnShowOverlay();
this.m_oOverlayApi.m_oControl = this.m_oOverlay; this.m_oOverlayApi.m_oControl = this.m_oOverlay;
this.m_oOverlayApi.m_oHtmlPage = this; this.m_oOverlayApi.m_oHtmlPage = this;
this.m_oOverlayApi.Clear(); this.m_oOverlayApi.Clear();
this.ShowOverlay();
this.m_oDrawingDocument.AutoShapesTrack = new AscCommon.CAutoshapeTrack(); this.m_oDrawingDocument.AutoShapesTrack = new AscCommon.CAutoshapeTrack();
this.m_oDrawingDocument.AutoShapesTrack.init2(this.m_oOverlayApi); this.m_oDrawingDocument.AutoShapesTrack.init2(this.m_oOverlayApi);
......
...@@ -485,10 +485,10 @@ function CEditorPage(api) ...@@ -485,10 +485,10 @@ function CEditorPage(api)
this.checkNeedRules(); this.checkNeedRules();
this.initEvents2(); this.initEvents2();
this.UnShowOverlay();
this.m_oOverlayApi.m_oControl = this.m_oOverlay; this.m_oOverlayApi.m_oControl = this.m_oOverlay;
this.m_oOverlayApi.m_oHtmlPage = this; this.m_oOverlayApi.m_oHtmlPage = this;
this.m_oOverlayApi.Clear(); this.m_oOverlayApi.Clear();
this.ShowOverlay();
this.m_oDrawingDocument.AutoShapesTrack = new AscCommon.CAutoshapeTrack(); this.m_oDrawingDocument.AutoShapesTrack = new AscCommon.CAutoshapeTrack();
this.m_oDrawingDocument.AutoShapesTrack.init2(this.m_oOverlayApi); this.m_oDrawingDocument.AutoShapesTrack.init2(this.m_oOverlayApi);
...@@ -693,31 +693,44 @@ function CEditorPage(api) ...@@ -693,31 +693,44 @@ function CEditorPage(api)
return e; return e;
}; };
this.m_oEditor.HtmlElement["ontouchstart"] = this.m_oOverlay.HtmlElement["ontouchstart"] = function(e) { var _cur = document.getElementById('id_target_cursor');
_cur["ontouchstart"] = this.m_oEditor.HtmlElement["ontouchstart"] = this.m_oOverlay.HtmlElement["ontouchstart"] = function(e) {
//console.log("start: " + AscCommon.isTouch); //console.log("start: " + AscCommon.isTouch);
if (AscCommon.isTouch) if (AscCommon.isTouch)
return; return;
var _old = global_mouseEvent.KoefPixToMM; var _old = global_mouseEvent.KoefPixToMM;
global_mouseEvent.KoefPixToMM = 5; global_mouseEvent.KoefPixToMM = 5;
AscCommon.isTouch = true; AscCommon.isTouch = true;
AscCommon.isTouchMove = false;
AscCommon.TouchStartTime = new Date().getTime();
AscCommon.stopEvent(e); AscCommon.stopEvent(e);
var _ret = this.onmousedown(_check_e(e), true); var _ret = this.onmousedown(_check_e(e), true);
global_mouseEvent.KoefPixToMM = _old; global_mouseEvent.KoefPixToMM = _old;
if ((document.activeElement !== undefined) &&
(AscCommon.g_inputContext != null) &&
(document.activeElement != AscCommon.g_inputContext.HtmlArea))
{
AscCommon.g_inputContext.HtmlArea.focus();
}
return _ret; return _ret;
}; };
this.m_oEditor.HtmlElement["ontouchmove"] = this.m_oOverlay.HtmlElement["ontouchmove"] = function(e) { _cur["ontouchmove"] = this.m_oEditor.HtmlElement["ontouchmove"] = this.m_oOverlay.HtmlElement["ontouchmove"] = function(e) {
//console.log("move: " + AscCommon.isTouch); //console.log("move: " + AscCommon.isTouch);
var _old = global_mouseEvent.KoefPixToMM; var _old = global_mouseEvent.KoefPixToMM;
global_mouseEvent.KoefPixToMM = 5; global_mouseEvent.KoefPixToMM = 5;
AscCommon.isTouch = true; AscCommon.isTouch = true;
AscCommon.isTouchMove = true;
AscCommon.stopEvent(e); AscCommon.stopEvent(e);
var _ret = this.onmousemove(_check_e(e), true); var _ret = this.onmousemove(_check_e(e), true);
global_mouseEvent.KoefPixToMM = _old; global_mouseEvent.KoefPixToMM = _old;
return _ret; return _ret;
}; };
this.m_oEditor.HtmlElement["ontouchend"] = this.m_oOverlay.HtmlElement["ontouchend"] = function(e) { _cur["ontouchend"] = this.m_oEditor.HtmlElement["ontouchend"] = this.m_oOverlay.HtmlElement["ontouchend"] = function(e) {
//console.log("end: " + AscCommon.isTouch); //console.log("end: " + AscCommon.isTouch);
if (!AscCommon.isTouch) if (!AscCommon.isTouch)
...@@ -727,11 +740,40 @@ function CEditorPage(api) ...@@ -727,11 +740,40 @@ function CEditorPage(api)
global_mouseEvent.KoefPixToMM = 5; global_mouseEvent.KoefPixToMM = 5;
AscCommon.isTouch = false; AscCommon.isTouch = false;
AscCommon.stopEvent(e); AscCommon.stopEvent(e);
var _ret = this.onmouseup(_check_e(e), undefined, true); var _natE = _check_e(e);
var _ret = this.onmouseup(_natE, undefined, true);
global_mouseEvent.KoefPixToMM = _old; global_mouseEvent.KoefPixToMM = _old;
if (!AscCommon.isTouchMove && (-1 != AscCommon.TouchStartTime) && (Math.abs(AscCommon.TouchStartTime - (new Date().getTime())) > 900))
{
var _eContextMenu = {
pageX : _natE.pageX,
pageY : _natE.pageY,
clientX : _natE.clientX,
clientY : _natE.clientY,
altKey : _natE.altKey,
shiftKey : _natE.shiftKey,
ctrlKey : _natE.ctrlKey,
metaKey : _natE.metaKey,
button : AscCommon.g_mouse_button_right,
target : e.target,
srcElement : e.srcElement
};
AscCommon.isTouch = true;
this.onmousedown(_eContextMenu, true);
this.onmouseup(_eContextMenu, undefined, true);
AscCommon.isTouch = false;
}
AscCommon.isTouchMove = false;
AscCommon.TouchStartTime = -1;
return _ret; return _ret;
}; };
this.m_oEditor.HtmlElement["ontouchcancel"] = this.m_oOverlay.HtmlElement["ontouchcancel"] = function(e) { _cur["ontouchcancel"] = this.m_oEditor.HtmlElement["ontouchcancel"] = this.m_oOverlay.HtmlElement["ontouchcancel"] = function(e) {
//console.log("cancel: " + AscCommon.isTouch); //console.log("cancel: " + AscCommon.isTouch);
if (!AscCommon.isTouch) if (!AscCommon.isTouch)
...@@ -743,6 +785,34 @@ function CEditorPage(api) ...@@ -743,6 +785,34 @@ function CEditorPage(api)
AscCommon.stopEvent(e); AscCommon.stopEvent(e);
var _ret = this.onmouseup(_check_e(e), undefined, true); var _ret = this.onmouseup(_check_e(e), undefined, true);
global_mouseEvent.KoefPixToMM = _old; global_mouseEvent.KoefPixToMM = _old;
if (!AscCommon.isTouchMove && (-1 != AscCommon.TouchStartTime) && (Math.abs(AscCommon.TouchStartTime - (new Date().getTime())) > 900))
{
var _eContextMenu = {
pageX : _natE.pageX,
pageY : _natE.pageY,
clientX : _natE.clientX,
clientY : _natE.clientY,
altKey : _natE.altKey,
shiftKey : _natE.shiftKey,
ctrlKey : _natE.ctrlKey,
metaKey : _natE.metaKey,
button : AscCommon.g_mouse_button_right,
target : e.target,
srcElement : e.srcElement
};
AscCommon.isTouch = true;
this.onmousedown(_eContextMenu, true);
this.onmouseup(_eContextMenu, undefined, true);
AscCommon.isTouch = false;
}
AscCommon.isTouchMove = false;
AscCommon.TouchStartTime = -1;
return _ret; return _ret;
}; };
} }
...@@ -1633,7 +1703,7 @@ function CEditorPage(api) ...@@ -1633,7 +1703,7 @@ function CEditorPage(api)
this.onMouseDown = function(e, isTouch) this.onMouseDown = function(e, isTouch)
{ {
//console.log("down: " + isTouch + ", " + AscCommon.isTouch); console.log("down: " + isTouch + ", " + AscCommon.isTouch);
if (false === oThis.m_oApi.bInit_word_control || (AscCommon.isTouch && undefined === isTouch)) if (false === oThis.m_oApi.bInit_word_control || (AscCommon.isTouch && undefined === isTouch))
return; return;
...@@ -1819,7 +1889,7 @@ function CEditorPage(api) ...@@ -1819,7 +1889,7 @@ function CEditorPage(api)
}; };
this.onMouseUp = function(e, bIsWindow, isTouch) this.onMouseUp = function(e, bIsWindow, isTouch)
{ {
//console.log("up: " + isTouch + ", " + AscCommon.isTouch); console.log("up: " + isTouch + ", " + AscCommon.isTouch);
if (false === oThis.m_oApi.bInit_word_control || (AscCommon.isTouch && undefined === isTouch)) if (false === oThis.m_oApi.bInit_word_control || (AscCommon.isTouch && undefined === isTouch))
return; return;
//if (true == global_mouseEvent.IsLocked) //if (true == global_mouseEvent.IsLocked)
......
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