Back to index

lightning-sunbird  0.9+nobinonly
nsDocElementBoxFrame.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "nsHTMLParts.h"
00038 #include "nsContainerFrame.h"
00039 #include "nsCSSRendering.h"
00040 #include "nsIDocument.h"
00041 #include "nsPresContext.h"
00042 #include "nsViewsCID.h"
00043 #include "nsIView.h"
00044 #include "nsIViewManager.h"
00045 #include "nsIWidget.h"
00046 #include "nsPageFrame.h"
00047 #include "nsIRenderingContext.h"
00048 #include "nsGUIEvent.h"
00049 #include "nsIDOMEvent.h"
00050 #include "nsStyleConsts.h"
00051 #include "nsIViewManager.h"
00052 #include "nsHTMLAtoms.h"
00053 #include "nsXULAtoms.h"
00054 #include "nsIEventStateManager.h"
00055 #include "nsIDeviceContext.h"
00056 #include "nsIScrollableView.h"
00057 #include "nsLayoutAtoms.h"
00058 #include "nsIPresShell.h"
00059 #include "nsBoxFrame.h"
00060 #include "nsStackLayout.h"
00061 #include "nsIRootBox.h"
00062 #include "nsIAnonymousContentCreator.h"
00063 #include "nsINodeInfo.h"
00064 #include "nsIServiceManager.h"
00065 #include "nsISupportsArray.h"
00066 #include "nsNodeInfoManager.h"
00067 #include "nsContentCreatorFunctions.h"
00068 
00069 // Interface IDs
00070 
00071 //#define DEBUG_REFLOW
00072 
00073 class nsDocElementBoxFrame : public nsBoxFrame, public nsIAnonymousContentCreator {
00074 public:
00075 
00076   friend nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
00077 
00078   nsDocElementBoxFrame(nsIPresShell* aShell);
00079 
00080   NS_DECL_ISUPPORTS_INHERITED
00081 
00082   // nsIAnonymousContentCreator
00083   NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,
00084                                     nsISupportsArray& aAnonymousItems);
00085   NS_IMETHOD CreateFrameFor(nsPresContext*   aPresContext,
00086                             nsIContent *      aContent,
00087                             nsIFrame**        aFrame) { if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; }
00088 
00089 #ifdef DEBUG
00090   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00091 #endif
00092 };
00093 
00094 //----------------------------------------------------------------------
00095 
00096 nsresult
00097 NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
00098 {
00099   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00100   if (nsnull == aNewFrame) {
00101     return NS_ERROR_NULL_POINTER;
00102   }
00103   nsDocElementBoxFrame* it = new (aPresShell) nsDocElementBoxFrame (aPresShell);
00104   if (nsnull == it) {
00105     return NS_ERROR_OUT_OF_MEMORY;
00106   }
00107 
00108   *aNewFrame = it;
00109 
00110   return NS_OK;
00111 }
00112 
00113 nsDocElementBoxFrame::nsDocElementBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell, PR_TRUE)
00114 {
00115 }
00116 
00117 NS_IMETHODIMP
00118 nsDocElementBoxFrame::CreateAnonymousContent(nsPresContext* aPresContext,
00119                                        nsISupportsArray& aAnonymousItems)
00120 {
00121   nsIDocument* doc = mContent->GetDocument();
00122   if (!doc)
00123     // The page is currently being torn down.  Why bother.
00124     return NS_ERROR_FAILURE;
00125   nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager();
00126 
00127   // create the top-secret popupgroup node. shhhhh!
00128   nsCOMPtr<nsINodeInfo> nodeInfo;
00129   nsresult rv = nodeInfoManager->GetNodeInfo(nsXULAtoms::popupgroup,
00130                                              nsnull, kNameSpaceID_XUL,
00131                                              getter_AddRefs(nodeInfo));
00132   NS_ENSURE_SUCCESS(rv, rv);
00133 
00134   nsCOMPtr<nsIContent> content;
00135   rv = NS_NewXULElement(getter_AddRefs(content), nodeInfo);
00136   NS_ENSURE_SUCCESS(rv, rv);
00137 
00138   aAnonymousItems.AppendElement(content);
00139 
00140   // create the top-secret default tooltip node. shhhhh!
00141   rv = nodeInfoManager->GetNodeInfo(nsXULAtoms::tooltip, nsnull,
00142                                     kNameSpaceID_XUL, getter_AddRefs(nodeInfo));
00143   NS_ENSURE_SUCCESS(rv, rv);
00144 
00145   rv = NS_NewXULElement(getter_AddRefs(content), nodeInfo);
00146   NS_ENSURE_SUCCESS(rv, rv);
00147 
00148   content->SetAttr(nsnull, nsXULAtoms::defaultz, NS_LITERAL_STRING("true"), PR_FALSE);
00149   aAnonymousItems.AppendElement(content);
00150   
00151   return NS_OK;
00152 }
00153 
00154 NS_IMETHODIMP_(nsrefcnt) 
00155 nsDocElementBoxFrame::AddRef(void)
00156 {
00157   return NS_OK;
00158 }
00159 
00160 NS_IMETHODIMP_(nsrefcnt)
00161 nsDocElementBoxFrame::Release(void)
00162 {
00163   return NS_OK;
00164 }
00165 
00166 NS_INTERFACE_MAP_BEGIN(nsDocElementBoxFrame)
00167   NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
00168 NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
00169 
00170 #ifdef DEBUG
00171 NS_IMETHODIMP
00172 nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const
00173 {
00174   return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult);
00175 }
00176 #endif