Bug 945517 - Make nsIFrame::GetPseudoElementContent return Element* instead of nsIContent*. r=bz
authorCameron McCormack <cam@mcc.id.au>
Tue, 03 Dec 2013 15:49:03 +1100
changeset 174176 ddd2dbbd9b2df8155d02c27fad4094ac1f545da2
parent 174175 c9322fc3ef1bc839b134737e5fccda5c34bc8dcb
child 174177 9d996ae7fc46ae0e7de42241b714b39b997f1828
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs945517
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 945517 - Make nsIFrame::GetPseudoElementContent return Element* instead of nsIContent*. r=bz
content/base/public/nsContentUtils.h
content/base/public/nsIDocument.h
content/base/src/nsContentUtils.cpp
content/base/src/nsDocument.cpp
layout/forms/nsColorControlFrame.cpp
layout/forms/nsColorControlFrame.h
layout/forms/nsMeterFrame.cpp
layout/forms/nsMeterFrame.h
layout/forms/nsNumberControlFrame.cpp
layout/forms/nsNumberControlFrame.h
layout/forms/nsProgressFrame.cpp
layout/forms/nsProgressFrame.h
layout/forms/nsRangeFrame.cpp
layout/forms/nsRangeFrame.h
layout/forms/nsTextControlFrame.cpp
layout/forms/nsTextControlFrame.h
layout/generic/nsFrame.cpp
layout/generic/nsIFrame.h
layout/style/nsComputedDOMStyle.cpp
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -1256,16 +1256,17 @@ public:
    * Delete strings allocated for nsContentList matches
    */
   static void DestroyMatchString(void* aData);
 
   /**
    * Unbinds the content from the tree and nulls it out if it's not null.
    */
   static void DestroyAnonymousContent(nsCOMPtr<nsIContent>* aContent);
