diff --git a/mozilla/editor/base/EditTable.cpp b/mozilla/editor/base/EditTable.cpp index c00a274297c..57e64119525 100644 --- a/mozilla/editor/base/EditTable.cpp +++ b/mozilla/editor/base/EditTable.cpp @@ -130,10 +130,11 @@ nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) if (NS_FAILED(res)) return res; // Get more data for current cell in row we are inserting at (we need COLSPAN) - PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan; + PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; res = GetCellDataAt(table, startRowIndex, startColIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; if (!curCell) return NS_ERROR_FAILURE; PRInt32 newCellIndex = aAfter ? (startColIndex+colSpan) : startColIndex; @@ -154,6 +155,28 @@ nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) return res; } +nsresult nsHTMLEditor::GetRowAt(nsCOMPtr &aTable, PRInt32 rowIndex, nsCOMPtr &aRow) +{ + aRow = nsnull; + nsCOMPtr nextRow; + PRInt32 index = 0; + nsAutoString tagName("tr"); + + nsresult res = GetNextElementByTagName(aTable, &tagName, getter_AddRefs(nextRow)); + if (NS_FAILED(res)) return res; + if (!nextRow) return NS_OK; + + nsCOMPtr parentTable; + res = GetElementOrParentByTagName("table", nextRow, getter_AddRefs(parentTable)); + if (NS_FAILED(res)) return res; + if (!parentTable) return NS_ERROR_NULL_POINTER; + + if (parentTable == aTable) + aRow = nextRow; + + return res; +} + NS_IMETHODIMP nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { @@ -166,10 +189,11 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) if (NS_FAILED(res)) return res; // Get more data for current cell (we need ROWSPAN) - PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan; + PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; res = GetCellDataAt(table, startRowIndex, startColIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; if (!curCell) return NS_ERROR_FAILURE; @@ -192,7 +216,8 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { // We are inserting before an existing column res = GetCellDataAt(table, row, startColIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; // Don't fail entire process if we fail to find a cell @@ -201,11 +226,16 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { if (curStartColIndex < startColIndex) { - // We have a cell spanning this location - // Simply increase its colspan to keep table rectangular - nsAutoString newColSpan; - newColSpan.Append(colSpan+aNumber, 10); - SetAttribute(curCell, "colspan", newColSpan); + if (colSpan > 0) + { + // We have a cell spanning this location + // Simply increase its colspan to keep table rectangular + nsAutoString newColSpan; + newColSpan.Append(colSpan+aNumber, 10); + SetAttribute(curCell, "colspan", newColSpan); + } + // Note: we do nothing if colsSpan=0, + // since it should automatically span the new column } else { // Simply set selection to the current cell // so we can let InsertTableCell() do the work @@ -215,13 +245,16 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) } } } else { + // We are inserting after all existing columns + //TODO: A better strategy is to get the row at index "row" // and append a cell to the end of it. // Need to write "GetRowAt()" to do this // Get last cell in row and insert new cell after it res = GetCellDataAt(table, row, lastColumn, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; if (curCell) { @@ -245,10 +278,11 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) if (NS_FAILED(res)) return res; // Get more data for current cell in row we are inserting at (we need COLSPAN) - PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan; + PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; res = GetCellDataAt(table, startRowIndex, startColIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; if (!curCell) return NS_ERROR_FAILURE; @@ -272,9 +306,9 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) if (aAfter) { // Use row after current cell - startRowIndex += rowSpan; + startRowIndex += actualRowSpan; // offset to use for new row insert - newRowOffset += rowSpan; + newRowOffset += actualRowSpan; } nsAutoEditBatch beginBatching(this); @@ -290,31 +324,50 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) // This returns NS_TABLELAYOUT_CELL_NOT_FOUND when we run past end of row, // which passes the NS_SUCCEEDED macro while ( NS_OK == GetCellDataAt(table, newRowOffset, colIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected) ) + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected) ) { if (curCell) { if (curStartRowIndex < startRowIndex) { - // We have a cell spanning this location - // Simply increase its colspan to keep table rectangular - nsAutoString newRowSpan; - newRowSpan.Append(rowSpan+aNumber, 10); - SetAttribute(curCell, "rowspan", newRowSpan); + if (rowSpan > 0) + { + // We have a cell spanning this location + // Simply increase its rowspan + nsAutoString newRowSpan; + newRowSpan.Append(rowSpan+aNumber, 10); + SetAttribute(curCell, "rowspan", newRowSpan); + } + //Note that if rowSpan == 0, we do nothing, + // since that cell should automatically extend into the new row } else { // Count the number of cells we need to add to the new row - cellsInRow += colSpan; + cellsInRow += actualColSpan; } // Next cell in row - colIndex += colSpan; + colIndex += actualColSpan; } else colIndex++; } } else { - // We are adding after existing rows, - // so use max number of cells in a row + // We are adding a new row after all others + // If it weren't for colspan=0 effect, + // we could simply use colCount for number of new cells... cellsInRow = colCount; + + // ...but we must compensate for all cells with rowSpan = 0 in the last row + PRInt32 lastRow = rowCount-1; + PRInt32 tempColIndex = 0; + while ( NS_OK == GetCellDataAt(table, lastRow, tempColIndex, *getter_AddRefs(curCell), + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected) ) + { + if (rowSpan == 0) + cellsInRow -= actualColSpan; + } + tempColIndex += actualColSpan; } if (cellsInRow > 0) @@ -527,7 +580,7 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) // Scan through cells in row to do rowspan adjustments nsCOMPtr curCell; - PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan; + PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; PRInt32 rowIndex = 0; @@ -535,40 +588,44 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) { do { res = GetCellDataAt(table, rowIndex, startColIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; - NS_ASSERTION((colSpan > 0),"COLSPAN = 0 in DeleteTableColumn"); - NS_ASSERTION((rowSpan > 0),"ROWSPAN = 0 in DeleteTableColumn"); + + NS_ASSERTION((actualColSpan > 0),"Effective COLSPAN = 0 in DeleteTableColumn"); + NS_ASSERTION((actualRowSpan > 0),"Effective ROWSPAN = 0 in DeleteTableColumn"); if (curCell) { // Find cells that don't start in column we are deleting - if (curStartColIndex < startColIndex || colSpan > 1) + if (curStartColIndex < startColIndex || colSpan > 1 || colSpan == 0) { - NS_ASSERTION((colSpan > 1),"Bad COLSPAN in DeleteTableColumn"); // We have a cell spanning this location - // Decrease its colspan to keep table rectangular - - nsAutoString newColSpan; - //This calculates final span for all columns deleted, - // but we are iterating aNumber times through here so - // just decrement current value by 1 - //PRInt32 minSpan = startColIndex - curStartColIndex; - //PRInt32 newSpan = PR_MAX(minSpan, colSpan - aNumber); - //newColSpan.Append(newSpan, 10); - newColSpan.Append(colSpan-1, 10); - SetAttribute(curCell, "colspan", newColSpan); - - // Delete contents of cell instead of cell itself + // Decrease its colspan to keep table rectangular, + // but if colSpan=0, it will adjust automatically + if (colSpan > 0) + { + NS_ASSERTION((colSpan > 1),"Bad COLSPAN in DeleteTableColumn"); + nsAutoString newColSpan; + //This calculates final span for all columns deleted, + // but we are iterating aNumber times through here so + // just decrement current value by 1 + //PRInt32 minSpan = startColIndex - curStartColIndex; + //PRInt32 newSpan = PR_MAX(minSpan, colSpan - aNumber); + //newColSpan.Append(newSpan, 10); + newColSpan.Append(colSpan-1, 10); + SetAttribute(curCell, "colspan", newColSpan); + } if (curStartColIndex == startColIndex) { + // Cell is in column to be deleted, + // but delete contents of cell instead of cell itself selection->Collapse(curCell,0); DeleteTableCellContents(); } - // To next cell in row - rowIndex++; - + // To next cell in column + rowIndex += actualRowSpan; } else { // Delete the cell if (1 == GetNumberOfCellsInRow(table, rowIndex)) @@ -603,7 +660,7 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) if (NS_FAILED(res)) return res; //Skipover any rows spanned by this cell - rowIndex +=rowSpan; + rowIndex += actualRowSpan; } } } else { @@ -649,15 +706,16 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) // Scan through cells in row to do rowspan adjustments nsCOMPtr curCell; - PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan; + PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; PRInt32 colIndex = 0; do { res = GetCellDataAt(table, startRowIndex, colIndex, *getter_AddRefs(curCell), - curStartRowIndex, curStartColIndex, rowSpan, colSpan, isSelected); + curStartRowIndex, curStartColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); - NS_ASSERTION((colSpan > 0),"COLSPAN = 0 in DeleteTableRow"); - NS_ASSERTION((rowSpan > 0),"ROWSPAN = 0 in DeleteTableRow"); + NS_ASSERTION((actualColSpan > 0),"Effective COLSPAN = 0 in DeleteTableRow"); + NS_ASSERTION((actualRowSpan > 0),"Effective ROWSPAN = 0 in DeleteTableRow"); // Find cells that don't start in row we are deleting if (NS_SUCCEEDED(res) && curCell) @@ -666,14 +724,18 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) { // We have a cell spanning this location // Decrease its rowspan to keep table rectangular - nsAutoString newRowSpan; - PRInt32 minSpan = startRowIndex - curStartRowIndex; - PRInt32 newSpan = PR_MAX(minSpan, rowSpan - aNumber); - newRowSpan.Append(newSpan, 10); - SetAttribute(curCell, "rowspan", newRowSpan); + // but we don't need to do this if rowspan=0, + // since it will automatically adjust + if (rowSpan > 0) + { + nsAutoString newRowSpan; + PRInt32 newSpan = PR_MAX((startRowIndex - curStartRowIndex), actualRowSpan - aNumber); + newRowSpan.Append(newSpan, 10); + SetAttribute(curCell, "rowspan", newRowSpan); + } } // Skip over locations spanned by this cell - colIndex += colSpan; + colIndex += actualColSpan; } else colIndex++; @@ -776,10 +838,11 @@ PRBool nsHTMLEditor::GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowInd PRInt32 colIndex = 0; nsresult res; do { - PRInt32 startRowIndex, startColIndex, rowSpan, colSpan; + PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; res = GetCellDataAt(aTable, rowIndex, colIndex, *getter_AddRefs(cell), - startRowIndex, startColIndex, rowSpan, colSpan, isSelected); + startRowIndex, startColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); if (NS_FAILED(res)) return res; if (cell) { @@ -788,7 +851,7 @@ PRBool nsHTMLEditor::GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowInd cellCount++; //Next possible location for a cell - colIndex += colSpan; + colIndex += actualColSpan; } else colIndex++; @@ -830,7 +893,9 @@ nsHTMLEditor::GetTableSize(nsIDOMElement *aTable, PRInt32& aRowCount, PRInt32& a NS_IMETHODIMP nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, PRInt32& aStartRowIndex, PRInt32& aStartColIndex, - PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected) + PRInt32& aRowSpan, PRInt32& aColSpan, + PRInt32& aActualRowSpan, PRInt32& aActualColSpan, + PRBool& aIsSelected) { nsresult res=NS_ERROR_FAILURE; aCell = nsnull; @@ -838,6 +903,8 @@ nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aC aStartColIndex = 0; aRowSpan = 0; aColSpan = 0; + aActualRowSpan = 0; + aActualColSpan = 0; aIsSelected = PR_FALSE; if (!aTable) @@ -862,17 +929,20 @@ nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aC // the index(es) are out of bounds return tableLayoutObject->GetCellDataAt(aRowIndex, aColIndex, aCell, aStartRowIndex, aStartColIndex, - aRowSpan, aColSpan, aIsSelected); + aRowSpan, aColSpan, + aActualRowSpan, aActualColSpan, + aIsSelected); } // When all you want is the cell NS_IMETHODIMP nsHTMLEditor::GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell) { - PRInt32 startRowIndex, startColIndex, rowSpan, colSpan; + PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; PRBool isSelected; return GetCellDataAt(aTable, aRowIndex, aColIndex, aCell, - startRowIndex, startColIndex, rowSpan, colSpan, isSelected); + startRowIndex, startColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); } NS_IMETHODIMP diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index ffb30f5dc12..0e801d6b076 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -3256,11 +3256,15 @@ nsEditorShell::GetCellAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 NS_IMETHODIMP nsEditorShell::GetCellDataAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 colIndex, PRInt32 *aStartRowIndex, PRInt32 *aStartColIndex, - PRInt32 *aRowSpan, PRInt32 *aColSpan, PRBool *aIsSelected, nsIDOMElement **_retval) + PRInt32 *aRowSpan, PRInt32 *aColSpan, + PRInt32 *aActualRowSpan, PRInt32 *aActualColSpan, + PRBool *aIsSelected, nsIDOMElement **_retval) { if (!_retval || !aStartRowIndex || !aStartColIndex || - !aRowSpan || !aColSpan || !aIsSelected ) + !aRowSpan || !aColSpan || + !aActualRowSpan || !aActualColSpan || + !aIsSelected ) return NS_ERROR_NULL_POINTER; nsresult result = NS_NOINTERFACE; @@ -3271,7 +3275,10 @@ nsEditorShell::GetCellDataAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRIn nsCOMPtr tableEditor = do_QueryInterface(mEditor); if (tableEditor) result = tableEditor->GetCellDataAt(tableElement, rowIndex, colIndex, *_retval, - *aStartRowIndex, *aStartColIndex, *aRowSpan, *aColSpan, *aIsSelected); + *aStartRowIndex, *aStartColIndex, + *aRowSpan, *aColSpan, + *aActualRowSpan, *aActualColSpan, + *aIsSelected); } break; default: diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index bf675136a9a..f74459dcbb4 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -7246,3 +7246,48 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMSelection *aInSelection) return result; } +NS_IMETHODIMP +nsHTMLEditor::GetNextElementByTagName(nsIDOMElement *aCurrentElement, + const nsString *aTagName, + nsIDOMElement **aReturn) +{ + nsresult res = NS_OK; + if (!aCurrentElement || !aTagName || !aReturn) + return NS_ERROR_NULL_POINTER; + + nsIAtom *tagAtom = NS_NewAtom(*aTagName); + if (!tagAtom) { return NS_ERROR_NULL_POINTER; } + if (tagAtom==nsIEditProperty::th) + tagAtom=nsIEditProperty::td; + + nsCOMPtr currentNode = do_QueryInterface(aCurrentElement); + if (!currentNode) + return NS_ERROR_FAILURE; + + *aReturn = nsnull; + + nsCOMPtr nextNode; + PRBool done = PR_FALSE; + + do { + res = GetNextNode(currentNode, PR_TRUE, getter_AddRefs(nextNode)); + if (NS_FAILED(res)) return res; + if (!nextNode) break; + + nsCOMPtr atom = GetTag(currentNode); + + if (tagAtom==atom) + { + nsCOMPtr element = do_QueryInterface(currentNode); + if (!element) return NS_ERROR_NULL_POINTER; + + *aReturn = element; + NS_ADDREF(*aReturn); + done = PR_TRUE; + return NS_OK; + } + currentNode = nextNode; + } while (!done); + + return res; +} diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index 56166562dfa..82d3a5e3218 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -138,6 +138,8 @@ public: NS_IMETHOD GetElementOrParentByTagName(const nsString& aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn); NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); + NS_IMETHOD GetNextElementByTagName(nsIDOMElement *aCurrentElement, const nsString *aTagName, nsIDOMElement **aReturn); + NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); @@ -187,7 +189,9 @@ public: NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell); NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, PRInt32& aStartRowIndex, PRInt32& aStartColIndex, - PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected); + PRInt32& aRowSpan, PRInt32& aColSpan, + PRInt32& aActualRowSpan, PRInt32& aActualColSpan, + PRBool& aIsSelected); NS_IMETHOD SetCaretAfterTableEdit(nsIDOMElement* aTable, PRInt32 aRow, PRInt32 aCol, PRInt32 aDirection); NS_IMETHOD GetSelectedOrParentTableElement(nsCOMPtr &aTableElement, nsString& aTagName, PRBool &aIsSelected); @@ -318,7 +322,8 @@ protected: NS_IMETHOD GetTableLayoutObject(nsIDOMElement* aTable, nsITableLayout **tableLayoutObject); // Needed to do appropriate deleting when last cell or row is about to be deleted // This doesn't count cells that don't start in the given row (are spanning from row above) - PRInt32 GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowIndex); + PRInt32 GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowIndex); + nsresult GetRowAt(nsCOMPtr &aTable, PRInt32 rowIndex, nsCOMPtr &aRow); // Most insert methods need to get the same basic context data NS_IMETHOD GetCellContext(nsCOMPtr &aSelection, diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index ffb30f5dc12..0e801d6b076 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -3256,11 +3256,15 @@ nsEditorShell::GetCellAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 NS_IMETHODIMP nsEditorShell::GetCellDataAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 colIndex, PRInt32 *aStartRowIndex, PRInt32 *aStartColIndex, - PRInt32 *aRowSpan, PRInt32 *aColSpan, PRBool *aIsSelected, nsIDOMElement **_retval) + PRInt32 *aRowSpan, PRInt32 *aColSpan, + PRInt32 *aActualRowSpan, PRInt32 *aActualColSpan, + PRBool *aIsSelected, nsIDOMElement **_retval) { if (!_retval || !aStartRowIndex || !aStartColIndex || - !aRowSpan || !aColSpan || !aIsSelected ) + !aRowSpan || !aColSpan || + !aActualRowSpan || !aActualColSpan || + !aIsSelected ) return NS_ERROR_NULL_POINTER; nsresult result = NS_NOINTERFACE; @@ -3271,7 +3275,10 @@ nsEditorShell::GetCellDataAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRIn nsCOMPtr tableEditor = do_QueryInterface(mEditor); if (tableEditor) result = tableEditor->GetCellDataAt(tableElement, rowIndex, colIndex, *_retval, - *aStartRowIndex, *aStartColIndex, *aRowSpan, *aColSpan, *aIsSelected); + *aStartRowIndex, *aStartColIndex, + *aRowSpan, *aColSpan, + *aActualRowSpan, *aActualColSpan, + *aIsSelected); } break; default: diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index 8ee15532b7e..3651202b25c 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -327,10 +327,15 @@ interface nsIEditorShell : nsISupports /* Get a cell and associated data from the layout frame based on cell map coordinates (0 index) */ nsIDOMElement GetCellAt(in nsIDOMElement tableElement, in PRInt32 rowIndex, in PRInt32 colIndex); /* Get cell at a location in the layout's cellmap with associated data - returns null when past last cell in a row or column */ + returns null when past last cell in a row or column + Note that rowSpan and/or colSpan may be 0 (for extending across entire table), + so actualRowSpan and actualColSpan are the real number of cells spanned + */ nsIDOMElement GetCellDataAt(in nsIDOMElement tableElement, in PRInt32 rowIndex, in PRInt32 colIndex, out PRInt32 startRowIndex, out PRInt32 startColIndex, - out PRInt32 rowSpan, out PRInt32 colSpan, out boolean isSelected); + out PRInt32 rowSpan, out PRInt32 colSpan, + out PRInt32 actualRowSpan, out PRInt32 actualColSpan, + out boolean isSelected); /**** end of table editing *****/ diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index bf675136a9a..f74459dcbb4 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -7246,3 +7246,48 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMSelection *aInSelection) return result; } +NS_IMETHODIMP +nsHTMLEditor::GetNextElementByTagName(nsIDOMElement *aCurrentElement, + const nsString *aTagName, + nsIDOMElement **aReturn) +{ + nsresult res = NS_OK; + if (!aCurrentElement || !aTagName || !aReturn) + return NS_ERROR_NULL_POINTER; + + nsIAtom *tagAtom = NS_NewAtom(*aTagName); + if (!tagAtom) { return NS_ERROR_NULL_POINTER; } + if (tagAtom==nsIEditProperty::th) + tagAtom=nsIEditProperty::td; + + nsCOMPtr currentNode = do_QueryInterface(aCurrentElement); + if (!currentNode) + return NS_ERROR_FAILURE; + + *aReturn = nsnull; + + nsCOMPtr nextNode; + PRBool done = PR_FALSE; + + do { + res = GetNextNode(currentNode, PR_TRUE, getter_AddRefs(nextNode)); + if (NS_FAILED(res)) return res; + if (!nextNode) break; + + nsCOMPtr atom = GetTag(currentNode); + + if (tagAtom==atom) + { + nsCOMPtr element = do_QueryInterface(currentNode); + if (!element) return NS_ERROR_NULL_POINTER; + + *aReturn = element; + NS_ADDREF(*aReturn); + done = PR_TRUE; + return NS_OK; + } + currentNode = nextNode; + } while (!done); + + return res; +} diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 56166562dfa..82d3a5e3218 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -138,6 +138,8 @@ public: NS_IMETHOD GetElementOrParentByTagName(const nsString& aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn); NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); + NS_IMETHOD GetNextElementByTagName(nsIDOMElement *aCurrentElement, const nsString *aTagName, nsIDOMElement **aReturn); + NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); @@ -187,7 +189,9 @@ public: NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell); NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, PRInt32& aStartRowIndex, PRInt32& aStartColIndex, - PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected); + PRInt32& aRowSpan, PRInt32& aColSpan, + PRInt32& aActualRowSpan, PRInt32& aActualColSpan, + PRBool& aIsSelected); NS_IMETHOD SetCaretAfterTableEdit(nsIDOMElement* aTable, PRInt32 aRow, PRInt32 aCol, PRInt32 aDirection); NS_IMETHOD GetSelectedOrParentTableElement(nsCOMPtr &aTableElement, nsString& aTagName, PRBool &aIsSelected); @@ -318,7 +322,8 @@ protected: NS_IMETHOD GetTableLayoutObject(nsIDOMElement* aTable, nsITableLayout **tableLayoutObject); // Needed to do appropriate deleting when last cell or row is about to be deleted // This doesn't count cells that don't start in the given row (are spanning from row above) - PRInt32 GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowIndex); + PRInt32 GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowIndex); + nsresult GetRowAt(nsCOMPtr &aTable, PRInt32 rowIndex, nsCOMPtr &aRow); // Most insert methods need to get the same basic context data NS_IMETHOD GetCellContext(nsCOMPtr &aSelection, diff --git a/mozilla/editor/public/nsITableEditor.h b/mozilla/editor/public/nsITableEditor.h index cda3bad84b2..b595d162637 100644 --- a/mozilla/editor/public/nsITableEditor.h +++ b/mozilla/editor/public/nsITableEditor.h @@ -134,15 +134,27 @@ public: * A "layout column" is all cells sharing the same left edge * This is important to determine what to do when inserting or deleting a column or row * - * @param aTable A table in the document - * @param aRowIndex, aColIndex The 0-based cellmap indexes + * @param aTable A table in the document + * @param aRowIndex, aColIndex The 0-based cellmap indexes + * returns values: + * @param aCell The cell at this cellmap location + * @param aStartRowIndex The row index where cell starts + * @param aStartColIndex The col index where cell starts + * @param aRowSpan May be 0 (to span down entire table) or number of cells spanned + * @param aColSpan May be 0 (to span across entire table) or number of cells spanned + * @param aActualRowSpan The actual number of cellmap locations (rows) spanned by the cell + * @param aActualColSpan The actual number of cellmap locations (columns) spanned by the cell + * @param aIsSelected + * @param * * Note that this returns NS_TABLELAYOUT_CELL_NOT_FOUND * when a cell is not found at the given indexes (see note for GetCellAt()) */ NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, PRInt32& aStartRowIndex, PRInt32& aStartColIndex, - PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected)=0; + PRInt32& aRowSpan, PRInt32& aColSpan, + PRInt32& aActualRowSpan, PRInt32& aActualColSpan, + PRBool& aIsSelected)=0; /** Preferred direction to search for neighboring cell diff --git a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js index 8616e7d14bd..fd34ee41f6c 100644 --- a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js +++ b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js @@ -118,11 +118,15 @@ function EditorTestTableLayout() var startColIndexObj = new Object(); var rowSpanObj = new Object(); var colSpanObj = new Object(); + var actualRowSpanObj = new Object(); + var actualColSpanObj = new Object(); var isSelectedObj = new Object(); var startRowIndex = 0; var startColIndex = 0; var rowSpan; var colSpan; + var actualRowSpan; + var actualColSpan; var isSelected; var col = 0; var row = 0; @@ -138,19 +142,24 @@ function EditorTestTableLayout() while (!doneWithRow) // Iterate through rows { + dump("* Data for ROW="+row+":\n"); while(!doneWithCol) // Iterate through cells in the row { try { cell = editorShell.GetCellDataAt(table, row, col, startRowIndexObj, startColIndexObj, - rowSpanObj, colSpanObj, isSelectedObj); + rowSpanObj, colSpanObj, actualRowSpanObj, actualColSpanObj, + isSelectedObj); if (cell) { rowSpan = rowSpanObj.value; colSpan = colSpanObj.value; + actualRowSpan = actualRowSpanObj.value; + actualColSpan = actualColSpanObj.value; isSelected = isSelectedObj.value; - dump("Row,Col: "+row+","+col+" StartRow,StartCol: "+startRowIndexObj.value+","+startColIndexObj.value+" RowSpan="+rowSpan+" ColSpan="+colSpan); + dump(" Row="+row+", Col="+col+" StartRow="+startRowIndexObj.value+", StartCol="+startColIndexObj.value+"\n"); + dump(" RowSpan="+rowSpan+", ColSpan="+colSpan+" ActualRowSpan="+actualRowSpan+", ActualColSpan="+actualColSpan); if (isSelected) dump(" Cell is selected\n"); else @@ -172,12 +181,12 @@ function EditorTestTableLayout() // Get maximum number of cells in any row if (col > maxColCount) maxColCount = col; - dump(" End of row found\n\n"); + dump(" End of row found\n\n"); } } catch (e) { - dump(" *** GetCellDataAt barfed at Row,Col:"+row+","+col+" ***\n\n"); - col++; + dump(" *** GetCellDataAt failed at Row="+row+, Col="+col+" ***\n\n"); + return; } } if (col == 0) { @@ -191,7 +200,6 @@ function EditorTestTableLayout() col = 0; row++; doneWithCol = false; - dump("Setup for next row\n"); } } dump("Counted during scan: Number of rows="+rowCount+" Number of Columns="+maxColCount+"\n"); diff --git a/mozilla/editor/ui/composer/skin/editor.css b/mozilla/editor/ui/composer/skin/editor.css index 949ceee03ce..be4fdbc9f6e 100644 --- a/mozilla/editor/ui/composer/skin/editor.css +++ b/mozilla/editor/ui/composer/skin/editor.css @@ -121,9 +121,8 @@ box#DisplayModeBar titledbutton.DisplayModeButton { border-left: 1px solid darkgray; padding: 0px 4px 0px 4px; margin: 0px; - /* Same as toolbar.standard titledbutton */ - color: #CCFFFF; - background-color: #003366; + color: black; + background-color: #CCCCCC; } box#DisplayModeBar titledbutton.DisplayModeButton:hover { @@ -143,8 +142,6 @@ box#DisplayModeBar titledbutton.DisplayModeButton[selected="1"] { padding: 0px 4px 0px 4px; margin: -2px 0px 0px 0px; font-weight: bold; - color: black; - background-color: #CCCCCC; } box#DisplayModeBar titledbutton.DisplayModeButton[selected="1"]:hover { diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index e9350dd6c54..a4732fce4f0 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -357,8 +357,9 @@ function SetPixelOrPercentByID(elementID, percentString) // USE onkeyup! // forceInteger by petejc (pete@postpagan.com) -var sysBeep = Components.classes["component://netscape/sound"].createInstance(); -sysBeep = sysBeep.QueryInterface(Components.interfaces.nsISound); +// No one likes the beep! +//var sysBeep = Components.classes["component://netscape/sound"].createInstance(); +//sysBeep = sysBeep.QueryInterface(Components.interfaces.nsISound); function forceInteger(elementID) { @@ -375,7 +376,7 @@ function forceInteger(elementID) // we hope to remove the following line for blur() once xp widgets land // cmanske (9/15) testing this now that GFX ender widget is active //editField.blur(); - sysBeep.Beep(); + //sysBeep.Beep(); } } diff --git a/mozilla/editor/ui/dialogs/content/EdDictionary.xul b/mozilla/editor/ui/dialogs/content/EdDictionary.xul index e41a0e537b9..da58855e570 100644 --- a/mozilla/editor/ui/dialogs/content/EdDictionary.xul +++ b/mozilla/editor/ui/dialogs/content/EdDictionary.xul @@ -24,52 +24,38 @@ - - - - + + - - - - - - - - - - - - - - - - -
- &wordEditField.label;
-
- - - -
- &DictionaryList.label; -
- - - -
- -
- - -
-
+ + + + &wordEditField.label; + + + + + + + &DictionaryList.label; + + + + + + + + + + + + + +