<ul><li>Command state observer; I can now tell the host when certain command's state has changes</li><li>Escape style rules for tables that are contained in controls</li></ul>

svn path=/trunk/aspeditor/; revision=49680
This commit is contained in:
Blagovest Dachev 2005-09-08 06:01:39 +00:00
Родитель aae97d6f8e
Коммит 2679124b91
2 изменённых файлов: 137 добавлений и 69 удалений

Просмотреть файл

@ -79,6 +79,25 @@ const REDO = 'cmd_redo';
// Implementations of some XPCOM interfaces, to observe various editor events
// and actions. Do not remove any of the methods entirely or Mozilla will choke
//_____________________________________________________________________________
// nsIObserver implementation
var gNsIObserverImplementation = {
// Tel the host command status has changed.
observe: function (aSubject, aTopic, aData)
{
switch (aTopic) {
case 'cmd_bold':
break;
case 'cmd_italics':
break;
case 'cmd_underline':
break;
case 'cmd_indent':
break;
case 'cmd_outdent':
break;
}
}
}
// nsISelectionListener implementation
// TODO: Redo this one, accounting for recursive calls
@ -403,6 +422,7 @@ aspNetHost.prototype =
JSCallRegisterClrHandler ('SelectControl', JSCall_SelectControl);
// HTML editing
JSCallRegisterClrHandler ('DoCommand', JSCall_DoCommand);
JSCallRegisterClrHandler ('IsCommandEnabled', JSCall_IsCommandEnabled);
JSCallRegisterClrHandler ('InsertFragment', JSCall_InsertFragment);
//tell the host we're ready for business
@ -496,11 +516,15 @@ function JSCall_LoadPage (arg) {
function JSCall_DoCommand (arg) {
var command = arg [0];
dump ('Executing command "' + command +'"...');
editor.doCommand (command);
return "";
}
function JSCall_IsCommandEnabled (arg) {
var command = arg [0];
return editor.isCommandEnabled (command);
}
function JSCall_InsertFragment (arg) {
return editor.insertFragment (arg [0]);
}
@ -638,36 +662,15 @@ aspNetEditor.prototype =
selectionPrivate.addSelectionListener (gNsISelectionListenerImplementation);
this.mNsIHtmlEditor.addObjectResizeEventListener (gNsIHTMLObjectResizeListenerImplementation);
this.mNsIHtmlEditor.addEditActionListener (gNsIEditActionListenerImplementation);
this.mNsICommandManager.addCommandObserver (gNsIObserverImplementation, 'cmd_bold');
this.mNsICommandManager.addCommandObserver (gNsIObserverImplementation, 'cmd_italics');
this.mNsICommandManager.addCommandObserver (gNsIObserverImplementation, 'cmd_underline');
this.mNsICommandManager.addCommandObserver (gNsIObserverImplementation, 'cmd_indent');
this.mNsICommandManager.addCommandObserver (gNsIObserverImplementation, 'cmd_outdent');
// ?????????????????????????????????????????????????????????????????????????
// Bug in Mozilla's InsertHTMLWithContext?
//this.mNsIHtmlEditor.addInsertionListener (gNsIContentFilterImplementation);
// All of our event listeners are added to the document here
this.base.document.addEventListener ('mousedown',
selectFromClick,
true);
this.base.document.addEventListener ('mouseup',
suppressMouseUp,
true);
this.base.document.addEventListener ('click',
detectSingleClick,
true);
this.base.document.addEventListener ('dblclick',
detectDoubleClick,
true);
this.base.document.addEventListener ('contextmenu',
handleContextMenu,
true);
this.base.document.addEventListener ('draggesture',
handleDragStart,
true);
this.base.document.addEventListener ('dragdrop',
handleDrop,
true);
this.base.document.addEventListener ('keypress',
handleKeyPress,
true);
this.mLastDeletedControls = new Array();
this.mLastSelectedControls = new Array();
this.mControlTable = controlTable;
@ -915,6 +918,30 @@ aspNetEditor.prototype =
0);
}
// All of our event listeners are added to the
// document here
this.base.document.addEventListener ('mousedown',
selectFromClick,
true);
this.base.document.addEventListener ('click',
detectSingleClick,
true);
this.base.document.addEventListener ('dblclick',
detectDoubleClick,
true);
this.base.document.addEventListener ('contextmenu',
handleContextMenu,
true);
this.base.document.addEventListener ('draggesture',
handleDragStart,
true);
this.base.document.addEventListener ('dragdrop',
handleDrop,
true);
this.base.document.addEventListener ('keypress',
handleKeyPress,
true);
// Load editing stylesheet
var baseEditor = this.base;
baseEditor.QueryInterface(STYLE_SHEETS);
@ -1033,13 +1060,62 @@ aspNetEditor.prototype =
this.showResizers (controlRef);
},
// Misc
// TODO: Handle commands on controls independently
doCommand: function (aCommand)
{
this.inCommandExec = true;
if (this.mNsICommandManager.isCommandSupported (aCommand, this.mEditorWindow))
this.mNsICommandManager.doCommand (aCommand, null,
if (this.mNsICommandManager.isCommandSupported (aCommand, this.mEditorWindow)) {
switch (aCommand) {
case 'cmd_bold':
this.mNsICommandManager.doCommand (aCommand,
null,
this.mEditorWindow);
break;
case 'cmd_italics':
this.mNsICommandManager.doCommand (aCommand,
null,
this.mEditorWindow);
break;
case 'cmd_underline':
this.mNsICommandManager.doCommand (aCommand,
null,
this.mEditorWindow);
break;
case 'cmd_indent':
this.mNsICommandManager.doCommand (aCommand,
null,
this.mEditorWindow);
break;
case 'cmd_outdent':
this.mNsICommandManager.doCommand (aCommand,
null,
this.mEditorWindow);
break;
case 'cmd_cut':
break;
case 'cmd_copy':
break;
case 'cmd_paste':
var focusNode = this.base.selection.focusNode;
var control =
this.base.getElementOrParentByTagName (CONTROL_TAG_NAME,
focusNode);
if(control) {
var controlId = control.getAttribute (ID);
this.selectControl (controlId);
}
this.collapseBeforeInsertion ("end");
if(this.mNsIEditor.canPaste (1))
this.mNsIEditor.paste (1);
break;
default:
this.mNsICommandManager.doCommand (aCommand,
null,
this.mEditorWindow);
break;
}
}
else
host.throwException ('doCommand (' + aCommand + ')',
'Command not supported');
@ -1047,6 +1123,20 @@ aspNetEditor.prototype =
this.inCommandExec = false;
},
isCommandEnabled: function (aCommand)
{
var commandManager = this.mNsICommandManager;
if (commandManager.isCommandSupported (aCommand, this.mEditorWindow))
if (commandManager.isCommandEnabled (aCommand, this.mEditorWindow))
return true;
else
return false;
else
host.throwException ('doCommand (' + aCommand + ')',
'Command not supported');
},
insertFragment: function (aHtml)
{
if(aHtml) {
@ -1158,36 +1248,6 @@ aspNetEditor.prototype =
aElement.style.setProperty ('-moz-user-select', 'none', '');
},
// TODO: Check if we have any copy-control transaction, and
// if we are pasting those same controls. If yes, notify host
// (it will create new objects), get new element id's from it,
// proceed to paste, and then change pasted controls' id's.
//
// If we are pasting controls, but no copy-control transaction
// has been started, then they are probably coming from cut, so
// notify host of new controls and paste them.
//
// If a copy-control transaction has been started, but not controls are
// pasted, then the transaction is obsolite and we should terminate
// transaction.
//
// If no controls are pasted and no copy-control transaction started,
// proceed with pasting and do nothing else.
paste: function(aEvent)
{
var focusNode = this.base.selection.focusNode;
var control =
this.base.getElementOrParentByTagName (CONTROL_TAG_NAME,
focusNode);
if(control) {
var controlId = control.getAttribute (ID);
this.selectControl (controlId);
}
this.collapseBeforeInsertion ("end");
if(this.mNsIEditor.canPaste (1))
this.mNsIEditor.paste (1);
},
serializePage: function()
{
var xml =
@ -1272,14 +1332,6 @@ function selectFromClick(aEvent)
}
}
function suppressMouseUp(aEvent) {
if(editor.base.resizedObject) {
var object = editor.base.resizedObject;
dump ('handles around <' + object.tagName + ' id=' +
object.getAttribute(ID) + '>');
}
}
function handleDragStart(aEvent) {
// If we are resizing, do nothing - false call
if(editor.inResize)
@ -1347,7 +1399,7 @@ function detectDoubleClick(aEvent)
host.click (DOUBLE_CLICK, controlId);
alert (editor.getPage ());
//alert (editor.getPage ());
}
function handleContextMenu(aEvent)
@ -1375,7 +1427,7 @@ function handleKeyPress(aEvent) {
}
// Handle paste
else if(aEvent.ctrlKey && aEvent.charCode == 118) {
editor.paste ();
editor.doCommand (PASTE);
aEvent.stopPropagation ();
aEvent.preventDefault ();
}

Просмотреть файл

@ -61,6 +61,22 @@ table {
border : 1px dotted red;
}
/* Cancell the above rules in case the table is in control
*/
aspcontrol table[empty-cells],
aspcontrol table[border="0"],
/* next two selectors on line below for the case where tbody is omitted */
aspcontrol table[border="0"] > tr > td, aspcontrol table[border="0"] > tr > th,
aspcontrol table[border="0"] > thead > tr > td, aspcontrol table[border="0"] > tbody > tr > td, aspcontrol table[border="0"] > tfoot > tr > td,
aspcontrol table[border="0"] > thead > tr > th, aspcontrol table[border="0"] > tbody > tr > th, aspcontrol table[border="0"] > tfoot > tr > th,
aspcontrol table:not([border]),
/* next two selectors on line below for the case where tbody is omitted */
aspcontrol table:not([border]) > tr > td, aspcontrol table:not([border]) > tr > th,
aspcontrol table:not([border]) > thead > tr > td, aspcontrol table:not([border]) > tbody > tr > td, aspcontrol table:not([border]) > tfoot > tr > td,
aspcontrol table:not([border]) > thead > tr > th, aspcontrol table:not([border]) > tbody > tr > th, aspcontrol table:not([border]) > tfoot > tr > th {
border : 0;
}
/* give a green dashed border to forms otherwise they are invisible
*/
form {