1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* a presentation of a document, part 1 */
8 #ifndef nsPresContext_h___
9 #define nsPresContext_h___
11 #include "mozilla/Attributes.h"
12 #include "mozilla/WeakPtr.h"
16 #include "nsIPresShell.h"
19 #include "gfxFontConstants.h"
21 #include "nsIObserver.h"
24 #include "FramePropertyTable.h"
25 #include "nsGkAtoms.h"
26 #include "nsCycleCollectionParticipant.h"
27 #include "nsChangeHint.h"
29 // This also pulls in gfxTypes.h, which we cannot include directly.
32 #include "nsAutoPtr.h"
33 #include "mozilla/MemoryReporting.h"
34 #include "mozilla/TimeStamp.h"
35 #include "mozilla/AppUnits.h"
37 #include "nsThreadUtils.h"
38 #include "ScrollbarStyles.h"
39 #include "nsIMessageManager.h"
40 #include "mozilla/RestyleLogging.h"
42 class nsBidiPresUtils
;
44 class nsIPrintSettings
;
48 class nsILanguageAtomService
;
55 class nsICSSPseudoComparator
;
56 struct nsStyleBackground
;
60 class gfxTextPerfMetrics
;
61 struct nsFontFaceRuleContainer
;
63 class nsTransitionManager
;
64 class nsAnimationManager
;
65 class nsRefreshDriver
;
67 class nsDeviceContext
;
68 class gfxMissingFontRecorder
;
71 class EventStateManager
;
73 class CounterStyleManager
;
82 // supported values for cached bool types
83 enum nsPresContext_CachedBoolPrefType
{
84 kPresContext_UseDocumentFonts
= 1,
85 kPresContext_UnderlineLinks
88 // supported values for cached integer pref types
89 enum nsPresContext_CachedIntPrefType
{
90 kPresContext_ScrollbarSide
= 1,
91 kPresContext_BidiDirection
94 // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
95 // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
96 const uint8_t kPresContext_DefaultVariableFont_ID
= 0x00; // kGenericFont_moz_variable
97 const uint8_t kPresContext_DefaultFixedFont_ID
= 0x01; // kGenericFont_moz_fixed
100 struct nsAutoLayoutPhase
;
110 class nsInvalidateRequestList
{
117 void TakeFrom(nsInvalidateRequestList
* aList
)
119 mRequests
.MoveElementsFrom(aList
->mRequests
);
121 bool IsEmpty() { return mRequests
.IsEmpty(); }
123 nsTArray
<Request
> mRequests
;
126 /* Used by nsPresContext::HasAuthorSpecifiedRules */
127 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
128 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
129 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
130 #define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3)
132 class nsRootPresContext
;
134 // An interface for presentation contexts. Presentation contexts are
135 // objects that provide an outer context for a presentation shell.
137 class nsPresContext
: public nsIObserver
{
139 typedef mozilla::FramePropertyTable FramePropertyTable
;
140 typedef mozilla::ScrollbarStyles ScrollbarStyles
;
142 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
144 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
145 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext
)
147 enum nsPresContextType
{
148 eContext_Galley
, // unpaginated screen presentation
149 eContext_PrintPreview
, // paginated screen presentation
150 eContext_Print
, // paginated printer presentation
151 eContext_PageLayout
// paginated & editable.
154 nsPresContext(nsIDocument
* aDocument
, nsPresContextType aType
);
157 * Initialize the presentation context from a particular device.
159 nsresult
Init(nsDeviceContext
* aDeviceContext
);
162 * Set the presentation shell that this context is bound to.
163 * A presentation context may only be bound to a single shell.
165 void SetShell(nsIPresShell
* aShell
);
168 nsPresContextType
Type() const { return mType
; }
171 * Get the PresentationShell that this context is bound to.
173 nsIPresShell
* PresShell() const
175 NS_ASSERTION(mShell
, "Null pres shell");
179 nsIPresShell
* GetPresShell() const { return mShell
; }
182 * Returns the parent prescontext for this one. Returns null if this is a
185 nsPresContext
* GetParentPresContext();
188 * Returns the prescontext of the toplevel content document that contains
189 * this presentation, or null if there isn't one.
191 nsPresContext
* GetToplevelContentDocumentPresContext();
194 * Returns the nearest widget for the root frame of this.
196 * @param aOffset If non-null the offset from the origin of the root
197 * frame's view to the widget's origin (usually positive)
198 * expressed in appunits of this will be returned in
201 nsIWidget
* GetNearestWidget(nsPoint
* aOffset
= nullptr);
204 * Returns the root widget for this.
205 * Note that the widget is a mediater with IME.
207 nsIWidget
* GetRootWidget();
210 * Return the presentation context for the root of the view manager
211 * hierarchy that contains this presentation context, or nullptr if it can't
212 * be found (e.g. it's detached).
214 nsRootPresContext
* GetRootPresContext();
215 nsRootPresContext
* GetDisplayRootPresContext();
216 virtual bool IsRoot() { return false; }
218 nsIDocument
* Document() const
220 NS_ASSERTION(!mShell
|| !mShell
->GetDocument() ||
221 mShell
->GetDocument() == mDocument
,
222 "nsPresContext doesn't have the same document as nsPresShell!");
226 #ifdef MOZILLA_INTERNAL_API
227 nsStyleSet
* StyleSet() { return GetPresShell()->StyleSet(); }
229 nsFrameManager
* FrameManager()
230 { return PresShell()->FrameManager(); }
232 nsCSSFrameConstructor
* FrameConstructor()
233 { return PresShell()->FrameConstructor(); }
235 nsTransitionManager
* TransitionManager() { return mTransitionManager
; }
236 nsAnimationManager
* AnimationManager() { return mAnimationManager
; }
238 nsRefreshDriver
* RefreshDriver() { return mRefreshDriver
; }
240 mozilla::RestyleManager
* RestyleManager() { return mRestyleManager
; }
242 mozilla::CounterStyleManager
* CounterStyleManager() {
243 return mCounterStyleManager
;
248 * Rebuilds all style data by throwing out the old rule tree and
249 * building a new one, and additionally applying aExtraHint (which
250 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
251 * For aRestyleHint, see RestyleManager::RebuildAllStyleData.
252 * Also rebuild the user font set and counter style manager.
254 void RebuildAllStyleData(nsChangeHint aExtraHint
, nsRestyleHint aRestyleHint
);
256 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
257 * doesn't rebuild the user font set.
259 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint
,
260 nsRestyleHint aRestyleHint
);
263 * Handle changes in the values of media features (used in media
266 * There are three sensible values to use for aRestyleHint:
267 * * nsRestyleHint(0) to rebuild style data, with rerunning of
268 * selector matching, only if media features have changed
269 * * eRestyle_ForceDescendants to force rebuilding of style data (but
270 * still only rerun selector matching if media query results have
271 * changed). (RebuildAllStyleData always adds
272 * eRestyle_ForceDescendants internally, so here we're only using
273 * it to distinguish from nsRestyleHint(0) whether we need to call
274 * RebuildAllStyleData at all.)
275 * * eRestyle_Subtree to force rebuilding of style data with
276 * rerunning of selector matching
278 * For aChangeHint, see RestyleManager::RebuildAllStyleData. (Passing
279 * a nonzero aChangeHint forces rebuilding style data even if
280 * nsRestyleHint(0) is passed.)
282 void MediaFeatureValuesChanged(nsRestyleHint aRestyleHint
,
283 nsChangeHint aChangeHint
= nsChangeHint(0));
284 void PostMediaFeatureValuesChangedEvent();
285 void HandleMediaFeatureValuesChangedEvent();
286 void FlushPendingMediaFeatureValuesChanged() {
287 if (mPendingMediaFeatureValuesChanged
)
288 MediaFeatureValuesChanged(nsRestyleHint(0));
292 * Access compatibility mode for this context. This is the same as
293 * our document's compatibility mode.
295 nsCompatibility
CompatibilityMode() const;
298 * Notify the context that the document's compatibility mode has changed
300 void CompatibilityModeChanged();
303 * Access the image animation mode for this context
305 uint16_t ImageAnimationMode() const { return mImageAnimationMode
; }
306 virtual void SetImageAnimationModeExternal(uint16_t aMode
);
307 void SetImageAnimationModeInternal(uint16_t aMode
);
308 #ifdef MOZILLA_INTERNAL_API
309 void SetImageAnimationMode(uint16_t aMode
)
310 { SetImageAnimationModeInternal(aMode
); }
312 void SetImageAnimationMode(uint16_t aMode
)
313 { SetImageAnimationModeExternal(aMode
); }
317 * Get medium of presentation
320 if (!mIsEmulatingMedia
)
322 return mMediaEmulated
;
326 * Render the document as if being viewed on a device with the specified
329 void EmulateMedium(const nsAString
& aMediaType
);
332 * Restore the viewer's natural medium
334 void StopEmulatingMedium();
336 void* AllocateFromShell(size_t aSize
)
339 return mShell
->AllocateMisc(aSize
);
343 void FreeToShell(size_t aSize
, void* aFreeChunk
)
345 NS_ASSERTION(mShell
, "freeing after shutdown");
347 mShell
->FreeMisc(aSize
, aFreeChunk
);
351 * Get the default font for the given language and generic font ID.
352 * If aLanguage is nullptr, the document's language is used.
354 * This object is read-only, you must copy the font to modify it.
356 * When aFontID is kPresContext_DefaultVariableFontID or
357 * kPresContext_DefaultFixedFontID (which equals
358 * kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
359 * the nsFont returned has its name as a CSS generic family (serif or
360 * sans-serif for the former, monospace for the latter), and its size
361 * as the default font size for variable or fixed fonts for the
364 * For aFontID corresponding to a CSS Generic, the nsFont returned has
365 * its name set to that generic font's name, and its size set to
366 * the user's preference for font size for that generic and the
369 const nsFont
* GetDefaultFont(uint8_t aFontID
,
370 nsIAtom
*aLanguage
) const;
372 /** Get a cached boolean pref, by its type */
373 // * - initially created for bugs 31816, 20760, 22963
374 bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType
) const
376 // If called with a constant parameter, the compiler should optimize
377 // this switch statement away.
379 case kPresContext_UseDocumentFonts
:
380 return mUseDocumentFonts
;
381 case kPresContext_UnderlineLinks
:
382 return mUnderlineLinks
;
384 NS_ERROR("Invalid arg passed to GetCachedBoolPref");
390 /** Get a cached integer pref, by its type */
391 // * - initially created for bugs 30910, 61883, 74186, 84398
392 int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType
) const
394 // If called with a constant parameter, the compiler should optimize
395 // this switch statement away.
397 case kPresContext_ScrollbarSide
:
398 return mPrefScrollbarSide
;
399 case kPresContext_BidiDirection
:
400 return mPrefBidiDirection
;
402 NS_ERROR("invalid arg passed to GetCachedIntPref");
409 * Get the default colors
411 const nscolor
DefaultColor() const { return mDefaultColor
; }
412 const nscolor
DefaultBackgroundColor() const { return mBackgroundColor
; }
413 const nscolor
DefaultLinkColor() const { return mLinkColor
; }
414 const nscolor
DefaultActiveLinkColor() const { return mActiveLinkColor
; }
415 const nscolor
DefaultVisitedLinkColor() const { return mVisitedLinkColor
; }
416 const nscolor
FocusBackgroundColor() const { return mFocusBackgroundColor
; }
417 const nscolor
FocusTextColor() const { return mFocusTextColor
; }
420 * Body text color, for use in quirks mode only.
422 const nscolor
BodyTextColor() const { return mBodyTextColor
; }
423 void SetBodyTextColor(nscolor aColor
) { mBodyTextColor
= aColor
; }
425 bool GetUseFocusColors() const { return mUseFocusColors
; }
426 uint8_t FocusRingWidth() const { return mFocusRingWidth
; }
427 bool GetFocusRingOnAnything() const { return mFocusRingOnAnything
; }
428 uint8_t GetFocusRingStyle() const { return mFocusRingStyle
; }
430 void SetContainer(nsIDocShell
* aContainer
);
432 virtual nsISupports
* GetContainerWeakExternal() const;
433 nsISupports
* GetContainerWeakInternal() const;
434 #ifdef MOZILLA_INTERNAL_API
435 nsISupports
* GetContainerWeak() const
436 { return GetContainerWeakInternal(); }
438 nsISupports
* GetContainerWeak() const
439 { return GetContainerWeakExternal(); }
442 nsIDocShell
* GetDocShell() const;
444 // XXX this are going to be replaced with set/get container
445 void SetLinkHandler(nsILinkHandler
* aHandler
) { mLinkHandler
= aHandler
; }
446 nsILinkHandler
* GetLinkHandler() { return mLinkHandler
; }
449 * Detach this pres context - i.e. cancel relevant timers,
450 * SetLinkHandler(null), SetContainer(null) etc.
451 * Only to be used by the DocumentViewer.
453 virtual void Detach();
456 * Get the visible area associated with this presentation context.
457 * This is the size of the visible area that is used for
458 * presenting the document. The returned value is in the standard
459 * nscoord units (as scaled by the device context).
461 nsRect
GetVisibleArea() { return mVisibleArea
; }
464 * Set the currently visible area. The units for r are standard
465 * nscoord units (as scaled by the device context).
467 void SetVisibleArea(const nsRect
& r
) {
468 if (!r
.IsEqualEdges(mVisibleArea
)) {
470 // Visible area does not affect media queries when paginated.
471 if (!IsPaginated() && HasCachedStyleData()) {
472 mPendingViewportChange
= true;
473 PostMediaFeatureValuesChangedEvent();
479 * Return true if this presentation context is a paginated
482 bool IsPaginated() const { return mPaginated
; }
485 * Sets whether the presentation context can scroll for a paginated
488 void SetPaginatedScrolling(bool aResult
);
491 * Return true if this presentation context can scroll for paginated
494 bool HasPaginatedScrolling() const { return mCanPaginatedScroll
; }
497 * Get/set the size of a page
499 nsSize
GetPageSize() { return mPageSize
; }
500 void SetPageSize(nsSize aSize
) { mPageSize
= aSize
; }
503 * Get/set whether this document should be treated as having real pages
504 * XXX This raises the obvious question of why a document that isn't a page
505 * is paginated; there isn't a good reason except history
507 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument
; }
508 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument
)
509 { mIsRootPaginatedDocument
= aIsRootPaginatedDocument
; }
512 * Get/set the print scaling level; used by nsPageFrame to scale up
513 * pages. Set safe to call before reflow, get guaranteed to be set
514 * properly after reflow.
517 float GetPageScale() { return mPageScale
; }
518 void SetPageScale(float aScale
) { mPageScale
= aScale
; }
521 * Get/set the scaling facor to use when rendering the pages for print preview.
522 * Only safe to get after print preview set up; safe to set anytime.
523 * This is a scaling factor for the display of the print preview. It
524 * does not affect layout. It only affects the size of the onscreen pages
526 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
528 float GetPrintPreviewScale() { return mPPScale
; }
529 void SetPrintPreviewScale(float aScale
) { mPPScale
= aScale
; }
531 nsDeviceContext
* DeviceContext() { return mDeviceContext
; }
532 mozilla::EventStateManager
* EventStateManager() { return mEventManager
; }
533 nsIAtom
* GetLanguageFromCharset() { return mLanguage
; }
535 float TextZoom() { return mTextZoom
; }
536 void SetTextZoom(float aZoom
) {
537 if (aZoom
== mTextZoom
)
541 if (HasCachedStyleData()) {
542 // Media queries could have changed, since we changed the meaning
543 // of 'em' units in them.
544 MediaFeatureValuesChanged(eRestyle_ForceDescendants
,
545 NS_STYLE_HINT_REFLOW
);
550 * Get the minimum font size for the specified language. If aLanguage
551 * is nullptr, then the document's language is used. This combines
552 * the language-specific global preference with the per-presentation
553 * base minimum font size.
555 int32_t MinFontSize(nsIAtom
*aLanguage
) const {
556 const LangGroupFontPrefs
*prefs
= GetFontPrefsForLang(aLanguage
);
557 return std::max(mBaseMinFontSize
, prefs
->mMinimumFontSize
);
561 * Get the per-presentation base minimum font size. This size is
562 * independent of the language-specific global preference.
564 int32_t BaseMinFontSize() const {
565 return mBaseMinFontSize
;
569 * Set the per-presentation base minimum font size. This size is
570 * independent of the language-specific global preference.
572 void SetBaseMinFontSize(int32_t aMinFontSize
) {
573 if (aMinFontSize
== mBaseMinFontSize
)
576 mBaseMinFontSize
= aMinFontSize
;
577 if (HasCachedStyleData()) {
578 // Media queries could have changed, since we changed the meaning
579 // of 'em' units in them.
580 MediaFeatureValuesChanged(eRestyle_ForceDescendants
,
581 NS_STYLE_HINT_REFLOW
);
585 float GetFullZoom() { return mFullZoom
; }
586 void SetFullZoom(float aZoom
);
588 nscoord
GetAutoQualityMinFontSize() {
589 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref
);
593 * Return the device's screen width in inches, for font size
596 * If |aChanged| is non-null, then aChanged is filled in with whether
597 * the return value has changed since either:
598 * a. the last time the function was called with non-null aChanged, or
599 * b. the first time the function was called.
601 float ScreenWidthInchesForFontInflation(bool* aChanged
= nullptr);
603 static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
604 int32_t AppUnitsPerDevPixel() const;
605 static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); }
607 static nscoord
CSSPixelsToAppUnits(int32_t aPixels
)
608 { return NSToCoordRoundWithClamp(float(aPixels
) *
609 float(AppUnitsPerCSSPixel())); }
611 static nscoord
CSSPixelsToAppUnits(float aPixels
)
612 { return NSToCoordRoundWithClamp(aPixels
*
613 float(AppUnitsPerCSSPixel())); }
615 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits
)
616 { return NSAppUnitsToIntPixels(aAppUnits
,
617 float(AppUnitsPerCSSPixel())); }
619 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits
)
620 { return NSAppUnitsToFloatPixels(aAppUnits
,
621 float(AppUnitsPerCSSPixel())); }
623 nscoord
DevPixelsToAppUnits(int32_t aPixels
) const
624 { return NSIntPixelsToAppUnits(aPixels
, AppUnitsPerDevPixel()); }
626 int32_t AppUnitsToDevPixels(nscoord aAppUnits
) const
627 { return NSAppUnitsToIntPixels(aAppUnits
,
628 float(AppUnitsPerDevPixel())); }
630 int32_t CSSPixelsToDevPixels(int32_t aPixels
)
631 { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels
)); }
633 float CSSPixelsToDevPixels(float aPixels
)
635 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels
),
636 float(AppUnitsPerDevPixel()));
639 int32_t DevPixelsToIntCSSPixels(int32_t aPixels
)
640 { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels
)); }
642 float DevPixelsToFloatCSSPixels(int32_t aPixels
)
643 { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels
)); }
645 // If there is a remainder, it is rounded to nearest app units.
646 nscoord
GfxUnitsToAppUnits(gfxFloat aGfxUnits
) const;
648 gfxFloat
AppUnitsToGfxUnits(nscoord aAppUnits
) const;
650 gfxRect
AppUnitsToGfxUnits(const nsRect
& aAppRect
) const
651 { return gfxRect(AppUnitsToGfxUnits(aAppRect
.x
),
652 AppUnitsToGfxUnits(aAppRect
.y
),
653 AppUnitsToGfxUnits(aAppRect
.width
),
654 AppUnitsToGfxUnits(aAppRect
.height
)); }
656 static nscoord
CSSTwipsToAppUnits(float aTwips
)
657 { return NSToCoordRoundWithClamp(
658 mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips
)); }
660 // Margin-specific version, since they often need TwipsToAppUnits
661 static nsMargin
CSSTwipsToAppUnits(const nsIntMargin
&marginInTwips
)
662 { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips
.top
)),
663 CSSTwipsToAppUnits(float(marginInTwips
.right
)),
664 CSSTwipsToAppUnits(float(marginInTwips
.bottom
)),
665 CSSTwipsToAppUnits(float(marginInTwips
.left
))); }
667 static nscoord
CSSPointsToAppUnits(float aPoints
)
668 { return NSToCoordRound(aPoints
* mozilla::AppUnitsPerCSSInch() /
669 POINTS_PER_INCH_FLOAT
); }
671 nscoord
RoundAppUnitsToNearestDevPixels(nscoord aAppUnits
) const
672 { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits
)); }
674 void SetViewportScrollbarStylesOverride(const ScrollbarStyles
& aScrollbarStyle
)
676 mViewportStyleScrollbar
= aScrollbarStyle
;
678 ScrollbarStyles
GetViewportScrollbarStylesOverride()
680 return mViewportStyleScrollbar
;
684 * Set and get methods for controlling the background drawing
686 bool GetBackgroundImageDraw() const { return mDrawImageBackground
; }
687 void SetBackgroundImageDraw(bool aCanDraw
)
689 mDrawImageBackground
= aCanDraw
;
692 bool GetBackgroundColorDraw() const { return mDrawColorBackground
; }
693 void SetBackgroundColorDraw(bool aCanDraw
)
695 mDrawColorBackground
= aCanDraw
;
699 * Getter and setters for OMTA time counters
701 bool StyleUpdateForAllAnimationsIsUpToDate() const;
702 void TickLastStyleUpdateForAllAnimations();
703 void ClearLastStyleUpdateForAllAnimations();
706 * Check if bidi enabled (set depending on the presence of RTL
707 * characters or when default directionality is RTL).
708 * If enabled, we should apply the Unicode Bidi Algorithm
712 #ifdef MOZILLA_INTERNAL_API
713 bool BidiEnabled() const { return BidiEnabledInternal(); }
715 bool BidiEnabled() const { return BidiEnabledExternal(); }
717 virtual bool BidiEnabledExternal() const;
718 bool BidiEnabledInternal() const;
721 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
725 void SetBidiEnabled() const;
728 * Set visual or implicit mode into the pres context.
730 * Visual directionality is a presentation method that displays text
731 * as if it were a uni-directional, according to the primary display
734 * Implicit directionality is a presentation method in which the
735 * direction is determined by the Bidi algorithm according to the
736 * category of the characters and the category of the adjacent
737 * characters, and according to their primary direction.
741 void SetVisualMode(bool aIsVisual
)
743 mIsVisual
= aIsVisual
;
747 * Check whether the content should be treated as visual.
751 bool IsVisualMode() const { return mIsVisual
; }
756 * Set the Bidi options for the presentation context
758 void SetBidi(uint32_t aBidiOptions
,
759 bool aForceRestyle
= false);
762 * Get the Bidi options for the presentation context
763 * Not inline so consumers of nsPresContext are not forced to
764 * include nsIDocument.
766 uint32_t GetBidi() const;
769 * Render only Selection
771 void SetIsRenderingOnlySelection(bool aResult
)
773 mIsRenderingOnlySelection
= aResult
;
776 bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection
; }
778 bool IsTopLevelWindowInactive();
781 * Obtain a native them for rendering our widgets (both form controls and html)
783 nsITheme
* GetTheme();
786 * Notify the pres context that the theme has changed. An internal switch
787 * means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
788 * Otherwise, the OS is telling us that the native theme for the platform
794 * Notify the pres context that the resolution of the user interface has
795 * changed. This happens if a window is moved between HiDPI and non-HiDPI
796 * displays, so that the ratio of points to device pixels changes.
798 void UIResolutionChanged();
801 * Notify the pres context that a system color has changed
803 void SysColorChanged();
805 /** Printing methods below should only be used for Medium() == print **/
806 void SetPrintSettings(nsIPrintSettings
*aPrintSettings
);
808 nsIPrintSettings
* GetPrintSettings() { return mPrintSettings
; }
810 /* Accessor for table of frame properties */
811 FramePropertyTable
* PropertyTable() { return &mPropertyTable
; }
813 /* Helper function that ensures that this prescontext is shown in its
814 docshell if it's the most recent prescontext for the docshell. Returns
815 whether the prescontext is now being shown.
817 bool EnsureVisible();
819 #ifdef MOZ_REFLOW_PERF
820 void CountReflows(const char * aName
,
824 void ConstructedFrame() {
825 ++mFramesConstructed
;
827 void ReflowedFrame() {
831 uint64_t FramesConstructedCount() {
832 return mFramesConstructed
;
834 uint64_t FramesReflowedCount() {
835 return mFramesReflowed
;
839 * This table maps border-width enums 'thin', 'medium', 'thick'
840 * to actual nscoord values.
842 const nscoord
* GetBorderWidthTable() { return mBorderWidthTable
; }
844 gfxTextPerfMetrics
*GetTextPerfMetrics() { return mTextPerf
; }
846 bool IsDynamic() { return (mType
== eContext_PageLayout
|| mType
== eContext_Galley
); }
847 bool IsScreen() { return (mMedium
== nsGkAtoms::screen
||
848 mType
== eContext_PageLayout
||
849 mType
== eContext_PrintPreview
); }
851 // Is this presentation in a chrome docshell?
852 bool IsChrome() const { return mIsChrome
; }
853 bool IsChromeOriginImage() const { return mIsChromeOriginImage
; }
854 void UpdateIsChrome();
856 // Public API for native theme code to get style internals.
857 virtual bool HasAuthorSpecifiedRules(nsIFrame
*aFrame
, uint32_t ruleTypeMask
) const;
859 // Is it OK to let the page specify colors and backgrounds?
860 bool UseDocumentColors() const {
861 MOZ_ASSERT(mUseDocumentColors
|| !(IsChrome() || IsChromeOriginImage()),
862 "We should never have a chrome doc or image that can't use its colors.");
863 return mUseDocumentColors
;
866 // Explicitly enable and disable paint flashing.
867 void SetPaintFlashing(bool aPaintFlashing
) {
868 mPaintFlashing
= aPaintFlashing
;
869 mPaintFlashingInitialized
= true;
872 // This method should be used instead of directly accessing mPaintFlashing,
873 // as that value may be out of date when mPaintFlashingInitialized is false.
874 bool GetPaintFlashing() const;
876 bool SupressingResizeReflow() const { return mSupressResizeReflow
; }
878 virtual gfxUserFontSet
* GetUserFontSetExternal();
879 gfxUserFontSet
* GetUserFontSetInternal();
880 #ifdef MOZILLA_INTERNAL_API
881 gfxUserFontSet
* GetUserFontSet() { return GetUserFontSetInternal(); }
883 gfxUserFontSet
* GetUserFontSet() { return GetUserFontSetExternal(); }
886 void FlushUserFontSet();
887 void RebuildUserFontSet(); // asynchronously
889 // Should be called whenever the set of fonts available in the user
890 // font set changes (e.g., because a new font loads, or because the
891 // user font set is changed and fonts become unavailable).
892 void UserFontSetUpdated();
894 gfxMissingFontRecorder
*MissingFontRecorder() { return mMissingFonts
; }
895 void NotifyMissingFonts();
897 mozilla::dom::FontFaceSet
* Fonts();
899 void FlushCounterStyles();
900 void RebuildCounterStyles(); // asynchronously
902 // Ensure that it is safe to hand out CSS rules outside the layout
903 // engine by ensuring that all CSS style sheets have unique inners
904 // and, if necessary, synchronously rebuilding all style data.
905 void EnsureSafeToHandOutCSSRules();
907 void NotifyInvalidation(uint32_t aFlags
);
908 void NotifyInvalidation(const nsRect
& aRect
, uint32_t aFlags
);
909 // aRect is in device pixels
910 void NotifyInvalidation(const nsIntRect
& aRect
, uint32_t aFlags
);
911 // aFlags are nsIPresShell::PAINT_ flags
912 void NotifyDidPaintForSubtree(uint32_t aFlags
);
913 void FireDOMPaintEvent(nsInvalidateRequestList
* aList
);
915 // Callback for catching invalidations in ContainerLayers
916 // Passed to LayerProperties::ComputeDifference
917 static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer
* aContainer
,
918 const nsIntRegion
& aRegion
);
919 void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer
* aContainer
);
920 static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer
* aContainer
);
921 bool IsDOMPaintEventPending();
922 void ClearMozAfterPaintEvents() {
923 mInvalidateRequestsSinceLastPaint
.mRequests
.Clear();
924 mUndeliveredInvalidateRequestsBeforeLastPaint
.mRequests
.Clear();
925 mAllInvalidated
= false;
929 * Returns whether there are any pending restyles or reflows.
931 bool HasPendingRestyleOrReflow();
934 * Informs the document's FontFaceSet that the refresh driver ticked,
935 * flushing style and layout.
937 void NotifyFontFaceSetOnRefresh();
940 * Notify the prescontext that the presshell is about to reflow a reflow root.
941 * The single argument indicates whether this reflow should be interruptible.
942 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
943 * will always return false. If aInterruptible is true then CheckForInterrupt
944 * will return true when a pending event is detected. This is for use by the
945 * presshell only. Reflow code wanting to prevent interrupts should use
946 * InterruptPreventer.
948 void ReflowStarted(bool aInterruptible
);
951 * A class that can be used to temporarily disable reflow interruption.
953 class InterruptPreventer
;
954 friend class InterruptPreventer
;
955 class MOZ_STACK_CLASS InterruptPreventer
{
957 explicit InterruptPreventer(nsPresContext
* aCtx
) :
959 mInterruptsEnabled(aCtx
->mInterruptsEnabled
),
960 mHasPendingInterrupt(aCtx
->mHasPendingInterrupt
)
962 mCtx
->mInterruptsEnabled
= false;
963 mCtx
->mHasPendingInterrupt
= false;
965 ~InterruptPreventer() {
966 mCtx
->mInterruptsEnabled
= mInterruptsEnabled
;
967 mCtx
->mHasPendingInterrupt
= mHasPendingInterrupt
;
972 bool mInterruptsEnabled
;
973 bool mHasPendingInterrupt
;
977 * Check for interrupts. This may return true if a pending event is
978 * detected. Once it has returned true, it will keep returning true
979 * until ReflowStarted is called. In all cases where this returns true,
980 * the passed-in frame (which should be the frame whose reflow will be
981 * interrupted if true is returned) will be passed to
982 * nsIPresShell::FrameNeedsToContinueReflow.
984 bool CheckForInterrupt(nsIFrame
* aFrame
);
986 * Returns true if CheckForInterrupt has returned true since the last
987 * ReflowStarted call. Cannot itself trigger an interrupt check.
989 bool HasPendingInterrupt() { return mHasPendingInterrupt
; }
992 * If we have a presshell, and if the given content's current
993 * document is the same as our presshell's document, return the
994 * content's primary frame. Otherwise, return null. Only use this
995 * if you care about which presshell the primary frame is in.
997 nsIFrame
* GetPrimaryFrameFor(nsIContent
* aContent
);
999 void NotifyDestroyingFrame(nsIFrame
* aFrame
)
1001 PropertyTable()->DeleteAllFor(aFrame
);
1004 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
1005 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
1006 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf
);
1009 bool IsRootContentDocument();
1010 bool IsCrossProcessRootContentDocument();
1012 bool IsGlyph() const {
1016 void SetIsGlyph(bool aValue
) {
1020 bool UsesRootEMUnits() const {
1021 return mUsesRootEMUnits
;
1024 void SetUsesRootEMUnits(bool aValue
) {
1025 mUsesRootEMUnits
= aValue
;
1028 bool UsesViewportUnits() const {
1029 return mUsesViewportUnits
;
1032 void SetUsesViewportUnits(bool aValue
) {
1033 mUsesViewportUnits
= aValue
;
1036 // true if there are OMTA transition updates for the current document which
1037 // have been throttled, and therefore some style information may not be up
1039 bool ExistThrottledUpdates() const {
1040 return mExistThrottledUpdates
;
1043 void SetExistThrottledUpdates(bool aExistThrottledUpdates
) {
1044 mExistThrottledUpdates
= aExistThrottledUpdates
;
1047 bool IsDeviceSizePageSize();
1049 bool HasWarnedAboutPositionedTableParts() const {
1050 return mHasWarnedAboutPositionedTableParts
;
1053 void SetHasWarnedAboutPositionedTableParts() {
1054 mHasWarnedAboutPositionedTableParts
= true;
1058 friend class nsRunnableMethod
<nsPresContext
>;
1059 void ThemeChangedInternal();
1060 void SysColorChangedInternal();
1061 void UIResolutionChangedInternal();
1064 UIResolutionChangedSubdocumentCallback(nsIDocument
* aDocument
, void* aData
);
1066 void SetImgAnimations(nsIContent
*aParent
, uint16_t aMode
);
1067 void SetSMILAnimations(nsIDocument
*aDoc
, uint16_t aNewMode
,
1069 void GetDocumentColorPreferences();
1071 void PreferenceChanged(const char* aPrefName
);
1072 static void PrefChangedCallback(const char*, void*);
1074 void UpdateAfterPreferencesChanged();
1075 static void PrefChangedUpdateTimerCallback(nsITimer
*aTimer
, void *aClosure
);
1077 void GetUserPreferences();
1079 // Allow nsAutoPtr<LangGroupFontPrefs> dtor to access this protected struct's
1081 struct LangGroupFontPrefs
;
1082 friend class nsAutoPtr
<LangGroupFontPrefs
>;
1083 struct LangGroupFontPrefs
{
1084 // Font sizes default to zero; they will be set in GetFontPreferences
1085 LangGroupFontPrefs()
1086 : mLangGroup(nullptr)
1087 , mMinimumFontSize(0)
1088 , mDefaultVariableFont(mozilla::eFamily_serif
, NS_FONT_STYLE_NORMAL
,
1089 NS_FONT_WEIGHT_NORMAL
,
1090 NS_FONT_STRETCH_NORMAL
, 0, 0)
1091 , mDefaultFixedFont(mozilla::eFamily_monospace
, NS_FONT_STYLE_NORMAL
,
1092 NS_FONT_WEIGHT_NORMAL
,
1093 NS_FONT_STRETCH_NORMAL
, 0, 0)
1094 , mDefaultSerifFont(mozilla::eFamily_serif
, NS_FONT_STYLE_NORMAL
,
1095 NS_FONT_WEIGHT_NORMAL
,
1096 NS_FONT_STRETCH_NORMAL
, 0, 0)
1097 , mDefaultSansSerifFont(mozilla::eFamily_sans_serif
,
1098 NS_FONT_STYLE_NORMAL
,
1099 NS_FONT_WEIGHT_NORMAL
,
1100 NS_FONT_STRETCH_NORMAL
, 0, 0)
1101 , mDefaultMonospaceFont(mozilla::eFamily_monospace
, NS_FONT_STYLE_NORMAL
,
1102 NS_FONT_WEIGHT_NORMAL
,
1103 NS_FONT_STRETCH_NORMAL
, 0, 0)
1104 , mDefaultCursiveFont(mozilla::eFamily_cursive
, NS_FONT_STYLE_NORMAL
,
1105 NS_FONT_WEIGHT_NORMAL
,
1106 NS_FONT_STRETCH_NORMAL
, 0, 0)
1107 , mDefaultFantasyFont(mozilla::eFamily_fantasy
, NS_FONT_STYLE_NORMAL
,
1108 NS_FONT_WEIGHT_NORMAL
,
1109 NS_FONT_STRETCH_NORMAL
, 0, 0)
1112 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
1114 LangGroupFontPrefs
*curr
= mNext
;
1116 n
+= aMallocSizeOf(curr
);
1118 // Measurement of the following members may be added later if DMD finds
1119 // it is worthwhile:
1128 nsCOMPtr
<nsIAtom
> mLangGroup
;
1129 nscoord mMinimumFontSize
;
1130 nsFont mDefaultVariableFont
;
1131 nsFont mDefaultFixedFont
;
1132 nsFont mDefaultSerifFont
;
1133 nsFont mDefaultSansSerifFont
;
1134 nsFont mDefaultMonospaceFont
;
1135 nsFont mDefaultCursiveFont
;
1136 nsFont mDefaultFantasyFont
;
1137 nsAutoPtr
<LangGroupFontPrefs
> mNext
;
1141 * Fetch the user's font preferences for the given aLanguage's
1144 const LangGroupFontPrefs
* GetFontPrefsForLang(nsIAtom
*aLanguage
) const;
1146 void ResetCachedFontPrefs() {
1147 // Throw away any other LangGroupFontPrefs objects:
1148 mLangGroupFontPrefs
.mNext
= nullptr;
1150 // Make GetFontPreferences reinitialize mLangGroupFontPrefs:
1151 mLangGroupFontPrefs
.mLangGroup
= nullptr;
1154 void UpdateCharSet(const nsCString
& aCharSet
);
1157 void DoChangeCharSet(const nsCString
& aCharSet
);
1160 * Checks for MozAfterPaint listeners on the document
1162 bool MayHavePaintEventListener();
1165 * Checks for MozAfterPaint listeners on the document and
1166 * any subdocuments, except for subdocuments that are non-top-level
1167 * content documents.
1169 bool MayHavePaintEventListenerInSubDocument();
1171 #ifdef RESTYLE_LOGGING
1172 // Controls for whether debug information about restyling in this
1173 // document should be output.
1174 bool RestyleLoggingEnabled() const { return mRestyleLoggingEnabled
; }
1175 void StartRestyleLogging() { mRestyleLoggingEnabled
= true; }
1176 void StopRestyleLogging() { mRestyleLoggingEnabled
= false; }
1179 void InvalidatePaintedLayers();
1182 // May be called multiple times (unlink, destructor)
1185 void AppUnitsPerDevPixelChanged();
1187 void HandleRebuildUserFontSet() {
1188 mPostedFlushUserFontSet
= false;
1192 void HandleRebuildCounterStyles() {
1193 mPostedFlushCounterStyles
= false;
1194 FlushCounterStyles();
1197 bool HavePendingInputEvent();
1199 // Can't be inline because we can't include nsStyleSet.h.
1200 bool HasCachedStyleData();
1202 bool IsChromeSlow() const;
1204 // IMPORTANT: The ownership implicit in the following member variables
1205 // has been explicitly checked. If you add any members to this class,
1206 // please make the ownership explicit (pinkerton, scc).
1208 nsPresContextType mType
;
1209 nsIPresShell
* mShell
; // [WEAK]
1210 nsCOMPtr
<nsIDocument
> mDocument
;
1211 nsRefPtr
<nsDeviceContext
> mDeviceContext
; // [STRONG] could be weak, but
1212 // better safe than sorry.
1213 // Cannot reintroduce cycles
1214 // since there is no dependency
1215 // from gfx back to layout.
1216 nsRefPtr
<mozilla::EventStateManager
> mEventManager
;
1217 nsRefPtr
<nsRefreshDriver
> mRefreshDriver
;
1218 nsRefPtr
<nsTransitionManager
> mTransitionManager
;
1219 nsRefPtr
<nsAnimationManager
> mAnimationManager
;
1220 nsRefPtr
<mozilla::RestyleManager
> mRestyleManager
;
1221 nsRefPtr
<mozilla::CounterStyleManager
> mCounterStyleManager
;
1222 nsIAtom
* mMedium
; // initialized by subclass ctors;
1223 // weak pointer to static atom
1224 nsCOMPtr
<nsIAtom
> mMediaEmulated
;
1226 nsILinkHandler
* mLinkHandler
; // [WEAK]
1228 // Formerly mLangGroup; moving from charset-oriented langGroup to
1229 // maintaining actual language settings everywhere (see bug 524107).
1230 // This may in fact hold a langGroup such as x-western rather than
1231 // a specific language, however (e.g, if it is inferred from the
1232 // charset rather than explicitly specified as a lang attribute).
1233 nsCOMPtr
<nsIAtom
> mLanguage
;
1236 // The following are public member variables so that we can use them
1237 // with mozilla::AutoToggle or mozilla::AutoRestore.
1239 // Should we disable font size inflation because we're inside of
1240 // shrink-wrapping calculations on an inflation container?
1241 bool mInflationDisabledForShrinkWrap
;
1245 mozilla::WeakPtr
<nsDocShell
> mContainer
;
1247 // Base minimum font size, independent of the language-specific global preference. Defaults to 0
1248 int32_t mBaseMinFontSize
;
1249 float mTextZoom
; // Text zoom, defaults to 1.0
1250 float mFullZoom
; // Page zoom, defaults to 1.0
1252 float mLastFontInflationScreenWidth
;
1254 int32_t mCurAppUnitsPerDevPixel
;
1255 int32_t mAutoQualityMinFontSizePixelsPref
;
1257 nsCOMPtr
<nsITheme
> mTheme
;
1258 nsCOMPtr
<nsILanguageAtomService
> mLangService
;
1259 nsCOMPtr
<nsIPrintSettings
> mPrintSettings
;
1260 nsCOMPtr
<nsITimer
> mPrefChangedTimer
;
1262 FramePropertyTable mPropertyTable
;
1264 nsInvalidateRequestList mInvalidateRequestsSinceLastPaint
;
1265 nsInvalidateRequestList mUndeliveredInvalidateRequestsBeforeLastPaint
;
1267 // container for per-context fonts (downloadable, SVG, etc.)
1268 nsRefPtr
<mozilla::dom::FontFaceSet
> mFontFaceSet
;
1270 // text performance metrics
1271 nsAutoPtr
<gfxTextPerfMetrics
> mTextPerf
;
1273 nsAutoPtr
<gfxMissingFontRecorder
> mMissingFonts
;
1275 nsRect mVisibleArea
;
1280 nscolor mDefaultColor
;
1281 nscolor mBackgroundColor
;
1284 nscolor mActiveLinkColor
;
1285 nscolor mVisitedLinkColor
;
1287 nscolor mFocusBackgroundColor
;
1288 nscolor mFocusTextColor
;
1290 nscolor mBodyTextColor
;
1292 ScrollbarStyles mViewportStyleScrollbar
;
1293 uint8_t mFocusRingWidth
;
1295 bool mExistThrottledUpdates
;
1297 uint16_t mImageAnimationMode
;
1298 uint16_t mImageAnimationModePref
;
1300 LangGroupFontPrefs mLangGroupFontPrefs
;
1302 nscoord mBorderWidthTable
[3];
1304 uint32_t mInterruptChecksToSkip
;
1306 // Counters for tests and tools that want to detect frame construction
1308 uint64_t mFramesConstructed
;
1309 uint64_t mFramesReflowed
;
1311 mozilla::TimeStamp mReflowStartTime
;
1313 // last time we did a full style flush
1314 mozilla::TimeStamp mLastStyleUpdateForAllAnimations
;
1316 unsigned mHasPendingInterrupt
: 1;
1317 unsigned mInterruptsEnabled
: 1;
1318 unsigned mUseDocumentFonts
: 1;
1319 unsigned mUseDocumentColors
: 1;
1320 unsigned mUnderlineLinks
: 1;
1321 unsigned mSendAfterPaintToContent
: 1;
1322 unsigned mUseFocusColors
: 1;
1323 unsigned mFocusRingOnAnything
: 1;
1324 unsigned mFocusRingStyle
: 1;
1325 unsigned mDrawImageBackground
: 1;
1326 unsigned mDrawColorBackground
: 1;
1327 unsigned mNeverAnimate
: 1;
1328 unsigned mIsRenderingOnlySelection
: 1;
1329 unsigned mPaginated
: 1;
1330 unsigned mCanPaginatedScroll
: 1;
1331 unsigned mDoScaledTwips
: 1;
1332 unsigned mIsRootPaginatedDocument
: 1;
1333 unsigned mPrefBidiDirection
: 1;
1334 unsigned mPrefScrollbarSide
: 2;
1335 unsigned mPendingSysColorChanged
: 1;
1336 unsigned mPendingThemeChanged
: 1;
1337 unsigned mPendingUIResolutionChanged
: 1;
1338 unsigned mPendingMediaFeatureValuesChanged
: 1;
1339 unsigned mPrefChangePendingNeedsReflow
: 1;
1340 unsigned mIsEmulatingMedia
: 1;
1341 // True if the requests in mInvalidateRequestsSinceLastPaint cover the
1343 unsigned mAllInvalidated
: 1;
1345 // Are we currently drawing an SVG glyph?
1346 unsigned mIsGlyph
: 1;
1348 // Does the associated document use root-em (rem) units?
1349 unsigned mUsesRootEMUnits
: 1;
1350 // Does the associated document use viewport units (vw/vh/vmin/vmax)?
1351 unsigned mUsesViewportUnits
: 1;
1353 // Has there been a change to the viewport's dimensions?
1354 unsigned mPendingViewportChange
: 1;
1356 // Is the current mFontFaceSet valid?
1357 unsigned mFontFaceSetDirty
: 1;
1358 // Has GetUserFontSet() been called?
1359 unsigned mGetUserFontSetCalled
: 1;
1360 // Do we currently have an event posted to call FlushUserFontSet?
1361 unsigned mPostedFlushUserFontSet
: 1;
1363 // Is the current mCounterStyleManager valid?
1364 unsigned mCounterStylesDirty
: 1;
1365 // Do we currently have an event posted to call FlushCounterStyles?
1366 unsigned mPostedFlushCounterStyles
: 1;
1368 // resize reflow is suppressed when the only change has been to zoom
1369 // the document rather than to change the document's dimensions
1370 unsigned mSupressResizeReflow
: 1;
1372 unsigned mIsVisual
: 1;
1374 unsigned mFireAfterPaintEvents
: 1;
1376 unsigned mIsChrome
: 1;
1377 unsigned mIsChromeOriginImage
: 1;
1379 // Should we paint flash in this context? Do not use this variable directly.
1380 // Use GetPaintFlashing() method instead.
1381 mutable unsigned mPaintFlashing
: 1;
1382 mutable unsigned mPaintFlashingInitialized
: 1;
1384 unsigned mHasWarnedAboutPositionedTableParts
: 1;
1386 #ifdef RESTYLE_LOGGING
1387 // Should we output debug information about restyling for this document?
1388 bool mRestyleLoggingEnabled
;
1398 virtual ~nsPresContext();
1400 // these are private, use the list in nsFont.h if you want a public list
1402 eDefaultFont_Variable
,
1405 eDefaultFont_SansSerif
,
1406 eDefaultFont_Monospace
,
1407 eDefaultFont_Cursive
,
1408 eDefaultFont_Fantasy
,
1412 nscolor
MakeColorPref(const nsString
& aColor
);
1418 friend struct nsAutoLayoutPhase
;
1419 uint32_t mLayoutPhaseCount
[eLayoutPhase_COUNT
];
1421 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase
) {
1422 return mLayoutPhaseCount
[aPhase
];
1428 class nsRootPresContext MOZ_FINAL
: public nsPresContext
{
1430 nsRootPresContext(nsIDocument
* aDocument
, nsPresContextType aType
);
1431 virtual ~nsRootPresContext();
1432 virtual void Detach() MOZ_OVERRIDE
;
1435 * Ensure that NotifyDidPaintForSubtree is eventually called on this
1436 * object after a timeout.
1438 void EnsureEventualDidPaintEvent();
1440 void CancelDidPaintTimer()
1442 if (mNotifyDidPaintTimer
) {
1443 mNotifyDidPaintTimer
->Cancel();
1444 mNotifyDidPaintTimer
= nullptr;
1449 * Registers a plugin to receive geometry updates (position and clip
1450 * region) so it can update its widget.
1451 * Callers must call UnregisterPluginForGeometryUpdates before
1452 * the aPlugin frame is destroyed.
1454 void RegisterPluginForGeometryUpdates(nsIContent
* aPlugin
);
1456 * Stops a plugin receiving geometry updates (position and clip
1457 * region). If the plugin was not already registered, this does
1460 void UnregisterPluginForGeometryUpdates(nsIContent
* aPlugin
);
1462 bool NeedToComputePluginGeometryUpdates()
1464 return mRegisteredPlugins
.Count() > 0;
1467 * Compute geometry updates for each plugin given that aList is the display
1468 * list for aFrame. The updates are not yet applied;
1469 * ApplyPluginGeometryUpdates is responsible for that. In the meantime they
1470 * are stored on each nsPluginFrame.
1471 * This needs to be called even when aFrame is a popup, since although
1472 * windowed plugins aren't allowed in popups, windowless plugins are
1473 * and ComputePluginGeometryUpdates needs to be called for them.
1475 void ComputePluginGeometryUpdates(nsIFrame
* aFrame
,
1476 nsDisplayListBuilder
* aBuilder
,
1477 nsDisplayList
* aList
);
1480 * Apply the stored plugin geometry updates. This should normally be called
1481 * in DidPaint so the plugins are moved/clipped immediately after we've
1482 * updated our window, so they look in sync with our window.
1484 void ApplyPluginGeometryUpdates();
1486 virtual bool IsRoot() MOZ_OVERRIDE
{ return true; }
1489 * Increment DOM-modification generation counter to indicate that
1490 * the DOM has changed in a way that might lead to style changes/
1491 * reflows/frame creation and destruction.
1493 void IncrementDOMGeneration() { mDOMGeneration
++; }
1496 * Get the current DOM generation counter.
1498 * See nsFrameManagerBase::GetGlobalGenerationNumber() for a
1499 * global generation number.
1501 uint32_t GetDOMGeneration() { return mDOMGeneration
; }
1504 * Add a runnable that will get called before the next paint. They will get
1505 * run eventually even if painting doesn't happen. They might run well before
1508 void AddWillPaintObserver(nsIRunnable
* aRunnable
);
1511 * Run all runnables that need to get called before the next paint.
1513 void FlushWillPaintObservers();
1515 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const MOZ_OVERRIDE
;
1519 * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates.
1521 void InitApplyPluginGeometryTimer();
1523 * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates.
1525 void CancelApplyPluginGeometryTimer();
1527 class RunWillPaintObservers
: public nsRunnable
{
1529 explicit RunWillPaintObservers(nsRootPresContext
* aPresContext
) : mPresContext(aPresContext
) {}
1530 void Revoke() { mPresContext
= nullptr; }
1531 NS_IMETHOD
Run() MOZ_OVERRIDE
1534 mPresContext
->FlushWillPaintObservers();
1538 nsRootPresContext
* mPresContext
;
1541 friend class nsPresContext
;
1543 nsCOMPtr
<nsITimer
> mNotifyDidPaintTimer
;
1544 nsCOMPtr
<nsITimer
> mApplyPluginGeometryTimer
;
1545 nsTHashtable
<nsRefPtrHashKey
<nsIContent
> > mRegisteredPlugins
;
1546 nsTArray
<nsCOMPtr
<nsIRunnable
> > mWillPaintObservers
;
1547 nsRevocableEventPtr
<RunWillPaintObservers
> mWillPaintFallbackEvent
;
1548 uint32_t mDOMGeneration
;
1551 #ifdef MOZ_REFLOW_PERF
1553 #define DO_GLOBAL_REFLOW_COUNT(_name) \
1554 aPresContext->CountReflows((_name), (nsIFrame*)this);
1556 #define DO_GLOBAL_REFLOW_COUNT(_name)
1557 #endif // MOZ_REFLOW_PERF
1559 #endif /* nsPresContext_h___ */