Table editing work. b=20973, r=jfrancis

This commit is contained in:
cmanske%netscape.com 2000-07-01 00:37:12 +00:00
parent 5ce5924431
commit e50d57138a
16 changed files with 1760 additions and 622 deletions

View File

@ -1861,22 +1861,11 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode,
}
// notify our internal selection state listener
// (Note: A nsAutoSelectionReset object must be created
// before calling this to initialize mSavedSel)
nsAutoReplaceContainerSelNotify selStateNotify(mSavedSel, inNode, *outNode);
// insert new container into tree
res = InsertNode( *outNode, parent, offset);
if (NS_FAILED(res)) return res;
// We sometimes insert default <br> (like in a table cell),
// so save this to delete later
nsCOMPtr<nsIDOMNode> newNodeDefaultChild;
nsresult resFirstChild = (*outNode)->GetFirstChild(getter_AddRefs(newNodeDefaultChild));
// move children into new container
nsCOMPtr<nsIDOMNode> child;
/*
// This doesn't work when used with table cells!
PRBool bHasMoreChildren;
inNode->HasChildNodes(&bHasMoreChildren);
while (bHasMoreChildren)
@ -1888,32 +1877,10 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode,
if (NS_FAILED(res)) return res;
inNode->HasChildNodes(&bHasMoreChildren);
}
*/
// Insert at start of the new node
PRInt32 insertIndex = 0;
res = inNode->GetFirstChild(getter_AddRefs(child));
// insert new container into tree
res = InsertNode( *outNode, parent, offset);
if (NS_FAILED(res)) return res;
while (child)
{
nsCOMPtr<nsIDOMNode> nextChild;
res = child->GetNextSibling(getter_AddRefs(nextChild));
if (NS_FAILED(res)) return res;
res = DeleteNode(child);
if (NS_FAILED(res)) return res;
res = InsertNode(child, *outNode, insertIndex);
if (NS_FAILED(res)) return res;
child = nextChild;
insertIndex++;
}
// Now that we have some real content in the new node,
// delete the default first child
// (We must do this AFTER moving the other nodes
// because rules would reinsert it if we did it first!)
if (NS_SUCCEEDED(resFirstChild) && newNodeDefaultChild)
DeleteNode(newNodeDefaultChild);
// delete old container
return DeleteNode(inNode);

View File

@ -2184,7 +2184,7 @@ nsEditorShell::SetDocumentTitle(const PRUnichar *title)
{
// Didn't find one above: Create a new one
nsCOMPtr<nsIDOMElement>titleElement;
res = domDoc->CreateElement(NS_ConvertASCIItoUCS2("title"),getter_AddRefs(titleElement));
res = domDoc->CreateElementNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"), NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
if (NS_SUCCEEDED(res) && titleElement)
{
titleNode = do_QueryInterface(titleElement);
@ -2902,7 +2902,26 @@ void nsEditorShell::GetBundleString(const nsString& name, nsString &outString)
}
}
// Utility to bring up a Yes/No/Cancel dialog.
// Utilities to bring up a Yes/No/Cancel dialog.
// For JavaScript:
NS_IMETHODIMP
nsEditorShell::ConfirmWithTitle(const PRUnichar *aTitle, const PRUnichar *aQuestion,
const PRUnichar *aYesButtonText, const PRUnichar *aNoButtonText, PRInt32 *_retval)
{
if (!aTitle || !aQuestion || !aYesButtonText || !_retval)
return NS_ERROR_NULL_POINTER;
nsAutoString title(aTitle);
nsAutoString question(aQuestion);
nsAutoString yesString(aYesButtonText);
nsAutoString noString(aNoButtonText);
*_retval = ConfirmWithCancel(title, question, &yesString, &noString);
return NS_OK;
}
nsEditorShell::EConfirmResult
nsEditorShell::ConfirmWithCancel(const nsString& aTitle, const nsString& aQuestion,
const nsString *aYesString, const nsString *aNoString)
@ -3777,7 +3796,12 @@ nsEditorShell::DeleteTable()
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTable();
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3796,7 +3820,12 @@ nsEditorShell::DeleteTableCell(PRInt32 aNumber)
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableCell(aNumber);
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3815,7 +3844,12 @@ nsEditorShell::DeleteTableCellContents()
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableCellContents();
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3834,7 +3868,12 @@ nsEditorShell::DeleteTableRow(PRInt32 aNumber)
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableRow(aNumber);
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3854,7 +3893,12 @@ nsEditorShell::DeleteTableColumn(PRInt32 aNumber)
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableColumn(aNumber);
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3884,7 +3928,7 @@ nsEditorShell::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMEleme
NS_IMETHODIMP
nsEditorShell::JoinTableCells()
nsEditorShell::JoinTableCells(PRBool aMergeNonContiguousContents)
{
nsresult result = NS_NOINTERFACE;
switch (mEditorType)
@ -3893,7 +3937,7 @@ nsEditorShell::JoinTableCells()
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
result = tableEditor->JoinTableCells();
result = tableEditor->JoinTableCells(aMergeNonContiguousContents);
}
break;
default:

