Editor: Add Insert Link and Image
git-svn-id: svn://10.0.0.236/trunk@25455 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
99d79287ff
commit
dd6ab917f7
@ -322,17 +322,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
||||
if (mEditor)
|
||||
{
|
||||
nsString nsstr ("<b>This is bold <em>and emphasized</em></b>");
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
nsresult res = NS_NewStringInputStream(getter_AddRefs(supp),
|
||||
nsstr);
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> stream = do_QueryInterface(supp);
|
||||
res = mEditor->Insert(stream);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
printf("nsTextEditor::Insert(stream) failed\n");
|
||||
}
|
||||
else printf("Couldn't create the input stream\n");
|
||||
nsresult res = mEditor->Insert(nsstr);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
printf("nsTextEditor::Insert(string) failed\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -25,6 +25,8 @@
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsEditorCID.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
@ -311,9 +313,9 @@ NS_IMETHODIMP nsHTMLEditor::Paste()
|
||||
return nsTextEditor::Paste();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
|
||||
NS_IMETHODIMP nsHTMLEditor::Insert(nsString& aInputString)
|
||||
{
|
||||
return nsTextEditor::Insert(aInputStream);
|
||||
return nsTextEditor::Insert(aInputString);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::OutputText(nsString& aOutputString)
|
||||
@ -331,3 +333,149 @@ NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsString& aOutputString)
|
||||
//
|
||||
// Note: Table Editing methods are implemented in EditTable.cpp
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertLink(nsString& aURL)
|
||||
{
|
||||
nsresult res = nsEditor::BeginTransaction();
|
||||
|
||||
// Find out if the selection is collapsed:
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
res = GetSelection(getter_AddRefs(selection));
|
||||
if (!NS_SUCCEEDED(res) || !selection)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Can't get selection!");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
PRBool isCollapsed;
|
||||
res = selection->IsCollapsed(&isCollapsed);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
isCollapsed = PR_TRUE;
|
||||
|
||||
// Temporary: we need to save the contents of the selection,
|
||||
// then insert them back in as the child of the newly created
|
||||
// anchor node in order to put the link around the selection.
|
||||
// This will require copying the selection into a document fragment,
|
||||
// then splicing the document fragment back into the tree after the
|
||||
// new anchor node has been put in place. As a temporary solution,
|
||||
// Copy/Paste does this for us in the text case
|
||||
// (and eventually in all cases).
|
||||
if (!isCollapsed)
|
||||
(void)Copy();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode;
|
||||
nsAutoString tag("A");
|
||||
res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||
if (!NS_SUCCEEDED(res) || !newNode)
|
||||
return res;
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor (do_QueryInterface(newNode));
|
||||
if (!anchor)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Not an anchor element\n");
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
res = anchor->SetHref(aURL);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("SetHref failed");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
// Set the selection to the node we just inserted:
|
||||
res = GetSelection(getter_AddRefs(selection));
|
||||
if (!NS_SUCCEEDED(res) || !selection)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Can't get selection!");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
res = selection->Collapse(newNode, 0);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Couldn't collapse");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
// If we weren't collapsed, paste the old selection back in under the link:
|
||||
if (!isCollapsed)
|
||||
(void)Paste();
|
||||
// Otherwise (we were collapsed) insert some bogus text in
|
||||
// so the link will be visible
|
||||
else
|
||||
{
|
||||
nsString link("[***]");
|
||||
(void) InsertText(link); // ignore return value -- we don't care
|
||||
}
|
||||
|
||||
nsEditor::EndTransaction(); // don't return this result!
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertImage(nsString& aURL,
|
||||
nsString& aWidth, nsString& aHeight,
|
||||
nsString& aHspace, nsString& aVspace,
|
||||
nsString& aBorder,
|
||||
nsString& aAlt,
|
||||
nsString& aAlignment)
|
||||
{
|
||||
nsresult res = nsEditor::BeginTransaction();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode;
|
||||
nsAutoString tag("IMG");
|
||||
res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||
if (!NS_SUCCEEDED(res) || !newNode)
|
||||
return res;
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image (do_QueryInterface(newNode));
|
||||
if (!image)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Not an image element\n");
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
res = image->SetSrc(aURL);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetWidth(aWidth);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetHeight(aHeight);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetHspace(aHspace);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetVspace(aVspace);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetBorder(aBorder);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetAlt(aAlt);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetAlign(aAlignment);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
|
||||
nsEditor::EndTransaction(); // don't return this result!
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -84,12 +84,18 @@ public:
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
// Input/Output
|
||||
NS_IMETHOD Insert(nsIInputStream *aInputStream);
|
||||
NS_IMETHOD Insert(nsString& aInputString);
|
||||
NS_IMETHOD OutputText(nsString& aOutputString);
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString);
|
||||
|
||||
//=====================================
|
||||
// HTML Editing methods
|
||||
NS_IMETHOD InsertLink(nsString& aURL);
|
||||
NS_IMETHOD InsertImage(nsString& aURL,
|
||||
nsString& aWidth, nsString& aHeight,
|
||||
nsString& aHspace, nsString& aVspace,
|
||||
nsString& aBorder,
|
||||
nsString& aAlt, nsString& aAlignment);
|
||||
|
||||
// Table Editing (implemented in EditTable.cpp)
|
||||
NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn);
|
||||
|
||||
@ -64,7 +64,7 @@ PRBool nsTextEditRules::IsEditable(nsIDOMNode *aNode)
|
||||
{
|
||||
nsAutoString att(kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
nsresult result = element->GetAttribute(att, val);
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(kMOZEditorBogusNodeValue)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
@ -392,7 +392,7 @@ nsTextEditRules:: DidUndo(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
nsAutoString att(kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
nsresult result = element->GetAttribute(att, val);
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(kMOZEditorBogusNodeValue)) {
|
||||
mBogusNode = do_QueryInterface(element);
|
||||
}
|
||||
@ -438,7 +438,7 @@ nsTextEditRules::DidRedo(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
nsAutoString att(kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
nsresult result = element->GetAttribute(att, val);
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(kMOZEditorBogusNodeValue)) {
|
||||
mBogusNode = do_QueryInterface(element);
|
||||
}
|
||||
|
||||
@ -625,8 +625,9 @@ NS_IMETHODIMP nsTextEditor::Paste()
|
||||
return nsEditor::Paste();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Insert(nsIInputStream *aInputStream)
|
||||
NS_IMETHODIMP nsTextEditor::Insert(nsString& aInputString)
|
||||
{
|
||||
printf("nsTextEditor::Insert not yet implemented\n");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ public:
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
// Input/Output
|
||||
NS_IMETHOD Insert(nsIInputStream *aInputStream);
|
||||
NS_IMETHOD Insert(nsString& aInputString);
|
||||
NS_IMETHOD OutputText(nsString& aOutputString);
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString);
|
||||
|
||||
|
||||
@ -25,6 +25,8 @@
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsEditorCID.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
@ -311,9 +313,9 @@ NS_IMETHODIMP nsHTMLEditor::Paste()
|
||||
return nsTextEditor::Paste();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
|
||||
NS_IMETHODIMP nsHTMLEditor::Insert(nsString& aInputString)
|
||||
{
|
||||
return nsTextEditor::Insert(aInputStream);
|
||||
return nsTextEditor::Insert(aInputString);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::OutputText(nsString& aOutputString)
|
||||
@ -331,3 +333,149 @@ NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsString& aOutputString)
|
||||
//
|
||||
// Note: Table Editing methods are implemented in EditTable.cpp
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertLink(nsString& aURL)
|
||||
{
|
||||
nsresult res = nsEditor::BeginTransaction();
|
||||
|
||||
// Find out if the selection is collapsed:
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
res = GetSelection(getter_AddRefs(selection));
|
||||
if (!NS_SUCCEEDED(res) || !selection)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Can't get selection!");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
PRBool isCollapsed;
|
||||
res = selection->IsCollapsed(&isCollapsed);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
isCollapsed = PR_TRUE;
|
||||
|
||||
// Temporary: we need to save the contents of the selection,
|
||||
// then insert them back in as the child of the newly created
|
||||
// anchor node in order to put the link around the selection.
|
||||
// This will require copying the selection into a document fragment,
|
||||
// then splicing the document fragment back into the tree after the
|
||||
// new anchor node has been put in place. As a temporary solution,
|
||||
// Copy/Paste does this for us in the text case
|
||||
// (and eventually in all cases).
|
||||
if (!isCollapsed)
|
||||
(void)Copy();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode;
|
||||
nsAutoString tag("A");
|
||||
res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||
if (!NS_SUCCEEDED(res) || !newNode)
|
||||
return res;
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor (do_QueryInterface(newNode));
|
||||
if (!anchor)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Not an anchor element\n");
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
res = anchor->SetHref(aURL);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("SetHref failed");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
// Set the selection to the node we just inserted:
|
||||
res = GetSelection(getter_AddRefs(selection));
|
||||
if (!NS_SUCCEEDED(res) || !selection)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Can't get selection!");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
res = selection->Collapse(newNode, 0);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Couldn't collapse");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
// If we weren't collapsed, paste the old selection back in under the link:
|
||||
if (!isCollapsed)
|
||||
(void)Paste();
|
||||
// Otherwise (we were collapsed) insert some bogus text in
|
||||
// so the link will be visible
|
||||
else
|
||||
{
|
||||
nsString link("[***]");
|
||||
(void) InsertText(link); // ignore return value -- we don't care
|
||||
}
|
||||
|
||||
nsEditor::EndTransaction(); // don't return this result!
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertImage(nsString& aURL,
|
||||
nsString& aWidth, nsString& aHeight,
|
||||
nsString& aHspace, nsString& aVspace,
|
||||
nsString& aBorder,
|
||||
nsString& aAlt,
|
||||
nsString& aAlignment)
|
||||
{
|
||||
nsresult res = nsEditor::BeginTransaction();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode;
|
||||
nsAutoString tag("IMG");
|
||||
res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||
if (!NS_SUCCEEDED(res) || !newNode)
|
||||
return res;
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image (do_QueryInterface(newNode));
|
||||
if (!image)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Not an image element\n");
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
res = image->SetSrc(aURL);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetWidth(aWidth);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetHeight(aHeight);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetHspace(aHspace);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetVspace(aVspace);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetBorder(aBorder);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetAlt(aAlt);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
res = image->SetAlign(aAlignment);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
return res;
|
||||
|
||||
nsEditor::EndTransaction(); // don't return this result!
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -84,12 +84,18 @@ public:
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
// Input/Output
|
||||
NS_IMETHOD Insert(nsIInputStream *aInputStream);
|
||||
NS_IMETHOD Insert(nsString& aInputString);
|
||||
NS_IMETHOD OutputText(nsString& aOutputString);
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString);
|
||||
|
||||
//=====================================
|
||||
// HTML Editing methods
|
||||
NS_IMETHOD InsertLink(nsString& aURL);
|
||||
NS_IMETHOD InsertImage(nsString& aURL,
|
||||
nsString& aWidth, nsString& aHeight,
|
||||
nsString& aHspace, nsString& aVspace,
|
||||
nsString& aBorder,
|
||||
nsString& aAlt, nsString& aAlignment);
|
||||
|
||||
// Table Editing (implemented in EditTable.cpp)
|
||||
NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn);
|
||||
|
||||
@ -322,17 +322,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
||||
if (mEditor)
|
||||
{
|
||||
nsString nsstr ("<b>This is bold <em>and emphasized</em></b>");
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
nsresult res = NS_NewStringInputStream(getter_AddRefs(supp),
|
||||
nsstr);
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> stream = do_QueryInterface(supp);
|
||||
res = mEditor->Insert(stream);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
printf("nsTextEditor::Insert(stream) failed\n");
|
||||
}
|
||||
else printf("Couldn't create the input stream\n");
|
||||
nsresult res = mEditor->Insert(nsstr);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
printf("nsTextEditor::Insert(string) failed\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -64,7 +64,7 @@ PRBool nsTextEditRules::IsEditable(nsIDOMNode *aNode)
|
||||
{
|
||||
nsAutoString att(kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
nsresult result = element->GetAttribute(att, val);
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(kMOZEditorBogusNodeValue)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
@ -392,7 +392,7 @@ nsTextEditRules:: DidUndo(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
nsAutoString att(kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
nsresult result = element->GetAttribute(att, val);
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(kMOZEditorBogusNodeValue)) {
|
||||
mBogusNode = do_QueryInterface(element);
|
||||
}
|
||||
@ -438,7 +438,7 @@ nsTextEditRules::DidRedo(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
nsAutoString att(kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
nsresult result = element->GetAttribute(att, val);
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(kMOZEditorBogusNodeValue)) {
|
||||
mBogusNode = do_QueryInterface(element);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public:
|
||||
NS_IMETHOD Copy()=0;
|
||||
NS_IMETHOD Paste()=0;
|
||||
|
||||
NS_IMETHOD Insert(nsIInputStream *aInputStream)=0;
|
||||
NS_IMETHOD Insert(nsString &aInputString)=0;
|
||||
NS_IMETHOD OutputText(nsString& aOutputString)=0;
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString)=0;
|
||||
|
||||
@ -92,6 +92,12 @@ public:
|
||||
* trigger off of ContentChanged notifications.
|
||||
*/
|
||||
|
||||
NS_IMETHOD InsertLink(nsString& aURL)=0;
|
||||
NS_IMETHOD InsertImage(nsString& aURL,
|
||||
nsString& aWidth, nsString& aHeight,
|
||||
nsString& aHspace, nsString& aVspace,
|
||||
nsString& aBorder,
|
||||
nsString& aAlt, nsString& aAlignment)=0;
|
||||
|
||||
// Table editing Methods
|
||||
NS_IMETHOD InsertTable()=0;
|
||||
|
||||
@ -254,7 +254,7 @@ public:
|
||||
|
||||
// Input/Output
|
||||
// nsString will be a stream, as soon as I can figure out what kind of stream we should be using
|
||||
NS_IMETHOD Insert(nsIInputStream *aInputStream)=0;
|
||||
NS_IMETHOD Insert(nsString& aInputString)=0;
|
||||
NS_IMETHOD OutputText(nsString& aOutputString)=0;
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString)=0;
|
||||
|
||||
|
||||
@ -21,6 +21,9 @@ interface EditorAppCore : BaseAppCore
|
||||
void showClipboard();
|
||||
|
||||
void insertText(in wstring textToInsert);
|
||||
|
||||
void insertLink();
|
||||
void insertImage();
|
||||
|
||||
void exit();
|
||||
|
||||
|
||||
@ -57,6 +57,10 @@ public:
|
||||
|
||||
NS_IMETHOD InsertText(const nsString& aTextToInsert)=0;
|
||||
|
||||
NS_IMETHOD InsertLink()=0;
|
||||
|
||||
NS_IMETHOD InsertImage()=0;
|
||||
|
||||
NS_IMETHOD Exit()=0;
|
||||
|
||||
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin)=0;
|
||||
@ -79,6 +83,8 @@ public:
|
||||
NS_IMETHOD SelectAll(); \
|
||||
NS_IMETHOD ShowClipboard(); \
|
||||
NS_IMETHOD InsertText(const nsString& aTextToInsert); \
|
||||
NS_IMETHOD InsertLink(); \
|
||||
NS_IMETHOD InsertImage(); \
|
||||
NS_IMETHOD Exit(); \
|
||||
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \
|
||||
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \
|
||||
@ -98,6 +104,8 @@ public:
|
||||
NS_IMETHOD SelectAll() { return _to##SelectAll(); } \
|
||||
NS_IMETHOD ShowClipboard() { return _to##ShowClipboard(); } \
|
||||
NS_IMETHOD InsertText(const nsString& aTextToInsert) { return _to##InsertText(aTextToInsert); } \
|
||||
NS_IMETHOD InsertLink() { return _to##InsertLink(); } \
|
||||
NS_IMETHOD InsertImage() { return _to##InsertImage(); } \
|
||||
NS_IMETHOD Exit() { return _to##Exit(); } \
|
||||
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to##SetToolbarWindow(aWin); } \
|
||||
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to##SetContentWindow(aWin); } \
|
||||
|
||||
@ -482,9 +482,9 @@ newWindow(char* urlName) {
|
||||
nsString controllerCID;
|
||||
|
||||
char * urlstr=nsnull;
|
||||
char * progname = nsnull;
|
||||
char * width=nsnull, *height=nsnull;
|
||||
char * iconic_state=nsnull;
|
||||
//char * progname = nsnull;
|
||||
//char * width=nsnull, *height=nsnull;
|
||||
//char * iconic_state=nsnull;
|
||||
|
||||
nsIAppShellService* appShell = nsnull;
|
||||
urlstr = urlName;
|
||||
@ -730,6 +730,35 @@ nsEditorAppCore::GetContentsAsHTML(nsString& aContentsAsHTML)
|
||||
return err;
|
||||
}
|
||||
|
||||
// Pop up the link dialog once we have dialogs ... for now, hardwire it
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::InsertLink()
|
||||
{
|
||||
if (!mEditor)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsString tmpString ("http://www.mozilla.org/editor/");
|
||||
return mEditor->InsertLink(tmpString);
|
||||
}
|
||||
|
||||
// Pop up the image dialog once we have dialogs ... for now, hardwire it
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::InsertImage()
|
||||
{
|
||||
if (!mEditor)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsString url ("http://www.mozilla.org/editor/images/pensplat.gif");
|
||||
nsString width("100");
|
||||
nsString height("138");
|
||||
nsString hspace("0");
|
||||
nsString border("1");
|
||||
nsString alt ("[pen splat]");
|
||||
nsString align ("left");
|
||||
return mEditor->InsertImage(url, width, height, hspace, hspace, border,
|
||||
alt, align);
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
void nsEditorAppCore::SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName)
|
||||
{
|
||||
|
||||
@ -79,6 +79,9 @@ class nsEditorAppCore : public nsBaseAppCore,
|
||||
NS_IMETHOD ShowClipboard();
|
||||
|
||||
NS_IMETHOD InsertText(const nsString& textToInsert);
|
||||
|
||||
NS_IMETHOD InsertLink();
|
||||
NS_IMETHOD InsertImage();
|
||||
|
||||
NS_IMETHOD NewWindow();
|
||||
NS_IMETHOD PrintPreview();
|
||||
|
||||
@ -464,6 +464,72 @@ EditorAppCoreInsertText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method InsertLink
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
EditorAppCoreInsertLink(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->InsertLink()) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function insertLink requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method InsertImage
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
EditorAppCoreInsertImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->InsertImage()) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function insertImage requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Exit
|
||||
//
|
||||
@ -666,6 +732,8 @@ static JSFunctionSpec EditorAppCoreMethods[] =
|
||||
{"selectAll", EditorAppCoreSelectAll, 0},
|
||||
{"showClipboard", EditorAppCoreShowClipboard, 0},
|
||||
{"insertText", EditorAppCoreInsertText, 1},
|
||||
{"insertLink", EditorAppCoreInsertLink, 0},
|
||||
{"insertImage", EditorAppCoreInsertImage, 0},
|
||||
{"exit", EditorAppCoreExit, 0},
|
||||
{"setToolbarWindow", EditorAppCoreSetToolbarWindow, 1},
|
||||
{"setContentWindow", EditorAppCoreSetContentWindow, 1},
|
||||
|
||||
@ -180,6 +180,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
function EditorInsertLink()
|
||||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
dump("Inserting link\n");
|
||||
appCore.insertLink();
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
}
|
||||
|
||||
function EditorInsertImage()
|
||||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
dump("Inserting image\n");
|
||||
appCore.insertImage();
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
}
|
||||
|
||||
function EditorExit()
|
||||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
@ -243,9 +265,9 @@
|
||||
</menu>
|
||||
|
||||
<menu name="Insert">
|
||||
<menuitem name="Link..." onclick=""/>
|
||||
<menuitem name="Link..." onclick="EditorInsertLink()"/>
|
||||
<menuitem name="Target..." onclick=""/>
|
||||
<menuitem name="Image..." onclick=""/>
|
||||
<menuitem name="Image..." onclick="EditorInsertImage()"/>
|
||||
<menuitem name="Horizontal Line" onclick=""/>
|
||||
<menuitem name="Table" onclick=""/>
|
||||
<menuitem name="HTML Tag..." onclick=""/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user