michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #include "nsHTMLParts.h" michael@0: #include "nsContainerFrame.h" michael@0: #include "nsCSSRendering.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsPageFrame.h" michael@0: #include "nsIDOMEvent.h" michael@0: #include "nsStyleConsts.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsIPresShell.h" michael@0: #include "nsBoxFrame.h" michael@0: #include "nsStackLayout.h" michael@0: #include "nsIAnonymousContentCreator.h" michael@0: #include "nsINodeInfo.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsNodeInfoManager.h" michael@0: #include "nsContentCreatorFunctions.h" michael@0: #include "nsContentUtils.h" michael@0: #include "nsContentList.h" michael@0: #include "mozilla/dom/Element.h" michael@0: michael@0: //#define DEBUG_REFLOW michael@0: michael@0: using namespace mozilla::dom; michael@0: michael@0: class nsDocElementBoxFrame : public nsBoxFrame, michael@0: public nsIAnonymousContentCreator michael@0: { michael@0: public: michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, michael@0: nsStyleContext* aContext); michael@0: michael@0: nsDocElementBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext) michael@0: :nsBoxFrame(aShell, aContext, true) {} michael@0: michael@0: NS_DECL_QUERYFRAME michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: // nsIAnonymousContentCreator michael@0: virtual nsresult CreateAnonymousContent(nsTArray& aElements) MOZ_OVERRIDE; michael@0: virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, michael@0: uint32_t aFilter) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE michael@0: { michael@0: // Override nsBoxFrame. michael@0: if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced)) michael@0: return false; michael@0: return nsBoxFrame::IsFrameOfType(aFlags); michael@0: } michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; michael@0: #endif michael@0: private: michael@0: nsCOMPtr mPopupgroupContent; michael@0: nsCOMPtr mTooltipContent; michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: michael@0: nsIFrame* michael@0: NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsDocElementBoxFrame (aPresShell, aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame) michael@0: michael@0: void michael@0: nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot) michael@0: { michael@0: nsContentUtils::DestroyAnonymousContent(&mPopupgroupContent); michael@0: nsContentUtils::DestroyAnonymousContent(&mTooltipContent); michael@0: nsBoxFrame::DestroyFrom(aDestructRoot); michael@0: } michael@0: michael@0: nsresult michael@0: nsDocElementBoxFrame::CreateAnonymousContent(nsTArray& aElements) michael@0: { michael@0: nsIDocument* doc = mContent->GetDocument(); michael@0: if (!doc) { michael@0: // The page is currently being torn down. Why bother. michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager(); michael@0: michael@0: // create the top-secret popupgroup node. shhhhh! michael@0: nsCOMPtr nodeInfo; michael@0: nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::popupgroup, michael@0: nullptr, kNameSpaceID_XUL, michael@0: nsIDOMNode::ELEMENT_NODE); michael@0: NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); michael@0: michael@0: nsresult rv = NS_NewXULElement(getter_AddRefs(mPopupgroupContent), michael@0: nodeInfo.forget()); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: if (!aElements.AppendElement(mPopupgroupContent)) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: // create the top-secret default tooltip node. shhhhh! michael@0: nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::tooltip, nullptr, michael@0: kNameSpaceID_XUL, michael@0: nsIDOMNode::ELEMENT_NODE); michael@0: NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); michael@0: michael@0: rv = NS_NewXULElement(getter_AddRefs(mTooltipContent), nodeInfo.forget()); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default, michael@0: NS_LITERAL_STRING("true"), false); michael@0: michael@0: if (!aElements.AppendElement(mTooltipContent)) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: nsDocElementBoxFrame::AppendAnonymousContentTo(nsBaseContentList& aElements, michael@0: uint32_t aFilter) michael@0: { michael@0: aElements.MaybeAppendElement(mPopupgroupContent); michael@0: aElements.MaybeAppendElement(mTooltipContent); michael@0: } michael@0: michael@0: NS_QUERYFRAME_HEAD(nsDocElementBoxFrame) michael@0: NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator) michael@0: NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame) michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: nsresult michael@0: nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult); michael@0: } michael@0: #endif