+  static void DestroyAnonymousContent(nsCOMPtr<Element>* aElement);
 
   static void DeferredFinalize(nsISupports* aSupports);
   static void DeferredFinalize(mozilla::DeferredFinalizeAppendFunction aAppendFunc,
                                mozilla::DeferredFinalizeFunction aFunc,
                                void* aThing);
 
   /*
    * Notify when the first XUL menu is opened and when the all XUL menus are
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -1955,16 +1955,22 @@ public:
     }
   }
 
   bool CreatingStaticClone() const
   {
     return mCreatingStaticClone;
   }
 
+  /**
+   * Creates a new element in the HTML namespace with a local name given by
+   * aTag.
+   */
+  already_AddRefed<Element> CreateHTMLElement(nsIAtom* aTag);
+
   // WebIDL API
   nsIGlobalObject* GetParentObject() const
   {
     return GetScopeObject();
   }
   static already_AddRefed<nsIDocument>
     Constructor(const GlobalObject& aGlobal,
                 mozilla::ErrorResult& rv);
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -4346,16 +4346,21 @@ nsContentUtils::IsInSameAnonymousTree(co
 
 class AnonymousContentDestroyer : public nsRunnable {
 public:
   AnonymousContentDestroyer(nsCOMPtr<nsIContent>* aContent) {
     mContent.swap(*aContent);
     mParent = mContent->GetParent();
     mDoc = mContent->OwnerDoc();
   }
+  AnonymousContentDestroyer(nsCOMPtr<Element>* aElement) {
+    mContent = aElement->forget();
+    mParent = mContent->GetParent();
+    mDoc = mContent->OwnerDoc();
+  }
   NS_IMETHOD Run() {
     mContent->UnbindFromTree();
     return NS_OK;
   }
 private:
   nsCOMPtr<nsIContent> mContent;
   // Hold strong refs to the parent content and document so that they
   // don't die unexpectedly
@@ -4369,16 +4374,25 @@ nsContentUtils::DestroyAnonymousContent(
 {
   if (*aContent) {
     AddScriptRunner(new AnonymousContentDestroyer(aContent));
   }
 }
 
 /* static */
 void
+nsContentUtils::DestroyAnonymousContent(nsCOMPtr<Element>* aElement)
+{
+  if (*aElement) {
+    AddScriptRunner(new AnonymousContentDestroyer(aElement));
+  }
+}
+
+/* static */
+void
 nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling)
 {
   nsIMEStateManager::OnInstalledMenuKeyboardListener(aInstalling);
 }
 
 static bool SchemeIs(nsIURI* aURI, const char* aScheme)
 {
   nsCOMPtr<nsIURI> baseURI = NS_GetInnermostURI(aURI);
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -11453,16 +11453,33 @@ nsIDocument::GetDocShell() const
 
 void
 nsIDocument::SetStateObject(nsIStructuredCloneContainer *scContainer)
 {
   mStateObjectContainer = scContainer;
   mStateObjectCached = nullptr;
 }
 
+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),
+                                             nodeInfo.forget(),
+                                             mozilla::dom::NOT_FROM_PARSER);
+
+  MOZ_ASSERT(NS_SUCCEEDED(rv), "NS_NewHTMLElement should never fail");
+  return dont_AddRef(content.forget().get()->AsElement());
+}
+
 bool
 MarkDocumentTreeToBeInSyncOperation(nsIDocument* aDoc, void* aData)
 {
   nsCOMArray<nsIDocument>* documents =
     static_cast<nsCOMArray<nsIDocument>*>(aData);
   if (aDoc) {
     aDoc->SetIsInSyncOperation(true);
     documents->AppendObject(aDoc);
--- a/layout/forms/nsColorControlFrame.cpp
+++ b/layout/forms/nsColorControlFrame.cpp
@@ -10,16 +10,18 @@
 #include "nsContentUtils.h"
 #include "nsFormControlFrame.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMNode.h"
 #include "nsIFormControl.h"
 #include "nsStyleSet.h"
 
+using mozilla::dom::Element;
+
 nsColorControlFrame::nsColorControlFrame(nsStyleContext* aContext):
   nsColorControlFrameSuper(aContext)
 {
 }
 
 nsIFrame*
 NS_NewColorControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
@@ -55,30 +57,22 @@ nsColorControlFrame::GetFrameName(nsAStr
 #endif
 
 // Create the color area for the button.
 // The frame will be generated by the frame constructor.
 nsresult
 nsColorControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
   nsCOMPtr<nsIDocument> doc = mContent->GetCurrentDoc();
-  nsCOMPtr<nsINodeInfo> nodeInfo =
-      doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nullptr,
-        kNameSpaceID_XHTML,
-        nsIDOMNode::ELEMENT_NODE);
-
-  nsresult rv = NS_NewHTMLElement(getter_AddRefs(mColorContent),
-                                  nodeInfo.forget(),
-                                  mozilla::dom::NOT_FROM_PARSER);
-  NS_ENSURE_SUCCESS(rv, rv);
+  mColorContent = doc->CreateHTMLElement(nsGkAtoms::div);
 
   // Mark the element to be native anonymous before setting any attributes.
   mColorContent->SetIsNativeAnonymousRoot();
 
-  rv = UpdateColor();
+  nsresult rv = UpdateColor();
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCSSPseudoElements::Type pseudoType = nsCSSPseudoElements::ePseudo_mozColorSwatch;
   nsRefPtr<nsStyleContext> newStyleContext = PresContext()->StyleSet()->
     ResolvePseudoElementStyle(mContent->AsElement(), pseudoType,
                               StyleContext(), mColorContent->AsElement());
   if (!aElements.AppendElement(ContentInfo(mColorContent, newStyleContext))) {
     return NS_ERROR_OUT_OF_MEMORY;
@@ -131,17 +125,17 @@ nsColorControlFrame::AttributeChanged(in
 }
 
 nsIFrame*
 nsColorControlFrame::GetContentInsertionFrame()
 {
   return this;
 }
 
-nsIContent*
-nsColorControlFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+Element*
+nsColorControlFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   if (aType == nsCSSPseudoElements::ePseudo_mozColorSwatch) {
     return mColorContent;
   }
 
-  return nsContainerFrame::GetPseudoElementContent(aType);
+  return nsContainerFrame::GetPseudoElement(aType);
 }
--- a/layout/forms/nsColorControlFrame.h
+++ b/layout/forms/nsColorControlFrame.h
@@ -12,16 +12,18 @@
 
 typedef nsHTMLButtonControlFrame nsColorControlFrameSuper;
 
 // Class which implements the input type=color
 
 class nsColorControlFrame MOZ_FINAL : public nsColorControlFrameSuper,
                                       public nsIAnonymousContentCreator
 {
+  typedef mozilla::dom::Element Element;
+
 public:
   friend nsIFrame* NS_NewColorControlFrame(nsIPresShell* aPresShell,
                                            nsStyleContext* aContext);
 
   virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
 
   NS_DECL_FRAMEARENA_HELPERS
   NS_DECL_QUERYFRAME
@@ -39,21 +41,21 @@ public:
 
   // nsIFrame
   NS_IMETHOD AttributeChanged(int32_t  aNameSpaceID,
                               nsIAtom* aAttribute,
                               int32_t  aModType) MOZ_OVERRIDE;
   virtual bool IsLeaf() const MOZ_OVERRIDE { return true; }
   virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE;
 
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
+  virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
 
 private:
   nsColorControlFrame(nsStyleContext* aContext);
 
   // Update the color swatch
   nsresult UpdateColor();
 
-  nsCOMPtr<nsIContent> mColorContent;
+  nsCOMPtr<Element> mColorContent;
 };
 
 
 #endif // nsColorControlFrame_h___
--- a/layout/forms/nsMeterFrame.cpp
+++ b/layout/forms/nsMeterFrame.cpp
@@ -19,16 +19,17 @@
 #include "nsFontMetrics.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLMeterElement.h"
 #include "nsContentList.h"
 #include "nsStyleSet.h"
 #include "nsThemeConstants.h"
 #include <algorithm>
 
+using mozilla::dom::Element;
 using mozilla::dom::HTMLMeterElement;
 
 nsIFrame*
 NS_NewMeterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMeterFrame(aContext);
 }
 
@@ -56,26 +57,18 @@ nsMeterFrame::DestroyFrom(nsIFrame* aDes
 }
 
 nsresult
 nsMeterFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
   // Get the NodeInfoManager and tag necessary to create the meter bar div.
   nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
 
-  nsCOMPtr<nsINodeInfo> nodeInfo;
-  nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nullptr,
-                                                 kNameSpaceID_XHTML,
-                                                 nsIDOMNode::ELEMENT_NODE);
-  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
-
   // Create the div.
