diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 8493505f9d4..759a59e0775 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -2026,6 +2026,30 @@ nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement) return result; } +NS_IMETHODIMP +nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray) +{ + if (!aObjectArray) + return NS_ERROR_NULL_POINTER; + + nsresult result; + + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetEmbeddedObjects(aObjectArray); + } + break; + + default: + result = NS_NOINTERFACE; + } + return result; +} + NS_IMETHODIMP nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) { diff --git a/mozilla/editor/base/nsEditorShell.h b/mozilla/editor/base/nsEditorShell.h index 519ba64d3de..e2dc7dc7a3c 100644 --- a/mozilla/editor/base/nsEditorShell.h +++ b/mozilla/editor/base/nsEditorShell.h @@ -52,7 +52,7 @@ class nsIPresShell; class nsIHTMLEditor; class nsITextEditor; class nsIOutputStream; - +class nsISupportsArray; #define NS_EDITORAPPCORE_CID \ @@ -147,7 +147,10 @@ class nsEditorShell : public nsIEditorShell, NS_IMETHOD SelectElement(nsIDOMElement *element); NS_IMETHOD SetSelectionAfterElement(nsIDOMElement *element); - /* void SetParagraphFormat (in string value); */ + /* Get list of embedded objects, e.g. for mail compose */ + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray **aObjectArray); + + /* void SetParagraphFormat (in string value); */ NS_IMETHOD SetParagraphFormat(PRUnichar *value); NS_IMETHOD GetParagraphFormat(PRUnichar * *aParagraphFormat); @@ -249,12 +252,12 @@ class nsEditorShell : public nsIEditorShell, #endif // NECKO protected: - nsCOMPtr mSpellChecker; - nsStringArray mSuggestedWordList; - PRInt32 mSuggestedWordIndex; - NS_IMETHOD DeleteSuggestedWordList(); - nsStringArray mDictionaryList; - PRInt32 mDictionaryIndex; + nsIDOMWindow *mToolbarWindow; // weak reference + nsIDOMWindow *mContentWindow; // weak reference + + nsIWebShellWindow *mWebShellWin; // weak reference + nsIWebShell *mWebShell; // weak reference + nsIWebShell *mContentAreaWebShell; // weak reference typedef enum { eUninitializedEditorType = 0, @@ -278,13 +281,6 @@ class nsEditorShell : public nsIEditorShell, nsString mEnableScript; nsString mDisableScript; - nsIDOMWindow *mToolbarWindow; // weak reference - nsIDOMWindow *mContentWindow; // weak reference - - nsIWebShellWindow *mWebShellWin; // weak reference - nsIWebShell *mWebShell; // weak reference - nsIWebShell *mContentAreaWebShell; // weak reference - EEditorType mEditorType; nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased) nsCOMPtr mEditor; // this can be either an HTML or plain text (or other?) editor @@ -296,6 +292,13 @@ class nsEditorShell : public nsIEditorShell, #endif PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while + + nsCOMPtr mSpellChecker; + nsStringArray mSuggestedWordList; + PRInt32 mSuggestedWordIndex; + NS_IMETHOD DeleteSuggestedWordList(); + nsStringArray mDictionaryList; + PRInt32 mDictionaryIndex; }; #endif // nsEditorAppCore_h___ diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 1463724c958..7c2791781ff 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -2685,7 +2685,7 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) } NS_IMETHODIMP -nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) +nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) { if (!aNodeList) return NS_ERROR_NULL_POINTER; @@ -2695,9 +2695,10 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) #else nsresult res; - res = NS_NewISupportsArray(&aNodeList); - if (NS_FAILED(res)) + res = NS_NewISupportsArray(aNodeList); + if (NS_FAILED(res) || !*aNodeList) return res; + //NS_ADDREF(*aNodeList); nsCOMPtr iter; res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull, @@ -2722,11 +2723,12 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) iter->Init(rootContent); // loop through the content iterator for each content node - nsCOMPtr content; - res = iter->CurrentNode(getter_AddRefs(content)); - while (NS_COMFALSE == iter->IsDone()) { + nsCOMPtr content; + res = iter->CurrentNode(getter_AddRefs(content)); + if (NS_FAILED(res)) + break; nsCOMPtr node (do_QueryInterface(content)); if (node) { @@ -2736,7 +2738,11 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) // See if it's an image or an embed if (tagName == "img" || tagName == "embed") - aNodeList->AppendElement(node); + (*aNodeList)->AppendElement(node); + else if (tagName == "a") + { + // XXX Only include links if they're links to file: URLs + } } iter->Next(); } diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index b393e0cf2ef..9557bf36c25 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -165,7 +165,7 @@ public: NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); // MHTML helper methods - NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aNodeList); + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); // Table Editing (implemented in EditTable.cpp) NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn); diff --git a/mozilla/editor/base/nsJSEditorLog.cpp b/mozilla/editor/base/nsJSEditorLog.cpp index 6e9d3e4e6b9..94f0bac4658 100644 --- a/mozilla/editor/base/nsJSEditorLog.cpp +++ b/mozilla/editor/base/nsJSEditorLog.cpp @@ -761,7 +761,7 @@ nsJSEditorLog::SetCaretAfterElement(nsIDOMElement* aElement) } NS_IMETHODIMP -nsJSEditorLog::GetEmbeddedObjects(nsISupportsArray* aNodeList) +nsJSEditorLog::GetEmbeddedObjects(nsISupportsArray** aNodeList) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/editor/base/nsJSEditorLog.h b/mozilla/editor/base/nsJSEditorLog.h index e3e2de4838f..2d13e6ec2d4 100644 --- a/mozilla/editor/base/nsJSEditorLog.h +++ b/mozilla/editor/base/nsJSEditorLog.h @@ -132,7 +132,7 @@ public: NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); NS_IMETHOD SelectElement(nsIDOMElement* aElement); NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); - NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aNodeList); + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); 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 8493505f9d4..759a59e0775 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -2026,6 +2026,30 @@ nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement) return result; } +NS_IMETHODIMP +nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray) +{ + if (!aObjectArray) + return NS_ERROR_NULL_POINTER; + + nsresult result; + + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + result = htmlEditor->GetEmbeddedObjects(aObjectArray); + } + break; + + default: + result = NS_NOINTERFACE; + } + return result; +} + NS_IMETHODIMP nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) { diff --git a/mozilla/editor/composer/src/nsEditorShell.h b/mozilla/editor/composer/src/nsEditorShell.h index 519ba64d3de..e2dc7dc7a3c 100644 --- a/mozilla/editor/composer/src/nsEditorShell.h +++ b/mozilla/editor/composer/src/nsEditorShell.h @@ -52,7 +52,7 @@ class nsIPresShell; class nsIHTMLEditor; class nsITextEditor; class nsIOutputStream; - +class nsISupportsArray; #define NS_EDITORAPPCORE_CID \ @@ -147,7 +147,10 @@ class nsEditorShell : public nsIEditorShell, NS_IMETHOD SelectElement(nsIDOMElement *element); NS_IMETHOD SetSelectionAfterElement(nsIDOMElement *element); - /* void SetParagraphFormat (in string value); */ + /* Get list of embedded objects, e.g. for mail compose */ + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray **aObjectArray); + + /* void SetParagraphFormat (in string value); */ NS_IMETHOD SetParagraphFormat(PRUnichar *value); NS_IMETHOD GetParagraphFormat(PRUnichar * *aParagraphFormat); @@ -249,12 +252,12 @@ class nsEditorShell : public nsIEditorShell, #endif // NECKO protected: - nsCOMPtr mSpellChecker; - nsStringArray mSuggestedWordList; - PRInt32 mSuggestedWordIndex; - NS_IMETHOD DeleteSuggestedWordList(); - nsStringArray mDictionaryList; - PRInt32 mDictionaryIndex; + nsIDOMWindow *mToolbarWindow; // weak reference + nsIDOMWindow *mContentWindow; // weak reference + + nsIWebShellWindow *mWebShellWin; // weak reference + nsIWebShell *mWebShell; // weak reference + nsIWebShell *mContentAreaWebShell; // weak reference typedef enum { eUninitializedEditorType = 0, @@ -278,13 +281,6 @@ class nsEditorShell : public nsIEditorShell, nsString mEnableScript; nsString mDisableScript; - nsIDOMWindow *mToolbarWindow; // weak reference - nsIDOMWindow *mContentWindow; // weak reference - - nsIWebShellWindow *mWebShellWin; // weak reference - nsIWebShell *mWebShell; // weak reference - nsIWebShell *mContentAreaWebShell; // weak reference - EEditorType mEditorType; nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased) nsCOMPtr mEditor; // this can be either an HTML or plain text (or other?) editor @@ -296,6 +292,13 @@ class nsEditorShell : public nsIEditorShell, #endif PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while + + nsCOMPtr mSpellChecker; + nsStringArray mSuggestedWordList; + PRInt32 mSuggestedWordIndex; + NS_IMETHOD DeleteSuggestedWordList(); + nsStringArray mDictionaryList; + PRInt32 mDictionaryIndex; }; #endif // nsEditorAppCore_h___ diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index ebdddc64535..84ea03a621b 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -19,6 +19,7 @@ #include "nsISupports.idl" #include "domstubs.idl" #include "nsIFileSpec.idl" +#include "nsISupportsArray.idl" %{C++ @@ -104,6 +105,9 @@ interface nsIEditorShell : nsISupports void SelectElement(in nsIDOMElement element); void SetSelectionAfterElement(in nsIDOMElement element); + /* Get list of embedded objects, e.g. for mail compose */ + nsISupportsArray GetEmbeddedObjects(); + /* Formatting */ void SetTextProperty(in wstring prop, in wstring attr, in wstring value); void RemoveTextProperty(in wstring prop, in wstring attr); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 1463724c958..7c2791781ff 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -2685,7 +2685,7 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) } NS_IMETHODIMP -nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) +nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) { if (!aNodeList) return NS_ERROR_NULL_POINTER; @@ -2695,9 +2695,10 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) #else nsresult res; - res = NS_NewISupportsArray(&aNodeList); - if (NS_FAILED(res)) + res = NS_NewISupportsArray(aNodeList); + if (NS_FAILED(res) || !*aNodeList) return res; + //NS_ADDREF(*aNodeList); nsCOMPtr iter; res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull, @@ -2722,11 +2723,12 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) iter->Init(rootContent); // loop through the content iterator for each content node - nsCOMPtr content; - res = iter->CurrentNode(getter_AddRefs(content)); - while (NS_COMFALSE == iter->IsDone()) { + nsCOMPtr content; + res = iter->CurrentNode(getter_AddRefs(content)); + if (NS_FAILED(res)) + break; nsCOMPtr node (do_QueryInterface(content)); if (node) { @@ -2736,7 +2738,11 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray* aNodeList) // See if it's an image or an embed if (tagName == "img" || tagName == "embed") - aNodeList->AppendElement(node); + (*aNodeList)->AppendElement(node); + else if (tagName == "a") + { + // XXX Only include links if they're links to file: URLs + } } iter->Next(); } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index b393e0cf2ef..9557bf36c25 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -165,7 +165,7 @@ public: NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); // MHTML helper methods - NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aNodeList); + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); // Table Editing (implemented in EditTable.cpp) NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn); diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index 58d0ba2ae42..8cab3bc2f7d 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -187,7 +187,7 @@ public: NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement)=0; // MHTML helper methods - NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aNodeList)=0; + NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList)=0; // Table editing Methods NS_IMETHOD InsertTable()=0; diff --git a/mozilla/editor/ui/composer/content/EditorAppShell.xul b/mozilla/editor/ui/composer/content/EditorAppShell.xul index c707e01de6b..94794710583 100644 --- a/mozilla/editor/ui/composer/content/EditorAppShell.xul +++ b/mozilla/editor/ui/composer/content/EditorAppShell.xul @@ -190,6 +190,7 @@ + @@ -481,6 +482,7 @@ + diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index 1d291c128b7..969f41f1f08 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -718,6 +718,13 @@ function EditorTestSelection() dump(output + "\n\n"); } +function EditorShowEmbeddedObjects() +{ + dump("\nEmbedded Objects:\n"); + var objectArray = editorShell.GetEmbeddedObjects(); + dump(objectArray.length + " embedded objects\n"); +} + function EditorUnitTests() { dump("Running Unit Tests\n");