зеркало из https://github.com/mozilla/pjs.git
Add support for getting text or HTML through a readonly properly on the EditorAppCore. Added attributes to .idl file, regenerated .h and .cpp with idlc. Simplified toolbar in the .xul file.
This commit is contained in:
Родитель
772a1e622d
Коммит
b6459a33d0
|
@ -2,11 +2,15 @@ interface EditorAppCore : BaseAppCore
|
|||
{
|
||||
/* IID: { 0x9afff72b, 0xca9a, 0x11d2, \
|
||||
{0x96, 0xc9, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56}} */
|
||||
|
||||
|
||||
readonly attribute wstring contentsAsText;
|
||||
readonly attribute wstring contentsAsHTML;
|
||||
|
||||
void EditorAppCore();
|
||||
|
||||
void setAttribute(in wstring attr, in wstring value);
|
||||
void undo();
|
||||
void redo();
|
||||
void exit();
|
||||
|
||||
void setToolbarWindow(in Window win);
|
||||
|
@ -14,4 +18,3 @@ interface EditorAppCore : BaseAppCore
|
|||
void setWebShellWindow(in Window win);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -35,6 +35,10 @@ class nsIDOMEditorAppCore : public nsIDOMBaseAppCore {
|
|||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMEDITORAPPCORE_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetContentsAsText(nsString& aContentsAsText)=0;
|
||||
|
||||
NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML)=0;
|
||||
|
||||
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue)=0;
|
||||
|
||||
NS_IMETHOD Undo()=0;
|
||||
|
@ -52,6 +56,8 @@ public:
|
|||
|
||||
|
||||
#define NS_DECL_IDOMEDITORAPPCORE \
|
||||
NS_IMETHOD GetContentsAsText(nsString& aContentsAsText); \
|
||||
NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML); \
|
||||
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue); \
|
||||
NS_IMETHOD Undo(); \
|
||||
NS_IMETHOD Redo(); \
|
||||
|
@ -63,6 +69,8 @@ public:
|
|||
|
||||
|
||||
#define NS_FORWARD_IDOMEDITORAPPCORE(_to) \
|
||||
NS_IMETHOD GetContentsAsText(nsString& aContentsAsText) { return _to##GetContentsAsText(aContentsAsText); } \
|
||||
NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML) { return _to##GetContentsAsHTML(aContentsAsHTML); } \
|
||||
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue) { return _to##SetAttribute(aAttr, aValue); } \
|
||||
NS_IMETHOD Undo() { return _to##Undo(); } \
|
||||
NS_IMETHOD Redo() { return _to##Redo(); } \
|
||||
|
|
|
@ -270,7 +270,8 @@ nsEditorAppCore::DoEditorMode(nsIWebShell *aWebShell)
|
|||
NS_IMETHODIMP
|
||||
nsEditorAppCore::SetAttribute(const nsString& aAttr, const nsString& aValue)
|
||||
{
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -403,6 +404,32 @@ nsEditorAppCore::Redo()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::GetContentsAsText(nsString& aContentsAsText)
|
||||
{
|
||||
nsresult err = NS_OK;
|
||||
|
||||
if (mEditor)
|
||||
{
|
||||
err = mEditor->OutputText(aContentsAsText);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::GetContentsAsHTML(nsString& aContentsAsHTML)
|
||||
{
|
||||
nsresult err = NS_OK;
|
||||
|
||||
if (mEditor)
|
||||
{
|
||||
err = mEditor->OutputHTML(aContentsAsHTML);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
void nsEditorAppCore::SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,8 @@ class nsEditorAppCore : public nsBaseAppCore,
|
|||
NS_IMETHOD Undo();
|
||||
NS_IMETHOD Redo();
|
||||
NS_IMETHOD Back();
|
||||
NS_IMETHOD GetContentsAsText(nsString& aContentsAsText);
|
||||
NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML);
|
||||
NS_IMETHOD Forward();
|
||||
NS_IMETHOD LoadUrl(const nsString& aUrl);
|
||||
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin);
|
||||
|
@ -68,6 +70,7 @@ class nsEditorAppCore : public nsBaseAppCore,
|
|||
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin);
|
||||
NS_IMETHOD SetDisableCallback(const nsString& aScript);
|
||||
NS_IMETHOD SetEnableCallback(const nsString& aScript);
|
||||
// NS_IMETHOD OutputText(nsString);
|
||||
NS_IMETHOD NewWindow();
|
||||
NS_IMETHOD PrintPreview();
|
||||
NS_IMETHOD Close();
|
||||
|
|
|
@ -42,6 +42,13 @@ static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
|
|||
NS_DEF_PTR(nsIDOMEditorAppCore);
|
||||
NS_DEF_PTR(nsIDOMWindow);
|
||||
|
||||
//
|
||||
// EditorAppCore property ids
|
||||
//
|
||||
enum EditorAppCore_slots {
|
||||
EDITORAPPCORE_CONTENTSASTEXT = -1,
|
||||
EDITORAPPCORE_CONTENTSASHTML = -2
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
|
@ -59,7 +66,28 @@ GetEditorAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case 0:
|
||||
case EDITORAPPCORE_CONTENTSASTEXT:
|
||||
{
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetContentsAsText(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EDITORAPPCORE_CONTENTSASHTML:
|
||||
{
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetContentsAsHTML(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
@ -137,6 +165,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString b0;
|
||||
nsAutoString b1;
|
||||
|
||||
|
@ -175,6 +204,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreUndo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
|
@ -199,6 +229,7 @@ EditorAppCoreUndo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Redo
|
||||
//
|
||||
|
@ -206,6 +237,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreRedo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
|
@ -238,6 +270,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreExit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
|
@ -270,6 +303,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreSetToolbarWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsIDOMWindowPtr b0;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
@ -311,6 +345,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreSetContentWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsIDOMWindowPtr b0;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
@ -352,6 +387,7 @@ PR_STATIC_CALLBACK(JSBool)
|
|||
EditorAppCoreSetWebShellWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsIDOMWindowPtr b0;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
@ -409,6 +445,8 @@ JSClass EditorAppCoreClass = {
|
|||
//
|
||||
static JSPropertySpec EditorAppCoreProperties[] =
|
||||
{
|
||||
{"contentsAsText", EDITORAPPCORE_CONTENTSASTEXT, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"contentsAsHTML", EDITORAPPCORE_CONTENTSASHTML, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -74,20 +74,41 @@
|
|||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
dump("Going Back\n");
|
||||
dump("Applying bold\n");
|
||||
appCore.setAttribute("bold", "");
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
}
|
||||
|
||||
function EditorGetText()
|
||||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
var outputText = appCore.contentsAsText;
|
||||
dump(outputText + "\n");
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
}
|
||||
|
||||
function EditorGetHTML()
|
||||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
var outputText = appCore.contentsAsHTML;
|
||||
dump(outputText + "\n");
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function EditorUndo()
|
||||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
dump("Opening New Window\n");
|
||||
dump("Undoing\n");
|
||||
appCore.undo();
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
|
@ -98,7 +119,7 @@
|
|||
{
|
||||
appCore = XPAppCoresManager.Find("EditorAppCore");
|
||||
if (appCore != null) {
|
||||
dump("Opening New Window\n");
|
||||
dump("Redoing\n");
|
||||
appCore.redo();
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
|
@ -195,21 +216,58 @@
|
|||
<toolbox>
|
||||
|
||||
<toolbar>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Cut.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Copy.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Paste.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Undo.gif"
|
||||
align="bottom" value="Undo"
|
||||
onClick="EditorUndo()"
|
||||
style="background-color:rgb(192,192,50);">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Redo.gif"
|
||||
align="bottom" value="Redo"
|
||||
onClick="EditorRedo()"
|
||||
style="background-color:rgb(192,192,50);">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Cut.gif"
|
||||
align="bottom" value="Cut"
|
||||
onClick="EditorUndo()">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Copy.gif"
|
||||
align="bottom" value="Copy"
|
||||
onClick="EditorUndo()">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Paste.gif"
|
||||
align="bottom" value="Paste"
|
||||
onClick="EditorUndo()">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Table.gif"
|
||||
align="bottom" value="Get HTML"
|
||||
onClick="EditorGetHTML()">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Spell.gif"
|
||||
align="bottom" value="Get Text"
|
||||
onClick="EditorGetText()">
|
||||
</titledbutton>
|
||||
|
||||
<titledbutton src="resource:/res/toolbar/ED_Bold.gif"
|
||||
align="bottom" value="Bold"
|
||||
onClick="EditorBold()">
|
||||
</titledbutton>
|
||||
|
||||
</toolbar>
|
||||
|
||||
<!-- Having so many buttons made loading v. slow. Commented out for now.
|
||||
<toolbar>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Find.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Link.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Target.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Image.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_HLine.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Table.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Spell.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
</toolbar>
|
||||
|
||||
<toolbar>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Undo.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Redo.gif" align="bottom" value="" onClick="EditorRedo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Bold.gif" align="bottom" value="" onClick="EditorBold()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Underline.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Indent.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
|
@ -220,7 +278,7 @@
|
|||
<titledbutton src="resource:/res/toolbar/ED_Center.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
<titledbutton src="resource:/res/toolbar/ED_Right.gif" align="bottom" value="" onClick="EditorUndo()"> </titledbutton>
|
||||
</toolbar>
|
||||
|
||||
-->
|
||||
|
||||
</toolbox>
|
||||
</html:div>
|
||||
|
|
Загрузка…
Ссылка в новой задаче