Back to index

lightning-sunbird  0.9+nobinonly
nsIFrame.h
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 
00038 #ifndef nsIFrame_h___
00039 #define nsIFrame_h___
00040 
00041 /* nsIFrame is in the process of being deCOMtaminated, i.e., this file is eventually
00042    going to be eliminated, and all callers will use nsFrame instead.  At the moment
00043    we're midway through this process, so you will see inlined functions and member
00044    variables in this file.  -dwh */
00045 
00046 #include <stdio.h>
00047 #include "nsISupports.h"
00048 #include "nsEvent.h"
00049 #include "nsStyleStruct.h"
00050 #include "nsStyleContext.h"
00051 #include "nsIContent.h"
00052 #include "nsHTMLReflowMetrics.h"
00053 
00071 struct nsHTMLReflowState;
00072 class nsHTMLReflowCommand;
00073 
00074 class nsIAtom;
00075 class nsPresContext;
00076 class nsIPresShell;
00077 class nsIRenderingContext;
00078 class nsIView;
00079 class nsIWidget;
00080 class nsIDOMRange;
00081 class nsISelectionController;
00082 class nsBoxLayoutState;
00083 class nsIBoxLayout;
00084 #ifdef ACCESSIBILITY
00085 class nsIAccessible;
00086 #endif
00087 
00088 struct nsPeekOffsetStruct;
00089 struct nsPoint;
00090 struct nsRect;
00091 struct nsSize;
00092 struct nsMargin;
00093 
00094 typedef class nsIFrame nsIBox;
00095 
00096 // IID for the nsIFrame interface 
00097 // 2fb5effc-5eeb-4ccb-b9fa-325f8642200f
00098 #define NS_IFRAME_IID \
00099 { 0x2fb5effc, 0x5eeb, 0x4ccb, \
00100   { 0xb9, 0xfa, 0x32, 0x5f, 0x86, 0x42, 0x20, 0x0f } }
00101 
00115 typedef PRUint32 nsSplittableType;
00116 
00117 #define NS_FRAME_NOT_SPLITTABLE             0   // Note: not a bit!
00118 #define NS_FRAME_SPLITTABLE                 0x1
00119 #define NS_FRAME_SPLITTABLE_NON_RECTANGULAR 0x3
00120 
00121 #define NS_FRAME_IS_SPLITTABLE(type)\
00122   (0 != ((type) & NS_FRAME_SPLITTABLE))
00123 
00124 #define NS_FRAME_IS_NOT_SPLITTABLE(type)\
00125   (0 == ((type) & NS_FRAME_SPLITTABLE))
00126 
00127 //----------------------------------------------------------------------
00128 
00133 typedef PRUint32 nsFrameState;
00134 
00135 #define NS_FRAME_IN_REFLOW                            0x00000001
00136 
00137 // This bit is set when a frame is created. After it has been reflowed
00138 // once (during the DidReflow with a finished state) the bit is
00139 // cleared.
00140 #define NS_FRAME_FIRST_REFLOW                         0x00000002
00141 
00142 // If this bit is set, then there is a child frame in the frame that
00143 // extends outside this frame's bounding box. The implication is that
00144 // the frame's rect does not completely cover its children and
00145 // therefore operations like rendering and hit testing (for example)
00146 // must operate differently.
00147 #define NS_FRAME_OUTSIDE_CHILDREN                     0x00000008
00148 
00149 // If this bit is set, then a reference to the frame is being held
00150 // elsewhere.  The frame may want to send a notification when it is
00151 // destroyed to allow these references to be cleared.
00152 #define NS_FRAME_EXTERNAL_REFERENCE                   0x00000010
00153 
00154 // If this bit is set, then the frame is a replaced element. For example,
00155 // a frame displaying an image
00156 #define NS_FRAME_REPLACED_ELEMENT                     0x00000020
00157 
00158 // If this bit is set, then the frame corresponds to generated content
00159 #define NS_FRAME_GENERATED_CONTENT                    0x00000040
00160 
00161 // If this bit is set, then the frame uses XUL flexible box layout
00162 // for its children.
00163 #define NS_FRAME_IS_BOX                               0x00000080
00164 
00165 // If this bit is set, then the frame has been moved out of the flow,
00166 // e.g., it is absolutely positioned or floated
00167 #define NS_FRAME_OUT_OF_FLOW                          0x00000100
00168 
00169 // If this bit is set, then the frame reflects content that may be selected
00170 #define NS_FRAME_SELECTED_CONTENT                     0x00000200
00171 
00172 // If this bit is set, then the frame is dirty and needs to be reflowed.
00173 // This bit is set when the frame is first created
00174 #define NS_FRAME_IS_DIRTY                             0x00000400
00175 
00176 // If this bit is set then the frame is unflowable.
00177 #define NS_FRAME_IS_UNFLOWABLE                        0x00000800
00178 
00179 // If this bit is set, the frame has dirty children.
00180 #define NS_FRAME_HAS_DIRTY_CHILDREN                   0x00001000
00181 
00182 // If this bit is set, the frame has an associated view
00183 #define NS_FRAME_HAS_VIEW                             0x00002000
00184 
00185 // If this bit is set, the frame was created from anonymous content.
00186 #define NS_FRAME_INDEPENDENT_SELECTION                0x00004000
00187 
00188 // If this bit is set, the frame is "special" (lame term, I know),
00189 // which means that it is part of the mangled frame hierarchy that
00190 // results when an inline has been split because of a nested block.
00191 #define NS_FRAME_IS_SPECIAL                           0x00008000
00192 
00193 // If this bit is set, the frame doesn't allow ignorable whitespace as
00194 // children. For example, the whitespace between <table>\n<tr>\n<td>
00195 // will be excluded during the construction of children. 
00196 // The bit is set when the frame is first created and remain
00197 // unchanged during the life-time of the frame.
00198 #define NS_FRAME_EXCLUDE_IGNORABLE_WHITESPACE         0x00010000
00199 
00200 #ifdef IBMBIDI
00201 // If this bit is set, the frame itself is a bidi continuation,
00202 // or is incomplete (its next sibling is a bidi continuation)
00203 #define NS_FRAME_IS_BIDI                              0x00020000
00204 #endif
00205 
00206 // If this bit is set the frame has descendant with a view
00207 #define NS_FRAME_HAS_CHILD_WITH_VIEW                  0x00040000
00208 
00209 // If this bit is set, then reflow may be dispatched from the current
00210 // frame instead of the root frame.
00211 #define NS_FRAME_REFLOW_ROOT                          0x00080000
00212 
00213 // The lower 20 bits of the frame state word are reserved by this API.
00214 #define NS_FRAME_RESERVED                             0x000FFFFF
00215 
00216 // The upper 12 bits of the frame state word are reserved for frame
00217 // implementations.
00218 #define NS_FRAME_IMPL_RESERVED                        0xFFF00000
00219 
00220 // Box layout bits
00221 #define NS_STATE_IS_HORIZONTAL                        0x00400000
00222 #define NS_STATE_IS_DIRECTION_NORMAL                  0x80000000
00223 
00224 //----------------------------------------------------------------------
00225 
00226 enum nsFramePaintLayer {
00227   eFramePaintLayer_Underlay = 1,
00228   eFramePaintLayer_Content = 2,
00229   eFramePaintLayer_Overlay = 4
00230 };
00231 
00232 enum nsSelectionAmount {
00233   eSelectCharacter = 0,
00234   eSelectWord      = 1,
00235   eSelectLine      = 2,  //previous drawn line in flow.
00236   eSelectBeginLine = 3,
00237   eSelectEndLine   = 4,
00238   eSelectNoAmount  = 5,   //just bounce back current offset.
00239   eSelectDir       = 6,   //select next/previous frame based on direction
00240   eSelectParagraph = 7    //select a "paragraph"
00241 };
00242 
00243 enum nsDirection {
00244   eDirNext    = 0,
00245   eDirPrevious= 1
00246 };
00247 
00248 enum nsSpread {
00249   eSpreadNone   = 0,
00250   eSpreadAcross = 1,
00251   eSpreadDown   = 2
00252 };
00253 
00254 // Carried out margin flags
00255 #define NS_CARRIED_TOP_MARGIN_IS_AUTO    0x1
00256 #define NS_CARRIED_BOTTOM_MARGIN_IS_AUTO 0x2
00257 
00258 //----------------------------------------------------------------------
00259 
00260 // For HTML reflow we rename with the different paint layers are
00261 // actually used for.
00262 #define NS_FRAME_PAINT_LAYER_BACKGROUND eFramePaintLayer_Underlay
00263 #define NS_FRAME_PAINT_LAYER_FLOATS   eFramePaintLayer_Content
00264 #define NS_FRAME_PAINT_LAYER_FOREGROUND eFramePaintLayer_Overlay
00265 #define NS_FRAME_PAINT_LAYER_DEBUG      eFramePaintLayer_Overlay
00266 #define NS_FRAME_PAINT_LAYER_ALL                       \
00267   (nsFramePaintLayer(NS_FRAME_PAINT_LAYER_BACKGROUND | \
00268                      NS_FRAME_PAINT_LAYER_FLOATS     | \
00269                      NS_FRAME_PAINT_LAYER_FOREGROUND))
00270 
00290 typedef PRUint32 nsReflowStatus;
00291 
00292 #define NS_FRAME_COMPLETE          0            // Note: not a bit!
00293 #define NS_FRAME_NOT_COMPLETE      0x1
00294 #define NS_FRAME_REFLOW_NEXTINFLOW 0x2
00295 
00296 #define NS_FRAME_IS_COMPLETE(status) \
00297   (0 == ((status) & NS_FRAME_NOT_COMPLETE))
00298 
00299 #define NS_FRAME_IS_NOT_COMPLETE(status) \
00300   (0 != ((status) & NS_FRAME_NOT_COMPLETE))
00301 
00302 // This macro tests to see if an nsReflowStatus is an error value
00303 // or just a regular return value
00304 #define NS_IS_REFLOW_ERROR(_status) (PRInt32(_status) < 0)
00305 
00310 // This bit is set, when a break is requested. This bit is orthogonal
00311 // to the nsIFrame::nsReflowStatus completion bits.
00312 #define NS_INLINE_BREAK              0x0100
00313 
00314 // When a break is requested, this bit when set indicates that the
00315 // break should occur after the frame just reflowed; when the bit is
00316 // clear the break should occur before the frame just reflowed.
00317 #define NS_INLINE_BREAK_BEFORE       0x0000
00318 #define NS_INLINE_BREAK_AFTER        0x0200
00319 
00320 // The type of break requested can be found in these bits.
00321 #define NS_INLINE_BREAK_TYPE_MASK    0xF000
00322 
00323 //----------------------------------------
00324 // Macros that use those bits
00325 
00326 #define NS_INLINE_IS_BREAK(_status) \
00327   (0 != ((_status) & NS_INLINE_BREAK))
00328 
00329 #define NS_INLINE_IS_BREAK_AFTER(_status) \
00330   (0 != ((_status) & NS_INLINE_BREAK_AFTER))
00331 
00332 #define NS_INLINE_IS_BREAK_BEFORE(_status) \
00333   (NS_INLINE_BREAK == ((_status) & (NS_INLINE_BREAK|NS_INLINE_BREAK_AFTER)))
00334 
00335 #define NS_INLINE_GET_BREAK_TYPE(_status) (((_status) >> 12) & 0xF)
00336 
00337 #define NS_INLINE_MAKE_BREAK_TYPE(_type)  ((_type) << 12)
00338 
00339 // Construct a line-break-before status. Note that there is no
00340 // completion status for a line-break before because we *know* that
00341 // the frame will be reflowed later and hence it's current completion
00342 // status doesn't matter.
00343 #define NS_INLINE_LINE_BREAK_BEFORE()                                   \
00344   (NS_INLINE_BREAK | NS_INLINE_BREAK_BEFORE |                           \
00345    NS_INLINE_MAKE_BREAK_TYPE(NS_STYLE_CLEAR_LINE))
00346 
00347 // Take a completion status and add to it the desire to have a
00348 // line-break after. For this macro we do need the completion status
00349 // because the user of the status will need to know whether to
00350 // continue the frame or not.
00351 #define NS_INLINE_LINE_BREAK_AFTER(_completionStatus)                   \
00352   ((_completionStatus) | NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER |      \
00353    NS_INLINE_MAKE_BREAK_TYPE(NS_STYLE_CLEAR_LINE))
00354 
00355 // The frame (not counting a continuation) did not fit in the available height and 
00356 // wasn't at the top of a page. If it was at the top of a page, then it is not 
00357 // possible to reflow it again with more height, so we don't set it in that case.
00358 #define NS_FRAME_TRUNCATED  0x0010
00359 #define NS_FRAME_IS_TRUNCATED(status) \
00360   (0 != ((status) & NS_FRAME_TRUNCATED))
00361 #define NS_FRAME_SET_TRUNCATION(status, aReflowState, aMetrics) \
00362   if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE &&   \
00363       !aReflowState.mFlags.mIsTopOfPage &&                      \
00364       aReflowState.availableHeight < aMetrics.height)           \
00365     status |= NS_FRAME_TRUNCATED;                               \
00366   else                                                          \
00367     status &= ~NS_FRAME_TRUNCATED;
00368 
00369 //----------------------------------------------------------------------
00370 
00374 typedef PRBool nsDidReflowStatus;
00375 
00376 #define NS_FRAME_REFLOW_NOT_FINISHED PR_FALSE
00377 #define NS_FRAME_REFLOW_FINISHED     PR_TRUE
00378 
00379 //----------------------------------------------------------------------
00380 
00402 class nsIFrame : public nsISupports
00403 {
00404 public:
00405   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFRAME_IID)
00406 
00407   nsPresContext* GetPresContext() const {
00408     return GetStyleContext()->GetRuleNode()->GetPresContext();
00409   }
00410 
00429   NS_IMETHOD  Init(nsPresContext*  aPresContext,
00430                    nsIContent*      aContent,
00431                    nsIFrame*        aParent,
00432                    nsStyleContext*  aContext,
00433                    nsIFrame*        aPrevInFlow) = 0;
00434 
00439   NS_IMETHOD  Destroy(nsPresContext* aPresContext) = 0;
00440 
00441   /*
00442    * Notify the frame that it has been removed as the primary frame for its content
00443    */
00444   virtual void RemovedAsPrimaryFrame(nsPresContext* aPresContext) {}
00445 
00464   NS_IMETHOD  SetInitialChildList(nsPresContext* aPresContext,
00465                                   nsIAtom*        aListName,
00466                                   nsIFrame*       aChildList) = 0;
00467 
00482   NS_IMETHOD AppendFrames(nsIAtom*        aListName,
00483                           nsIFrame*       aFrameList) = 0;
00484 
00500   NS_IMETHOD InsertFrames(nsIAtom*        aListName,
00501                           nsIFrame*       aPrevFrame,
00502                           nsIFrame*       aFrameList) = 0;
00503 
00520   NS_IMETHOD RemoveFrame(nsIAtom*        aListName,
00521                          nsIFrame*       aOldFrame) = 0;
00522 
00540   NS_IMETHOD ReplaceFrame(nsIAtom*        aListName,
00541                           nsIFrame*       aOldFrame,
00542                           nsIFrame*       aNewFrame) = 0;
00543 
00547   nsIContent* GetContent() const { return mContent; }
00548 
00552   virtual nsIFrame* GetContentInsertionFrame() { return this; }
00553 
00561   virtual already_AddRefed<nsIContent> GetContentInsertionNode() { return nsnull; }
00562 
00567   NS_IMETHOD GetOffsets(PRInt32 &start, PRInt32 &end) const = 0;
00568 
00573   virtual void AdjustOffsetsForBidi(PRInt32 aStart, PRInt32 aEnd) {}
00574 
00579   nsStyleContext* GetStyleContext() const { return mStyleContext; }
00580   void SetStyleContext(nsPresContext* aPresContext, nsStyleContext* aContext)
00581   { 
00582     if (aContext != mStyleContext) {
00583       if (mStyleContext)
00584         mStyleContext->Release();
00585       mStyleContext = aContext;
00586       if (aContext) {
00587         aContext->AddRef();
00588         DidSetStyleContext(aPresContext);
00589       }
00590     }
00591   }
00592 
00593   // Style post processing hook
00594   NS_IMETHOD DidSetStyleContext(nsPresContext* aPresContext) = 0;
00595 
00604   virtual const nsStyleStruct* GetStyleDataExternal(nsStyleStructID aSID) const = 0;
00605 
00606   const nsStyleStruct* GetStyleData(nsStyleStructID aSID) const {
00607 #ifdef _IMPL_NS_LAYOUT
00608     NS_ASSERTION(mStyleContext, "No style context found!");
00609     return mStyleContext->GetStyleData(aSID);
00610 #else
00611     return GetStyleDataExternal(aSID);
00612 #endif
00613   }
00614 
00623   #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_)                      \
00624     const nsStyle##name_ * GetStyle##name_() const {                          \
00625       return NS_STATIC_CAST(const nsStyle##name_*,                            \
00626                             GetStyleData(eStyleStruct_##name_));              \
00627     }
00628   #include "nsStyleStructList.h"
00629   #undef STYLE_STRUCT
00630 
00631   // Utility function: more convenient than 2 calls to GetStyleData to get border and padding
00632   
00633   NS_IMETHOD  CalcBorderPadding(nsMargin& aBorderPadding) const = 0;
00634 
00645   virtual nsStyleContext* GetAdditionalStyleContext(PRInt32 aIndex) const = 0;
00646 
00647   virtual void SetAdditionalStyleContext(PRInt32 aIndex,
00648                                          nsStyleContext* aStyleContext) = 0;
00649 
00653   nsIFrame* GetParent() const { return mParent; }
00654   NS_IMETHOD SetParent(const nsIFrame* aParent) { mParent = (nsIFrame*)aParent; return NS_OK; }
00655 
00664   nsRect GetRect() const { return mRect; }
00665   nsPoint GetPosition() const { return nsPoint(mRect.x, mRect.y); }
00666   nsSize GetSize() const { return nsSize(mRect.width, mRect.height); }
00667   void SetRect(const nsRect& aRect) { mRect = aRect; }
00668   void SetPosition(const nsPoint& aPt) { mRect.MoveTo(aPt); }
00669   void SetSize(const nsSize& aSize) { mRect.SizeTo(aSize); }
00670 
00679   virtual nsIAtom* GetAdditionalChildListName(PRInt32 aIndex) const = 0;
00680 
00689   virtual nsIFrame* GetFirstChild(nsIAtom* aListName) const = 0;
00690 
00694   nsIFrame* GetNextSibling() const { return mNextSibling; }
00695   void SetNextSibling(nsIFrame* aNextSibling) {
00696     NS_ASSERTION(this != aNextSibling, "Creating a circular frame list, this is very bad."); 
00697     mNextSibling = aNextSibling;
00698   }
00699 
00705   NS_IMETHOD  Paint(nsPresContext*      aPresContext,
00706                     nsIRenderingContext& aRenderingContext,
00707                     const nsRect&        aDirtyRect,
00708                     nsFramePaintLayer    aWhichLayer,
00709                     PRUint32             aFlags = 0) = 0;
00710 
00715   virtual PRBool CanPaintBackground() { return PR_TRUE; }
00716 
00720   virtual PRBool NeedsView() { return PR_FALSE; }
00721 
00728   virtual nsresult CreateWidgetForView(nsIView* aView);
00729 
00747   NS_IMETHOD  HandleEvent(nsPresContext* aPresContext,
00748                           nsGUIEvent*     aEvent,
00749                           nsEventStatus*  aEventStatus) = 0;
00750 
00751   NS_IMETHOD  GetContentForEvent(nsPresContext* aPresContext,
00752                                  nsEvent* aEvent,
00753                                  nsIContent** aContent) = 0;
00754 
00755   NS_IMETHOD GetContentAndOffsetsFromPoint(nsPresContext* aCX,
00756                                            const nsPoint&  aPoint,
00757                                            nsIContent **   aNewContent,
00758                                            PRInt32&        aContentOffset,
00759                                            PRInt32&        aContentOffsetEnd,
00760                                            PRBool&         aBeginFrameContent) = 0;
00761 
00767   struct Cursor {
00768     nsCOMPtr<imgIContainer> mContainer;
00769     PRInt32                 mCursor;
00770     PRBool                  mHaveHotspot;
00771     float                   mHotspotX, mHotspotY;
00772   };
00776   NS_IMETHOD  GetCursor(const nsPoint&  aPoint,
00777                         Cursor&         aCursor) = 0;
00778 
00786   NS_IMETHOD  GetFrameForPoint(const nsPoint& aPoint, 
00787                                nsFramePaintLayer aWhichLayer,
00788                                nsIFrame**     aFrame) = 0;
00789   
00790   
00796   NS_IMETHOD  GetPointFromOffset(nsPresContext*          inPresContext,
00797                                  nsIRenderingContext*     inRendContext,
00798                                  PRInt32                  inOffset,
00799                                  nsPoint*                 outPoint) = 0;
00800   
00809   NS_IMETHOD  GetChildFrameContainingOffset(PRInt32       inContentOffset,
00810                                  PRBool                   inHint,//false stick left
00811                                  PRInt32*                 outFrameContentOffset,
00812                                  nsIFrame*                *outChildFrame) = 0;
00813 
00818   nsFrameState GetStateBits() const { return mState; }
00819 
00823   void AddStateBits(nsFrameState aBits) { mState |= aBits; }
00824   void RemoveStateBits(nsFrameState aBits) { mState &= ~aBits; }
00825 
00835   NS_IMETHOD  CharacterDataChanged(nsPresContext* aPresContext,
00836                                    nsIContent*     aChild,
00837                                    PRBool          aAppend) = 0;
00838 
00851   NS_IMETHOD  AttributeChanged(nsIContent*     aChild,
00852                                PRInt32         aNameSpaceID,
00853                                nsIAtom*        aAttribute,
00854                                PRInt32         aModType) = 0;
00855 
00859   NS_IMETHOD  IsSplittable(nsSplittableType& aIsSplittable) const = 0;
00860 
00864   virtual nsIFrame* GetPrevInFlow() const = 0;
00865   NS_IMETHOD  SetPrevInFlow(nsIFrame*) = 0;
00866   virtual nsIFrame* GetNextInFlow() const = 0;
00867   NS_IMETHOD  SetNextInFlow(nsIFrame*) = 0;
00868 
00872   virtual nsIFrame* GetFirstInFlow() const {
00873     return NS_CONST_CAST(nsIFrame*, this);
00874   }
00875 
00879   virtual nsIFrame* GetLastInFlow() const {
00880     return NS_CONST_CAST(nsIFrame*, this);
00881   }
00882 
00892   NS_IMETHOD  WillReflow(nsPresContext* aPresContext) = 0;
00893 
00934   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00935                     nsHTMLReflowMetrics&     aReflowMetrics,
00936                     const nsHTMLReflowState& aReflowState,
00937                     nsReflowStatus&          aStatus) = 0;
00938 
00954   NS_IMETHOD  DidReflow(nsPresContext*           aPresContext,
00955                         const nsHTMLReflowState*  aReflowState,
00956                         nsDidReflowStatus         aStatus) = 0;
00957 
00958   // XXX Maybe these three should be a separate interface?
00959 
00971   NS_IMETHOD CanContinueTextRun(PRBool& aContinueTextRun) const = 0;
00972 
00973   // Justification helper method used to distribute extra space in a
00974   // line to leaf frames. aUsedSpace is filled in with the amount of
00975   // space actually used.
00976   NS_IMETHOD AdjustFrameSize(nscoord aExtraSpace, nscoord& aUsedSpace) = 0;
00977 
00978   // Justification helper method that is used to remove trailing
00979   // whitespace before justification.
00980   NS_IMETHOD TrimTrailingWhiteSpace(nsPresContext* aPresContext,
00981                                     nsIRenderingContext& aRC,
00982                                     nscoord& aDeltaWidth,
00983                                     PRBool& aLastCharIsJustifiable) = 0;
00984 
00990   PRBool HasView() const { return mState & NS_FRAME_HAS_VIEW; }
00991   nsIView* GetView() const;
00992   virtual nsIView* GetViewExternal() const;
00993   nsresult SetView(nsIView* aView);
00994 
01000   virtual nsIView* GetParentViewForChildFrame(nsIFrame* aFrame) const;
01001 
01007   nsIView* GetClosestView(nsPoint* aOffset = nsnull) const;
01008 
01012   nsIFrame* GetAncestorWithView() const;
01013   virtual nsIFrame* GetAncestorWithViewExternal() const;
01014 
01028   nsPoint GetOffsetTo(const nsIFrame* aOther) const;
01029   virtual nsPoint GetOffsetToExternal(const nsIFrame* aOther) const;
01030 
01035   nsIntRect GetScreenRect() const;
01036   virtual nsIntRect GetScreenRectExternal() const;
01037 
01042   NS_IMETHOD  GetOffsetFromView(nsPoint&  aOffset,
01043                                 nsIView** aView) const = 0;
01044 
01053   NS_IMETHOD  GetOriginToViewOffset(nsPoint&        aOffset,
01054                                     nsIView**       aView) const = 0;
01055 
01060   virtual PRBool AreAncestorViewsVisible() const;
01061 
01069   virtual nsIWidget* GetWindow() const;
01070 
01076   virtual nsIAtom* GetType() const = 0;
01077   
01078 
01082   enum {
01083     eMathML =           1 << 0,
01084     eSVG =              1 << 1,
01085     eSVGForeignObject = 1 << 2
01086   };
01087 
01092   virtual PRBool IsFrameOfType(PRUint32 aFlags) const
01093   {
01094     return !aFlags;
01095   }
01096 
01100   virtual PRBool IsContainingBlock() const = 0;
01101 
01106   virtual PRBool IsFloatContainingBlock() const { return PR_FALSE; }
01107 
01117   virtual PRBool IsLeaf() const;
01118 
01125   virtual nsIView* GetMouseCapturer() const { return nsnull; }
01126 
01137   void Invalidate(const nsRect& aDamageRect, PRBool aImmediate = PR_FALSE) const;
01138 
01147   nsRect GetOverflowRect() const;
01148 
01154   void FinishAndStoreOverflow(nsRect* aOverflowArea, nsSize aNewSize);
01155 
01156   void FinishAndStoreOverflow(nsHTMLReflowMetrics* aMetrics) {
01157     FinishAndStoreOverflow(&aMetrics->mOverflowArea, nsSize(aMetrics->width, aMetrics->height));
01158   }
01159 
01170   NS_IMETHOD  SetSelected(nsPresContext* aPresContext,
01171                           nsIDOMRange*    aRange,
01172                           PRBool          aSelected,
01173                           nsSpread        aSpread) = 0;
01174 
01175   NS_IMETHOD  GetSelected(PRBool *aSelected) const = 0;
01176 
01186   NS_IMETHOD  IsSelectable(PRBool* aIsSelectable, PRUint8* aSelectStyle) const = 0;
01187 
01193   NS_IMETHOD  GetSelectionController(nsPresContext *aPresContext, nsISelectionController **aSelCon) = 0;
01194 
01204   NS_IMETHOD CaptureMouse(nsPresContext* aPresContext, PRBool aGrabMouseEvents) = 0;
01205 
01213   NS_IMETHOD  PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) = 0;
01214 
01226   NS_IMETHOD CheckVisibility(nsPresContext* aContext, PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aRecurse, PRBool *aFinished, PRBool *_retval)=0;
01227 
01234   NS_IMETHOD ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild) = 0;
01235 
01243 #ifdef ACCESSIBILITY
01244   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible) = 0;
01245 #endif
01246 
01264   NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext,
01265                                         nsIFrame**      aProviderFrame,
01266                                         PRBool*         aIsChild) = 0;
01267 
01277   NS_IMETHOD IsVisibleForPainting(nsPresContext *     aPresContext, 
01278                                   nsIRenderingContext& aRenderingContext,
01279                                   PRBool               aCheckVis,
01280                                   PRBool*              aIsVisible) = 0;
01281 
01291   virtual PRBool IsEmpty() = 0;
01292 
01297   virtual PRBool IsSelfEmpty() = 0;
01298 
01305   PRBool IsGeneratedContentFrame() {
01306     return (mState & NS_FRAME_GENERATED_CONTENT) != 0;
01307   }
01308 
01317   PRBool IsPseudoFrame(nsIContent* aParentContent) {
01318     return mContent == aParentContent;
01319   }
01320 
01321 
01322   NS_HIDDEN_(void*) GetProperty(nsIAtom* aPropertyName,
01323                                 nsresult* aStatus = nsnull) const;
01324   virtual NS_HIDDEN_(void*) GetPropertyExternal(nsIAtom*  aPropertyName,
01325                                                 nsresult* aStatus) const;
01326   NS_HIDDEN_(nsresult) SetProperty(nsIAtom*           aPropertyName,
01327                                    void*              aValue,
01328                                    NSPropertyDtorFunc aDestructor = nsnull,
01329                                    void*              aDtorData = nsnull);
01330   NS_HIDDEN_(nsresult) DeleteProperty(nsIAtom* aPropertyName) const;
01331   NS_HIDDEN_(void*) UnsetProperty(nsIAtom* aPropertyName,
01332                                   nsresult* aStatus = nsnull) const;
01333 
01334 #define NS_GET_BASE_LEVEL(frame) \
01335 NS_PTR_TO_INT32(frame->GetProperty(nsLayoutAtoms::baseLevel))
01336 
01337 #define NS_GET_EMBEDDING_LEVEL(frame) \
01338 NS_PTR_TO_INT32(frame->GetProperty(nsLayoutAtoms::embeddingLevel))
01339 
01346   nsRect* GetOverflowAreaProperty(PRBool aCreateIfNecessary = PR_FALSE);
01347 
01353   virtual PRBool SupportsVisibilityHidden() { return PR_TRUE; }
01354 
01373   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull, PRBool aWithMouse = PR_FALSE);
01374 
01375   // BOX LAYOUT METHODS
01376   // These methods have been migrated from nsIBox and are in the process of
01377   // being refactored. DO NOT USE OUTSIDE OF XUL.
01378   PRBool IsBoxFrame() const { return (mState & NS_FRAME_IS_BOX) != 0; }
01379   PRBool IsBoxWrapped() const
01380   { return (!IsBoxFrame() && mParent && mParent->IsBoxFrame()); }
01381 
01382   enum Halignment {
01383     hAlign_Left,
01384     hAlign_Right,
01385     hAlign_Center
01386   };
01387 
01388   enum Valignment {
01389     vAlign_Top,
01390     vAlign_Middle,
01391     vAlign_BaseLine,
01392     vAlign_Bottom
01393   };
01394 
01395   NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize)=0;
01396   NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize)=0;
01397   NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize)=0;
01398   NS_IMETHOD GetFlex(nsBoxLayoutState& aBoxLayoutState, nscoord& aFlex)=0;
01399   NS_HIDDEN_(nsresult)
01400     GetOrdinal(nsBoxLayoutState& aBoxLayoutState, PRUint32& aOrdinal);
01401 
01406   virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) = 0;
01407 
01408   NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent)=0;
01409   NS_IMETHOD IsCollapsed(nsBoxLayoutState& aBoxLayoutState, PRBool& aCollapsed)=0;
01410   // This does not alter the overflow area. If the caller is changing
01411   // the box size, the caller is responsible for updating the overflow
01412   // area. It's enough to just call Layout or SyncLayout on the
01413   // box. You can pass PR_TRUE to aRemoveOverflowArea as a
01414   // convenience.
01415   NS_IMETHOD SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
01416                        PRBool aRemoveOverflowArea = PR_FALSE)=0;
01417   NS_HIDDEN_(nsresult) Layout(nsBoxLayoutState& aBoxLayoutState);
01418   nsresult IsDirty(PRBool& aIsDirty) { aIsDirty = (mState & NS_FRAME_IS_DIRTY) != 0; return NS_OK; }
01419   nsresult HasDirtyChildren(PRBool& aIsDirty) { aIsDirty = (mState & NS_FRAME_HAS_DIRTY_CHILDREN) != 0; return NS_OK; }
01420   NS_IMETHOD MarkDirty(nsBoxLayoutState& aState)=0;
01421   NS_HIDDEN_(nsresult) MarkDirtyChildren(nsBoxLayoutState& aState);
01422   nsresult GetChildBox(nsIBox** aBox)
01423   {
01424     // box layout ends at box-wrapped frames, so don't allow these frames
01425     // to report child boxes.
01426     *aBox = IsBoxFrame() ? GetFirstChild(nsnull) : nsnull;
01427     return NS_OK;
01428   }
01429   nsresult GetNextBox(nsIBox** aBox)
01430   {
01431     *aBox = (mParent && mParent->IsBoxFrame()) ? mNextSibling : nsnull;
01432     return NS_OK;
01433   }
01434   NS_HIDDEN_(nsresult) GetParentBox(nsIBox** aParent);
01435   // Box methods.  Note that these do NOT just get the CSS border, padding,
01436   // etc.  They also talk to nsITheme.
01437   NS_IMETHOD GetBorderAndPadding(nsMargin& aBorderAndPadding);
01438   NS_IMETHOD GetBorder(nsMargin& aBorder)=0;
01439   NS_IMETHOD GetPadding(nsMargin& aBorderAndPadding)=0;
01440 #ifdef DEBUG_LAYOUT
01441   NS_IMETHOD GetInset(nsMargin& aInset)=0;
01442 #else
01443   nsresult GetInset(nsMargin& aInset) { aInset.SizeTo(0, 0, 0, 0); return NS_OK; }
01444 #endif
01445   NS_IMETHOD GetMargin(nsMargin& aMargin)=0;
01446   NS_IMETHOD SetLayoutManager(nsIBoxLayout* aLayout)=0;
01447   NS_IMETHOD GetLayoutManager(nsIBoxLayout** aLayout)=0;
01448   NS_HIDDEN_(nsresult) GetContentRect(nsRect& aContentRect);
01449   NS_HIDDEN_(nsresult) GetClientRect(nsRect& aContentRect);
01450   NS_IMETHOD GetVAlign(Valignment& aAlign) = 0;
01451   NS_IMETHOD GetHAlign(Halignment& aAlign) = 0;
01452 
01453   PRBool IsHorizontal() const { return (mState & NS_STATE_IS_HORIZONTAL) != 0; }
01454   nsresult GetOrientation(PRBool& aIsHorizontal)  
01455   { aIsHorizontal = IsHorizontal(); return NS_OK; }
01456 
01457   PRBool IsNormalDirection() const { return (mState & NS_STATE_IS_DIRECTION_NORMAL) != 0; }
01458   nsresult GetDirection(PRBool& aIsNormal)  
01459   { aIsNormal = IsNormalDirection(); return NS_OK; }
01460 
01461   NS_HIDDEN_(nsresult) Redraw(nsBoxLayoutState& aState, const nsRect* aRect = nsnull, PRBool aImmediate = PR_FALSE);
01462   NS_IMETHOD NeedsRecalc()=0;
01463   NS_IMETHOD RelayoutDirtyChild(nsBoxLayoutState& aState, nsIBox* aChild)=0;
01464   NS_IMETHOD RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIBox* aChild)=0;
01465   NS_IMETHOD GetMouseThrough(PRBool& aMouseThrough)=0;
01466   NS_IMETHOD MarkChildrenStyleChange()=0;
01467   NS_IMETHOD MarkStyleChange(nsBoxLayoutState& aState)=0;
01468   NS_IMETHOD SetIncludeOverflow(PRBool aInclude) = 0;
01469   NS_IMETHOD GetOverflow(nsSize& aOverflow) = 0;
01470 
01471 #ifdef DEBUG_LAYOUT
01472   NS_IMETHOD SetDebug(nsBoxLayoutState& aState, PRBool aDebug)=0;
01473   NS_IMETHOD GetDebug(PRBool& aDebug)=0;
01474   NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIBox** aBox)=0;
01475 
01476   NS_IMETHOD DumpBox(FILE* out)=0;
01477 #endif
01478   NS_IMETHOD ChildrenMustHaveWidgets(PRBool& aMust) const=0;
01479   NS_IMETHOD GetIndexOf(nsIBox* aChild, PRInt32* aIndex)=0;
01480 
01481   static PRBool AddCSSPrefSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize);
01482   static PRBool AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize);
01483   static PRBool AddCSSMaxSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize);
01484   static PRBool AddCSSFlex(nsBoxLayoutState& aState, nsIBox* aBox, nscoord& aFlex);
01485   static PRBool AddCSSCollapsed(nsBoxLayoutState& aState, nsIBox* aBox, PRBool& aCollapsed);
01486   static PRBool AddCSSOrdinal(nsBoxLayoutState& aState, nsIBox* aBox, PRUint32& aOrdinal);
01487 
01488   // END OF BOX LAYOUT METHODS
01489   // The above methods have been migrated from nsIBox and are in the process of
01490   // being refactored. DO NOT USE OUTSIDE OF XUL.
01491 
01503   nsPeekOffsetStruct GetExtremeCaretPosition(PRBool aStart);
01504 
01505 protected:
01506   // Members
01507   nsRect           mRect;
01508   nsIContent*      mContent;
01509   nsStyleContext*  mStyleContext;
01510   nsIFrame*        mParent;
01511   nsIFrame*        mNextSibling;  // singly-linked list of frames
01512   nsFrameState     mState;
01513 
01514 private:
01515   NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
01516   NS_IMETHOD_(nsrefcnt) Release(void) = 0;
01517 };
01518 
01532 class nsWeakFrame {
01533 public:
01534   nsWeakFrame(nsIFrame* aFrame) : mPrev(nsnull), mFrame(nsnull)
01535   {
01536     Init(aFrame);
01537   }
01538 
01539   nsWeakFrame& operator=(nsWeakFrame& aOther) {
01540     Init(aOther.GetFrame());
01541     return *this;
01542   }
01543 
01544   nsWeakFrame& operator=(nsIFrame* aFrame) {
01545     Init(aFrame);
01546     return *this;
01547   }
01548 
01549   nsIFrame* operator->()
01550   {
01551     return mFrame;
01552   }
01553 
01554   operator nsIFrame*()
01555   {
01556     return mFrame;
01557   }
01558 
01559   void Clear(nsIPresShell_MOZILLA_1_8_BRANCH* aShell) {
01560     if (aShell) {
01561       aShell->RemoveWeakFrame(this);
01562     }
01563     mFrame = nsnull;
01564     mPrev = nsnull;
01565   }
01566 
01567   PRBool IsAlive() { return !!mFrame; }
01568 
01569   nsIFrame* GetFrame() { return mFrame; }
01570 
01571   nsWeakFrame* GetPreviousWeakFrame() { return mPrev; }
01572 
01573   void SetPreviousWeakFrame(nsWeakFrame* aPrev) { mPrev = aPrev; }
01574 
01575   ~nsWeakFrame()
01576   {
01577     nsCOMPtr<nsIPresShell_MOZILLA_1_8_BRANCH> shell18 =
01578       do_QueryInterface(mFrame ? mFrame->GetPresContext()->GetPresShell() : nsnull);
01579     Clear(shell18);
01580   }
01581 private:
01582   void Init(nsIFrame* aFrame)
01583   {
01584     nsCOMPtr<nsIPresShell_MOZILLA_1_8_BRANCH> shell18 =
01585       do_QueryInterface(mFrame ? mFrame->GetPresContext()->GetPresShell() : nsnull);
01586     Clear(shell18);
01587     mFrame = aFrame;
01588     if (mFrame) {
01589       shell18 = do_QueryInterface(mFrame->GetPresContext()->GetPresShell());
01590       NS_WARN_IF_FALSE(shell18, "Null PresShell in nsWeakFrame!");
01591       if (shell18) {
01592         shell18->AddWeakFrame(this);
01593       } else {
01594         mFrame = nsnull;
01595       }
01596     }
01597   }
01598 
01599   nsWeakFrame*  mPrev;
01600   nsIFrame*     mFrame;
01601 };
01602 
01603 #endif /* nsIFrame_h___ */