Bug 945572 part 1. Make NS_NewHTMLElement take an Element** outparam instead of an nsIContent** one. r=smaug

This commit is contained in:
Boris Zbarsky 2013-12-03 09:40:10 -05:00
parent 9866760836
commit 92f32069b0
10 changed files with 38 additions and 37 deletions

View File

@ -22,6 +22,12 @@ class imgRequestProxy;
class nsNodeInfoManager; class nsNodeInfoManager;
class nsGenericHTMLElement; class nsGenericHTMLElement;
namespace mozilla {
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
nsresult nsresult
NS_NewElement(nsIContent** aResult, NS_NewElement(nsIContent** aResult,
already_AddRefed<nsINodeInfo> aNodeInfo, already_AddRefed<nsINodeInfo> aNodeInfo,
@ -31,7 +37,8 @@ nsresult
NS_NewXMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo); NS_NewXMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
nsresult nsresult
NS_NewHTMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo, NS_NewHTMLElement(mozilla::dom::Element** aResult,
already_AddRefed<nsINodeInfo> aNodeInfo,
mozilla::dom::FromParser aFromParser); mozilla::dom::FromParser aFromParser);
// First argument should be nsHTMLTag, but that adds dependency to parser // First argument should be nsHTMLTag, but that adds dependency to parser

View File

@ -11466,13 +11466,13 @@ nsIDocument::CreateHTMLElement(nsIAtom* aTag)
nsIDOMNode::ELEMENT_NODE); nsIDOMNode::ELEMENT_NODE);
MOZ_ASSERT(nodeInfo, "GetNodeInfo should never fail"); MOZ_ASSERT(nodeInfo, "GetNodeInfo should never fail");
nsCOMPtr<nsIContent> content = nullptr; nsCOMPtr<Element> element;
DebugOnly<nsresult> rv = NS_NewHTMLElement(getter_AddRefs(content), DebugOnly<nsresult> rv = NS_NewHTMLElement(getter_AddRefs(element),
nodeInfo.forget(), nodeInfo.forget(),
mozilla::dom::NOT_FROM_PARSER); mozilla::dom::NOT_FROM_PARSER);
MOZ_ASSERT(NS_SUCCEEDED(rv), "NS_NewHTMLElement should never fail"); MOZ_ASSERT(NS_SUCCEEDED(rv), "NS_NewHTMLElement should never fail");
return dont_AddRef(content.forget().get()->AsElement()); return element.forget();
} }
bool bool

View File

