Bug 1468402 - Part 3: Add test for subgrids in the grid list. r=pbro
[gecko.git] / layout / base / nsPresContext.h
blobcb0b1008f4d69b85948a6f25bc339e2ce8e18f18
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* a presentation of a document, part 1 */
9 #ifndef nsPresContext_h___
10 #define nsPresContext_h___
12 #include "mozilla/Attributes.h"
13 #include "mozilla/MediaFeatureChange.h"
14 #include "mozilla/NotNull.h"
15 #include "mozilla/ScrollStyles.h"
16 #include "mozilla/PreferenceSheet.h"
17 #include "mozilla/UniquePtr.h"
18 #include "mozilla/WeakPtr.h"
19 #include "nsColor.h"
20 #include "nsCoord.h"
21 #include "nsCOMPtr.h"
22 #include "nsRect.h"
23 #include "nsStringFwd.h"
24 #include "nsFont.h"
25 #include "gfxFontConstants.h"
26 #include "nsAtom.h"
27 #include "nsCRT.h"
28 #include "nsIWidgetListener.h" // for nsSizeMode
29 #include "nsGkAtoms.h"
30 #include "nsCycleCollectionParticipant.h"
31 #include "nsChangeHint.h"
32 #include <algorithm>
33 #include "gfxTypes.h"
34 #include "gfxRect.h"
35 #include "nsTArray.h"
36 #include "mozilla/MemoryReporting.h"
37 #include "mozilla/TimeStamp.h"
38 #include "mozilla/AppUnits.h"
39 #include "prclist.h"
40 #include "nsThreadUtils.h"
41 #include "nsIMessageManager.h"
42 #include "Units.h"
43 #include "prenv.h"
44 #include "mozilla/StaticPresData.h"
46 class nsBidi;
47 class nsIPrintSettings;
48 class nsDocShell;
49 class nsIDocShell;
50 class nsITheme;
51 class nsITimer;
52 class nsIContent;
53 class nsIFrame;
54 class nsFrameManager;
55 class nsILinkHandler;
56 class nsAtom;
57 class nsIRunnable;
58 class gfxFontFeatureValueSet;
59 class gfxUserFontEntry;
60 class gfxUserFontSet;
61 class gfxTextPerfMetrics;
62 class nsCSSFontFeatureValuesRule;
63 class nsCSSFrameConstructor;
64 class nsDisplayList;
65 class nsDisplayListBuilder;
66 class nsPluginFrame;
67 class nsTransitionManager;
68 class nsAnimationManager;
69 class nsRefreshDriver;
70 class nsIWidget;
71 class nsDeviceContext;
72 class gfxMissingFontRecorder;
74 namespace mozilla {
75 class AnimationEventDispatcher;
76 class EffectCompositor;
77 class Encoding;
78 class EventStateManager;
79 class CounterStyleManager;
80 class PresShell;
81 class RestyleManager;
82 namespace layers {
83 class ContainerLayer;
84 class LayerManager;
85 } // namespace layers
86 namespace dom {
87 class Document;
88 class Element;
89 } // namespace dom
90 } // namespace mozilla
92 // supported values for cached integer pref types
93 enum nsPresContext_CachedIntPrefType {
94 kPresContext_ScrollbarSide = 1,
95 kPresContext_BidiDirection
98 // IDs for the default variable and fixed fonts (not to be changed, see
99 // nsFont.h) To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are
100 // also supported.
102 // kGenericFont_moz_variable
103 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00;
104 // kGenericFont_moz_fixed
105 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01;
107 #ifdef DEBUG
108 struct nsAutoLayoutPhase;
110 enum nsLayoutPhase {
111 eLayoutPhase_Paint,
112 eLayoutPhase_DisplayListBuilding, // sometimes a subset of the paint phase
113 eLayoutPhase_Reflow,
114 eLayoutPhase_FrameC,
115 eLayoutPhase_COUNT
117 #endif
119 /* Used by nsPresContext::HasAuthorSpecifiedRules */
120 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
121 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
122 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
124 class nsRootPresContext;
126 // An interface for presentation contexts. Presentation contexts are
127 // objects that provide an outer context for a presentation shell.
129 class nsPresContext : public nsISupports,
130 public mozilla::SupportsWeakPtr<nsPresContext> {
131 public:
132 using Encoding = mozilla::Encoding;
133 template <typename T>
134 using NotNull = mozilla::NotNull<T>;
135 typedef mozilla::ScrollStyles ScrollStyles;
136 typedef mozilla::StaticPresData StaticPresData;
137 using TransactionId = mozilla::layers::TransactionId;
139 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
140 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
141 MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsPresContext)
143 enum nsPresContextType {
144 eContext_Galley, // unpaginated screen presentation
145 eContext_PrintPreview, // paginated screen presentation
146 eContext_Print, // paginated printer presentation
147 eContext_PageLayout // paginated & editable.
150 nsPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
153 * Initialize the presentation context from a particular device.
155 nsresult Init(nsDeviceContext* aDeviceContext);
158 * Set and detach presentation shell that this context is bound to.
159 * A presentation context may only be bound to a single shell.
161 void AttachPresShell(mozilla::PresShell* aPresShell);
162 void DetachPresShell();
164 nsPresContextType Type() const { return mType; }
167 * Get the PresentationShell that this context is bound to.
169 mozilla::PresShell* PresShell() const {
170 NS_ASSERTION(mPresShell, "Null pres shell");
171 return mPresShell;
174 mozilla::PresShell* GetPresShell() const { return mPresShell; }
176 void DispatchCharSetChange(NotNull<const Encoding*> aCharSet);
179 * Returns the parent prescontext for this one. Returns null if this is a
180 * root.
182 nsPresContext* GetParentPresContext();
185 * Returns the prescontext of the toplevel content document that contains
186 * this presentation, or null if there isn't one.
188 nsPresContext* GetToplevelContentDocumentPresContext();
191 * Returns the nearest widget for the root frame of this.
193 * @param aOffset If non-null the offset from the origin of the root
194 * frame's view to the widget's origin (usually positive)
195 * expressed in appunits of this will be returned in
196 * aOffset.
198 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
201 * Returns the root widget for this.
202 * Note that the widget is a mediater with IME.
204 nsIWidget* GetRootWidget();
207 * Return the presentation context for the root of the view manager
208 * hierarchy that contains this presentation context, or nullptr if it can't
209 * be found (e.g. it's detached).
211 nsRootPresContext* GetRootPresContext();
213 virtual bool IsRoot() { return false; }
215 mozilla::dom::Document* Document() const {
216 #ifdef DEBUG
217 ValidatePresShellAndDocumentReleation();
218 #endif // #ifdef DEBUG
219 return mDocument;
222 inline mozilla::ServoStyleSet* StyleSet() const;
224 bool HasPendingMediaQueryUpdates() const {
225 return !!mPendingMediaFeatureValuesChange;
228 inline nsCSSFrameConstructor* FrameConstructor();
230 mozilla::AnimationEventDispatcher* AnimationEventDispatcher() {
231 return mAnimationEventDispatcher;
234 mozilla::EffectCompositor* EffectCompositor() { return mEffectCompositor; }
235 nsTransitionManager* TransitionManager() { return mTransitionManager.get(); }
236 nsAnimationManager* AnimationManager() { return mAnimationManager.get(); }
237 const nsAnimationManager* AnimationManager() const {
238 return mAnimationManager.get();
241 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
243 mozilla::RestyleManager* RestyleManager() {
244 MOZ_ASSERT(mRestyleManager);
245 return mRestyleManager.get();
248 mozilla::CounterStyleManager* CounterStyleManager() const {
249 return mCounterStyleManager;
253 * Rebuilds all style data by throwing out the old rule tree and
254 * building a new one, and additionally applying aExtraHint (which
255 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
256 * For aRestyleHint, see RestyleManager::RebuildAllStyleData.
257 * Also rebuild the user font set and counter style manager.
259 void RebuildAllStyleData(nsChangeHint aExtraHint, mozilla::RestyleHint);
261 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
262 * doesn't rebuild the user font set.
264 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
265 mozilla::RestyleHint);
267 void ContentLanguageChanged();
270 * Handle changes in the values of media features (used in media queries).
272 void MediaFeatureValuesChanged(const mozilla::MediaFeatureChange& aChange);
274 void FlushPendingMediaFeatureValuesChanged();
277 * Calls MediaFeatureValuesChanged for this pres context and all descendant
278 * subdocuments that have a pres context. This should be used for media
279 * features that must be updated in all subdocuments e.g. display-mode.
281 void MediaFeatureValuesChangedAllDocuments(
282 const mozilla::MediaFeatureChange&);
285 * Updates the size mode on all remote children and recursively notifies this
286 * document and all subdocuments (including remote children) that a media
287 * feature value has changed.
289 void SizeModeChanged(nsSizeMode aSizeMode);
292 * Access compatibility mode for this context. This is the same as
293 * our document's compatibility mode.
295 nsCompatibility CompatibilityMode() const;
298 * Access the image animation mode for this context
300 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
301 void SetImageAnimationMode(uint16_t aMode);
304 * Get medium of presentation
306 nsAtom* Medium() {
307 if (!mIsEmulatingMedia) return mMedium;
308 return mMediaEmulated;
312 * Render the document as if being viewed on a device with the specified
313 * media type.
315 void EmulateMedium(const nsAString& aMediaType);
318 * Restore the viewer's natural medium
320 void StopEmulatingMedium();
322 /** Get a cached integer pref, by its type */
323 // * - initially created for bugs 30910, 61883, 74186, 84398
324 int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const {
325 // If called with a constant parameter, the compiler should optimize
326 // this switch statement away.
327 switch (aPrefType) {
328 case kPresContext_ScrollbarSide:
329 return mPrefScrollbarSide;
330 case kPresContext_BidiDirection:
331 return mPrefBidiDirection;
332 default:
333 NS_ERROR("invalid arg passed to GetCachedIntPref");
336 return false;
339 const mozilla::PreferenceSheet::Prefs& PrefSheetPrefs() const {
340 return mozilla::PreferenceSheet::PrefsFor(*mDocument);
342 nscolor DefaultBackgroundColor() const {
343 return PrefSheetPrefs().mDefaultBackgroundColor;
346 nsISupports* GetContainerWeak() const;
348 nsIDocShell* GetDocShell() const;
350 // XXX this are going to be replaced with set/get container
351 void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
352 nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
355 * Detach this pres context - i.e. cancel relevant timers,
356 * SetLinkHandler(null), etc.
357 * Only to be used by the DocumentViewer.
359 virtual void Detach();
362 * Get the visible area associated with this presentation context.
363 * This is the size of the visible area that is used for
364 * presenting the document. The returned value is in the standard
365 * nscoord units (as scaled by the device context).
367 nsRect GetVisibleArea() const { return mVisibleArea; }
370 * Set the currently visible area. The units for r are standard
371 * nscoord units (as scaled by the device context).
373 void SetVisibleArea(const nsRect& r) {
374 if (!r.IsEqualEdges(mVisibleArea)) {
375 mVisibleArea = r;
376 // Visible area does not affect media queries when paginated.
377 if (!IsPaginated()) {
378 MediaFeatureValuesChanged(
379 {mozilla::MediaFeatureChangeReason::ViewportChange});
385 * Return true if this presentation context is a paginated
386 * context.
388 bool IsPaginated() const { return mPaginated; }
391 * Sets whether the presentation context can scroll for a paginated
392 * context.
394 void SetPaginatedScrolling(bool aResult);
397 * Return true if this presentation context can scroll for paginated
398 * context.
400 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
403 * Get/set the size of a page
405 nsSize GetPageSize() { return mPageSize; }
406 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
409 * Get/set whether this document should be treated as having real pages
410 * XXX This raises the obvious question of why a document that isn't a page
411 * is paginated; there isn't a good reason except history
413 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
414 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) {
415 mIsRootPaginatedDocument = aIsRootPaginatedDocument;
419 * Get/set the print scaling level; used by nsPageFrame to scale up
420 * pages. Set safe to call before reflow, get guaranteed to be set
421 * properly after reflow.
424 float GetPageScale() { return mPageScale; }
425 void SetPageScale(float aScale) { mPageScale = aScale; }
428 * Get/set the scaling facor to use when rendering the pages for print
429 * preview. Only safe to get after print preview set up; safe to set anytime.
430 * This is a scaling factor for the display of the print preview. It
431 * does not affect layout. It only affects the size of the onscreen pages
432 * in print preview.
433 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
435 float GetPrintPreviewScale() { return mPPScale; }
436 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
438 nsDeviceContext* DeviceContext() const { return mDeviceContext; }
439 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
442 * Get/set a text zoom factor that is applied on top of the normal text zoom
443 * set by the front-end/user.
445 float GetSystemFontScale() const { return mSystemFontScale; }
446 void SetSystemFontScale(float aFontScale) {
447 MOZ_ASSERT(aFontScale > 0.0f, "invalid font scale");
448 if (aFontScale == mSystemFontScale || IsPrintingOrPrintPreview()) {
449 return;
452 mSystemFontScale = aFontScale;
453 UpdateEffectiveTextZoom();
457 * Get/set the text zoom factor in use.
458 * This value should be used if you're interested in the pure text zoom value
459 * controlled by the front-end, e.g. when transferring zoom levels to a new
460 * document.
461 * Code that wants to use this value for layouting and rendering purposes
462 * should consider using EffectiveTextZoom() instead, so as to take the system
463 * font scale into account as well.
465 float TextZoom() const { return mTextZoom; }
466 void SetTextZoom(float aZoom) {
467 MOZ_ASSERT(aZoom > 0.0f, "invalid zoom factor");
468 if (aZoom == mTextZoom) return;
470 mTextZoom = aZoom;
471 UpdateEffectiveTextZoom();
474 protected:
475 void UpdateEffectiveTextZoom();
477 #ifdef DEBUG
478 void ValidatePresShellAndDocumentReleation() const;
479 #endif // #ifdef DEBUG
481 public:
483 * Corresponds to the product of text zoom and system font scale, limited
484 * by zoom.maxPercent and minPercent.
485 * As the system font scale is automatically set by the PresShell, code that
486 * e.g. wants to transfer zoom levels to a new document should use TextZoom()
487 * instead, which corresponds to the text zoom level that was actually set by
488 * the front-end/user.
490 float EffectiveTextZoom() const { return mEffectiveTextZoom; }
492 float GetFullZoom() { return mFullZoom; }
494 * Device full zoom differs from full zoom because it gets the zoom from
495 * the device context, which may be using a different zoom due to rounding
496 * of app units to device pixels.
498 float GetDeviceFullZoom();
499 void SetFullZoom(float aZoom);
501 float GetOverrideDPPX() { return mOverrideDPPX; }
502 void SetOverrideDPPX(float aDPPX);
504 nscoord GetAutoQualityMinFontSize() {
505 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
509 * Return the device's screen size in inches, for font size
510 * inflation.
512 * If |aChanged| is non-null, then aChanged is filled in with whether
513 * the screen size value has changed since either:
514 * a. the last time the function was called with non-null aChanged, or
515 * b. the first time the function was called.
517 gfxSize ScreenSizeInchesForFontInflation(bool* aChanged = nullptr);
519 int32_t AppUnitsPerDevPixel() const { return mCurAppUnitsPerDevPixel; }
521 static nscoord CSSPixelsToAppUnits(int32_t aPixels) {
522 return NSToCoordRoundWithClamp(float(aPixels) *
523 float(mozilla::AppUnitsPerCSSPixel()));
526 static nscoord CSSPixelsToAppUnits(float aPixels) {
527 return NSToCoordRoundWithClamp(aPixels *
528 float(mozilla::AppUnitsPerCSSPixel()));
531 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) {
532 return NSAppUnitsToIntPixels(aAppUnits,
533 float(mozilla::AppUnitsPerCSSPixel()));
536 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) {
537 return NSAppUnitsToFloatPixels(aAppUnits,
538 float(mozilla::AppUnitsPerCSSPixel()));
541 static double AppUnitsToDoubleCSSPixels(nscoord aAppUnits) {
542 return NSAppUnitsToDoublePixels(aAppUnits,
543 double(mozilla::AppUnitsPerCSSPixel()));
546 nscoord DevPixelsToAppUnits(int32_t aPixels) const {
547 return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel());
550 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const {
551 return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerDevPixel()));
554 float AppUnitsToFloatDevPixels(nscoord aAppUnits) {
555 return aAppUnits / float(AppUnitsPerDevPixel());
558 int32_t CSSPixelsToDevPixels(int32_t aPixels) {
559 return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels));
562 float CSSPixelsToDevPixels(float aPixels) {
563 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
564 float(AppUnitsPerDevPixel()));
567 int32_t DevPixelsToIntCSSPixels(int32_t aPixels) {
568 return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels));
571 float DevPixelsToFloatCSSPixels(int32_t aPixels) {
572 return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels));
575 mozilla::CSSToLayoutDeviceScale CSSToDevPixelScale() const {
576 return mozilla::CSSToLayoutDeviceScale(
577 float(mozilla::AppUnitsPerCSSPixel()) / float(AppUnitsPerDevPixel()));
580 // If there is a remainder, it is rounded to nearest app units.
581 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
583 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
585 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const {
586 return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
587 AppUnitsToGfxUnits(aAppRect.y),
588 AppUnitsToGfxUnits(aAppRect.Width()),
589 AppUnitsToGfxUnits(aAppRect.Height()));
592 static nscoord CSSTwipsToAppUnits(float aTwips) {
593 return NSToCoordRoundWithClamp(mozilla::AppUnitsPerCSSInch() *
594 NS_TWIPS_TO_INCHES(aTwips));
597 // Margin-specific version, since they often need TwipsToAppUnits
598 static nsMargin CSSTwipsToAppUnits(const nsIntMargin& marginInTwips) {
599 return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
600 CSSTwipsToAppUnits(float(marginInTwips.right)),
601 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
602 CSSTwipsToAppUnits(float(marginInTwips.left)));
605 static nscoord CSSPointsToAppUnits(float aPoints) {
606 return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
607 POINTS_PER_INCH_FLOAT);
610 nscoord PhysicalMillimetersToAppUnits(float aMM) const;
612 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const {
613 return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits));
617 * This checks the root element and the HTML BODY, if any, for an "overflow"
618 * property that should be applied to the viewport. If one is found then we
619 * return the element that we took the overflow from (which should then be
620 * treated as "overflow: visible"), and we store the overflow style here.
621 * If the document is in fullscreen, and the fullscreen element is not the
622 * root, the scrollbar of viewport will be suppressed.
623 * @return if scroll was propagated from some content node, the content node
624 * it was propagated from.
626 mozilla::dom::Element* UpdateViewportScrollStylesOverride();
629 * Returns the cached result from the last call to
630 * UpdateViewportScrollStylesOverride() -- i.e. return the node
631 * whose scrollbar styles we have propagated to the viewport (or nullptr if
632 * there is no such node).
634 mozilla::dom::Element* GetViewportScrollStylesOverrideElement() const {
635 return mViewportScrollOverrideElement;
638 const ScrollStyles& GetViewportScrollStylesOverride() const {
639 return mViewportScrollStyles;
643 * Check whether the given element would propagate its scrollbar styles to the
644 * viewport in non-paginated mode. Must only be called if IsPaginated().
646 bool ElementWouldPropagateScrollStyles(const mozilla::dom::Element&);
649 * Set and get methods for controlling the background drawing
651 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
652 void SetBackgroundImageDraw(bool aCanDraw) {
653 mDrawImageBackground = aCanDraw;
656 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
657 void SetBackgroundColorDraw(bool aCanDraw) {
658 mDrawColorBackground = aCanDraw;
662 * Check if bidi enabled (set depending on the presence of RTL
663 * characters or when default directionality is RTL).
664 * If enabled, we should apply the Unicode Bidi Algorithm
666 * @lina 07/12/2000
668 bool BidiEnabled() const;
671 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
673 * @lina 07/12/2000
675 void SetBidiEnabled() const;
678 * Set visual or implicit mode into the pres context.
680 * Visual directionality is a presentation method that displays text
681 * as if it were a uni-directional, according to the primary display
682 * direction only.
684 * Implicit directionality is a presentation method in which the
685 * direction is determined by the Bidi algorithm according to the
686 * category of the characters and the category of the adjacent
687 * characters, and according to their primary direction.
689 * @lina 05/02/2000
691 void SetVisualMode(bool aIsVisual) { mIsVisual = aIsVisual; }
694 * Check whether the content should be treated as visual.
696 * @lina 05/02/2000
698 bool IsVisualMode() const { return mIsVisual; }
700 enum class InteractionType : uint32_t {
701 ClickInteraction,
702 KeyInteraction,
703 MouseMoveInteraction,
704 ScrollInteraction
707 void RecordInteractionTime(InteractionType aType,
708 const mozilla::TimeStamp& aTimeStamp);
710 void DisableInteractionTimeRecording() { mInteractionTimeEnabled = false; }
712 // Mohamed
715 * Set the Bidi options for the presentation context
717 void SetBidi(uint32_t aBidiOptions);
720 * Get the Bidi options for the presentation context
721 * Not inline so consumers of nsPresContext are not forced to
722 * include Document.
724 uint32_t GetBidi() const;
726 bool IsTopLevelWindowInactive();
729 * Obtain a native them for rendering our widgets (both form controls and
730 * html)
732 nsITheme* GetTheme();
735 * Notify the pres context that the theme has changed. An internal switch
736 * means it's one of our Mozilla themes that changed (e.g., Modern to
737 * Classic). Otherwise, the OS is telling us that the native theme for the
738 * platform has changed.
740 void ThemeChanged();
743 * Notify the pres context that the resolution of the user interface has
744 * changed. This happens if a window is moved between HiDPI and non-HiDPI
745 * displays, so that the ratio of points to device pixels changes.
746 * The notification happens asynchronously.
748 void UIResolutionChanged();
751 * Like UIResolutionChanged() but invalidates values immediately.
753 void UIResolutionChangedSync();
756 * Notify the pres context that a system color has changed
758 void SysColorChanged();
760 /** Printing methods below should only be used for Medium() == print **/
761 void SetPrintSettings(nsIPrintSettings* aPrintSettings);
763 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
765 /* Helper function that ensures that this prescontext is shown in its
766 docshell if it's the most recent prescontext for the docshell. Returns
767 whether the prescontext is now being shown.
769 bool EnsureVisible();
771 #ifdef MOZ_REFLOW_PERF
772 void CountReflows(const char* aName, nsIFrame* aFrame);
773 #endif
775 void ConstructedFrame() { ++mFramesConstructed; }
776 void ReflowedFrame() { ++mFramesReflowed; }
778 uint64_t FramesConstructedCount() { return mFramesConstructed; }
779 uint64_t FramesReflowedCount() { return mFramesReflowed; }
781 static nscoord GetBorderWidthForKeyword(unsigned int aBorderWidthKeyword) {
782 // This table maps border-width enums 'thin', 'medium', 'thick'
783 // to actual nscoord values.
784 static const nscoord kBorderWidths[] = {
785 CSSPixelsToAppUnits(1), CSSPixelsToAppUnits(3), CSSPixelsToAppUnits(5)};
786 MOZ_ASSERT(size_t(aBorderWidthKeyword) <
787 mozilla::ArrayLength(kBorderWidths));
789 return kBorderWidths[aBorderWidthKeyword];
792 gfxTextPerfMetrics* GetTextPerfMetrics() { return mTextPerf.get(); }
794 bool IsDynamic() {
795 return (mType == eContext_PageLayout || mType == eContext_Galley);
797 bool IsScreen() {
798 return (mMedium == nsGkAtoms::screen || mType == eContext_PageLayout ||
799 mType == eContext_PrintPreview);
801 bool IsPrintingOrPrintPreview() {
802 return (mType == eContext_Print || mType == eContext_PrintPreview);
805 // Is this presentation in a chrome docshell?
806 bool IsChrome() const;
807 bool IsChromeOriginImage() const;
809 // Public API for native theme code to get style internals.
810 bool HasAuthorSpecifiedRules(const nsIFrame* aFrame,
811 uint32_t ruleTypeMask) const;
813 // Explicitly enable and disable paint flashing.
814 void SetPaintFlashing(bool aPaintFlashing) {
815 mPaintFlashing = aPaintFlashing;
816 mPaintFlashingInitialized = true;
819 // This method should be used instead of directly accessing mPaintFlashing,
820 // as that value may be out of date when mPaintFlashingInitialized is false.
821 bool GetPaintFlashing() const;
823 bool SuppressingResizeReflow() const { return mSuppressResizeReflow; }
825 gfxUserFontSet* GetUserFontSet();
827 // Should be called whenever the set of fonts available in the user
828 // font set changes (e.g., because a new font loads, or because the
829 // user font set is changed and fonts become unavailable).
830 void UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont = nullptr);
832 gfxMissingFontRecorder* MissingFontRecorder() { return mMissingFonts.get(); }
834 void NotifyMissingFonts();
836 void FlushCounterStyles();
837 void MarkCounterStylesDirty();
839 void FlushFontFeatureValues();
840 void MarkFontFeatureValuesDirty() { mFontFeatureValuesDirty = true; }
842 // Ensure that it is safe to hand out CSS rules outside the layout
843 // engine by ensuring that all CSS style sheets have unique inners
844 // and, if necessary, synchronously rebuilding all style data.
845 void EnsureSafeToHandOutCSSRules();
847 // Mark an area as invalidated, associated with a given transaction id
848 // (allocated by nsRefreshDriver::GetTransactionId). Invalidated regions will
849 // be dispatched to MozAfterPaint events when NotifyDidPaintForSubtree is
850 // called for the transaction id (or any higher id).
851 void NotifyInvalidation(TransactionId aTransactionId, const nsRect& aRect);
852 // aRect is in device pixels
853 void NotifyInvalidation(TransactionId aTransactionId, const nsIntRect& aRect);
854 void NotifyDidPaintForSubtree(
855 TransactionId aTransactionId = TransactionId{0},
856 const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp());
857 void NotifyRevokingDidPaint(TransactionId aTransactionId);
858 void FireDOMPaintEvent(nsTArray<nsRect>* aList, TransactionId aTransactionId,
859 mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());
861 // Callback for catching invalidations in ContainerLayers
862 // Passed to LayerProperties::ComputeDifference
863 static void NotifySubDocInvalidation(
864 mozilla::layers::ContainerLayer* aContainer, const nsIntRegion* aRegion);
865 void SetNotifySubDocInvalidationData(
866 mozilla::layers::ContainerLayer* aContainer);
867 static void ClearNotifySubDocInvalidationData(
868 mozilla::layers::ContainerLayer* aContainer);
869 bool IsDOMPaintEventPending();
872 * Returns the RestyleManager's restyle generation counter.
874 uint64_t GetRestyleGeneration() const;
875 uint64_t GetUndisplayedRestyleGeneration() const;
878 * Returns whether there are any pending restyles or reflows.
880 bool HasPendingRestyleOrReflow();
883 * Notify the prescontext that the presshell is about to reflow a reflow root.
884 * The single argument indicates whether this reflow should be interruptible.
885 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
886 * will always return false. If aInterruptible is true then CheckForInterrupt
887 * will return true when a pending event is detected. This is for use by the
888 * presshell only. Reflow code wanting to prevent interrupts should use
889 * InterruptPreventer.
891 void ReflowStarted(bool aInterruptible);
894 * A class that can be used to temporarily disable reflow interruption.
896 class InterruptPreventer;
897 friend class InterruptPreventer;
898 class MOZ_STACK_CLASS InterruptPreventer {
899 public:
900 explicit InterruptPreventer(nsPresContext* aCtx)
901 : mCtx(aCtx),
902 mInterruptsEnabled(aCtx->mInterruptsEnabled),
903 mHasPendingInterrupt(aCtx->mHasPendingInterrupt) {
904 mCtx->mInterruptsEnabled = false;
905 mCtx->mHasPendingInterrupt = false;
907 ~InterruptPreventer() {
908 mCtx->mInterruptsEnabled = mInterruptsEnabled;
909 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
912 private:
913 nsPresContext* mCtx;
914 bool mInterruptsEnabled;
915 bool mHasPendingInterrupt;
919 * Check for interrupts. This may return true if a pending event is
920 * detected. Once it has returned true, it will keep returning true
921 * until ReflowStarted is called. In all cases where this returns true,
922 * the passed-in frame (which should be the frame whose reflow will be
923 * interrupted if true is returned) will be passed to
924 * PresShell::FrameNeedsToContinueReflow.
926 bool CheckForInterrupt(nsIFrame* aFrame);
928 * Returns true if CheckForInterrupt has returned true since the last
929 * ReflowStarted call. Cannot itself trigger an interrupt check.
931 bool HasPendingInterrupt() { return mHasPendingInterrupt; }
933 * Sets a flag that will trip a reflow interrupt. This only bypasses the
934 * interrupt timeout and the pending event check; other checks such as whether
935 * interrupts are enabled and the interrupt check skipping still take effect.
937 void SetPendingInterruptFromTest() { mPendingInterruptFromTest = true; }
940 * If we have a presshell, and if the given content's current
941 * document is the same as our presshell's document, return the
942 * content's primary frame. Otherwise, return null. Only use this
943 * if you care about which presshell the primary frame is in.
945 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
947 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
948 virtual size_t SizeOfIncludingThis(
949 mozilla::MallocSizeOf aMallocSizeOf) const {
950 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
953 bool IsRootContentDocument() const;
955 bool HadNonBlankPaint() const { return mHadNonBlankPaint; }
956 bool HadContentfulPaint() const { return mHadContentfulPaint; }
957 void NotifyNonBlankPaint();
958 void NotifyContentfulPaint();
959 void NotifyDOMContentFlushed();
961 bool UsesRootEMUnits() const { return mUsesRootEMUnits; }
963 void SetUsesRootEMUnits(bool aValue) { mUsesRootEMUnits = aValue; }
965 bool UsesExChUnits() const { return mUsesExChUnits; }
967 void SetUsesExChUnits(bool aValue) { mUsesExChUnits = aValue; }
969 // true if there are OMTA transition updates for the current document which
970 // have been throttled, and therefore some style information may not be up
971 // to date
972 bool ExistThrottledUpdates() const { return mExistThrottledUpdates; }
974 void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
975 mExistThrottledUpdates = aExistThrottledUpdates;
978 bool IsDeviceSizePageSize();
980 bool HasWarnedAboutPositionedTableParts() const {
981 return mHasWarnedAboutPositionedTableParts;
984 void SetHasWarnedAboutPositionedTableParts() {
985 mHasWarnedAboutPositionedTableParts = true;
988 bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
989 return mHasWarnedAboutTooLargeDashedOrDottedRadius;
992 void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
993 mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
996 nsBidi& GetBidiEngine();
998 gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const {
999 return mFontFeatureValuesLookup;
1002 protected:
1003 friend class nsRunnableMethod<nsPresContext>;
1004 void ThemeChangedInternal();
1005 void SysColorChangedInternal();
1006 void RefreshSystemMetrics();
1008 // update device context's resolution from the widget
1009 void UIResolutionChangedInternal();
1011 // if aScale > 0.0, use it as resolution scale factor to the device context
1012 // (otherwise get it from the widget)
1013 void UIResolutionChangedInternalScale(double aScale);
1015 // aData here is a pointer to a double that holds the CSS to device-pixel
1016 // scale factor from the parent, which will be applied to the subdocument's
1017 // device context instead of retrieving a scale from the widget.
1018 static bool UIResolutionChangedSubdocumentCallback(
1019 mozilla::dom::Document* aDocument, void* aData);
1021 void SetImgAnimations(nsIContent* aParent, uint16_t aMode);
1022 void SetSMILAnimations(mozilla::dom::Document* aDoc, uint16_t aNewMode,
1023 uint16_t aOldMode);
1024 void GetDocumentColorPreferences();
1026 void PreferenceChanged(const char* aPrefName);
1028 void UpdateAfterPreferencesChanged();
1029 void DispatchPrefChangedRunnableIfNeeded();
1031 void GetUserPreferences();
1033 void UpdateCharSet(NotNull<const Encoding*> aCharSet);
1035 static bool NotifyDidPaintSubdocumentCallback(
1036 mozilla::dom::Document* aDocument, void* aData);
1037 static bool NotifyRevokingDidPaintSubdocumentCallback(
1038 mozilla::dom::Document* aDocument, void* aData);
1040 public:
1041 // Used by the PresShell to force a reflow when some aspect of font info
1042 // has been updated, potentially affecting font selection and layout.
1043 void ForceReflowForFontInfoUpdate();
1045 void DoChangeCharSet(NotNull<const Encoding*> aCharSet);
1048 * Checks for MozAfterPaint listeners on the document
1050 bool MayHavePaintEventListener();
1053 * Checks for MozAfterPaint listeners on the document and
1054 * any subdocuments, except for subdocuments that are non-top-level
1055 * content documents.
1057 bool MayHavePaintEventListenerInSubDocument();
1059 void InvalidatePaintedLayers();
1061 uint32_t GetNextFrameRateMultiplier() const {
1062 return mNextFrameRateMultiplier;
1065 void DidUseFrameRateMultiplier() {
1066 if (!mNextFrameRateMultiplier) {
1067 mNextFrameRateMultiplier = 1;
1068 } else if (mNextFrameRateMultiplier < 8) {
1069 mNextFrameRateMultiplier = mNextFrameRateMultiplier * 2;
1073 protected:
1074 // May be called multiple times (unlink, destructor)
1075 void Destroy();
1077 void AppUnitsPerDevPixelChanged();
1079 bool HavePendingInputEvent();
1081 // Creates a one-shot timer with the given aCallback & aDelay.
1082 // Returns a refcounted pointer to the timer (or nullptr on failure).
1083 already_AddRefed<nsITimer> CreateTimer(nsTimerCallbackFunc aCallback,
1084 const char* aName, uint32_t aDelay);
1086 struct TransactionInvalidations {
1087 TransactionId mTransactionId;
1088 nsTArray<nsRect> mInvalidations;
1089 bool mIsWaitingForPreviousTransaction = false;
1091 TransactionInvalidations* GetInvalidations(TransactionId aTransactionId);
1093 // IMPORTANT: The ownership implicit in the following member variables
1094 // has been explicitly checked. If you add any members to this class,
1095 // please make the ownership explicit (pinkerton, scc).
1097 nsPresContextType mType;
1098 // the PresShell owns a strong reference to the nsPresContext, and is
1099 // responsible for nulling this pointer before it is destroyed
1100 mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell; // [WEAK]
1101 RefPtr<mozilla::dom::Document> mDocument;
1102 RefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1103 // better safe than sorry.
1104 // Cannot reintroduce cycles
1105 // since there is no dependency
1106 // from gfx back to layout.
1107 RefPtr<mozilla::EventStateManager> mEventManager;
1108 RefPtr<nsRefreshDriver> mRefreshDriver;
1109 RefPtr<mozilla::AnimationEventDispatcher> mAnimationEventDispatcher;
1110 RefPtr<mozilla::EffectCompositor> mEffectCompositor;
1111 mozilla::UniquePtr<nsTransitionManager> mTransitionManager;
1112 mozilla::UniquePtr<nsAnimationManager> mAnimationManager;
1113 mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager;
1114 RefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
1115 nsAtom* MOZ_UNSAFE_REF(
1116 "always a static atom") mMedium; // initialized by subclass ctors
1117 RefPtr<nsAtom> mMediaEmulated;
1118 RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup;
1120 // This pointer is nulled out through SetLinkHandler() in the destructors of
1121 // the classes which set it. (using SetLinkHandler() again).
1122 nsILinkHandler* MOZ_NON_OWNING_REF mLinkHandler;
1124 public:
1125 // The following are public member variables so that we can use them
1126 // with mozilla::AutoToggle or mozilla::AutoRestore.
1128 // Should we disable font size inflation because we're inside of
1129 // shrink-wrapping calculations on an inflation container?
1130 bool mInflationDisabledForShrinkWrap;
1132 protected:
1133 float mSystemFontScale; // Internal text zoom factor, defaults to 1.0
1134 float mTextZoom; // Text zoom, defaults to 1.0
1135 float mEffectiveTextZoom; // Text zoom * system font scale
1136 float mFullZoom; // Page zoom, defaults to 1.0
1137 float mOverrideDPPX; // DPPX overrided, defaults to 0.0
1138 gfxSize mLastFontInflationScreenSize;
1140 int32_t mCurAppUnitsPerDevPixel;
1141 int32_t mAutoQualityMinFontSizePixelsPref;
1143 nsCOMPtr<nsITheme> mTheme;
1144 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1146 mozilla::UniquePtr<nsBidi> mBidiEngine;
1148 AutoTArray<TransactionInvalidations, 4> mTransactions;
1150 // text performance metrics
1151 mozilla::UniquePtr<gfxTextPerfMetrics> mTextPerf;
1153 mozilla::UniquePtr<gfxMissingFontRecorder> mMissingFonts;
1155 nsRect mVisibleArea;
1156 nsSize mPageSize;
1157 float mPageScale;
1158 float mPPScale;
1160 // This is a non-owning pointer. May be null. If non-null, it's guaranteed to
1161 // be pointing to an element that's still alive, because we'll reset it in
1162 // UpdateViewportScrollStylesOverride() as part of the cleanup code when
1163 // this element is removed from the document. (For <body> and the root
1164 // element, this call happens in nsCSSFrameConstructor::ContentRemoved(). For
1165 // fullscreen elements, it happens in the fullscreen-specific cleanup invoked
1166 // by Element::UnbindFromTree().)
1167 mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollOverrideElement;
1168 ScrollStyles mViewportScrollStyles;
1170 bool mExistThrottledUpdates;
1172 uint16_t mImageAnimationMode;
1173 uint16_t mImageAnimationModePref;
1175 uint32_t mInterruptChecksToSkip;
1177 // During page load we use slower frame rate.
1178 uint32_t mNextFrameRateMultiplier;
1180 // Counters for tests and tools that want to detect frame construction
1181 // or reflow.
1182 uint64_t mElementsRestyled;
1183 uint64_t mFramesConstructed;
1184 uint64_t mFramesReflowed;
1186 mozilla::TimeStamp mReflowStartTime;
1188 mozilla::Maybe<TransactionId> mFirstContentfulPaintTransactionId;
1190 // Time of various first interaction types, used to report time from
1191 // first paint of the top level content pres shell to first interaction.
1192 mozilla::TimeStamp mFirstNonBlankPaintTime;
1193 mozilla::TimeStamp mFirstClickTime;
1194 mozilla::TimeStamp mFirstKeyTime;
1195 mozilla::TimeStamp mFirstMouseMoveTime;
1196 mozilla::TimeStamp mFirstScrollTime;
1198 bool mInteractionTimeEnabled;
1200 // last time we did a full style flush
1201 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1203 unsigned mHasPendingInterrupt : 1;
1204 unsigned mPendingInterruptFromTest : 1;
1205 unsigned mInterruptsEnabled : 1;
1206 unsigned mSendAfterPaintToContent : 1;
1207 unsigned mDrawImageBackground : 1;
1208 unsigned mDrawColorBackground : 1;
1209 unsigned mNeverAnimate : 1;
1210 unsigned mPaginated : 1;
1211 unsigned mCanPaginatedScroll : 1;
1212 unsigned mDoScaledTwips : 1;
1213 unsigned mIsRootPaginatedDocument : 1;
1214 unsigned mPrefBidiDirection : 1;
1215 unsigned mPrefScrollbarSide : 2;
1216 unsigned mPendingSysColorChanged : 1;
1217 unsigned mPendingThemeChanged : 1;
1218 unsigned mPendingUIResolutionChanged : 1;
1219 unsigned mPrefChangePendingNeedsReflow : 1;
1220 unsigned mPostedPrefChangedRunnable : 1;
1221 unsigned mIsEmulatingMedia : 1;
1223 // Are we currently drawing an SVG glyph?
1224 unsigned mIsGlyph : 1;
1226 // Does the associated document use root-em (rem) units?
1227 unsigned mUsesRootEMUnits : 1;
1228 // Does the associated document use ex or ch units?
1229 unsigned mUsesExChUnits : 1;
1231 // Is the current mCounterStyleManager valid?
1232 unsigned mCounterStylesDirty : 1;
1234 // Is the current mFontFeatureValuesLookup valid?
1235 unsigned mFontFeatureValuesDirty : 1;
1237 // resize reflow is suppressed when the only change has been to zoom
1238 // the document rather than to change the document's dimensions
1239 unsigned mSuppressResizeReflow : 1;
1241 unsigned mIsVisual : 1;
1243 // Should we paint flash in this context? Do not use this variable directly.
1244 // Use GetPaintFlashing() method instead.
1245 mutable unsigned mPaintFlashing : 1;
1246 mutable unsigned mPaintFlashingInitialized : 1;
1248 unsigned mHasWarnedAboutPositionedTableParts : 1;
1250 unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;
1252 // Have we added quirk.css to the style set?
1253 unsigned mQuirkSheetAdded : 1;
1255 // Has NotifyNonBlankPaint been called on this PresContext?
1256 unsigned mHadNonBlankPaint : 1;
1257 // Has NotifyContentfulPaint been called on this PresContext?
1258 unsigned mHadContentfulPaint : 1;
1259 // Has NotifyDidPaintForSubtree been called for a contentful paint?
1260 unsigned mHadContentfulPaintComposite : 1;
1262 #ifdef DEBUG
1263 unsigned mInitialized : 1;
1264 #endif
1266 mozilla::Maybe<mozilla::MediaFeatureChange> mPendingMediaFeatureValuesChange;
1268 protected:
1269 virtual ~nsPresContext();
1271 void LastRelease();
1273 #ifdef DEBUG
1274 private:
1275 friend struct nsAutoLayoutPhase;
1276 uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT];
1278 public:
1279 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1280 return mLayoutPhaseCount[aPhase];
1282 #endif
1285 class nsRootPresContext final : public nsPresContext {
1286 public:
1287 nsRootPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
1288 virtual ~nsRootPresContext();
1289 virtual void Detach() override;
1292 * Registers a plugin to receive geometry updates (position and clip
1293 * region) so it can update its widget.
1294 * Callers must call UnregisterPluginForGeometryUpdates before
1295 * the aPlugin frame is destroyed.
1297 void RegisterPluginForGeometryUpdates(nsIContent* aPlugin);
1299 * Stops a plugin receiving geometry updates (position and clip
1300 * region). If the plugin was not already registered, this does
1301 * nothing.
1303 void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin);
1305 bool NeedToComputePluginGeometryUpdates() {
1306 return mRegisteredPlugins.Count() > 0;
1309 * Compute geometry updates for each plugin given that aList is the display
1310 * list for aFrame. The updates are not yet applied;
1311 * ApplyPluginGeometryUpdates is responsible for that. In the meantime they
1312 * are stored on each nsPluginFrame.
1313 * This needs to be called even when aFrame is a popup, since although
1314 * windowed plugins aren't allowed in popups, windowless plugins are
1315 * and ComputePluginGeometryUpdates needs to be called for them.
1316 * aBuilder and aList can be null. This indicates that all plugins are
1317 * hidden because we're in a background tab.
1319 void ComputePluginGeometryUpdates(nsIFrame* aFrame,
1320 nsDisplayListBuilder* aBuilder,
1321 nsDisplayList* aList);
1324 * Apply the stored plugin geometry updates. This should normally be called
1325 * in DidPaint so the plugins are moved/clipped immediately after we've
1326 * updated our window, so they look in sync with our window.
1328 void ApplyPluginGeometryUpdates();
1331 * Transfer stored plugin geometry updates to the compositor. Called during
1332 * reflow, data is shipped over with layer updates. e10s specific.
1334 void CollectPluginGeometryUpdates(
1335 mozilla::layers::LayerManager* aLayerManager);
1337 virtual bool IsRoot() override { return true; }
1340 * Add a runnable that will get called before the next paint. They will get
1341 * run eventually even if painting doesn't happen. They might run well before
1342 * painting happens.
1344 void AddWillPaintObserver(nsIRunnable* aRunnable);
1347 * Run all runnables that need to get called before the next paint.
1349 void FlushWillPaintObservers();
1351 virtual size_t SizeOfExcludingThis(
1352 mozilla::MallocSizeOf aMallocSizeOf) const override;
1354 protected:
1356 * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates.
1358 void InitApplyPluginGeometryTimer();
1360 * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates.
1362 void CancelApplyPluginGeometryTimer();
1364 class RunWillPaintObservers : public mozilla::Runnable {
1365 public:
1366 explicit RunWillPaintObservers(nsRootPresContext* aPresContext)
1367 : Runnable("nsPresContextType::RunWillPaintObservers"),
1368 mPresContext(aPresContext) {}
1369 void Revoke() { mPresContext = nullptr; }
1370 NS_IMETHOD Run() override {
1371 if (mPresContext) {
1372 mPresContext->FlushWillPaintObservers();
1374 return NS_OK;
1376 // The lifetime of this reference is handled by an nsRevocableEventPtr
1377 nsRootPresContext* MOZ_NON_OWNING_REF mPresContext;
1380 friend class nsPresContext;
1382 nsCOMPtr<nsITimer> mApplyPluginGeometryTimer;
1383 nsTHashtable<nsRefPtrHashKey<nsIContent>> mRegisteredPlugins;
1384 nsTArray<nsCOMPtr<nsIRunnable>> mWillPaintObservers;
1385 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1388 #ifdef MOZ_REFLOW_PERF
1390 # define DO_GLOBAL_REFLOW_COUNT(_name) \
1391 aPresContext->CountReflows((_name), (nsIFrame*)this);
1392 #else
1393 # define DO_GLOBAL_REFLOW_COUNT(_name)
1394 #endif // MOZ_REFLOW_PERF
1396 #endif /* nsPresContext_h___ */