View File

@ -28,6 +28,7 @@
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMSelection.h"
#include "nsIDOMEventTarget.h"
@ -162,19 +163,49 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
nsresult res = mouseEvent->GetButton(&buttonNumber);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIDOMEventTarget> targetNode;
res = aMouseEvent->GetTarget(getter_AddRefs(targetNode));
nsCOMPtr<nsIDOMEventTarget> target;
res = aMouseEvent->GetTarget(getter_AddRefs(target));
if (NS_FAILED(res)) return res;
if (!targetNode) return NS_ERROR_NULL_POINTER;
if (!target) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(targetNode);
PRInt32 clickCount;
res = mouseEvent->GetDetail(&clickCount);
if (NS_FAILED(res)) return res;
if (buttonNumber == 3 || (buttonNumber == 1 && clickCount == 2))
{
/**XXX Context menu design is flawed:
* Mouse message arrives here first,
* then to XULPopupListenerImpl::MouseDown,
* and never bubbles to frame.
* So we don't reposition the caret correctly
* within a text node and don't detect if clicking
* on a selection. (Logic for both is in frame code.)
* Kludge: Set selection to beginning of text node.
* TODO: try to solve click within selection with a new
* nsSelection method.
* We also want to do this for double-click to detect
* a link enclosing the text node
*/
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(target);
if (textNode)
{
//XXX We should do this only if not clicking inside an existing selection!
nsCOMPtr<nsIDOMSelection> selection;
mEditorShell->GetEditorSelection(getter_AddRefs(selection));
if (selection)
selection->Collapse(textNode, 0);
// Get enclosing link
res = mEditorShell->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), textNode, getter_AddRefs(element));
if (NS_FAILED(res)) return res;
}
}
if (buttonNumber == 1)
{
PRInt32 clickCount;
nsresult res = mouseEvent->GetDetail(&clickCount);
if (NS_FAILED(res)) return res;
#ifdef DEBUG_cmanske
printf("nsEditorShellMouseListener::MouseDown: clickCount=%d\n",clickCount);
#endif
@ -201,9 +232,6 @@ printf("nsEditorShellMouseListener::MouseDown-DoubleClick in cell\n");
#endif
}
// No table or cell -- look for other element (ignore text nodes)
if (!element)
element = do_QueryInterface(targetNode);
if (element)
{
PRInt32 x,y;

View File

@ -201,7 +201,7 @@ public:
NS_IMETHOD SelectTable();
NS_IMETHOD SelectAllTableCells();
NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell);
NS_IMETHOD JoinTableCells();
NS_IMETHOD JoinTableCells(PRBool aMergeNonContiguousContents);
NS_IMETHOD SplitTableCell();
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32& aRowIndex, PRInt32& aColIndex);
@ -218,6 +218,9 @@ public:
PRInt32 aDirection, PRBool aSelected);
NS_IMETHOD GetSelectedOrParentTableElement(nsIDOMElement* &aTableElement, nsString& aTagName, PRInt32 &aSelectedCount);
NS_IMETHOD GetSelectedCellsType(nsIDOMElement *aElement, PRUint32 &aSelectionType);
nsresult GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell);
// Finds the first selected cell in first range of selection
// This is in the *order of selection*, not order in the table
// (i.e., each cell added to selection is added in another range
@ -380,10 +383,15 @@ protected:
NS_IMETHOD InsertCell(nsIDOMElement *aCell, PRInt32 aRowSpan, PRInt32 aColSpan,
PRBool aAfter, PRBool aIsHeader, nsIDOMElement **aNewCell);
// Helpers that don't touch the selection or do batch transactions
NS_IMETHOD DeleteRow(nsIDOMElement *aTable, PRInt32 aRowIndex);
NS_IMETHOD DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex);
NS_IMETHOD DeleteCellContents(nsIDOMElement *aCell);
// Move all contents from aCellToMerge into aTargetCell (append at end)
NS_IMETHOD MergeCells(nsCOMPtr<nsIDOMElement> aTargetCell, nsCOMPtr<nsIDOMElement> aCellToMerge, PRBool aDeleteCellToMerge);
NS_IMETHOD DeleteTable2(nsCOMPtr<nsIDOMElement> &aTable, nsCOMPtr<nsIDOMSelection> &aSelection);
NS_IMETHOD DeleteTable2(nsIDOMElement *aTable, nsIDOMSelection *aSelection);
NS_IMETHOD SetColSpan(nsIDOMElement *aCell, PRInt32 aColSpan);
NS_IMETHOD SetRowSpan(nsIDOMElement *aCell, PRInt32 aRowSpan);
@ -418,7 +426,9 @@ protected:
NS_IMETHOD SplitCellIntoRows(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32 aColIndex,
PRInt32 aRowSpanAbove, PRInt32 aRowSpanBelow, nsIDOMElement **aNewCell);
// Reduce rowspan/colspan when cells span into non-existent rows/columns
NS_IMETHOD FixBadRowSpan(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32& aNewRowCount);
NS_IMETHOD FixBadColSpan(nsIDOMElement *aTable, PRInt32 aColIndex, PRInt32& aNewColCount);
// Fallback method: Call this after using ClearSelection() and you
// failed to set selection to some other content in the document

