Back to index

lightning-sunbird  0.9+nobinonly
nsSplittableFrame.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 "nsSplittableFrame.h"
00038 #include "nsIContent.h"
00039 #include "nsPresContext.h"
00040 #include "nsStyleContext.h"
00041 
00042 NS_IMETHODIMP
00043 nsSplittableFrame::Init(nsPresContext*  aPresContext,
00044                         nsIContent*      aContent,
00045                         nsIFrame*        aParent,
00046                         nsStyleContext*  aContext,
00047                         nsIFrame*        aPrevInFlow)
00048 {
00049   nsresult  rv;
00050   
00051   rv = nsFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
00052 
00053   if (aPrevInFlow) {
00054     // Hook the frame into the flow
00055     mPrevInFlow = aPrevInFlow;
00056     aPrevInFlow->SetNextInFlow(this);
00057   }
00058 
00059   return rv;
00060 }
00061 
00062 NS_IMETHODIMP
00063 nsSplittableFrame::Destroy(nsPresContext* aPresContext)
00064 {
00065   // Disconnect from the flow list
00066   if (mPrevInFlow || mNextInFlow) {
00067     RemoveFromFlow(this);
00068   }
00069 
00070   // Let the base class destroy the frame
00071   return nsFrame::Destroy(aPresContext);
00072 }
00073 
00074 NS_IMETHODIMP
00075 nsSplittableFrame::IsSplittable(nsSplittableType& aIsSplittable) const
00076 {
00077   aIsSplittable = NS_FRAME_SPLITTABLE;
00078   return NS_OK;
00079 }
00080 
00081 nsIFrame* nsSplittableFrame::GetPrevInFlow() const
00082 {
00083   return mPrevInFlow;
00084 }
00085 
00086 NS_METHOD nsSplittableFrame::SetPrevInFlow(nsIFrame* aFrame)
00087 {
00088   mPrevInFlow = aFrame;
00089   return NS_OK;
00090 }
00091 
00092 nsIFrame* nsSplittableFrame::GetNextInFlow() const
00093 {
00094   return mNextInFlow;
00095 }
00096 
00097 NS_METHOD nsSplittableFrame::SetNextInFlow(nsIFrame* aFrame)
00098 {
00099   mNextInFlow = aFrame;
00100   return NS_OK;
00101 }
00102 
00103 nsIFrame* nsSplittableFrame::GetFirstInFlow() const
00104 {
00105   nsSplittableFrame* firstInFlow = (nsSplittableFrame*)this;
00106   while (firstInFlow->mPrevInFlow)  {
00107     firstInFlow = (nsSplittableFrame*)firstInFlow->mPrevInFlow;
00108   }
00109   NS_POSTCONDITION(firstInFlow, "illegal state in flow chain.");
00110   return firstInFlow;
00111 }
00112 
00113 nsIFrame* nsSplittableFrame::GetLastInFlow() const
00114 {
00115   nsSplittableFrame* lastInFlow = (nsSplittableFrame*)this;
00116   while (lastInFlow->mNextInFlow)  {
00117     lastInFlow = (nsSplittableFrame*)lastInFlow->mNextInFlow;
00118   }
00119   NS_POSTCONDITION(lastInFlow, "illegal state in flow chain.");
00120   return lastInFlow;
00121 }
00122 
00123 // Remove this frame from the flow. Connects prev in flow and next in flow
00124 void
00125 nsSplittableFrame::RemoveFromFlow(nsIFrame* aFrame)
00126 {
00127   nsIFrame* prevInFlow = aFrame->GetPrevInFlow();
00128   nsIFrame* nextInFlow = aFrame->GetNextInFlow();
00129 
00130   if (prevInFlow) {
00131     prevInFlow->SetNextInFlow(nextInFlow);
00132   }
00133 
00134   if (nextInFlow) {
00135     nextInFlow->SetPrevInFlow(prevInFlow);
00136   }
00137 
00138   aFrame->SetPrevInFlow(nsnull);
00139   aFrame->SetNextInFlow(nsnull);
00140 }
00141 
00142 // Detach from previous frame in flow
00143 void
00144 nsSplittableFrame::BreakFromPrevFlow(nsIFrame* aFrame)
00145 {
00146   nsIFrame* prevInFlow = aFrame->GetPrevInFlow();
00147   if (prevInFlow) {
00148     prevInFlow->SetNextInFlow(nsnull);
00149     aFrame->SetPrevInFlow(nsnull);
00150   }
00151 }
00152 
00153 #ifdef DEBUG
00154 void
00155 nsSplittableFrame::DumpBaseRegressionData(nsPresContext* aPresContext, FILE* out, PRInt32 aIndent, PRBool aIncludeStyleData)
00156 {
00157   nsFrame::DumpBaseRegressionData(aPresContext, out, aIndent, aIncludeStyleData);
00158   if (nsnull != mNextInFlow) {
00159     IndentBy(out, aIndent);
00160     fprintf(out, "<next-in-flow va=\"%ld\"/>\n", PRUptrdiff(mNextInFlow));
00161   }
00162   if (nsnull != mPrevInFlow) {
00163     IndentBy(out, aIndent);
00164     fprintf(out, "<prev-in-flow va=\"%ld\"/>\n", PRUptrdiff(mPrevInFlow));
00165   }
00166 
00167 }
00168 #endif