Bug 1839115 - Expose nsMsgCompose::_NodeTreeConvertible to JS. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D181355

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Bieling 2023-06-19 22:54:20 +00:00
Родитель f2654ec93e
Коммит 01922ec13f
4 изменённых файлов: 42 добавлений и 5 удалений

Просмотреть файл

@ -65,6 +65,33 @@ async function checkMsgFile(aFilePath, aConvertibility) {
await BrowserTestUtils.closeWindow(messageController.window); await BrowserTestUtils.closeWindow(messageController.window);
} }
/**
* Tests nodeTreeConvertible() can be called from JavaScript.
*/
add_task(async function test_msg_nodeTreeConvertible() {
let msgCompose = Cc["@mozilla.org/messengercompose/compose;1"].createInstance(
Ci.nsIMsgCompose
);
let textDoc = new DOMParser().parseFromString(
"<p>Simple Text</p>",
"text/html"
);
Assert.equal(
msgCompose.nodeTreeConvertible(textDoc.documentElement),
Ci.nsIMsgCompConvertible.Plain
);
let htmlDoc = new DOMParser().parseFromString(
'<p>Complex <span style="font-weight: bold">Text</span></p>',
"text/html"
);
Assert.equal(
msgCompose.nodeTreeConvertible(htmlDoc.documentElement),
Ci.nsIMsgCompConvertible.No
);
});
/** /**
* Tests that we only open one compose window for one instance of a draft. * Tests that we only open one compose window for one instance of a draft.
*/ */

Просмотреть файл

@ -20,6 +20,8 @@ interface mozIDOMWindowProxy;
interface nsIEditor; interface nsIEditor;
interface nsIMsgWindow; interface nsIMsgWindow;
webidl Element;
typedef long MSG_ComposeSaveType; typedef long MSG_ComposeSaveType;
[scriptable, uuid(6953e50a-7531-11d3-85fe-006008948010)] [scriptable, uuid(6953e50a-7531-11d3-85fe-006008948010)]
@ -169,6 +171,13 @@ interface nsIMsgCompose : nsIMsgSendListener {
*/ */
long bodyConvertible(); long bodyConvertible();
/**
* The level of "convertibility" of the provided node to plaintext.
*
* @return a value from nsIMsgCompConvertible.
*/
long nodeTreeConvertible(in Element aNode);
/** /**
* The identity currently selected for the message compose object. When set * The identity currently selected for the message compose object. When set
* this may change the signature on a message being composed. Note that * this may change the signature on a message being composed. Note that

Просмотреть файл

@ -4715,7 +4715,9 @@ void nsMsgCompose::TagConvertible(Element* node, int32_t* _retval) {
/** /**
* Note: Helper function. Parameters are not checked. * Note: Helper function. Parameters are not checked.
*/ */
void nsMsgCompose::_NodeTreeConvertible(Element* node, int32_t* _retval) { NS_IMETHODIMP
nsMsgCompose::NodeTreeConvertible(Element* node, int32_t* _retval) {
NS_ENSURE_ARG_POINTER(_retval);
int32_t result; int32_t result;
// Check this node // Check this node
@ -4730,13 +4732,14 @@ void nsMsgCompose::_NodeTreeConvertible(Element* node, int32_t* _retval) {
nsCOMPtr<Element> domElement = do_QueryInterface(pItem); nsCOMPtr<Element> domElement = do_QueryInterface(pItem);
if (domElement) { if (domElement) {
int32_t curresult; int32_t curresult;
_NodeTreeConvertible(domElement, &curresult); NodeTreeConvertible(domElement, &curresult);
if (curresult > result) result = curresult; if (curresult > result) result = curresult;
} }
} }
*_retval = result; *_retval = result;
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -4752,8 +4755,7 @@ nsMsgCompose::BodyConvertible(int32_t* _retval) {
// get the top level element, which contains <html> // get the top level element, which contains <html>
nsCOMPtr<Element> rootElement = rootDocument->GetDocumentElement(); nsCOMPtr<Element> rootElement = rootDocument->GetDocumentElement();
if (!rootElement) return NS_ERROR_UNEXPECTED; if (!rootElement) return NS_ERROR_UNEXPECTED;
NodeTreeConvertible(rootElement, _retval);
_NodeTreeConvertible(rootElement, _retval);
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -82,7 +82,6 @@ class nsMsgCompose : public nsIMsgCompose, public nsSupportsWeakReference {
nsTArray<nsMsgMailList>& mailListResolved, nsTArray<nsMsgMailList>& mailListResolved,
nsTArray<nsMsgRecipient>& aListMembers); nsTArray<nsMsgRecipient>& aListMembers);
void TagConvertible(mozilla::dom::Element* node, int32_t* _retval); void TagConvertible(mozilla::dom::Element* node, int32_t* _retval);
void _NodeTreeConvertible(mozilla::dom::Element* node, int32_t* _retval);
MOZ_CAN_RUN_SCRIPT nsresult MoveToAboveQuote(void); MOZ_CAN_RUN_SCRIPT nsresult MoveToAboveQuote(void);
MOZ_CAN_RUN_SCRIPT nsresult MoveToBeginningOfDocument(void); MOZ_CAN_RUN_SCRIPT nsresult MoveToBeginningOfDocument(void);
MOZ_CAN_RUN_SCRIPT nsresult MoveToEndOfDocument(void); MOZ_CAN_RUN_SCRIPT nsresult MoveToEndOfDocument(void);