Back to index

lightning-sunbird  0.9+nobinonly
nsStackFrame.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 Communicator client 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 
00038 //
00039 // Eric Vaughan
00040 // Netscape Communications
00041 //
00042 // See documentation in associated header file
00043 //
00044 
00045 #include "nsStackFrame.h"
00046 #include "nsStyleContext.h"
00047 #include "nsPresContext.h"
00048 #include "nsIContent.h"
00049 #include "nsCOMPtr.h"
00050 #include "nsUnitConversion.h"
00051 #include "nsXULAtoms.h"
00052 #include "nsHTMLAtoms.h"
00053 #include "nsHTMLParts.h"
00054 #include "nsIPresShell.h"
00055 #include "nsStyleChangeList.h"
00056 #include "nsCSSRendering.h"
00057 #include "nsIViewManager.h"
00058 #include "nsBoxLayoutState.h"
00059 #include "nsStackLayout.h"
00060 
00061 nsresult
00062 NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager)
00063 {
00064   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00065   if (nsnull == aNewFrame) {
00066     return NS_ERROR_NULL_POINTER;
00067   }
00068   nsStackFrame* it = new (aPresShell) nsStackFrame(aPresShell, aLayoutManager);
00069   if (nsnull == it)
00070     return NS_ERROR_OUT_OF_MEMORY;
00071 
00072   *aNewFrame = it;
00073 
00074   return NS_OK;
00075   
00076 } // NS_NewStackFrame
00077 
00078 nsStackFrame::nsStackFrame(nsIPresShell* aPresShell, nsIBoxLayout* aLayoutManager):nsBoxFrame(aPresShell)
00079 {
00080     // if no layout manager specified us the stack layout
00081   nsCOMPtr<nsIBoxLayout> layout = aLayoutManager;
00082 
00083   if (layout == nsnull) {
00084     NS_NewStackLayout(aPresShell, layout);
00085   }
00086 
00087   SetLayoutManager(layout);
00088 }
00089 
00090 
00091 NS_IMETHODIMP  
00092 nsStackFrame::GetFrameForPoint(const nsPoint& aPoint, 
00093                                nsFramePaintLayer aWhichLayer,    
00094                                nsIFrame** aFrame)
00095 {
00096   if (aWhichLayer != NS_FRAME_PAINT_LAYER_BACKGROUND)
00097     return NS_ERROR_FAILURE;
00098 
00099   return nsBoxFrame::GetFrameForPoint(aPoint, aWhichLayer, aFrame);
00100 }
00101 
00102 /* virtual */ nsresult
00103 nsStackFrame::GetFrameForPointChild(const nsPoint&    aPoint,
00104                                     nsFramePaintLayer aWhichLayer,    
00105                                     nsIFrame*         aChild,
00106                                     PRBool            aCheckMouseThrough,
00107                                     nsIFrame**        aFrame)
00108 {
00109   if (aWhichLayer != NS_FRAME_PAINT_LAYER_BACKGROUND)
00110     return NS_ERROR_FAILURE;
00111 
00112   nsresult rv = nsBoxFrame::GetFrameForPointChild(aPoint,
00113                                            NS_FRAME_PAINT_LAYER_FOREGROUND,
00114                                            aChild, aCheckMouseThrough, aFrame);
00115   if (NS_SUCCEEDED(rv))
00116     return rv;
00117   return nsBoxFrame::GetFrameForPointChild(aPoint,
00118                                            NS_FRAME_PAINT_LAYER_BACKGROUND,
00119                                            aChild, aCheckMouseThrough, aFrame);
00120 }
00121 
00122 void
00123 nsStackFrame::PaintChildren(nsPresContext*      aPresContext,
00124                             nsIRenderingContext& aRenderingContext,
00125                             const nsRect&        aDirtyRect,
00126                             nsFramePaintLayer    aWhichLayer,
00127                             PRUint32             aFlags)
00128 {
00129   // we need to make sure we paint background then foreground of each child because they
00130   // are stacked. Otherwise the foreground of the first child could be on the top of the
00131   // background of the second.
00132   if (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND)
00133   {
00134       nsBoxFrame::PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
00135   }
00136 }
00137 
00138 // Paint one child frame
00139 void
00140 nsStackFrame::PaintChild(nsPresContext*      aPresContext,
00141                          nsIRenderingContext& aRenderingContext,
00142                          const nsRect&        aDirtyRect,
00143                          nsIFrame*            aFrame,
00144                          nsFramePaintLayer    aWhichLayer,
00145                          PRUint32             aFlags)
00146 {
00147   // we need to make sure we paint background then foreground of each child because they
00148   // are stacked. Otherwise the foreground of the first child could be on the top of the
00149   // background of the second.
00150   if (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND)
00151   {
00152     nsBoxFrame::PaintChild(aPresContext, aRenderingContext, aDirtyRect, aFrame, NS_FRAME_PAINT_LAYER_BACKGROUND);
00153     nsBoxFrame::PaintChild(aPresContext, aRenderingContext, aDirtyRect, aFrame, NS_FRAME_PAINT_LAYER_FOREGROUND);
00154   } 
00155 }