layout/xul/nsDocElementBoxFrame.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsDocElementBoxFrame.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#include "nsHTMLParts.h"
     1.9 +#include "nsContainerFrame.h"
    1.10 +#include "nsCSSRendering.h"
    1.11 +#include "nsIDocument.h"
    1.12 +#include "nsPageFrame.h"
    1.13 +#include "nsIDOMEvent.h"
    1.14 +#include "nsStyleConsts.h"
    1.15 +#include "nsGkAtoms.h"
    1.16 +#include "nsIPresShell.h"
    1.17 +#include "nsBoxFrame.h"
    1.18 +#include "nsStackLayout.h"
    1.19 +#include "nsIAnonymousContentCreator.h"
    1.20 +#include "nsINodeInfo.h"
    1.21 +#include "nsIServiceManager.h"
    1.22 +#include "nsNodeInfoManager.h"
    1.23 +#include "nsContentCreatorFunctions.h"
    1.24 +#include "nsContentUtils.h"
    1.25 +#include "nsContentList.h"
    1.26 +#include "mozilla/dom/Element.h"
    1.27 +
    1.28 +//#define DEBUG_REFLOW
    1.29 +
    1.30 +using namespace mozilla::dom;
    1.31 +
    1.32 +class nsDocElementBoxFrame : public nsBoxFrame,
    1.33 +                             public nsIAnonymousContentCreator
    1.34 +{
    1.35 +public:
    1.36 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.37 +
    1.38 +  friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    1.39 +                                  nsStyleContext* aContext);
    1.40 +
    1.41 +  nsDocElementBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext)
    1.42 +    :nsBoxFrame(aShell, aContext, true) {}
    1.43 +
    1.44 +  NS_DECL_QUERYFRAME
    1.45 +  NS_DECL_FRAMEARENA_HELPERS
    1.46 +
    1.47 +  // nsIAnonymousContentCreator
    1.48 +  virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
    1.49 +  virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
    1.50 +                                        uint32_t aFilter) MOZ_OVERRIDE;
    1.51 +
    1.52 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
    1.53 +  {
    1.54 +    // Override nsBoxFrame.
    1.55 +    if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
    1.56 +      return false;
    1.57 +    return nsBoxFrame::IsFrameOfType(aFlags);
    1.58 +  }
    1.59 +
    1.60 +#ifdef DEBUG_FRAME_DUMP
    1.61 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
    1.62 +#endif
    1.63 +private:
    1.64 +  nsCOMPtr<Element> mPopupgroupContent;
    1.65 +  nsCOMPtr<Element> mTooltipContent;
    1.66 +};
    1.67 +
    1.68 +//----------------------------------------------------------------------
    1.69 +
    1.70 +nsIFrame*
    1.71 +NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    1.72 +{
    1.73 +  return new (aPresShell) nsDocElementBoxFrame (aPresShell, aContext);
    1.74 +}
    1.75 +
    1.76 +NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame)
    1.77 +
    1.78 +void
    1.79 +nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
    1.80 +{
    1.81 +  nsContentUtils::DestroyAnonymousContent(&mPopupgroupContent);
    1.82 +  nsContentUtils::DestroyAnonymousContent(&mTooltipContent);
    1.83 +  nsBoxFrame::DestroyFrom(aDestructRoot);
    1.84 +}
    1.85 +
    1.86 +nsresult
    1.87 +nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
    1.88 +{
    1.89 +  nsIDocument* doc = mContent->GetDocument();
    1.90 +  if (!doc) {
    1.91 +    // The page is currently being torn down.  Why bother.
    1.92 +    return NS_ERROR_FAILURE;
    1.93 +  }
    1.94 +  nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager();
    1.95 +
    1.96 +  // create the top-secret popupgroup node. shhhhh!
    1.97 +  nsCOMPtr<nsINodeInfo> nodeInfo;
    1.98 +  nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::popupgroup,
    1.99 +                                          nullptr, kNameSpaceID_XUL,
   1.100 +                                          nsIDOMNode::ELEMENT_NODE);
   1.101 +  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
   1.102 +
   1.103 +  nsresult rv = NS_NewXULElement(getter_AddRefs(mPopupgroupContent),
   1.104 +                                 nodeInfo.forget());
   1.105 +  NS_ENSURE_SUCCESS(rv, rv);
   1.106 +
   1.107 +  if (!aElements.AppendElement(mPopupgroupContent))
   1.108 +    return NS_ERROR_OUT_OF_MEMORY;
   1.109 +
   1.110 +  // create the top-secret default tooltip node. shhhhh!
   1.111 +  nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::tooltip, nullptr,
   1.112 +                                          kNameSpaceID_XUL,
   1.113 +                                          nsIDOMNode::ELEMENT_NODE);
   1.114 +  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
   1.115 +
   1.116 +  rv = NS_NewXULElement(getter_AddRefs(mTooltipContent), nodeInfo.forget());
   1.117 +  NS_ENSURE_SUCCESS(rv, rv);
   1.118 +
   1.119 +  mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default,
   1.120 +                           NS_LITERAL_STRING("true"), false);
   1.121 +
   1.122 +  if (!aElements.AppendElement(mTooltipContent))
   1.123 +    return NS_ERROR_OUT_OF_MEMORY;
   1.124 +
   1.125 +  return NS_OK;
   1.126 +}
   1.127 +
   1.128 +void
   1.129 +nsDocElementBoxFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
   1.130 +                                               uint32_t aFilter)
   1.131 +{
   1.132 +  aElements.MaybeAppendElement(mPopupgroupContent);
   1.133 +  aElements.MaybeAppendElement(mTooltipContent);
   1.134 +}
   1.135 +
   1.136 +NS_QUERYFRAME_HEAD(nsDocElementBoxFrame)
   1.137 +  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
   1.138 +NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
   1.139 +
   1.140 +#ifdef DEBUG_FRAME_DUMP
   1.141 +nsresult
   1.142 +nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const
   1.143 +{
   1.144 +  return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult);
   1.145 +}
   1.146 +#endif

mercurial