Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / layout / base / nsPresContext.h
blobdda4c8ccc92a93a783f049a0c34ef4a87f1fa806
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/intl/Bidi.h"
13 #include "mozilla/AppUnits.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/DepthOrderedFrameList.h"
16 #include "mozilla/EnumeratedArray.h"
17 #include "mozilla/MediaEmulationData.h"
18 #include "mozilla/MemoryReporting.h"
19 #include "mozilla/NotNull.h"
20 #include "mozilla/PreferenceSheet.h"
21 #include "mozilla/PresShellForwards.h"
22 #include "mozilla/ScrollStyles.h"
23 #include "mozilla/TimeStamp.h"
24 #include "mozilla/UniquePtr.h"
25 #include "mozilla/WeakPtr.h"
26 #include "mozilla/widget/ThemeChangeKind.h"
27 #include "nsColor.h"
28 #include "nsCompatibility.h"
29 #include "nsCoord.h"
30 #include "nsCOMPtr.h"
31 #include "nsFontMetrics.h"
32 #include "nsHashKeys.h"
33 #include "nsRect.h"
34 #include "nsStringFwd.h"
35 #include "nsTHashSet.h"
36 #include "nsTHashtable.h"
37 #include "nsAtom.h"
38 #include "nsIWidgetListener.h" // for nsSizeMode
39 #include "nsGkAtoms.h"
40 #include "nsCycleCollectionParticipant.h"
41 #include "nsChangeHint.h"
42 #include "gfxTypes.h"
43 #include "gfxRect.h"
44 #include "nsTArray.h"
45 #include "nsThreadUtils.h"
46 #include "Units.h"
48 class nsIPrintSettings;
49 class nsDocShell;
50 class nsIDocShell;
51 class nsITheme;
52 class nsITimer;
53 class nsIContent;
54 class nsIFrame;
55 class nsFrameManager;
56 class nsAtom;
57 class nsIRunnable;
58 class gfxFontFamily;
59 class gfxFontFeatureValueSet;
60 class gfxUserFontEntry;
61 class gfxUserFontSet;
62 class gfxTextPerfMetrics;
63 class nsCSSFontFeatureValuesRule;
64 class nsCSSFrameConstructor;
65 class nsFontCache;
66 class nsTransitionManager;
67 class nsAnimationManager;
68 class nsRefreshDriver;
69 class nsIWidget;
70 class nsDeviceContext;
71 class gfxMissingFontRecorder;
73 namespace mozilla {
74 class AnimationEventDispatcher;
75 class EffectCompositor;
76 class Encoding;
77 class EventStateManager;
78 class CounterStyleManager;
79 class ManagedPostRefreshObserver;
80 class PresShell;
81 class RestyleManager;
82 class ServoStyleSet;
83 class StaticPresData;
84 class TimelineManager;
85 struct MediaFeatureChange;
86 enum class MediaFeatureChangePropagation : uint8_t;
87 enum class ColorScheme : uint8_t;
88 namespace layers {
89 class ContainerLayer;
90 class LayerManager;
91 } // namespace layers
92 namespace dom {
93 class Document;
94 class Element;
95 enum class PrefersColorSchemeOverride : uint8_t;
96 } // namespace dom
97 namespace gfx {
98 class FontPaletteValueSet;
99 } // namespace gfx
100 } // namespace mozilla
102 // supported values for cached integer pref types
103 enum nsPresContext_CachedIntPrefType {
104 kPresContext_ScrollbarSide = 1,
105 kPresContext_BidiDirection
108 // IDs for the default variable and fixed fonts (not to be changed, see
109 // nsFont.h) To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are
110 // also supported.
112 // kGenericFont_moz_variable
113 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00;
114 // kGenericFont_moz_fixed
115 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01;
117 #ifdef DEBUG
118 struct nsAutoLayoutPhase;
120 enum class nsLayoutPhase : uint8_t {
121 Paint,
122 DisplayListBuilding, // sometimes a subset of the paint phase
123 Reflow,
124 FrameC,
125 COUNT
127 #endif
129 class nsRootPresContext;
131 // An interface for presentation contexts. Presentation contexts are
132 // objects that provide an outer context for a presentation shell.
134 class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
135 public:
136 using Encoding = mozilla::Encoding;
137 template <typename T>
138 using NotNull = mozilla::NotNull<T>;
139 template <typename T>
140 using Maybe = mozilla::Maybe<T>;
141 using MediaEmulationData = mozilla::MediaEmulationData;
143 typedef mozilla::ScrollStyles ScrollStyles;
144 using TransactionId = mozilla::layers::TransactionId;
146 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
147 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
149 enum nsPresContextType : uint8_t {
150 eContext_Galley, // unpaginated screen presentation
151 eContext_PrintPreview, // paginated screen presentation
152 eContext_Print, // paginated printer presentation
153 eContext_PageLayout // paginated & editable.
156 nsPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
159 * Initialize the presentation context from a particular device.
161 nsresult Init(nsDeviceContext* aDeviceContext);
164 * Initialize the font cache if it hasn't been initialized yet.
165 * (Needed for stylo)
167 void InitFontCache();
169 void UpdateFontCacheUserFonts(gfxUserFontSet* aUserFontSet);
171 FontVisibility GetFontVisibility() const { return mFontVisibility; }
172 void ReportBlockedFontFamily(const mozilla::fontlist::Family& aFamily);
173 void ReportBlockedFontFamily(const gfxFontFamily& aFamily);
176 * Get the nsFontMetrics that describe the properties of
177 * an nsFont.
178 * @param aFont font description to obtain metrics for
180 already_AddRefed<nsFontMetrics> GetMetricsFor(
181 const nsFont& aFont, const nsFontMetrics::Params& aParams);
184 * Notification when a font metrics instance created for this context is
185 * about to be deleted
187 nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
190 * Attempt to free up resources by flushing out any fonts no longer
191 * referenced by anything other than the font cache itself.
192 * @return error status
194 nsresult FlushFontCache();
197 * Set and detach presentation shell that this context is bound to.
198 * A presentation context may only be bound to a single shell.
200 void AttachPresShell(mozilla::PresShell* aPresShell);
201 void DetachPresShell();
203 nsPresContextType Type() const { return mType; }
206 * Get the PresentationShell that this context is bound to.
208 mozilla::PresShell* PresShell() const {
209 NS_ASSERTION(mPresShell, "Null pres shell");
210 return mPresShell;
213 mozilla::PresShell* GetPresShell() const { return mPresShell; }
215 void DocumentCharSetChanged(NotNull<const Encoding*> aCharSet);
218 * Returns the parent prescontext for this one. Returns null if this is a
219 * root.
221 nsPresContext* GetParentPresContext() const;
224 * Returns the prescontext of the root content document in the same process
225 * that contains this presentation, or null if there isn't one.
227 nsPresContext* GetInProcessRootContentDocumentPresContext();
230 * Returns the nearest widget for the root frame or view of this.
232 * @param aOffset If non-null the offset from the origin of the root
233 * frame's view to the widget's origin (usually positive)
234 * expressed in appunits of this will be returned in
235 * aOffset.
237 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
240 * Returns the root widget for this.
242 nsIWidget* GetRootWidget() const;
245 * Returns the widget which may have native focus and handles text input
246 * like keyboard input, IME, etc.
248 nsIWidget* GetTextInputHandlingWidget() const {
249 // Currently, root widget for each PresContext handles text input.
250 return GetRootWidget();
254 * Return the presentation context for the root of the view manager
255 * hierarchy that contains this presentation context, or nullptr if it can't
256 * be found (e.g. it's detached).
258 nsRootPresContext* GetRootPresContext() const;
260 virtual bool IsRoot() const { return false; }
262 mozilla::dom::Document* Document() const {
263 #ifdef DEBUG
264 ValidatePresShellAndDocumentReleation();
265 #endif // #ifdef DEBUG
266 return mDocument;
269 inline mozilla::ServoStyleSet* StyleSet() const;
271 bool HasPendingMediaQueryUpdates() const {
272 return !!mPendingMediaFeatureValuesChange;
275 inline nsCSSFrameConstructor* FrameConstructor() const;
277 mozilla::AnimationEventDispatcher* AnimationEventDispatcher() {
278 return mAnimationEventDispatcher;
281 mozilla::EffectCompositor* EffectCompositor() { return mEffectCompositor; }
282 nsTransitionManager* TransitionManager() { return mTransitionManager.get(); }
283 nsAnimationManager* AnimationManager() { return mAnimationManager.get(); }
284 const nsAnimationManager* AnimationManager() const {
285 return mAnimationManager.get();
287 mozilla::TimelineManager* TimelineManager() { return mTimelineManager.get(); }
289 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
291 mozilla::RestyleManager* RestyleManager() {
292 MOZ_ASSERT(mRestyleManager);
293 return mRestyleManager.get();
296 mozilla::CounterStyleManager* CounterStyleManager() const {
297 return mCounterStyleManager;
301 * Rebuilds all style data by throwing out the old rule tree and
302 * building a new one, and additionally applying a change hint (which must not
303 * contain nsChangeHint_ReconstructFrame) to the root frame.
305 * For the restyle hint argument, see RestyleManager::RebuildAllStyleData.
306 * Also rebuild the user font set and counter style manager.
308 * FIXME(emilio): The name of this is an utter lie. We should probably call
309 * this PostGlobalStyleChange or something, as it doesn't really rebuild
310 * anything unless you tell it to via the change hint / restyle hint
311 * machinery.
313 void RebuildAllStyleData(nsChangeHint, const mozilla::RestyleHint&);
315 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
316 * doesn't rebuild the user font set / counter-style manager / etc.
318 void PostRebuildAllStyleDataEvent(nsChangeHint, const mozilla::RestyleHint&);
320 void ContentLanguageChanged();
322 /** Returns whether any media query changed. */
323 bool FlushPendingMediaFeatureValuesChanged();
326 * Schedule a media feature change for this document, and potentially for
327 * other subdocuments and images (depending on the arguments).
329 void MediaFeatureValuesChanged(const mozilla::MediaFeatureChange&,
330 mozilla::MediaFeatureChangePropagation);
333 * Updates the size mode on all remote children and recursively notifies this
334 * document and all subdocuments (including remote children) that a media
335 * feature value has changed.
337 void SizeModeChanged(nsSizeMode aSizeMode);
340 * Access compatibility mode for this context. This is the same as
341 * our document's compatibility mode.
343 nsCompatibility CompatibilityMode() const;
346 * Access the image animation mode for this context
348 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
349 void SetImageAnimationMode(uint16_t aMode);
352 * Get medium of presentation
354 const nsAtom* Medium() const {
355 MOZ_ASSERT(mMedium);
356 return mMediaEmulationData.mMedium ? mMediaEmulationData.mMedium.get()
357 : mMedium;
361 * Render the document as if being viewed on a device with the specified
362 * media type.
364 * If passed null, it stops emulating.
366 void EmulateMedium(nsAtom* aMediaType);
368 /** Get a cached integer pref, by its type */
369 // * - initially created for bugs 30910, 61883, 74186, 84398
370 int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const {
371 // If called with a constant parameter, the compiler should optimize
372 // this switch statement away.
373 switch (aPrefType) {
374 case kPresContext_ScrollbarSide:
375 return mPrefScrollbarSide;
376 case kPresContext_BidiDirection:
377 return mPrefBidiDirection;
378 default:
379 NS_ERROR("invalid arg passed to GetCachedIntPref");
382 return false;
385 const mozilla::PreferenceSheet::Prefs& PrefSheetPrefs() const {
386 return mozilla::PreferenceSheet::PrefsFor(*mDocument);
389 bool ForcingColors() const {
390 return mozilla::PreferenceSheet::MayForceColors() &&
391 !PrefSheetPrefs().mUseDocumentColors;
394 mozilla::ColorScheme DefaultBackgroundColorScheme() const;
395 nscolor DefaultBackgroundColor() const;
397 nsISupports* GetContainerWeak() const;
399 nsDocShell* GetDocShell() const;
402 * Get the visible area associated with this presentation context.
403 * This is the size of the visible area that is used for
404 * presenting the document. The returned value is in the standard
405 * nscoord units (as scaled by the device context).
407 nsRect GetVisibleArea() const { return mVisibleArea; }
410 * Set the currently visible area. The units for r are standard
411 * nscoord units (as scaled by the device context).
413 void SetVisibleArea(const nsRect& r);
415 nsSize GetSizeForViewportUnits() const { return mSizeForViewportUnits; }
418 * Set the maximum height of the dynamic toolbar in nscoord units.
420 MOZ_CAN_RUN_SCRIPT
421 void SetDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight);
423 mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const {
424 MOZ_ASSERT(IsRootContentDocumentCrossProcess());
425 return mDynamicToolbarMaxHeight;
429 * Returns true if we are using the dynamic toolbar.
431 bool HasDynamicToolbar() const {
432 MOZ_ASSERT(IsRootContentDocumentCrossProcess());
433 return mDynamicToolbarMaxHeight > 0;
437 * |aOffset| must be offset from the bottom edge of the ICB and it's negative.
439 void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
440 mozilla::ScreenIntCoord GetDynamicToolbarHeight() const {
441 MOZ_ASSERT(IsRootContentDocumentCrossProcess());
442 return mDynamicToolbarHeight;
446 * Returns the state of the dynamic toolbar.
448 mozilla::DynamicToolbarState GetDynamicToolbarState() const;
451 * Return true if this presentation context is a paginated
452 * context.
454 bool IsPaginated() const { return mPaginated; }
457 * Sets whether the presentation context can scroll for a paginated
458 * context.
460 void SetPaginatedScrolling(bool aResult);
463 * Return true if this presentation context can scroll for paginated
464 * context.
466 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
469 * Get/set the size of a page
471 const nsSize& GetPageSize() const { return mPageSize; }
472 const nsMargin& GetDefaultPageMargin() const { return mDefaultPageMargin; }
473 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
476 * Get/set whether this document should be treated as having real pages
477 * XXX This raises the obvious question of why a document that isn't a page
478 * is paginated; there isn't a good reason except history
480 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
481 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) {
482 mIsRootPaginatedDocument = aIsRootPaginatedDocument;
486 * Get/set the print scaling level; used by nsPageFrame to scale up
487 * pages. Set safe to call before reflow, get guaranteed to be set
488 * properly after reflow.
491 float GetPageScale() { return mPageScale; }
492 void SetPageScale(float aScale) { mPageScale = aScale; }
495 * Get/set the scaling factor to use when rendering the pages for print
496 * preview. Only safe to get after print preview set up; safe to set anytime.
497 * This is a scaling factor for the display of the print preview. It
498 * does not affect layout. It only affects the size of the onscreen pages
499 * in print preview.
501 * The getter should only be used by the page sequence frame, which is the
502 * frame responsible for applying the scaling. Other callers should use
503 * nsPageSequenceFrame::GetPrintPreviewScale() if needed, instead of this API.
505 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
507 float GetPrintPreviewScaleForSequenceFrameOrScrollbars() const {
508 return mPPScale;
510 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
512 nsDeviceContext* DeviceContext() const { return mDeviceContext; }
513 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
515 bool UserInputEventsAllowed();
517 void MaybeIncreaseMeasuredTicksSinceLoading();
519 void ResetUserInputEventsAllowed() {
520 MOZ_ASSERT(IsRoot());
521 mMeasuredTicksSinceLoading = 0;
522 mUserInputEventsAllowed = false;
525 // Get the text zoom factor in use.
526 float TextZoom() const { return mTextZoom; }
529 * Notify the pres context that the safe area insets have changed.
531 void SetSafeAreaInsets(const mozilla::ScreenIntMargin& aInsets);
533 mozilla::ScreenIntMargin GetSafeAreaInsets() const { return mSafeAreaInsets; }
535 void RegisterManagedPostRefreshObserver(mozilla::ManagedPostRefreshObserver*);
536 void UnregisterManagedPostRefreshObserver(
537 mozilla::ManagedPostRefreshObserver*);
539 protected:
540 void CancelManagedPostRefreshObservers();
542 #ifdef DEBUG
543 void ValidatePresShellAndDocumentReleation() const;
544 #endif // #ifdef DEBUG
546 void SetTextZoom(float aZoom);
547 void SetFullZoom(float aZoom);
548 void SetOverrideDPPX(float);
549 void SetInRDMPane(bool aInRDMPane);
551 public:
552 float GetFullZoom() { return mFullZoom; }
554 * Device full zoom differs from full zoom because it gets the zoom from
555 * the device context, which may be using a different zoom due to rounding
556 * of app units to device pixels.
558 float GetDeviceFullZoom();
560 float GetOverrideDPPX() const { return mMediaEmulationData.mDPPX; }
562 // Gets the forced color-scheme if any via either our embedder, or DevTools
563 // emulation, or printing.
565 // NOTE(emilio): This might be called from an stylo thread.
566 Maybe<mozilla::ColorScheme> GetOverriddenOrEmbedderColorScheme() const;
569 * Recomputes the data dependent on the browsing context, like zoom and text
570 * zoom.
572 void RecomputeBrowsingContextDependentData();
575 * Sets the effective color scheme override, and invalidate stuff as needed.
577 void SetColorSchemeOverride(mozilla::dom::PrefersColorSchemeOverride);
580 * Return the device's screen size in inches, for font size
581 * inflation.
583 * If |aChanged| is non-null, then aChanged is filled in with whether
584 * the screen size value has changed since either:
585 * a. the last time the function was called with non-null aChanged, or
586 * b. the first time the function was called.
588 gfxSize ScreenSizeInchesForFontInflation(bool* aChanged = nullptr);
590 int32_t AppUnitsPerDevPixel() const { return mCurAppUnitsPerDevPixel; }
592 static nscoord CSSPixelsToAppUnits(int32_t aPixels) {
593 return NSToCoordRoundWithClamp(float(aPixels) *
594 float(mozilla::AppUnitsPerCSSPixel()));
597 static nscoord CSSPixelsToAppUnits(float aPixels) {
598 return NSToCoordRoundWithClamp(aPixels *
599 float(mozilla::AppUnitsPerCSSPixel()));
602 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) {
603 return NSAppUnitsToIntPixels(aAppUnits,
604 float(mozilla::AppUnitsPerCSSPixel()));
607 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) {
608 return NSAppUnitsToFloatPixels(aAppUnits,
609 float(mozilla::AppUnitsPerCSSPixel()));
612 static double AppUnitsToDoubleCSSPixels(nscoord aAppUnits) {
613 return NSAppUnitsToDoublePixels(aAppUnits,
614 double(mozilla::AppUnitsPerCSSPixel()));
617 nscoord DevPixelsToAppUnits(int32_t aPixels) const {
618 return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel());
621 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const {
622 return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerDevPixel()));
625 float AppUnitsToFloatDevPixels(nscoord aAppUnits) {
626 return aAppUnits / float(AppUnitsPerDevPixel());
629 int32_t CSSPixelsToDevPixels(int32_t aPixels) {
630 return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels));
633 float CSSPixelsToDevPixels(float aPixels) {
634 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
635 float(AppUnitsPerDevPixel()));
638 int32_t DevPixelsToIntCSSPixels(int32_t aPixels) {
639 return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels));
642 static nscoord RoundDownAppUnitsToCSSPixel(nscoord aAppUnits) {
643 return mozilla::RoundDownToMultiple(aAppUnits,
644 mozilla::AppUnitsPerCSSPixel());
646 static nscoord RoundUpAppUnitsToCSSPixel(nscoord aAppUnits) {
647 return mozilla::RoundUpToMultiple(aAppUnits,
648 mozilla::AppUnitsPerCSSPixel());
650 static nscoord RoundAppUnitsToCSSPixel(nscoord aAppUnits) {
651 return mozilla::RoundToMultiple(aAppUnits, mozilla::AppUnitsPerCSSPixel());
654 nscoord RoundDownAppUnitsToDevPixel(nscoord aAppUnits) const {
655 return mozilla::RoundDownToMultiple(aAppUnits, AppUnitsPerDevPixel());
657 nscoord RoundUpAppUnitsToDevPixel(nscoord aAppUnits) const {
658 return mozilla::RoundUpToMultiple(aAppUnits, AppUnitsPerDevPixel());
660 nscoord RoundAppUnitsToDevPixel(nscoord aAppUnits) const {
661 return mozilla::RoundToMultiple(aAppUnits, AppUnitsPerDevPixel());
664 mozilla::CSSIntPoint DevPixelsToIntCSSPixels(
665 const mozilla::LayoutDeviceIntPoint& aPoint) {
666 return mozilla::CSSIntPoint(
667 AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPoint.x)),
668 AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPoint.y)));
671 float DevPixelsToFloatCSSPixels(int32_t aPixels) const {
672 return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels));
675 mozilla::CSSToLayoutDeviceScale CSSToDevPixelScale() const {
676 return mozilla::CSSToLayoutDeviceScale(
677 float(mozilla::AppUnitsPerCSSPixel()) / float(AppUnitsPerDevPixel()));
680 // If there is a remainder, it is rounded to nearest app units.
681 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
683 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
685 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const {
686 return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
687 AppUnitsToGfxUnits(aAppRect.y),
688 AppUnitsToGfxUnits(aAppRect.Width()),
689 AppUnitsToGfxUnits(aAppRect.Height()));
692 static nscoord CSSTwipsToAppUnits(float aTwips) {
693 return NSToCoordRoundWithClamp(mozilla::AppUnitsPerCSSInch() *
694 NS_TWIPS_TO_INCHES(aTwips));
697 // Margin-specific version, since they often need TwipsToAppUnits
698 static nsMargin CSSTwipsToAppUnits(const nsIntMargin& marginInTwips) {
699 return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
700 CSSTwipsToAppUnits(float(marginInTwips.right)),
701 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
702 CSSTwipsToAppUnits(float(marginInTwips.left)));
705 static nscoord CSSPointsToAppUnits(float aPoints) {
706 return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
707 POINTS_PER_INCH_FLOAT);
710 nscoord PhysicalMillimetersToAppUnits(float aMM) const;
712 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const {
713 return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits));
717 * This checks the root element and the HTML BODY, if any, for an "overflow"
718 * property that should be applied to the viewport. If one is found then we
719 * return the element that we took the overflow from (which should then be
720 * treated as "overflow: visible"), and we store the overflow style here.
721 * If the document is in fullscreen, and the fullscreen element is not the
722 * root, the scrollbar of viewport will be suppressed.
723 * @return if scroll was propagated from some content node, the content node
724 * it was propagated from.
726 mozilla::dom::Element* UpdateViewportScrollStylesOverride();
729 * Returns the cached result from the last call to
730 * UpdateViewportScrollStylesOverride() -- i.e. return the node
731 * whose scrollbar styles we have propagated to the viewport (or nullptr if
732 * there is no such node).
734 mozilla::dom::Element* GetViewportScrollStylesOverrideElement() const {
735 return mViewportScrollOverrideElement;
738 const ScrollStyles& GetViewportScrollStylesOverride() const {
739 return mViewportScrollStyles;
743 * Check whether the given element would propagate its scrollbar styles to the
744 * viewport in non-paginated mode.
746 bool ElementWouldPropagateScrollStyles(const mozilla::dom::Element&);
749 * Methods for controlling the background drawing.
751 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
752 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
755 * Check if bidi enabled (set depending on the presence of RTL
756 * characters or when default directionality is RTL).
757 * If enabled, we should apply the Unicode Bidi Algorithm
759 * @lina 07/12/2000
761 bool BidiEnabled() const;
764 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
766 * @lina 07/12/2000
768 void SetBidiEnabled() const;
771 * Set visual or implicit mode into the pres context.
773 * Visual directionality is a presentation method that displays text
774 * as if it were a uni-directional, according to the primary display
775 * direction only.
777 * Implicit directionality is a presentation method in which the
778 * direction is determined by the Bidi algorithm according to the
779 * category of the characters and the category of the adjacent
780 * characters, and according to their primary direction.
782 * @lina 05/02/2000
784 void SetVisualMode(bool aIsVisual) { mIsVisual = aIsVisual; }
787 * Check whether the content should be treated as visual.
789 * @lina 05/02/2000
791 bool IsVisualMode() const { return mIsVisual; }
793 enum class InteractionType : uint32_t {
794 ClickInteraction,
795 KeyInteraction,
796 MouseMoveInteraction,
797 ScrollInteraction
800 void RecordInteractionTime(InteractionType aType,
801 const mozilla::TimeStamp& aTimeStamp);
803 void DisableInteractionTimeRecording() { mInteractionTimeEnabled = false; }
805 // Mohamed
808 * Set the Bidi options for the presentation context
810 void SetBidi(uint32_t aBidiOptions);
813 * Get the Bidi options for the presentation context
814 * Not inline so consumers of nsPresContext are not forced to
815 * include Document.
817 uint32_t GetBidi() const;
819 nsITheme* Theme() const MOZ_NONNULL_RETURN;
821 void RecomputeTheme();
823 bool UseOverlayScrollbars() const;
826 * Notify the pres context that the theme has changed. An internal switch
827 * means it's one of our Mozilla themes that changed (e.g., Modern to
828 * Classic). Otherwise, the OS is telling us that the native theme for the
829 * platform has changed.
831 void ThemeChanged(mozilla::widget::ThemeChangeKind);
834 * Notify the pres context that the resolution of the user interface has
835 * changed. This happens if a window is moved between HiDPI and non-HiDPI
836 * displays, so that the ratio of points to device pixels changes.
837 * The notification happens asynchronously.
839 void UIResolutionChanged();
842 * Like UIResolutionChanged() but invalidates values immediately.
844 void UIResolutionChangedSync();
846 /** Printing methods below should only be used for Medium() == print **/
847 void SetPrintSettings(nsIPrintSettings* aPrintSettings);
849 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
851 /* Helper function that ensures that this prescontext is shown in its
852 docshell if it's the most recent prescontext for the docshell. Returns
853 whether the prescontext is now being shown.
855 bool EnsureVisible();
857 #ifdef MOZ_REFLOW_PERF
858 void CountReflows(const char* aName, nsIFrame* aFrame);
859 #endif
861 void ConstructedFrame() { ++mFramesConstructed; }
862 void ReflowedFrame() { ++mFramesReflowed; }
863 void TriggeredAnimationRestyle() { ++mAnimationTriggeredRestyles; }
865 uint64_t FramesConstructedCount() const { return mFramesConstructed; }
866 uint64_t FramesReflowedCount() const { return mFramesReflowed; }
867 uint64_t AnimationTriggeredRestylesCount() const {
868 return mAnimationTriggeredRestyles;
871 static nscoord GetBorderWidthForKeyword(unsigned int aBorderWidthKeyword) {
872 // This table maps border-width enums 'thin', 'medium', 'thick'
873 // to actual nscoord values.
874 static const nscoord kBorderWidths[] = {
875 CSSPixelsToAppUnits(1), CSSPixelsToAppUnits(3), CSSPixelsToAppUnits(5)};
876 MOZ_ASSERT(size_t(aBorderWidthKeyword) <
877 mozilla::ArrayLength(kBorderWidths));
879 return kBorderWidths[aBorderWidthKeyword];
882 gfxTextPerfMetrics* GetTextPerfMetrics() { return mTextPerf.get(); }
884 bool IsDynamic() const {
885 return mType == eContext_PageLayout || mType == eContext_Galley;
887 bool IsScreen() const {
888 return mMedium == nsGkAtoms::screen || mType == eContext_PageLayout ||
889 mType == eContext_PrintPreview;
891 bool IsPrintingOrPrintPreview() const {
892 return mType == eContext_Print || mType == eContext_PrintPreview;
895 bool IsPrintPreview() const { return mType == eContext_PrintPreview; }
897 // Is this presentation in a chrome docshell?
898 bool IsChrome() const;
900 gfxUserFontSet* GetUserFontSet();
902 // Should be called whenever the set of fonts available in the user
903 // font set changes (e.g., because a new font loads, or because the
904 // user font set is changed and fonts become unavailable).
905 void UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont = nullptr);
907 gfxMissingFontRecorder* MissingFontRecorder() { return mMissingFonts.get(); }
909 void NotifyMissingFonts();
911 void FlushCounterStyles();
912 void MarkCounterStylesDirty();
914 void FlushFontFeatureValues();
915 void MarkFontFeatureValuesDirty() { mFontFeatureValuesDirty = true; }
917 void FlushFontPaletteValues();
918 void MarkFontPaletteValuesDirty() { mFontPaletteValuesDirty = true; }
920 // Ensure that it is safe to hand out CSS rules outside the layout
921 // engine by ensuring that all CSS style sheets have unique inners
922 // and, if necessary, synchronously rebuilding all style data.
923 void EnsureSafeToHandOutCSSRules();
925 // Mark an area as invalidated, associated with a given transaction id
926 // (allocated by nsRefreshDriver::GetTransactionId). Invalidated regions will
927 // be dispatched to MozAfterPaint events when NotifyDidPaintForSubtree is
928 // called for the transaction id (or any higher id).
929 void NotifyInvalidation(TransactionId aTransactionId, const nsRect& aRect);
930 // aRect is in device pixels
931 void NotifyInvalidation(TransactionId aTransactionId, const nsIntRect& aRect);
932 void NotifyDidPaintForSubtree(
933 TransactionId aTransactionId = TransactionId{0},
934 const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp());
935 void NotifyRevokingDidPaint(TransactionId aTransactionId);
936 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
937 MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireDOMPaintEvent(
938 nsTArray<nsRect>* aList, TransactionId aTransactionId,
939 mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());
941 bool IsDOMPaintEventPending();
944 * Returns the RestyleManager's restyle generation counter.
946 uint64_t GetRestyleGeneration() const;
947 uint64_t GetUndisplayedRestyleGeneration() const;
950 * Returns whether there are any pending restyles or reflows.
952 bool HasPendingRestyleOrReflow();
955 * Notify the prescontext that the presshell is about to reflow a reflow root.
956 * The single argument indicates whether this reflow should be interruptible.
957 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
958 * will always return false. If aInterruptible is true then CheckForInterrupt
959 * will return true when a pending event is detected. This is for use by the
960 * presshell only. Reflow code wanting to prevent interrupts should use
961 * InterruptPreventer.
963 void ReflowStarted(bool aInterruptible);
966 * A class that can be used to temporarily disable reflow interruption.
968 class InterruptPreventer;
969 friend class InterruptPreventer;
970 class MOZ_STACK_CLASS InterruptPreventer {
971 public:
972 explicit InterruptPreventer(nsPresContext* aCtx)
973 : mCtx(aCtx),
974 mInterruptsEnabled(aCtx->mInterruptsEnabled),
975 mHasPendingInterrupt(aCtx->mHasPendingInterrupt) {
976 mCtx->mInterruptsEnabled = false;
977 mCtx->mHasPendingInterrupt = false;
979 ~InterruptPreventer() {
980 mCtx->mInterruptsEnabled = mInterruptsEnabled;
981 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
984 private:
985 nsPresContext* mCtx;
986 bool mInterruptsEnabled;
987 bool mHasPendingInterrupt;
991 * Check for interrupts. This may return true if a pending event is
992 * detected. Once it has returned true, it will keep returning true
993 * until ReflowStarted is called. In all cases where this returns true,
994 * the passed-in frame (which should be the frame whose reflow will be
995 * interrupted if true is returned) will be passed to
996 * PresShell::FrameNeedsToContinueReflow.
998 bool CheckForInterrupt(nsIFrame* aFrame);
1000 * Returns true if CheckForInterrupt has returned true since the last
1001 * ReflowStarted call. Cannot itself trigger an interrupt check.
1003 bool HasPendingInterrupt() { return mHasPendingInterrupt; }
1005 * Sets a flag that will trip a reflow interrupt. This only bypasses the
1006 * interrupt timeout and the pending event check; other checks such as whether
1007 * interrupts are enabled and the interrupt check skipping still take effect.
1009 void SetPendingInterruptFromTest() { mPendingInterruptFromTest = true; }
1012 * If we have a presshell, and if the given content's current
1013 * document is the same as our presshell's document, return the
1014 * content's primary frame. Otherwise, return null. Only use this
1015 * if you care about which presshell the primary frame is in.
1017 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
1019 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1020 virtual size_t SizeOfIncludingThis(
1021 mozilla::MallocSizeOf aMallocSizeOf) const {
1022 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
1026 * We are a root content document in process if: we are not a resource doc, we
1027 * are not chrome, and we either have no parent in the current process or our
1028 * parent is chrome.
1030 bool IsRootContentDocumentInProcess() const;
1033 * We are a root content document cross process if: we are not a resource doc,
1034 * we are not chrome, and we either have no parent in any process or our
1035 * parent is chrome.
1037 bool IsRootContentDocumentCrossProcess() const;
1039 bool HadNonBlankPaint() const { return mHadNonBlankPaint; }
1040 bool HadFirstContentfulPaint() const { return mHadFirstContentfulPaint; }
1041 void NotifyNonBlankPaint();
1042 void NotifyContentfulPaint();
1043 void NotifyPaintStatusReset();
1044 void NotifyDOMContentFlushed();
1046 bool HasEverBuiltInvisibleText() const { return mHasEverBuiltInvisibleText; }
1047 void SetBuiltInvisibleText() { mHasEverBuiltInvisibleText = true; }
1049 bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
1050 return mHasWarnedAboutTooLargeDashedOrDottedRadius;
1053 void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
1054 mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
1057 void RegisterContainerQueryFrame(nsIFrame* aFrame);
1058 void UnregisterContainerQueryFrame(nsIFrame* aFrame);
1059 bool HasContainerQueryFrames() const {
1060 return !mContainerQueryFrames.IsEmpty();
1063 void FinishedContainerQueryUpdate();
1065 bool UpdateContainerQueryStyles();
1067 mozilla::intl::Bidi& BidiEngine();
1069 gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const {
1070 return mFontFeatureValuesLookup;
1073 mozilla::gfx::FontPaletteValueSet* GetFontPaletteValueSet() const {
1074 return mFontPaletteValueSet;
1077 protected:
1078 friend class nsRunnableMethod<nsPresContext>;
1079 void ThemeChangedInternal();
1080 void RefreshSystemMetrics();
1082 // Update device context's resolution from the widget
1083 void UIResolutionChangedInternal();
1085 void SetImgAnimations(nsIContent* aParent, uint16_t aMode);
1086 void SetSMILAnimations(mozilla::dom::Document* aDoc, uint16_t aNewMode,
1087 uint16_t aOldMode);
1089 static void PreferenceChanged(const char* aPrefName, void* aSelf);
1090 void PreferenceChanged(const char* aPrefName);
1092 void GetUserPreferences();
1094 void UpdateCharSet(NotNull<const Encoding*> aCharSet);
1096 void DoForceReflowForFontInfoUpdateFromStyle();
1098 public:
1099 // Used by the PresShell to force a reflow when some aspect of font info
1100 // has been updated, potentially affecting font selection and layout.
1101 void ForceReflowForFontInfoUpdate(bool aNeedsReframe);
1102 void ForceReflowForFontInfoUpdateFromStyle();
1105 * Checks for MozAfterPaint listeners on the document
1107 bool MayHavePaintEventListener();
1109 void InvalidatePaintedLayers();
1111 uint32_t GetNextFrameRateMultiplier() const {
1112 return mNextFrameRateMultiplier;
1115 void DidUseFrameRateMultiplier() {
1116 // This heuristic is used to reduce frame rate between fcp and the end of
1117 // the page load.
1118 if (mNextFrameRateMultiplier < 8) {
1119 ++mNextFrameRateMultiplier;
1123 protected:
1124 // May be called multiple times (unlink, destructor)
1125 void Destroy();
1127 void AppUnitsPerDevPixelChanged();
1129 bool HavePendingInputEvent();
1131 // Creates a one-shot timer with the given aCallback & aDelay.
1132 // Returns a refcounted pointer to the timer (or nullptr on failure).
1133 already_AddRefed<nsITimer> CreateTimer(nsTimerCallbackFunc aCallback,
1134 const char* aName, uint32_t aDelay);
1136 struct TransactionInvalidations {
1137 TransactionId mTransactionId;
1138 nsTArray<nsRect> mInvalidations;
1139 bool mIsWaitingForPreviousTransaction = false;
1141 TransactionInvalidations* GetInvalidations(TransactionId aTransactionId);
1143 // This should be called only when we update mVisibleArea or
1144 // mDynamicToolbarMaxHeight or `app units per device pixels` changes.
1145 void AdjustSizeForViewportUnits();
1147 // Call in response to prefs changes that might affect what fonts should be
1148 // visibile to CSS. Returns whether the current visibility value actually
1149 // changed (in which case content should be reflowed).
1150 bool UpdateFontVisibility();
1151 void ReportBlockedFontFamilyName(const nsCString& aFamily,
1152 FontVisibility aVisibility);
1154 // IMPORTANT: The ownership implicit in the following member variables
1155 // has been explicitly checked. If you add any members to this class,
1156 // please make the ownership explicit (pinkerton, scc).
1158 // the PresShell owns a strong reference to the nsPresContext, and is
1159 // responsible for nulling this pointer before it is destroyed
1160 mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell; // [WEAK]
1161 RefPtr<mozilla::dom::Document> mDocument;
1162 RefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1163 // better safe than sorry.
1164 // Cannot reintroduce cycles
1165 // since there is no dependency
1166 // from gfx back to layout.
1167 RefPtr<nsFontCache> mFontCache;
1168 RefPtr<mozilla::EventStateManager> mEventManager;
1169 RefPtr<nsRefreshDriver> mRefreshDriver;
1170 RefPtr<mozilla::AnimationEventDispatcher> mAnimationEventDispatcher;
1171 RefPtr<mozilla::EffectCompositor> mEffectCompositor;
1172 mozilla::UniquePtr<nsTransitionManager> mTransitionManager;
1173 mozilla::UniquePtr<nsAnimationManager> mAnimationManager;
1174 mozilla::UniquePtr<mozilla::TimelineManager> mTimelineManager;
1175 mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager;
1176 RefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
1177 const nsStaticAtom* mMedium;
1178 RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup;
1179 RefPtr<mozilla::gfx::FontPaletteValueSet> mFontPaletteValueSet;
1181 // TODO(emilio): Maybe lazily create and put under a UniquePtr if this grows a
1182 // lot?
1183 MediaEmulationData mMediaEmulationData;
1185 float mTextZoom; // Text zoom, defaults to 1.0
1186 float mFullZoom; // Page zoom, defaults to 1.0
1187 gfxSize mLastFontInflationScreenSize;
1189 int32_t mCurAppUnitsPerDevPixel;
1190 int32_t mAutoQualityMinFontSizePixelsPref;
1192 nsCOMPtr<nsITheme> mTheme;
1193 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1195 mozilla::UniquePtr<mozilla::intl::Bidi> mBidiEngine;
1197 AutoTArray<TransactionInvalidations, 4> mTransactions;
1199 // text performance metrics
1200 mozilla::UniquePtr<gfxTextPerfMetrics> mTextPerf;
1202 mozilla::UniquePtr<gfxMissingFontRecorder> mMissingFonts;
1204 nsRect mVisibleArea;
1205 // This value is used to resolve viewport units.
1206 // On mobile this size is including the dynamic toolbar maximum height below.
1207 // On desktops this size is pretty much the same as |mVisibleArea|.
1208 nsSize mSizeForViewportUnits;
1209 // The maximum height of the dynamic toolbar on mobile.
1210 mozilla::ScreenIntCoord mDynamicToolbarMaxHeight;
1211 mozilla::ScreenIntCoord mDynamicToolbarHeight;
1212 // Safe area insets support
1213 mozilla::ScreenIntMargin mSafeAreaInsets;
1214 nsSize mPageSize;
1216 // The computed page margins from the print settings.
1218 // This margin will be used for each page in the current print operation, by
1219 // default (i.e. unless overridden by @page rules).
1221 // FIXME(emilio): Maybe we could let a global @page rule do that, though it's
1222 // sketchy at best, see https://github.com/w3c/csswg-drafts/issues/5437 for
1223 // discussion.
1224 nsMargin mDefaultPageMargin;
1225 float mPageScale;
1226 float mPPScale;
1228 // This is a non-owning pointer. May be null. If non-null, it's guaranteed to
1229 // be pointing to an element that's still alive, because we'll reset it in
1230 // UpdateViewportScrollStylesOverride() as part of the cleanup code when
1231 // this element is removed from the document. (For <body> and the root
1232 // element, this call happens in nsCSSFrameConstructor::ContentRemoved(). For
1233 // fullscreen elements, it happens in the fullscreen-specific cleanup invoked
1234 // by Element::UnbindFromTree().)
1235 mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollOverrideElement;
1237 // Counters for tests and tools that want to detect frame construction
1238 // or reflow.
1239 uint64_t mElementsRestyled;
1240 uint64_t mFramesConstructed;
1241 uint64_t mFramesReflowed;
1242 uint64_t mAnimationTriggeredRestyles;
1244 mozilla::TimeStamp mReflowStartTime;
1246 Maybe<TransactionId> mFirstContentfulPaintTransactionId;
1248 mozilla::UniquePtr<mozilla::MediaFeatureChange>
1249 mPendingMediaFeatureValuesChange;
1251 // Time of various first interaction types, used to report time from
1252 // first paint of the top level content pres shell to first interaction.
1253 mozilla::TimeStamp mFirstNonBlankPaintTime;
1254 mozilla::TimeStamp mFirstClickTime;
1255 mozilla::TimeStamp mFirstKeyTime;
1256 mozilla::TimeStamp mFirstMouseMoveTime;
1257 mozilla::TimeStamp mFirstScrollTime;
1259 // last time we did a full style flush
1260 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1262 uint32_t mInterruptChecksToSkip;
1264 // During page load we use slower frame rate.
1265 uint32_t mNextFrameRateMultiplier;
1267 uint32_t mMeasuredTicksSinceLoading;
1269 nsTArray<RefPtr<mozilla::ManagedPostRefreshObserver>>
1270 mManagedPostRefreshObservers;
1272 // If we block the use of a font-family that is explicitly requested,
1273 // due to font visibility settings, we log a message to the web console;
1274 // this hash-set keeps track of names we've logged for this context, so
1275 // that we can avoid repeatedly reporting the same font.
1276 nsTHashSet<nsCString> mBlockedFonts;
1278 // The set of container query boxes currently in the document, sorted by
1279 // depth.
1280 mozilla::DepthOrderedFrameList mContainerQueryFrames;
1281 // The set of container query elements currently in the document that have
1282 // been updated so far. This is necessary to avoid reentering on container
1283 // query style changes which cause us to do frame reconstruction.
1284 nsTHashSet<nsIContent*> mUpdatedContainerQueryContents;
1286 ScrollStyles mViewportScrollStyles;
1288 uint16_t mImageAnimationMode;
1289 uint16_t mImageAnimationModePref;
1291 nsPresContextType mType;
1293 public:
1294 // The following are public member variables so that we can use them
1295 // with mozilla::AutoToggle or mozilla::AutoRestore.
1297 // Should we disable font size inflation because we're inside of
1298 // shrink-wrapping calculations on an inflation container?
1299 bool mInflationDisabledForShrinkWrap;
1301 protected:
1302 static constexpr size_t kThemeChangeKindBits = 2;
1303 static_assert(unsigned(mozilla::widget::ThemeChangeKind::AllBits) <=
1304 (1u << kThemeChangeKindBits) - 1,
1305 "theme change kind doesn't fit");
1307 unsigned mInteractionTimeEnabled : 1;
1308 unsigned mHasPendingInterrupt : 1;
1309 unsigned mHasEverBuiltInvisibleText : 1;
1310 unsigned mPendingInterruptFromTest : 1;
1311 unsigned mInterruptsEnabled : 1;
1312 unsigned mSendAfterPaintToContent : 1;
1313 unsigned mDrawImageBackground : 1;
1314 unsigned mDrawColorBackground : 1;
1315 unsigned mNeverAnimate : 1;
1316 unsigned mPaginated : 1;
1317 unsigned mCanPaginatedScroll : 1;
1318 unsigned mDoScaledTwips : 1;
1319 unsigned mIsRootPaginatedDocument : 1;
1320 unsigned mPrefBidiDirection : 1;
1321 unsigned mPrefScrollbarSide : 2;
1322 unsigned mPendingThemeChanged : 1;
1323 // widget::ThemeChangeKind
1324 unsigned mPendingThemeChangeKind : kThemeChangeKindBits;
1325 unsigned mPendingUIResolutionChanged : 1;
1326 unsigned mPendingFontInfoUpdateReflowFromStyle : 1;
1328 // Are we currently drawing an SVG glyph?
1329 unsigned mIsGlyph : 1;
1331 // Is the current mCounterStyleManager valid?
1332 unsigned mCounterStylesDirty : 1;
1334 // Is the current mFontFeatureValuesLookup valid?
1335 unsigned mFontFeatureValuesDirty : 1;
1337 // Is the current mFontFeatureValueSet valid?
1338 unsigned mFontPaletteValuesDirty : 1;
1340 unsigned mIsVisual : 1;
1342 // Are we in the RDM pane?
1343 unsigned mInRDMPane : 1;
1345 unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;
1347 // Have we added quirk.css to the style set?
1348 unsigned mQuirkSheetAdded : 1;
1350 // Has NotifyNonBlankPaint been called on this PresContext?
1351 unsigned mHadNonBlankPaint : 1;
1352 // Has NotifyContentfulPaint been called on this PresContext?
1353 unsigned mHadFirstContentfulPaint : 1;
1354 // True when a contentful paint has happened and this paint doesn't
1355 // come from the regular tick process. Usually this means a
1356 // contentful paint was triggered manually.
1357 unsigned mHadNonTickContentfulPaint : 1;
1359 // Has NotifyDidPaintForSubtree been called for a contentful paint?
1360 unsigned mHadContentfulPaintComposite : 1;
1362 unsigned mUserInputEventsAllowed : 1;
1363 #ifdef DEBUG
1364 unsigned mInitialized : 1;
1365 #endif
1367 // FIXME(emilio): These would be better packed on top of the bitfields, but
1368 // that breaks bindgen in win32.
1369 FontVisibility mFontVisibility = FontVisibility::Unknown;
1370 mozilla::dom::PrefersColorSchemeOverride mOverriddenOrEmbedderColorScheme;
1372 protected:
1373 virtual ~nsPresContext();
1375 void LastRelease();
1377 void EnsureTheme();
1379 #ifdef DEBUG
1380 private:
1381 friend struct nsAutoLayoutPhase;
1382 mozilla::EnumeratedArray<nsLayoutPhase, nsLayoutPhase::COUNT, uint32_t>
1383 mLayoutPhaseCount;
1385 public:
1386 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1387 return mLayoutPhaseCount[aPhase];
1389 #endif
1392 class nsRootPresContext final : public nsPresContext {
1393 public:
1394 nsRootPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
1395 virtual bool IsRoot() const override { return true; }
1398 * Add a runnable that will get called before the next paint. They will get
1399 * run eventually even if painting doesn't happen. They might run well before
1400 * painting happens.
1402 void AddWillPaintObserver(nsIRunnable* aRunnable);
1405 * Run all runnables that need to get called before the next paint.
1407 void FlushWillPaintObservers();
1409 virtual size_t SizeOfExcludingThis(
1410 mozilla::MallocSizeOf aMallocSizeOf) const override;
1412 protected:
1413 class RunWillPaintObservers : public mozilla::Runnable {
1414 public:
1415 explicit RunWillPaintObservers(nsRootPresContext* aPresContext)
1416 : Runnable("nsPresContextType::RunWillPaintObservers"),
1417 mPresContext(aPresContext) {}
1418 void Revoke() { mPresContext = nullptr; }
1419 NS_IMETHOD Run() override {
1420 if (mPresContext) {
1421 mPresContext->FlushWillPaintObservers();
1423 return NS_OK;
1425 // The lifetime of this reference is handled by an nsRevocableEventPtr
1426 nsRootPresContext* MOZ_NON_OWNING_REF mPresContext;
1429 friend class nsPresContext;
1431 nsTArray<nsCOMPtr<nsIRunnable>> mWillPaintObservers;
1432 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1435 #ifdef MOZ_REFLOW_PERF
1437 # define DO_GLOBAL_REFLOW_COUNT(_name) \
1438 aPresContext->CountReflows((_name), (nsIFrame*)this);
1439 #else
1440 # define DO_GLOBAL_REFLOW_COUNT(_name)
1441 #endif // MOZ_REFLOW_PERF
1443 #endif /* nsPresContext_h___ */