Commit b86f6286 authored by Oleg Korshul's avatar Oleg Korshul

focus

parent e30d1027
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
process : 1, process : 1,
end : 2 end : 2
}; };
function CTextInput(api) function CTextInput(api)
{ {
this.Api = api; this.Api = api;
...@@ -74,6 +75,8 @@ ...@@ -74,6 +75,8 @@
this.IsLockTargetMode = false; this.IsLockTargetMode = false;
this.IsUseFirstTextInputAfterComposition = false; this.IsUseFirstTextInputAfterComposition = false;
this.nativeFocusElement = null;
} }
CTextInput.prototype = CTextInput.prototype =
...@@ -134,7 +137,8 @@ ...@@ -134,7 +137,8 @@
oHtmlDivScrollable.appendChild(this.HtmlDiv); oHtmlDivScrollable.appendChild(this.HtmlDiv);
oHtmlParent.parentNode.appendChild(oHtmlDivScrollable); oHtmlParent.parentNode.appendChild(oHtmlDivScrollable);
oHtmlParent.onresize = function(e) { oHtmlParent.onresize = function(e)
{
var _elem = document.getElementById("area_id_parent"); var _elem = document.getElementById("area_id_parent");
var style = getComputedStyle(oHtmlParent); var style = getComputedStyle(oHtmlParent);
_elem.style.left = style.left; _elem.style.left = style.left;
...@@ -150,20 +154,44 @@ ...@@ -150,20 +154,44 @@
// events: // events:
var oThis = this; var oThis = this;
this.HtmlArea["onkeydown"] = function(e) { return oThis.onKeyDown(e); }; this.HtmlArea["onkeydown"] = function(e)
this.HtmlArea["onkeypress"] = function(e) { return oThis.onKeyPress(e); }; {
this.HtmlArea["onkeyup"] = function(e) { return oThis.onKeyUp(e); }; return oThis.onKeyDown(e);
};
this.HtmlArea["onkeypress"] = function(e)
{
return oThis.onKeyPress(e);
};
this.HtmlArea["onkeyup"] = function(e)
{
return oThis.onKeyUp(e);
};
this.HtmlArea.addEventListener("input", function(e) { return oThis.onInput(e); }, false); this.HtmlArea.addEventListener("input", function(e)
this.HtmlArea.addEventListener("textInput", function(e) { return oThis.onTextInput(e); }, false); {
return oThis.onInput(e);
}, false);
this.HtmlArea.addEventListener("textInput", function(e)
{
return oThis.onTextInput(e);
}, false);
this.HtmlArea.addEventListener("compositionstart", function(e) { return oThis.onCompositionStart(e); }, false); this.HtmlArea.addEventListener("compositionstart", function(e)
this.HtmlArea.addEventListener("compositionupdate", function(e) { return oThis.onCompositionUpdate(e); }, false); {
this.HtmlArea.addEventListener("compositionend", function(e) { return oThis.onCompositionEnd(e); }, false); return oThis.onCompositionStart(e);
}, false);
this.HtmlArea.addEventListener("compositionupdate", function(e)
{
return oThis.onCompositionUpdate(e);
}, false);
this.HtmlArea.addEventListener("compositionend", function(e)
{
return oThis.onCompositionEnd(e);
}, false);
this.show(false); this.show(false);
// TODO: /*
setInterval(function(){ setInterval(function(){
if (oThis.Api.asc_IsFocus() && !AscCommon.g_clipboardBase.IsFocus() && !AscCommon.g_clipboardBase.IsWorking()) if (oThis.Api.asc_IsFocus() && !AscCommon.g_clipboardBase.IsFocus() && !AscCommon.g_clipboardBase.IsWorking())
{ {
...@@ -171,6 +199,7 @@ ...@@ -171,6 +199,7 @@
oThis.HtmlArea.focus(); oThis.HtmlArea.focus();
} }
}, 10); }, 10);
*/
this.Api.Input_UpdatePos(); this.Api.Input_UpdatePos();
}, },
...@@ -193,7 +222,8 @@ ...@@ -193,7 +222,8 @@
*/ */
var oThis = this; var oThis = this;
setTimeout(function(){ setTimeout(function()
{
oThis.checkFocus(); oThis.checkFocus();
oThis.initTimer(); oThis.initTimer();
}, 40); }, 40);
...@@ -263,11 +293,71 @@ ...@@ -263,11 +293,71 @@
} }
}, },
emulateNativeKeyDown : function(e)
{
var oEvent = document.createEvent('KeyboardEvent');
/*
var _event = new KeyboardEvent("keydown", {
bubbles : true,
cancelable : true,
char : e.charCode,
shiftKey : e.shiftKey,
ctrlKey : e.ctrlKey,
metaKey : e.metaKey,
altKey : e.altKey,
keyCode : e.keyCode,
which : e.which,
key : e.key
});
*/
// Chromium Hack
Object.defineProperty(oEvent, 'keyCode', {
get : function()
{
return this.keyCodeVal;
}
});
Object.defineProperty(oEvent, 'which', {
get : function()
{
return this.keyCodeVal;
}
});
var k = e.keyCode;
if (oEvent.initKeyboardEvent)
{
oEvent.initKeyboardEvent("keydown", true, true, window, false, false, false, false, k, k);
}
else
{
oEvent.initKeyEvent("keydown", true, true, window, false, false, false, false, k, 0);
}
oEvent.keyCodeVal = k;
var _elem = _getElementKeyboardDown(this.nativeFocusElement, 3);
_elem.dispatchEvent(oEvent);
return oEvent.defaultPrevented;
},
onKeyDown : function(e) onKeyDown : function(e)
{ {
if (c_oCompositionState.end != this.compositionState) if (c_oCompositionState.end != this.compositionState)
return; return;
if (null != this.nativeFocusElement)
{
if (this.emulateNativeKeyDown(e))
{
e.preventDefault();
return false;
}
}
// некоторые рукописные вводы не присылают keyUp // некоторые рукописные вводы не присылают keyUp
var _code = e.keyCode; var _code = e.keyCode;
if (_code != 8 && _code != 46) if (_code != 8 && _code != 46)
...@@ -319,7 +409,10 @@ ...@@ -319,7 +409,10 @@
this.Api.asc_LockTargetUpdate(true); this.Api.asc_LockTargetUpdate(true);
var oThis = this; var oThis = this;
this.LockerTargetTimer = setTimeout(function(){ oThis.unlockTarget(); }, 1000); this.LockerTargetTimer = setTimeout(function()
{
oThis.unlockTarget();
}, 1000);
}, },
unlockTarget : function() unlockTarget : function()
...@@ -440,6 +533,29 @@ ...@@ -440,6 +533,29 @@
} }
}; };
function _getAttirbute(_elem, _attr, _depth)
{
var _elemTest = _elem;
for (var _level = 0; _elemTest && (_level < _depth); ++_level, _elemTest = _elemTest.parentNode)
{
var _res = _elemTest.getAttribute(_attr);
if (null != _res)
return _res;
}
return null;
}
function _getElementKeyboardDown(_elem, _depth)
{
var _elemTest = _elem;
for (var _level = 0; _elemTest && (_level < _depth); ++_level, _elemTest = _elemTest.parentNode)
{
var _res = _elemTest.getAttribute("oo_editor_keyboard");
if (null != _res)
return _elemTest;
}
return null;
}
window['AscCommon'] = window['AscCommon'] || {}; window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].CTextInput = CTextInput; window['AscCommon'].CTextInput = CTextInput;
...@@ -448,5 +564,86 @@ ...@@ -448,5 +564,86 @@
window['AscCommon'].g_inputContext = new CTextInput(api); window['AscCommon'].g_inputContext = new CTextInput(api);
window['AscCommon'].g_inputContext.init(target_id); window['AscCommon'].g_inputContext.init(target_id);
window['AscCommon'].g_clipboardBase.Init(api); window['AscCommon'].g_clipboardBase.Init(api);
document.addEventListener("focus", function(e)
{
var t = window['AscCommon'].g_inputContext;
t.nativeFocusElement = e.target;
//console.log(t.nativeFocusElement);
if (t.nativeFocusElement.id == t.HtmlArea.id)
{
t.Api.asc_enableKeyEvents(true);
t.nativeFocusElement = null;
return;
}
if (t.nativeFocusElement.id == window['AscCommon'].g_clipboardBase.CommonDivId)
{
t.nativeFocusElement = null;
return;
}
var _isElementEditable = false;
if (true)
{
// detect _isElementEditable
var _name = t.nativeFocusElement.nodeName;
if (_name)
_name = _name.toUpperCase();
if ("INPUT" == _name || "TEXTAREA" == _name)
_isElementEditable = true;
else if ("DIV" == _name)
{
if (t.nativeFocusElement.getAttribute("contenteditable") == "true")
_isElementEditable = true;
}
}
if ("IFRAME" == _name)
{
// перехват клавиатуры
t.Api.asc_enableKeyEvents(false);
t.nativeFocusElement = null;
return;
}
// перехватывает ли элемент ввод
var _oo_editor_input = _getAttirbute(t.nativeFocusElement, "oo_editor_input", 3);
// нужно ли прокидывать нажатие клавиш элементу (ТОЛЬКО keyDown)
var _oo_editor_keyboard = _getAttirbute(t.nativeFocusElement, "oo_editor_keyboard", 3);
if (_oo_editor_keyboard == "true")
_oo_editor_input = undefined;
if (_oo_editor_input == "true")
{
// перехват клавиатуры
t.Api.asc_enableKeyEvents(false);
t.nativeFocusElement = null;
return;
}
if (_isElementEditable && (_oo_editor_input != "false"))
{
// перехват клавиатуры
t.Api.asc_enableKeyEvents(false);
t.nativeFocusElement = null;
return;
}
// итак, ввод у нас. теперь определяем, нужна ли клавиатура элементу
if (_oo_editor_keyboard != "true")
t.nativeFocusElement = null;
var _elem = t.nativeFocusElement;
t.HtmlArea.focus();
t.nativeFocusElement = _elem;
t.Api.asc_enableKeyEvents(true);
}, true);
// send focus
window['AscCommon'].g_inputContext.HtmlArea.focus();
}; };
})(window); })(window);
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