-  nsresult rv = NS_NewHTMLElement(getter_AddRefs(mBarDiv), nodeInfo.forget(),
-                                  mozilla::dom::NOT_FROM_PARSER);
-  NS_ENSURE_SUCCESS(rv, rv);
+  mBarDiv = doc->CreateHTMLElement(nsGkAtoms::div);
 
   // Associate ::-moz-meter-bar pseudo-element to the anonymous child.
   nsCSSPseudoElements::Type pseudoType = nsCSSPseudoElements::ePseudo_mozMeterBar;
   nsRefPtr<nsStyleContext> newStyleContext = PresContext()->StyleSet()->
     ResolvePseudoElementStyle(mContent->AsElement(), pseudoType,
                               StyleContext(), mBarDiv->AsElement());
 
   if (!aElements.AppendElement(ContentInfo(mBarDiv, newStyleContext))) {
@@ -273,17 +266,17 @@ nsMeterFrame::ShouldUseNativeStyle() con
   return StyleDisplay()->mAppearance == NS_THEME_METERBAR &&
          mBarDiv->GetPrimaryFrame()->StyleDisplay()->mAppearance == NS_THEME_METERBAR_CHUNK &&
          !PresContext()->HasAuthorSpecifiedRules(const_cast<nsMeterFrame*>(this),
                                                  NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND) &&
          !PresContext()->HasAuthorSpecifiedRules(mBarDiv->GetPrimaryFrame(),
                                                  NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND);
 }
 
-nsIContent*
-nsMeterFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+Element*
+nsMeterFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   if (aType == nsCSSPseudoElements::ePseudo_mozMeterBar) {
     return mBarDiv;
   }
 
-  return nsContainerFrame::GetPseudoElementContent(aType);
+  return nsContainerFrame::GetPseudoElement(aType);
 }
--- a/layout/forms/nsMeterFrame.h
+++ b/layout/forms/nsMeterFrame.h
@@ -10,16 +10,18 @@
 #include "nsContainerFrame.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsCOMPtr.h"
 
 class nsMeterFrame : public nsContainerFrame,
                      public nsIAnonymousContentCreator
 
 {
+  typedef mozilla::dom::Element Element;
+
 public:
   NS_DECL_QUERYFRAME_TARGET(nsMeterFrame)
   NS_DECL_QUERYFRAME
   NS_DECL_FRAMEARENA_HELPERS
 
   nsMeterFrame(nsStyleContext* aContext);
   virtual ~nsMeterFrame();
 
@@ -61,24 +63,24 @@ public:
       ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
   }
 
   /**
    * Returns whether the frame and its child should use the native style.
    */
   bool ShouldUseNativeStyle() const;
 
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
+  virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
 
 protected:
   // Helper function which reflow the anonymous div frame.
   void ReflowBarFrame(nsIFrame*                aBarFrame,
                       nsPresContext*           aPresContext,
                       const nsHTMLReflowState& aReflowState,
                       nsReflowStatus&          aStatus);
   /**
    * The div used to show the meter bar.
    * @see nsMeterFrame::CreateAnonymousContent
    */
