Bug 945572 part 1. Make NS_NewHTMLElement take an Element** outparam instead of an nsIContent** one. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 03 Dec 2013 09:40:10 -0500
changeset 158591 2ae6663f558c4241302066e46b8cc57e8a2d6f69
parent 158590 efc30ce15377d80715992055b403ec1a3a29a5e6
child 158592 4f841d982dcbb958900758c887193fd2dff67cc7
push id2968
push userryanvm@gmail.com
push dateTue, 03 Dec 2013 22:06:07 +0000
treeherderb2g-inbound@70b6149628d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs945572
milestone28.0a1
Bug 945572 part 1. Make NS_NewHTMLElement take an Element** outparam instead of an nsIContent** one. r=smaug
content/base/public/nsContentCreatorFunctions.h
content/base/src/nsDocument.cpp
content/base/src/nsNameSpaceManager.cpp
content/html/content/src/nsTextEditorState.h
content/html/document/src/PluginDocument.cpp
content/html/document/src/nsHTMLContentSink.cpp
content/xslt/src/xslt/txMozillaTextOutput.cpp
content/xslt/src/xslt/txMozillaXMLOutput.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsFileControlFrame.cpp
--- a/content/base/public/nsContentCreatorFunctions.h
+++ b/content/base/public/nsContentCreatorFunctions.h
@@ -17,26 +17,33 @@
 
 class nsAString;
 class nsIContent;
 class nsINodeInfo;
 class imgRequestProxy;
 class nsNodeInfoManager;
 class nsGenericHTMLElement;
 
+namespace mozilla {
+namespace dom {
+class Element;
+} // namespace dom
+} // namespace mozilla
+
 nsresult
 NS_NewElement(nsIContent** aResult,
               already_AddRefed<nsINodeInfo> aNodeInfo,
               mozilla::dom::FromParser aFromParser);
 
 nsresult
 NS_NewXMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
 
 nsresult
