Back to index

lightning-sunbird  0.9+nobinonly
nsIPresShell.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  *   Steve Clark <buster@netscape.com>
00024  *   Dan Rosen <dr@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK *****
00039  *
00040  * This Original Code has been modified by IBM Corporation.
00041  * Modifications made by IBM described herein are
00042  * Copyright (c) International Business Machines
00043  * Corporation, 2000
00044  *
00045  * Modifications to Mozilla code or documentation
00046  * identified per MPL Section 3.3
00047  *
00048  * Date         Modified by     Description of modification
00049  * 05/03/2000   IBM Corp.       Observer related defines for reflow
00050  */
00051 #ifndef nsIPresShell_h___
00052 #define nsIPresShell_h___
00053 
00054 #include "nsISupports.h"
00055 #include "nsCoord.h"
00056 #include "nsEvent.h"
00057 #include "nsReflowType.h"
00058 #include "nsCompatibility.h"
00059 #include "nsCOMArray.h"
00060 #include "nsFrameManagerBase.h"
00061 #include "mozFlushType.h"
00062 #include "nsWeakReference.h"
00063 #include <stdio.h> // for FILE definition
00064 
00065 class nsIAtom;
00066 class nsIContent;
00067 class nsIContentIterator;
00068 class nsIDocument;
00069 class nsIDocumentObserver;
00070 class nsIFrame;
00071 class nsPresContext;
00072 class nsStyleSet;
00073 class nsIViewManager;
00074 class nsIDeviceContext;
00075 class nsIRenderingContext;
00076 class nsIPageSequenceFrame;
00077 class nsString;
00078 class nsAString;
00079 class nsStringArray;
00080 class nsICaret;
00081 class nsStyleContext;
00082 class nsIFrameSelection;
00083 class nsFrameManager;
00084 class nsILayoutHistoryState;
00085 class nsIReflowCallback;
00086 class nsISupportsArray;
00087 class nsIDOMNode;
00088 class nsIStyleFrameConstruction;
00089 class nsIStyleSheet;
00090 class nsCSSFrameConstructor;
00091 class nsISelection;
00092 class nsWeakFrame;
00093 
00094 #define NS_IPRESSHELL_IID     \
00095 { 0x0672be76, 0x1047, 0x4905, \
00096   {0xad, 0xd1, 0xc5, 0xc6, 0x90, 0xe8, 0x70, 0x3a} }
00097 
00098 // Constants uses for ScrollFrameIntoView() function
00099 #define NS_PRESSHELL_SCROLL_TOP      0
00100 #define NS_PRESSHELL_SCROLL_BOTTOM   100
00101 #define NS_PRESSHELL_SCROLL_LEFT     0
00102 #define NS_PRESSHELL_SCROLL_RIGHT    100
00103 #define NS_PRESSHELL_SCROLL_CENTER   50
00104 #define NS_PRESSHELL_SCROLL_ANYWHERE -1
00105 #define NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE -2
00106 
00107 // debug VerifyReflow flags
00108 #define VERIFY_REFLOW_ON              0x01
00109 #define VERIFY_REFLOW_NOISY           0x02
00110 #define VERIFY_REFLOW_ALL             0x04
00111 #define VERIFY_REFLOW_DUMP_COMMANDS   0x08
00112 #define VERIFY_REFLOW_NOISY_RC        0x10
00113 #define VERIFY_REFLOW_REALLY_NOISY_RC 0x20
00114 #define VERIFY_REFLOW_INCLUDE_SPACE_MANAGER 0x40
00115 #define VERIFY_REFLOW_DURING_RESIZE_REFLOW  0x80
00116 
00117 #ifdef IBMBIDI // Constant for Set/Get CaretBidiLevel
00118 #define BIDI_LEVEL_UNDEFINED 0x80
00119 #endif
00120 
00121 // for PostAttributeChanged
00122 enum nsAttributeChangeType {
00123   eChangeType_Set = 0,       // Set attribute
00124   eChangeType_Remove = 1     // Remove attribute
00125 };
00126 
00139 // hack to make egcs / gcc 2.95.2 happy
00140 class nsIPresShell_base : public nsISupports
00141 {
00142 public:
00143   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRESSHELL_IID)
00144 };
00145 
00146 class nsIPresShell : public nsIPresShell_base
00147 {
00148 public:
00149   NS_IMETHOD Init(nsIDocument* aDocument,
00150                   nsPresContext* aPresContext,
00151                   nsIViewManager* aViewManager,
00152                   nsStyleSet* aStyleSet,
00153                   nsCompatibility aCompatMode) = 0;
00154 
00162   NS_IMETHOD Destroy() = 0;
00163 
00164   // All frames owned by the shell are allocated from an arena.  They are also recycled
00165   // using free lists (separate free lists being maintained for each size_t).
00166   // Methods for recycling frames.
00167   virtual void* AllocateFrame(size_t aSize) = 0;
00168   virtual void  FreeFrame(size_t aSize, void* aFreeChunk) = 0;
00169 
00170   // Dynamic stack memory allocation
00171   NS_IMETHOD PushStackMemory() = 0;
00172   NS_IMETHOD PopStackMemory() = 0;
00173   NS_IMETHOD AllocateStackMemory(size_t aSize, void** aResult) = 0;
00174   
00175   nsIDocument* GetDocument() { return mDocument; }
00176 
00177   nsPresContext* GetPresContext() { return mPresContext; }
00178 
00179   nsIViewManager* GetViewManager() { return mViewManager; }
00180 
00181 #ifdef _IMPL_NS_LAYOUT
00182   nsStyleSet*  StyleSet() { return mStyleSet; }
00183 
00184   nsCSSFrameConstructor* FrameConstructor()
00185   {
00186     return mFrameConstructor;
00187   }
00188 
00189   nsFrameManager* FrameManager() const {
00190     return NS_REINTERPRET_CAST(nsFrameManager*,
00191       &NS_CONST_CAST(nsIPresShell*, this)->mFrameManager);
00192   }
00193 
00194 #endif
00195 
00196   // These two methods are used only by viewer
00197   NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle) = 0;
00198 
00199   NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle) = 0;
00200 
00201 
00202   /* Enable/disable author style level. Disabling author style disables the entire
00203    * author level of the cascade, including the HTML preshint level.
00204    */
00205   // XXX these could easily be inlined, but there is a circular #include
00206   // problem with nsStyleSet.
00207   NS_HIDDEN_(void) SetAuthorStyleDisabled(PRBool aDisabled);
00208   NS_HIDDEN_(PRBool) GetAuthorStyleDisabled();
00209 
00210   /*
00211    * Called when stylesheets are added/removed/enabled/disabled to rebuild
00212    * all style data for a given pres shell without necessarily reconstructing
00213    * all of the frames.  ReconstructStyleDataInternal() will not reconstruct
00214    * style synchronously; if you need to do that, call
00215    * FlushPendingNotifications to flush out style reresolves.
00216    * ReconstructStyleDataExternal() will handle calling
00217    * FlushPendingNotifications for backwards-compatibility reasons.
00218    * // XXXbz why do we have this on the interface anyway?  The only consumer
00219    * is calling AddOverrideStyleSheet/RemoveOverrideStyleSheet, and I think
00220    * those should just handle reconstructing style data...
00221    */
00222   virtual NS_HIDDEN_(void) ReconstructStyleDataExternal();
00223   NS_HIDDEN_(void) ReconstructStyleDataInternal();
00224 #ifdef _IMPL_NS_LAYOUT
00225   void ReconstructStyleData() { ReconstructStyleDataInternal(); }
00226 #else
00227   void ReconstructStyleData() { ReconstructStyleDataExternal(); }
00228 #endif
00229 
00238   NS_IMETHOD SetPreferenceStyleRules(PRBool aForceReflow) = 0;
00239 
00244   NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList) = 0;
00245 
00251   nsIFrameSelection* FrameSelection() { return mSelection; }
00252 
00253   // Make shell be a document observer
00254   NS_IMETHOD BeginObservingDocument() = 0;
00255 
00256   // Make shell stop being a document observer
00257   NS_IMETHOD EndObservingDocument() = 0;
00258 
00264   NS_IMETHOD GetDidInitialReflow(PRBool *aDidInitialReflow) = 0;
00265 
00273   NS_IMETHOD InitialReflow(nscoord aWidth, nscoord aHeight) = 0;
00274 
00279   NS_IMETHOD ResizeReflow(nscoord aWidth, nscoord aHeight) = 0;
00280 
00284   NS_IMETHOD StyleChangeReflow() = 0;
00285 
00291   virtual NS_HIDDEN_(nsIFrame*) GetRootFrame() const;
00292 
00297   NS_IMETHOD GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const = 0;
00298 
00313   NS_IMETHOD GetPrimaryFrameFor(nsIContent* aContent,
00314                                 nsIFrame**  aPrimaryFrame) const = 0;
00315 
00322   NS_IMETHOD GetLayoutObjectFor(nsIContent*   aContent,
00323                                 nsISupports** aResult) const = 0;
00324 
00329   NS_IMETHOD GetPlaceholderFrameFor(nsIFrame*  aFrame,
00330                                     nsIFrame** aPlaceholderFrame) const = 0;
00331 
00335   NS_IMETHOD AppendReflowCommand(nsIFrame*    aTargetFrame,
00336                                  nsReflowType aReflowType,
00337                                  nsIAtom*     aChildListName) = 0;
00338   // XXXbz don't we need a child list name on this too?
00339   NS_IMETHOD CancelReflowCommand(nsIFrame* aTargetFrame, nsReflowType* aCmdType) = 0;
00340   NS_IMETHOD CancelAllReflowCommands() = 0;
00341 
00345   NS_IMETHOD RecreateFramesFor(nsIContent* aContent) = 0;
00346 
00352   NS_IMETHOD IsSafeToFlush(PRBool& aIsSafeToFlush) = 0;
00353 
00363   NS_IMETHOD FlushPendingNotifications(mozFlushType aType) = 0;
00364 
00368   NS_IMETHOD PostDOMEvent(nsIContent* aContent, nsEvent* aEvent)=0;
00369 
00373   NS_IMETHOD PostAttributeChange(nsIContent* aContent,
00374                                  PRInt32 aNameSpaceID, 
00375                                  nsIAtom* aName,
00376                                  const nsString& aValue,
00377                                  PRBool aNotify,
00378                                  nsAttributeChangeType aType) = 0;
00379 
00380   NS_IMETHOD PostReflowCallback(nsIReflowCallback* aCallback) = 0;
00381   NS_IMETHOD CancelReflowCallback(nsIReflowCallback* aCallback) = 0;
00385   NS_IMETHOD BeginReflowBatching() = 0;
00386   NS_IMETHOD EndReflowBatching(PRBool aFlushPendingReflows) = 0;
00387   NS_IMETHOD GetReflowBatchingStatus(PRBool* aIsBatching) = 0;
00388 
00389   NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame) = 0;
00390 
00395   NS_IMETHOD CreateRenderingContext(nsIFrame *aFrame,
00396                                     nsIRenderingContext** aContext) = 0;
00397 
00405   NS_IMETHOD CantRenderReplacedElement(nsIFrame* aFrame) = 0;
00406 
00407 
00416   NS_IMETHOD GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) = 0;
00417 
00446   NS_IMETHOD ScrollFrameIntoView(nsIFrame *aFrame,
00447                                  PRIntn   aVPercent, 
00448                                  PRIntn   aHPercent) const = 0;
00449 
00454   NS_IMETHOD SetIgnoreFrameDestruction(PRBool aIgnore) = 0;
00455 
00461   NS_IMETHOD NotifyDestroyingFrame(nsIFrame* aFrame) = 0;
00462 
00466   NS_IMETHOD DoCopy() = 0;
00467 
00472   NS_IMETHOD GetSelectionForCopy(nsISelection** outSelection) = 0;
00473 
00477   NS_IMETHOD GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocation) = 0;
00478 
00482   NS_IMETHOD DoGetContents(const nsACString& aMimeType, PRUint32 aFlags, PRBool aSelectionOnly, nsAString& outValue) = 0;
00483 
00487   NS_IMETHOD GetCaret(nsICaret **aOutCaret) = 0;
00488 
00498   NS_IMETHOD SetSelectionFlags(PRInt16 aInEnable) = 0;
00499 
00507   NS_IMETHOD GetSelectionFlags(PRInt16 *aOutEnabled) = 0;
00508 
00513   NS_IMETHOD HandleEventWithTarget(nsEvent* aEvent, 
00514                                    nsIFrame* aFrame, 
00515                                    nsIContent* aContent,
00516                                    PRUint32 aFlags,
00517                                    nsEventStatus* aStatus) = 0;
00518 
00523   NS_IMETHOD HandleDOMEventWithTarget(nsIContent* aTargetContent,
00524                             nsEvent* aEvent,
00525                             nsEventStatus* aStatus) = 0;
00526 
00530   NS_IMETHOD GetEventTargetFrame(nsIFrame** aFrame) = 0;
00531 
00535   NS_IMETHOD GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent) = 0;
00536 
00541   NS_IMETHOD CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState, PRBool aLeavingPage = PR_FALSE) = 0;
00542 
00547   NS_IMETHOD IsReflowLocked(PRBool* aIsLocked) = 0;  
00548 
00556   enum GeneratedContentType {Before, After};
00557   NS_IMETHOD GetGeneratedContentIterator(nsIContent*          aContent,
00558                                          GeneratedContentType aType,
00559                                          nsIContentIterator** aIterator) const = 0;
00560 
00561 
00573   NS_IMETHOD SetAnonymousContentFor(nsIContent* aContent, nsISupportsArray* aAnonymousElements) = 0;
00574 
00584   NS_IMETHOD GetAnonymousContentFor(nsIContent* aContent, nsISupportsArray** aAnonymousElements) = 0;
00585 
00590   NS_IMETHOD ReleaseAnonymousContent() = 0;
00591 
00597   NS_IMETHOD IsPaintingSuppressed(PRBool* aResult)=0;
00598 
00602   NS_IMETHOD UnsuppressPainting() = 0;
00603 
00607   NS_IMETHOD DisableThemeSupport() = 0;
00608 
00612   virtual PRBool IsThemeSupportEnabled() = 0;
00613 
00617   virtual nsresult GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets) = 0;
00618 
00622   virtual nsresult SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets) = 0;
00623 
00627   virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet) = 0;
00628 
00632   virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) = 0;
00633 
00637   virtual nsresult ReconstructFrames() = 0;
00638 
00645   static PRBool GetVerifyReflowEnable();
00646 
00650   static void SetVerifyReflowEnable(PRBool aEnabled);
00651 
00655   static PRInt32 GetVerifyReflowFlags();
00656 
00657 #ifdef MOZ_REFLOW_PERF
00658   NS_IMETHOD DumpReflows() = 0;
00659   NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0;
00660   NS_IMETHOD PaintCount(const char * aName, 
00661                         nsIRenderingContext* aRenderingContext, 
00662                         nsPresContext * aPresContext, 
00663                         nsIFrame * aFrame,
00664                         PRUint32 aColor) = 0;
00665   NS_IMETHOD SetPaintFrameCount(PRBool aOn) = 0;
00666 #endif
00667 
00668 #ifdef IBMBIDI
00669 
00672   NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel) = 0;
00673 
00677   NS_IMETHOD GetCaretBidiLevel(PRUint8 *aOutLevel) = 0;
00678 
00682   NS_IMETHOD UndefineCaretBidiLevel(void) = 0;
00683 
00687   NS_IMETHOD BidiStyleChangeReflow(void) = 0;
00688 #endif
00689 
00690 #ifdef DEBUG
00691   // Debugging hooks
00692   virtual void ListStyleContexts(nsIFrame *aRootFrame, FILE *out,
00693                                  PRInt32 aIndent = 0) = 0;
00694 
00695   virtual void ListStyleSheets(FILE *out, PRInt32 aIndent = 0) = 0;
00696 #endif
00697 
00698   PRBool IsAccessibilityActive() { return mIsAccessibilityActive; }
00699 
00705   virtual void Freeze() = 0;
00706 
00711   virtual void Thaw() = 0;
00712 
00719   void SetForwardingContainer(nsWeakPtr aContainer)
00720   {
00721     mForwardingContainer = aContainer;
00722   }
00723 
00724 protected:
00725   // IMPORTANT: The ownership implicit in the following member variables
00726   // has been explicitly checked.  If you add any members to this class,
00727   // please make the ownership explicit (pinkerton, scc).
00728 
00729   // these are the same Document and PresContext owned by the DocViewer.
00730   // we must share ownership.
00731   nsIDocument*              mDocument;      // [STRONG]
00732   nsPresContext*            mPresContext;   // [STRONG]
00733   nsStyleSet*               mStyleSet;      // [OWNS]
00734   nsCSSFrameConstructor*    mFrameConstructor; // [OWNS]
00735   nsIViewManager*           mViewManager;   // [WEAK] docViewer owns it so I don't have to
00736   nsIFrameSelection*        mSelection;
00737   nsFrameManagerBase        mFrameManager;  // [OWNS]
00738   nsWeakPtr                 mForwardingContainer;
00739 
00740   PRPackedBool              mStylesHaveChanged;
00741 
00742 #ifdef ACCESSIBILITY
00743 
00747   void InvalidateAccessibleSubtree(nsIContent *aContent);
00748 #endif
00749 
00750   // Set to true when the accessibility service is being used to mirror
00751   // the dom/layout trees
00752   PRPackedBool mIsAccessibilityActive;
00753 
00754   // Last so it won't change any other offsets
00755   PRPackedBool              mDidInitialReflow;
00756 };
00757 
00758 #define NS_IPRESSHELL_MOZILLA_1_8_BRANCH_IID \
00759 { 0x365C83FB, 0x7D4C, 0x4B53, \
00760   { 0x84, 0xde, 0xa5, 0xcc, 0x9a, 0x05, 0x9a, 0x26 } }
00761 
00762 class nsIPresShell_MOZILLA_1_8_BRANCH : public nsIPresShell
00763 {
00764 public: 
00765   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRESSHELL_MOZILLA_1_8_BRANCH_IID)
00766 
00767   void AddWeakFrame(nsWeakFrame* aWeakFrame);
00768   void RemoveWeakFrame(nsWeakFrame* aWeakFrame);
00769 
00770   virtual void HidePopups() = 0;
00771 
00772 protected:
00773   // A list of weak frames. This is a pointer to the last item in the list.
00774   nsWeakFrame* mWeakFrames;
00775 };
00776 
00777 #define NS_IPRESSHELL_MOZILLA_1_8_BRANCH2_IID \
00778 { 0x5187f765, 0x895b, 0x4566, \
00779  { 0x99, 0x7d, 0xd8, 0xd8, 0xbf, 0xa4, 0x74, 0x21 } }
00780 
00781 class nsIPresShell_MOZILLA_1_8_BRANCH2 : public nsIPresShell_MOZILLA_1_8_BRANCH
00782 {
00783 public: 
00784   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRESSHELL_MOZILLA_1_8_BRANCH2_IID)
00785 
00786   virtual void BlockFlushing() = 0;
00787   virtual void UnblockFlushing() = 0;
00788 
00789   // Added in Gecko 1.8.1.9. For internal use only.
00790   virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
00791   virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
00792 };
00793 
00798 nsresult
00799 NS_NewPresShell(nsIPresShell** aInstancePtrResult);
00800 
00801 #endif /* nsIPresShell_h___ */