-  nsCOMPtr<nsIContent> mBarDiv;
+  nsCOMPtr<Element> mBarDiv;
 };
 
 #endif
--- a/layout/forms/nsNumberControlFrame.cpp
+++ b/layout/forms/nsNumberControlFrame.cpp
@@ -170,51 +170,44 @@ nsNumberControlFrame::AttributeChanged(i
     }
   }
 
   return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
                                             aModType);
 }
 
 nsresult
-nsNumberControlFrame::MakeAnonymousElement(nsIContent** aResult,
+nsNumberControlFrame::MakeAnonymousElement(Element** aResult,
                                            nsTArray<ContentInfo>& aElements,
                                            nsIAtom* aTagName,
                                            nsCSSPseudoElements::Type aPseudoType,
                                            nsStyleContext* aParentContext)
 {
   // Get the NodeInfoManager and tag necessary to create the anonymous divs.
   nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
-
-  nsCOMPtr<nsINodeInfo> nodeInfo;
-  nodeInfo = doc->NodeInfoManager()->GetNodeInfo(aTagName, nullptr,
-                                                 kNameSpaceID_XHTML,
-                                                 nsIDOMNode::ELEMENT_NODE);
-  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
-  nsresult rv = NS_NewHTMLElement(aResult, nodeInfo.forget(),
-                                  dom::NOT_FROM_PARSER);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsRefPtr<Element> resultElement = doc->CreateHTMLElement(aTagName);
 
   // If we legitimately fail this assertion and need to allow
   // non-pseudo-element anonymous children, then we'll need to add a branch
   // that calls ResolveStyleFor((*aResult)->AsElement(), aParentContext)") to
   // set newStyleContext.
   NS_ASSERTION(aPseudoType != nsCSSPseudoElements::ePseudo_NotPseudoElement,
                "Expecting anonymous children to all be pseudo-elements");
   // Associate the pseudo-element with the anonymous child
-  Element* resultElement = (*aResult)->AsElement();
   nsRefPtr<nsStyleContext> newStyleContext =
     PresContext()->StyleSet()->ResolvePseudoElementStyle(mContent->AsElement(),
                                                          aPseudoType,
                                                          aParentContext,
                                                          resultElement);
 
   if (!aElements.AppendElement(ContentInfo(resultElement, newStyleContext))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
+
+  resultElement.forget(aResult);
   return NS_OK;
 }
 
 nsresult
 nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
   nsresult rv;
 
@@ -374,18 +367,18 @@ nsNumberControlFrame::UpdateForValueChan
   }
   // We need to update the value of our anonymous text control here. Note that
   // this must be its value, and not its 'value' attribute (the default value),
   // since the default value is ignored once a user types into the text
   // control.
   HTMLInputElement::FromContent(mTextField)->SetValue(aValue);
 }
 
-nsIContent*
-nsNumberControlFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+Element*
+nsNumberControlFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   if (aType == nsCSSPseudoElements::ePseudo_mozNumberWrapper) {
     return mOuterWrapper;
   }
 
   if (aType == nsCSSPseudoElements::ePseudo_mozNumberText) {
     return mTextField;
   }
@@ -397,10 +390,10 @@ nsNumberControlFrame::GetPseudoElementCo
   if (aType == nsCSSPseudoElements::ePseudo_mozNumberSpinUp) {
     return mSpinUp;
   }
 
   if (aType == nsCSSPseudoElements::ePseudo_mozNumberSpinDown) {
     return mSpinDown;
   }
 
-  return nsContainerFrame::GetPseudoElementContent(aType);
+  return nsContainerFrame::GetPseudoElement(aType);
 }
