mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +00:00
synched with changes to nsITextEditor text property methods
This commit is contained in:
parent
53b5306cec
commit
2e78504cc6
@ -401,12 +401,12 @@ nsEditorAppCore::DoEditorMode(nsIWebShell *aWebShell)
|
||||
// the name of the attribute here should be the contents of the appropriate
|
||||
// tag, e.g. 'b' for bold, 'i' for italics.
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::SetTextProperty(const nsString& aAttr)
|
||||
nsEditorAppCore::SetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue)
|
||||
{
|
||||
nsIAtom *styleAtom = nsnull;
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
|
||||
styleAtom = NS_NewAtom(aAttr); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
||||
styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
||||
|
||||
if (! styleAtom)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@ -421,14 +421,14 @@ nsEditorAppCore::SetTextProperty(const nsString& aAttr)
|
||||
// should we allow this?
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->SetTextProperty(styleAtom);
|
||||
err = textEditor->SetTextProperty(styleAtom, &aAttr, &aValue);
|
||||
}
|
||||
break;
|
||||
case eHTMLTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
err = htmlEditor->SetTextProperty(styleAtom);
|
||||
err = htmlEditor->SetTextProperty(styleAtom, &aAttr, &aValue);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -442,12 +442,12 @@ nsEditorAppCore::SetTextProperty(const nsString& aAttr)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::RemoveOneProperty(const nsString &aAttr)
|
||||
nsEditorAppCore::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
|
||||
{
|
||||
nsIAtom *styleAtom = nsnull;
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
|
||||
styleAtom = NS_NewAtom(aAttr); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
||||
styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
||||
|
||||
if (! styleAtom)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@ -462,14 +462,14 @@ nsEditorAppCore::RemoveOneProperty(const nsString &aAttr)
|
||||
// should we allow this?
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->RemoveTextProperty(styleAtom);
|
||||
err = textEditor->RemoveTextProperty(styleAtom, &aAttr);
|
||||
}
|
||||
break;
|
||||
case eHTMLTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
err = htmlEditor->RemoveTextProperty(styleAtom);
|
||||
err = htmlEditor->RemoveTextProperty(styleAtom, &aAttr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -484,7 +484,7 @@ nsEditorAppCore::RemoveOneProperty(const nsString &aAttr)
|
||||
// the name of the attribute here should be the contents of the appropriate
|
||||
// tag, e.g. 'b' for bold, 'i' for italics.
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::RemoveTextProperty(const nsString& aAttr)
|
||||
nsEditorAppCore::RemoveTextProperty(const nsString& aProp, const nsString& aAttr)
|
||||
{
|
||||
// OK, I'm really hacking now. This is just so that we can accept 'all' as input.
|
||||
// this logic should live elsewhere.
|
||||
@ -495,7 +495,7 @@ nsEditorAppCore::RemoveTextProperty(const nsString& aAttr)
|
||||
nsnull // this null is important
|
||||
};
|
||||
|
||||
nsAutoString allStr = aAttr;
|
||||
nsAutoString allStr = aProp;
|
||||
allStr.ToLowerCase();
|
||||
PRBool doingAll = (allStr == "all");
|
||||
nsresult err = NS_OK;
|
||||
@ -510,7 +510,7 @@ nsEditorAppCore::RemoveTextProperty(const nsString& aAttr)
|
||||
thisAttr.Truncate(0);
|
||||
thisAttr += (char *)(*tagName);
|
||||
|
||||
err = RemoveOneProperty(thisAttr);
|
||||
err = RemoveOneProperty(thisAttr, aAttr);
|
||||
|
||||
tagName ++;
|
||||
}
|
||||
@ -518,14 +518,15 @@ nsEditorAppCore::RemoveTextProperty(const nsString& aAttr)
|
||||
}
|
||||
else
|
||||
{
|
||||
err = RemoveOneProperty(aAttr);
|
||||
err = RemoveOneProperty(aProp, aAttr);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::GetTextProperty(const nsString& aAttr, PRBool* aFirstHas, PRBool* aAnyHas, PRBool* aAllHas)
|
||||
nsEditorAppCore::GetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue,
|
||||
PRBool* aFirstHas, PRBool* aAnyHas, PRBool* aAllHas)
|
||||
{
|
||||
nsIAtom *styleAtom = nsnull;
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
@ -534,7 +535,7 @@ nsEditorAppCore::GetTextProperty(const nsString& aAttr, PRBool* aFirstHas, PRBoo
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
styleAtom = NS_NewAtom(aAttr); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
||||
styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
||||
|
||||
switch (mEditorType)
|
||||
{
|
||||
@ -543,14 +544,14 @@ nsEditorAppCore::GetTextProperty(const nsString& aAttr, PRBool* aFirstHas, PRBoo
|
||||
// should we allow this?
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->GetTextProperty(styleAtom, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
err = textEditor->GetTextProperty(styleAtom, &aAttr, &aValue, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
}
|
||||
break;
|
||||
case eHTMLTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
err = htmlEditor->GetTextProperty(styleAtom, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
err = htmlEditor->GetTextProperty(styleAtom, &aAttr, &aValue, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -61,9 +61,14 @@ class nsEditorAppCore : public nsBaseAppCore,
|
||||
NS_IMETHOD SetDocumentCharset(const nsString& aCharset) { return nsBaseAppCore::SetDocumentCharset(aCharset); }
|
||||
|
||||
NS_IMETHOD SetEditorType(const nsString& aEditorType);
|
||||
NS_IMETHOD SetTextProperty(const nsString& aAttr);
|
||||
NS_IMETHOD RemoveTextProperty(const nsString& aAttr);
|
||||
NS_IMETHOD GetTextProperty(const nsString& aAttr, PRBool* aFirstHas, PRBool* aAnyHas, PRBool* aAllHas);
|
||||
NS_IMETHOD SetTextProperty(const nsString& aProp,
|
||||
const nsString& aAttr,
|
||||
const nsString& aValue);
|
||||
NS_IMETHOD RemoveTextProperty(const nsString& aProp, const nsString& aAttr);
|
||||
NS_IMETHOD GetTextProperty(const nsString& aProp,
|
||||
const nsString& aAttr,
|
||||
const nsString& aValue,
|
||||
PRBool* aFirstHas, PRBool* aAnyHas, PRBool* aAllHas);
|
||||
NS_IMETHOD GetContentsAsText(nsString& aContentsAsText);
|
||||
NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML);
|
||||
NS_IMETHOD GetEditorDocument(nsIDOMDocument** aEditorDocument);
|
||||
@ -113,7 +118,7 @@ class nsEditorAppCore : public nsBaseAppCore,
|
||||
NS_IMETHOD DoEditorMode(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
|
||||
NS_IMETHOD InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||
NS_IMETHOD RemoveOneProperty(const nsString& aAttr);
|
||||
NS_IMETHOD RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
void SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName);
|
||||
|
||||
nsString mEnableScript;
|
||||
|
@ -235,6 +235,8 @@ EditorAppCoreSetTextProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString b0;
|
||||
nsAutoString b1;
|
||||
nsAutoString b2;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
@ -243,18 +245,22 @@ EditorAppCoreSetTextProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
if (argc >= 3) {
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
|
||||
|
||||
if (NS_OK != nativeThis->SetTextProperty(b0)) {
|
||||
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
|
||||
|
||||
if (NS_OK != nativeThis->SetTextProperty(b0, b1, b2)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function setTextProperty requires 1 parameters");
|
||||
JS_ReportError(cx, "Function setTextProperty requires 3 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -271,6 +277,7 @@ EditorAppCoreRemoveTextProperty(JSContext *cx, JSObject *obj, uintN argc, jsval
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString b0;
|
||||
nsAutoString b1;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
@ -279,18 +286,20 @@ EditorAppCoreRemoveTextProperty(JSContext *cx, JSObject *obj, uintN argc, jsval
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
if (argc >= 2) {
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
|
||||
|
||||
if (NS_OK != nativeThis->RemoveTextProperty(b0)) {
|
||||
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
|
||||
|
||||
if (NS_OK != nativeThis->RemoveTextProperty(b0, b1)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function removeTextProperty requires 1 parameters");
|
||||
JS_ReportError(cx, "Function removeTextProperty requires 2 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -307,9 +316,11 @@ EditorAppCoreGetTextProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
|
||||
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString b0;
|
||||
PRBool b1;
|
||||
PRBool b2;
|
||||
nsAutoString b1;
|
||||
nsAutoString b2;
|
||||
PRBool b3;
|
||||
PRBool b4;
|
||||
PRBool b5;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
@ -318,30 +329,34 @@ EditorAppCoreGetTextProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 4) {
|
||||
if (argc >= 6) {
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
|
||||
|
||||
if (!nsJSUtils::nsConvertJSValToBool(&b1, cx, argv[1])) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
|
||||
|
||||
if (!nsJSUtils::nsConvertJSValToBool(&b2, cx, argv[2])) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
|
||||
|
||||
if (!nsJSUtils::nsConvertJSValToBool(&b3, cx, argv[3])) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (NS_OK != nativeThis->GetTextProperty(b0, &b1, &b2, &b3)) {
|
||||
if (!nsJSUtils::nsConvertJSValToBool(&b4, cx, argv[4])) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (!nsJSUtils::nsConvertJSValToBool(&b5, cx, argv[5])) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (NS_OK != nativeThis->GetTextProperty(b0, b1, b2, &b3, &b4, &b5)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function getTextProperty requires 4 parameters");
|
||||
JS_ReportError(cx, "Function getTextProperty requires 6 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -944,9 +959,9 @@ static JSPropertySpec EditorAppCoreProperties[] =
|
||||
static JSFunctionSpec EditorAppCoreMethods[] =
|
||||
{
|
||||
{"setEditorType", EditorAppCoreSetEditorType, 1},
|
||||
{"setTextProperty", EditorAppCoreSetTextProperty, 1},
|
||||
{"removeTextProperty", EditorAppCoreRemoveTextProperty, 1},
|
||||
{"getTextProperty", EditorAppCoreGetTextProperty, 4},
|
||||
{"setTextProperty", EditorAppCoreSetTextProperty, 3},
|
||||
{"removeTextProperty", EditorAppCoreRemoveTextProperty, 2},
|
||||
{"getTextProperty", EditorAppCoreGetTextProperty, 6},
|
||||
{"undo", EditorAppCoreUndo, 0},
|
||||
{"redo", EditorAppCoreRedo, 0},
|
||||
{"cut", EditorAppCoreCut, 0},
|
||||
|
@ -32,7 +32,7 @@
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore != null) {
|
||||
dump("Applying Style\n");
|
||||
appCore.setTextProperty(styleName);
|
||||
appCore.setTextProperty(styleName, null, null);
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
@ -43,7 +43,7 @@
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore != null) {
|
||||
dump("Removing Style\n");
|
||||
appCore.removeTextProperty(styleName);
|
||||
appCore.removeTextProperty(styleName, null);
|
||||
} else {
|
||||
dump("EditorAppCore has not been created!\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user