Bug 1104435 part 2 - Make AnimationPlayer derive from nsISupports; r=smaug
[gecko.git] / layout / base / nsPresContext.h
blobeb3e29925b7445f3fe63a4d7cbe100c4cb965c28
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* a presentation of a document, part 1 */
8 #ifndef nsPresContext_h___
9 #define nsPresContext_h___
11 #include "mozilla/Attributes.h"
12 #include "mozilla/WeakPtr.h"
13 #include "nsColor.h"
14 #include "nsCoord.h"
15 #include "nsCOMPtr.h"
16 #include "nsIPresShell.h"
17 #include "nsRect.h"
18 #include "nsFont.h"
19 #include "gfxFontConstants.h"
20 #include "nsIAtom.h"
21 #include "nsIObserver.h"
22 #include "nsITimer.h"
23 #include "nsCRT.h"
24 #include "FramePropertyTable.h"
25 #include "nsGkAtoms.h"
26 #include "nsCycleCollectionParticipant.h"
27 #include "nsChangeHint.h"
28 #include <algorithm>
29 // This also pulls in gfxTypes.h, which we cannot include directly.
30 #include "gfxRect.h"
31 #include "nsTArray.h"
32 #include "nsAutoPtr.h"
33 #include "mozilla/MemoryReporting.h"
34 #include "mozilla/TimeStamp.h"
35 #include "mozilla/AppUnits.h"
36 #include "prclist.h"
37 #include "nsThreadUtils.h"
38 #include "ScrollbarStyles.h"
39 #include "nsIMessageManager.h"
40 #include "mozilla/RestyleLogging.h"
42 class nsBidiPresUtils;
43 class nsAString;
44 class nsIPrintSettings;
45 class nsDocShell;
46 class nsIDocShell;
47 class nsIDocument;
48 class nsILanguageAtomService;
49 class nsITheme;
50 class nsIContent;
51 class nsIFrame;
52 class nsFrameManager;
53 class nsILinkHandler;
54 class nsIAtom;
55 class nsICSSPseudoComparator;
56 struct nsStyleBackground;
57 struct nsStyleBorder;
58 class nsIRunnable;
59 class gfxUserFontSet;
60 class gfxTextPerfMetrics;
61 struct nsFontFaceRuleContainer;
62 class nsPluginFrame;
63 class nsTransitionManager;
64 class nsAnimationManager;
65 class nsRefreshDriver;
66 class nsIWidget;
67 class nsDeviceContext;
69 namespace mozilla {
70 class EventStateManager;
71 class RestyleManager;
72 class CounterStyleManager;
73 namespace dom {
74 class FontFaceSet;
76 namespace layers {
77 class ContainerLayer;
81 // supported values for cached bool types
82 enum nsPresContext_CachedBoolPrefType {
83 kPresContext_UseDocumentFonts = 1,
84 kPresContext_UnderlineLinks
87 // supported values for cached integer pref types
88 enum nsPresContext_CachedIntPrefType {
89 kPresContext_ScrollbarSide = 1,
90 kPresContext_BidiDirection
93 // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
94 // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
95 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable
96 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed
98 #ifdef DEBUG
99 struct nsAutoLayoutPhase;
101 enum nsLayoutPhase {
102 eLayoutPhase_Paint,
103 eLayoutPhase_Reflow,
104 eLayoutPhase_FrameC,
105 eLayoutPhase_COUNT
107 #endif
109 class nsInvalidateRequestList {
110 public:
111 struct Request {
112 nsRect mRect;
113 uint32_t mFlags;
116 void TakeFrom(nsInvalidateRequestList* aList)
118 mRequests.MoveElementsFrom(aList->mRequests);
120 bool IsEmpty() { return mRequests.IsEmpty(); }
122 nsTArray<Request> mRequests;
125 /* Used by nsPresContext::HasAuthorSpecifiedRules */
126 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
127 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
128 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
129 #define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3)
131 class nsRootPresContext;
133 // An interface for presentation contexts. Presentation contexts are
134 // objects that provide an outer context for a presentation shell.
136 class nsPresContext : public nsIObserver {
137 public:
138 typedef mozilla::FramePropertyTable FramePropertyTable;
139 typedef mozilla::ScrollbarStyles ScrollbarStyles;
141 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
142 NS_DECL_NSIOBSERVER
143 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
144 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
146 enum nsPresContextType {
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(nsIDocument* aDocument, nsPresContextType aType);
156 * Initialize the presentation context from a particular device.
158 nsresult Init(nsDeviceContext* aDeviceContext);
161 * Set the presentation shell that this context is bound to.
162 * A presentation context may only be bound to a single shell.
164 void SetShell(nsIPresShell* aShell);
167 nsPresContextType Type() const { return mType; }
170 * Get the PresentationShell that this context is bound to.
172 nsIPresShell* PresShell() const
174 NS_ASSERTION(mShell, "Null pres shell");
175 return mShell;
178 nsIPresShell* GetPresShell() const { return mShell; }
181 * Returns the parent prescontext for this one. Returns null if this is a
182 * root.
184 nsPresContext* GetParentPresContext();
187 * Returns the prescontext of the toplevel content document that contains
188 * this presentation, or null if there isn't one.
190 nsPresContext* GetToplevelContentDocumentPresContext();
193 * Returns the nearest widget for the root frame of this.
195 * @param aOffset If non-null the offset from the origin of the root
196 * frame's view to the widget's origin (usually positive)
197 * expressed in appunits of this will be returned in
198 * aOffset.
200 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
203 * Returns the root widget for this.
204 * Note that the widget is a mediater with IME.
206 nsIWidget* GetRootWidget();
209 * Return the presentation context for the root of the view manager
210 * hierarchy that contains this presentation context, or nullptr if it can't
211 * be found (e.g. it's detached).
213 nsRootPresContext* GetRootPresContext();
214 nsRootPresContext* GetDisplayRootPresContext();
215 virtual bool IsRoot() { return false; }
217 nsIDocument* Document() const
219 NS_ASSERTION(!mShell || !mShell->GetDocument() ||
220 mShell->GetDocument() == mDocument,
221 "nsPresContext doesn't have the same document as nsPresShell!");
222 return mDocument;
225 #ifdef MOZILLA_INTERNAL_API
226 nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); }
228 nsFrameManager* FrameManager()
229 { return PresShell()->FrameManager(); }
231 nsCSSFrameConstructor* FrameConstructor()
232 { return PresShell()->FrameConstructor(); }
234 nsTransitionManager* TransitionManager() { return mTransitionManager; }
235 nsAnimationManager* AnimationManager() { return mAnimationManager; }
237 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
239 mozilla::RestyleManager* RestyleManager() { return mRestyleManager; }
241 mozilla::CounterStyleManager* CounterStyleManager() {
242 return mCounterStyleManager;
244 #endif
247 * Rebuilds all style data by throwing out the old rule tree and
248 * building a new one, and additionally applying aExtraHint (which
249 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
250 * For aRestyleHint, see RestyleManager::RebuildAllStyleData.
251 * Also rebuild the user font set and counter style manager.
253 void RebuildAllStyleData(nsChangeHint aExtraHint, nsRestyleHint aRestyleHint);
255 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
256 * doesn't rebuild the user font set.
258 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
259 nsRestyleHint aRestyleHint);
262 * Handle changes in the values of media features (used in media
263 * queries).
265 * There are three sensible values to use for aRestyleHint:
266 * * nsRestyleHint(0) to rebuild style data, with rerunning of
267 * selector matching, only if media features have changed
268 * * eRestyle_ForceDescendants to force rebuilding of style data (but
269 * still only rerun selector matching if media query results have
270 * changed). (RebuildAllStyleData always adds
271 * eRestyle_ForceDescendants internally, so here we're only using
272 * it to distinguish from nsRestyleHint(0) whether we need to call
273 * RebuildAllStyleData at all.)
274 * * eRestyle_Subtree to force rebuilding of style data with
275 * rerunning of selector matching
277 * For aChangeHint, see RestyleManager::RebuildAllStyleData. (Passing
278 * a nonzero aChangeHint forces rebuilding style data even if
279 * nsRestyleHint(0) is passed.)
281 void MediaFeatureValuesChanged(nsRestyleHint aRestyleHint,
282 nsChangeHint aChangeHint = nsChangeHint(0));
283 void PostMediaFeatureValuesChangedEvent();
284 void HandleMediaFeatureValuesChangedEvent();
285 void FlushPendingMediaFeatureValuesChanged() {
286 if (mPendingMediaFeatureValuesChanged)
287 MediaFeatureValuesChanged(nsRestyleHint(0));
291 * Access compatibility mode for this context. This is the same as
292 * our document's compatibility mode.
294 nsCompatibility CompatibilityMode() const;
297 * Notify the context that the document's compatibility mode has changed
299 void CompatibilityModeChanged();
302 * Access the image animation mode for this context
304 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
305 virtual void SetImageAnimationModeExternal(uint16_t aMode);
306 void SetImageAnimationModeInternal(uint16_t aMode);
307 #ifdef MOZILLA_INTERNAL_API
308 void SetImageAnimationMode(uint16_t aMode)
309 { SetImageAnimationModeInternal(aMode); }
310 #else
311 void SetImageAnimationMode(uint16_t aMode)
312 { SetImageAnimationModeExternal(aMode); }
313 #endif
316 * Get medium of presentation
318 nsIAtom* Medium() {
319 if (!mIsEmulatingMedia)
320 return mMedium;
321 return mMediaEmulated;
325 * Render the document as if being viewed on a device with the specified
326 * media type.
328 void EmulateMedium(const nsAString& aMediaType);
331 * Restore the viewer's natural medium
333 void StopEmulatingMedium();
335 void* AllocateFromShell(size_t aSize)
337 if (mShell)
338 return mShell->AllocateMisc(aSize);
339 return nullptr;
342 void FreeToShell(size_t aSize, void* aFreeChunk)
344 NS_ASSERTION(mShell, "freeing after shutdown");
345 if (mShell)
346 mShell->FreeMisc(aSize, aFreeChunk);
350 * Get the default font for the given language and generic font ID.
351 * If aLanguage is nullptr, the document's language is used.
353 * This object is read-only, you must copy the font to modify it.
355 * When aFontID is kPresContext_DefaultVariableFontID or
356 * kPresContext_DefaultFixedFontID (which equals
357 * kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
358 * the nsFont returned has its name as a CSS generic family (serif or
359 * sans-serif for the former, monospace for the latter), and its size
360 * as the default font size for variable or fixed fonts for the
361 * language group.
363 * For aFontID corresponding to a CSS Generic, the nsFont returned has
364 * its name set to that generic font's name, and its size set to
365 * the user's preference for font size for that generic and the
366 * given language.
368 const nsFont* GetDefaultFont(uint8_t aFontID,
369 nsIAtom *aLanguage) const;
371 /** Get a cached boolean pref, by its type */
372 // * - initially created for bugs 31816, 20760, 22963
373 bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const
375 // If called with a constant parameter, the compiler should optimize
376 // this switch statement away.
377 switch (aPrefType) {
378 case kPresContext_UseDocumentFonts:
379 return mUseDocumentFonts;
380 case kPresContext_UnderlineLinks:
381 return mUnderlineLinks;
382 default:
383 NS_ERROR("Invalid arg passed to GetCachedBoolPref");
386 return false;
389 /** Get a cached integer pref, by its type */
390 // * - initially created for bugs 30910, 61883, 74186, 84398
391 int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const
393 // If called with a constant parameter, the compiler should optimize
394 // this switch statement away.
395 switch (aPrefType) {
396 case kPresContext_ScrollbarSide:
397 return mPrefScrollbarSide;
398 case kPresContext_BidiDirection:
399 return mPrefBidiDirection;
400 default:
401 NS_ERROR("invalid arg passed to GetCachedIntPref");
404 return false;
408 * Get the default colors
410 const nscolor DefaultColor() const { return mDefaultColor; }
411 const nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
412 const nscolor DefaultLinkColor() const { return mLinkColor; }
413 const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
414 const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
415 const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
416 const nscolor FocusTextColor() const { return mFocusTextColor; }
419 * Body text color, for use in quirks mode only.
421 const nscolor BodyTextColor() const { return mBodyTextColor; }
422 void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; }
424 bool GetUseFocusColors() const { return mUseFocusColors; }
425 uint8_t FocusRingWidth() const { return mFocusRingWidth; }
426 bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
427 uint8_t GetFocusRingStyle() const { return mFocusRingStyle; }
429 void SetContainer(nsIDocShell* aContainer);
431 virtual nsISupports* GetContainerWeakExternal() const;
432 nsISupports* GetContainerWeakInternal() const;
433 #ifdef MOZILLA_INTERNAL_API
434 nsISupports* GetContainerWeak() const
435 { return GetContainerWeakInternal(); }
436 #else
437 nsISupports* GetContainerWeak() const
438 { return GetContainerWeakExternal(); }
439 #endif
441 nsIDocShell* GetDocShell() const;
443 // XXX this are going to be replaced with set/get container
444 void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
445 nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
448 * Detach this pres context - i.e. cancel relevant timers,
449 * SetLinkHandler(null), SetContainer(null) etc.
450 * Only to be used by the DocumentViewer.
452 virtual void Detach();
455 * Get the visible area associated with this presentation context.
456 * This is the size of the visible area that is used for
457 * presenting the document. The returned value is in the standard
458 * nscoord units (as scaled by the device context).
460 nsRect GetVisibleArea() { return mVisibleArea; }
463 * Set the currently visible area. The units for r are standard
464 * nscoord units (as scaled by the device context).
466 void SetVisibleArea(const nsRect& r) {
467 if (!r.IsEqualEdges(mVisibleArea)) {
468 mVisibleArea = r;
469 // Visible area does not affect media queries when paginated.
470 if (!IsPaginated() && HasCachedStyleData()) {
471 mPendingViewportChange = true;
472 PostMediaFeatureValuesChangedEvent();
478 * Return true if this presentation context is a paginated
479 * context.
481 bool IsPaginated() const { return mPaginated; }
484 * Sets whether the presentation context can scroll for a paginated
485 * context.
487 void SetPaginatedScrolling(bool aResult);
490 * Return true if this presentation context can scroll for paginated
491 * context.
493 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
496 * Get/set the size of a page
498 nsSize GetPageSize() { return mPageSize; }
499 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
502 * Get/set whether this document should be treated as having real pages
503 * XXX This raises the obvious question of why a document that isn't a page
504 * is paginated; there isn't a good reason except history
506 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
507 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument)
508 { mIsRootPaginatedDocument = aIsRootPaginatedDocument; }
511 * Get/set the print scaling level; used by nsPageFrame to scale up
512 * pages. Set safe to call before reflow, get guaranteed to be set
513 * properly after reflow.
516 float GetPageScale() { return mPageScale; }
517 void SetPageScale(float aScale) { mPageScale = aScale; }
520 * Get/set the scaling facor to use when rendering the pages for print preview.
521 * Only safe to get after print preview set up; safe to set anytime.
522 * This is a scaling factor for the display of the print preview. It
523 * does not affect layout. It only affects the size of the onscreen pages
524 * in print preview.
525 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
527 float GetPrintPreviewScale() { return mPPScale; }
528 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
530 nsDeviceContext* DeviceContext() { return mDeviceContext; }
531 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
532 nsIAtom* GetLanguageFromCharset() { return mLanguage; }
534 float TextZoom() { return mTextZoom; }
535 void SetTextZoom(float aZoom) {
536 if (aZoom == mTextZoom)
537 return;
539 mTextZoom = aZoom;
540 if (HasCachedStyleData()) {
541 // Media queries could have changed, since we changed the meaning
542 // of 'em' units in them.
543 MediaFeatureValuesChanged(eRestyle_ForceDescendants,
544 NS_STYLE_HINT_REFLOW);
549 * Get the minimum font size for the specified language. If aLanguage
550 * is nullptr, then the document's language is used. This combines
551 * the language-specific global preference with the per-presentation
552 * base minimum font size.
554 int32_t MinFontSize(nsIAtom *aLanguage) const {
555 const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
556 return std::max(mBaseMinFontSize, prefs->mMinimumFontSize);
560 * Get the per-presentation base minimum font size. This size is
561 * independent of the language-specific global preference.
563 int32_t BaseMinFontSize() const {
564 return mBaseMinFontSize;
568 * Set the per-presentation base minimum font size. This size is
569 * independent of the language-specific global preference.
571 void SetBaseMinFontSize(int32_t aMinFontSize) {
572 if (aMinFontSize == mBaseMinFontSize)
573 return;
575 mBaseMinFontSize = aMinFontSize;
576 if (HasCachedStyleData()) {
577 // Media queries could have changed, since we changed the meaning
578 // of 'em' units in them.
579 MediaFeatureValuesChanged(eRestyle_ForceDescendants,
580 NS_STYLE_HINT_REFLOW);
584 float GetFullZoom() { return mFullZoom; }
585 void SetFullZoom(float aZoom);
587 nscoord GetAutoQualityMinFontSize() {
588 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
592 * Return the device's screen width in inches, for font size
593 * inflation.
595 * If |aChanged| is non-null, then aChanged is filled in with whether
596 * the return value has changed since either:
597 * a. the last time the function was called with non-null aChanged, or
598 * b. the first time the function was called.
600 float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr);
602 static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
603 int32_t AppUnitsPerDevPixel() const;
604 static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); }
606 static nscoord CSSPixelsToAppUnits(int32_t aPixels)
607 { return NSToCoordRoundWithClamp(float(aPixels) *
608 float(AppUnitsPerCSSPixel())); }
610 static nscoord CSSPixelsToAppUnits(float aPixels)
611 { return NSToCoordRoundWithClamp(aPixels *
612 float(AppUnitsPerCSSPixel())); }
614 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits)
615 { return NSAppUnitsToIntPixels(aAppUnits,
616 float(AppUnitsPerCSSPixel())); }
618 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits)
619 { return NSAppUnitsToFloatPixels(aAppUnits,
620 float(AppUnitsPerCSSPixel())); }
622 nscoord DevPixelsToAppUnits(int32_t aPixels) const
623 { return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel()); }
625 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const
626 { return NSAppUnitsToIntPixels(aAppUnits,
627 float(AppUnitsPerDevPixel())); }
629 int32_t CSSPixelsToDevPixels(int32_t aPixels)
630 { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }
632 float CSSPixelsToDevPixels(float aPixels)
634 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
635 float(AppUnitsPerDevPixel()));
638 int32_t DevPixelsToIntCSSPixels(int32_t aPixels)
639 { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); }
641 float DevPixelsToFloatCSSPixels(int32_t aPixels)
642 { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); }
644 // If there is a remainder, it is rounded to nearest app units.
645 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
647 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
649 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const
650 { return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
651 AppUnitsToGfxUnits(aAppRect.y),
652 AppUnitsToGfxUnits(aAppRect.width),
653 AppUnitsToGfxUnits(aAppRect.height)); }
655 static nscoord CSSTwipsToAppUnits(float aTwips)
656 { return NSToCoordRoundWithClamp(
657 mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); }
659 // Margin-specific version, since they often need TwipsToAppUnits
660 static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips)
661 { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
662 CSSTwipsToAppUnits(float(marginInTwips.right)),
663 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
664 CSSTwipsToAppUnits(float(marginInTwips.left))); }
666 static nscoord CSSPointsToAppUnits(float aPoints)
667 { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
668 POINTS_PER_INCH_FLOAT); }
670 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
671 { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
673 void SetViewportScrollbarStylesOverride(const ScrollbarStyles& aScrollbarStyle)
675 mViewportStyleScrollbar = aScrollbarStyle;
677 ScrollbarStyles GetViewportScrollbarStylesOverride()
679 return mViewportStyleScrollbar;
683 * Set and get methods for controlling the background drawing
685 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
686 void SetBackgroundImageDraw(bool aCanDraw)
688 mDrawImageBackground = aCanDraw;
691 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
692 void SetBackgroundColorDraw(bool aCanDraw)
694 mDrawColorBackground = aCanDraw;
698 * Getter and setters for OMTA time counters
700 bool StyleUpdateForAllAnimationsIsUpToDate() const;
701 void TickLastStyleUpdateForAllAnimations();
702 void ClearLastStyleUpdateForAllAnimations();
705 * Check if bidi enabled (set depending on the presence of RTL
706 * characters or when default directionality is RTL).
707 * If enabled, we should apply the Unicode Bidi Algorithm
709 * @lina 07/12/2000
711 #ifdef MOZILLA_INTERNAL_API
712 bool BidiEnabled() const { return BidiEnabledInternal(); }
713 #else
714 bool BidiEnabled() const { return BidiEnabledExternal(); }
715 #endif
716 virtual bool BidiEnabledExternal() const;
717 bool BidiEnabledInternal() const;
720 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
722 * @lina 07/12/2000
724 void SetBidiEnabled() const;
727 * Set visual or implicit mode into the pres context.
729 * Visual directionality is a presentation method that displays text
730 * as if it were a uni-directional, according to the primary display
731 * direction only.
733 * Implicit directionality is a presentation method in which the
734 * direction is determined by the Bidi algorithm according to the
735 * category of the characters and the category of the adjacent
736 * characters, and according to their primary direction.
738 * @lina 05/02/2000
740 void SetVisualMode(bool aIsVisual)
742 mIsVisual = aIsVisual;
746 * Check whether the content should be treated as visual.
748 * @lina 05/02/2000
750 bool IsVisualMode() const { return mIsVisual; }
752 //Mohamed
755 * Set the Bidi options for the presentation context
757 void SetBidi(uint32_t aBidiOptions,
758 bool aForceRestyle = false);
761 * Get the Bidi options for the presentation context
762 * Not inline so consumers of nsPresContext are not forced to
763 * include nsIDocument.
765 uint32_t GetBidi() const;
768 * Render only Selection
770 void SetIsRenderingOnlySelection(bool aResult)
772 mIsRenderingOnlySelection = aResult;
775 bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; }
777 bool IsTopLevelWindowInactive();
780 * Obtain a native them for rendering our widgets (both form controls and html)
782 nsITheme* GetTheme();
785 * Notify the pres context that the theme has changed. An internal switch
786 * means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
787 * Otherwise, the OS is telling us that the native theme for the platform
788 * has changed.
790 void ThemeChanged();
793 * Notify the pres context that the resolution of the user interface has
794 * changed. This happens if a window is moved between HiDPI and non-HiDPI
795 * displays, so that the ratio of points to device pixels changes.
797 void UIResolutionChanged();
800 * Notify the pres context that a system color has changed
802 void SysColorChanged();
804 /** Printing methods below should only be used for Medium() == print **/
805 void SetPrintSettings(nsIPrintSettings *aPrintSettings);
807 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
809 /* Accessor for table of frame properties */
810 FramePropertyTable* PropertyTable() { return &mPropertyTable; }
812 /* Helper function that ensures that this prescontext is shown in its
813 docshell if it's the most recent prescontext for the docshell. Returns
814 whether the prescontext is now being shown.
816 bool EnsureVisible();
818 #ifdef MOZ_REFLOW_PERF
819 void CountReflows(const char * aName,
820 nsIFrame * aFrame);
821 #endif
824 * This table maps border-width enums 'thin', 'medium', 'thick'
825 * to actual nscoord values.
827 const nscoord* GetBorderWidthTable() { return mBorderWidthTable; }
829 gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; }
831 bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); }
832 bool IsScreen() { return (mMedium == nsGkAtoms::screen ||
833 mType == eContext_PageLayout ||
834 mType == eContext_PrintPreview); }
836 // Is this presentation in a chrome docshell?
837 bool IsChrome() const { return mIsChrome; }
838 bool IsChromeOriginImage() const { return mIsChromeOriginImage; }
839 void UpdateIsChrome();
841 // Public API for native theme code to get style internals.
842 virtual bool HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const;
844 // Is it OK to let the page specify colors and backgrounds?
845 bool UseDocumentColors() const {
846 MOZ_ASSERT(mUseDocumentColors || !(IsChrome() || IsChromeOriginImage()),
847 "We should never have a chrome doc or image that can't use its colors.");
848 return mUseDocumentColors;
851 // Explicitly enable and disable paint flashing.
852 void SetPaintFlashing(bool aPaintFlashing) {
853 mPaintFlashing = aPaintFlashing;
854 mPaintFlashingInitialized = true;
857 // This method should be used instead of directly accessing mPaintFlashing,
858 // as that value may be out of date when mPaintFlashingInitialized is false.
859 bool GetPaintFlashing() const;
861 bool SupressingResizeReflow() const { return mSupressResizeReflow; }
863 virtual gfxUserFontSet* GetUserFontSetExternal();
864 gfxUserFontSet* GetUserFontSetInternal();
865 #ifdef MOZILLA_INTERNAL_API
866 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); }
867 #else
868 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); }
869 #endif
871 void FlushUserFontSet();
872 void RebuildUserFontSet(); // asynchronously
874 // Should be called whenever the set of fonts available in the user
875 // font set changes (e.g., because a new font loads, or because the
876 // user font set is changed and fonts become unavailable).
877 void UserFontSetUpdated();
879 mozilla::dom::FontFaceSet* Fonts();
881 void FlushCounterStyles();
882 void RebuildCounterStyles(); // asynchronously
884 // Ensure that it is safe to hand out CSS rules outside the layout
885 // engine by ensuring that all CSS style sheets have unique inners
886 // and, if necessary, synchronously rebuilding all style data.
887 void EnsureSafeToHandOutCSSRules();
889 void NotifyInvalidation(uint32_t aFlags);
890 void NotifyInvalidation(const nsRect& aRect, uint32_t aFlags);
891 // aRect is in device pixels
892 void NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags);
893 // aFlags are nsIPresShell::PAINT_ flags
894 void NotifyDidPaintForSubtree(uint32_t aFlags);
895 void FireDOMPaintEvent(nsInvalidateRequestList* aList);
897 // Callback for catching invalidations in ContainerLayers
898 // Passed to LayerProperties::ComputeDifference
899 static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer,
900 const nsIntRegion& aRegion);
901 void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer);
902 static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer);
903 bool IsDOMPaintEventPending();
904 void ClearMozAfterPaintEvents() {
905 mInvalidateRequestsSinceLastPaint.mRequests.Clear();
906 mUndeliveredInvalidateRequestsBeforeLastPaint.mRequests.Clear();
907 mAllInvalidated = false;
911 * Returns whether there are any pending restyles or reflows.
913 bool HasPendingRestyleOrReflow();
916 * Informs the document's FontFaceSet that the refresh driver ticked,
917 * flushing style and layout.
919 void NotifyFontFaceSetOnRefresh();
922 * Notify the prescontext that the presshell is about to reflow a reflow root.
923 * The single argument indicates whether this reflow should be interruptible.
924 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
925 * will always return false. If aInterruptible is true then CheckForInterrupt
926 * will return true when a pending event is detected. This is for use by the
927 * presshell only. Reflow code wanting to prevent interrupts should use
928 * InterruptPreventer.
930 void ReflowStarted(bool aInterruptible);
933 * A class that can be used to temporarily disable reflow interruption.
935 class InterruptPreventer;
936 friend class InterruptPreventer;
937 class MOZ_STACK_CLASS InterruptPreventer {
938 public:
939 explicit InterruptPreventer(nsPresContext* aCtx) :
940 mCtx(aCtx),
941 mInterruptsEnabled(aCtx->mInterruptsEnabled),
942 mHasPendingInterrupt(aCtx->mHasPendingInterrupt)
944 mCtx->mInterruptsEnabled = false;
945 mCtx->mHasPendingInterrupt = false;
947 ~InterruptPreventer() {
948 mCtx->mInterruptsEnabled = mInterruptsEnabled;
949 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
952 private:
953 nsPresContext* mCtx;
954 bool mInterruptsEnabled;
955 bool mHasPendingInterrupt;
959 * Check for interrupts. This may return true if a pending event is
960 * detected. Once it has returned true, it will keep returning true
961 * until ReflowStarted is called. In all cases where this returns true,
962 * the passed-in frame (which should be the frame whose reflow will be
963 * interrupted if true is returned) will be passed to
964 * nsIPresShell::FrameNeedsToContinueReflow.
966 bool CheckForInterrupt(nsIFrame* aFrame);
968 * Returns true if CheckForInterrupt has returned true since the last
969 * ReflowStarted call. Cannot itself trigger an interrupt check.
971 bool HasPendingInterrupt() { return mHasPendingInterrupt; }
974 * If we have a presshell, and if the given content's current
975 * document is the same as our presshell's document, return the
976 * content's primary frame. Otherwise, return null. Only use this
977 * if you care about which presshell the primary frame is in.
979 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
981 void NotifyDestroyingFrame(nsIFrame* aFrame)
983 PropertyTable()->DeleteAllFor(aFrame);
986 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
987 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
988 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
991 bool IsRootContentDocument();
992 bool IsCrossProcessRootContentDocument();
994 bool IsGlyph() const {
995 return mIsGlyph;
998 void SetIsGlyph(bool aValue) {
999 mIsGlyph = aValue;
1002 bool UsesRootEMUnits() const {
1003 return mUsesRootEMUnits;
1006 void SetUsesRootEMUnits(bool aValue) {
1007 mUsesRootEMUnits = aValue;
1010 bool UsesViewportUnits() const {
1011 return mUsesViewportUnits;
1014 void SetUsesViewportUnits(bool aValue) {
1015 mUsesViewportUnits = aValue;
1018 // true if there are OMTA transition updates for the current document which
1019 // have been throttled, and therefore some style information may not be up
1020 // to date
1021 bool ExistThrottledUpdates() const {
1022 return mExistThrottledUpdates;
1025 void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
1026 mExistThrottledUpdates = aExistThrottledUpdates;
1029 bool IsDeviceSizePageSize();
1031 bool HasWarnedAboutPositionedTableParts() const {
1032 return mHasWarnedAboutPositionedTableParts;
1035 void SetHasWarnedAboutPositionedTableParts() {
1036 mHasWarnedAboutPositionedTableParts = true;
1039 protected:
1040 friend class nsRunnableMethod<nsPresContext>;
1041 void ThemeChangedInternal();
1042 void SysColorChangedInternal();
1043 void UIResolutionChangedInternal();
1045 static bool
1046 UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument, void* aData);
1048 void SetImgAnimations(nsIContent *aParent, uint16_t aMode);
1049 void SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode,
1050 uint16_t aOldMode);
1051 void GetDocumentColorPreferences();
1053 void PreferenceChanged(const char* aPrefName);
1054 static void PrefChangedCallback(const char*, void*);
1056 void UpdateAfterPreferencesChanged();
1057 static void PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure);
1059 void GetUserPreferences();
1061 // Allow nsAutoPtr<LangGroupFontPrefs> dtor to access this protected struct's
1062 // dtor:
1063 struct LangGroupFontPrefs;
1064 friend class nsAutoPtr<LangGroupFontPrefs>;
1065 struct LangGroupFontPrefs {
1066 // Font sizes default to zero; they will be set in GetFontPreferences
1067 LangGroupFontPrefs()
1068 : mLangGroup(nullptr)
1069 , mMinimumFontSize(0)
1070 , mDefaultVariableFont(mozilla::eFamily_serif, NS_FONT_STYLE_NORMAL,
1071 NS_FONT_WEIGHT_NORMAL,
1072 NS_FONT_STRETCH_NORMAL, 0, 0)
1073 , mDefaultFixedFont(mozilla::eFamily_monospace, NS_FONT_STYLE_NORMAL,
1074 NS_FONT_WEIGHT_NORMAL,
1075 NS_FONT_STRETCH_NORMAL, 0, 0)
1076 , mDefaultSerifFont(mozilla::eFamily_serif, NS_FONT_STYLE_NORMAL,
1077 NS_FONT_WEIGHT_NORMAL,
1078 NS_FONT_STRETCH_NORMAL, 0, 0)
1079 , mDefaultSansSerifFont(mozilla::eFamily_sans_serif,
1080 NS_FONT_STYLE_NORMAL,
1081 NS_FONT_WEIGHT_NORMAL,
1082 NS_FONT_STRETCH_NORMAL, 0, 0)
1083 , mDefaultMonospaceFont(mozilla::eFamily_monospace, NS_FONT_STYLE_NORMAL,
1084 NS_FONT_WEIGHT_NORMAL,
1085 NS_FONT_STRETCH_NORMAL, 0, 0)
1086 , mDefaultCursiveFont(mozilla::eFamily_cursive, NS_FONT_STYLE_NORMAL,
1087 NS_FONT_WEIGHT_NORMAL,
1088 NS_FONT_STRETCH_NORMAL, 0, 0)
1089 , mDefaultFantasyFont(mozilla::eFamily_fantasy, NS_FONT_STYLE_NORMAL,
1090 NS_FONT_WEIGHT_NORMAL,
1091 NS_FONT_STRETCH_NORMAL, 0, 0)
1094 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
1095 size_t n = 0;
1096 LangGroupFontPrefs *curr = mNext;
1097 while (curr) {
1098 n += aMallocSizeOf(curr);
1100 // Measurement of the following members may be added later if DMD finds
1101 // it is worthwhile:
1102 // - mLangGroup
1103 // - mDefault*Font
1105 curr = curr->mNext;
1107 return n;
1110 nsCOMPtr<nsIAtom> mLangGroup;
1111 nscoord mMinimumFontSize;
1112 nsFont mDefaultVariableFont;
1113 nsFont mDefaultFixedFont;
1114 nsFont mDefaultSerifFont;
1115 nsFont mDefaultSansSerifFont;
1116 nsFont mDefaultMonospaceFont;
1117 nsFont mDefaultCursiveFont;
1118 nsFont mDefaultFantasyFont;
1119 nsAutoPtr<LangGroupFontPrefs> mNext;
1123 * Fetch the user's font preferences for the given aLanguage's
1124 * langugage group.
1126 const LangGroupFontPrefs* GetFontPrefsForLang(nsIAtom *aLanguage) const;
1128 void ResetCachedFontPrefs() {
1129 // Throw away any other LangGroupFontPrefs objects:
1130 mLangGroupFontPrefs.mNext = nullptr;
1132 // Make GetFontPreferences reinitialize mLangGroupFontPrefs:
1133 mLangGroupFontPrefs.mLangGroup = nullptr;
1136 void UpdateCharSet(const nsCString& aCharSet);
1138 public:
1139 void DoChangeCharSet(const nsCString& aCharSet);
1142 * Checks for MozAfterPaint listeners on the document
1144 bool MayHavePaintEventListener();
1147 * Checks for MozAfterPaint listeners on the document and
1148 * any subdocuments, except for subdocuments that are non-top-level
1149 * content documents.
1151 bool MayHavePaintEventListenerInSubDocument();
1153 #ifdef RESTYLE_LOGGING
1154 // Controls for whether debug information about restyling in this
1155 // document should be output.
1156 bool RestyleLoggingEnabled() const { return mRestyleLoggingEnabled; }
1157 void StartRestyleLogging() { mRestyleLoggingEnabled = true; }
1158 void StopRestyleLogging() { mRestyleLoggingEnabled = false; }
1159 #endif
1161 protected:
1162 // May be called multiple times (unlink, destructor)
1163 void Destroy();
1165 void InvalidatePaintedLayers();
1166 void AppUnitsPerDevPixelChanged();
1168 void HandleRebuildUserFontSet() {
1169 mPostedFlushUserFontSet = false;
1170 FlushUserFontSet();
1173 void HandleRebuildCounterStyles() {
1174 mPostedFlushCounterStyles = false;
1175 FlushCounterStyles();
1178 bool HavePendingInputEvent();
1180 // Can't be inline because we can't include nsStyleSet.h.
1181 bool HasCachedStyleData();
1183 bool IsChromeSlow() const;
1185 // IMPORTANT: The ownership implicit in the following member variables
1186 // has been explicitly checked. If you add any members to this class,
1187 // please make the ownership explicit (pinkerton, scc).
1189 nsPresContextType mType;
1190 nsIPresShell* mShell; // [WEAK]
1191 nsCOMPtr<nsIDocument> mDocument;
1192 nsRefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1193 // better safe than sorry.
1194 // Cannot reintroduce cycles
1195 // since there is no dependency
1196 // from gfx back to layout.
1197 nsRefPtr<mozilla::EventStateManager> mEventManager;
1198 nsRefPtr<nsRefreshDriver> mRefreshDriver;
1199 nsRefPtr<nsTransitionManager> mTransitionManager;
1200 nsRefPtr<nsAnimationManager> mAnimationManager;
1201 nsRefPtr<mozilla::RestyleManager> mRestyleManager;
1202 nsRefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
1203 nsIAtom* mMedium; // initialized by subclass ctors;
1204 // weak pointer to static atom
1205 nsCOMPtr<nsIAtom> mMediaEmulated;
1207 nsILinkHandler* mLinkHandler; // [WEAK]
1209 // Formerly mLangGroup; moving from charset-oriented langGroup to
1210 // maintaining actual language settings everywhere (see bug 524107).
1211 // This may in fact hold a langGroup such as x-western rather than
1212 // a specific language, however (e.g, if it is inferred from the
1213 // charset rather than explicitly specified as a lang attribute).
1214 nsCOMPtr<nsIAtom> mLanguage;
1216 public:
1217 // The following are public member variables so that we can use them
1218 // with mozilla::AutoToggle or mozilla::AutoRestore.
1220 // Should we disable font size inflation because we're inside of
1221 // shrink-wrapping calculations on an inflation container?
1222 bool mInflationDisabledForShrinkWrap;
1224 protected:
1226 mozilla::WeakPtr<nsDocShell> mContainer;
1228 // Base minimum font size, independent of the language-specific global preference. Defaults to 0
1229 int32_t mBaseMinFontSize;
1230 float mTextZoom; // Text zoom, defaults to 1.0
1231 float mFullZoom; // Page zoom, defaults to 1.0
1233 float mLastFontInflationScreenWidth;
1235 int32_t mCurAppUnitsPerDevPixel;
1236 int32_t mAutoQualityMinFontSizePixelsPref;
1238 nsCOMPtr<nsITheme> mTheme;
1239 nsCOMPtr<nsILanguageAtomService> mLangService;
1240 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1241 nsCOMPtr<nsITimer> mPrefChangedTimer;
1243 FramePropertyTable mPropertyTable;
1245 nsInvalidateRequestList mInvalidateRequestsSinceLastPaint;
1246 nsInvalidateRequestList mUndeliveredInvalidateRequestsBeforeLastPaint;
1248 // container for per-context fonts (downloadable, SVG, etc.)
1249 nsRefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
1251 // text performance metrics
1252 nsAutoPtr<gfxTextPerfMetrics> mTextPerf;
1254 nsRect mVisibleArea;
1255 nsSize mPageSize;
1256 float mPageScale;
1257 float mPPScale;
1259 nscolor mDefaultColor;
1260 nscolor mBackgroundColor;
1262 nscolor mLinkColor;
1263 nscolor mActiveLinkColor;
1264 nscolor mVisitedLinkColor;
1266 nscolor mFocusBackgroundColor;
1267 nscolor mFocusTextColor;
1269 nscolor mBodyTextColor;
1271 ScrollbarStyles mViewportStyleScrollbar;
1272 uint8_t mFocusRingWidth;
1274 bool mExistThrottledUpdates;
1276 uint16_t mImageAnimationMode;
1277 uint16_t mImageAnimationModePref;
1279 LangGroupFontPrefs mLangGroupFontPrefs;
1281 nscoord mBorderWidthTable[3];
1283 uint32_t mInterruptChecksToSkip;
1285 mozilla::TimeStamp mReflowStartTime;
1287 // last time we did a full style flush
1288 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1290 unsigned mHasPendingInterrupt : 1;
1291 unsigned mInterruptsEnabled : 1;
1292 unsigned mUseDocumentFonts : 1;
1293 unsigned mUseDocumentColors : 1;
1294 unsigned mUnderlineLinks : 1;
1295 unsigned mSendAfterPaintToContent : 1;
1296 unsigned mUseFocusColors : 1;
1297 unsigned mFocusRingOnAnything : 1;
1298 unsigned mFocusRingStyle : 1;
1299 unsigned mDrawImageBackground : 1;
1300 unsigned mDrawColorBackground : 1;
1301 unsigned mNeverAnimate : 1;
1302 unsigned mIsRenderingOnlySelection : 1;
1303 unsigned mPaginated : 1;
1304 unsigned mCanPaginatedScroll : 1;
1305 unsigned mDoScaledTwips : 1;
1306 unsigned mIsRootPaginatedDocument : 1;
1307 unsigned mPrefBidiDirection : 1;
1308 unsigned mPrefScrollbarSide : 2;
1309 unsigned mPendingSysColorChanged : 1;
1310 unsigned mPendingThemeChanged : 1;
1311 unsigned mPendingUIResolutionChanged : 1;
1312 unsigned mPendingMediaFeatureValuesChanged : 1;
1313 unsigned mPrefChangePendingNeedsReflow : 1;
1314 unsigned mIsEmulatingMedia : 1;
1315 // True if the requests in mInvalidateRequestsSinceLastPaint cover the
1316 // entire viewport
1317 unsigned mAllInvalidated : 1;
1319 // Are we currently drawing an SVG glyph?
1320 unsigned mIsGlyph : 1;
1322 // Does the associated document use root-em (rem) units?
1323 unsigned mUsesRootEMUnits : 1;
1324 // Does the associated document use viewport units (vw/vh/vmin/vmax)?
1325 unsigned mUsesViewportUnits : 1;
1327 // Has there been a change to the viewport's dimensions?
1328 unsigned mPendingViewportChange : 1;
1330 // Is the current mFontFaceSet valid?
1331 unsigned mFontFaceSetDirty : 1;
1332 // Has GetUserFontSet() been called?
1333 unsigned mGetUserFontSetCalled : 1;
1334 // Do we currently have an event posted to call FlushUserFontSet?
1335 unsigned mPostedFlushUserFontSet : 1;
1337 // Is the current mCounterStyleManager valid?
1338 unsigned mCounterStylesDirty : 1;
1339 // Do we currently have an event posted to call FlushCounterStyles?
1340 unsigned mPostedFlushCounterStyles: 1;
1342 // resize reflow is suppressed when the only change has been to zoom
1343 // the document rather than to change the document's dimensions
1344 unsigned mSupressResizeReflow : 1;
1346 unsigned mIsVisual : 1;
1348 unsigned mFireAfterPaintEvents : 1;
1350 unsigned mIsChrome : 1;
1351 unsigned mIsChromeOriginImage : 1;
1353 // Should we paint flash in this context? Do not use this variable directly.
1354 // Use GetPaintFlashing() method instead.
1355 mutable unsigned mPaintFlashing : 1;
1356 mutable unsigned mPaintFlashingInitialized : 1;
1358 unsigned mHasWarnedAboutPositionedTableParts : 1;
1360 #ifdef RESTYLE_LOGGING
1361 // Should we output debug information about restyling for this document?
1362 bool mRestyleLoggingEnabled;
1363 #endif
1365 #ifdef DEBUG
1366 bool mInitialized;
1367 #endif
1370 protected:
1372 virtual ~nsPresContext();
1374 // these are private, use the list in nsFont.h if you want a public list
1375 enum {
1376 eDefaultFont_Variable,
1377 eDefaultFont_Fixed,
1378 eDefaultFont_Serif,
1379 eDefaultFont_SansSerif,
1380 eDefaultFont_Monospace,
1381 eDefaultFont_Cursive,
1382 eDefaultFont_Fantasy,
1383 eDefaultFont_COUNT
1386 nscolor MakeColorPref(const nsString& aColor);
1388 void LastRelease();
1390 #ifdef DEBUG
1391 private:
1392 friend struct nsAutoLayoutPhase;
1393 uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT];
1394 public:
1395 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1396 return mLayoutPhaseCount[aPhase];
1398 #endif
1402 class nsRootPresContext MOZ_FINAL : public nsPresContext {
1403 public:
1404 nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType);
1405 virtual ~nsRootPresContext();
1406 virtual void Detach() MOZ_OVERRIDE;
1409 * Ensure that NotifyDidPaintForSubtree is eventually called on this
1410 * object after a timeout.
1412 void EnsureEventualDidPaintEvent();
1414 void CancelDidPaintTimer()
1416 if (mNotifyDidPaintTimer) {
1417 mNotifyDidPaintTimer->Cancel();
1418 mNotifyDidPaintTimer = nullptr;
1423 * Registers a plugin to receive geometry updates (position and clip
1424 * region) so it can update its widget.
1425 * Callers must call UnregisterPluginForGeometryUpdates before
1426 * the aPlugin frame is destroyed.
1428 void RegisterPluginForGeometryUpdates(nsIContent* aPlugin);
1430 * Stops a plugin receiving geometry updates (position and clip
1431 * region). If the plugin was not already registered, this does
1432 * nothing.
1434 void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin);
1436 bool NeedToComputePluginGeometryUpdates()
1438 return mRegisteredPlugins.Count() > 0;
1441 * Compute geometry updates for each plugin given that aList is the display
1442 * list for aFrame. The updates are not yet applied;
1443 * ApplyPluginGeometryUpdates is responsible for that. In the meantime they
1444 * are stored on each nsPluginFrame.
1445 * This needs to be called even when aFrame is a popup, since although
1446 * windowed plugins aren't allowed in popups, windowless plugins are
1447 * and ComputePluginGeometryUpdates needs to be called for them.
1449 void ComputePluginGeometryUpdates(nsIFrame* aFrame,
1450 nsDisplayListBuilder* aBuilder,
1451 nsDisplayList* aList);
1454 * Apply the stored plugin geometry updates. This should normally be called
1455 * in DidPaint so the plugins are moved/clipped immediately after we've
1456 * updated our window, so they look in sync with our window.
1458 void ApplyPluginGeometryUpdates();
1460 virtual bool IsRoot() MOZ_OVERRIDE { return true; }
1463 * Increment DOM-modification generation counter to indicate that
1464 * the DOM has changed in a way that might lead to style changes/
1465 * reflows/frame creation and destruction.
1467 void IncrementDOMGeneration() { mDOMGeneration++; }
1470 * Get the current DOM generation counter.
1472 * See nsFrameManagerBase::GetGlobalGenerationNumber() for a
1473 * global generation number.
1475 uint32_t GetDOMGeneration() { return mDOMGeneration; }
1478 * Add a runnable that will get called before the next paint. They will get
1479 * run eventually even if painting doesn't happen. They might run well before
1480 * painting happens.
1482 void AddWillPaintObserver(nsIRunnable* aRunnable);
1485 * Run all runnables that need to get called before the next paint.
1487 void FlushWillPaintObservers();
1489 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
1491 protected:
1493 * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates.
1495 void InitApplyPluginGeometryTimer();
1497 * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates.
1499 void CancelApplyPluginGeometryTimer();
1501 class RunWillPaintObservers : public nsRunnable {
1502 public:
1503 explicit RunWillPaintObservers(nsRootPresContext* aPresContext) : mPresContext(aPresContext) {}
1504 void Revoke() { mPresContext = nullptr; }
1505 NS_IMETHOD Run() MOZ_OVERRIDE
1507 if (mPresContext) {
1508 mPresContext->FlushWillPaintObservers();
1510 return NS_OK;
1512 nsRootPresContext* mPresContext;
1515 friend class nsPresContext;
1517 nsCOMPtr<nsITimer> mNotifyDidPaintTimer;
1518 nsCOMPtr<nsITimer> mApplyPluginGeometryTimer;
1519 nsTHashtable<nsRefPtrHashKey<nsIContent> > mRegisteredPlugins;
1520 nsTArray<nsCOMPtr<nsIRunnable> > mWillPaintObservers;
1521 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1522 uint32_t mDOMGeneration;
1525 #ifdef MOZ_REFLOW_PERF
1527 #define DO_GLOBAL_REFLOW_COUNT(_name) \
1528 aPresContext->CountReflows((_name), (nsIFrame*)this);
1529 #else
1530 #define DO_GLOBAL_REFLOW_COUNT(_name)
1531 #endif // MOZ_REFLOW_PERF
1533 #endif /* nsPresContext_h___ */