Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / layout / base / nsPresContext.h
blob9e674516aeff17aa290ca545a4afe46605943726
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 /* a presentation of a document, part 1 */
41 #ifndef nsPresContext_h___
42 #define nsPresContext_h___
44 #include "nsISupports.h"
45 #include "nsColor.h"
46 #include "nsCoord.h"
47 #include "nsAString.h"
48 #include "nsCOMPtr.h"
49 #include "nsIPresShell.h"
50 #include "nsRect.h"
51 #include "nsIDeviceContext.h"
52 #include "nsFont.h"
53 #include "nsIWeakReference.h"
54 #include "nsITheme.h"
55 #include "nsILanguageAtomService.h"
56 #include "nsIObserver.h"
57 #include "nsITimer.h"
58 #include "nsCRT.h"
59 #include "nsIPrintSettings.h"
60 #include "FramePropertyTable.h"
61 #include "nsGkAtoms.h"
62 #include "nsIDocument.h"
63 #include "nsRefPtrHashtable.h"
64 #include "nsCycleCollectionParticipant.h"
65 #include "nsChangeHint.h"
66 // This also pulls in gfxTypes.h, which we cannot include directly.
67 #include "gfxRect.h"
68 #include "nsRegion.h"
69 #include "nsTArray.h"
70 #include "nsAutoPtr.h"
71 #include "nsThreadUtils.h"
72 #include "nsContentUtils.h"
73 #include "nsIWidget.h"
74 #include "mozilla/TimeStamp.h"
75 #include "nsIContent.h"
77 class nsImageLoader;
78 #ifdef IBMBIDI
79 class nsBidiPresUtils;
80 #endif // IBMBIDI
82 struct nsRect;
84 class imgIRequest;
86 class nsIFontMetrics;
87 class nsIFrame;
88 class nsFrameManager;
89 class nsILinkHandler;
90 class nsStyleContext;
91 class nsIAtom;
92 class nsIEventStateManager;
93 class nsIURI;
94 class nsILookAndFeel;
95 class nsICSSPseudoComparator;
96 class nsIAtom;
97 struct nsStyleBackground;
98 struct nsStyleBorder;
99 class nsIRunnable;
100 class gfxUserFontSet;
101 class nsUserFontSet;
102 struct nsFontFaceRuleContainer;
103 class nsObjectFrame;
104 class nsTransitionManager;
105 class nsRefreshDriver;
106 class imgIContainer;
108 #ifdef MOZ_REFLOW_PERF
109 class nsIRenderingContext;
110 #endif
112 enum nsWidgetType {
113 eWidgetType_Button = 1,
114 eWidgetType_Checkbox = 2,
115 eWidgetType_Radio = 3,
116 eWidgetType_Text = 4
119 enum nsLanguageSpecificTransformType {
120 eLanguageSpecificTransformType_Unknown = -1,
121 eLanguageSpecificTransformType_None = 0,
122 eLanguageSpecificTransformType_Japanese
125 // supported values for cached bool types
126 enum nsPresContext_CachedBoolPrefType {
127 kPresContext_UseDocumentColors = 1,
128 kPresContext_UseDocumentFonts,
129 kPresContext_UnderlineLinks
132 // supported values for cached integer pref types
133 enum nsPresContext_CachedIntPrefType {
134 kPresContext_MinimumFontSize = 1,
135 kPresContext_ScrollbarSide,
136 kPresContext_BidiDirection
139 // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
140 // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
141 const PRUint8 kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable
142 const PRUint8 kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed
144 #ifdef DEBUG
145 struct nsAutoLayoutPhase;
147 enum nsLayoutPhase {
148 eLayoutPhase_Paint,
149 eLayoutPhase_Reflow,
150 eLayoutPhase_FrameC,
151 eLayoutPhase_COUNT
153 #endif
155 class nsInvalidateRequestList {
156 public:
157 struct Request {
158 nsRect mRect;
159 PRUint32 mFlags;
162 nsTArray<Request> mRequests;
165 /* Used by nsPresContext::HasAuthorSpecifiedRules */
166 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
167 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
168 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
170 class nsRootPresContext;
172 // An interface for presentation contexts. Presentation contexts are
173 // objects that provide an outer context for a presentation shell.
175 class nsPresContext : public nsIObserver {
176 public:
177 typedef mozilla::FramePropertyTable FramePropertyTable;
179 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
180 NS_DECL_NSIOBSERVER
181 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
182 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
184 enum nsPresContextType {
185 eContext_Galley, // unpaginated screen presentation
186 eContext_PrintPreview, // paginated screen presentation
187 eContext_Print, // paginated printer presentation
188 eContext_PageLayout // paginated & editable.
191 nsPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN;
194 * Initialize the presentation context from a particular device.
196 NS_HIDDEN_(nsresult) Init(nsIDeviceContext* aDeviceContext);
199 * Set the presentation shell that this context is bound to.
200 * A presentation context may only be bound to a single shell.
202 NS_HIDDEN_(void) SetShell(nsIPresShell* aShell);
205 NS_HIDDEN_(nsPresContextType) Type() const { return mType; }
208 * Get the PresentationShell that this context is bound to.
210 nsIPresShell* PresShell() const
212 NS_ASSERTION(mShell, "Null pres shell");
213 return mShell;
216 nsIPresShell* GetPresShell() const { return mShell; }
219 * Return the presentation context for the root of the view manager
220 * hierarchy that contains this presentation context, or nsnull if it can't
221 * be found (e.g. it's detached).
223 nsRootPresContext* GetRootPresContext();
224 virtual PRBool IsRoot() { return PR_FALSE; }
226 nsIDocument* Document() const
228 NS_ASSERTION(!mShell || !mShell->GetDocument() ||
229 mShell->GetDocument() == mDocument,
230 "nsPresContext doesn't have the same document as nsPresShell!");
231 return mDocument;
234 #ifdef _IMPL_NS_LAYOUT
235 nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); }
237 nsFrameManager* FrameManager()
238 { return GetPresShell()->FrameManager(); }
240 nsTransitionManager* TransitionManager() { return mTransitionManager; }
242 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
243 #endif
246 * Rebuilds all style data by throwing out the old rule tree and
247 * building a new one, and additionally applying aExtraHint (which
248 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
249 * Also rebuild the user font set.
251 void RebuildAllStyleData(nsChangeHint aExtraHint);
253 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
254 * doesn't rebuild the user font set.
256 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint);
258 void MediaFeatureValuesChanged(PRBool aCallerWillRebuildStyleData);
259 void PostMediaFeatureValuesChangedEvent();
260 NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent();
261 void FlushPendingMediaFeatureValuesChanged() {
262 if (mPendingMediaFeatureValuesChanged)
263 MediaFeatureValuesChanged(PR_FALSE);
267 * Access compatibility mode for this context. This is the same as
268 * our document's compatibility mode.
270 nsCompatibility CompatibilityMode() const {
271 return Document()->GetCompatibilityMode();
274 * Notify the context that the document's compatibility mode has changed
276 NS_HIDDEN_(void) CompatibilityModeChanged();
279 * Access the image animation mode for this context
281 PRUint16 ImageAnimationMode() const { return mImageAnimationMode; }
282 virtual NS_HIDDEN_(void) SetImageAnimationModeExternal(PRUint16 aMode);
283 NS_HIDDEN_(void) SetImageAnimationModeInternal(PRUint16 aMode);
284 #ifdef _IMPL_NS_LAYOUT
285 void SetImageAnimationMode(PRUint16 aMode)
286 { SetImageAnimationModeInternal(aMode); }
287 #else
288 void SetImageAnimationMode(PRUint16 aMode)
289 { SetImageAnimationModeExternal(aMode); }
290 #endif
293 * Get cached look and feel service. This is faster than obtaining it
294 * through the service manager.
296 nsILookAndFeel* LookAndFeel() { return mLookAndFeel; }
298 /**
299 * Get medium of presentation
301 nsIAtom* Medium() { return mMedium; }
303 void* AllocateFromShell(size_t aSize)
305 if (mShell)
306 return mShell->AllocateMisc(aSize);
307 return nsnull;
310 void FreeToShell(size_t aSize, void* aFreeChunk)
312 NS_ASSERTION(mShell, "freeing after shutdown");
313 if (mShell)
314 mShell->FreeMisc(aSize, aFreeChunk);
318 * Get the font metrics for a given font.
320 * If aUseUserFontSet is false, don't build or use the user font set.
321 * This is intended only for nsRuleNode::CalcLengthWithInitialFont
322 * (which is used from media query matching, which is in turn called
323 * when building the user font set).
325 NS_HIDDEN_(already_AddRefed<nsIFontMetrics>)
326 GetMetricsFor(const nsFont& aFont, PRBool aUseUserFontSet = PR_TRUE);
329 * Get the default font corresponding to the given ID. This object is
330 * read-only, you must copy the font to modify it.
332 * When aFontID is kPresContext_DefaultVariableFontID or
333 * kPresContext_DefaultFixedFontID (which equals
334 * kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
335 * the nsFont returned has its name as a CSS generic family (serif or
336 * sans-serif for the former, monospace for the latter), and its size
337 * as the default font size for variable or fixed fonts for the pres
338 * context's language group.
340 * For aFontID corresponds to a CSS Generic, the nsFont returned has
341 * its name as the name or names of the fonts in the user's
342 * preferences for the given generic and the pres context's language
343 * group, and its size set to the default variable font size.
345 NS_HIDDEN_(const nsFont*) GetDefaultFont(PRUint8 aFontID) const;
347 /** Get a cached boolean pref, by its type */
348 // * - initially created for bugs 31816, 20760, 22963
349 PRBool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const
351 // If called with a constant parameter, the compiler should optimize
352 // this switch statement away.
353 switch (aPrefType) {
354 case kPresContext_UseDocumentFonts:
355 return mUseDocumentFonts;
356 case kPresContext_UseDocumentColors:
357 return mUseDocumentColors;
358 case kPresContext_UnderlineLinks:
359 return mUnderlineLinks;
360 default:
361 NS_ERROR("Invalid arg passed to GetCachedBoolPref");
364 return PR_FALSE;
367 /** Get a cached integer pref, by its type */
368 // * - initially created for bugs 30910, 61883, 74186, 84398
369 PRInt32 GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const
371 // If called with a constant parameter, the compiler should optimize
372 // this switch statement away.
373 switch (aPrefType) {
374 case kPresContext_MinimumFontSize:
375 return mMinimumFontSize;
376 case kPresContext_ScrollbarSide:
377 return mPrefScrollbarSide;
378 case kPresContext_BidiDirection:
379 return mPrefBidiDirection;
380 default:
381 NS_ERROR("invalid arg passed to GetCachedIntPref");
384 return PR_FALSE;
388 * Access Nav's magic font scaler value
390 PRInt32 FontScaler() const { return mFontScaler; }
392 /**
393 * Get the default colors
395 const nscolor DefaultColor() const { return mDefaultColor; }
396 const nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
397 const nscolor DefaultLinkColor() const { return mLinkColor; }
398 const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
399 const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
400 const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
401 const nscolor FocusTextColor() const { return mFocusTextColor; }
403 PRBool GetUseFocusColors() const { return mUseFocusColors; }
404 PRUint8 FocusRingWidth() const { return mFocusRingWidth; }
405 PRBool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
406 PRUint8 GetFocusRingStyle() const { return mFocusRingStyle; }
409 * The types of image load types that the pres context needs image
410 * loaders to track invalidation for.
412 enum ImageLoadType {
413 BACKGROUND_IMAGE,
414 BORDER_IMAGE,
415 IMAGE_LOAD_TYPE_COUNT
419 * Set the list of image loaders that track invalidation for a
420 * specific frame and type of image. This list will replace any
421 * previous list for that frame and image type (and null will remove
422 * any previous list).
424 NS_HIDDEN_(void) SetImageLoaders(nsIFrame* aTargetFrame,
425 ImageLoadType aType,
426 nsImageLoader* aImageLoaders);
429 * Make an appropriate SetImageLoaders call (including potentially
430 * with null aImageLoaders) given that aFrame draws its background
431 * based on aStyleBackground.
433 NS_HIDDEN_(void) SetupBackgroundImageLoaders(nsIFrame* aFrame,
434 const nsStyleBackground*
435 aStyleBackground);
438 * Make an appropriate SetImageLoaders call (including potentially
439 * with null aImageLoaders) given that aFrame draws its border
440 * based on aStyleBorder.
442 NS_HIDDEN_(void) SetupBorderImageLoaders(nsIFrame* aFrame,
443 const nsStyleBorder* aStyleBorder);
446 * This method is called when a frame is being destroyed to
447 * ensure that the image loads get disassociated from the prescontext
449 NS_HIDDEN_(void) StopImagesFor(nsIFrame* aTargetFrame);
451 NS_HIDDEN_(void) SetContainer(nsISupports* aContainer);
453 virtual NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerExternal() const;
454 NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerInternal() const;
455 #ifdef _IMPL_NS_LAYOUT
456 already_AddRefed<nsISupports> GetContainer() const
457 { return GetContainerInternal(); }
458 #else
459 already_AddRefed<nsISupports> GetContainer() const
460 { return GetContainerExternal(); }
461 #endif
463 // XXX this are going to be replaced with set/get container
464 void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
465 nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
468 * Get the visible area associated with this presentation context.
469 * This is the size of the visible area that is used for
470 * presenting the document. The returned value is in the standard
471 * nscoord units (as scaled by the device context).
473 nsRect GetVisibleArea() { return mVisibleArea; }
476 * Set the currently visible area. The units for r are standard
477 * nscoord units (as scaled by the device context).
479 void SetVisibleArea(const nsRect& r) {
480 if (!r.IsExactEqual(mVisibleArea)) {
481 mVisibleArea = r;
482 // Visible area does not affect media queries when paginated.
483 if (!IsPaginated() && HasCachedStyleData())
484 PostMediaFeatureValuesChangedEvent();
489 * Return true if this presentation context is a paginated
490 * context.
492 PRBool IsPaginated() const { return mPaginated; }
495 * Sets whether the presentation context can scroll for a paginated
496 * context.
498 NS_HIDDEN_(void) SetPaginatedScrolling(PRBool aResult);
501 * Return true if this presentation context can scroll for paginated
502 * context.
504 PRBool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
507 * Get/set the size of a page
509 nsSize GetPageSize() { return mPageSize; }
510 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
513 * Get/set whether this document should be treated as having real pages
514 * XXX This raises the obvious question of why a document that isn't a page
515 * is paginated; there isn't a good reason except history
517 PRBool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
518 void SetIsRootPaginatedDocument(PRBool aIsRootPaginatedDocument)
519 { mIsRootPaginatedDocument = aIsRootPaginatedDocument; }
522 * Get/set the print scaling level; used by nsPageFrame to scale up
523 * pages. Set safe to call before reflow, get guaranteed to be set
524 * properly after reflow.
527 float GetPageScale() { return mPageScale; }
528 void SetPageScale(float aScale) { mPageScale = aScale; }
531 * Get/set the scaling facor to use when rendering the pages for print preview.
532 * Only safe to get after print preview set up; safe to set anytime.
533 * This is a scaling factor for the display of the print preview. It
534 * does not affect layout. It only affects the size of the onscreen pages
535 * in print preview.
536 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
538 float GetPrintPreviewScale() { return mPPScale; }
539 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
541 nsIDeviceContext* DeviceContext() { return mDeviceContext; }
542 nsIEventStateManager* EventStateManager() { return mEventManager; }
543 nsIAtom* GetLanguageFromCharset() { return mLanguage; }
545 float TextZoom() { return mTextZoom; }
546 void SetTextZoom(float aZoom) {
547 if (aZoom == mTextZoom)
548 return;
550 mTextZoom = aZoom;
551 if (HasCachedStyleData()) {
552 // Media queries could have changed since we changed the meaning
553 // of 'em' units in them.
554 MediaFeatureValuesChanged(PR_TRUE);
555 RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
559 float GetFullZoom() { return mFullZoom; }
560 void SetFullZoom(float aZoom);
562 nscoord GetAutoQualityMinFontSize() {
563 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
566 static PRInt32 AppUnitsPerCSSPixel() { return nsIDeviceContext::AppUnitsPerCSSPixel(); }
567 PRInt32 AppUnitsPerDevPixel() const { return mDeviceContext->AppUnitsPerDevPixel(); }
568 static PRInt32 AppUnitsPerCSSInch() { return nsIDeviceContext::AppUnitsPerCSSInch(); }
570 static nscoord CSSPixelsToAppUnits(PRInt32 aPixels)
571 { return NSIntPixelsToAppUnits(aPixels,
572 nsIDeviceContext::AppUnitsPerCSSPixel()); }
574 static nscoord CSSPixelsToAppUnits(float aPixels)
575 { return NSFloatPixelsToAppUnits(aPixels,
576 float(nsIDeviceContext::AppUnitsPerCSSPixel())); }
578 static PRInt32 AppUnitsToIntCSSPixels(nscoord aAppUnits)
579 { return NSAppUnitsToIntPixels(aAppUnits,
580 float(nsIDeviceContext::AppUnitsPerCSSPixel())); }
582 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits)
583 { return NSAppUnitsToFloatPixels(aAppUnits,
584 float(nsIDeviceContext::AppUnitsPerCSSPixel())); }
586 nscoord DevPixelsToAppUnits(PRInt32 aPixels) const
587 { return NSIntPixelsToAppUnits(aPixels,
588 mDeviceContext->AppUnitsPerDevPixel()); }
590 PRInt32 AppUnitsToDevPixels(nscoord aAppUnits) const
591 { return NSAppUnitsToIntPixels(aAppUnits,
592 float(mDeviceContext->AppUnitsPerDevPixel())); }
594 PRInt32 CSSPixelsToDevPixels(PRInt32 aPixels)
595 { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }
597 float CSSPixelsToDevPixels(float aPixels)
599 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
600 float(mDeviceContext->AppUnitsPerDevPixel()));
603 PRInt32 DevPixelsToIntCSSPixels(PRInt32 aPixels)
604 { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); }
606 float DevPixelsToFloatCSSPixels(PRInt32 aPixels)
607 { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); }
609 // If there is a remainder, it is rounded to nearest app units.
610 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
611 { return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits); }
613 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const
614 { return mDeviceContext->AppUnitsToGfxUnits(aAppUnits); }
616 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const
617 { return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
618 AppUnitsToGfxUnits(aAppRect.y),
619 AppUnitsToGfxUnits(aAppRect.width),
620 AppUnitsToGfxUnits(aAppRect.height)); }
622 static nscoord CSSTwipsToAppUnits(float aTwips)
623 { return NSToCoordRoundWithClamp(
624 nsIDeviceContext::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); }
626 // Margin-specific version, since they often need TwipsToAppUnits
627 static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips)
628 { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.left)),
629 CSSTwipsToAppUnits(float(marginInTwips.top)),
630 CSSTwipsToAppUnits(float(marginInTwips.right)),
631 CSSTwipsToAppUnits(float(marginInTwips.bottom))); }
633 static nscoord CSSPointsToAppUnits(float aPoints)
634 { return NSToCoordRound(aPoints * nsIDeviceContext::AppUnitsPerCSSInch() /
635 POINTS_PER_INCH_FLOAT); }
637 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
638 { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
640 struct ScrollbarStyles {
641 // Always one of NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
642 // or NS_STYLE_OVERFLOW_AUTO.
643 PRUint8 mHorizontal, mVertical;
644 ScrollbarStyles(PRUint8 h, PRUint8 v) : mHorizontal(h), mVertical(v) {}
645 ScrollbarStyles() {}
646 PRBool operator==(const ScrollbarStyles& aStyles) const {
647 return aStyles.mHorizontal == mHorizontal && aStyles.mVertical == mVertical;
649 PRBool operator!=(const ScrollbarStyles& aStyles) const {
650 return aStyles.mHorizontal != mHorizontal || aStyles.mVertical != mVertical;
653 void SetViewportOverflowOverride(PRUint8 aX, PRUint8 aY)
655 mViewportStyleOverflow.mHorizontal = aX;
656 mViewportStyleOverflow.mVertical = aY;
658 ScrollbarStyles GetViewportOverflowOverride()
660 return mViewportStyleOverflow;
664 * Set and get methods for controlling the background drawing
666 PRBool GetBackgroundImageDraw() const { return mDrawImageBackground; }
667 void SetBackgroundImageDraw(PRBool aCanDraw)
669 NS_ASSERTION(!(aCanDraw & ~1), "Value must be true or false");
670 mDrawImageBackground = aCanDraw;
673 PRBool GetBackgroundColorDraw() const { return mDrawColorBackground; }
674 void SetBackgroundColorDraw(PRBool aCanDraw)
676 NS_ASSERTION(!(aCanDraw & ~1), "Value must be true or false");
677 mDrawColorBackground = aCanDraw;
680 #ifdef IBMBIDI
682 * Check if bidi enabled (set depending on the presence of RTL
683 * characters or when default directionality is RTL).
684 * If enabled, we should apply the Unicode Bidi Algorithm
686 * @lina 07/12/2000
688 virtual PRBool BidiEnabledExternal() const { return BidiEnabledInternal(); }
689 PRBool BidiEnabledInternal() const { return Document()->GetBidiEnabled(); }
690 #ifdef _IMPL_NS_LAYOUT
691 PRBool BidiEnabled() const { return BidiEnabledInternal(); }
692 #else
693 PRBool BidiEnabled() const { return BidiEnabledExternal(); }
694 #endif
697 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
699 * @lina 07/12/2000
701 NS_HIDDEN_(void) SetBidiEnabled() const;
704 * Set visual or implicit mode into the pres context.
706 * Visual directionality is a presentation method that displays text
707 * as if it were a uni-directional, according to the primary display
708 * direction only.
710 * Implicit directionality is a presentation method in which the
711 * direction is determined by the Bidi algorithm according to the
712 * category of the characters and the category of the adjacent
713 * characters, and according to their primary direction.
715 * @lina 05/02/2000
717 void SetVisualMode(PRBool aIsVisual)
719 NS_ASSERTION(!(aIsVisual & ~1), "Value must be true or false");
720 mIsVisual = aIsVisual;
724 * Check whether the content should be treated as visual.
726 * @lina 05/02/2000
728 PRBool IsVisualMode() const { return mIsVisual; }
730 //Mohamed
733 * Get a Bidi presentation utilities object
735 NS_HIDDEN_(nsBidiPresUtils*) GetBidiUtils();
738 * Set the Bidi options for the presentation context
740 NS_HIDDEN_(void) SetBidi(PRUint32 aBidiOptions,
741 PRBool aForceRestyle = PR_FALSE);
744 * Get the Bidi options for the presentation context
745 * Not inline so consumers of nsPresContext are not forced to
746 * include nsIDocument.
748 NS_HIDDEN_(PRUint32) GetBidi() const;
750 PRUint32 GetBidiMemoryUsed();
751 #else
752 PRUint32 GetBidiMemoryUsed() { return 0; }
753 #endif // IBMBIDI
756 * Render only Selection
758 void SetIsRenderingOnlySelection(PRBool aResult)
760 NS_ASSERTION(!(aResult & ~1), "Value must be true or false");
761 mIsRenderingOnlySelection = aResult;
764 PRBool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; }
766 NS_HIDDEN_(PRBool) IsTopLevelWindowInactive();
769 * Obtain a native them for rendering our widgets (both form controls and html)
771 NS_HIDDEN_(nsITheme*) GetTheme();
774 * Notify the pres context that the theme has changed. An internal switch
775 * means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
776 * Otherwise, the OS is telling us that the native theme for the platform
777 * has changed.
779 NS_HIDDEN_(void) ThemeChanged();
782 * Notify the pres context that a system color has changed
784 NS_HIDDEN_(void) SysColorChanged();
786 /** Printing methods below should only be used for Medium() == print **/
787 NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings);
789 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
791 /* Accessor for table of frame properties */
792 FramePropertyTable* PropertyTable() { return &mPropertyTable; }
794 /* Helper function that ensures that this prescontext is shown in its
795 docshell if it's the most recent prescontext for the docshell. Returns
796 whether the prescontext is now being shown.
798 NS_HIDDEN_(PRBool) EnsureVisible();
800 #ifdef MOZ_REFLOW_PERF
801 NS_HIDDEN_(void) CountReflows(const char * aName,
802 nsIFrame * aFrame);
803 #endif
806 * This table maps border-width enums 'thin', 'medium', 'thick'
807 * to actual nscoord values.
809 const nscoord* GetBorderWidthTable() { return mBorderWidthTable; }
811 PRBool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); }
812 PRBool IsScreen() { return (mMedium == nsGkAtoms::screen ||
813 mType == eContext_PageLayout ||
814 mType == eContext_PrintPreview); }
816 // Is this presentation in a chrome docshell?
817 PRBool IsChrome() const
819 return mIsChromeIsCached ? mIsChrome : IsChromeSlow();
822 virtual void InvalidateIsChromeCacheExternal();
823 void InvalidateIsChromeCacheInternal() { mIsChromeIsCached = PR_FALSE; }
824 #ifdef _IMPL_NS_LAYOUT
825 void InvalidateIsChromeCache()
826 { InvalidateIsChromeCacheInternal(); }
827 #else
828 void InvalidateIsChromeCache()
829 { InvalidateIsChromeCacheExternal(); }
830 #endif
832 // Public API for native theme code to get style internals.
833 virtual PRBool HasAuthorSpecifiedRules(nsIFrame *aFrame, PRUint32 ruleTypeMask) const;
835 // Is it OK to let the page specify colors and backgrounds?
836 PRBool UseDocumentColors() const {
837 return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome();
840 PRBool SupressingResizeReflow() const { return mSupressResizeReflow; }
842 virtual NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetExternal();
843 NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetInternal();
844 #ifdef _IMPL_NS_LAYOUT
845 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); }
846 #else
847 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); }
848 #endif
850 void FlushUserFontSet();
851 void RebuildUserFontSet(); // asynchronously
853 // Should be called whenever the set of fonts available in the user
854 // font set changes (e.g., because a new font loads, or because the
855 // user font set is changed and fonts become unavailable).
856 void UserFontSetUpdated();
858 // Ensure that it is safe to hand out CSS rules outside the layout
859 // engine by ensuring that all CSS style sheets have unique inners
860 // and, if necessary, synchronously rebuilding all style data.
861 // Returns true on success and false on failure (not safe).
862 PRBool EnsureSafeToHandOutCSSRules();
864 void NotifyInvalidation(const nsRect& aRect, PRUint32 aFlags);
865 void NotifyDidPaintForSubtree();
866 void FireDOMPaintEvent();
868 PRBool IsDOMPaintEventPending() {
869 return !mInvalidateRequests.mRequests.IsEmpty();
871 void ClearMozAfterPaintEvents() {
872 mInvalidateRequests.mRequests.Clear();
875 PRBool IsProcessingRestyles() const {
876 return mProcessingRestyles;
879 void SetProcessingRestyles(PRBool aProcessing) {
880 NS_ASSERTION(aProcessing != PRBool(mProcessingRestyles),
881 "should never nest");
882 mProcessingRestyles = aProcessing;
885 PRBool IsProcessingAnimationStyleChange() const {
886 return mProcessingAnimationStyleChange;
889 void SetProcessingAnimationStyleChange(PRBool aProcessing) {
890 NS_ASSERTION(aProcessing != PRBool(mProcessingAnimationStyleChange),
891 "should never nest");
892 mProcessingAnimationStyleChange = aProcessing;
896 * Notify the prescontext that the presshell is about to reflow a reflow root.
897 * The single argument indicates whether this reflow should be interruptible.
898 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
899 * will always return false. If aInterruptible is true then CheckForInterrupt
900 * will return true when a pending event is detected. This is for use by the
901 * presshell only. Reflow code wanting to prevent interrupts should use
902 * InterruptPreventer.
904 void ReflowStarted(PRBool aInterruptible);
907 * A class that can be used to temporarily disable reflow interruption.
909 class InterruptPreventer;
910 friend class InterruptPreventer;
911 class NS_STACK_CLASS InterruptPreventer {
912 public:
913 InterruptPreventer(nsPresContext* aCtx) :
914 mCtx(aCtx),
915 mInterruptsEnabled(aCtx->mInterruptsEnabled),
916 mHasPendingInterrupt(aCtx->mHasPendingInterrupt)
918 mCtx->mInterruptsEnabled = PR_FALSE;
919 mCtx->mHasPendingInterrupt = PR_FALSE;
921 ~InterruptPreventer() {
922 mCtx->mInterruptsEnabled = mInterruptsEnabled;
923 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
926 private:
927 nsPresContext* mCtx;
928 PRBool mInterruptsEnabled;
929 PRBool mHasPendingInterrupt;
933 * Check for interrupts. This may return true if a pending event is
934 * detected. Once it has returned true, it will keep returning true
935 * until ReflowStarted is called. In all cases where this returns true,
936 * the passed-in frame (which should be the frame whose reflow will be
937 * interrupted if true is returned) will be passed to
938 * nsIPresShell::FrameNeedsToContinueReflow.
940 PRBool CheckForInterrupt(nsIFrame* aFrame);
942 * Returns true if CheckForInterrupt has returned true since the last
943 * ReflowStarted call. Cannot itself trigger an interrupt check.
945 PRBool HasPendingInterrupt() { return mHasPendingInterrupt; }
948 * If we have a presshell, and if the given content's current
949 * document is the same as our presshell's document, return the
950 * content's primary frame. Otherwise, return null. Only use this
951 * if you care about which presshell the primary frame is in.
953 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent) {
954 NS_PRECONDITION(aContent, "Don't do that");
955 if (GetPresShell() &&
956 GetPresShell()->GetDocument() == aContent->GetCurrentDoc()) {
957 return aContent->GetPrimaryFrame();
959 return nsnull;
962 void NotifyDestroyingFrame(nsIFrame* aFrame)
964 PropertyTable()->DeleteAllFor(aFrame);
966 inline void ForgetUpdatePluginGeometryFrame(nsIFrame* aFrame);
968 void SetContainsUpdatePluginGeometryFrame(PRBool aValue)
970 mContainsUpdatePluginGeometryFrame = aValue;
973 PRBool MayHaveFixedBackgroundFrames() { return mMayHaveFixedBackgroundFrames; }
974 void SetHasFixedBackgroundFrame() { mMayHaveFixedBackgroundFrames = PR_TRUE; }
976 PRUint32 EstimateMemoryUsed() {
977 PRUint32 result = 0;
979 result += sizeof(nsPresContext);
980 result += GetBidiMemoryUsed();
982 return result;
985 PRBool IsRootContentDocument();
987 protected:
988 friend class nsRunnableMethod<nsPresContext>;
989 NS_HIDDEN_(void) ThemeChangedInternal();
990 NS_HIDDEN_(void) SysColorChangedInternal();
992 NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, PRUint16 aMode);
993 #ifdef MOZ_SMIL
994 NS_HIDDEN_(void) SetSMILAnimations(nsIDocument *aDoc, PRUint16 aNewMode,
995 PRUint16 aOldMode);
996 #endif // MOZ_SMIL
997 NS_HIDDEN_(void) GetDocumentColorPreferences();
999 NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName);
1000 static NS_HIDDEN_(int) PrefChangedCallback(const char*, void*);
1002 NS_HIDDEN_(void) UpdateAfterPreferencesChanged();
1003 static NS_HIDDEN_(void) PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure);
1005 NS_HIDDEN_(void) GetUserPreferences();
1006 NS_HIDDEN_(void) GetFontPreferences();
1008 NS_HIDDEN_(void) UpdateCharSet(const nsAFlatCString& aCharSet);
1010 PRBool MayHavePaintEventListener();
1012 void HandleRebuildUserFontSet() {
1013 mPostedFlushUserFontSet = PR_FALSE;
1014 FlushUserFontSet();
1017 PRBool HavePendingInputEvent();
1019 // Can't be inline because we can't include nsStyleSet.h.
1020 PRBool HasCachedStyleData();
1022 PRBool IsChromeSlow() const;
1024 // IMPORTANT: The ownership implicit in the following member variables
1025 // has been explicitly checked. If you add any members to this class,
1026 // please make the ownership explicit (pinkerton, scc).
1028 nsPresContextType mType;
1029 nsIPresShell* mShell; // [WEAK]
1030 nsCOMPtr<nsIDocument> mDocument;
1031 nsIDeviceContext* mDeviceContext; // [STRONG] could be weak, but
1032 // better safe than sorry.
1033 // Cannot reintroduce cycles
1034 // since there is no dependency
1035 // from gfx back to layout.
1036 nsIEventStateManager* mEventManager; // [STRONG]
1037 nsILookAndFeel* mLookAndFeel; // [STRONG]
1038 nsRefPtr<nsRefreshDriver> mRefreshDriver;
1039 nsRefPtr<nsTransitionManager> mTransitionManager;
1040 nsIAtom* mMedium; // initialized by subclass ctors;
1041 // weak pointer to static atom
1043 nsILinkHandler* mLinkHandler; // [WEAK]
1045 // Formerly mLangGroup; moving from charset-oriented langGroup to
1046 // maintaining actual language settings everywhere (see bug 524107).
1047 // This may in fact hold a langGroup such as x-western rather than
1048 // a specific language, however (e.g, if it is inferred from the
1049 // charset rather than explicitly specified as a lang attribute).
1050 nsIAtom* mLanguage; // [STRONG]
1052 nsRefPtrHashtable<nsVoidPtrHashKey, nsImageLoader>
1053 mImageLoaders[IMAGE_LOAD_TYPE_COUNT];
1055 nsWeakPtr mContainer;
1057 float mTextZoom; // Text zoom, defaults to 1.0
1058 float mFullZoom; // Page zoom, defaults to 1.0
1060 PRInt32 mCurAppUnitsPerDevPixel;
1061 PRInt32 mAutoQualityMinFontSizePixelsPref;
1063 #ifdef IBMBIDI
1064 nsAutoPtr<nsBidiPresUtils> mBidiUtils;
1065 #endif
1067 nsCOMPtr<nsITheme> mTheme;
1068 nsCOMPtr<nsILanguageAtomService> mLangService;
1069 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1070 nsCOMPtr<nsITimer> mPrefChangedTimer;
1072 FramePropertyTable mPropertyTable;
1074 nsInvalidateRequestList mInvalidateRequests;
1076 // container for per-context fonts (downloadable, SVG, etc.)
1077 nsUserFontSet* mUserFontSet;
1078 // The list of @font-face rules that we put into mUserFontSet
1079 nsTArray<nsFontFaceRuleContainer> mFontFaceRules;
1081 PRInt32 mFontScaler;
1082 nscoord mMinimumFontSize;
1084 nsRect mVisibleArea;
1085 nsSize mPageSize;
1086 float mPageScale;
1087 float mPPScale;
1089 nscolor mDefaultColor;
1090 nscolor mBackgroundColor;
1092 nscolor mLinkColor;
1093 nscolor mActiveLinkColor;
1094 nscolor mVisitedLinkColor;
1096 nscolor mFocusBackgroundColor;
1097 nscolor mFocusTextColor;
1099 ScrollbarStyles mViewportStyleOverflow;
1100 PRUint8 mFocusRingWidth;
1102 PRUint16 mImageAnimationMode;
1103 PRUint16 mImageAnimationModePref;
1105 nsFont mDefaultVariableFont;
1106 nsFont mDefaultFixedFont;
1107 nsFont mDefaultSerifFont;
1108 nsFont mDefaultSansSerifFont;
1109 nsFont mDefaultMonospaceFont;
1110 nsFont mDefaultCursiveFont;
1111 nsFont mDefaultFantasyFont;
1113 nscoord mBorderWidthTable[3];
1115 PRUint32 mInterruptChecksToSkip;
1117 mozilla::TimeStamp mReflowStartTime;
1119 unsigned mHasPendingInterrupt : 1;
1120 unsigned mInterruptsEnabled : 1;
1121 unsigned mUseDocumentFonts : 1;
1122 unsigned mUseDocumentColors : 1;
1123 unsigned mUnderlineLinks : 1;
1124 unsigned mSendAfterPaintToContent : 1;
1125 unsigned mUseFocusColors : 1;
1126 unsigned mFocusRingOnAnything : 1;
1127 unsigned mFocusRingStyle : 1;
1128 unsigned mDrawImageBackground : 1;
1129 unsigned mDrawColorBackground : 1;
1130 unsigned mNeverAnimate : 1;
1131 unsigned mIsRenderingOnlySelection : 1;
1132 unsigned mPaginated : 1;
1133 unsigned mCanPaginatedScroll : 1;
1134 unsigned mDoScaledTwips : 1;
1135 unsigned mEnableJapaneseTransform : 1;
1136 unsigned mIsRootPaginatedDocument : 1;
1137 unsigned mPrefBidiDirection : 1;
1138 unsigned mPrefScrollbarSide : 2;
1139 unsigned mPendingSysColorChanged : 1;
1140 unsigned mPendingThemeChanged : 1;
1141 unsigned mPendingMediaFeatureValuesChanged : 1;
1142 unsigned mPrefChangePendingNeedsReflow : 1;
1143 unsigned mMayHaveFixedBackgroundFrames : 1;
1145 // Is the current mUserFontSet valid?
1146 unsigned mUserFontSetDirty : 1;
1147 // Has GetUserFontSet() been called?
1148 unsigned mGetUserFontSetCalled : 1;
1149 // Do we currently have an event posted to call FlushUserFontSet?
1150 unsigned mPostedFlushUserFontSet : 1;
1152 // resize reflow is suppressed when the only change has been to zoom
1153 // the document rather than to change the document's dimensions
1154 unsigned mSupressResizeReflow : 1;
1156 unsigned mIsVisual : 1;
1158 unsigned mProcessingRestyles : 1;
1159 unsigned mProcessingAnimationStyleChange : 1;
1161 unsigned mContainsUpdatePluginGeometryFrame : 1;
1162 unsigned mFireAfterPaintEvents : 1;
1164 // Cache whether we are chrome or not because it is expensive.
1165 // mIsChromeIsCached tells us if mIsChrome is valid or we need to get the
1166 // value the slow way.
1167 mutable unsigned mIsChromeIsCached : 1;
1168 mutable unsigned mIsChrome : 1;
1170 #ifdef DEBUG
1171 PRBool mInitialized;
1172 #endif
1175 protected:
1177 virtual ~nsPresContext() NS_HIDDEN;
1179 // these are private, use the list in nsFont.h if you want a public list
1180 enum {
1181 eDefaultFont_Variable,
1182 eDefaultFont_Fixed,
1183 eDefaultFont_Serif,
1184 eDefaultFont_SansSerif,
1185 eDefaultFont_Monospace,
1186 eDefaultFont_Cursive,
1187 eDefaultFont_Fantasy,
1188 eDefaultFont_COUNT
1191 #ifdef DEBUG
1192 private:
1193 friend struct nsAutoLayoutPhase;
1194 PRUint32 mLayoutPhaseCount[eLayoutPhase_COUNT];
1195 public:
1196 PRUint32 LayoutPhaseCount(nsLayoutPhase aPhase) {
1197 return mLayoutPhaseCount[aPhase];
1199 #endif
1203 class nsRootPresContext : public nsPresContext {
1204 public:
1205 nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN;
1206 virtual ~nsRootPresContext();
1209 * Ensure that NotifyDidPaintForSubtree is eventually called on this
1210 * object after a timeout.
1212 void EnsureEventualDidPaintEvent();
1214 void CancelDidPaintTimer()
1216 if (mNotifyDidPaintTimer) {
1217 mNotifyDidPaintTimer->Cancel();
1218 mNotifyDidPaintTimer = nsnull;
1223 * Registers a plugin to receive geometry updates (position and clip
1224 * region) so it can update its widget.
1225 * Callers must call UnregisterPluginForGeometryUpdates before
1226 * the aPlugin frame is destroyed.
1228 void RegisterPluginForGeometryUpdates(nsObjectFrame* aPlugin);
1230 * Stops a plugin receiving geometry updates (position and clip
1231 * region). If the plugin was not already registered, this does
1232 * nothing.
1234 void UnregisterPluginForGeometryUpdates(nsObjectFrame* aPlugin);
1237 * Iterate through all plugins that are registered for geometry updates
1238 * and update their position and clip region to match the current frame
1239 * tree.
1241 void UpdatePluginGeometry();
1244 * Iterate through all plugins that are registered for geometry updates
1245 * and compute their position and clip region according to the
1246 * current frame tree. Only frames at or under aChangedRoot can have
1247 * changed their geometry. The computed positions and clip regions are
1248 * appended to aConfigurations.
1250 void GetPluginGeometryUpdates(nsIFrame* aChangedRoot,
1251 nsTArray<nsIWidget::Configuration>* aConfigurations);
1254 * When all geometry updates have been applied, call this function
1255 * in case the nsObjectFrames have work to do after the widgets
1256 * have been updated.
1258 void DidApplyPluginGeometryUpdates();
1260 virtual PRBool IsRoot() { return PR_TRUE; }
1263 * This method is called off an event to force the plugin geometry to
1264 * be updated. First we try to paint, since updating plugin geometry
1265 * during paint is best for keeping plugins in sync with content.
1266 * But we also force geometry updates in case painting doesn't work.
1268 void SynchronousPluginGeometryUpdate();
1271 * Call this after reflow and scrolling to ensure that the geometry
1272 * of any windowed plugins is updated. aFrame is the root of the
1273 * frame subtree whose geometry has changed.
1275 void RequestUpdatePluginGeometry(nsIFrame* aFrame);
1278 * Call this when a frame is being destroyed and
1279 * mContainsUpdatePluginGeometryFrame is set in the frame's prescontext.
1281 void RootForgetUpdatePluginGeometryFrame(nsIFrame* aFrame);
1284 * Increment DOM-modification generation counter to indicate that
1285 * the DOM has changed in a way that might lead to style changes/
1286 * reflows/frame creation and destruction.
1288 void IncrementDOMGeneration() { mDOMGeneration++; }
1291 * Get the current DOM generation counter.
1293 PRUint32 GetDOMGeneration() { return mDOMGeneration; }
1295 private:
1296 nsCOMPtr<nsITimer> mNotifyDidPaintTimer;
1297 nsTHashtable<nsPtrHashKey<nsObjectFrame> > mRegisteredPlugins;
1298 // if mNeedsToUpdatePluginGeometry is set, then this is the frame to
1299 // use as the root of the subtree to search for plugin updates, or
1300 // null to use the root frame of this prescontext
1301 nsIFrame* mUpdatePluginGeometryForFrame;
1302 PRUint32 mDOMGeneration;
1303 PRPackedBool mNeedsToUpdatePluginGeometry;
1306 inline void
1307 nsPresContext::ForgetUpdatePluginGeometryFrame(nsIFrame* aFrame)
1309 if (mContainsUpdatePluginGeometryFrame) {
1310 nsRootPresContext* rootPC = GetRootPresContext();
1311 if (rootPC) {
1312 rootPC->RootForgetUpdatePluginGeometryFrame(aFrame);
1317 #ifdef DEBUG
1319 struct nsAutoLayoutPhase {
1320 nsAutoLayoutPhase(nsPresContext* aPresContext, nsLayoutPhase aPhase)
1321 : mPresContext(aPresContext), mPhase(aPhase), mCount(0)
1323 Enter();
1326 ~nsAutoLayoutPhase()
1328 Exit();
1329 NS_ASSERTION(mCount == 0, "imbalanced");
1332 void Enter()
1334 switch (mPhase) {
1335 case eLayoutPhase_Paint:
1336 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
1337 "recurring into paint");
1338 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
1339 "painting in the middle of reflow");
1340 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
1341 "painting in the middle of frame construction");
1342 break;
1343 case eLayoutPhase_Reflow:
1344 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
1345 "reflowing in the middle of a paint");
1346 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
1347 "recurring into reflow");
1348 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
1349 "reflowing in the middle of frame construction");
1350 break;
1351 case eLayoutPhase_FrameC:
1352 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
1353 "constructing frames in the middle of a paint");
1354 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
1355 "constructing frames in the middle of reflow");
1356 NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
1357 "recurring into frame construction");
1358 NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
1359 "constructing frames and scripts are not blocked");
1360 break;
1361 default:
1362 break;
1364 ++(mPresContext->mLayoutPhaseCount[mPhase]);
1365 ++mCount;
1368 void Exit()
1370 NS_ASSERTION(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
1371 "imbalanced");
1372 --(mPresContext->mLayoutPhaseCount[mPhase]);
1373 --mCount;
1376 private:
1377 nsPresContext *mPresContext;
1378 nsLayoutPhase mPhase;
1379 PRUint32 mCount;
1382 #define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
1383 nsAutoLayoutPhase autoLayoutPhase((pc_), (eLayoutPhase_##phase_))
1384 #define LAYOUT_PHASE_TEMP_EXIT() \
1385 PR_BEGIN_MACRO \
1386 autoLayoutPhase.Exit(); \
1387 PR_END_MACRO
1388 #define LAYOUT_PHASE_TEMP_REENTER() \
1389 PR_BEGIN_MACRO \
1390 autoLayoutPhase.Enter(); \
1391 PR_END_MACRO
1393 #else
1395 #define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
1396 PR_BEGIN_MACRO PR_END_MACRO
1397 #define LAYOUT_PHASE_TEMP_EXIT() \
1398 PR_BEGIN_MACRO PR_END_MACRO
1399 #define LAYOUT_PHASE_TEMP_REENTER() \
1400 PR_BEGIN_MACRO PR_END_MACRO
1402 #endif
1404 #ifdef MOZ_REFLOW_PERF
1406 #define DO_GLOBAL_REFLOW_COUNT(_name) \
1407 aPresContext->CountReflows((_name), (nsIFrame*)this);
1408 #else
1409 #define DO_GLOBAL_REFLOW_COUNT(_name)
1410 #endif // MOZ_REFLOW_PERF
1412 #endif /* nsPresContext_h___ */