View File

@ -621,9 +621,8 @@ nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber)
return nsHTMLEditor::DeleteTableRow(aNumber);
}
NS_IMETHODIMP
nsHTMLEditorLog:: JoinTableCells()
nsHTMLEditorLog:: JoinTableCells(PRBool aMergeNonContiguousContents)
{
nsAutoHTMLEditorLogLock logLock(this);
@ -633,7 +632,7 @@ nsHTMLEditorLog:: JoinTableCells()
Flush();
}
return nsHTMLEditor::JoinTableCells();
return nsHTMLEditor::JoinTableCells(aMergeNonContiguousContents);
}
NS_IMETHODIMP
@ -666,6 +665,20 @@ nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable)
return nsHTMLEditor::NormalizeTable(aTable);
}
NS_IMETHODIMP
nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell)
{
nsAutoHTMLEditorLogLock logLock(this);
if (!mLocked && mFileSpec)
{
Write("window.editorShell.SwitchTableCellHeaderType(\"");
Write("\");\n");
Flush();
}
return nsHTMLEditor::SwitchTableCellHeaderType(aSourceCell, aNewCell);
}
NS_IMETHODIMP
nsHTMLEditorLog::MakeOrChangeList(const nsString& aListType)

View File

@ -99,9 +99,10 @@ public:
NS_IMETHOD DeleteTableCellContents();
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber);
NS_IMETHOD DeleteTableRow(PRInt32 aNumber);
NS_IMETHOD JoinTableCells();
NS_IMETHOD JoinTableCells(PRBool aMergeNonContiguousContents);
NS_IMETHOD SplitTableCell();
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell);
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile);
NS_IMETHOD StopLogging();

