Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / layout / base / nsPresContext.h
blobcb3a1a4c2b8b751f3ed23569853157ab012b5dab
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 enum class StyleForcedColors : uint8_t;
89 namespace layers {
90 class ContainerLayer;
91 class LayerManager;
92 } // namespace layers
93 namespace dom {
94 class Document;
95 class Element;
96 class PerformanceMainThread;
97 enum class PrefersColorSchemeOverride : uint8_t;
98 } // namespace dom
99 namespace gfx {
100 class FontPaletteValueSet;
101 class PaletteCache;
102 } // namespace gfx
103 } // namespace mozilla
105 // IDs for the default variable and fixed fonts (not to be changed, see
106 // nsFont.h) To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are
107 // also supported.
109 // kGenericFont_moz_variable
110 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00;
111 // kGenericFont_moz_fixed
112 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01;
114 #ifdef DEBUG
115 struct nsAutoLayoutPhase;
117 enum class nsLayoutPhase : uint8_t {
118 Paint,
119 DisplayListBuilding, // sometimes a subset of the paint phase
120 Reflow,
121 FrameC,
122 COUNT
124 #endif
126 class nsRootPresContext;
128 // An interface for presentation contexts. Presentation contexts are
129 // objects that provide an outer context for a presentation shell.
131 class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
132 public:
133 using Encoding = mozilla::Encoding;
134 template <typename T>
135 using NotNull = mozilla::NotNull<T>;
136 template <typename T>
137 using Maybe = mozilla::Maybe<T>;
138 using MediaEmulationData = mozilla::MediaEmulationData;
140 typedef mozilla::ScrollStyles ScrollStyles;
141 using TransactionId = mozilla::layers::TransactionId;
143 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
144 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
146 enum nsPresContextType : uint8_t {
147 eContext_Galley, // unpaginated screen presentation
148 eContext_PrintPreview, // paginated screen presentation
149 eContext_Print, // paginated printer presentation
150 eContext_PageLayout // paginated & editable.
153 nsPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
156 * Initialize the presentation context from a particular device.
158 nsresult Init(nsDeviceContext* aDeviceContext);
161 * Initialize the font cache if it hasn't been initialized yet.
162 * (Needed for stylo)
164 void InitFontCache();
166 void UpdateFontCacheUserFonts(gfxUserFontSet* aUserFontSet);
169 * Return the font visibility level to be applied to this context,
170 * potentially blocking user-installed or non-standard fonts from being
171 * used by web content.
172 * Note that depending on ResistFingerprinting options, the caller may
173 * override this value when resolving CSS <generic-family> keywords.
175 FontVisibility GetFontVisibility() const { return mFontVisibility; }
178 * Log a message to the console about a font request being blocked.
180 void ReportBlockedFontFamily(const mozilla::fontlist::Family& aFamily);
181 void ReportBlockedFontFamily(const gfxFontFamily& aFamily);
184 * Get the nsFontMetrics that describe the properties of
185 * an nsFont.
186 * @param aFont font description to obtain metrics for
188 already_AddRefed<nsFontMetrics> GetMetricsFor(
189 const nsFont& aFont, const nsFontMetrics::Params& aParams);
192 * Notification when a font metrics instance created for this context is
193 * about to be deleted
195 nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
198 * Attempt to free up resources by flushing out any fonts no longer
199 * referenced by anything other than the font cache itself.
200 * @return error status
202 nsresult FlushFontCache();
205 * Set and detach presentation shell that this context is bound to.
206 * A presentation context may only be bound to a single shell.
208 void AttachPresShell(mozilla::PresShell* aPresShell);
209 void DetachPresShell();
211 nsPresContextType Type() const { return mType; }
214 * Get the PresentationShell that this context is bound to.
216 mozilla::PresShell* PresShell() const {
217 NS_ASSERTION(mPresShell, "Null pres shell");
218 return mPresShell;
221 mozilla::PresShell* GetPresShell() const { return mPresShell; }
223 void DocumentCharSetChanged(NotNull<const Encoding*> aCharSet);
225 mozilla::dom::PerformanceMainThread* GetPerformanceMainThread() const;
227 * Returns the parent prescontext for this one. Returns null if this is a
228 * root.
230 nsPresContext* GetParentPresContext() const;
233 * Returns the prescontext of the root content document in the same process
234 * that contains this presentation, or null if there isn't one.
236 nsPresContext* GetInProcessRootContentDocumentPresContext();
239 * Returns the nearest widget for the root frame or view of this.
241 * @param aOffset If non-null the offset from the origin of the root
242 * frame's view to the widget's origin (usually positive)
243 * expressed in appunits of this will be returned in
244 * aOffset.
246 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
249 * Returns the root widget for this.
251 nsIWidget* GetRootWidget() const;
254 * Returns the widget which may have native focus and handles text input
255 * like keyboard input, IME, etc.
257 nsIWidget* GetTextInputHandlingWidget() const {
258 // Currently, root widget for each PresContext handles text input.
259 return GetRootWidget();
263 * Return the presentation context for the root of the view manager
264 * hierarchy that contains this presentation context, or nullptr if it can't
265 * be found (e.g. it's detached).
267 nsRootPresContext* GetRootPresContext() const;
269 virtual bool IsRoot() const { return false; }
271 mozilla::dom::Document* Document() const {
272 #ifdef DEBUG
273 ValidatePresShellAndDocumentReleation();
274 #endif // #ifdef DEBUG
275 return mDocument;
278 inline mozilla::ServoStyleSet* StyleSet() const;
280 bool HasPendingMediaQueryUpdates() const {
281 return !!mPendingMediaFeatureValuesChange;
284 inline nsCSSFrameConstructor* FrameConstructor() const;
286 mozilla::AnimationEventDispatcher* AnimationEventDispatcher() {
287 return mAnimationEventDispatcher;
290 mozilla::EffectCompositor* EffectCompositor() { return mEffectCompositor; }
291 nsTransitionManager* TransitionManager() { return mTransitionManager.get(); }
292 nsAnimationManager* AnimationManager() { return mAnimationManager.get(); }
293 const nsAnimationManager* AnimationManager() const {
294 return mAnimationManager.get();
296 mozilla::TimelineManager* TimelineManager() { return mTimelineManager.get(); }
298 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
300 mozilla::RestyleManager* RestyleManager() {
301 MOZ_ASSERT(mRestyleManager);
302 return mRestyleManager.get();
305 mozilla::CounterStyleManager* CounterStyleManager() const {
306 return mCounterStyleManager;
310 * Rebuilds all style data by throwing out the old rule tree and
311 * building a new one, and additionally applying a change hint (which must not
312 * contain nsChangeHint_ReconstructFrame) to the root frame.
314 * For the restyle hint argument, see RestyleManager::RebuildAllStyleData.
315 * Also rebuild the user font set and counter style manager.
317 * FIXME(emilio): The name of this is an utter lie. We should probably call
318 * this PostGlobalStyleChange or something, as it doesn't really rebuild
319 * anything unless you tell it to via the change hint / restyle hint
320 * machinery.
322 void RebuildAllStyleData(nsChangeHint, const mozilla::RestyleHint&);
324 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
325 * doesn't rebuild the user font set / counter-style manager / etc.
327 void PostRebuildAllStyleDataEvent(nsChangeHint, const mozilla::RestyleHint&);
329 void ContentLanguageChanged();
331 /** Returns whether any media query changed. */
332 bool FlushPendingMediaFeatureValuesChanged();
335 * Schedule a media feature change for this document, and potentially for
336 * other subdocuments and images (depending on the arguments).
338 void MediaFeatureValuesChanged(const mozilla::MediaFeatureChange&,
339 mozilla::MediaFeatureChangePropagation);
342 * Updates the size mode on all remote children and recursively notifies this
343 * document and all subdocuments (including remote children) that a media
344 * feature value has changed.
346 void SizeModeChanged(nsSizeMode aSizeMode);
349 * Access compatibility mode for this context. This is the same as
350 * our document's compatibility mode.
352 nsCompatibility CompatibilityMode() const;
355 * Access the image animation mode for this context
357 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
358 void SetImageAnimationMode(uint16_t aMode);
361 * Get medium of presentation
363 const nsAtom* Medium() const {
364 MOZ_ASSERT(mMedium);
365 return mMediaEmulationData.mMedium ? mMediaEmulationData.mMedium.get()
366 : mMedium;
370 * Render the document as if being viewed on a device with the specified
371 * media type.
373 * If passed null, it stops emulating.
375 void EmulateMedium(nsAtom* aMediaType);
377 const mozilla::PreferenceSheet::Prefs& PrefSheetPrefs() const {
378 return mozilla::PreferenceSheet::PrefsFor(*mDocument);
381 bool ForcingColors() const;
383 mozilla::ColorScheme DefaultBackgroundColorScheme() const;
384 nscolor DefaultBackgroundColor() const;
386 nsISupports* GetContainerWeak() const;
388 nsDocShell* GetDocShell() const;
391 * Get the visible area associated with this presentation context.
392 * This is the size of the visible area that is used for
393 * presenting the document. The returned value is in the standard
394 * nscoord units (as scaled by the device context).
396 nsRect GetVisibleArea() const { return mVisibleArea; }
399 * Set the currently visible area. The units for r are standard
400 * nscoord units (as scaled by the device context).
402 void SetVisibleArea(const nsRect& aRect);
405 * Set the initial visible area. This should be called only from
406 * nsDocumentViewer when initializing this pres context visible area with
407 * the document viewer bounds.
409 void SetInitialVisibleArea(const nsRect& aRect);
411 nsSize GetSizeForViewportUnits() const { return mSizeForViewportUnits; }
414 * Set the maximum height of the dynamic toolbar in nscoord units.
416 MOZ_CAN_RUN_SCRIPT
417 void SetDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight);
420 * Returns true if we are using the dynamic toolbar.
422 bool HasDynamicToolbar() const { return GetDynamicToolbarMaxHeight() > 0; }
425 * |aOffset| must be offset from the bottom edge of the ICB and it's negative.
427 void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
429 mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const {
430 MOZ_ASSERT_IF(mDynamicToolbarMaxHeight > 0,
431 IsRootContentDocumentCrossProcess());
432 return mDynamicToolbarMaxHeight;
435 nscoord GetDynamicToolbarMaxHeightInAppUnits() const;
437 mozilla::ScreenIntCoord GetDynamicToolbarHeight() const {
438 MOZ_ASSERT_IF(mDynamicToolbarHeight > 0,
439 IsRootContentDocumentCrossProcess());
440 return mDynamicToolbarHeight;
443 void UpdateKeyboardHeight(mozilla::ScreenIntCoord aHeight);
445 mozilla::ScreenIntCoord GetKeyboardHeight() const;
448 * Returns true if the software keyboard is hidden or
449 * the document is `interactive-widget=resizes-content` mode.
451 bool IsKeyboardHiddenOrResizesContentMode() const;
454 * Returns the maximum height of the dynamic toolbar if the toolbar state is
455 * `DynamicToolbarState::Collapsed`, otherwise returns zero.
457 nscoord GetBimodalDynamicToolbarHeightInAppUnits() const;
460 * Returns the state of the dynamic toolbar.
462 mozilla::DynamicToolbarState GetDynamicToolbarState() const;
465 * Return true if this presentation context is a paginated
466 * context.
468 bool IsPaginated() const { return mPaginated; }
471 * Sets whether the presentation context can scroll for a paginated
472 * context.
474 void SetPaginatedScrolling(bool aResult);
477 * Return true if this presentation context can scroll for paginated
478 * context.
480 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
483 * Get/set the size of a page
485 const nsSize& GetPageSize() const { return mPageSize; }
486 const nsMargin& GetDefaultPageMargin() const { return mDefaultPageMargin; }
487 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
490 * Get/set whether this document should be treated as having real pages
491 * XXX This raises the obvious question of why a document that isn't a page
492 * is paginated; there isn't a good reason except history
494 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
495 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) {
496 mIsRootPaginatedDocument = aIsRootPaginatedDocument;
500 * Get/set the print scaling level; used by nsPageFrame to scale up
501 * pages. Set safe to call before reflow, get guaranteed to be set
502 * properly after reflow.
505 float GetPageScale() { return mPageScale; }
506 void SetPageScale(float aScale) { mPageScale = aScale; }
509 * Get/set the scaling factor to use when rendering the pages for print
510 * preview. Only safe to get after print preview set up; safe to set anytime.
511 * This is a scaling factor for the display of the print preview. It
512 * does not affect layout. It only affects the size of the onscreen pages
513 * in print preview.
515 * The getter should only be used by the page sequence frame, which is the
516 * frame responsible for applying the scaling. Other callers should use
517 * nsPageSequenceFrame::GetPrintPreviewScale() if needed, instead of this API.
519 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
521 float GetPrintPreviewScaleForSequenceFrameOrScrollbars() const {
522 return mPPScale;
524 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
526 nsDeviceContext* DeviceContext() const { return mDeviceContext; }
527 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
529 bool UserInputEventsAllowed();
531 void MaybeIncreaseMeasuredTicksSinceLoading();
533 bool NeedsMoreTicksForUserInput() const;
535 void ResetUserInputEventsAllowed() {
536 MOZ_ASSERT(IsRoot());
537 mMeasuredTicksSinceLoading = 0;
538 mUserInputEventsAllowed = false;
541 // Get the text zoom factor in use.
542 float TextZoom() const { return mTextZoom; }
545 * Notify the pres context that the safe area insets have changed.
547 void SetSafeAreaInsets(const mozilla::LayoutDeviceIntMargin& aInsets);
549 const mozilla::LayoutDeviceIntMargin& GetSafeAreaInsets() const {
550 return mSafeAreaInsets;
553 void RegisterManagedPostRefreshObserver(mozilla::ManagedPostRefreshObserver*);
554 void UnregisterManagedPostRefreshObserver(
555 mozilla::ManagedPostRefreshObserver*);
557 protected:
558 void CancelManagedPostRefreshObservers();
560 #ifdef DEBUG
561 void ValidatePresShellAndDocumentReleation() const;
562 #endif // #ifdef DEBUG
564 void SetTextZoom(float aZoom);
565 void SetFullZoom(float aZoom);
566 void SetOverrideDPPX(float);
567 void SetInRDMPane(bool aInRDMPane);
568 void UpdateTopInnerSizeForRFP();
569 void UpdateForcedColors(bool aNotify = true);
571 public:
572 float GetFullZoom() { return mFullZoom; }
574 * Device full zoom differs from full zoom because it gets the zoom from
575 * the device context, which may be using a different zoom due to rounding
576 * of app units to device pixels.
578 float GetDeviceFullZoom();
580 float GetOverrideDPPX() const { return mMediaEmulationData.mDPPX; }
582 // Gets the forced color-scheme if any via either our embedder, or DevTools
583 // emulation, or printing.
585 // NOTE(emilio): This might be called from an stylo thread.
586 Maybe<mozilla::ColorScheme> GetOverriddenOrEmbedderColorScheme() const;
589 * Recomputes the data dependent on the browsing context, like zoom and text
590 * zoom.
592 void RecomputeBrowsingContextDependentData();
595 * Sets the effective color scheme override, and invalidate stuff as needed.
597 void SetColorSchemeOverride(mozilla::dom::PrefersColorSchemeOverride);
600 * Return the device's screen size in inches, for font size
601 * inflation.
603 * If |aChanged| is non-null, then aChanged is filled in with whether
604 * the screen size value has changed since either:
605 * a. the last time the function was called with non-null aChanged, or
606 * b. the first time the function was called.
608 gfxSize ScreenSizeInchesForFontInflation(bool* aChanged = nullptr);
610 int32_t AppUnitsPerDevPixel() const { return mCurAppUnitsPerDevPixel; }
612 static nscoord CSSPixelsToAppUnits(int32_t aPixels) {
613 return NSToCoordRoundWithClamp(float(aPixels) *
614 float(mozilla::AppUnitsPerCSSPixel()));
617 static nscoord CSSPixelsToAppUnits(float aPixels) {
618 return NSToCoordRoundWithClamp(aPixels *
619 float(mozilla::AppUnitsPerCSSPixel()));
622 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) {
623 return NSAppUnitsToIntPixels(aAppUnits,
624 float(mozilla::AppUnitsPerCSSPixel()));
627 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) {
628 return NSAppUnitsToFloatPixels(aAppUnits,
629 float(mozilla::AppUnitsPerCSSPixel()));
632 static double AppUnitsToDoubleCSSPixels(nscoord aAppUnits) {
633 return NSAppUnitsToDoublePixels(aAppUnits,
634 double(mozilla::AppUnitsPerCSSPixel()));
637 nscoord DevPixelsToAppUnits(int32_t aPixels) const {
638 return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel());
641 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const {
642 return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerDevPixel()));
645 float AppUnitsToFloatDevPixels(nscoord aAppUnits) {
646 return aAppUnits / float(AppUnitsPerDevPixel());
649 int32_t CSSPixelsToDevPixels(int32_t aPixels) {
650 return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels));
653 float CSSPixelsToDevPixels(float aPixels) {
654 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
655 float(AppUnitsPerDevPixel()));
658 int32_t DevPixelsToIntCSSPixels(int32_t aPixels) {
659 return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels));
662 static nscoord RoundDownAppUnitsToCSSPixel(nscoord aAppUnits) {
663 return mozilla::RoundDownToMultiple(aAppUnits,
664 mozilla::AppUnitsPerCSSPixel());
666 static nscoord RoundUpAppUnitsToCSSPixel(nscoord aAppUnits) {
667 return mozilla::RoundUpToMultiple(aAppUnits,
668 mozilla::AppUnitsPerCSSPixel());
670 static nscoord RoundAppUnitsToCSSPixel(nscoord aAppUnits) {
671 return mozilla::RoundToMultiple(aAppUnits, mozilla::AppUnitsPerCSSPixel());
674 nscoord RoundDownAppUnitsToDevPixel(nscoord aAppUnits) const {
675 return mozilla::RoundDownToMultiple(aAppUnits, AppUnitsPerDevPixel());
677 nscoord RoundUpAppUnitsToDevPixel(nscoord aAppUnits) const {
678 return mozilla::RoundUpToMultiple(aAppUnits, AppUnitsPerDevPixel());
680 nscoord RoundAppUnitsToDevPixel(nscoord aAppUnits) const {
681 return mozilla::RoundToMultiple(aAppUnits, AppUnitsPerDevPixel());
684 mozilla::CSSIntPoint DevPixelsToIntCSSPixels(
685 const mozilla::LayoutDeviceIntPoint& aPoint) {
686 return mozilla::CSSIntPoint(
687 AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPoint.x)),
688 AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPoint.y)));
691 float DevPixelsToFloatCSSPixels(int32_t aPixels) const {
692 return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels));
695 mozilla::CSSToLayoutDeviceScale CSSToDevPixelScale() const {
696 return mozilla::CSSToLayoutDeviceScale(
697 float(mozilla::AppUnitsPerCSSPixel()) / float(AppUnitsPerDevPixel()));
700 // If there is a remainder, it is rounded to nearest app units.
701 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
703 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
705 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const {
706 return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
707 AppUnitsToGfxUnits(aAppRect.y),
708 AppUnitsToGfxUnits(aAppRect.Width()),
709 AppUnitsToGfxUnits(aAppRect.Height()));
712 static nscoord CSSTwipsToAppUnits(float aTwips) {
713 return NSToCoordRoundWithClamp(mozilla::AppUnitsPerCSSInch() *
714 NS_TWIPS_TO_INCHES(aTwips));
717 // Margin-specific version, since they often need TwipsToAppUnits
718 static nsMargin CSSTwipsToAppUnits(const nsIntMargin& marginInTwips) {
719 return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
720 CSSTwipsToAppUnits(float(marginInTwips.right)),
721 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
722 CSSTwipsToAppUnits(float(marginInTwips.left)));
725 static nscoord CSSPointsToAppUnits(float aPoints) {
726 return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
727 POINTS_PER_INCH_FLOAT);
730 nscoord PhysicalMillimetersToAppUnits(float aMM) const;
732 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const {
733 return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits));
737 * This checks the root element and the HTML BODY, if any, for an "overflow"
738 * property that should be applied to the viewport. If one is found then we
739 * return the element that we took the overflow from (which should then be
740 * treated as "overflow: visible"), and we store the overflow style here.
741 * If the document is in fullscreen, and the fullscreen element is not the
742 * root, the scrollbar of viewport will be suppressed.
743 * @param aRemovedChild the element we're about to remove from the DOM, which
744 * we can't make the new override element.
745 * @return if scroll was propagated from some content node, the content node
746 * it was propagated from.
748 mozilla::dom::Element* UpdateViewportScrollStylesOverride(
749 const mozilla::dom::Element* aRemovedChild = nullptr);
752 * Returns the cached result from the last call to
753 * UpdateViewportScrollStylesOverride() -- i.e. return the node
754 * whose scrollbar styles we have propagated to the viewport (or nullptr if
755 * there is no such node).
757 mozilla::dom::Element* GetViewportScrollStylesOverrideElement() const {
758 return mViewportScrollOverrideElement;
761 const ScrollStyles& GetViewportScrollStylesOverride() const {
762 return mViewportScrollStyles;
766 * Check whether the given element would propagate its scrollbar styles to the
767 * viewport in non-paginated mode.
769 bool ElementWouldPropagateScrollStyles(const mozilla::dom::Element&);
772 * Methods for controlling the background drawing.
774 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
775 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
778 * Check if bidi enabled (set depending on the presence of RTL
779 * characters or when default directionality is RTL).
780 * If enabled, we should apply the Unicode Bidi Algorithm
782 * @lina 07/12/2000
784 bool BidiEnabled() const;
787 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
789 * @lina 07/12/2000
791 void SetBidiEnabled() const;
794 * Set visual or implicit mode into the pres context.
796 * Visual directionality is a presentation method that displays text
797 * as if it were a uni-directional, according to the primary display
798 * direction only.
800 * Implicit directionality is a presentation method in which the
801 * direction is determined by the Bidi algorithm according to the
802 * category of the characters and the category of the adjacent
803 * characters, and according to their primary direction.
805 * @lina 05/02/2000
807 void SetVisualMode(bool aIsVisual) { mIsVisual = aIsVisual; }
810 * Check whether the content should be treated as visual.
812 * @lina 05/02/2000
814 bool IsVisualMode() const { return mIsVisual; }
816 enum class InteractionType : uint32_t {
817 ClickInteraction,
818 KeyInteraction,
819 MouseMoveInteraction,
820 ScrollInteraction
823 void RecordInteractionTime(InteractionType aType,
824 const mozilla::TimeStamp& aTimeStamp);
826 void DisableInteractionTimeRecording() { mInteractionTimeEnabled = false; }
828 // Mohamed
831 * Set the Bidi options for the presentation context
833 void SetBidi(uint32_t aBidiOptions);
836 * Get the Bidi options for the presentation context
837 * Not inline so consumers of nsPresContext are not forced to
838 * include Document.
840 uint32_t GetBidi() const;
842 nsITheme* Theme() const MOZ_NONNULL_RETURN;
844 void RecomputeTheme();
846 bool UseOverlayScrollbars() const;
849 * Notify the pres context that the theme has changed. An internal switch
850 * means it's one of our Mozilla themes that changed (e.g., Modern to
851 * Classic). Otherwise, the OS is telling us that the native theme for the
852 * platform has changed.
854 void ThemeChanged(mozilla::widget::ThemeChangeKind);
857 * Notify the pres context that the resolution of the user interface has
858 * changed. This happens if a window is moved between HiDPI and non-HiDPI
859 * displays, so that the ratio of points to device pixels changes.
860 * The notification happens asynchronously.
862 void UIResolutionChanged();
865 * Like UIResolutionChanged() but invalidates values immediately.
867 void UIResolutionChangedSync();
869 /** Printing methods below should only be used for Medium() == print **/
870 void SetPrintSettings(nsIPrintSettings* aPrintSettings);
872 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
874 /* Helper function that ensures that this prescontext is shown in its
875 docshell if it's the most recent prescontext for the docshell. Returns
876 whether the prescontext is now being shown.
878 bool EnsureVisible();
880 #ifdef MOZ_REFLOW_PERF
881 void CountReflows(const char* aName, nsIFrame* aFrame);
882 #endif
884 void ConstructedFrame() { ++mFramesConstructed; }
885 void ReflowedFrame() { ++mFramesReflowed; }
886 void TriggeredAnimationRestyle() { ++mAnimationTriggeredRestyles; }
888 uint64_t FramesConstructedCount() const { return mFramesConstructed; }
889 uint64_t FramesReflowedCount() const { return mFramesReflowed; }
890 uint64_t AnimationTriggeredRestylesCount() const {
891 return mAnimationTriggeredRestyles;
894 static nscoord GetBorderWidthForKeyword(unsigned int aBorderWidthKeyword) {
895 // This table maps border-width enums 'thin', 'medium', 'thick'
896 // to actual nscoord values.
897 static const nscoord kBorderWidths[] = {
898 CSSPixelsToAppUnits(1), CSSPixelsToAppUnits(3), CSSPixelsToAppUnits(5)};
899 MOZ_ASSERT(size_t(aBorderWidthKeyword) < std::size(kBorderWidths));
901 return kBorderWidths[aBorderWidthKeyword];
904 gfxTextPerfMetrics* GetTextPerfMetrics() { return mTextPerf.get(); }
906 bool IsDynamic() const {
907 return mType == eContext_PageLayout || mType == eContext_Galley;
909 bool IsScreen() const {
910 return mMedium == nsGkAtoms::screen || mType == eContext_PageLayout ||
911 mType == eContext_PrintPreview;
913 bool IsPrintingOrPrintPreview() const {
914 return mType == eContext_Print || mType == eContext_PrintPreview;
917 bool IsPrintPreview() const { return mType == eContext_PrintPreview; }
919 // Is this presentation in a chrome docshell?
920 bool IsChrome() const;
922 gfxUserFontSet* GetUserFontSet();
924 // Should be called whenever the set of fonts available in the user
925 // font set changes (e.g., because a new font loads, or because the
926 // user font set is changed and fonts become unavailable).
927 void UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont = nullptr);
929 gfxMissingFontRecorder* MissingFontRecorder() { return mMissingFonts.get(); }
931 void NotifyMissingFonts();
933 void FlushCounterStyles();
934 void MarkCounterStylesDirty();
936 void FlushFontFeatureValues();
937 void MarkFontFeatureValuesDirty() { mFontFeatureValuesDirty = true; }
939 void FlushFontPaletteValues();
940 void MarkFontPaletteValuesDirty() { mFontPaletteValuesDirty = true; }
942 mozilla::gfx::PaletteCache& FontPaletteCache();
944 // Ensure that it is safe to hand out CSS rules outside the layout
945 // engine by ensuring that all CSS style sheets have unique inners
946 // and, if necessary, synchronously rebuilding all style data.
947 void EnsureSafeToHandOutCSSRules();
949 // Mark an area as invalidated, associated with a given transaction id
950 // (allocated by nsRefreshDriver::GetTransactionId). Invalidated regions will
951 // be dispatched to MozAfterPaint events when NotifyDidPaintForSubtree is
952 // called for the transaction id (or any higher id).
953 void NotifyInvalidation(TransactionId aTransactionId, const nsRect& aRect);
954 // aRect is in device pixels
955 void NotifyInvalidation(TransactionId aTransactionId, const nsIntRect& aRect);
956 void NotifyDidPaintForSubtree(
957 TransactionId aTransactionId = TransactionId{0},
958 const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp());
959 void NotifyRevokingDidPaint(TransactionId aTransactionId);
960 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
961 MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireDOMPaintEvent(
962 nsTArray<nsRect>* aList, TransactionId aTransactionId,
963 mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());
965 bool IsDOMPaintEventPending();
968 * Returns the RestyleManager's restyle generation counter.
970 uint64_t GetRestyleGeneration() const;
971 uint64_t GetUndisplayedRestyleGeneration() const;
974 * Notify the prescontext that the presshell is about to reflow a reflow root.
975 * The single argument indicates whether this reflow should be interruptible.
976 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
977 * will always return false. If aInterruptible is true then CheckForInterrupt
978 * will return true when a pending event is detected. This is for use by the
979 * presshell only. Reflow code wanting to prevent interrupts should use
980 * InterruptPreventer.
982 void ReflowStarted(bool aInterruptible);
985 * A class that can be used to temporarily disable reflow interruption.
987 class InterruptPreventer;
988 friend class InterruptPreventer;
989 class MOZ_STACK_CLASS InterruptPreventer {
990 public:
991 explicit InterruptPreventer(nsPresContext* aCtx)
992 : mCtx(aCtx),
993 mInterruptsEnabled(aCtx->mInterruptsEnabled),
994 mHasPendingInterrupt(aCtx->mHasPendingInterrupt) {
995 mCtx->mInterruptsEnabled = false;
996 mCtx->mHasPendingInterrupt = false;
998 ~InterruptPreventer() {
999 mCtx->mInterruptsEnabled = mInterruptsEnabled;
1000 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
1003 private:
1004 nsPresContext* mCtx;
1005 bool mInterruptsEnabled;
1006 bool mHasPendingInterrupt;
1010 * Check for interrupts. This may return true if a pending event is
1011 * detected. Once it has returned true, it will keep returning true
1012 * until ReflowStarted is called. In all cases where this returns true,
1013 * the passed-in frame (which should be the frame whose reflow will be
1014 * interrupted if true is returned) will be passed to
1015 * PresShell::FrameNeedsToContinueReflow.
1017 bool CheckForInterrupt(nsIFrame* aFrame);
1019 * Returns true if CheckForInterrupt has returned true since the last
1020 * ReflowStarted call. Cannot itself trigger an interrupt check.
1022 bool HasPendingInterrupt() const { return mHasPendingInterrupt; }
1024 * Sets a flag that will trip a reflow interrupt. This only bypasses the
1025 * interrupt timeout and the pending event check; other checks such as whether
1026 * interrupts are enabled and the interrupt check skipping still take effect.
1028 void SetPendingInterruptFromTest() { mPendingInterruptFromTest = true; }
1031 * If we have a presshell, and if the given content's current
1032 * document is the same as our presshell's document, return the
1033 * content's primary frame. Otherwise, return null. Only use this
1034 * if you care about which presshell the primary frame is in.
1036 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
1038 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1039 virtual size_t SizeOfIncludingThis(
1040 mozilla::MallocSizeOf aMallocSizeOf) const {
1041 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
1045 * We are a root content document in process if: we are not a resource doc, we
1046 * are not chrome, and we either have no parent in the current process or our
1047 * parent is chrome.
1049 bool IsRootContentDocumentInProcess() const;
1052 * We are a root content document cross process if: we are not a resource doc,
1053 * we are not chrome, and we either have no parent in any process or our
1054 * parent is chrome.
1056 bool IsRootContentDocumentCrossProcess() const;
1058 bool HadNonBlankPaint() const { return mHadNonBlankPaint; }
1059 bool HadFirstContentfulPaint() const { return mHadFirstContentfulPaint; }
1060 bool HasStoppedGeneratingLCP() const;
1061 void NotifyNonBlankPaint();
1062 void NotifyContentfulPaint();
1063 void NotifyPaintStatusReset();
1065 bool HasEverBuiltInvisibleText() const { return mHasEverBuiltInvisibleText; }
1066 void SetBuiltInvisibleText() { mHasEverBuiltInvisibleText = true; }
1068 bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
1069 return mHasWarnedAboutTooLargeDashedOrDottedRadius;
1072 void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
1073 mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
1076 void RegisterContainerQueryFrame(nsIFrame* aFrame);
1077 void UnregisterContainerQueryFrame(nsIFrame* aFrame);
1078 bool HasContainerQueryFrames() const {
1079 return !mContainerQueryFrames.IsEmpty();
1082 void FinishedContainerQueryUpdate();
1084 bool UpdateContainerQueryStyles();
1086 mozilla::intl::Bidi& BidiEngine();
1088 gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const {
1089 return mFontFeatureValuesLookup;
1092 mozilla::gfx::FontPaletteValueSet* GetFontPaletteValueSet() const {
1093 return mFontPaletteValueSet;
1096 bool NeedsToUpdateHiddenByContentVisibilityForAnimations() const {
1097 return mNeedsToUpdateHiddenByContentVisibilityForAnimations;
1099 void SetNeedsToUpdateHiddenByContentVisibilityForAnimations() {
1100 mNeedsToUpdateHiddenByContentVisibilityForAnimations = true;
1102 void UpdateHiddenByContentVisibilityForAnimationsIfNeeded() {
1103 if (mNeedsToUpdateHiddenByContentVisibilityForAnimations) {
1104 DoUpdateHiddenByContentVisibilityForAnimations();
1108 protected:
1109 void DoUpdateHiddenByContentVisibilityForAnimations();
1110 friend class nsRunnableMethod<nsPresContext>;
1111 void ThemeChangedInternal();
1112 void RefreshSystemMetrics();
1114 // Update device context's resolution from the widget
1115 void UIResolutionChangedInternal();
1117 void SetImgAnimations(nsIContent* aParent, uint16_t aMode);
1118 void SetSMILAnimations(mozilla::dom::Document* aDoc, uint16_t aNewMode,
1119 uint16_t aOldMode);
1121 static void PreferenceChanged(const char* aPrefName, void* aSelf);
1122 void PreferenceChanged(const char* aPrefName);
1124 void GetUserPreferences();
1126 void UpdateCharSet(NotNull<const Encoding*> aCharSet);
1128 void DoForceReflowForFontInfoUpdateFromStyle();
1130 public:
1131 // Used by the PresShell to force a reflow when some aspect of font info
1132 // has been updated, potentially affecting font selection and layout.
1133 void ForceReflowForFontInfoUpdate(bool aNeedsReframe);
1134 void ForceReflowForFontInfoUpdateFromStyle();
1137 * Checks for MozAfterPaint listeners on the document
1139 bool MayHavePaintEventListener();
1141 void InvalidatePaintedLayers();
1143 uint32_t GetNextFrameRateMultiplier() const {
1144 return mNextFrameRateMultiplier;
1147 void DidUseFrameRateMultiplier() {
1148 // This heuristic is used to reduce frame rate between fcp and the end of
1149 // the page load.
1150 if (mNextFrameRateMultiplier < 8) {
1151 ++mNextFrameRateMultiplier;
1155 mozilla::TimeStamp GetMarkPaintTimingStart() const {
1156 return mMarkPaintTimingStart;
1159 protected:
1160 // May be called multiple times (unlink, destructor)
1161 void Destroy();
1163 void AppUnitsPerDevPixelChanged();
1165 bool HavePendingInputEvent();
1167 // Creates a one-shot timer with the given aCallback & aDelay.
1168 // Returns a refcounted pointer to the timer (or nullptr on failure).
1169 already_AddRefed<nsITimer> CreateTimer(nsTimerCallbackFunc aCallback,
1170 const char* aName, uint32_t aDelay);
1172 struct TransactionInvalidations {
1173 TransactionId mTransactionId;
1174 nsTArray<nsRect> mInvalidations;
1175 bool mIsWaitingForPreviousTransaction = false;
1177 TransactionInvalidations* GetInvalidations(TransactionId aTransactionId);
1179 // This should be called only when we update mVisibleArea or
1180 // mDynamicToolbarMaxHeight or `app units per device pixels` changes.
1181 void AdjustSizeForViewportUnits();
1183 // Call in response to prefs changes that might affect what fonts should be
1184 // visibile to CSS. Returns whether the current visibility value actually
1185 // changed (in which case content should be reflowed).
1186 bool UpdateFontVisibility();
1187 void ReportBlockedFontFamilyName(const nsCString& aFamily,
1188 FontVisibility aVisibility);
1190 // IMPORTANT: The ownership implicit in the following member variables
1191 // has been explicitly checked. If you add any members to this class,
1192 // please make the ownership explicit (pinkerton, scc).
1194 // the PresShell owns a strong reference to the nsPresContext, and is
1195 // responsible for nulling this pointer before it is destroyed
1196 mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell; // [WEAK]
1197 RefPtr<mozilla::dom::Document> mDocument;
1198 RefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1199 // better safe than sorry.
1200 // Cannot reintroduce cycles
1201 // since there is no dependency
1202 // from gfx back to layout.
1203 RefPtr<nsFontCache> mFontCache;
1204 RefPtr<mozilla::EventStateManager> mEventManager;
1205 RefPtr<nsRefreshDriver> mRefreshDriver;
1206 RefPtr<mozilla::AnimationEventDispatcher> mAnimationEventDispatcher;
1207 RefPtr<mozilla::EffectCompositor> mEffectCompositor;
1208 mozilla::UniquePtr<nsTransitionManager> mTransitionManager;
1209 mozilla::UniquePtr<nsAnimationManager> mAnimationManager;
1210 mozilla::UniquePtr<mozilla::TimelineManager> mTimelineManager;
1211 mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager;
1212 RefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
1213 const nsStaticAtom* mMedium;
1214 RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup;
1215 RefPtr<mozilla::gfx::FontPaletteValueSet> mFontPaletteValueSet;
1217 mozilla::UniquePtr<mozilla::gfx::PaletteCache> mFontPaletteCache;
1219 // TODO(emilio): Maybe lazily create and put under a UniquePtr if this grows a
1220 // lot?
1221 MediaEmulationData mMediaEmulationData;
1223 float mTextZoom; // Text zoom, defaults to 1.0
1224 float mFullZoom; // Page zoom, defaults to 1.0
1225 gfxSize mLastFontInflationScreenSize;
1227 int32_t mCurAppUnitsPerDevPixel;
1228 int32_t mAutoQualityMinFontSizePixelsPref;
1230 nsCOMPtr<nsITheme> mTheme;
1231 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1233 mozilla::UniquePtr<mozilla::intl::Bidi> mBidiEngine;
1235 AutoTArray<TransactionInvalidations, 4> mTransactions;
1237 // text performance metrics
1238 mozilla::UniquePtr<gfxTextPerfMetrics> mTextPerf;
1240 mozilla::UniquePtr<gfxMissingFontRecorder> mMissingFonts;
1242 nsRect mVisibleArea;
1243 // This value is used to resolve viewport units.
1244 // On mobile this size is including the dynamic toolbar maximum height below.
1245 // On desktops this size is pretty much the same as |mVisibleArea|.
1246 nsSize mSizeForViewportUnits;
1247 // The maximum height of the dynamic toolbar on mobile.
1248 mozilla::ScreenIntCoord mDynamicToolbarMaxHeight;
1249 mozilla::ScreenIntCoord mDynamicToolbarHeight;
1250 // Safe area insets support
1251 mozilla::LayoutDeviceIntMargin mSafeAreaInsets;
1252 nsSize mPageSize;
1254 // The computed page margins from the print settings.
1256 // This margin will be used for each page in the current print operation, by
1257 // default (i.e. unless overridden by @page rules).
1259 // FIXME(emilio): Maybe we could let a global @page rule do that, though it's
1260 // sketchy at best, see https://github.com/w3c/csswg-drafts/issues/5437 for
1261 // discussion.
1262 nsMargin mDefaultPageMargin;
1263 float mPageScale;
1264 float mPPScale;
1266 // This is a non-owning pointer. May be null. If non-null, it's guaranteed to
1267 // be pointing to an element that's still alive, because we'll reset it in
1268 // UpdateViewportScrollStylesOverride() as part of the cleanup code when
1269 // this element is removed from the document. (For <body> and the root
1270 // element, this call happens in nsCSSFrameConstructor::ContentRemoved(). For
1271 // fullscreen elements, it happens in the fullscreen-specific cleanup invoked
1272 // by Element::UnbindFromTree().)
1273 mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollOverrideElement;
1275 // Counters for tests and tools that want to detect frame construction
1276 // or reflow.
1277 uint64_t mElementsRestyled;
1278 uint64_t mFramesConstructed;
1279 uint64_t mFramesReflowed;
1280 uint64_t mAnimationTriggeredRestyles;
1282 mozilla::TimeStamp mReflowStartTime;
1284 // Defined in https://w3c.github.io/paint-timing/#mark-paint-timing step 2.
1285 mozilla::TimeStamp mMarkPaintTimingStart;
1287 Maybe<TransactionId> mFirstContentfulPaintTransactionId;
1289 mozilla::UniquePtr<mozilla::MediaFeatureChange>
1290 mPendingMediaFeatureValuesChange;
1292 // Time of various first interaction types, used to report time from
1293 // first paint of the top level content pres shell to first interaction.
1294 mozilla::TimeStamp mFirstNonBlankPaintTime;
1295 mozilla::TimeStamp mFirstClickTime;
1296 mozilla::TimeStamp mFirstKeyTime;
1297 mozilla::TimeStamp mFirstMouseMoveTime;
1298 mozilla::TimeStamp mFirstScrollTime;
1300 // last time we did a full style flush
1301 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1303 uint32_t mInterruptChecksToSkip;
1305 // During page load we use slower frame rate.
1306 uint32_t mNextFrameRateMultiplier;
1308 uint32_t mMeasuredTicksSinceLoading;
1310 nsTArray<RefPtr<mozilla::ManagedPostRefreshObserver>>
1311 mManagedPostRefreshObservers;
1313 // If we block the use of a font-family that is explicitly requested,
1314 // due to font visibility settings, we log a message to the web console;
1315 // this hash-set keeps track of names we've logged for this context, so
1316 // that we can avoid repeatedly reporting the same font.
1317 nsTHashSet<nsCString> mBlockedFonts;
1319 // The set of container query boxes currently in the document, sorted by
1320 // depth.
1321 mozilla::DepthOrderedFrameList mContainerQueryFrames;
1322 // The set of container query elements currently in the document that have
1323 // been updated so far. This is necessary to avoid reentering on container
1324 // query style changes which cause us to do frame reconstruction.
1325 nsTHashSet<nsIContent*> mUpdatedContainerQueryContents;
1327 ScrollStyles mViewportScrollStyles;
1329 uint16_t mImageAnimationMode;
1330 uint16_t mImageAnimationModePref;
1332 nsPresContextType mType;
1334 public:
1335 // The following are public member variables so that we can use them
1336 // with mozilla::AutoToggle or mozilla::AutoRestore.
1338 // Should we disable font size inflation because we're inside of
1339 // shrink-wrapping calculations on an inflation container?
1340 bool mInflationDisabledForShrinkWrap;
1342 protected:
1343 static constexpr size_t kThemeChangeKindBits = 2;
1344 static_assert(unsigned(mozilla::widget::ThemeChangeKind::AllBits) <=
1345 (1u << kThemeChangeKindBits) - 1,
1346 "theme change kind doesn't fit");
1348 unsigned mInteractionTimeEnabled : 1;
1349 unsigned mHasPendingInterrupt : 1;
1350 unsigned mHasEverBuiltInvisibleText : 1;
1351 unsigned mPendingInterruptFromTest : 1;
1352 unsigned mInterruptsEnabled : 1;
1353 unsigned mDrawImageBackground : 1;
1354 unsigned mDrawColorBackground : 1;
1355 unsigned mNeverAnimate : 1;
1356 unsigned mPaginated : 1;
1357 unsigned mCanPaginatedScroll : 1;
1358 unsigned mDoScaledTwips : 1;
1359 unsigned mIsRootPaginatedDocument : 1;
1360 unsigned mPendingThemeChanged : 1;
1361 // widget::ThemeChangeKind
1362 unsigned mPendingThemeChangeKind : kThemeChangeKindBits;
1363 unsigned mPendingUIResolutionChanged : 1;
1364 unsigned mPendingFontInfoUpdateReflowFromStyle : 1;
1366 // Are we currently drawing an SVG glyph?
1367 unsigned mIsGlyph : 1;
1369 // Is the current mCounterStyleManager valid?
1370 unsigned mCounterStylesDirty : 1;
1372 // Is the current mFontFeatureValuesLookup valid?
1373 unsigned mFontFeatureValuesDirty : 1;
1375 // Is the current mFontFeatureValueSet valid?
1376 unsigned mFontPaletteValuesDirty : 1;
1378 unsigned mIsVisual : 1;
1380 // Are we in the RDM pane?
1381 unsigned mInRDMPane : 1;
1383 unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;
1385 // Have we added quirk.css to the style set?
1386 unsigned mQuirkSheetAdded : 1;
1388 // Has NotifyNonBlankPaint been called on this PresContext?
1389 unsigned mHadNonBlankPaint : 1;
1390 // Has NotifyContentfulPaint been called on this PresContext?
1391 unsigned mHadFirstContentfulPaint : 1;
1392 // True when a contentful paint has happened and this paint doesn't
1393 // come from the regular tick process. Usually this means a
1394 // contentful paint was triggered manually.
1395 unsigned mHadNonTickContentfulPaint : 1;
1397 // Has NotifyDidPaintForSubtree been called for a contentful paint?
1398 unsigned mHadContentfulPaintComposite : 1;
1400 // Whether we might need to update c-v state for animations.
1401 unsigned mNeedsToUpdateHiddenByContentVisibilityForAnimations : 1;
1403 unsigned mUserInputEventsAllowed : 1;
1404 #ifdef DEBUG
1405 unsigned mInitialized : 1;
1406 #endif
1408 // FIXME(emilio): These would be better packed on top of the bitfields, but
1409 // that breaks bindgen in win32.
1410 FontVisibility mFontVisibility = FontVisibility::Unknown;
1411 mozilla::dom::PrefersColorSchemeOverride mOverriddenOrEmbedderColorScheme;
1412 mozilla::StyleForcedColors mForcedColors;
1414 protected:
1415 virtual ~nsPresContext();
1417 void LastRelease();
1419 void EnsureTheme();
1421 #ifdef DEBUG
1422 private:
1423 friend struct nsAutoLayoutPhase;
1424 mozilla::EnumeratedArray<nsLayoutPhase, uint32_t,
1425 size_t(nsLayoutPhase::COUNT)>
1426 mLayoutPhaseCount;
1428 public:
1429 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1430 return mLayoutPhaseCount[aPhase];
1432 #endif
1435 class nsRootPresContext final : public nsPresContext {
1436 public:
1437 nsRootPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
1438 virtual bool IsRoot() const override { return true; }
1441 * Add a runnable that will get called before the next paint. They will get
1442 * run eventually even if painting doesn't happen. They might run well before
1443 * painting happens.
1445 void AddWillPaintObserver(nsIRunnable* aRunnable);
1448 * Run all runnables that need to get called before the next paint.
1450 void FlushWillPaintObservers();
1452 virtual size_t SizeOfExcludingThis(
1453 mozilla::MallocSizeOf aMallocSizeOf) const override;
1455 protected:
1456 class RunWillPaintObservers : public mozilla::Runnable {
1457 public:
1458 explicit RunWillPaintObservers(nsRootPresContext* aPresContext)
1459 : Runnable("nsPresContextType::RunWillPaintObservers"),
1460 mPresContext(aPresContext) {}
1461 void Revoke() { mPresContext = nullptr; }
1462 NS_IMETHOD Run() override {
1463 if (mPresContext) {
1464 mPresContext->FlushWillPaintObservers();
1466 return NS_OK;
1468 // The lifetime of this reference is handled by an nsRevocableEventPtr
1469 nsRootPresContext* MOZ_NON_OWNING_REF mPresContext;
1472 friend class nsPresContext;
1474 nsTArray<nsCOMPtr<nsIRunnable>> mWillPaintObservers;
1475 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1478 #ifdef MOZ_REFLOW_PERF
1480 # define DO_GLOBAL_REFLOW_COUNT(_name) \
1481 aPresContext->CountReflows((_name), (nsIFrame*)this);
1482 #else
1483 # define DO_GLOBAL_REFLOW_COUNT(_name)
1484 #endif // MOZ_REFLOW_PERF
1486 #endif /* nsPresContext_h___ */