--- a/layout/forms/nsNumberControlFrame.h
+++ b/layout/forms/nsNumberControlFrame.h
@@ -25,16 +25,17 @@ class HTMLInputElement;
  * This frame type is used for <input type=number>.
  */
 class nsNumberControlFrame MOZ_FINAL : public nsContainerFrame
                                      , public nsIAnonymousContentCreator
 {
   friend nsIFrame*
   NS_NewNumberControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
+  typedef mozilla::dom::Element Element;
   typedef mozilla::dom::HTMLInputElement HTMLInputElement;
   typedef mozilla::WidgetEvent WidgetEvent;
   typedef mozilla::WidgetGUIEvent WidgetGUIEvent;
 
   nsNumberControlFrame(nsStyleContext* aContext);
 
 public:
   NS_DECL_QUERYFRAME_TARGET(nsNumberControlFrame)
@@ -100,36 +101,36 @@ public:
    * Returns one of the SpinButtonEnum values to depending on whether the
    * pointer event is over the spin-up button, the spin-down button, or
    * neither.
    */
   int32_t GetSpinButtonForPointerEvent(WidgetGUIEvent* aEvent) const;
 
   void HandleFocusEvent(WidgetEvent* aEvent);
 
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
+  virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
 
 private:
 
-  nsresult MakeAnonymousElement(nsIContent** aResult,
+  nsresult MakeAnonymousElement(Element** aResult,
                                 nsTArray<ContentInfo>& aElements,
                                 nsIAtom* aTagName,
                                 nsCSSPseudoElements::Type aPseudoType,
                                 nsStyleContext* aParentContext);
 
   nsresult ReflowAnonymousContent(nsPresContext* aPresContext,
                                   nsHTMLReflowMetrics& aWrappersDesiredSize,
                                   const nsHTMLReflowState& aReflowState,
                                   nsIFrame* aOuterWrapperFrame);
 
   /**
    * The text field used to edit and show the number.
    * @see nsNumberControlFrame::CreateAnonymousContent.
    */
-  nsCOMPtr<nsIContent> mOuterWrapper;
-  nsCOMPtr<nsIContent> mTextField;
-  nsCOMPtr<nsIContent> mSpinBox;
-  nsCOMPtr<nsIContent> mSpinUp;
-  nsCOMPtr<nsIContent> mSpinDown;
+  nsCOMPtr<Element> mOuterWrapper;
+  nsCOMPtr<Element> mTextField;
+  nsCOMPtr<Element> mSpinBox;
+  nsCOMPtr<Element> mSpinUp;
+  nsCOMPtr<Element> mSpinDown;
   bool mHandlingInputEvent;
 };
 
 #endif // nsNumberControlFrame_h__
--- a/layout/forms/nsProgressFrame.cpp
+++ b/layout/forms/nsProgressFrame.cpp
@@ -53,29 +53,19 @@ nsProgressFrame::DestroyFrom(nsIFrame* a
   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
   nsContentUtils::DestroyAnonymousContent(&mBarDiv);
   nsContainerFrame::DestroyFrom(aDestructRoot);
 }
 
 nsresult
 nsProgressFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
-  // Get the NodeInfoManager and tag necessary to create the progress bar div.
+  // Create the progress bar div.
   nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
-
-  nsCOMPtr<nsINodeInfo> nodeInfo;
-  nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nullptr,
-                                                 kNameSpaceID_XHTML,
-                                                 nsIDOMNode::ELEMENT_NODE);
-  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
-
-  // Create the div.
-  nsresult rv = NS_NewHTMLElement(getter_AddRefs(mBarDiv), nodeInfo.forget(),
-                                  mozilla::dom::NOT_FROM_PARSER);
-  NS_ENSURE_SUCCESS(rv, rv);
+  mBarDiv = doc->CreateHTMLElement(nsGkAtoms::div);
 
   // Associate ::-moz-progress-bar pseudo-element to the anonymous child.
   nsCSSPseudoElements::Type pseudoType = nsCSSPseudoElements::ePseudo_mozProgressBar;
   nsRefPtr<nsStyleContext> newStyleContext = PresContext()->StyleSet()->
     ResolvePseudoElementStyle(mContent->AsElement(), pseudoType,
                               StyleContext(), mBarDiv->AsElement());
 
   if (!aElements.AppendElement(ContentInfo(mBarDiv, newStyleContext))) {
@@ -283,17 +273,17 @@ nsProgressFrame::ShouldUseNativeStyle() 
   return StyleDisplay()->mAppearance == NS_THEME_PROGRESSBAR &&
          mBarDiv->GetPrimaryFrame()->StyleDisplay()->mAppearance == NS_THEME_PROGRESSBAR_CHUNK &&
          !PresContext()->HasAuthorSpecifiedRules(const_cast<nsProgressFrame*>(this),
                                                  NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND) &&
          !PresContext()->HasAuthorSpecifiedRules(mBarDiv->GetPrimaryFrame(),
                                                  NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND);
 }
 
-nsIContent*
-nsProgressFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+Element*
+nsProgressFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   if (aType == nsCSSPseudoElements::ePseudo_mozProgressBar) {
     return mBarDiv;
   }
 
-  return nsContainerFrame::GetPseudoElementContent(aType);
+  return nsContainerFrame::GetPseudoElement(aType);
 }