File diff suppressed because it is too large Load Diff

View File

@ -2184,7 +2184,7 @@ nsEditorShell::SetDocumentTitle(const PRUnichar *title)
{
// Didn't find one above: Create a new one
nsCOMPtr<nsIDOMElement>titleElement;
res = domDoc->CreateElement(NS_ConvertASCIItoUCS2("title"),getter_AddRefs(titleElement));
res = domDoc->CreateElementNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"), NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
if (NS_SUCCEEDED(res) && titleElement)
{
titleNode = do_QueryInterface(titleElement);
@ -2902,7 +2902,26 @@ void nsEditorShell::GetBundleString(const nsString& name, nsString &outString)
}
}
// Utility to bring up a Yes/No/Cancel dialog.
// Utilities to bring up a Yes/No/Cancel dialog.
// For JavaScript:
NS_IMETHODIMP
nsEditorShell::ConfirmWithTitle(const PRUnichar *aTitle, const PRUnichar *aQuestion,
const PRUnichar *aYesButtonText, const PRUnichar *aNoButtonText, PRInt32 *_retval)
{
if (!aTitle || !aQuestion || !aYesButtonText || !_retval)
return NS_ERROR_NULL_POINTER;
nsAutoString title(aTitle);
nsAutoString question(aQuestion);
nsAutoString yesString(aYesButtonText);
nsAutoString noString(aNoButtonText);
*_retval = ConfirmWithCancel(title, question, &yesString, &noString);
return NS_OK;
}
nsEditorShell::EConfirmResult
nsEditorShell::ConfirmWithCancel(const nsString& aTitle, const nsString& aQuestion,
const nsString *aYesString, const nsString *aNoString)
@ -3777,7 +3796,12 @@ nsEditorShell::DeleteTable()
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTable();
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3796,7 +3820,12 @@ nsEditorShell::DeleteTableCell(PRInt32 aNumber)
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableCell(aNumber);
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3815,7 +3844,12 @@ nsEditorShell::DeleteTableCellContents()
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableCellContents();
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3834,7 +3868,12 @@ nsEditorShell::DeleteTableRow(PRInt32 aNumber)
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableRow(aNumber);
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3854,7 +3893,12 @@ nsEditorShell::DeleteTableColumn(PRInt32 aNumber)
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
{
result = tableEditor->DeleteTableColumn(aNumber);
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
// to JavaScript
if(NS_SUCCEEDED(result)) return NS_OK;
}
}
break;
default:
@ -3884,7 +3928,7 @@ nsEditorShell::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMEleme
NS_IMETHODIMP
nsEditorShell::JoinTableCells()
nsEditorShell::JoinTableCells(PRBool aMergeNonContiguousContents)
{
nsresult result = NS_NOINTERFACE;
switch (mEditorType)
@ -3893,7 +3937,7 @@ nsEditorShell::JoinTableCells()
{
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
if (tableEditor)
result = tableEditor->JoinTableCells();
result = tableEditor->JoinTableCells(aMergeNonContiguousContents);
}
break;
default:

View File

@ -28,6 +28,7 @@
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMSelection.h"
#include "nsIDOMEventTarget.h"
@ -162,19 +163,49 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
nsresult res = mouseEvent->GetButton(&buttonNumber);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIDOMEventTarget> targetNode;
res = aMouseEvent->GetTarget(getter_AddRefs(targetNode));
nsCOMPtr<nsIDOMEventTarget> target;
res = aMouseEvent->GetTarget(getter_AddRefs(target));
if (NS_FAILED(res)) return res;
if (!targetNode) return NS_ERROR_NULL_POINTER;
if (!target) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(targetNode);
PRInt32 clickCount;
res = mouseEvent->GetDetail(&clickCount);
if (NS_FAILED(res)) return res;
if (buttonNumber == 3 || (buttonNumber == 1 && clickCount == 2))
{
/**XXX Context menu design is flawed:
* Mouse message arrives here first,
* then to XULPopupListenerImpl::MouseDown,
* and never bubbles to frame.
* So we don't reposition the caret correctly
* within a text node and don't detect if clicking
* on a selection. (Logic for both is in frame code.)
* Kludge: Set selection to beginning of text node.
* TODO: try to solve click within selection with a new
* nsSelection method.
* We also want to do this for double-click to detect
* a link enclosing the text node
*/
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(target);
if (textNode)
{
//XXX We should do this only if not clicking inside an existing selection!
nsCOMPtr<nsIDOMSelection> selection;
mEditorShell->GetEditorSelection(getter_AddRefs(selection));
if (selection)
selection->Collapse(textNode, 0);
// Get enclosing link
res = mEditorShell->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), textNode, getter_AddRefs(element));
if (NS_FAILED(res)) return res;
}
}
if (buttonNumber == 1)
{
PRInt32 clickCount;
nsresult res = mouseEvent->GetDetail(&clickCount);
if (NS_FAILED(res)) return res;
#ifdef DEBUG_cmanske
printf("nsEditorShellMouseListener::MouseDown: clickCount=%d\n",clickCount);
#endif
@ -201,9 +232,6 @@ printf("nsEditorShellMouseListener::MouseDown-DoubleClick in cell\n");
#endif
}
// No table or cell -- look for other element (ignore text nodes)
if (!element)
element = do_QueryInterface(targetNode);
if (element)
{
PRInt32 x,y;

View File

@ -104,9 +104,34 @@ interface nsIEditorShell : nsISupports
*/
void Shutdown();
/* Access for the common alert dialog */
/** Access for the common alert dialog
*
* title Title (caption) of the dialog
* msg Message in the dialog
*
* Dialog contains an "Ok" button. No return value
*/
void AlertWithTitle(in wstring title, in wstring msg);
/** Access for the common alert dialog
*
* title Title (caption) of the dialog
* question Question asked of the user
* yesButtonText Text for the "Yes" button
* If empty, "Yes" will be used
* noButtonText Text for the "No" button.
* If empty, the button will not be displayed
*
* Dialog always has a "Cancel" button
* Button order follows platform-specific rules
*
* Returns: 0 Yes button pressed
* 1 Cancel button pressed
* 2 No button pressed
*/
PRInt32 ConfirmWithTitle(in wstring title, in wstring question,
in wstring yesButtonText, in wstring noButtonText);
/* check a particular window's URL to see if it matches the given URL */
boolean checkOpenWindowForURLMatch( in wstring inFileURL, in nsIDOMWindow inCheckWindow);
@ -353,15 +378,20 @@ interface nsIEditorShell : nsISupports
* The resulting cell is in the location of the
* cell at the upper-left corner of the adjacent
* block of selected cells
* Non-adjacent cells are not deleted,
* but their contents are still moved
* to the upper-left cell
*
* mergeNonContiguousContents:
* If true:
* Non-contiguous cells are not deleted,
* but their contents are still moved
* to the upper-left cell
* If false: contiguous cells are ignored
*
* If there are no selected cells,
* and selection or caret is in a cell,
* that cell and the one to the right
* are merged
*/
void JoinTableCells();
void JoinTableCells(in boolean mergeNonContiguousContents);
/** Split a cell that has rowspan and/or colspan > 0
* into cells such that all new cells have

View File

@ -1861,22 +1861,11 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode,
}
// notify our internal selection state listener
// (Note: A nsAutoSelectionReset object must be created
// before calling this to initialize mSavedSel)
nsAutoReplaceContainerSelNotify selStateNotify(mSavedSel, inNode, *outNode);
// insert new container into tree
res = InsertNode( *outNode, parent, offset);
if (NS_FAILED(res)) return res;
// We sometimes insert default <br> (like in a table cell),
// so save this to delete later
nsCOMPtr<nsIDOMNode> newNodeDefaultChild;
nsresult resFirstChild = (*outNode)->GetFirstChild(getter_AddRefs(newNodeDefaultChild));
// move children into new container
nsCOMPtr<nsIDOMNode> child;
/*
// This doesn't work when used with table cells!
PRBool bHasMoreChildren;
inNode->HasChildNodes(&bHasMoreChildren);
while (bHasMoreChildren)
@ -1888,32 +1877,10 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode,
if (NS_FAILED(res)) return res;
inNode->HasChildNodes(&bHasMoreChildren);
}
*/
// Insert at start of the new node
PRInt32 insertIndex = 0;
res = inNode->GetFirstChild(getter_AddRefs(child));
// insert new container into tree
res = InsertNode( *outNode, parent, offset);
if (NS_FAILED(res)) return res;
while (child)
{
nsCOMPtr<nsIDOMNode> nextChild;
res = child->GetNextSibling(getter_AddRefs(nextChild));
if (NS_FAILED(res)) return res;
res = DeleteNode(child);
if (NS_FAILED(res)) return res;
res = InsertNode(child, *outNode, insertIndex);
if (NS_FAILED(res)) return res;
child = nextChild;
insertIndex++;
}
// Now that we have some real content in the new node,
// delete the default first child
// (We must do this AFTER moving the other nodes
// because rules would reinsert it if we did it first!)
if (NS_SUCCEEDED(resFirstChild) && newNodeDefaultChild)
DeleteNode(newNodeDefaultChild);
// delete old container
return DeleteNode(inNode);

View File

@ -201,7 +201,7 @@ public:
NS_IMETHOD SelectTable();
NS_IMETHOD SelectAllTableCells();
NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell);
NS_IMETHOD JoinTableCells();
NS_IMETHOD JoinTableCells(PRBool aMergeNonContiguousContents);
NS_IMETHOD SplitTableCell();
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32& aRowIndex, PRInt32& aColIndex);
@ -218,6 +218,9 @@ public:
PRInt32 aDirection, PRBool aSelected);
NS_IMETHOD GetSelectedOrParentTableElement(nsIDOMElement* &aTableElement, nsString& aTagName, PRInt32 &aSelectedCount);
NS_IMETHOD GetSelectedCellsType(nsIDOMElement *aElement, PRUint32 &aSelectionType);
nsresult GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell);
// Finds the first selected cell in first range of selection
// This is in the *order of selection*, not order in the table
// (i.e., each cell added to selection is added in another range
@ -380,10 +383,15 @@ protected:
NS_IMETHOD InsertCell(nsIDOMElement *aCell, PRInt32 aRowSpan, PRInt32 aColSpan,
PRBool aAfter, PRBool aIsHeader, nsIDOMElement **aNewCell);
// Helpers that don't touch the selection or do batch transactions
NS_IMETHOD DeleteRow(nsIDOMElement *aTable, PRInt32 aRowIndex);
NS_IMETHOD DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex);
NS_IMETHOD DeleteCellContents(nsIDOMElement *aCell);
// Move all contents from aCellToMerge into aTargetCell (append at end)
NS_IMETHOD MergeCells(nsCOMPtr<nsIDOMElement> aTargetCell, nsCOMPtr<nsIDOMElement> aCellToMerge, PRBool aDeleteCellToMerge);
NS_IMETHOD DeleteTable2(nsCOMPtr<nsIDOMElement> &aTable, nsCOMPtr<nsIDOMSelection> &aSelection);
NS_IMETHOD DeleteTable2(nsIDOMElement *aTable, nsIDOMSelection *aSelection);
NS_IMETHOD SetColSpan(nsIDOMElement *aCell, PRInt32 aColSpan);
NS_IMETHOD SetRowSpan(nsIDOMElement *aCell, PRInt32 aRowSpan);
@ -418,7 +426,9 @@ protected:
NS_IMETHOD SplitCellIntoRows(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32 aColIndex,
PRInt32 aRowSpanAbove, PRInt32 aRowSpanBelow, nsIDOMElement **aNewCell);
// Reduce rowspan/colspan when cells span into non-existent rows/columns
NS_IMETHOD FixBadRowSpan(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32& aNewRowCount);
NS_IMETHOD FixBadColSpan(nsIDOMElement *aTable, PRInt32 aColIndex, PRInt32& aNewColCount);
// Fallback method: Call this after using ClearSelection() and you
// failed to set selection to some other content in the document

