Back to index

lightning-sunbird  0.9+nobinonly
nsPlaceholderFrame.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 "nsPlaceholderFrame.h"
00038 #include "nsLineLayout.h"
00039 #include "nsIContent.h"
00040 #include "nsPresContext.h"
00041 #include "nsIRenderingContext.h"
00042 #include "nsLayoutAtoms.h"
00043 #include "nsFrameManager.h"
00044 
00045 nsresult
00046 NS_NewPlaceholderFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
00047 {
00048   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00049   if (nsnull == aNewFrame) {
00050     return NS_ERROR_NULL_POINTER;
00051   }
00052   nsPlaceholderFrame* it = new (aPresShell) nsPlaceholderFrame;
00053   if (nsnull == it) {
00054     return NS_ERROR_OUT_OF_MEMORY;
00055   }
00056   *aNewFrame = it;
00057   return NS_OK;
00058 }
00059 
00060 // These are useful for debugging
00061 nsPlaceholderFrame::nsPlaceholderFrame()
00062 {
00063 }
00064 
00065 nsPlaceholderFrame::~nsPlaceholderFrame()
00066 {
00067 }
00068 
00069 NS_IMETHODIMP
00070 nsPlaceholderFrame::Reflow(nsPresContext*          aPresContext,
00071                            nsHTMLReflowMetrics&     aDesiredSize,
00072                            const nsHTMLReflowState& aReflowState,
00073                            nsReflowStatus&          aStatus)
00074 {
00075   DO_GLOBAL_REFLOW_COUNT("nsPlaceholderFrame", aReflowState.reason);
00076   DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
00077   aDesiredSize.width = 0;
00078   aDesiredSize.height = 0;
00079   aDesiredSize.ascent = 0;
00080   aDesiredSize.descent = 0;
00081   if (aDesiredSize.mComputeMEW) {
00082     aDesiredSize.mMaxElementWidth = 0;
00083   }
00084 
00085   aStatus = NS_FRAME_COMPLETE;
00086   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
00087   return NS_OK;
00088 }
00089 
00090 NS_IMETHODIMP
00091 nsPlaceholderFrame::Destroy(nsPresContext* aPresContext)
00092 {
00093   nsIPresShell* shell = aPresContext->GetPresShell();
00094   if (shell && mOutOfFlowFrame) {
00095     NS_ASSERTION(!shell->FrameManager()->GetPlaceholderFrameFor(mOutOfFlowFrame),
00096                  "Placeholder relationship should have been torn down");
00097   }
00098 
00099   return nsSplittableFrame::Destroy(aPresContext);
00100 }
00101 
00102 nsIAtom*
00103 nsPlaceholderFrame::GetType() const
00104 {
00105   return nsLayoutAtoms::placeholderFrame; 
00106 }
00107 
00108 #ifdef DEBUG
00109 NS_IMETHODIMP
00110 nsPlaceholderFrame::Paint(nsPresContext*      aPresContext,
00111                           nsIRenderingContext& aRenderingContext,
00112                           const nsRect&        aDirtyRect,
00113                           nsFramePaintLayer    aWhichLayer,
00114                           PRUint32             aFlags)
00115 {
00116   if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
00117     float p2t;
00118     p2t = aPresContext->PixelsToTwips();
00119     aRenderingContext.SetColor(NS_RGB(0, 255, 255));
00120     nscoord x = NSIntPixelsToTwips(-5, p2t);
00121     aRenderingContext.FillRect(x, 0, NSIntPixelsToTwips(13, p2t),
00122                                NSIntPixelsToTwips(3, p2t));
00123     nscoord y = NSIntPixelsToTwips(-10, p2t);
00124     aRenderingContext.FillRect(0, y, NSIntPixelsToTwips(3, p2t),
00125                                NSIntPixelsToTwips(10, p2t));
00126   }
00127   DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame", &aRenderingContext);
00128   return NS_OK;
00129 }
00130 
00131 NS_IMETHODIMP
00132 nsPlaceholderFrame::GetFrameName(nsAString& aResult) const
00133 {
00134   return MakeFrameName(NS_LITERAL_STRING("Placeholder"), aResult);
00135 }
00136 
00137 NS_IMETHODIMP
00138 nsPlaceholderFrame::List(nsPresContext* aPresContext, FILE* out, PRInt32 aIndent) const
00139 {
00140   IndentBy(out, aIndent);
00141   ListTag(out);
00142 #ifdef DEBUG_waterson
00143   fprintf(out, " [parent=%p]", NS_STATIC_CAST(void*, mParent));
00144 #endif
00145   if (HasView()) {
00146     fprintf(out, " [view=%p]", (void*)GetView());
00147   }
00148   fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
00149   if (0 != mState) {
00150     fprintf(out, " [state=%08x]", mState);
00151   }
00152   nsIFrame* prevInFlow = GetPrevInFlow();
00153   nsIFrame* nextInFlow = GetNextInFlow();
00154   if (nsnull != prevInFlow) {
00155     fprintf(out, " prev-in-flow=%p", NS_STATIC_CAST(void*, prevInFlow));
00156   }
00157   if (nsnull != nextInFlow) {
00158     fprintf(out, " next-in-flow=%p", NS_STATIC_CAST(void*, nextInFlow));
00159   }
00160   if (mOutOfFlowFrame) {
00161     fprintf(out, " outOfFlowFrame=");
00162     nsFrame::ListTag(out, mOutOfFlowFrame);
00163   }
00164   fputs("\n", out);
00165   return NS_OK;
00166 }
00167 #endif