--- a/layout/forms/nsProgressFrame.h
+++ b/layout/forms/nsProgressFrame.h
@@ -11,16 +11,18 @@
 #include "nsIAnonymousContentCreator.h"
 #include "nsCOMPtr.h"
 
 class nsBaseContentList;
 
 class nsProgressFrame : public nsContainerFrame,
                         public nsIAnonymousContentCreator
 {
+  typedef mozilla::dom::Element Element;
+
 public:
   NS_DECL_QUERYFRAME_TARGET(nsProgressFrame)
   NS_DECL_QUERYFRAME
   NS_DECL_FRAMEARENA_HELPERS
 
   nsProgressFrame(nsStyleContext* aContext);
   virtual ~nsProgressFrame();
 
@@ -66,26 +68,26 @@ public:
       ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
   }
 
   /**
    * Returns whether the frame and its child should use the native style.
    */
   bool ShouldUseNativeStyle() const;
 
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
+  virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
 
 protected:
   // Helper function which reflow the anonymous div frame.
   void ReflowBarFrame(nsIFrame*                aBarFrame,
                       nsPresContext*           aPresContext,
                       const nsHTMLReflowState& aReflowState,
                       nsReflowStatus&          aStatus);
 
   /**
    * The div used to show the progress bar.
    * @see nsProgressFrame::CreateAnonymousContent
    */
-  nsCOMPtr<nsIContent> mBarDiv;
+  nsCOMPtr<Element> mBarDiv;
 };
 
 #endif
 
--- a/layout/forms/nsRangeFrame.cpp
+++ b/layout/forms/nsRangeFrame.cpp
@@ -28,16 +28,17 @@
 
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #endif
 
 #define LONG_SIDE_TO_SHORT_SIDE_RATIO 10
 
 using namespace mozilla;
+using namespace mozilla::dom;
 
 nsIFrame*
 NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsRangeFrame(aContext);
 }
 
 nsRangeFrame::nsRangeFrame(nsStyleContext* aContext)
@@ -93,41 +94,35 @@ nsRangeFrame::DestroyFrom(nsIFrame* aDes
   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
   nsContentUtils::DestroyAnonymousContent(&mTrackDiv);
   nsContentUtils::DestroyAnonymousContent(&mProgressDiv);
   nsContentUtils::DestroyAnonymousContent(&mThumbDiv);
   nsContainerFrame::DestroyFrom(aDestructRoot);
 }
 
 nsresult
-nsRangeFrame::MakeAnonymousDiv(nsIContent** aResult,
+nsRangeFrame::MakeAnonymousDiv(Element** aResult,
                                nsCSSPseudoElements::Type aPseudoType,
                                nsTArray<ContentInfo>& aElements)
 {
-  // Get the NodeInfoManager and tag necessary to create the anonymous divs.
   nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
+  nsRefPtr<Element> resultElement = doc->CreateHTMLElement(nsGkAtoms::div);
 
-  nsCOMPtr<nsINodeInfo> nodeInfo;
-  nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nullptr,
-                                                 kNameSpaceID_XHTML,
-                                                 nsIDOMNode::ELEMENT_NODE);
-  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
-  nsresult rv = NS_NewHTMLElement(aResult, nodeInfo.forget(),
-                                  dom::NOT_FROM_PARSER);
-  NS_ENSURE_SUCCESS(rv, rv);
   // Associate the pseudo-element with the anonymous child.
   nsRefPtr<nsStyleContext> newStyleContext =
     PresContext()->StyleSet()->ResolvePseudoElementStyle(mContent->AsElement(),
                                                          aPseudoType,
                                                          StyleContext(),
-                                                         (*aResult)->AsElement());
+                                                         resultElement);
 
-  if (!aElements.AppendElement(ContentInfo(*aResult, newStyleContext))) {
+  if (!aElements.AppendElement(ContentInfo(resultElement, newStyleContext))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
+
+  resultElement.forget(aResult);
   return NS_OK;
 }
 
 nsresult
 nsRangeFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
 {
   nsresult rv;
 
@@ -828,25 +823,25 @@ nsRangeFrame::ShouldUseNativeStyle() con
          !PresContext()->HasAuthorSpecifiedRules(mTrackDiv->GetPrimaryFrame(),
                                                  STYLES_DISABLING_NATIVE_THEMING) &&
          !PresContext()->HasAuthorSpecifiedRules(mProgressDiv->GetPrimaryFrame(),
                                                  STYLES_DISABLING_NATIVE_THEMING) &&
          !PresContext()->HasAuthorSpecifiedRules(mThumbDiv->GetPrimaryFrame(),
                                                  STYLES_DISABLING_NATIVE_THEMING);
 }
 
-nsIContent*
-nsRangeFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+Element*
+nsRangeFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   if (aType == nsCSSPseudoElements::ePseudo_mozRangeTrack) {
     return mTrackDiv;
   }
 
   if (aType == nsCSSPseudoElements::ePseudo_mozRangeThumb) {
     return mThumbDiv;
   }
 
   if (aType == nsCSSPseudoElements::ePseudo_mozRangeProgress) {
     return mProgressDiv;
   }
 
-  return nsContainerFrame::GetPseudoElementContent(aType);
+  return nsContainerFrame::GetPseudoElement(aType);
 }
