nsDocElementBoxFrame.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsHTMLParts.h"
  6. #include "nsContainerFrame.h"
  7. #include "nsCSSRendering.h"
  8. #include "nsIDocument.h"
  9. #include "nsPageFrame.h"
  10. #include "nsIDOMEvent.h"
  11. #include "nsStyleConsts.h"
  12. #include "nsGkAtoms.h"
  13. #include "nsIPresShell.h"
  14. #include "nsBoxFrame.h"
  15. #include "nsStackLayout.h"
  16. #include "nsIAnonymousContentCreator.h"
  17. #include "mozilla/dom/NodeInfo.h"
  18. #include "nsIServiceManager.h"
  19. #include "nsNodeInfoManager.h"
  20. #include "nsContentCreatorFunctions.h"
  21. #include "nsContentUtils.h"
  22. #include "nsContentList.h"
  23. #include "mozilla/dom/Element.h"
  24. //#define DEBUG_REFLOW
  25. using namespace mozilla::dom;
  26. class nsDocElementBoxFrame : public nsBoxFrame,
  27. public nsIAnonymousContentCreator
  28. {
  29. public:
  30. virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
  31. friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
  32. nsStyleContext* aContext);
  33. explicit nsDocElementBoxFrame(nsStyleContext* aContext)
  34. :nsBoxFrame(aContext, true) {}
  35. NS_DECL_QUERYFRAME
  36. NS_DECL_FRAMEARENA_HELPERS
  37. // nsIAnonymousContentCreator
  38. virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
  39. virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
  40. uint32_t aFilter) override;
  41. virtual bool IsFrameOfType(uint32_t aFlags) const override
  42. {
  43. // Override nsBoxFrame.
  44. if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
  45. return false;
  46. return nsBoxFrame::IsFrameOfType(aFlags);
  47. }
  48. #ifdef DEBUG_FRAME_DUMP
  49. virtual nsresult GetFrameName(nsAString& aResult) const override;
  50. #endif
  51. private:
  52. nsCOMPtr<Element> mPopupgroupContent;
  53. nsCOMPtr<Element> mTooltipContent;
  54. };
  55. //----------------------------------------------------------------------
  56. nsContainerFrame*
  57. NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
  58. {
  59. return new (aPresShell) nsDocElementBoxFrame(aContext);
  60. }
  61. NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame)
  62. void
  63. nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
  64. {
  65. nsContentUtils::DestroyAnonymousContent(&mPopupgroupContent);
  66. nsContentUtils::DestroyAnonymousContent(&mTooltipContent);
  67. nsBoxFrame::DestroyFrom(aDestructRoot);
  68. }
  69. nsresult
  70. nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
  71. {
  72. nsIDocument* doc = mContent->GetComposedDoc();
  73. if (!doc) {
  74. // The page is currently being torn down. Why bother.
  75. return NS_ERROR_FAILURE;
  76. }
  77. nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager();
  78. // create the top-secret popupgroup node. shhhhh!
  79. RefPtr<NodeInfo> nodeInfo;
  80. nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::popupgroup,
  81. nullptr, kNameSpaceID_XUL,
  82. nsIDOMNode::ELEMENT_NODE);
  83. NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
  84. nsresult rv = NS_NewXULElement(getter_AddRefs(mPopupgroupContent),
  85. nodeInfo.forget());
  86. NS_ENSURE_SUCCESS(rv, rv);
  87. if (!aElements.AppendElement(mPopupgroupContent))
  88. return NS_ERROR_OUT_OF_MEMORY;
  89. // create the top-secret default tooltip node. shhhhh!
  90. nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::tooltip, nullptr,
  91. kNameSpaceID_XUL,
  92. nsIDOMNode::ELEMENT_NODE);
  93. NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
  94. rv = NS_NewXULElement(getter_AddRefs(mTooltipContent), nodeInfo.forget());
  95. NS_ENSURE_SUCCESS(rv, rv);
  96. mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default,
  97. NS_LITERAL_STRING("true"), false);
  98. if (!aElements.AppendElement(mTooltipContent))
  99. return NS_ERROR_OUT_OF_MEMORY;
  100. return NS_OK;
  101. }
  102. void
  103. nsDocElementBoxFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
  104. uint32_t aFilter)
  105. {
  106. if (mPopupgroupContent) {
  107. aElements.AppendElement(mPopupgroupContent);
  108. }
  109. if (mTooltipContent) {
  110. aElements.AppendElement(mTooltipContent);
  111. }
  112. }
  113. NS_QUERYFRAME_HEAD(nsDocElementBoxFrame)
  114. NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
  115. NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
  116. #ifdef DEBUG_FRAME_DUMP
  117. nsresult
  118. nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const
  119. {
  120. return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult);
  121. }
  122. #endif