@ -19,6 +19,7 @@
#include "nsString.h" #include "nsString.h"
#include "nsINodeInfo.h" #include "nsINodeInfo.h"
#include "mozilla/dom/XBLChildrenElement.h" #include "mozilla/dom/XBLChildrenElement.h"
#include "mozilla/dom/Element.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -193,7 +194,10 @@ NS_NewElement(nsIContent** aResult,
{ {
int32_t ns = aNodeInfo.get()->NamespaceID(); int32_t ns = aNodeInfo.get()->NamespaceID();
if (ns == kNameSpaceID_XHTML) { if (ns == kNameSpaceID_XHTML) {
return NS_NewHTMLElement(aResult, aNodeInfo, aFromParser); nsCOMPtr<Element> el;
nsresult rv = NS_NewHTMLElement(getter_AddRefs(el), aNodeInfo, aFromParser);
el.forget(aResult);
return rv;
} }
#ifdef MOZ_XUL #ifdef MOZ_XUL
if (ns == kNameSpaceID_XUL) { if (ns == kNameSpaceID_XUL) {

View File

@ -12,7 +12,7 @@
#include "nsITextControlElement.h" #include "nsITextControlElement.h"
#include "nsITextControlFrame.h" #include "nsITextControlFrame.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsIContent.h" #include "mozilla/dom/Element.h"
#include "mozilla/WeakPtr.h" #include "mozilla/WeakPtr.h"
class nsTextInputListener; class nsTextInputListener;
@ -142,12 +142,12 @@ public:
nsresult CreatePlaceholderNode(); nsresult CreatePlaceholderNode();
nsIContent* GetRootNode() { mozilla::dom::Element* GetRootNode() {
if (!mRootNode) if (!mRootNode)
CreateRootNode(); CreateRootNode();
return mRootNode; return mRootNode;
} }
nsIContent* GetPlaceholderNode() { mozilla::dom::Element* GetPlaceholderNode() {
return mPlaceholderDiv; return mPlaceholderDiv;
} }
@ -267,8 +267,8 @@ private:
nsRefPtr<nsTextInputSelectionImpl> mSelCon; nsRefPtr<nsTextInputSelectionImpl> mSelCon;
RestoreSelectionState* mRestoringSelection; RestoreSelectionState* mRestoringSelection;
nsCOMPtr<nsIEditor> mEditor; nsCOMPtr<nsIEditor> mEditor;
nsCOMPtr<nsIContent> mRootNode; nsCOMPtr<mozilla::dom::Element> mRootNode;
nsCOMPtr<nsIContent> mPlaceholderDiv; nsCOMPtr<mozilla::dom::Element> mPlaceholderDiv;
nsTextControlFrame* mBoundFrame; nsTextControlFrame* mBoundFrame;
nsTextInputListener* mTextListener; nsTextInputListener* mTextListener;
nsAutoPtr<nsCString> mValue; nsAutoPtr<nsCString> mValue;

View File

@ -44,7 +44,7 @@ public:
virtual bool CanSavePresentation(nsIRequest *aNewRequest); virtual bool CanSavePresentation(nsIRequest *aNewRequest);
const nsCString& GetType() const { return mMimeType; } const nsCString& GetType() const { return mMimeType; }
nsIContent* GetPluginContent() { return mPluginContent; } Element* GetPluginContent() { return mPluginContent; }
void StartLayout() { MediaDocument::StartLayout(); } void StartLayout() { MediaDocument::StartLayout(); }
@ -52,7 +52,7 @@ public:
protected: protected:
nsresult CreateSyntheticPluginDocument(); nsresult CreateSyntheticPluginDocument();
nsCOMPtr<nsIContent> mPluginContent; nsCOMPtr<Element> mPluginContent;
nsRefPtr<MediaDocumentStreamListener> mStreamListener; nsRefPtr<MediaDocumentStreamListener> mStreamListener;
nsCString mMimeType; nsCString mMimeType;
}; };

View File

@ -242,7 +242,7 @@ public:
}; };
nsresult nsresult
NS_NewHTMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo, NS_NewHTMLElement(Element** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser) FromParser aFromParser)
{ {
*aResult = nullptr; *aResult = nullptr;

View File

@ -242,12 +242,7 @@ nsresult
txMozillaTextOutput::createXHTMLElement(nsIAtom* aName, txMozillaTextOutput::createXHTMLElement(nsIAtom* aName,
nsIContent** aResult) nsIContent** aResult)
{ {
*aResult = nullptr; nsCOMPtr<Element> element = mDocument->CreateHTMLElement(aName);
element.forget(aResult);
nsCOMPtr<nsINodeInfo> ni; return NS_OK;
ni = mDocument->NodeInfoManager()->
GetNodeInfo(aName, nullptr, kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
return NS_NewHTMLElement(aResult, ni.forget(), NOT_FROM_PARSER);
} }

View File

@ -934,9 +934,13 @@ txMozillaXMLOutput::createHTMLElement(nsIAtom* aName,
kNameSpaceID_XHTML, kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE); nsIDOMNode::ELEMENT_NODE);
return NS_NewHTMLElement(aResult, ni.forget(), mCreatingNewDocument ? nsCOMPtr<Element> el;
FROM_PARSER_XSLT : FROM_PARSER_FRAGMENT); nsresult rv =
NS_NewHTMLElement(getter_AddRefs(el), ni.forget(),
mCreatingNewDocument ?
FROM_PARSER_XSLT : FROM_PARSER_FRAGMENT);
el.forget(aResult);
return rv;
} }
txTransformNotifier::txTransformNotifier() txTransformNotifier::txTransformNotifier()

View File

@ -1168,13 +1168,7 @@ nsComboboxControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
if (!aElements.AppendElement(mDisplayContent)) if (!aElements.AppendElement(mDisplayContent))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsINodeInfo> nodeInfo; mButtonContent = mContent->OwnerDoc()->CreateHTMLElement(nsGkAtoms::button);
nodeInfo = nimgr->GetNodeInfo(nsGkAtoms::button, nullptr, kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
// create button which drops the list down
NS_NewHTMLElement(getter_AddRefs(mButtonContent), nodeInfo.forget(),
dom::NOT_FROM_PARSER);
if (!mButtonContent) if (!mButtonContent)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;

View File

@ -9,6 +9,7 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsINodeInfo.h" #include "nsINodeInfo.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLButtonElement.h" #include "mozilla/dom/HTMLButtonElement.h"
#include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLInputElement.h"
#include "nsNodeInfoManager.h" #include "nsNodeInfoManager.h"
@ -75,14 +76,9 @@ nsresult
nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{ {
nsCOMPtr<nsIDocument> doc = mContent->GetDocument(); nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
nsCOMPtr<nsINodeInfo> nodeInfo;
// Create and setup the file picking button. // Create and setup the file picking button.
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::button, nullptr, mBrowse = doc->CreateHTMLElement(nsGkAtoms::button);
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_NewHTMLElement(getter_AddRefs(mBrowse), nodeInfo.forget(),
dom::NOT_FROM_PARSER);
// NOTE: SetIsNativeAnonymousRoot() has to be called before setting any // NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
// attribute. // attribute.
mBrowse->SetIsNativeAnonymousRoot(); mBrowse->SetIsNativeAnonymousRoot();
@ -122,6 +118,7 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
} }
// Create and setup the text showing the selected files. // Create and setup the text showing the selected files.
nsCOMPtr<nsINodeInfo> nodeInfo;
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr, nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
kNameSpaceID_XUL, kNameSpaceID_XUL,
nsIDOMNode::ELEMENT_NODE); nsIDOMNode::ELEMENT_NODE);