View File

@ -621,9 +621,8 @@ nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber)
return nsHTMLEditor::DeleteTableRow(aNumber);
}
NS_IMETHODIMP
nsHTMLEditorLog:: JoinTableCells()
nsHTMLEditorLog:: JoinTableCells(PRBool aMergeNonContiguousContents)
{
nsAutoHTMLEditorLogLock logLock(this);
@ -633,7 +632,7 @@ nsHTMLEditorLog:: JoinTableCells()
Flush();
}
return nsHTMLEditor::JoinTableCells();
return nsHTMLEditor::JoinTableCells(aMergeNonContiguousContents);
}
NS_IMETHODIMP
@ -666,6 +665,20 @@ nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable)
return nsHTMLEditor::NormalizeTable(aTable);
}
NS_IMETHODIMP
nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell)
{
nsAutoHTMLEditorLogLock logLock(this);
if (!mLocked && mFileSpec)
{
Write("window.editorShell.SwitchTableCellHeaderType(\"");
Write("\");\n");
Flush();
}
return nsHTMLEditor::SwitchTableCellHeaderType(aSourceCell, aNewCell);
}
NS_IMETHODIMP
nsHTMLEditorLog::MakeOrChangeList(const nsString& aListType)

View File

@ -99,9 +99,10 @@ public:
NS_IMETHOD DeleteTableCellContents();
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber);
NS_IMETHOD DeleteTableRow(PRInt32 aNumber);
NS_IMETHOD JoinTableCells();
NS_IMETHOD JoinTableCells(PRBool aMergeNonContiguousContents);
NS_IMETHOD SplitTableCell();
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell);
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile);
NS_IMETHOD StopLogging();