-NS_NewHTMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLElement(mozilla::dom::Element** aResult,
+                  already_AddRefed<nsINodeInfo> aNodeInfo,
                   mozilla::dom::FromParser aFromParser);
 
 // First argument should be nsHTMLTag, but that adds dependency to parser
 // for a bunch of files.
 already_AddRefed<nsGenericHTMLElement>
 CreateHTMLElement(uint32_t aNodeType, already_AddRefed<nsINodeInfo> aNodeInfo,
                   mozilla::dom::FromParser aFromParser);
 
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -11461,23 +11461,23 @@ nsIDocument::SetStateObject(nsIStructure
 already_AddRefed<Element>
 nsIDocument::CreateHTMLElement(nsIAtom* aTag)
 {
   nsCOMPtr<nsINodeInfo> nodeInfo;
   nodeInfo = mNodeInfoManager->GetNodeInfo(aTag, nullptr, kNameSpaceID_XHTML,
                                            nsIDOMNode::ELEMENT_NODE);
   MOZ_ASSERT(nodeInfo, "GetNodeInfo should never fail");
 
-  nsCOMPtr<nsIContent> content = nullptr;
-  DebugOnly<nsresult> rv = NS_NewHTMLElement(getter_AddRefs(content),
+  nsCOMPtr<Element> element;
+  DebugOnly<nsresult> rv = NS_NewHTMLElement(getter_AddRefs(element),
                                              nodeInfo.forget(),
                                              mozilla::dom::NOT_FROM_PARSER);
 
   MOZ_ASSERT(NS_SUCCEEDED(rv), "NS_NewHTMLElement should never fail");
-  return dont_AddRef(content.forget().get()->AsElement());
+  return element.forget();
 }
 
 bool
 MarkDocumentTreeToBeInSyncOperation(nsIDocument* aDoc, void* aData)
 {
   nsCOMArray<nsIDocument>* documents =
     static_cast<nsCOMArray<nsIDocument>*>(aData);
   if (aDoc) {
--- a/content/base/src/nsNameSpaceManager.cpp
+++ b/content/base/src/nsNameSpaceManager.cpp
@@ -14,16 +14,17 @@
 #include "nsINodeInfo.h"
 #include "nsCOMArray.h"
 #include "nsTArray.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsDataHashtable.h"
 #include "nsString.h"
 #include "nsINodeInfo.h"
 #include "mozilla/dom/XBLChildrenElement.h"
+#include "mozilla/dom/Element.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/"
 #define kXMLNameSpaceURI "http://www.w3.org/XML/1998/namespace"
 #define kXHTMLNameSpaceURI "http://www.w3.org/1999/xhtml"
 #define kXLinkNameSpaceURI "http://www.w3.org/1999/xlink"
@@ -188,17 +189,20 @@ NameSpaceManagerImpl::GetNameSpaceID(con
 }
 
 nsresult
 NS_NewElement(nsIContent** aResult,
               already_AddRefed<nsINodeInfo> aNodeInfo, FromParser aFromParser)
 {
   int32_t ns = aNodeInfo.get()->NamespaceID();
   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
   if (ns == kNameSpaceID_XUL) {
     return NS_NewXULElement(aResult, aNodeInfo);
   }
 #endif
   if (ns == kNameSpaceID_MathML) {
     return NS_NewMathMLElement(aResult, aNodeInfo);
--- a/content/html/content/src/nsTextEditorState.h
+++ b/content/html/content/src/nsTextEditorState.h
@@ -7,17 +7,17 @@
 #ifndef nsTextEditorState_h__
 #define nsTextEditorState_h__
 
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsITextControlElement.h"
 #include "nsITextControlFrame.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsIContent.h"
+#include "mozilla/dom/Element.h"
 #include "mozilla/WeakPtr.h"
 
 class nsTextInputListener;
 class nsTextControlFrame;
 class nsTextInputSelectionImpl;
 class nsAnonDivObserver;
 class nsISelectionController;
 class nsFrameSelection;
@@ -137,22 +137,22 @@ public:
   void SetValue(const nsAString& aValue, bool aUserInput,
                 bool aSetValueAsChanged);
   void GetValue(nsAString& aValue, bool aIgnoreWrap) const;
   void EmptyValue() { if (mValue) mValue->Truncate(); }
   bool IsEmpty() const { return mValue ? mValue->IsEmpty() : true; }
 
   nsresult CreatePlaceholderNode();
 
-  nsIContent* GetRootNode() {
+  mozilla::dom::Element* GetRootNode() {
     if (!mRootNode)
       CreateRootNode();
     return mRootNode;
   }
-  nsIContent* GetPlaceholderNode() {
+  mozilla::dom::Element* GetPlaceholderNode() {
     return mPlaceholderDiv;
   }
 
   bool IsSingleLineTextControl() const {
     return mTextCtrlElement->IsSingleLineTextControl();
   }
   bool IsTextArea() const {
     return mTextCtrlElement->IsTextArea();
@@ -262,18 +262,18 @@ private:
   };
   friend class InitializationGuard;
   friend class PrepareEditorEvent;
 
   nsITextControlElement* const mTextCtrlElement;
   nsRefPtr<nsTextInputSelectionImpl> mSelCon;
   RestoreSelectionState* mRestoringSelection;
   nsCOMPtr<nsIEditor> mEditor;
-  nsCOMPtr<nsIContent> mRootNode;
-  nsCOMPtr<nsIContent> mPlaceholderDiv;
+  nsCOMPtr<mozilla::dom::Element> mRootNode;
+  nsCOMPtr<mozilla::dom::Element> mPlaceholderDiv;
   nsTextControlFrame* mBoundFrame;
   nsTextInputListener* mTextListener;
   nsAutoPtr<nsCString> mValue;
   nsRefPtr<nsAnonDivObserver> mMutationObserver;
   mutable nsString mCachedValue; // Caches non-hard-wrapped value on a multiline control.
   bool mEverInited; // Have we ever been initialized?
   bool mEditorInitialized;
   bool mInitializing; // Whether we're in the process of initialization
--- a/content/html/document/src/PluginDocument.cpp
+++ b/content/html/document/src/PluginDocument.cpp
@@ -39,25 +39,25 @@ public:
                                      nsIStreamListener** aDocListener,
                                      bool                aReset = true,
                                      nsIContentSink*     aSink = nullptr);
 
   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
   virtual bool CanSavePresentation(nsIRequest *aNewRequest);
 
   const nsCString& GetType() const { return mMimeType; }
-  nsIContent*      GetPluginContent() { return mPluginContent; }
+  Element*         GetPluginContent() { return mPluginContent; }
 
   void StartLayout() { MediaDocument::StartLayout(); }
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PluginDocument, MediaDocument)
 protected:
   nsresult CreateSyntheticPluginDocument();
 
-  nsCOMPtr<nsIContent>                     mPluginContent;
+  nsCOMPtr<Element>                        mPluginContent;
   nsRefPtr<MediaDocumentStreamListener>    mStreamListener;
   nsCString                                mMimeType;
 };
 
 class PluginStreamListener : public MediaDocumentStreamListener
 {
 public:
   PluginStreamListener(PluginDocument* doc)
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -237,17 +237,17 @@ public:
   };
 
   Node* mStack;
   int32_t mStackSize;
   int32_t mStackPos;
 };
 
 nsresult
-NS_NewHTMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLElement(Element** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
                   FromParser aFromParser)
 {
   *aResult = nullptr;
 
   nsCOMPtr<nsINodeInfo> nodeInfo = aNodeInfo;
 
   nsIParserService* parserService = nsContentUtils::GetParserService();
   if (!parserService)
--- a/content/xslt/src/xslt/txMozillaTextOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaTextOutput.cpp
@@ -237,17 +237,12 @@ void txMozillaTextOutput::getOutputDocum
 {
     CallQueryInterface(mDocument, aDocument);
 }
 
 nsresult
 txMozillaTextOutput::createXHTMLElement(nsIAtom* aName,
                                         nsIContent** aResult)
 {
-    *aResult = nullptr;
-
-    nsCOMPtr<nsINodeInfo> ni;
-    ni = mDocument->NodeInfoManager()->
-        GetNodeInfo(aName, nullptr, kNameSpaceID_XHTML,
-                    nsIDOMNode::ELEMENT_NODE);
-
-    return NS_NewHTMLElement(aResult, ni.forget(), NOT_FROM_PARSER);
+    nsCOMPtr<Element> element = mDocument->CreateHTMLElement(aName);
+    element.forget(aResult);
+    return NS_OK;
 }
--- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp
@@ -929,19 +929,23 @@ txMozillaXMLOutput::createHTMLElement(ns
 
     *aResult = nullptr;
 
     nsCOMPtr<nsINodeInfo> ni;
     ni = mNodeInfoManager->GetNodeInfo(aName, nullptr,
                                        kNameSpaceID_XHTML,
                                        nsIDOMNode::ELEMENT_NODE);
 
-    return NS_NewHTMLElement(aResult, ni.forget(), mCreatingNewDocument ?
-        FROM_PARSER_XSLT : FROM_PARSER_FRAGMENT);
-
+    nsCOMPtr<Element> el;
+    nsresult rv =
+        NS_NewHTMLElement(getter_AddRefs(el), ni.forget(),
+                          mCreatingNewDocument ?
+                            FROM_PARSER_XSLT : FROM_PARSER_FRAGMENT);
+    el.forget(aResult);
+    return rv;
 }
 
 txTransformNotifier::txTransformNotifier()
     : mPendingStylesheetCount(0),
       mInTransform(false)      
 {
 }
 
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -1163,23 +1163,17 @@ nsComboboxControlFrame::CreateAnonymousC
   if (mDisplayedIndex != -1) {
     mListControlFrame->GetOptionText(mDisplayedIndex, mDisplayedOptionText);
   }
   ActuallyDisplayText(false);
 
   if (!aElements.AppendElement(mDisplayContent))
     return NS_ERROR_OUT_OF_MEMORY;
 
-  nsCOMPtr<nsINodeInfo> nodeInfo;
-  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);
+  mButtonContent = mContent->OwnerDoc()->CreateHTMLElement(nsGkAtoms::button);
   if (!mButtonContent)
     return NS_ERROR_OUT_OF_MEMORY;
 
   // make someone to listen to the button. If its pressed by someone like Accessibility
   // then open or close the combo box.
   mButtonListener = new nsComboButtonListener(this);
   mButtonContent->AddEventListener(NS_LITERAL_STRING("click"), mButtonListener,
                                    false, false);
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsFileControlFrame.h"
 
 #include "nsGkAtoms.h"
 #include "nsCOMPtr.h"
 #include "nsIDocument.h"
 #include "nsINodeInfo.h"
+#include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLButtonElement.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "nsNodeInfoManager.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentUtils.h"
 #include "nsEventStates.h"
 #include "nsIDOMDataTransfer.h"
 #include "nsIDOMDOMStringList.h"
@@ -70,24 +71,19 @@ nsFileControlFrame::DestroyFrom(nsIFrame
   mMouseListener->ForgetFrame();
   nsBlockFrame::DestroyFrom(aDestructRoot);
 }
 
 nsresult
 nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
   nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
-  nsCOMPtr<nsINodeInfo> nodeInfo;
 
   // Create and setup the file picking button.
-  nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::button, nullptr,
-                                                 kNameSpaceID_XHTML,
-                                                 nsIDOMNode::ELEMENT_NODE);
-  NS_NewHTMLElement(getter_AddRefs(mBrowse), nodeInfo.forget(),
-                    dom::NOT_FROM_PARSER);
+  mBrowse = doc->CreateHTMLElement(nsGkAtoms::button);
   // NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
   // attribute.
   mBrowse->SetIsNativeAnonymousRoot();
   mBrowse->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                    NS_LITERAL_STRING("button"), false);
 
   // Set the file picking button text depending on the current locale.
   nsXPIDLString buttonTxt;
@@ -117,16 +113,17 @@ nsFileControlFrame::CreateAnonymousConte
   fileContent->GetTabIndex(&tabIndex);
   browseControl->SetTabIndex(tabIndex);
 
   if (!aElements.AppendElement(mBrowse)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // Create and setup the text showing the selected files.
+  nsCOMPtr<nsINodeInfo> nodeInfo;
   nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
                                                  kNameSpaceID_XUL,
                                                  nsIDOMNode::ELEMENT_NODE);
   NS_TrustedNewXULElement(getter_AddRefs(mTextContent), nodeInfo.forget());
   // NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
   // attribute.
   mTextContent->SetIsNativeAnonymousRoot();
   mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::crop,