layout/xul/nsDocElementBoxFrame.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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 "nsINodeInfo.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"
    25 //#define DEBUG_REFLOW
    27 using namespace mozilla::dom;
    29 class nsDocElementBoxFrame : public nsBoxFrame,
    30                              public nsIAnonymousContentCreator
    31 {
    32 public:
    33   virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    35   friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    36                                   nsStyleContext* aContext);
    38   nsDocElementBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext)
    39     :nsBoxFrame(aShell, aContext, true) {}
    41   NS_DECL_QUERYFRAME
    42   NS_DECL_FRAMEARENA_HELPERS
    44   // nsIAnonymousContentCreator
    45   virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
    46   virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
    47                                         uint32_t aFilter) MOZ_OVERRIDE;
    49   virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
    50   {
    51     // Override nsBoxFrame.
    52     if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
    53       return false;
    54     return nsBoxFrame::IsFrameOfType(aFlags);
    55   }
    57 #ifdef DEBUG_FRAME_DUMP
    58   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
    59 #endif
    60 private:
    61   nsCOMPtr<Element> mPopupgroupContent;
    62   nsCOMPtr<Element> mTooltipContent;
    63 };
    65 //----------------------------------------------------------------------
    67 nsIFrame*
    68 NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    69 {
    70   return new (aPresShell) nsDocElementBoxFrame (aPresShell, aContext);
    71 }
    73 NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame)
    75 void
    76 nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
    77 {
    78   nsContentUtils::DestroyAnonymousContent(&mPopupgroupContent);
    79   nsContentUtils::DestroyAnonymousContent(&mTooltipContent);
    80   nsBoxFrame::DestroyFrom(aDestructRoot);
    81 }
    83 nsresult
    84 nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
    85 {
    86   nsIDocument* doc = mContent->GetDocument();
    87   if (!doc) {
    88     // The page is currently being torn down.  Why bother.
    89     return NS_ERROR_FAILURE;
    90   }
    91   nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager();
    93   // create the top-secret popupgroup node. shhhhh!
    94   nsCOMPtr<nsINodeInfo> nodeInfo;
    95   nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::popupgroup,
    96                                           nullptr, kNameSpaceID_XUL,
    97                                           nsIDOMNode::ELEMENT_NODE);
    98   NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
   100   nsresult rv = NS_NewXULElement(getter_AddRefs(mPopupgroupContent),
   101                                  nodeInfo.forget());
   102   NS_ENSURE_SUCCESS(rv, rv);
   104   if (!aElements.AppendElement(mPopupgroupContent))
   105     return NS_ERROR_OUT_OF_MEMORY;
   107   // create the top-secret default tooltip node. shhhhh!
   108   nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::tooltip, nullptr,
   109                                           kNameSpaceID_XUL,
   110                                           nsIDOMNode::ELEMENT_NODE);
   111   NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
   113   rv = NS_NewXULElement(getter_AddRefs(mTooltipContent), nodeInfo.forget());
   114   NS_ENSURE_SUCCESS(rv, rv);
   116   mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default,
   117                            NS_LITERAL_STRING("true"), false);
   119   if (!aElements.AppendElement(mTooltipContent))
   120     return NS_ERROR_OUT_OF_MEMORY;
   122   return NS_OK;
   123 }
   125 void
   126 nsDocElementBoxFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
   127                                                uint32_t aFilter)
   128 {
   129   aElements.MaybeAppendElement(mPopupgroupContent);
   130   aElements.MaybeAppendElement(mTooltipContent);
   131 }
   133 NS_QUERYFRAME_HEAD(nsDocElementBoxFrame)
   134   NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
   135 NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
   137 #ifdef DEBUG_FRAME_DUMP
   138 nsresult
   139 nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const
   140 {
   141   return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult);
   142 }
   143 #endif

mercurial