File diff suppressed because it is too large Load Diff

View File

@ -74,8 +74,23 @@ public:
* @param aNumber Number of items to insert/delete
*/
NS_IMETHOD DeleteTable()=0;
NS_IMETHOD DeleteTableCell(PRInt32 aNumber)=0;
/** Delete just the cell contents
* This is what should happen when Delete key is used
* for selected cells, to minimize upsetting the table layout
*/
NS_IMETHOD DeleteTableCellContents()=0;
/** Delete cell elements as well as contents
* @param aNumber Number of contiguous cells, rows, or columns
*
* When there are more than 1 selected cells, aNumber is ignored.
* For Delete Rows or Columns, the complete columns or rows are
* determined by the selected cells. E.g., to delete 2 complete rows,
* user simply selects a cell in each, and they don't
* have to be contiguous.
*/
NS_IMETHOD DeleteTableCell(PRInt32 aNumber)=0;
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber)=0;
NS_IMETHOD DeleteTableRow(PRInt32 aNumber)=0;
@ -117,15 +132,20 @@ public:
* The resulting cell is in the location of the
* cell at the upper-left corner of the adjacent
* block of selected cells
* Non-adjacent cells are not deleted,
* but their contents are still moved
* to the upper-left cell
*
* @param aMergeNonContiguousContents:
* If true:
* Non-contiguous cells are not deleted,
* but their contents are still moved
* to the upper-left cell
* If false: contiguous cells are ignored
*
* If there are no selected cells,
* and selection or caret is in a cell,
* that cell and the one to the right
* are merged
*/
NS_IMETHOD JoinTableCells()=0;
NS_IMETHOD JoinTableCells(PRBool aMergeNonContiguousContents)=0;
/** Split a cell that has rowspan and/or colspan > 0
* into cells such that all new cells have