--- a/layout/forms/nsRangeFrame.h
+++ b/layout/forms/nsRangeFrame.h
@@ -19,16 +19,18 @@ class nsRangeFrame : public nsContainerF
                      public nsIAnonymousContentCreator
 {
   friend nsIFrame*
   NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
   nsRangeFrame(nsStyleContext* aContext);
   virtual ~nsRangeFrame();
 
+  typedef mozilla::dom::Element Element;
+
 public:
   NS_DECL_QUERYFRAME_TARGET(nsRangeFrame)
   NS_DECL_QUERYFRAME
   NS_DECL_FRAMEARENA_HELPERS
 
   // nsIFrame overrides
   virtual void Init(nsIContent*      aContent,
                     nsIFrame*        aParent,
@@ -117,21 +119,21 @@ public:
    * Helper that's used when the value of the range changes to reposition the
    * thumb, resize the range-progress element, and schedule a repaint. (This
    * does not reflow, since the position and size of the thumb and
    * range-progress element do not affect the position or size of any other
    * frames.)
    */
   void UpdateForValueChange();
 
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
+  virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
 
 private:
 
-  nsresult MakeAnonymousDiv(nsIContent** aResult,
+  nsresult MakeAnonymousDiv(Element** aResult,
                             nsCSSPseudoElements::Type aPseudoType,
                             nsTArray<ContentInfo>& aElements);
 
   // Helper function which reflows the anonymous div frames.
   nsresult ReflowAnonymousContent(nsPresContext*           aPresContext,
                                   nsHTMLReflowMetrics&     aDesiredSize,
                                   const nsHTMLReflowState& aReflowState);
 
@@ -140,26 +142,26 @@ private:
 
   void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
                                   const nsSize& aRangeSize);
 
   /**
    * The div used to show the ::-moz-range-track pseudo-element.
    * @see nsRangeFrame::CreateAnonymousContent
    */
-  nsCOMPtr<nsIContent> mTrackDiv;
+  nsCOMPtr<Element> mTrackDiv;
 
   /**
    * The div used to show the ::-moz-range-progress pseudo-element, which is
    * used to (optionally) style the specific chunk of track leading up to the
    * thumb's current position.
    * @see nsRangeFrame::CreateAnonymousContent
    */
-  nsCOMPtr<nsIContent> mProgressDiv;
+  nsCOMPtr<Element> mProgressDiv;
 
   /**
    * The div used to show the ::-moz-range-thumb pseudo-element.
    * @see nsRangeFrame::CreateAnonymousContent
    */
-  nsCOMPtr<nsIContent> mThumbDiv;
+  nsCOMPtr<Element> mThumbDiv;
 };
 
 #endif
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -1427,25 +1427,29 @@ nsTextControlFrame::BuildDisplayList(nsD
     if (kid->GetContent() != txtCtrl->GetPlaceholderNode() ||
         txtCtrl->GetPlaceholderVisibility()) {
       BuildDisplayListForChild(aBuilder, kid, aDirtyRect, set, 0);
     }
     kid = kid->GetNextSibling();
   }
 }
 
-nsIContent*
-nsTextControlFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+mozilla::dom::Element*
+nsTextControlFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   if (aType == nsCSSPseudoElements::ePseudo_mozPlaceholder) {
     nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
-    return txtCtrl->GetPlaceholderNode();
+    nsIContent* placeholderNode = txtCtrl->GetPlaceholderNode();
+    if (placeholderNode && placeholderNode->IsElement()) {
+      return placeholderNode->AsElement();
+    }
+    return nullptr;
   }
 
