Bug 1877662 - expose mozconfig as an artifact from build-fat-aar. r=glandium,geckovie...
[gecko.git] / layout / base / nsPresContext.h
blob563dac0eaea55183016986967b80ee674c2440ca
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 class PerformanceMainThread;
96 enum class PrefersColorSchemeOverride : uint8_t;
97 } // namespace dom
98 namespace gfx {
99 class FontPaletteValueSet;
100 class PaletteCache;
101 } // namespace gfx
102 } // namespace mozilla
104 // IDs for the default variable and fixed fonts (not to be changed, see
105 // nsFont.h) To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are
106 // also supported.
108 // kGenericFont_moz_variable
109 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00;
110 // kGenericFont_moz_fixed
111 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01;
113 #ifdef DEBUG
114 struct nsAutoLayoutPhase;
116 enum class nsLayoutPhase : uint8_t {
117 Paint,
118 DisplayListBuilding, // sometimes a subset of the paint phase
119 Reflow,
120 FrameC,
121 COUNT
123 #endif
125 class nsRootPresContext;
127 // An interface for presentation contexts. Presentation contexts are
128 // objects that provide an outer context for a presentation shell.
130 class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
131 public:
132 using Encoding = mozilla::Encoding;
133 template <typename T>
134 using NotNull = mozilla::NotNull<T>;
135 template <typename T>
136 using Maybe = mozilla::Maybe<T>;
137 using MediaEmulationData = mozilla::MediaEmulationData;
139 typedef mozilla::ScrollStyles ScrollStyles;
140 using TransactionId = mozilla::layers::TransactionId;
142 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
143 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
145 enum nsPresContextType : uint8_t {
146 eContext_Galley, // unpaginated screen presentation
147 eContext_PrintPreview, // paginated screen presentation
148 eContext_Print, // paginated printer presentation
149 eContext_PageLayout // paginated & editable.
152 nsPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
155 * Initialize the presentation context from a particular device.
157 nsresult Init(nsDeviceContext* aDeviceContext);
160 * Initialize the font cache if it hasn't been initialized yet.
161 * (Needed for stylo)
163 void InitFontCache();
165 void UpdateFontCacheUserFonts(gfxUserFontSet* aUserFontSet);
168 * Return the font visibility level to be applied to this context,
169 * potentially blocking user-installed or non-standard fonts from being
170 * used by web content.
171 * Note that depending on ResistFingerprinting options, the caller may
172 * override this value when resolving CSS <generic-family> keywords.
174 FontVisibility GetFontVisibility() const { return mFontVisibility; }
177 * Log a message to the console about a font request being blocked.
179 void ReportBlockedFontFamily(const mozilla::fontlist::Family& aFamily);
180 void ReportBlockedFontFamily(const gfxFontFamily& aFamily);
183 * Get the nsFontMetrics that describe the properties of
184 * an nsFont.
185 * @param aFont font description to obtain metrics for
187 already_AddRefed<nsFontMetrics> GetMetricsFor(
188 const nsFont& aFont, const nsFontMetrics::Params& aParams);
191 * Notification when a font metrics instance created for this context is
192 * about to be deleted
194 nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
197 * Attempt to free up resources by flushing out any fonts no longer
198 * referenced by anything other than the font cache itself.
199 * @return error status
201 nsresult FlushFontCache();
204 * Set and detach presentation shell that this context is bound to.
205 * A presentation context may only be bound to a single shell.
207 void AttachPresShell(mozilla::PresShell* aPresShell);
208 void DetachPresShell();
210 nsPresContextType Type() const { return mType; }
213 * Get the PresentationShell that this context is bound to.
215 mozilla::PresShell* PresShell() const {
216 NS_ASSERTION(mPresShell, "Null pres shell");
217 return mPresShell;
220 mozilla::PresShell* GetPresShell() const { return mPresShell; }
222 void DocumentCharSetChanged(NotNull<const Encoding*> aCharSet);
224 mozilla::dom::PerformanceMainThread* GetPerformanceMainThread() const;
226 * Returns the parent prescontext for this one. Returns null if this is a
227 * root.
229 nsPresContext* GetParentPresContext() const;
232 * Returns the prescontext of the root content document in the same process
233 * that contains this presentation, or null if there isn't one.
235 nsPresContext* GetInProcessRootContentDocumentPresContext();
238 * Returns the nearest widget for the root frame or view of this.
240 * @param aOffset If non-null the offset from the origin of the root
241 * frame's view to the widget's origin (usually positive)
242 * expressed in appunits of this will be returned in
243 * aOffset.
245 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
248 * Returns the root widget for this.
250 nsIWidget* GetRootWidget() const;
253 * Returns the widget which may have native focus and handles text input
254 * like keyboard input, IME, etc.
256 nsIWidget* GetTextInputHandlingWidget() const {
257 // Currently, root widget for each PresContext handles text input.
258 return GetRootWidget();
262 * Return the presentation context for the root of the view manager
263 * hierarchy that contains this presentation context, or nullptr if it can't
264 * be found (e.g. it's detached).
266 nsRootPresContext* GetRootPresContext() const;
268 virtual bool IsRoot() const { return false; }
270 mozilla::dom::Document* Document() const {
271 #ifdef DEBUG
272 ValidatePresShellAndDocumentReleation();
273 #endif // #ifdef DEBUG
274 return mDocument;
277 inline mozilla::ServoStyleSet* StyleSet() const;
279 bool HasPendingMediaQueryUpdates() const {
280 return !!mPendingMediaFeatureValuesChange;
283 inline nsCSSFrameConstructor* FrameConstructor() const;
285 mozilla::AnimationEventDispatcher* AnimationEventDispatcher() {
286 return mAnimationEventDispatcher;
289 mozilla::EffectCompositor* EffectCompositor() { return mEffectCompositor; }
290 nsTransitionManager* TransitionManager() { return mTransitionManager.get(); }
291 nsAnimationManager* AnimationManager() { return mAnimationManager.get(); }
292 const nsAnimationManager* AnimationManager() const {
293 return mAnimationManager.get();
295 mozilla::TimelineManager* TimelineManager() { return mTimelineManager.get(); }
297 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
299 mozilla::RestyleManager* RestyleManager() {
300 MOZ_ASSERT(mRestyleManager);
301 return mRestyleManager.get();
304 mozilla::CounterStyleManager* CounterStyleManager() const {
305 return mCounterStyleManager;
309 * Rebuilds all style data by throwing out the old rule tree and
310 * building a new one, and additionally applying a change hint (which must not
311 * contain nsChangeHint_ReconstructFrame) to the root frame.
313 * For the restyle hint argument, see RestyleManager::RebuildAllStyleData.
314 * Also rebuild the user font set and counter style manager.
316 * FIXME(emilio): The name of this is an utter lie. We should probably call
317 * this PostGlobalStyleChange or something, as it doesn't really rebuild
318 * anything unless you tell it to via the change hint / restyle hint
319 * machinery.
321 void RebuildAllStyleData(nsChangeHint, const mozilla::RestyleHint&);
323 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
324 * doesn't rebuild the user font set / counter-style manager / etc.
326 void PostRebuildAllStyleDataEvent(nsChangeHint, const mozilla::RestyleHint&);
328 void ContentLanguageChanged();
330 /** Returns whether any media query changed. */
331 bool FlushPendingMediaFeatureValuesChanged();
334 * Schedule a media feature change for this document, and potentially for
335 * other subdocuments and images (depending on the arguments).
337 void MediaFeatureValuesChanged(const mozilla::MediaFeatureChange&,
338 mozilla::MediaFeatureChangePropagation);
341 * Updates the size mode on all remote children and recursively notifies this
342 * document and all subdocuments (including remote children) that a media
343 * feature value has changed.
345 void SizeModeChanged(nsSizeMode aSizeMode);
348 * Access compatibility mode for this context. This is the same as
349 * our document's compatibility mode.
351 nsCompatibility CompatibilityMode() const;
354 * Access the image animation mode for this context
356 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
357 void SetImageAnimationMode(uint16_t aMode);
360 * Get medium of presentation
362 const nsAtom* Medium() const {
363 MOZ_ASSERT(mMedium);
364 return mMediaEmulationData.mMedium ? mMediaEmulationData.mMedium.get()
365 : mMedium;
369 * Render the document as if being viewed on a device with the specified
370 * media type.
372 * If passed null, it stops emulating.
374 void EmulateMedium(nsAtom* aMediaType);
376 const mozilla::PreferenceSheet::Prefs& PrefSheetPrefs() const {
377 return mozilla::PreferenceSheet::PrefsFor(*mDocument);
380 bool ForcingColors() const {
381 return mozilla::PreferenceSheet::MayForceColors() &&
382 !PrefSheetPrefs().mUseDocumentColors;
385 mozilla::ColorScheme DefaultBackgroundColorScheme() const;
386 nscolor DefaultBackgroundColor() const;
388 nsISupports* GetContainerWeak() const;
390 nsDocShell* GetDocShell() const;
393 * Get the visible area associated with this presentation context.
394 * This is the size of the visible area that is used for
395 * presenting the document. The returned value is in the standard
396 * nscoord units (as scaled by the device context).
398 nsRect GetVisibleArea() const { return mVisibleArea; }
401 * Set the currently visible area. The units for r are standard
402 * nscoord units (as scaled by the device context).
404 void SetVisibleArea(const nsRect& r);
406 nsSize GetSizeForViewportUnits() const { return mSizeForViewportUnits; }
409 * Set the maximum height of the dynamic toolbar in nscoord units.
411 MOZ_CAN_RUN_SCRIPT
412 void SetDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight);
414 mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const {
415 MOZ_ASSERT(IsRootContentDocumentCrossProcess());
416 return mDynamicToolbarMaxHeight;
420 * Returns true if we are using the dynamic toolbar.
422 bool HasDynamicToolbar() const {
423 MOZ_ASSERT(IsRootContentDocumentCrossProcess());
424 return mDynamicToolbarMaxHeight > 0;
428 * |aOffset| must be offset from the bottom edge of the ICB and it's negative.
430 void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
431 mozilla::ScreenIntCoord GetDynamicToolbarHeight() const {
432 MOZ_ASSERT(IsRootContentDocumentCrossProcess());
433 return mDynamicToolbarHeight;
437 * Returns the state of the dynamic toolbar.
439 mozilla::DynamicToolbarState GetDynamicToolbarState() const;
442 * Return true if this presentation context is a paginated
443 * context.
445 bool IsPaginated() const { return mPaginated; }
448 * Sets whether the presentation context can scroll for a paginated
449 * context.
451 void SetPaginatedScrolling(bool aResult);
454 * Return true if this presentation context can scroll for paginated
455 * context.
457 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
460 * Get/set the size of a page
462 const nsSize& GetPageSize() const { return mPageSize; }
463 const nsMargin& GetDefaultPageMargin() const { return mDefaultPageMargin; }
464 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
467 * Get/set whether this document should be treated as having real pages
468 * XXX This raises the obvious question of why a document that isn't a page
469 * is paginated; there isn't a good reason except history
471 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
472 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) {
473 mIsRootPaginatedDocument = aIsRootPaginatedDocument;
477 * Get/set the print scaling level; used by nsPageFrame to scale up
478 * pages. Set safe to call before reflow, get guaranteed to be set
479 * properly after reflow.
482 float GetPageScale() { return mPageScale; }
483 void SetPageScale(float aScale) { mPageScale = aScale; }
486 * Get/set the scaling factor to use when rendering the pages for print
487 * preview. Only safe to get after print preview set up; safe to set anytime.
488 * This is a scaling factor for the display of the print preview. It
489 * does not affect layout. It only affects the size of the onscreen pages
490 * in print preview.
492 * The getter should only be used by the page sequence frame, which is the
493 * frame responsible for applying the scaling. Other callers should use
494 * nsPageSequenceFrame::GetPrintPreviewScale() if needed, instead of this API.
496 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
498 float GetPrintPreviewScaleForSequenceFrameOrScrollbars() const {
499 return mPPScale;
501 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
503 nsDeviceContext* DeviceContext() const { return mDeviceContext; }
504 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
506 bool UserInputEventsAllowed();
508 void MaybeIncreaseMeasuredTicksSinceLoading();
510 bool NeedsMoreTicksForUserInput() const;
512 void ResetUserInputEventsAllowed() {
513 MOZ_ASSERT(IsRoot());
514 mMeasuredTicksSinceLoading = 0;
515 mUserInputEventsAllowed = false;
518 // Get the text zoom factor in use.
519 float TextZoom() const { return mTextZoom; }
522 * Notify the pres context that the safe area insets have changed.
524 void SetSafeAreaInsets(const mozilla::ScreenIntMargin& aInsets);
526 mozilla::ScreenIntMargin GetSafeAreaInsets() const { return mSafeAreaInsets; }
528 void RegisterManagedPostRefreshObserver(mozilla::ManagedPostRefreshObserver*);
529 void UnregisterManagedPostRefreshObserver(
530 mozilla::ManagedPostRefreshObserver*);
532 protected:
533 void CancelManagedPostRefreshObservers();
535 #ifdef DEBUG
536 void ValidatePresShellAndDocumentReleation() const;
537 #endif // #ifdef DEBUG
539 void SetTextZoom(float aZoom);
540 void SetFullZoom(float aZoom);
541 void SetOverrideDPPX(float);
542 void SetInRDMPane(bool aInRDMPane);
544 public:
545 float GetFullZoom() { return mFullZoom; }
547 * Device full zoom differs from full zoom because it gets the zoom from
548 * the device context, which may be using a different zoom due to rounding
549 * of app units to device pixels.
551 float GetDeviceFullZoom();
553 float GetOverrideDPPX() const { return mMediaEmulationData.mDPPX; }
555 // Gets the forced color-scheme if any via either our embedder, or DevTools
556 // emulation, or printing.
558 // NOTE(emilio): This might be called from an stylo thread.
559 Maybe<mozilla::ColorScheme> GetOverriddenOrEmbedderColorScheme() const;
562 * Recomputes the data dependent on the browsing context, like zoom and text
563 * zoom.
565 void RecomputeBrowsingContextDependentData();
568 * Sets the effective color scheme override, and invalidate stuff as needed.
570 void SetColorSchemeOverride(mozilla::dom::PrefersColorSchemeOverride);
573 * Return the device's screen size in inches, for font size
574 * inflation.
576 * If |aChanged| is non-null, then aChanged is filled in with whether
577 * the screen size value has changed since either:
578 * a. the last time the function was called with non-null aChanged, or
579 * b. the first time the function was called.
581 gfxSize ScreenSizeInchesForFontInflation(bool* aChanged = nullptr);
583 int32_t AppUnitsPerDevPixel() const { return mCurAppUnitsPerDevPixel; }
585 static nscoord CSSPixelsToAppUnits(int32_t aPixels) {
586 return NSToCoordRoundWithClamp(float(aPixels) *
587 float(mozilla::AppUnitsPerCSSPixel()));
590 static nscoord CSSPixelsToAppUnits(float aPixels) {
591 return NSToCoordRoundWithClamp(aPixels *
592 float(mozilla::AppUnitsPerCSSPixel()));
595 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) {
596 return NSAppUnitsToIntPixels(aAppUnits,
597 float(mozilla::AppUnitsPerCSSPixel()));
600 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) {
601 return NSAppUnitsToFloatPixels(aAppUnits,
602 float(mozilla::AppUnitsPerCSSPixel()));
605 static double AppUnitsToDoubleCSSPixels(nscoord aAppUnits) {
606 return NSAppUnitsToDoublePixels(aAppUnits,
607 double(mozilla::AppUnitsPerCSSPixel()));
610 nscoord DevPixelsToAppUnits(int32_t aPixels) const {
611 return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel());
614 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const {
615 return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerDevPixel()));
618 float AppUnitsToFloatDevPixels(nscoord aAppUnits) {
619 return aAppUnits / float(AppUnitsPerDevPixel());
622 int32_t CSSPixelsToDevPixels(int32_t aPixels) {
623 return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels));
626 float CSSPixelsToDevPixels(float aPixels) {
627 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
628 float(AppUnitsPerDevPixel()));
631 int32_t DevPixelsToIntCSSPixels(int32_t aPixels) {
632 return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels));
635 static nscoord RoundDownAppUnitsToCSSPixel(nscoord aAppUnits) {
636 return mozilla::RoundDownToMultiple(aAppUnits,
637 mozilla::AppUnitsPerCSSPixel());
639 static nscoord RoundUpAppUnitsToCSSPixel(nscoord aAppUnits) {
640 return mozilla::RoundUpToMultiple(aAppUnits,
641 mozilla::AppUnitsPerCSSPixel());
643 static nscoord RoundAppUnitsToCSSPixel(nscoord aAppUnits) {
644 return mozilla::RoundToMultiple(aAppUnits, mozilla::AppUnitsPerCSSPixel());
647 nscoord RoundDownAppUnitsToDevPixel(nscoord aAppUnits) const {
648 return mozilla::RoundDownToMultiple(aAppUnits, AppUnitsPerDevPixel());
650 nscoord RoundUpAppUnitsToDevPixel(nscoord aAppUnits) const {
651 return mozilla::RoundUpToMultiple(aAppUnits, AppUnitsPerDevPixel());
653 nscoord RoundAppUnitsToDevPixel(nscoord aAppUnits) const {
654 return mozilla::RoundToMultiple(aAppUnits, AppUnitsPerDevPixel());
657 mozilla::CSSIntPoint DevPixelsToIntCSSPixels(
658 const mozilla::LayoutDeviceIntPoint& aPoint) {
659 return mozilla::CSSIntPoint(
660 AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPoint.x)),
661 AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPoint.y)));
664 float DevPixelsToFloatCSSPixels(int32_t aPixels) const {
665 return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels));
668 mozilla::CSSToLayoutDeviceScale CSSToDevPixelScale() const {
669 return mozilla::CSSToLayoutDeviceScale(
670 float(mozilla::AppUnitsPerCSSPixel()) / float(AppUnitsPerDevPixel()));
673 // If there is a remainder, it is rounded to nearest app units.
674 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
676 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
678 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const {
679 return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
680 AppUnitsToGfxUnits(aAppRect.y),
681 AppUnitsToGfxUnits(aAppRect.Width()),
682 AppUnitsToGfxUnits(aAppRect.Height()));
685 static nscoord CSSTwipsToAppUnits(float aTwips) {
686 return NSToCoordRoundWithClamp(mozilla::AppUnitsPerCSSInch() *
687 NS_TWIPS_TO_INCHES(aTwips));
690 // Margin-specific version, since they often need TwipsToAppUnits
691 static nsMargin CSSTwipsToAppUnits(const nsIntMargin& marginInTwips) {
692 return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
693 CSSTwipsToAppUnits(float(marginInTwips.right)),
694 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
695 CSSTwipsToAppUnits(float(marginInTwips.left)));
698 static nscoord CSSPointsToAppUnits(float aPoints) {
699 return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
700 POINTS_PER_INCH_FLOAT);
703 nscoord PhysicalMillimetersToAppUnits(float aMM) const;
705 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const {
706 return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits));
710 * This checks the root element and the HTML BODY, if any, for an "overflow"
711 * property that should be applied to the viewport. If one is found then we
712 * return the element that we took the overflow from (which should then be
713 * treated as "overflow: visible"), and we store the overflow style here.
714 * If the document is in fullscreen, and the fullscreen element is not the
715 * root, the scrollbar of viewport will be suppressed.
716 * @return if scroll was propagated from some content node, the content node
717 * it was propagated from.
719 mozilla::dom::Element* UpdateViewportScrollStylesOverride();
722 * Returns the cached result from the last call to
723 * UpdateViewportScrollStylesOverride() -- i.e. return the node
724 * whose scrollbar styles we have propagated to the viewport (or nullptr if
725 * there is no such node).
727 mozilla::dom::Element* GetViewportScrollStylesOverrideElement() const {
728 return mViewportScrollOverrideElement;
731 const ScrollStyles& GetViewportScrollStylesOverride() const {
732 return mViewportScrollStyles;
736 * Check whether the given element would propagate its scrollbar styles to the
737 * viewport in non-paginated mode.
739 bool ElementWouldPropagateScrollStyles(const mozilla::dom::Element&);
742 * Methods for controlling the background drawing.
744 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
745 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
748 * Check if bidi enabled (set depending on the presence of RTL
749 * characters or when default directionality is RTL).
750 * If enabled, we should apply the Unicode Bidi Algorithm
752 * @lina 07/12/2000
754 bool BidiEnabled() const;
757 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
759 * @lina 07/12/2000
761 void SetBidiEnabled() const;
764 * Set visual or implicit mode into the pres context.
766 * Visual directionality is a presentation method that displays text
767 * as if it were a uni-directional, according to the primary display
768 * direction only.
770 * Implicit directionality is a presentation method in which the
771 * direction is determined by the Bidi algorithm according to the
772 * category of the characters and the category of the adjacent
773 * characters, and according to their primary direction.
775 * @lina 05/02/2000
777 void SetVisualMode(bool aIsVisual) { mIsVisual = aIsVisual; }
780 * Check whether the content should be treated as visual.
782 * @lina 05/02/2000
784 bool IsVisualMode() const { return mIsVisual; }
786 enum class InteractionType : uint32_t {
787 ClickInteraction,
788 KeyInteraction,
789 MouseMoveInteraction,
790 ScrollInteraction
793 void RecordInteractionTime(InteractionType aType,
794 const mozilla::TimeStamp& aTimeStamp);
796 void DisableInteractionTimeRecording() { mInteractionTimeEnabled = false; }
798 // Mohamed
801 * Set the Bidi options for the presentation context
803 void SetBidi(uint32_t aBidiOptions);
806 * Get the Bidi options for the presentation context
807 * Not inline so consumers of nsPresContext are not forced to
808 * include Document.
810 uint32_t GetBidi() const;
812 nsITheme* Theme() const MOZ_NONNULL_RETURN;
814 void RecomputeTheme();
816 bool UseOverlayScrollbars() const;
819 * Notify the pres context that the theme has changed. An internal switch
820 * means it's one of our Mozilla themes that changed (e.g., Modern to
821 * Classic). Otherwise, the OS is telling us that the native theme for the
822 * platform has changed.
824 void ThemeChanged(mozilla::widget::ThemeChangeKind);
827 * Notify the pres context that the resolution of the user interface has
828 * changed. This happens if a window is moved between HiDPI and non-HiDPI
829 * displays, so that the ratio of points to device pixels changes.
830 * The notification happens asynchronously.
832 void UIResolutionChanged();
835 * Like UIResolutionChanged() but invalidates values immediately.
837 void UIResolutionChangedSync();
839 /** Printing methods below should only be used for Medium() == print **/
840 void SetPrintSettings(nsIPrintSettings* aPrintSettings);
842 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
844 /* Helper function that ensures that this prescontext is shown in its
845 docshell if it's the most recent prescontext for the docshell. Returns
846 whether the prescontext is now being shown.
848 bool EnsureVisible();
850 #ifdef MOZ_REFLOW_PERF
851 void CountReflows(const char* aName, nsIFrame* aFrame);
852 #endif
854 void ConstructedFrame() { ++mFramesConstructed; }
855 void ReflowedFrame() { ++mFramesReflowed; }
856 void TriggeredAnimationRestyle() { ++mAnimationTriggeredRestyles; }
858 uint64_t FramesConstructedCount() const { return mFramesConstructed; }
859 uint64_t FramesReflowedCount() const { return mFramesReflowed; }
860 uint64_t AnimationTriggeredRestylesCount() const {
861 return mAnimationTriggeredRestyles;
864 static nscoord GetBorderWidthForKeyword(unsigned int aBorderWidthKeyword) {
865 // This table maps border-width enums 'thin', 'medium', 'thick'
866 // to actual nscoord values.
867 static const nscoord kBorderWidths[] = {
868 CSSPixelsToAppUnits(1), CSSPixelsToAppUnits(3), CSSPixelsToAppUnits(5)};
869 MOZ_ASSERT(size_t(aBorderWidthKeyword) <
870 mozilla::ArrayLength(kBorderWidths));
872 return kBorderWidths[aBorderWidthKeyword];
875 gfxTextPerfMetrics* GetTextPerfMetrics() { return mTextPerf.get(); }
877 bool IsDynamic() const {
878 return mType == eContext_PageLayout || mType == eContext_Galley;
880 bool IsScreen() const {
881 return mMedium == nsGkAtoms::screen || mType == eContext_PageLayout ||
882 mType == eContext_PrintPreview;
884 bool IsPrintingOrPrintPreview() const {
885 return mType == eContext_Print || mType == eContext_PrintPreview;
888 bool IsPrintPreview() const { return mType == eContext_PrintPreview; }
890 // Is this presentation in a chrome docshell?
891 bool IsChrome() const;
893 gfxUserFontSet* GetUserFontSet();
895 // Should be called whenever the set of fonts available in the user
896 // font set changes (e.g., because a new font loads, or because the
897 // user font set is changed and fonts become unavailable).
898 void UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont = nullptr);
900 gfxMissingFontRecorder* MissingFontRecorder() { return mMissingFonts.get(); }
902 void NotifyMissingFonts();
904 void FlushCounterStyles();
905 void MarkCounterStylesDirty();
907 void FlushFontFeatureValues();
908 void MarkFontFeatureValuesDirty() { mFontFeatureValuesDirty = true; }
910 void FlushFontPaletteValues();
911 void MarkFontPaletteValuesDirty() { mFontPaletteValuesDirty = true; }
913 mozilla::gfx::PaletteCache& FontPaletteCache();
915 // Ensure that it is safe to hand out CSS rules outside the layout
916 // engine by ensuring that all CSS style sheets have unique inners
917 // and, if necessary, synchronously rebuilding all style data.
918 void EnsureSafeToHandOutCSSRules();
920 // Mark an area as invalidated, associated with a given transaction id
921 // (allocated by nsRefreshDriver::GetTransactionId). Invalidated regions will
922 // be dispatched to MozAfterPaint events when NotifyDidPaintForSubtree is
923 // called for the transaction id (or any higher id).
924 void NotifyInvalidation(TransactionId aTransactionId, const nsRect& aRect);
925 // aRect is in device pixels
926 void NotifyInvalidation(TransactionId aTransactionId, const nsIntRect& aRect);
927 void NotifyDidPaintForSubtree(
928 TransactionId aTransactionId = TransactionId{0},
929 const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp());
930 void NotifyRevokingDidPaint(TransactionId aTransactionId);
931 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
932 MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireDOMPaintEvent(
933 nsTArray<nsRect>* aList, TransactionId aTransactionId,
934 mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());
936 bool IsDOMPaintEventPending();
939 * Returns the RestyleManager's restyle generation counter.
941 uint64_t GetRestyleGeneration() const;
942 uint64_t GetUndisplayedRestyleGeneration() const;
945 * Returns whether there are any pending restyles or reflows.
947 bool HasPendingRestyleOrReflow();
950 * Notify the prescontext that the presshell is about to reflow a reflow root.
951 * The single argument indicates whether this reflow should be interruptible.
952 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
953 * will always return false. If aInterruptible is true then CheckForInterrupt
954 * will return true when a pending event is detected. This is for use by the
955 * presshell only. Reflow code wanting to prevent interrupts should use
956 * InterruptPreventer.
958 void ReflowStarted(bool aInterruptible);
961 * A class that can be used to temporarily disable reflow interruption.
963 class InterruptPreventer;
964 friend class InterruptPreventer;
965 class MOZ_STACK_CLASS InterruptPreventer {
966 public:
967 explicit InterruptPreventer(nsPresContext* aCtx)
968 : mCtx(aCtx),
969 mInterruptsEnabled(aCtx->mInterruptsEnabled),
970 mHasPendingInterrupt(aCtx->mHasPendingInterrupt) {
971 mCtx->mInterruptsEnabled = false;
972 mCtx->mHasPendingInterrupt = false;
974 ~InterruptPreventer() {
975 mCtx->mInterruptsEnabled = mInterruptsEnabled;
976 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
979 private:
980 nsPresContext* mCtx;
981 bool mInterruptsEnabled;
982 bool mHasPendingInterrupt;
986 * Check for interrupts. This may return true if a pending event is
987 * detected. Once it has returned true, it will keep returning true
988 * until ReflowStarted is called. In all cases where this returns true,
989 * the passed-in frame (which should be the frame whose reflow will be
990 * interrupted if true is returned) will be passed to
991 * PresShell::FrameNeedsToContinueReflow.
993 bool CheckForInterrupt(nsIFrame* aFrame);
995 * Returns true if CheckForInterrupt has returned true since the last
996 * ReflowStarted call. Cannot itself trigger an interrupt check.
998 bool HasPendingInterrupt() { return mHasPendingInterrupt; }
1000 * Sets a flag that will trip a reflow interrupt. This only bypasses the
1001 * interrupt timeout and the pending event check; other checks such as whether
1002 * interrupts are enabled and the interrupt check skipping still take effect.
1004 void SetPendingInterruptFromTest() { mPendingInterruptFromTest = true; }
1007 * If we have a presshell, and if the given content's current
1008 * document is the same as our presshell's document, return the
1009 * content's primary frame. Otherwise, return null. Only use this
1010 * if you care about which presshell the primary frame is in.
1012 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
1014 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1015 virtual size_t SizeOfIncludingThis(
1016 mozilla::MallocSizeOf aMallocSizeOf) const {
1017 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
1021 * We are a root content document in process if: we are not a resource doc, we
1022 * are not chrome, and we either have no parent in the current process or our
1023 * parent is chrome.
1025 bool IsRootContentDocumentInProcess() const;
1028 * We are a root content document cross process if: we are not a resource doc,
1029 * we are not chrome, and we either have no parent in any process or our
1030 * parent is chrome.
1032 bool IsRootContentDocumentCrossProcess() const;
1034 bool HadNonBlankPaint() const { return mHadNonBlankPaint; }
1035 bool HadFirstContentfulPaint() const { return mHadFirstContentfulPaint; }
1036 bool HasStoppedGeneratingLCP() const;
1037 void NotifyNonBlankPaint();
1038 void NotifyContentfulPaint();
1039 void NotifyPaintStatusReset();
1040 void NotifyDOMContentFlushed();
1042 bool HasEverBuiltInvisibleText() const { return mHasEverBuiltInvisibleText; }
1043 void SetBuiltInvisibleText() { mHasEverBuiltInvisibleText = true; }
1045 bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
1046 return mHasWarnedAboutTooLargeDashedOrDottedRadius;
1049 void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
1050 mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
1053 void RegisterContainerQueryFrame(nsIFrame* aFrame);
1054 void UnregisterContainerQueryFrame(nsIFrame* aFrame);
1055 bool HasContainerQueryFrames() const {
1056 return !mContainerQueryFrames.IsEmpty();
1059 void FinishedContainerQueryUpdate();
1061 bool UpdateContainerQueryStyles();
1063 mozilla::intl::Bidi& BidiEngine();
1065 gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const {
1066 return mFontFeatureValuesLookup;
1069 mozilla::gfx::FontPaletteValueSet* GetFontPaletteValueSet() const {
1070 return mFontPaletteValueSet;
1073 bool NeedsToUpdateHiddenByContentVisibilityForAnimations() const {
1074 return mNeedsToUpdateHiddenByContentVisibilityForAnimations;
1076 void SetNeedsToUpdateHiddenByContentVisibilityForAnimations() {
1077 mNeedsToUpdateHiddenByContentVisibilityForAnimations = true;
1079 void UpdateHiddenByContentVisibilityForAnimationsIfNeeded() {
1080 if (mNeedsToUpdateHiddenByContentVisibilityForAnimations) {
1081 DoUpdateHiddenByContentVisibilityForAnimations();
1085 protected:
1086 void DoUpdateHiddenByContentVisibilityForAnimations();
1087 friend class nsRunnableMethod<nsPresContext>;
1088 void ThemeChangedInternal();
1089 void RefreshSystemMetrics();
1091 // Update device context's resolution from the widget
1092 void UIResolutionChangedInternal();
1094 void SetImgAnimations(nsIContent* aParent, uint16_t aMode);
1095 void SetSMILAnimations(mozilla::dom::Document* aDoc, uint16_t aNewMode,
1096 uint16_t aOldMode);
1098 static void PreferenceChanged(const char* aPrefName, void* aSelf);
1099 void PreferenceChanged(const char* aPrefName);
1101 void GetUserPreferences();
1103 void UpdateCharSet(NotNull<const Encoding*> aCharSet);
1105 void DoForceReflowForFontInfoUpdateFromStyle();
1107 public:
1108 // Used by the PresShell to force a reflow when some aspect of font info
1109 // has been updated, potentially affecting font selection and layout.
1110 void ForceReflowForFontInfoUpdate(bool aNeedsReframe);
1111 void ForceReflowForFontInfoUpdateFromStyle();
1114 * Checks for MozAfterPaint listeners on the document
1116 bool MayHavePaintEventListener();
1118 void InvalidatePaintedLayers();
1120 uint32_t GetNextFrameRateMultiplier() const {
1121 return mNextFrameRateMultiplier;
1124 void DidUseFrameRateMultiplier() {
1125 // This heuristic is used to reduce frame rate between fcp and the end of
1126 // the page load.
1127 if (mNextFrameRateMultiplier < 8) {
1128 ++mNextFrameRateMultiplier;
1132 mozilla::TimeStamp GetMarkPaintTimingStart() const {
1133 return mMarkPaintTimingStart;
1136 protected:
1137 // May be called multiple times (unlink, destructor)
1138 void Destroy();
1140 void AppUnitsPerDevPixelChanged();
1142 bool HavePendingInputEvent();
1144 // Creates a one-shot timer with the given aCallback & aDelay.
1145 // Returns a refcounted pointer to the timer (or nullptr on failure).
1146 already_AddRefed<nsITimer> CreateTimer(nsTimerCallbackFunc aCallback,
1147 const char* aName, uint32_t aDelay);
1149 struct TransactionInvalidations {
1150 TransactionId mTransactionId;
1151 nsTArray<nsRect> mInvalidations;
1152 bool mIsWaitingForPreviousTransaction = false;
1154 TransactionInvalidations* GetInvalidations(TransactionId aTransactionId);
1156 // This should be called only when we update mVisibleArea or
1157 // mDynamicToolbarMaxHeight or `app units per device pixels` changes.
1158 void AdjustSizeForViewportUnits();
1160 // Call in response to prefs changes that might affect what fonts should be
1161 // visibile to CSS. Returns whether the current visibility value actually
1162 // changed (in which case content should be reflowed).
1163 bool UpdateFontVisibility();
1164 void ReportBlockedFontFamilyName(const nsCString& aFamily,
1165 FontVisibility aVisibility);
1167 // IMPORTANT: The ownership implicit in the following member variables
1168 // has been explicitly checked. If you add any members to this class,
1169 // please make the ownership explicit (pinkerton, scc).
1171 // the PresShell owns a strong reference to the nsPresContext, and is
1172 // responsible for nulling this pointer before it is destroyed
1173 mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell; // [WEAK]
1174 RefPtr<mozilla::dom::Document> mDocument;
1175 RefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1176 // better safe than sorry.
1177 // Cannot reintroduce cycles
1178 // since there is no dependency
1179 // from gfx back to layout.
1180 RefPtr<nsFontCache> mFontCache;
1181 RefPtr<mozilla::EventStateManager> mEventManager;
1182 RefPtr<nsRefreshDriver> mRefreshDriver;
1183 RefPtr<mozilla::AnimationEventDispatcher> mAnimationEventDispatcher;
1184 RefPtr<mozilla::EffectCompositor> mEffectCompositor;
1185 mozilla::UniquePtr<nsTransitionManager> mTransitionManager;
1186 mozilla::UniquePtr<nsAnimationManager> mAnimationManager;
1187 mozilla::UniquePtr<mozilla::TimelineManager> mTimelineManager;
1188 mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager;
1189 RefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
1190 const nsStaticAtom* mMedium;
1191 RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup;
1192 RefPtr<mozilla::gfx::FontPaletteValueSet> mFontPaletteValueSet;
1194 mozilla::UniquePtr<mozilla::gfx::PaletteCache> mFontPaletteCache;
1196 // TODO(emilio): Maybe lazily create and put under a UniquePtr if this grows a
1197 // lot?
1198 MediaEmulationData mMediaEmulationData;
1200 float mTextZoom; // Text zoom, defaults to 1.0
1201 float mFullZoom; // Page zoom, defaults to 1.0
1202 gfxSize mLastFontInflationScreenSize;
1204 int32_t mCurAppUnitsPerDevPixel;
1205 int32_t mAutoQualityMinFontSizePixelsPref;
1207 nsCOMPtr<nsITheme> mTheme;
1208 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1210 mozilla::UniquePtr<mozilla::intl::Bidi> mBidiEngine;
1212 AutoTArray<TransactionInvalidations, 4> mTransactions;
1214 // text performance metrics
1215 mozilla::UniquePtr<gfxTextPerfMetrics> mTextPerf;
1217 mozilla::UniquePtr<gfxMissingFontRecorder> mMissingFonts;
1219 nsRect mVisibleArea;
1220 // This value is used to resolve viewport units.
1221 // On mobile this size is including the dynamic toolbar maximum height below.
1222 // On desktops this size is pretty much the same as |mVisibleArea|.
1223 nsSize mSizeForViewportUnits;
1224 // The maximum height of the dynamic toolbar on mobile.
1225 mozilla::ScreenIntCoord mDynamicToolbarMaxHeight;
1226 mozilla::ScreenIntCoord mDynamicToolbarHeight;
1227 // Safe area insets support
1228 mozilla::ScreenIntMargin mSafeAreaInsets;
1229 nsSize mPageSize;
1231 // The computed page margins from the print settings.
1233 // This margin will be used for each page in the current print operation, by
1234 // default (i.e. unless overridden by @page rules).
1236 // FIXME(emilio): Maybe we could let a global @page rule do that, though it's
1237 // sketchy at best, see https://github.com/w3c/csswg-drafts/issues/5437 for
1238 // discussion.
1239 nsMargin mDefaultPageMargin;
1240 float mPageScale;
1241 float mPPScale;
1243 // This is a non-owning pointer. May be null. If non-null, it's guaranteed to
1244 // be pointing to an element that's still alive, because we'll reset it in
1245 // UpdateViewportScrollStylesOverride() as part of the cleanup code when
1246 // this element is removed from the document. (For <body> and the root
1247 // element, this call happens in nsCSSFrameConstructor::ContentRemoved(). For
1248 // fullscreen elements, it happens in the fullscreen-specific cleanup invoked
1249 // by Element::UnbindFromTree().)
1250 mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollOverrideElement;
1252 // Counters for tests and tools that want to detect frame construction
1253 // or reflow.
1254 uint64_t mElementsRestyled;
1255 uint64_t mFramesConstructed;
1256 uint64_t mFramesReflowed;
1257 uint64_t mAnimationTriggeredRestyles;
1259 mozilla::TimeStamp mReflowStartTime;
1261 // Defined in https://w3c.github.io/paint-timing/#mark-paint-timing step 2.
1262 mozilla::TimeStamp mMarkPaintTimingStart;
1264 Maybe<TransactionId> mFirstContentfulPaintTransactionId;
1266 mozilla::UniquePtr<mozilla::MediaFeatureChange>
1267 mPendingMediaFeatureValuesChange;
1269 // Time of various first interaction types, used to report time from
1270 // first paint of the top level content pres shell to first interaction.
1271 mozilla::TimeStamp mFirstNonBlankPaintTime;
1272 mozilla::TimeStamp mFirstClickTime;
1273 mozilla::TimeStamp mFirstKeyTime;
1274 mozilla::TimeStamp mFirstMouseMoveTime;
1275 mozilla::TimeStamp mFirstScrollTime;
1277 // last time we did a full style flush
1278 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1280 uint32_t mInterruptChecksToSkip;
1282 // During page load we use slower frame rate.
1283 uint32_t mNextFrameRateMultiplier;
1285 uint32_t mMeasuredTicksSinceLoading;
1287 nsTArray<RefPtr<mozilla::ManagedPostRefreshObserver>>
1288 mManagedPostRefreshObservers;
1290 // If we block the use of a font-family that is explicitly requested,
1291 // due to font visibility settings, we log a message to the web console;
1292 // this hash-set keeps track of names we've logged for this context, so
1293 // that we can avoid repeatedly reporting the same font.
1294 nsTHashSet<nsCString> mBlockedFonts;
1296 // The set of container query boxes currently in the document, sorted by
1297 // depth.
1298 mozilla::DepthOrderedFrameList mContainerQueryFrames;
1299 // The set of container query elements currently in the document that have
1300 // been updated so far. This is necessary to avoid reentering on container
1301 // query style changes which cause us to do frame reconstruction.
1302 nsTHashSet<nsIContent*> mUpdatedContainerQueryContents;
1304 ScrollStyles mViewportScrollStyles;
1306 uint16_t mImageAnimationMode;
1307 uint16_t mImageAnimationModePref;
1309 nsPresContextType mType;
1311 public:
1312 // The following are public member variables so that we can use them
1313 // with mozilla::AutoToggle or mozilla::AutoRestore.
1315 // Should we disable font size inflation because we're inside of
1316 // shrink-wrapping calculations on an inflation container?
1317 bool mInflationDisabledForShrinkWrap;
1319 protected:
1320 static constexpr size_t kThemeChangeKindBits = 2;
1321 static_assert(unsigned(mozilla::widget::ThemeChangeKind::AllBits) <=
1322 (1u << kThemeChangeKindBits) - 1,
1323 "theme change kind doesn't fit");
1325 unsigned mInteractionTimeEnabled : 1;
1326 unsigned mHasPendingInterrupt : 1;
1327 unsigned mHasEverBuiltInvisibleText : 1;
1328 unsigned mPendingInterruptFromTest : 1;
1329 unsigned mInterruptsEnabled : 1;
1330 unsigned mDrawImageBackground : 1;
1331 unsigned mDrawColorBackground : 1;
1332 unsigned mNeverAnimate : 1;
1333 unsigned mPaginated : 1;
1334 unsigned mCanPaginatedScroll : 1;
1335 unsigned mDoScaledTwips : 1;
1336 unsigned mIsRootPaginatedDocument : 1;
1337 unsigned mPendingThemeChanged : 1;
1338 // widget::ThemeChangeKind
1339 unsigned mPendingThemeChangeKind : kThemeChangeKindBits;
1340 unsigned mPendingUIResolutionChanged : 1;
1341 unsigned mPendingFontInfoUpdateReflowFromStyle : 1;
1343 // Are we currently drawing an SVG glyph?
1344 unsigned mIsGlyph : 1;
1346 // Is the current mCounterStyleManager valid?
1347 unsigned mCounterStylesDirty : 1;
1349 // Is the current mFontFeatureValuesLookup valid?
1350 unsigned mFontFeatureValuesDirty : 1;
1352 // Is the current mFontFeatureValueSet valid?
1353 unsigned mFontPaletteValuesDirty : 1;
1355 unsigned mIsVisual : 1;
1357 // Are we in the RDM pane?
1358 unsigned mInRDMPane : 1;
1360 unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;
1362 // Have we added quirk.css to the style set?
1363 unsigned mQuirkSheetAdded : 1;
1365 // Has NotifyNonBlankPaint been called on this PresContext?
1366 unsigned mHadNonBlankPaint : 1;
1367 // Has NotifyContentfulPaint been called on this PresContext?
1368 unsigned mHadFirstContentfulPaint : 1;
1369 // True when a contentful paint has happened and this paint doesn't
1370 // come from the regular tick process. Usually this means a
1371 // contentful paint was triggered manually.
1372 unsigned mHadNonTickContentfulPaint : 1;
1374 // Has NotifyDidPaintForSubtree been called for a contentful paint?
1375 unsigned mHadContentfulPaintComposite : 1;
1377 // Whether we might need to update c-v state for animations.
1378 unsigned mNeedsToUpdateHiddenByContentVisibilityForAnimations : 1;
1380 unsigned mUserInputEventsAllowed : 1;
1381 #ifdef DEBUG
1382 unsigned mInitialized : 1;
1383 #endif
1385 // FIXME(emilio): These would be better packed on top of the bitfields, but
1386 // that breaks bindgen in win32.
1387 FontVisibility mFontVisibility = FontVisibility::Unknown;
1388 mozilla::dom::PrefersColorSchemeOverride mOverriddenOrEmbedderColorScheme;
1390 protected:
1391 virtual ~nsPresContext();
1393 void LastRelease();
1395 void EnsureTheme();
1397 #ifdef DEBUG
1398 private:
1399 friend struct nsAutoLayoutPhase;
1400 mozilla::EnumeratedArray<nsLayoutPhase, uint32_t,
1401 size_t(nsLayoutPhase::COUNT)>
1402 mLayoutPhaseCount;
1404 public:
1405 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1406 return mLayoutPhaseCount[aPhase];
1408 #endif
1411 class nsRootPresContext final : public nsPresContext {
1412 public:
1413 nsRootPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
1414 virtual bool IsRoot() const override { return true; }
1417 * Add a runnable that will get called before the next paint. They will get
1418 * run eventually even if painting doesn't happen. They might run well before
1419 * painting happens.
1421 void AddWillPaintObserver(nsIRunnable* aRunnable);
1424 * Run all runnables that need to get called before the next paint.
1426 void FlushWillPaintObservers();
1428 virtual size_t SizeOfExcludingThis(
1429 mozilla::MallocSizeOf aMallocSizeOf) const override;
1431 protected:
1432 class RunWillPaintObservers : public mozilla::Runnable {
1433 public:
1434 explicit RunWillPaintObservers(nsRootPresContext* aPresContext)
1435 : Runnable("nsPresContextType::RunWillPaintObservers"),
1436 mPresContext(aPresContext) {}
1437 void Revoke() { mPresContext = nullptr; }
1438 NS_IMETHOD Run() override {
1439 if (mPresContext) {
1440 mPresContext->FlushWillPaintObservers();
1442 return NS_OK;
1444 // The lifetime of this reference is handled by an nsRevocableEventPtr
1445 nsRootPresContext* MOZ_NON_OWNING_REF mPresContext;
1448 friend class nsPresContext;
1450 nsTArray<nsCOMPtr<nsIRunnable>> mWillPaintObservers;
1451 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1454 #ifdef MOZ_REFLOW_PERF
1456 # define DO_GLOBAL_REFLOW_COUNT(_name) \
1457 aPresContext->CountReflows((_name), (nsIFrame*)this);
1458 #else
1459 # define DO_GLOBAL_REFLOW_COUNT(_name)
1460 #endif // MOZ_REFLOW_PERF
1462 #endif /* nsPresContext_h___ */