From 19ab0e4029f204c85d5a8259e71eba4f92f14a3e Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Tue, 27 Jul 1999 23:59:22 +0000 Subject: [PATCH] Initial table editing stuff. Removed table editing transactions (use basic node txns). Fixed TrimString JS methods. Fixed setting border in insert table. git-svn-id: svn://10.0.0.236/trunk@41372 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/EditTable.cpp | 159 ++++++++++---- mozilla/editor/base/Makefile.in | 9 - mozilla/editor/base/makefile.win | 18 -- mozilla/editor/base/nsEditorShell.cpp | 204 +++++++++++++++++- mozilla/editor/base/nsEditorShell.h | 10 + mozilla/editor/base/nsHTMLEditor.cpp | 132 +++++++----- mozilla/editor/base/nsHTMLEditor.h | 28 +-- mozilla/editor/base/nsJSEditorLog.cpp | 63 ++++++ mozilla/editor/base/nsJSEditorLog.h | 11 + mozilla/editor/composer/src/nsEditorShell.cpp | 204 +++++++++++++++++- mozilla/editor/composer/src/nsEditorShell.h | 10 + mozilla/editor/idl/nsIEditorShell.idl | 13 ++ .../editor/libeditor/html/nsHTMLEditor.cpp | 132 +++++++----- mozilla/editor/libeditor/html/nsHTMLEditor.h | 28 +-- mozilla/editor/public/nsIHTMLEditor.h | 11 +- .../ui/dialogs/content/EdDialogCommon.js | 59 +++-- .../editor/ui/dialogs/content/EdHLineProps.js | 1 - .../ui/dialogs/content/EdInsertTable.js | 30 ++- .../ui/dialogs/content/EdInsertTable.xul | 4 +- 19 files changed, 869 insertions(+), 257 deletions(-) diff --git a/mozilla/editor/base/EditTable.cpp b/mozilla/editor/base/EditTable.cpp index 8d3075a571a..d0234a33b6f 100644 --- a/mozilla/editor/base/EditTable.cpp +++ b/mozilla/editor/base/EditTable.cpp @@ -27,7 +27,8 @@ #include "nsIDOMRange.h" #include "nsIDOMSelection.h" #include "nsIAtom.h" - +#include "nsIDOMHTMLTableElement.h" +#include "nsIDOMHTMLTableCellElement.h" /* #include "nsIDocument.h" #include "nsIServiceManager.h" @@ -49,78 +50,88 @@ // transactions the editor knows how to build #include "TransactionFactory.h" #include "EditAggregateTxn.h" -#include "InsertTableTxn.h" -#include "InsertTableCellTxn.h" -#include "InsertTableColumnTxn.h" -#include "InsertTableRowTxn.h" -#include "DeleteTableTxn.h" -#include "DeleteTableCellTxn.h" -#include "DeleteTableColumnTxn.h" -#include "DeleteTableRowTxn.h" -#include "JoinTableCellsTxn.h" -// Include after above so Transaction types are defined first +#include "nsIDOMHTMLCollection.h" #include "nsHTMLEditor.h" static NS_DEFINE_IID(kITransactionManagerIID, NS_ITRANSACTIONMANAGER_IID); -// Table Editing methods -- for testing, hooked up to Tool Menu items -// Modeled after nsEditor::InsertText() -NS_IMETHODIMP nsHTMLEditor::InsertTable() +// Table Editing methods + +NS_IMETHODIMP +nsHTMLEditor::InsertTable() { nsresult result=NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn) -{ - if( aTableNode == nsnull || aTxn == nsnull ) - { - return NS_ERROR_NULL_POINTER; - } - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) +NS_IMETHODIMP +nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) +NS_IMETHODIMP +nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) +NS_IMETHODIMP +nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) +{ + nsCOMPtrselection; + nsresult res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) + return res; + // Collapse the current selection + selection->ClearSelection(); + nsCOMPtr anchorNode; + res = selection->GetAnchorNode(getter_AddRefs(anchorNode)); + if (NS_FAILED(res) || !anchorNode) + return res; + + nsCOMPtr cell; + nsCOMPtr row; + nsCOMPtr table; + res = NS_ERROR_FAILURE; + //if(NS_SUCCEEDED(GetElementOrParentByTagName("td", anchorNode, getter_AddRefs(cell)) + + + return res; +} + +NS_IMETHODIMP +nsHTMLEditor::DeleteTable() { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::DeleteTable() +NS_IMETHODIMP +nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) +NS_IMETHODIMP +nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) +NS_IMETHODIMP +nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) +NS_IMETHODIMP +nsHTMLEditor::JoinTableCells(PRBool aCellToRight) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::JoinTableCells(PRBool aCellToRight) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsHTMLEditor::GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColIndex, PRInt32 &aRowIndex) +NS_IMETHODIMP +nsHTMLEditor::GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex) { nsresult result=NS_ERROR_NOT_INITIALIZED; aColIndex=0; // initialize out params @@ -128,7 +139,7 @@ NS_IMETHODIMP nsHTMLEditor::GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColI result = NS_ERROR_FAILURE; // we return an error unless we get the index nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr - result = nsEditor::GetLayoutObject(aCellNode, &layoutObject); + result = nsEditor::GetLayoutObject(aCell, &layoutObject); if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject)) { // get the table cell interface from the frame @@ -138,33 +149,93 @@ NS_IMETHODIMP nsHTMLEditor::GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColI { // get the index result = cellLayoutObject->GetColIndex(aColIndex); if (NS_SUCCEEDED(result)) + { result = cellLayoutObject->GetRowIndex(aRowIndex); + } + } + } + return result; +} + +NS_IMETHODIMP +nsHTMLEditor::GetRowIndex(nsIDOMElement *aCell, PRInt32 &aRowIndex) +{ + nsresult result=NS_ERROR_NOT_INITIALIZED; + aRowIndex=0; + result = NS_ERROR_FAILURE; // we return an error unless we get the index + nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr + + result = nsEditor::GetLayoutObject(aCell, &layoutObject); + + if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject)) + { // get the table cell interface from the frame + nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted + result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject)); + if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject)) + { // get the index + result = cellLayoutObject->GetRowIndex(aRowIndex); } } return result; } -NS_IMETHODIMP nsHTMLEditor::GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode) +NS_IMETHODIMP +nsHTMLEditor::GetColumnIndex(nsIDOMElement *aCell, PRInt32 &aColIndex) +{ + nsresult result=NS_ERROR_NOT_INITIALIZED; + aColIndex=0; // initialize out params + result = NS_ERROR_FAILURE; // we return an error unless we get the index + nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr + + result = nsEditor::GetLayoutObject(aCell, &layoutObject); + + if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject)) + { // get the table cell interface from the frame + nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted + result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject)); + if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject)) + { // get the index + result = cellLayoutObject->GetColIndex(aColIndex); + } + } + return result; +} + +NS_IMETHODIMP +nsHTMLEditor::GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32& aCount) { return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP nsHTMLEditor::GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode) +NS_IMETHODIMP +nsHTMLEditor::GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32& aCount) { return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP nsHTMLEditor::GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode) +NS_IMETHODIMP +nsHTMLEditor::GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32& aCount) { return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP nsHTMLEditor::GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode) +NS_IMETHODIMP +nsHTMLEditor::GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32& aCount) { return NS_ERROR_NOT_IMPLEMENTED; } +//TODO: This should be implemented by layout for efficiency +NS_IMETHODIMP +nsHTMLEditor::GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, + PRInt32& aStartRowIndex, PRInt32& aStartColIndex, PRInt32& aRowSpan, PRInt32& aColSpan) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/editor/base/Makefile.in b/mozilla/editor/base/Makefile.in index 219ebd6bac7..54139085e4c 100644 --- a/mozilla/editor/base/Makefile.in +++ b/mozilla/editor/base/Makefile.in @@ -41,15 +41,6 @@ CPPSRCS = \ EditTxn.cpp \ EditAggregateTxn.cpp \ EditTable.cpp \ - InsertTableTxn.cpp \ - InsertTableCellTxn.cpp \ - InsertTableColumnTxn.cpp \ - InsertTableRowTxn.cpp \ - DeleteTableTxn.cpp \ - DeleteTableCellTxn.cpp \ - DeleteTableColumnTxn.cpp \ - DeleteTableRowTxn.cpp \ - JoinTableCellsTxn.cpp \ InsertTextTxn.cpp \ nsInsertHTMLTxn.cpp \ PlaceholderTxn.cpp \ diff --git a/mozilla/editor/base/makefile.win b/mozilla/editor/base/makefile.win index c1fc006dbce..79e412e399f 100644 --- a/mozilla/editor/base/makefile.win +++ b/mozilla/editor/base/makefile.win @@ -48,15 +48,6 @@ CPPSRCS = \ nsHTMLEditor.cpp \ nsHTMLEditFactory.cpp \ EditTable.cpp \ - InsertTableTxn.cpp \ - InsertTableCellTxn.cpp \ - InsertTableColumnTxn.cpp \ - InsertTableRowTxn.cpp \ - DeleteTableTxn.cpp \ - DeleteTableCellTxn.cpp \ - DeleteTableColumnTxn.cpp \ - DeleteTableRowTxn.cpp \ - JoinTableCellsTxn.cpp \ nsInternetCiter.cpp \ nsAOLCiter.cpp \ nsEditorShell.cpp \ @@ -95,15 +86,6 @@ CPP_OBJS = \ .\$(OBJDIR)\nsHTMLEditor.obj \ .\$(OBJDIR)\nsHTMLEditFactory.obj \ .\$(OBJDIR)\EditTable.obj \ - .\$(OBJDIR)\InsertTableTxn.obj \ - .\$(OBJDIR)\InsertTableCellTxn.obj \ - .\$(OBJDIR)\InsertTableColumnTxn.obj \ - .\$(OBJDIR)\InsertTableRowTxn.obj \ - .\$(OBJDIR)\DeleteTableTxn.obj \ - .\$(OBJDIR)\DeleteTableCellTxn.obj \ - .\$(OBJDIR)\DeleteTableColumnTxn.obj \ - .\$(OBJDIR)\DeleteTableRowTxn.obj \ - .\$(OBJDIR)\JoinTableCellsTxn.obj \ .\$(OBJDIR)\nsInternetCiter.obj \ .\$(OBJDIR)\nsAOLCiter.obj \ .\$(OBJDIR)\nsEditorShell.obj \ diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 38dae9ad8e8..8701593f952 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -1080,9 +1080,9 @@ nsEditorShell::GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType fileWidget->SetFilterList(1, titles, filters); dialogResult = fileWidget->GetFile(nsnull, title, fileSpec); } else { - nsAutoString titles[] = {"Image Files"}; - nsAutoString filters[] = {"*.gif; *.jpg; *.jpeg; *.png"}; - fileWidget->SetFilterList(1, titles, filters); + nsAutoString imgTitles[] = {"Image Files"}; + nsAutoString imgFilters[] = {"*.gif; *.jpg; *.jpeg; *.png"}; + fileWidget->SetFilterList(1, imgTitles, imgFilters); dialogResult = fileWidget->GetFile(nsnull, title, fileSpec); } // Do this after we get this from preferences @@ -1871,11 +1871,38 @@ nsEditorShell::InsertImage() NS_IMETHODIMP nsEditorShell::GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_retval) { - if (!_retval) + if (!tagName || !_retval) return NS_ERROR_NULL_POINTER; nsresult result = NS_NOINTERFACE; - nsAutoString aTagName(tagName); + nsAutoString TagName(tagName); + + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + nsCOMPtr element; + if (htmlEditor) + return htmlEditor->GetSelectedElement(TagName, _retval); + } + break; + case ePlainTextEditorType: + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetElementOrParentByTagName(const PRUnichar *tagName, nsIDOMNode *node, nsIDOMElement **_retval) +{ + if (!tagName || !node || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + nsAutoString TagName(tagName); switch (mEditorType) { @@ -1883,10 +1910,9 @@ nsEditorShell::GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_ret { nsCOMPtr htmlEditor = do_QueryInterface(mEditor); if (htmlEditor) - return htmlEditor->GetSelectedElement(aTagName, _retval); + return htmlEditor->GetElementOrParentByTagName(TagName, node, _retval); } break; - case ePlainTextEditorType: default: result = NS_ERROR_NOT_IMPLEMENTED; } @@ -2028,6 +2054,170 @@ nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement) return result; } +/* Table Editing */ +NS_IMETHODIMP +nsEditorShell::GetRowIndex(nsIDOMElement *cellElement, PRInt32 *_retval) +{ + if (!cellElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetRowIndex(cellElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetColumnIndex(nsIDOMElement *cellElement, PRInt32 *_retval) +{ + if (!cellElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetColumnIndex(cellElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetCellAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 colIndex, nsIDOMElement **_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetCellAt(tableElement, rowIndex, colIndex, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetRowCellCount(nsIDOMElement *tableElement, PRInt32 colIndex, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetRowCellCount(tableElement, colIndex, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + + +NS_IMETHODIMP +nsEditorShell::GetColumnCellCount(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetColumnCellCount(tableElement, rowIndex, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetMaxRowCellCount(nsIDOMElement *tableElement, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetMaxRowCellCount(tableElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetMaxColumnCellCount(nsIDOMElement *tableElement, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetMaxColumnCellCount(tableElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} +/* end of table editing */ + NS_IMETHODIMP nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray) { diff --git a/mozilla/editor/base/nsEditorShell.h b/mozilla/editor/base/nsEditorShell.h index e2dc7dc7a3c..5bd10220189 100644 --- a/mozilla/editor/base/nsEditorShell.h +++ b/mozilla/editor/base/nsEditorShell.h @@ -140,6 +140,7 @@ class nsEditorShell : public nsIEditorShell, /* nsIDOMElement GetSelectedElement (in wstring tagName); */ NS_IMETHOD GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_retval); + NS_IMETHOD GetElementOrParentByTagName(const PRUnichar *tagName, nsIDOMNode *aNode, nsIDOMElement **_retval); NS_IMETHOD CreateElementWithDefaults(const PRUnichar *tagName, nsIDOMElement **_retval); NS_IMETHOD InsertElement(nsIDOMElement *element, PRBool deleteSelection); NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); @@ -147,6 +148,15 @@ class nsEditorShell : public nsIEditorShell, NS_IMETHOD SelectElement(nsIDOMElement *element); NS_IMETHOD SetSelectionAfterElement(nsIDOMElement *element); + // Return just 1 value -- for Java Script + NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 *aRowIndex); + NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 *aColIndex); + NS_IMETHOD GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 *aCount); + NS_IMETHOD GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32 *aCount); + NS_IMETHOD GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32 *aCount); + NS_IMETHOD GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32 *aCount); + NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement **_retval); + /* Get list of embedded objects, e.g. for mail compose */ NS_IMETHOD GetEmbeddedObjects(nsISupportsArray **aObjectArray); diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 67b70187c61..78198f6a44d 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -86,7 +86,44 @@ static PRBool gNoisy = PR_FALSE; static const PRBool gNoisy = PR_FALSE; #endif +// Some utilities to handle stupid overloading of "A" tag for link and named anchor +static char hrefText[] = "href"; +static char linkText[] = "link"; +static char anchorText[] = "anchor"; +static char namedanchorText[] = "namedanchor"; +#define IsLink(s) (s.EqualsIgnoreCase(hrefText) || s.EqualsIgnoreCase(linkText)) +#define IsNamedAnchor(s) (s.EqualsIgnoreCase(anchorText) || s.EqualsIgnoreCase(namedanchorText)) + +static PRBool IsLinkNode(nsIDOMNode *aNode) +{ + if (aNode) + { + nsCOMPtr anchor = do_QueryInterface(aNode); + if (anchor) + { + nsString tmpText; + if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) + return PR_TRUE; + } + } + return PR_FALSE; +} + +static PRBool IsNamedAnchorNode(nsIDOMNode *aNode) +{ + if (aNode) + { + nsCOMPtr anchor = do_QueryInterface(aNode); + if (anchor) + { + nsString tmpText; + if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) + return PR_TRUE; + } + } + return PR_FALSE; +} nsHTMLEditor::nsHTMLEditor() { @@ -1941,45 +1978,48 @@ nsHTMLEditor::InsertImage(nsString& aURL, return res; } -static PRBool IsLinkNode(nsIDOMNode *aNode) -{ - if (aNode) - { - nsCOMPtr anchor = do_QueryInterface(aNode); - if (anchor) - { - nsString tmpText; - if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) - return PR_TRUE; - } - } - return PR_FALSE; -} - NS_IMETHODIMP -nsHTMLEditor::GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn) +nsHTMLEditor::GetElementOrParentByTagName(const nsString &aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn) { - if (!aNode || !aReturn ) + if (aTagName.Length() == 0 || !aNode || !aReturn ) return NS_ERROR_NULL_POINTER; + nsAutoString TagName = aTagName; + TagName.ToLowerCase(); + PRBool getLink = IsLink(TagName); + PRBool getNamedAnchor = IsNamedAnchor(TagName); + if ( getLink || getNamedAnchor) + { + TagName = "a"; + } + // default is null - no element found *aReturn = nsnull; - nsCOMPtr linkNode = aNode; + nsCOMPtr currentNode = aNode; nsCOMPtr parent; PRBool bNodeFound = PR_FALSE; while (PR_TRUE) { // Test if we have a link (an anchor with href set) - if (IsLinkNode(linkNode)) + if ( (getLink && IsLinkNode(currentNode)) || + (getNamedAnchor && IsNamedAnchorNode(currentNode)) ) { bNodeFound = PR_TRUE; break; + } else { + nsAutoString currentTagName; + aNode->GetNodeName(currentTagName); + if (currentTagName.EqualsIgnoreCase(TagName)) + { + bNodeFound = PR_TRUE; + break; + } } // Search up the parent chain // We should never fail because of root test below, but lets be safe - if (!NS_SUCCEEDED(linkNode->GetParentNode(getter_AddRefs(parent))) || !parent) + if (!NS_SUCCEEDED(currentNode->GetParentNode(getter_AddRefs(parent))) || !parent) break; // Stop searching if parent is a root (body or table cell) @@ -1988,14 +2028,14 @@ nsHTMLEditor::GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn) parent->GetNodeName(parentTagName); if (!NS_SUCCEEDED(IsRootTag(parentTagName, isRoot)) || isRoot) break; - linkNode = parent; + currentNode = parent; } if (bNodeFound) { - nsCOMPtr linkElement = do_QueryInterface(linkNode); - if (linkElement) + nsCOMPtr currentElement = do_QueryInterface(currentNode); + if (currentElement) { - *aReturn = linkElement; + *aReturn = currentElement; // Getters must addref NS_ADDREF(*aReturn); } @@ -2003,6 +2043,7 @@ nsHTMLEditor::GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn) return NS_OK; } + NS_IMETHODIMP nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { @@ -2031,7 +2072,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu nsCOMPtr selectedElement; PRBool bNodeFound = PR_FALSE; - if (TagName == "href") + if (IsLink(TagName)) { // Link tag is a special case - we return the anchor node // found for any selection that is totally within a link, @@ -2065,7 +2106,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu } #endif nsCOMPtr parentLinkOfAnchor; - res = GetParentLinkElement(anchorNode, getter_AddRefs(parentLinkOfAnchor)); + res = GetElementOrParentByTagName("href", anchorNode, getter_AddRefs(parentLinkOfAnchor)); if (NS_SUCCEEDED(res) && parentLinkOfAnchor) { if (isCollapsed) @@ -2075,14 +2116,14 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu } else if(focusNode) { // Link node must be the same for both ends of selection nsCOMPtr parentLinkOfFocus; - res = GetParentLinkElement(focusNode, getter_AddRefs(parentLinkOfFocus)); + res = GetElementOrParentByTagName("href", focusNode, getter_AddRefs(parentLinkOfFocus)); if (NS_SUCCEEDED(res) && parentLinkOfFocus == parentLinkOfAnchor) bNodeFound = PR_TRUE; } // We found a link node parent if (bNodeFound) { - // GetParentLinkElement addref'd this, so we don't need to do it here + // GetElementOrParentByTagName addref'd this, so we don't need to do it here *aReturn = parentLinkOfAnchor; return NS_OK; } @@ -2100,7 +2141,6 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu } } } - //NOTE: We will not find the link node aboveif it is the only thing selected if (!bNodeFound && !isCollapsed) // Don't bother to examine selection if it is collapsed { @@ -2156,23 +2196,11 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu // The "A" tag is a pain, // used for both link(href is set) and "Named Anchor" - if (TagName == "href" || TagName == "anchor") + nsCOMPtr selectedNode = do_QueryInterface(selectedElement); + if ( (IsLink(TagName) && IsLinkNode(selectedNode)) || + (IsNamedAnchor(TagName) && IsNamedAnchorNode(selectedNode)) ) { - // We could use GetAttribute, but might as well use anchor element directly - nsCOMPtr anchor = do_QueryInterface(selectedElement); - if (anchor) - { - nsString tmpText; - if( TagName == "href") - { - if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) - bNodeFound = PR_TRUE; - } else if (TagName == "anchor") - { - if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) - bNodeFound = PR_TRUE; - } - } + bNodeFound = PR_TRUE; } else if (TagName == domTagName) { // All other tag names are handled here bNodeFound = PR_TRUE; } @@ -2218,9 +2246,7 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* TagName.ToLowerCase(); nsAutoString realTagName; - PRBool isHREF = (TagName == "href"); - PRBool isAnchor = (TagName == "anchor"); - if (isHREF || isAnchor) + if (IsLink(TagName) || IsNamedAnchor(TagName)) { realTagName = "a"; } else { @@ -2368,13 +2394,9 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) // Named Anchor is a special case, // We collapse to insert element BEFORE the selection // For all other tags, we insert AFTER the selection - nsCOMPtr anchor = do_QueryInterface(aElement); - if (anchor) - { - nsAutoString name; - if (NS_SUCCEEDED(anchor->GetName(name)) && name.GetUnicode() && name.Length() != 0) - collapseAfter = PR_FALSE; - } + nsCOMPtr node = do_QueryInterface(aElement); + if (IsNamedAnchorNode(node)) + collapseAfter = PR_FALSE; if (collapseAfter) { diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index 99f57779e91..ec7d3bf71d3 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -152,7 +152,10 @@ public: nsString& aAlt, nsString& aAlignment); NS_IMETHOD InsertList(const nsString& aListType); - NS_IMETHOD GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn); +// MHTML helper methods + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); + + 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 InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); @@ -164,16 +167,18 @@ public: PRBool SetCaretInTableCell(nsIDOMElement* aElement); PRBool IsElementInBody(nsIDOMElement* aElement); -// MHTML helper methods - NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); - // Table Editing (implemented in EditTable.cpp) - NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn); - NS_IMETHOD GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColIndex, PRInt32 &aRowIndex); - NS_IMETHOD GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode); - NS_IMETHOD GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode); - NS_IMETHOD GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode); - NS_IMETHOD GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode); + NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex); + // Return just 1 value -- for Java Script + NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 &aRowIndex); + NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 &aColIndex); + NS_IMETHOD GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32& aCount); + NS_IMETHOD GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32& aCount); + NS_IMETHOD GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32& aCount); + NS_IMETHOD GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32& aCount); + 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); NS_IMETHOD InsertTable(); NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool aAfter); NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool aAfter); @@ -183,8 +188,7 @@ public: NS_IMETHOD DeleteTableColumn(PRInt32 aNumber); NS_IMETHOD DeleteTableRow(PRInt32 aNumber); NS_IMETHOD JoinTableCells(PRBool aCellToRight); - - + protected: // rules initialization diff --git a/mozilla/editor/base/nsJSEditorLog.cpp b/mozilla/editor/base/nsJSEditorLog.cpp index 94f0bac4658..b9908710b8a 100644 --- a/mozilla/editor/base/nsJSEditorLog.cpp +++ b/mozilla/editor/base/nsJSEditorLog.cpp @@ -690,6 +690,12 @@ nsJSEditorLog::Align(const nsString& aAlign) return NS_OK; } +NS_IMETHODIMP +nsJSEditorLog::GetElementOrParentByTagName(const nsString &aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsJSEditorLog::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { @@ -820,6 +826,63 @@ nsJSEditorLog::JoinTableCells(PRBool aCellToRight) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +nsJSEditorLog::GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJSEditorLog::GetRowIndex(nsIDOMElement *aCell, PRInt32 &aRowIndex) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsJSEditorLog::GetColumnIndex(nsIDOMElement *aCell, PRInt32 &aColIndex) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJSEditorLog::GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32& aCount) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJSEditorLog::GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32& aCount) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJSEditorLog::GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32& aCount) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJSEditorLog::GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32& aCount) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +//TODO: This should be implemented by layout for efficiency +NS_IMETHODIMP +nsJSEditorLog::GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJSEditorLog::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, + PRInt32& aStartRowIndex, PRInt32& aStartColIndex, PRInt32& aRowSpan, PRInt32& aColSpan) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsJSEditorLog::BeginComposition(void) { diff --git a/mozilla/editor/base/nsJSEditorLog.h b/mozilla/editor/base/nsJSEditorLog.h index 2d13e6ec2d4..0282c45de56 100644 --- a/mozilla/editor/base/nsJSEditorLog.h +++ b/mozilla/editor/base/nsJSEditorLog.h @@ -125,6 +125,7 @@ public: NS_IMETHOD InsertList(const nsString& aListType); NS_IMETHOD Indent(const nsString& aIndent); NS_IMETHOD Align(const nsString& aAlign); + 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 InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); @@ -133,6 +134,16 @@ public: NS_IMETHOD SelectElement(nsIDOMElement* aElement); NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); + NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex); + NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 &aRowIndex); + NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 &aColIndex); + NS_IMETHOD GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32& aCount); + NS_IMETHOD GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32& aCount); + NS_IMETHOD GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32& aCount); + NS_IMETHOD GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32& aCount); + 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); NS_IMETHOD InsertTable(); NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool aAfter); NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool aAfter); diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 38dae9ad8e8..8701593f952 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -1080,9 +1080,9 @@ nsEditorShell::GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType fileWidget->SetFilterList(1, titles, filters); dialogResult = fileWidget->GetFile(nsnull, title, fileSpec); } else { - nsAutoString titles[] = {"Image Files"}; - nsAutoString filters[] = {"*.gif; *.jpg; *.jpeg; *.png"}; - fileWidget->SetFilterList(1, titles, filters); + nsAutoString imgTitles[] = {"Image Files"}; + nsAutoString imgFilters[] = {"*.gif; *.jpg; *.jpeg; *.png"}; + fileWidget->SetFilterList(1, imgTitles, imgFilters); dialogResult = fileWidget->GetFile(nsnull, title, fileSpec); } // Do this after we get this from preferences @@ -1871,11 +1871,38 @@ nsEditorShell::InsertImage() NS_IMETHODIMP nsEditorShell::GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_retval) { - if (!_retval) + if (!tagName || !_retval) return NS_ERROR_NULL_POINTER; nsresult result = NS_NOINTERFACE; - nsAutoString aTagName(tagName); + nsAutoString TagName(tagName); + + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + nsCOMPtr element; + if (htmlEditor) + return htmlEditor->GetSelectedElement(TagName, _retval); + } + break; + case ePlainTextEditorType: + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetElementOrParentByTagName(const PRUnichar *tagName, nsIDOMNode *node, nsIDOMElement **_retval) +{ + if (!tagName || !node || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + nsAutoString TagName(tagName); switch (mEditorType) { @@ -1883,10 +1910,9 @@ nsEditorShell::GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_ret { nsCOMPtr htmlEditor = do_QueryInterface(mEditor); if (htmlEditor) - return htmlEditor->GetSelectedElement(aTagName, _retval); + return htmlEditor->GetElementOrParentByTagName(TagName, node, _retval); } break; - case ePlainTextEditorType: default: result = NS_ERROR_NOT_IMPLEMENTED; } @@ -2028,6 +2054,170 @@ nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement) return result; } +/* Table Editing */ +NS_IMETHODIMP +nsEditorShell::GetRowIndex(nsIDOMElement *cellElement, PRInt32 *_retval) +{ + if (!cellElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetRowIndex(cellElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetColumnIndex(nsIDOMElement *cellElement, PRInt32 *_retval) +{ + if (!cellElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetColumnIndex(cellElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetCellAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 colIndex, nsIDOMElement **_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetCellAt(tableElement, rowIndex, colIndex, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetRowCellCount(nsIDOMElement *tableElement, PRInt32 colIndex, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetRowCellCount(tableElement, colIndex, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + + +NS_IMETHODIMP +nsEditorShell::GetColumnCellCount(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetColumnCellCount(tableElement, rowIndex, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetMaxRowCellCount(nsIDOMElement *tableElement, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetMaxRowCellCount(tableElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetMaxColumnCellCount(nsIDOMElement *tableElement, PRInt32 *_retval) +{ + if (!tableElement || !_retval) + return NS_ERROR_NULL_POINTER; + + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetMaxColumnCellCount(tableElement, *_retval); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + + return result; +} +/* end of table editing */ + NS_IMETHODIMP nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray) { diff --git a/mozilla/editor/composer/src/nsEditorShell.h b/mozilla/editor/composer/src/nsEditorShell.h index e2dc7dc7a3c..5bd10220189 100644 --- a/mozilla/editor/composer/src/nsEditorShell.h +++ b/mozilla/editor/composer/src/nsEditorShell.h @@ -140,6 +140,7 @@ class nsEditorShell : public nsIEditorShell, /* nsIDOMElement GetSelectedElement (in wstring tagName); */ NS_IMETHOD GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_retval); + NS_IMETHOD GetElementOrParentByTagName(const PRUnichar *tagName, nsIDOMNode *aNode, nsIDOMElement **_retval); NS_IMETHOD CreateElementWithDefaults(const PRUnichar *tagName, nsIDOMElement **_retval); NS_IMETHOD InsertElement(nsIDOMElement *element, PRBool deleteSelection); NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); @@ -147,6 +148,15 @@ class nsEditorShell : public nsIEditorShell, NS_IMETHOD SelectElement(nsIDOMElement *element); NS_IMETHOD SetSelectionAfterElement(nsIDOMElement *element); + // Return just 1 value -- for Java Script + NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 *aRowIndex); + NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 *aColIndex); + NS_IMETHOD GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 *aCount); + NS_IMETHOD GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32 *aCount); + NS_IMETHOD GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32 *aCount); + NS_IMETHOD GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32 *aCount); + NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement **_retval); + /* Get list of embedded objects, e.g. for mail compose */ NS_IMETHOD GetEmbeddedObjects(nsISupportsArray **aObjectArray); diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index 84ea03a621b..c434e69a802 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -27,6 +27,7 @@ class nsIDOMWindow; class nsIDOMDocument; class nsIDOMSelection; class nsIDOMElement; +class nsIDOMNode; %} interface nsIFileSpec; @@ -97,7 +98,10 @@ interface nsIEditorShell : nsISupports void Indent(in wstring indent); void Align(in wstring align); + /* Element insert and property editing */ nsIDOMElement GetSelectedElement(in wstring tagName); + /* returns the element conversion of supplied node or a parent of required type */ + nsIDOMElement GetElementOrParentByTagName(in wstring tagName, in nsIDOMNode node); nsIDOMElement CreateElementWithDefaults(in wstring tagName); void InsertElement(in nsIDOMElement element, in boolean deleteSelection); void SaveHLineSettings(in nsIDOMElement element); @@ -105,6 +109,15 @@ interface nsIEditorShell : nsISupports void SelectElement(in nsIDOMElement element); void SetSelectionAfterElement(in nsIDOMElement element); + /* Table editing */ + PRInt32 GetRowIndex(in nsIDOMElement cellElement); + PRInt32 GetColumnIndex(in nsIDOMElement cellElement); + nsIDOMElement GetCellAt(in nsIDOMElement tableElement, in PRInt32 rowIndex, in PRInt32 colIndex); + PRInt32 GetRowCellCount(in nsIDOMElement tableElement, in PRInt32 colIndex); + PRInt32 GetColumnCellCount(in nsIDOMElement tableElement, in PRInt32 rowIndex); + PRInt32 GetMaxRowCellCount(in nsIDOMElement tableElement); + PRInt32 GetMaxColumnCellCount(in nsIDOMElement tableElement); + /* Get list of embedded objects, e.g. for mail compose */ nsISupportsArray GetEmbeddedObjects(); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 67b70187c61..78198f6a44d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -86,7 +86,44 @@ static PRBool gNoisy = PR_FALSE; static const PRBool gNoisy = PR_FALSE; #endif +// Some utilities to handle stupid overloading of "A" tag for link and named anchor +static char hrefText[] = "href"; +static char linkText[] = "link"; +static char anchorText[] = "anchor"; +static char namedanchorText[] = "namedanchor"; +#define IsLink(s) (s.EqualsIgnoreCase(hrefText) || s.EqualsIgnoreCase(linkText)) +#define IsNamedAnchor(s) (s.EqualsIgnoreCase(anchorText) || s.EqualsIgnoreCase(namedanchorText)) + +static PRBool IsLinkNode(nsIDOMNode *aNode) +{ + if (aNode) + { + nsCOMPtr anchor = do_QueryInterface(aNode); + if (anchor) + { + nsString tmpText; + if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) + return PR_TRUE; + } + } + return PR_FALSE; +} + +static PRBool IsNamedAnchorNode(nsIDOMNode *aNode) +{ + if (aNode) + { + nsCOMPtr anchor = do_QueryInterface(aNode); + if (anchor) + { + nsString tmpText; + if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) + return PR_TRUE; + } + } + return PR_FALSE; +} nsHTMLEditor::nsHTMLEditor() { @@ -1941,45 +1978,48 @@ nsHTMLEditor::InsertImage(nsString& aURL, return res; } -static PRBool IsLinkNode(nsIDOMNode *aNode) -{ - if (aNode) - { - nsCOMPtr anchor = do_QueryInterface(aNode); - if (anchor) - { - nsString tmpText; - if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) - return PR_TRUE; - } - } - return PR_FALSE; -} - NS_IMETHODIMP -nsHTMLEditor::GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn) +nsHTMLEditor::GetElementOrParentByTagName(const nsString &aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn) { - if (!aNode || !aReturn ) + if (aTagName.Length() == 0 || !aNode || !aReturn ) return NS_ERROR_NULL_POINTER; + nsAutoString TagName = aTagName; + TagName.ToLowerCase(); + PRBool getLink = IsLink(TagName); + PRBool getNamedAnchor = IsNamedAnchor(TagName); + if ( getLink || getNamedAnchor) + { + TagName = "a"; + } + // default is null - no element found *aReturn = nsnull; - nsCOMPtr linkNode = aNode; + nsCOMPtr currentNode = aNode; nsCOMPtr parent; PRBool bNodeFound = PR_FALSE; while (PR_TRUE) { // Test if we have a link (an anchor with href set) - if (IsLinkNode(linkNode)) + if ( (getLink && IsLinkNode(currentNode)) || + (getNamedAnchor && IsNamedAnchorNode(currentNode)) ) { bNodeFound = PR_TRUE; break; + } else { + nsAutoString currentTagName; + aNode->GetNodeName(currentTagName); + if (currentTagName.EqualsIgnoreCase(TagName)) + { + bNodeFound = PR_TRUE; + break; + } } // Search up the parent chain // We should never fail because of root test below, but lets be safe - if (!NS_SUCCEEDED(linkNode->GetParentNode(getter_AddRefs(parent))) || !parent) + if (!NS_SUCCEEDED(currentNode->GetParentNode(getter_AddRefs(parent))) || !parent) break; // Stop searching if parent is a root (body or table cell) @@ -1988,14 +2028,14 @@ nsHTMLEditor::GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn) parent->GetNodeName(parentTagName); if (!NS_SUCCEEDED(IsRootTag(parentTagName, isRoot)) || isRoot) break; - linkNode = parent; + currentNode = parent; } if (bNodeFound) { - nsCOMPtr linkElement = do_QueryInterface(linkNode); - if (linkElement) + nsCOMPtr currentElement = do_QueryInterface(currentNode); + if (currentElement) { - *aReturn = linkElement; + *aReturn = currentElement; // Getters must addref NS_ADDREF(*aReturn); } @@ -2003,6 +2043,7 @@ nsHTMLEditor::GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn) return NS_OK; } + NS_IMETHODIMP nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { @@ -2031,7 +2072,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu nsCOMPtr selectedElement; PRBool bNodeFound = PR_FALSE; - if (TagName == "href") + if (IsLink(TagName)) { // Link tag is a special case - we return the anchor node // found for any selection that is totally within a link, @@ -2065,7 +2106,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu } #endif nsCOMPtr parentLinkOfAnchor; - res = GetParentLinkElement(anchorNode, getter_AddRefs(parentLinkOfAnchor)); + res = GetElementOrParentByTagName("href", anchorNode, getter_AddRefs(parentLinkOfAnchor)); if (NS_SUCCEEDED(res) && parentLinkOfAnchor) { if (isCollapsed) @@ -2075,14 +2116,14 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu } else if(focusNode) { // Link node must be the same for both ends of selection nsCOMPtr parentLinkOfFocus; - res = GetParentLinkElement(focusNode, getter_AddRefs(parentLinkOfFocus)); + res = GetElementOrParentByTagName("href", focusNode, getter_AddRefs(parentLinkOfFocus)); if (NS_SUCCEEDED(res) && parentLinkOfFocus == parentLinkOfAnchor) bNodeFound = PR_TRUE; } // We found a link node parent if (bNodeFound) { - // GetParentLinkElement addref'd this, so we don't need to do it here + // GetElementOrParentByTagName addref'd this, so we don't need to do it here *aReturn = parentLinkOfAnchor; return NS_OK; } @@ -2100,7 +2141,6 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu } } } - //NOTE: We will not find the link node aboveif it is the only thing selected if (!bNodeFound && !isCollapsed) // Don't bother to examine selection if it is collapsed { @@ -2156,23 +2196,11 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu // The "A" tag is a pain, // used for both link(href is set) and "Named Anchor" - if (TagName == "href" || TagName == "anchor") + nsCOMPtr selectedNode = do_QueryInterface(selectedElement); + if ( (IsLink(TagName) && IsLinkNode(selectedNode)) || + (IsNamedAnchor(TagName) && IsNamedAnchorNode(selectedNode)) ) { - // We could use GetAttribute, but might as well use anchor element directly - nsCOMPtr anchor = do_QueryInterface(selectedElement); - if (anchor) - { - nsString tmpText; - if( TagName == "href") - { - if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) - bNodeFound = PR_TRUE; - } else if (TagName == "anchor") - { - if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) - bNodeFound = PR_TRUE; - } - } + bNodeFound = PR_TRUE; } else if (TagName == domTagName) { // All other tag names are handled here bNodeFound = PR_TRUE; } @@ -2218,9 +2246,7 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* TagName.ToLowerCase(); nsAutoString realTagName; - PRBool isHREF = (TagName == "href"); - PRBool isAnchor = (TagName == "anchor"); - if (isHREF || isAnchor) + if (IsLink(TagName) || IsNamedAnchor(TagName)) { realTagName = "a"; } else { @@ -2368,13 +2394,9 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) // Named Anchor is a special case, // We collapse to insert element BEFORE the selection // For all other tags, we insert AFTER the selection - nsCOMPtr anchor = do_QueryInterface(aElement); - if (anchor) - { - nsAutoString name; - if (NS_SUCCEEDED(anchor->GetName(name)) && name.GetUnicode() && name.Length() != 0) - collapseAfter = PR_FALSE; - } + nsCOMPtr node = do_QueryInterface(aElement); + if (IsNamedAnchorNode(node)) + collapseAfter = PR_FALSE; if (collapseAfter) { diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 99f57779e91..ec7d3bf71d3 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -152,7 +152,10 @@ public: nsString& aAlt, nsString& aAlignment); NS_IMETHOD InsertList(const nsString& aListType); - NS_IMETHOD GetParentLinkElement(nsIDOMNode *aNode, nsIDOMElement** aReturn); +// MHTML helper methods + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); + + 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 InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); @@ -164,16 +167,18 @@ public: PRBool SetCaretInTableCell(nsIDOMElement* aElement); PRBool IsElementInBody(nsIDOMElement* aElement); -// MHTML helper methods - NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); - // Table Editing (implemented in EditTable.cpp) - NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn); - NS_IMETHOD GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColIndex, PRInt32 &aRowIndex); - NS_IMETHOD GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode); - NS_IMETHOD GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode); - NS_IMETHOD GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode); - NS_IMETHOD GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode); + NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex); + // Return just 1 value -- for Java Script + NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 &aRowIndex); + NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 &aColIndex); + NS_IMETHOD GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32& aCount); + NS_IMETHOD GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32& aCount); + NS_IMETHOD GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32& aCount); + NS_IMETHOD GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32& aCount); + 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); NS_IMETHOD InsertTable(); NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool aAfter); NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool aAfter); @@ -183,8 +188,7 @@ public: NS_IMETHOD DeleteTableColumn(PRInt32 aNumber); NS_IMETHOD DeleteTableRow(PRInt32 aNumber); NS_IMETHOD JoinTableCells(PRBool aCellToRight); - - + protected: // rules initialization diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index 8cab3bc2f7d..102da294846 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -177,7 +177,7 @@ public: NS_IMETHOD Indent(const nsString& aIndent)=0; NS_IMETHOD Align(const nsString& aAlign)=0; - // This should replace InsertLink and InsertImage once it is working + NS_IMETHOD GetElementOrParentByTagName(const nsString& aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn)=0; NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn)=0; NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn)=0; NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection)=0; @@ -199,6 +199,15 @@ public: NS_IMETHOD DeleteTableColumn(PRInt32 aNumber)=0; NS_IMETHOD DeleteTableRow(PRInt32 aNumber)=0; NS_IMETHOD JoinTableCells(PRBool aCellToRight)=0; + NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 &aRowIndex)=0; + NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 &aColIndex)=0; + NS_IMETHOD GetColumnCellCount(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32& aCount)=0; + NS_IMETHOD GetRowCellCount(nsIDOMElement* aTable, PRInt32 aColIndex, PRInt32& aCount)=0; + NS_IMETHOD GetMaxColumnCellCount(nsIDOMElement* aTable, PRInt32& aCount)=0; + NS_IMETHOD GetMaxRowCellCount(nsIDOMElement* aTable, PRInt32& aCount)=0; + NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell)=0; + NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell, + PRInt32& aStartRowIndex, PRInt32& aStartColIndex, PRInt32& aRowSpan, PRInt32& aColSpan)=0; // IME editing Methods NS_IMETHOD BeginComposition(void)=0; diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index 9224ffe292d..054ea3af956 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -4,6 +4,7 @@ var editorShell; var SelectionOnly=1; var FormatedWithDoctype=2; var FormatedWithoutDoctype=6; +var maxPixels = 10000; function InitEditorShell() { @@ -114,39 +115,29 @@ function ShowInputErrorMessage(message) function TrimStringLeft(string) { - firstCharIndex = 0; - len = string.length; - var result; - - while (firstCharIndex < len) { - if (!IsWhitespace(string.charAt(firstCharIndex))) break; - firstCharIndex = firstCharIndex + 1; - } - if (firstCharIndex > len) { - string = ""; - } else { - string = string.slice(firstCharIndex); - } + if(!StringExists(string)) + return ""; + if( IsWhitespace(string.charAt(0))) + string = string.replace(/\s+/, ""); return string; } function TrimStringRight(string) { - len = string.length; - if (len > 0 ) { - lastCharIndex = string.length-1; - var result; - - while (lastCharIndex > 0) { - // Find the last non-whitespace char - if (!IsWhitespace(string.charAt(lastCharIndex))) break; - lastCharIndex = lastCharIndex - 1; - } - if (lastCharIndex == 0) { - string = ""; - } else { - string = string.slice(0, lastCharIndex+1); - } + if(!StringExists(string)) + return ""; + var lastCharIndex = string.length-1; + var result; + var done = false; + while (!done && lastCharIndex >= 0) { + // Find the last non-whitespace char + if (!IsWhitespace(string.charAt(lastCharIndex))) break; + lastCharIndex--; + } + if (lastCharIndex < 0) { + string = ""; + } else { + string = string.slice(0, lastCharIndex+1); } return string; } @@ -159,7 +150,7 @@ function TrimString(string) function IsWhitespace(character) { - result = character.match(/\s/); + var result = character.match(/\s/); if (result == null) return false; return true; @@ -168,9 +159,9 @@ function IsWhitespace(character) function TruncateStringAtWordEnd(string, maxLength, addEllipses) { // We assume they probably don't want whitespace at the beginning - string = TrimStringLeft(string); + var string = TrimStringLeft(string); - len = string.length; + var len = string.length; if (len > maxLength) { // We need to truncate the string var max; @@ -194,7 +185,7 @@ function TruncateStringAtWordEnd(string, maxLength, addEllipses) dump("Skip to first whitspace from end: "); while (lastCharIndex > 0) { - lastChar = string.charAt(lastCharIndex); + var lastChar = string.charAt(lastCharIndex); dump(lastChar); if (IsWhitespace(lastChar)) break; lastCharIndex = lastCharIndex -1; @@ -328,7 +319,9 @@ function forceInteger(elementID) var stringIn = editfield.value; var pat = /\D/g; - + // THIS DOESN'T WORK ON WINDOWS WITH NATIVE WIDGET + // It causes the caret to reposition to the beginning, + // so characters are inserted backwards! editfield.value = stringIn.replace(pat, ""); } diff --git a/mozilla/editor/ui/dialogs/content/EdHLineProps.js b/mozilla/editor/ui/dialogs/content/EdHLineProps.js index 730f893c457..acad9d489cc 100644 --- a/mozilla/editor/ui/dialogs/content/EdHLineProps.js +++ b/mozilla/editor/ui/dialogs/content/EdHLineProps.js @@ -3,7 +3,6 @@ var tagName = "hr"; var hLineElement; var tempLineElement; var percentChar = ""; -var maxPixels = 10000; var shading = true; // dialog initialization code diff --git a/mozilla/editor/ui/dialogs/content/EdInsertTable.js b/mozilla/editor/ui/dialogs/content/EdInsertTable.js index 6d900c4baf0..c089b9316e2 100644 --- a/mozilla/editor/ui/dialogs/content/EdInsertTable.js +++ b/mozilla/editor/ui/dialogs/content/EdInsertTable.js @@ -15,6 +15,7 @@ function Startup() return; dump("EditoreditorShell found for Insert Table dialog\n"); + dump(tagName+" = InsertTable tagName\n"); tableElement = editorShell.CreateElementWithDefaults(tagName); if(!tableElement) { @@ -33,7 +34,7 @@ function Startup() // Get the width attribute of the element, stripping out "%" // This sets contents of button text and "percentChar" variable dialog.widthInput.value = InitPixelOrPercentPopupButton(tableElement, "width", "pixelOrPercentButton"); - dialog.borderInput.value = tableElement.getAttribute("border"); + dialog.borderInput.value = 5; //tableElement.getAttribute("border"); // Set default number to 1 row, 2 columns: dialog.rowsInput.value = 1; @@ -74,7 +75,34 @@ function onOK() } } } + // Set attributes: these may be empty strings + borderText = TrimString(dialog.borderInput.value); + if (StringExists(borderText)) { + // Set the other attributes on the table + if (ValidateNumberString(borderText, 0, maxPixels)) + tableElement.setAttribute("border", borderText); + } + + widthText = TrimString(dialog.widthInput.value); + if (StringExists(widthText)) { + var maxLimit; + if (percentChar == "%") { + maxLimit = 100; + } else { + // Upper limit when using pixels + maxLimit = maxPixels; + } + + widthText = ValidateNumberString(dialog.widthInput.value, 1, maxLimit); + if (widthText != "") { + widthText += percentChar; + dump("Table Width="+widthText+"\n"); + tableElement.setAttribute("width", widthText); + } + } + // Don't delete selected text when inserting editorShell.InsertElement(tableElement, false); + window.close(); } diff --git a/mozilla/editor/ui/dialogs/content/EdInsertTable.xul b/mozilla/editor/ui/dialogs/content/EdInsertTable.xul index 30f814d525e..596a5ed45dc 100644 --- a/mozilla/editor/ui/dialogs/content/EdInsertTable.xul +++ b/mozilla/editor/ui/dialogs/content/EdInsertTable.xul @@ -79,8 +79,8 @@ - + +