-  return nsContainerFrame::GetPseudoElementContent(aType);
+  return nsContainerFrame::GetPseudoElement(aType);
 }
 
 NS_IMETHODIMP
 nsTextControlFrame::EditorInitializer::Run()
 {
   if (!mFrame) {
     return NS_OK;
   }
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -89,17 +89,17 @@ public:
 
   NS_IMETHOD SetInitialChildList(ChildListID     aListID,
                                  nsFrameList&    aChildList) MOZ_OVERRIDE;
 
   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                 const nsRect&           aDirtyRect,
                                 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
 
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
+  virtual mozilla::dom::Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
 
 //==== BEGIN NSIFORMCONTROLFRAME
   virtual void SetFocus(bool aOn , bool aRepaint) MOZ_OVERRIDE; 
   virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) MOZ_OVERRIDE;
 
 //==== END NSIFORMCONTROLFRAME
 
 //==== NSITEXTCONTROLFRAME
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -80,19 +80,20 @@
 
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/css/ImageLoader.h"
 #include "mozilla/gfx/Tools.h"
 
 using namespace mozilla;
+using namespace mozilla::css;
+using namespace mozilla::dom;
 using namespace mozilla::layers;
 using namespace mozilla::layout;
-using namespace mozilla::css;
 
 // Struct containing cached metrics for box-wrapped frames.
 struct nsBoxLayoutMetrics
 {
   nsSize mPrefSize;
   nsSize mMinSize;
   nsSize mMaxSize;
 
@@ -8100,28 +8101,35 @@ nsIFrame::DestroyRegion(void* aPropertyV
 bool
 nsIFrame::IsPseudoStackingContextFromStyle() {
   const nsStyleDisplay* disp = StyleDisplay();
   return disp->mOpacity != 1.0f ||
          disp->IsPositioned(this) ||
          disp->IsFloating(this);
 }
 
-nsIContent*
-nsIFrame::GetPseudoElementContent(nsCSSPseudoElements::Type aType)
+Element*
+nsIFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
 {
   nsIFrame* frame = nullptr;
 
   if (aType == nsCSSPseudoElements::ePseudo_before) {
     frame = nsLayoutUtils::GetBeforeFrame(this);
   } else if (aType == nsCSSPseudoElements::ePseudo_after) {
     frame = nsLayoutUtils::GetAfterFrame(this);
   }
 
-  return frame ? frame->GetContent() : nullptr;
+  if (frame) {
+    nsIContent* content = frame->GetContent();
+    if (content->IsElement()) {
+      return content->AsElement();
+    }
+  }
+  
+  return nullptr;
 }
 
 nsIFrame::ContentOffsets::ContentOffsets()
 {
 }
 
 nsIFrame::ContentOffsets::ContentOffsets(const ContentOffsets& rhs)
   : content(rhs.content),
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -3021,17 +3021,17 @@ NS_PTR_TO_INT32(frame->Properties().Get(
     return GetStateBits() & NS_FRAME_FONT_INFLATION_CONTAINER;
   }
 
   /**
    * Returns the content node within the anonymous content that this frame
    * generated and which corresponds to the specified pseudo-element type,
    * or nullptr if there is no such anonymous content.
    */
-  virtual nsIContent* GetPseudoElementContent(nsCSSPseudoElements::Type aType);
+  virtual mozilla::dom::Element* GetPseudoElement(nsCSSPseudoElements::Type aType);
 
 protected:
   // Members
   nsRect           mRect;
   nsIContent*      mContent;
   nsStyleContext*  mStyleContext;
   nsIFrame*        mParent;
 private:
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -483,24 +483,18 @@ nsComputedDOMStyle::GetStyleContextForEl
   nsStyleSet *styleSet = presShell->StyleSet();
 
   nsRefPtr<nsStyleContext> sc;
   if (aPseudo) {
     nsCSSPseudoElements::Type type = nsCSSPseudoElements::GetPseudoType(aPseudo);
     if (type >= nsCSSPseudoElements::ePseudo_PseudoElementCount) {
       return nullptr;
     }
-    Element* pseudoElement = nullptr;
     nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement);
-    if (frame) {
-      nsIContent* pseudoContent = frame->GetPseudoElementContent(type);
-      if (pseudoContent && pseudoContent->IsElement()) {
-        pseudoElement = pseudoContent->AsElement();
-      }
-    }
+    Element* pseudoElement = frame ? frame->GetPseudoElement(type) : nullptr;
     sc = styleSet->ResolvePseudoElementStyle(aElement, type, parentContext,
                                              pseudoElement);
   } else {
     sc = styleSet->ResolveStyleFor(aElement, parentContext);
   }
 
   if (aStyleType == eDefaultOnly) {
     // We really only want the user and UA rules.  Filter out the other ones.