mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-18 14:56:07 +00:00
anthonyd: r=mjudge bug 39919 letting DOM level 2 stuff work for the editor. eliminating createelementNS and using the factory instead.
This commit is contained in:
parent
8a39869b3c
commit
aea4ff3323
@ -28,6 +28,9 @@
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
//included for new nsEditor::CreateContent()
|
||||
#include "nsIContent.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
@ -41,7 +44,7 @@ CreateElementTxn::CreateElementTxn()
|
||||
/* log description initialized in parent constructor */
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Init(nsIEditor *aEditor,
|
||||
NS_IMETHODIMP CreateElementTxn::Init(nsEditor *aEditor,
|
||||
const nsString &aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRUint32 aOffsetInParent)
|
||||
@ -103,11 +106,12 @@ NS_IMETHODIMP CreateElementTxn::Do(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=mTag;
|
||||
result = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(newElement));
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
mEditor->CreateHTMLContent(mTag, getter_AddRefs(newContent));
|
||||
newElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!newElement) return NS_ERROR_NULL_POINTER;
|
||||
mNewNode = do_QueryInterface(newElement);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define CreateElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
@ -51,7 +51,7 @@ public:
|
||||
* @param aOffsetInParent the location in aParent to insert the new element
|
||||
* if eAppend, the new element is appended as the last child
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
NS_IMETHOD Init(nsEditor *aEditor,
|
||||
const nsString& aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRUint32 aOffsetInParent);
|
||||
@ -84,7 +84,7 @@ public:
|
||||
protected:
|
||||
|
||||
/** the document into which the new node will be inserted */
|
||||
nsIEditor* mEditor;
|
||||
nsEditor* mEditor;
|
||||
|
||||
/** the tag (mapping to object type) for the new element */
|
||||
nsString mTag;
|
||||
|
@ -90,6 +90,10 @@
|
||||
#include "nsStyleSheetTxns.h"
|
||||
#include "IMETextTxn.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
// included for nsEditor::CreateHTMLContent
|
||||
#include "nsIElementFactory.h"
|
||||
#include "nsINodeInfo.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
// #define HACK_FORCE_REDRAW 1
|
||||
|
||||
@ -1840,12 +1844,13 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode,
|
||||
|
||||
// create new container
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=aNodeType;
|
||||
res = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(elem));
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
CreateHTMLContent(aNodeType, getter_AddRefs(newContent));
|
||||
elem = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res)) return res;
|
||||
*outNode = do_QueryInterface(elem);
|
||||
*outNode = do_QueryInterface(elem);
|
||||
|
||||
// set attribute if needed
|
||||
if (aAttribute && aValue && !aAttribute->IsEmpty())
|
||||
@ -1960,10 +1965,11 @@ nsEditor::InsertContainerAbove( nsIDOMNode *inNode,
|
||||
|
||||
// create new container
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=aNodeType;
|
||||
res = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(elem));
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
CreateHTMLContent(aNodeType, getter_AddRefs(newContent));
|
||||
elem = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res)) return res;
|
||||
*outNode = do_QueryInterface(elem);
|
||||
|
||||
@ -5741,3 +5747,43 @@ nsresult nsEditor::ClearSelection()
|
||||
return selection->ClearSelection();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditor::CreateHTMLContent(const nsString& aTag, nsIContent** aContent)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIElementFactory, elementFactory,
|
||||
NS_ELEMENT_FACTORY_PROGID_PREFIX"http://www.w3.org/1999/xhtml" , &rv);
|
||||
if (!elementFactory)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> tempDoc;
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
|
||||
rv = GetDocument(getter_AddRefs(tempDoc));
|
||||
if (NS_FAILED(rv) || !tempDoc)
|
||||
return rv?rv:NS_ERROR_FAILURE;
|
||||
|
||||
doc = do_QueryInterface(tempDoc);
|
||||
|
||||
nsCOMPtr<nsINodeInfoManager> nodeInfoManager;
|
||||
rv = doc->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
||||
rv = nodeInfoManager->GetNodeInfo(aTag, nsnull, kNameSpaceID_None,*getter_AddRefs(nodeInfo));
|
||||
|
||||
if (NS_FAILED(rv) || !nodeInfo)
|
||||
return rv?rv:NS_ERROR_FAILURE;
|
||||
|
||||
rv = elementFactory->CreateInstanceByTag(nodeInfo, aContent);
|
||||
|
||||
if (NS_FAILED(rv) || !aContent)
|
||||
return rv?rv:NS_ERROR_FAILURE;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -330,6 +330,13 @@ public:
|
||||
const nsString *aValue = nsnull);
|
||||
nsresult MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset);
|
||||
|
||||
/* Method to replace certain CreateElementNS() calls.
|
||||
Arguments:
|
||||
nsString& aTag - tag you want
|
||||
nsIContent** aContent - returned Content that was created with above namespace.
|
||||
*/
|
||||
nsresult CreateHTMLContent(const nsString& aTag, nsIContent** aContent);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
@ -2230,7 +2230,7 @@ nsEditorShell::SetDocumentTitle(const PRUnichar *title)
|
||||
{
|
||||
// Didn't find one above: Create a new one
|
||||
nsCOMPtr<nsIDOMElement>titleElement;
|
||||
res = domDoc->CreateElementNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"), NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
|
||||
res = domDoc->CreateElement(NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
|
||||
if (NS_SUCCEEDED(res) && titleElement)
|
||||
{
|
||||
titleNode = do_QueryInterface(titleElement);
|
||||
|
@ -3744,12 +3744,13 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement*
|
||||
// go through the transaction system
|
||||
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
|
||||
if (!doc) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=realTagName;
|
||||
res = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(newElement));
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
CreateHTMLContent(realTagName, getter_AddRefs(newContent));
|
||||
newElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res) || !newElement)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -1221,9 +1221,13 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
res = mEditor->GetDocument(getter_AddRefs(domDoc));
|
||||
nsCOMPtr<nsIDOMElement>brElement;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:br");
|
||||
res = domDoc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(brElement));
|
||||
qualifiedTag.AssignWithConversion("br");
|
||||
|
||||
mEditor->CreateHTMLContent(qualifiedTag, getter_AddRefs(newContent));
|
||||
brElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// set mBogusNode to be the newly created <br>
|
||||
|
@ -2230,7 +2230,7 @@ nsEditorShell::SetDocumentTitle(const PRUnichar *title)
|
||||
{
|
||||
// Didn't find one above: Create a new one
|
||||
nsCOMPtr<nsIDOMElement>titleElement;
|
||||
res = domDoc->CreateElementNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"), NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
|
||||
res = domDoc->CreateElement(NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
|
||||
if (NS_SUCCEEDED(res) && titleElement)
|
||||
{
|
||||
titleNode = do_QueryInterface(titleElement);
|
||||
|
@ -28,6 +28,9 @@
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
//included for new nsEditor::CreateContent()
|
||||
#include "nsIContent.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
@ -41,7 +44,7 @@ CreateElementTxn::CreateElementTxn()
|
||||
/* log description initialized in parent constructor */
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Init(nsIEditor *aEditor,
|
||||
NS_IMETHODIMP CreateElementTxn::Init(nsEditor *aEditor,
|
||||
const nsString &aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRUint32 aOffsetInParent)
|
||||
@ -103,11 +106,12 @@ NS_IMETHODIMP CreateElementTxn::Do(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=mTag;
|
||||
result = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(newElement));
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
mEditor->CreateHTMLContent(mTag, getter_AddRefs(newContent));
|
||||
newElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!newElement) return NS_ERROR_NULL_POINTER;
|
||||
mNewNode = do_QueryInterface(newElement);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define CreateElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
@ -51,7 +51,7 @@ public:
|
||||
* @param aOffsetInParent the location in aParent to insert the new element
|
||||
* if eAppend, the new element is appended as the last child
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
NS_IMETHOD Init(nsEditor *aEditor,
|
||||
const nsString& aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRUint32 aOffsetInParent);
|
||||
@ -84,7 +84,7 @@ public:
|
||||
protected:
|
||||
|
||||
/** the document into which the new node will be inserted */
|
||||
nsIEditor* mEditor;
|
||||
nsEditor* mEditor;
|
||||
|
||||
/** the tag (mapping to object type) for the new element */
|
||||
nsString mTag;
|
||||
|
@ -90,6 +90,10 @@
|
||||
#include "nsStyleSheetTxns.h"
|
||||
#include "IMETextTxn.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
// included for nsEditor::CreateHTMLContent
|
||||
#include "nsIElementFactory.h"
|
||||
#include "nsINodeInfo.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
// #define HACK_FORCE_REDRAW 1
|
||||
|
||||
@ -1840,12 +1844,13 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode,
|
||||
|
||||
// create new container
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=aNodeType;
|
||||
res = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(elem));
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
CreateHTMLContent(aNodeType, getter_AddRefs(newContent));
|
||||
elem = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res)) return res;
|
||||
*outNode = do_QueryInterface(elem);
|
||||
*outNode = do_QueryInterface(elem);
|
||||
|
||||
// set attribute if needed
|
||||
if (aAttribute && aValue && !aAttribute->IsEmpty())
|
||||
@ -1960,10 +1965,11 @@ nsEditor::InsertContainerAbove( nsIDOMNode *inNode,
|
||||
|
||||
// create new container
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=aNodeType;
|
||||
res = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(elem));
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
CreateHTMLContent(aNodeType, getter_AddRefs(newContent));
|
||||
elem = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res)) return res;
|
||||
*outNode = do_QueryInterface(elem);
|
||||
|
||||
@ -5741,3 +5747,43 @@ nsresult nsEditor::ClearSelection()
|
||||
return selection->ClearSelection();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditor::CreateHTMLContent(const nsString& aTag, nsIContent** aContent)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIElementFactory, elementFactory,
|
||||
NS_ELEMENT_FACTORY_PROGID_PREFIX"http://www.w3.org/1999/xhtml" , &rv);
|
||||
if (!elementFactory)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> tempDoc;
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
|
||||
rv = GetDocument(getter_AddRefs(tempDoc));
|
||||
if (NS_FAILED(rv) || !tempDoc)
|
||||
return rv?rv:NS_ERROR_FAILURE;
|
||||
|
||||
doc = do_QueryInterface(tempDoc);
|
||||
|
||||
nsCOMPtr<nsINodeInfoManager> nodeInfoManager;
|
||||
rv = doc->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
||||
rv = nodeInfoManager->GetNodeInfo(aTag, nsnull, kNameSpaceID_None,*getter_AddRefs(nodeInfo));
|
||||
|
||||
if (NS_FAILED(rv) || !nodeInfo)
|
||||
return rv?rv:NS_ERROR_FAILURE;
|
||||
|
||||
rv = elementFactory->CreateInstanceByTag(nodeInfo, aContent);
|
||||
|
||||
if (NS_FAILED(rv) || !aContent)
|
||||
return rv?rv:NS_ERROR_FAILURE;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -330,6 +330,13 @@ public:
|
||||
const nsString *aValue = nsnull);
|
||||
nsresult MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset);
|
||||
|
||||
/* Method to replace certain CreateElementNS() calls.
|
||||
Arguments:
|
||||
nsString& aTag - tag you want
|
||||
nsIContent** aContent - returned Content that was created with above namespace.
|
||||
*/
|
||||
nsresult CreateHTMLContent(const nsString& aTag, nsIContent** aContent);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
@ -3744,12 +3744,13 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement*
|
||||
// go through the transaction system
|
||||
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
|
||||
if (!doc) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:");
|
||||
qualifiedTag+=realTagName;
|
||||
res = doc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(newElement));
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
CreateHTMLContent(realTagName, getter_AddRefs(newContent));
|
||||
newElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res) || !newElement)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -1221,9 +1221,13 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
res = mEditor->GetDocument(getter_AddRefs(domDoc));
|
||||
nsCOMPtr<nsIDOMElement>brElement;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
|
||||
nsString qualifiedTag;
|
||||
qualifiedTag.AssignWithConversion("html:br");
|
||||
res = domDoc->CreateElementNS(NS_ConvertASCIItoUCS2("http://www.w3.org/1999/xhtml"), qualifiedTag, getter_AddRefs(brElement));
|
||||
qualifiedTag.AssignWithConversion("br");
|
||||
|
||||
mEditor->CreateHTMLContent(qualifiedTag, getter_AddRefs(newContent));
|
||||
brElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// set mBogusNode to be the newly created <br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user