layout/xul/nsDocElementBoxFrame.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial