Commit 6254fe3d authored by Oleg Korshul's avatar Oleg Korshul

copy/paste новая схема, новый ввод

parent 59006b72
"use strict";
///
// api редактора должен иметь методы
// 1) asc_IsFocus(true /* bIsNaturalFocus */) - это принимаем ли мы сейчас клавиатуру.
// bIsNaturalFocus - это параметр, говорящий о том, что нам нужен фокус наш, исключая поля для ввода (иероглифы например)
// 2) asc_CheckCopy(_clipboard /* CClipboardData */, _formats) - для наполнения буфера обмена.
// В нем вызывать _clipboard.pushData(_format, _data); _formats - какие форматы нужны
// 3) asc_PasteData(_format, ...)
// 4) incrementCounterLongAction / decrementCounterLongAction - для залочивания вставки
// 5) asc_SelectionCut();
///
// Для инициализации вызвать g_clipboardBase.Init(api); в любой момент времени
// Import
var AscBrowser = AscCommon.AscBrowser;
var c_oAscClipboardDataFormat = {
(function(window, undefined)
{
///
// api редактора должен иметь методы
// 1) asc_IsFocus(true /* bIsNaturalFocus */) - это принимаем ли мы сейчас клавиатуру.
// bIsNaturalFocus - это параметр, говорящий о том, что нам нужен фокус наш, исключая поля для ввода (иероглифы например)
// 2) asc_CheckCopy(_clipboard /* CClipboardData */, _formats) - для наполнения буфера обмена.
// В нем вызывать _clipboard.pushData(_format, _data); _formats - какие форматы нужны
// 3) asc_PasteData(_format, ...)
// 4) incrementCounterLongAction / decrementCounterLongAction - для залочивания вставки
// 5) asc_SelectionCut();
///
// Для инициализации вызвать g_clipboardBase.Init(api); в любой момент времени
// Import
var AscBrowser = AscCommon.AscBrowser;
var c_oAscClipboardDataFormat = {
Text : 1,
Html : 2,
Internal : 4,
HtmlElement : 8
};
AscCommon.c_oAscClipboardDataFormat = c_oAscClipboardDataFormat;
};
AscCommon.c_oAscClipboardDataFormat = c_oAscClipboardDataFormat;
function CClipboardBase()
{
function CClipboardBase()
{
this.PasteFlag = false;
this.CopyFlag = false;
......@@ -48,13 +50,16 @@ function CClipboardBase()
this.CommonIframe = null;
this.ClosureParams = {};
}
CClipboardBase.prototype =
{
this.CopyPasteFocus = false;
this.CopyPasteFocusTimer = -1;
}
CClipboardBase.prototype =
{
_console_log : function(_obj)
{
console.log(_obj);
//console.log(_obj);
},
_private_oncopy : function(e)
......@@ -122,7 +127,8 @@ CClipboardBase.prototype =
if (this.IsNeedDivOnPaste)
{
window.setTimeout( function() {
window.setTimeout(function()
{
g_clipboardBase.Api.asc_PasteData(AscCommon.c_oAscClipboardDataFormat.HtmlElement, g_clipboardBase.CommonDiv);
g_clipboardBase.CommonDiv_End();
......@@ -149,7 +155,7 @@ CClipboardBase.prototype =
if (_html_format && _html_format != "")
{
var nIndex = _html_format.indexOf("</html>");
if(-1 != nIndex)
if (-1 != nIndex)
_html_format = _html_format.substring(0, nIndex + "</html>".length);
this.CommonIframe_PasteStart(_html_format);
......@@ -162,15 +168,15 @@ CClipboardBase.prototype =
var sHtml = "<html><body>";
var sCurPar = "";
var nParCount = 0;
for ( var i = 0, length = _text_format.length; i < length; i++ )
for (var i = 0, length = _text_format.length; i < length; i++)
{
var Char = _text_format.charAt(i);
var Code = _text_format.charCodeAt(i);
var Item = null;
if ( '\n' === Char )
if ('\n' === Char)
{
if("" == sCurPar)
if ("" == sCurPar)
sHtml += "<p><span>&nbsp;</span></p>";
else
{
......@@ -179,7 +185,7 @@ CClipboardBase.prototype =
}
nParCount++;
}
else if ( 13 === Code )
else if (13 === Code)
{
continue;
}
......@@ -228,12 +234,13 @@ CClipboardBase.prototype =
{
this._console_log("onbeforepaste");
if (isAttackEmulate === true)
//if (isAttackEmulate === true)
{
this.CommonDiv = this.CommonDiv_Check();
this.CommonDiv_Start();
this.CommonDiv.focus();
this.StartFocus();
this.CommonDiv_Select();
return;
}
......@@ -252,6 +259,7 @@ CClipboardBase.prototype =
this.CommonDiv.innerHTML = "<span> </span>";
this.CommonDiv.focus();
this.StartFocus();
this.CommonDiv_Select();
}
},
......@@ -260,13 +268,14 @@ CClipboardBase.prototype =
{
this._console_log("onbeforecopy");
if (isAttackEmulate === true)
//if (isAttackEmulate === true)
{
this.CommonDiv = this.CommonDiv_Check();
this.CommonDiv_Start();
this.CommonDiv.innerHTML = "<span> </span>";
this.CommonDiv.focus();
this.StartFocus();
this.CommonDiv_Select();
}
......@@ -291,7 +300,7 @@ CClipboardBase.prototype =
{
return _clipboard.getData(_type);
}
catch ( e )
catch (e)
{
}
return null;
......@@ -311,28 +320,64 @@ CClipboardBase.prototype =
{
_clipboard.setData(_type, _data);
}
catch ( e )
catch (e)
{
}
};
if (!AscBrowser.isIE)
{
document.oncopy = function(e) { return g_clipboardBase._private_oncopy(e) };
document.oncut = function(e) { return g_clipboardBase._private_oncut(e) };
document.onpaste = function (e) { return g_clipboardBase._private_onpaste(e); };
document["onbeforecopy"] = function(e) { return g_clipboardBase._private_onbeforecopy(e); };
document["onbeforecut"] = function(e) { return g_clipboardBase._private_onbeforecopy(e); };
document["onbeforepaste"] = function (e) { return g_clipboardBase._private_onbeforepaste(e); };
document.oncopy = function(e)
{
return g_clipboardBase._private_oncopy(e)
};
document.oncut = function(e)
{
return g_clipboardBase._private_oncut(e)
};
document.onpaste = function(e)
{
return g_clipboardBase._private_onpaste(e);
};
document["onbeforecopy"] = function(e)
{
return g_clipboardBase._private_onbeforecopy(e);
};
document["onbeforecut"] = function(e)
{
return g_clipboardBase._private_onbeforecopy(e);
};
document["onbeforepaste"] = function(e)
{
return g_clipboardBase._private_onbeforepaste(e);
};
}
else
{
document.addEventListener("copy", function(e) { return g_clipboardBase._private_oncopy(e); });
document.addEventListener("cut", function(e) { return g_clipboardBase._private_oncut(e); });
document.addEventListener("paste", function(e) { return g_clipboardBase._private_onpaste(e); });
document.addEventListener("beforepaste", function(e) { return g_clipboardBase._private_onbeforepaste(e); });
document.addEventListener("beforecopy", function(e) { return g_clipboardBase._private_onbeforecopy(e); });
document.addEventListener("beforecut", function(e) { return g_clipboardBase._private_onbeforecopy(e); });
document.addEventListener("copy", function(e)
{
return g_clipboardBase._private_oncopy(e);
});
document.addEventListener("cut", function(e)
{
return g_clipboardBase._private_oncut(e);
});
document.addEventListener("paste", function(e)
{
return g_clipboardBase._private_onpaste(e);
});
document.addEventListener("beforepaste", function(e)
{
return g_clipboardBase._private_onbeforepaste(e);
});
document.addEventListener("beforecopy", function(e)
{
return g_clipboardBase._private_onbeforecopy(e);
});
document.addEventListener("beforecut", function(e)
{
return g_clipboardBase._private_onbeforecopy(e);
});
}
if (this.IsCopyCutOnlyInEditable || this.IsPasteOnlyInEditable)
......@@ -369,7 +414,7 @@ CClipboardBase.prototype =
{
isEmulate = _cut ? document.execCommand("beforecut") : document.execCommand("beforecopy");
}
catch(err)
catch (err)
{
}
......@@ -403,11 +448,12 @@ CClipboardBase.prototype =
};
}
if (AscBrowser.isSafari)
if (AscBrowser.isSafari && false)
{
this.CommonDiv = this.CommonDiv_Check();
setInterval(function(){
setInterval(function()
{
if (g_clipboardBase.Api.asc_IsFocus(true))
g_clipboardBase.CommonDiv.focus();
......@@ -421,10 +467,41 @@ CClipboardBase.prototype =
return (this.CopyFlag || this.PasteFlag) ? true : false;
},
StartFocus : function()
{
// не плодим таймеры
this.EndFocus();
this.CopyPasteFocus = true;
// этот метод используется на beforeCopy/Cut/Paste
// нужно не отдать фокус текстовому полю (до настоящих Copy/Cut/Paste)
// время ставим с запасом, так как обрубим на конец Copy/Cut/Paste
this.CopyPasteFocusTimer = setTimeout(function(){
g_clipboardBase.EndFocus();
}, 1000);
},
EndFocus : function()
{
this.CopyPasteFocus = false;
if (-1 != this.CopyPasteFocusTimer)
{
clearTimeout(this.CopyPasteFocusTimer);
this.CopyPasteFocusTimer = -1;
}
},
IsFocus : function()
{
return this.CopyPasteFocus;
},
CommonDiv_Check : function()
{
var ElemToSelect = document.getElementById( this.CommonDivId );
if ( !ElemToSelect )
var ElemToSelect = document.getElementById(this.CommonDivId);
if (!ElemToSelect)
{
ElemToSelect = document.createElement("div");
ElemToSelect.id = this.CommonDivId;
......@@ -460,15 +537,15 @@ CClipboardBase.prototype =
var is_gecko = AscBrowser.isGecko;
if (is_gecko)
{
ElemToSelect.appendChild( document.createTextNode( '\xa0' ) );
ElemToSelect.insertBefore( document.createTextNode( '\xa0' ), ElemToSelect.firstChild );
rangeToSelect.setStartAfter (ElemToSelect.firstChild);
rangeToSelect.setEndBefore (ElemToSelect.lastChild);
ElemToSelect.appendChild(document.createTextNode('\xa0'));
ElemToSelect.insertBefore(document.createTextNode('\xa0'), ElemToSelect.firstChild);
rangeToSelect.setStartAfter(ElemToSelect.firstChild);
rangeToSelect.setEndBefore(ElemToSelect.lastChild);
}
else
{
var aChildNodes = ElemToSelect.childNodes;
if(aChildNodes.length == 1)
if (aChildNodes.length == 1)
{
var elem = aChildNodes[0];
var wrap = document.createElement("b");
......@@ -477,11 +554,11 @@ CClipboardBase.prototype =
wrap.appendChild(elem);
ElemToSelect.appendChild(wrap);
}
rangeToSelect.selectNodeContents (ElemToSelect);
rangeToSelect.selectNodeContents(ElemToSelect);
}
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
selection.removeAllRanges();
selection.addRange(rangeToSelect);
}
else
{
......@@ -505,8 +582,8 @@ CClipboardBase.prototype =
var ElemToSelect = this.CommonDiv;
ElemToSelect.style.display = "block";
while ( ElemToSelect.hasChildNodes() )
ElemToSelect.removeChild( ElemToSelect.lastChild );
while (ElemToSelect.hasChildNodes())
ElemToSelect.removeChild(ElemToSelect.lastChild);
document.body.style.MozUserSelect = "text";
delete document.body.style["-khtml-user-select"];
......@@ -534,6 +611,7 @@ CClipboardBase.prototype =
document.body.style.overflow = this.ClosureParams.overflowBody;
this.CopyFlag = false;
this.EndFocus();
},
CommonDiv_Copy : function()
......@@ -549,7 +627,8 @@ CClipboardBase.prototype =
this.CommonDiv_Select();
window.setTimeout( function() {
window.setTimeout(function()
{
g_clipboardBase.CommonDiv_End();
......@@ -588,12 +667,12 @@ CClipboardBase.prototype =
ifr.style.width = '10000px';
var frameWindow = window.frames[this.CommonIframeId];
if(frameWindow)
if (frameWindow)
{
frameWindow.document.open();
frameWindow.document.write(_html_data);
frameWindow.document.close();
if(null != frameWindow.document && null != frameWindow.document.body)
if (null != frameWindow.document && null != frameWindow.document.body)
{
ifr.style.display = "block";
......@@ -620,6 +699,7 @@ CClipboardBase.prototype =
this.CommonIframe_PasteEnd();
this.Api.decrementCounterLongAction();
this.PasteFlag = false;
this.EndFocus();
},
pushData : function(_format, _data)
......@@ -672,6 +752,9 @@ CClipboardBase.prototype =
{
return document.execCommand("paste");
}
};
};
var g_clipboardBase = new CClipboardBase();
\ No newline at end of file
var g_clipboardBase = new CClipboardBase();
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].g_clipboardBase = g_clipboardBase;
})(window);
\ No newline at end of file
......@@ -85,7 +85,7 @@
// TODO:
setInterval(function(){
if (oThis.Api.asc_IsFocus())
if (oThis.Api.asc_IsFocus() && !AscCommon.g_clipboardBase.IsFocus() && !AscCommon.g_clipboardBase.IsWorking())
oThis.HtmlArea.focus();
}, 10);
},
......@@ -318,4 +318,11 @@
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].CTextInput = CTextInput;
window['AscCommon'].InitBrowserInputContext = function(api, target_id)
{
window['AscCommon'].g_inputContext = new CTextInput(api);
window['AscCommon'].g_inputContext.init(target_id);
window['AscCommon'].g_clipboardBase.Init(api);
};
})(window);
......@@ -3064,6 +3064,9 @@ function CDrawingDocument()
this.m_oWordControl.CheckTextBoxInputPos();
}
if (AscCommon.g_inputContext)
AscCommon.g_inputContext.move(this.TargetHtmlElementLeft, this.TargetHtmlElementTop);
}
this.UpdateTargetTransform = function(matrix)
......
......@@ -549,9 +549,12 @@ function CEditorPage(api)
this.m_oLeftRuler_vertRuler.HtmlElement.onmouseup = this.verRulerMouseUp;//new Function("event", "verRulerMouseUp(event);");
this.m_oLeftRuler_vertRuler.HtmlElement.onmousemove = this.verRulerMouseMove;//new Function("event", "verRulerMouseMove(event);");
/*
// теперь все делает AscCommon.InitBrowserSystemContext
window.onkeydown = this.onKeyDown;//Editor_OnKeyDown;
window.onkeypress = this.onKeyPress;//Editor_OnKeyPress;
window.onkeyup = this.onKeyUp;
*/
this.m_oBody.HtmlElement.oncontextmenu = function() { return false; };
//window.oncontextmenu = function() { return false; };
......@@ -2559,7 +2562,7 @@ function CEditorPage(api)
}
this.onKeyPress = function(e)
{
if (window.GlobalPasteFlag || window.GlobalCopyFlag)
if (AscCommon.g_clipboardBase.IsWorking())
return;
if (oThis.m_oApi.isLongAction())
......@@ -3688,6 +3691,8 @@ function CEditorPage(api)
window["AutoTester"]["RunTest"]();
}
AscCommon.InitBrowserInputContext(this.m_oApi, "id_target_cursor");
//this.m_oDrawingDocument.CheckFontCache();
}
......@@ -3761,7 +3766,7 @@ function CEditorPage(api)
if (oWordControl.IsFocus && oWordControl.TextBoxInputMode && oWordControl.TextBoxInput && !AscCommon.AscBrowser.isSafariMacOs)
{
if (!oWordControl.m_oApi.isLongAction() && !window.GlobalCopyFlag)
if (!oWordControl.m_oApi.isLongAction() && !AscCommon.g_clipboardBase.IsWorking())
oWordControl.TextBoxInput.focus();
}
......@@ -3775,7 +3780,7 @@ function CEditorPage(api)
if (null != oWordControl.m_oLogicDocument && oWordControl.m_oApi.bInit_word_control)
oWordControl.m_oLogicDocument.Viewer_OnChangePosition();
}
if (null != oWordControl.m_oLogicDocument)
if (null != oWordControl.m_oLogicDocument && !oWordControl.m_oApi.isLockTargetUpdate)
{
oWordControl.m_oDrawingDocument.UpdateTargetFromPaint = true;
oWordControl.m_oLogicDocument.CheckTargetUpdate();
......
......@@ -11179,45 +11179,6 @@ CDocument.prototype.OnKeyDown = function(e)
this.Cursor_MoveDown(true === e.ShiftKey);
bRetValue = keydownresult_PreventAll;
}
else if (e.KeyCode == 45) // Insert
{
if (true === e.CtrlKey) // Ctrl + Insert (аналогично Ctrl + C)
{
Editor_Copy(this.Api);
bRetValue = keydownresult_PreventKeyPress;
}
else if (true === e.ShiftKey && false === editor.isViewMode) // Shift + Insert (аналогично Ctrl + V)
{
if (false === this.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
if (!window.GlobalPasteFlag)
{
if (!AscCommon.AscBrowser.isSafariMacOs)
{
this.Create_NewHistoryPoint(AscDFH.historydescription_Document_ShiftInsert);
window.GlobalPasteFlag = true;
editor.incrementCounterLongAction();
Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
bRetValue = keydownresult_PreventKeyPress;
}
else
{
if (0 === window.GlobalPasteFlagCounter)
{
this.Create_NewHistoryPoint(AscDFH.historydescription_Document_ShiftInsertSafari);
AscCommon.SafariIntervalFocus();
window.GlobalPasteFlag = true;
editor.incrementCounterLongAction();
Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
bRetValue = keydownresult_PreventKeyPress;
}
}
}
}
}
}
else if (e.KeyCode == 46 && false === editor.isViewMode) // Delete
{
if (true != e.ShiftKey)
......@@ -11229,14 +11190,6 @@ CDocument.prototype.OnKeyDown = function(e)
}
bRetValue = keydownresult_PreventAll;
}
else // Shift + Delete (аналогично Ctrl + X)
{
if (false === this.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
Editor_Copy(this.Api, true);
}
bRetValue = keydownresult_PreventKeyPress;
}
}
else if (e.KeyCode == 49 && false === editor.isViewMode && true === e.AltKey && !e.AltGr) // Alt + Ctrl + Num1 - применяем стиль Heading1
{
......@@ -11309,11 +11262,6 @@ CDocument.prototype.OnKeyDown = function(e)
this.Document_Format_Copy();
bRetValue = keydownresult_PreventAll;
}
else // Ctrl + C - copy
{
Editor_Copy(this.Api);
bRetValue = keydownresult_PreventKeyPress;
}
}
else if (e.KeyCode == 69 && false === editor.isViewMode && true === e.CtrlKey) // Ctrl + E + ...
{
......@@ -11432,59 +11380,6 @@ CDocument.prototype.OnKeyDown = function(e)
bRetValue = keydownresult_PreventAll;
}
}
else if (e.KeyCode == 86 && false === editor.isViewMode && true === e.CtrlKey) // Ctrl + V - paste
{
if (false === this.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
if (true === e.ShiftKey) // Ctrl + Shift + V - вставляем по образцу
{
this.Create_NewHistoryPoint(AscDFH.historydescription_Document_FormatPasteHotKey);
this.Document_Format_Paste();
bRetValue = keydownresult_PreventAll;
}
else // Ctrl + V - paste
{
if (!window.GlobalPasteFlag)
{
if (!AscCommon.AscBrowser.isSafariMacOs)
{
this.Create_NewHistoryPoint(AscDFH.historydescription_Document_PasteHotKey);
window.GlobalPasteFlag = true;
editor.incrementCounterLongAction();
Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
bRetValue = keydownresult_PreventKeyPress;
}
else
{
if (0 === window.GlobalPasteFlagCounter)
{
this.Create_NewHistoryPoint(AscDFH.historydescription_Document_PasteSafariHotKey);
AscCommon.SafariIntervalFocus();
window.GlobalPasteFlag = true;
editor.incrementCounterLongAction();
Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
bRetValue = keydownresult_PreventKeyPress;
}
}
}
else
{
if (!AscCommon.AscBrowser.isSafariMacOs)
bRetValue = keydownresult_PreventAll;
}
}
}
}
else if (e.KeyCode == 88 && false === editor.isViewMode && true === e.CtrlKey) // Ctrl + X - cut
{
if (false === this.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
Editor_Copy(this.Api, true);
}
bRetValue = keydownresult_PreventKeyPress;
}
else if (e.KeyCode == 89 && false === editor.isViewMode && true === e.CtrlKey) // Ctrl + Y - Redo
{
this.Document_Redo();
......
......@@ -814,9 +814,6 @@ background-repeat: no-repeat;\
PasteElementsId.PASTE_ELEMENT_ID = "wrd_pastebin";
PasteElementsId.ELEMENT_DISPAY_STYLE = "none";
}
if (AscCommon.AscBrowser.isSafariMacOs)
setInterval(AscCommon.SafariIntervalFocus, 10);
};
// Callbacks
/* все имена callback'оф начинаются с On. Пока сделаны:
......@@ -1882,23 +1879,10 @@ background-repeat: no-repeat;\
if (false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
if (!window.GlobalPasteFlag)
{
if (!AscCommon.AscBrowser.isSafariMacOs)
{
window.GlobalPasteFlag = true;
return AscCommon.Editor_Paste_Button(this);
}
else
{
if (0 === window.GlobalPasteFlagCounter)
{
AscCommon.SafariIntervalFocus();
window.GlobalPasteFlag = true;
return AscCommon.Editor_Paste_Button(this);
}
}
}
if (AscCommon.g_clipboardBase.IsWorking())
return false;
return AscCommon.g_clipboardBase.Button_Paste();
}
};
......@@ -6864,29 +6848,8 @@ background-repeat: no-repeat;\
// там при LongActions теряется фокус и вставляются пробелы
this.decrementCounterLongAction();
this.pasteCallback();
window.GlobalPasteFlag = false;
window.GlobalPasteFlagCounter = 0;
this.pasteCallback = null;
if (-1 != window.PasteEndTimerId)
{
clearTimeout(window.PasteEndTimerId);
window.PasteEndTimerId = -1;
document.body.style.MozUserSelect = "none";
document.body.style["-khtml-user-select"] = "none";
document.body.style["-o-user-select"] = "none";
document.body.style["user-select"] = "none";
document.body.style["-webkit-user-select"] = "none";
var pastebin = AscCommon.Editor_Paste_GetElem(this, true);
if (!AscCommon.AscBrowser.isSafariMacOs)
pastebin.onpaste = null;
pastebin.style.display = PasteElementsId.ELEMENT_DISPAY_STYLE;
}
return;
}
......
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