Bumping manifests a=b2g-bump
[gecko.git] / layout / base / nsPresContext.h
blobc6664c9316792649226c3df838db6bfda992e26e
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"
41 class nsBidiPresUtils;
42 class nsAString;
43 class nsIPrintSettings;
44 class nsDocShell;
45 class nsIDocShell;
46 class nsIDocument;
47 class nsILanguageAtomService;
48 class nsITheme;
49 class nsIContent;
50 class nsIFrame;
51 class nsFrameManager;
52 class nsILinkHandler;
53 class nsIAtom;
54 class nsICSSPseudoComparator;
55 struct nsStyleBackground;
56 struct nsStyleBorder;
57 class nsIRunnable;
58 class gfxUserFontSet;
59 class gfxTextPerfMetrics;
60 class nsUserFontSet;
61 struct nsFontFaceRuleContainer;
62 class nsObjectFrame;
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 MediaQueryList;
76 namespace layers {
77 class ContainerLayer;
81 // supported values for cached bool types
82 enum nsPresContext_CachedBoolPrefType {
83 kPresContext_UseDocumentColors = 1,
84 kPresContext_UseDocumentFonts,
85 kPresContext_UnderlineLinks
88 // supported values for cached integer pref types
89 enum nsPresContext_CachedIntPrefType {
90 kPresContext_ScrollbarSide = 1,
91 kPresContext_BidiDirection
94 // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
95 // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
96 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable
97 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed
99 #ifdef DEBUG
100 struct nsAutoLayoutPhase;
102 enum nsLayoutPhase {
103 eLayoutPhase_Paint,
104 eLayoutPhase_Reflow,
105 eLayoutPhase_FrameC,
106 eLayoutPhase_COUNT
108 #endif
110 class nsInvalidateRequestList {
111 public:
112 struct Request {
113 nsRect mRect;
114 uint32_t mFlags;
117 void TakeFrom(nsInvalidateRequestList* aList)
119 mRequests.MoveElementsFrom(aList->mRequests);
121 bool IsEmpty() { return mRequests.IsEmpty(); }
123 nsTArray<Request> mRequests;
126 /* Used by nsPresContext::HasAuthorSpecifiedRules */
127 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
128 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
129 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
130 #define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3)
132 class nsRootPresContext;
134 // An interface for presentation contexts. Presentation contexts are
135 // objects that provide an outer context for a presentation shell.
137 class nsPresContext : public nsIObserver {
138 public:
139 typedef mozilla::FramePropertyTable FramePropertyTable;
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 // Policies for rebuilding style data.
154 enum StyleRebuildType {
155 eRebuildStyleIfNeeded,
156 eAlwaysRebuildStyle
159 nsPresContext(nsIDocument* aDocument, nsPresContextType aType);
162 * Initialize the presentation context from a particular device.
164 nsresult Init(nsDeviceContext* aDeviceContext);
167 * Set the presentation shell that this context is bound to.
168 * A presentation context may only be bound to a single shell.
170 void SetShell(nsIPresShell* aShell);
173 nsPresContextType Type() const { return mType; }
176 * Get the PresentationShell that this context is bound to.
178 nsIPresShell* PresShell() const
180 NS_ASSERTION(mShell, "Null pres shell");
181 return mShell;
184 nsIPresShell* GetPresShell() const { return mShell; }
187 * Returns the parent prescontext for this one. Returns null if this is a
188 * root.
190 nsPresContext* GetParentPresContext();
193 * Returns the prescontext of the toplevel content document that contains
194 * this presentation, or null if there isn't one.
196 nsPresContext* GetToplevelContentDocumentPresContext();
199 * Returns the nearest widget for the root frame of this.
201 * @param aOffset If non-null the offset from the origin of the root
202 * frame's view to the widget's origin (usually positive)
203 * expressed in appunits of this will be returned in
204 * aOffset.
206 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
209 * Returns the root widget for this.
210 * Note that the widget is a mediater with IME.
212 nsIWidget* GetRootWidget();
215 * Return the presentation context for the root of the view manager
216 * hierarchy that contains this presentation context, or nullptr if it can't
217 * be found (e.g. it's detached).
219 nsRootPresContext* GetRootPresContext();
220 nsRootPresContext* GetDisplayRootPresContext();
221 virtual bool IsRoot() { return false; }
223 nsIDocument* Document() const
225 NS_ASSERTION(!mShell || !mShell->GetDocument() ||
226 mShell->GetDocument() == mDocument,
227 "nsPresContext doesn't have the same document as nsPresShell!");
228 return mDocument;
231 #ifdef MOZILLA_INTERNAL_API
232 nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); }
234 nsFrameManager* FrameManager()
235 { return PresShell()->FrameManager(); }
237 nsCSSFrameConstructor* FrameConstructor()
238 { return PresShell()->FrameConstructor(); }
240 nsTransitionManager* TransitionManager() { return mTransitionManager; }
241 nsAnimationManager* AnimationManager() { return mAnimationManager; }
243 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
245 mozilla::RestyleManager* RestyleManager() { return mRestyleManager; }
247 mozilla::CounterStyleManager* CounterStyleManager() {
248 return mCounterStyleManager;
250 #endif
253 * Rebuilds all style data by throwing out the old rule tree and
254 * building a new one, and additionally applying aExtraHint (which
255 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
256 * Also rebuild the user font set and counter style manager.
258 void RebuildAllStyleData(nsChangeHint aExtraHint);
260 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
261 * doesn't rebuild the user font set.
263 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint);
265 void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild,
266 nsChangeHint aChangeHint = nsChangeHint(0));
267 void PostMediaFeatureValuesChangedEvent();
268 void HandleMediaFeatureValuesChangedEvent();
269 void FlushPendingMediaFeatureValuesChanged() {
270 if (mPendingMediaFeatureValuesChanged)
271 MediaFeatureValuesChanged(eRebuildStyleIfNeeded);
275 * Support for window.matchMedia()
277 already_AddRefed<mozilla::dom::MediaQueryList>
278 MatchMedia(const nsAString& aMediaQueryList);
281 * Access compatibility mode for this context. This is the same as
282 * our document's compatibility mode.
284 nsCompatibility CompatibilityMode() const;
287 * Notify the context that the document's compatibility mode has changed
289 void CompatibilityModeChanged();
292 * Access the image animation mode for this context
294 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
295 virtual void SetImageAnimationModeExternal(uint16_t aMode);
296 void SetImageAnimationModeInternal(uint16_t aMode);
297 #ifdef MOZILLA_INTERNAL_API
298 void SetImageAnimationMode(uint16_t aMode)
299 { SetImageAnimationModeInternal(aMode); }
300 #else
301 void SetImageAnimationMode(uint16_t aMode)
302 { SetImageAnimationModeExternal(aMode); }
303 #endif
306 * Get medium of presentation
308 nsIAtom* Medium() {
309 if (!mIsEmulatingMedia)
310 return mMedium;
311 return mMediaEmulated;
315 * Render the document as if being viewed on a device with the specified
316 * media type.
318 void EmulateMedium(const nsAString& aMediaType);
321 * Restore the viewer's natural medium
323 void StopEmulatingMedium();
325 void* AllocateFromShell(size_t aSize)
327 if (mShell)
328 return mShell->AllocateMisc(aSize);
329 return nullptr;
332 void FreeToShell(size_t aSize, void* aFreeChunk)
334 NS_ASSERTION(mShell, "freeing after shutdown");
335 if (mShell)
336 mShell->FreeMisc(aSize, aFreeChunk);
340 * Get the default font for the given language and generic font ID.
341 * If aLanguage is nullptr, the document's language is used.
343 * This object is read-only, you must copy the font to modify it.
345 * When aFontID is kPresContext_DefaultVariableFontID or
346 * kPresContext_DefaultFixedFontID (which equals
347 * kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
348 * the nsFont returned has its name as a CSS generic family (serif or
349 * sans-serif for the former, monospace for the latter), and its size
350 * as the default font size for variable or fixed fonts for the
351 * language group.
353 * For aFontID corresponding to a CSS Generic, the nsFont returned has
354 * its name set to that generic font's name, and its size set to
355 * the user's preference for font size for that generic and the
356 * given language.
358 const nsFont* GetDefaultFont(uint8_t aFontID,
359 nsIAtom *aLanguage) const;
361 /** Get a cached boolean pref, by its type */
362 // * - initially created for bugs 31816, 20760, 22963
363 bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const
365 // If called with a constant parameter, the compiler should optimize
366 // this switch statement away.
367 switch (aPrefType) {
368 case kPresContext_UseDocumentFonts:
369 return mUseDocumentFonts;
370 case kPresContext_UseDocumentColors:
371 return mUseDocumentColors;
372 case kPresContext_UnderlineLinks:
373 return mUnderlineLinks;
374 default:
375 NS_ERROR("Invalid arg passed to GetCachedBoolPref");
378 return false;
381 /** Get a cached integer pref, by its type */
382 // * - initially created for bugs 30910, 61883, 74186, 84398
383 int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const
385 // If called with a constant parameter, the compiler should optimize
386 // this switch statement away.
387 switch (aPrefType) {
388 case kPresContext_ScrollbarSide:
389 return mPrefScrollbarSide;
390 case kPresContext_BidiDirection:
391 return mPrefBidiDirection;
392 default:
393 NS_ERROR("invalid arg passed to GetCachedIntPref");
396 return false;
400 * Get the default colors
402 const nscolor DefaultColor() const { return mDefaultColor; }
403 const nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
404 const nscolor DefaultLinkColor() const { return mLinkColor; }
405 const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
406 const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
407 const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
408 const nscolor FocusTextColor() const { return mFocusTextColor; }
411 * Body text color, for use in quirks mode only.
413 const nscolor BodyTextColor() const { return mBodyTextColor; }
414 void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; }
416 bool GetUseFocusColors() const { return mUseFocusColors; }
417 uint8_t FocusRingWidth() const { return mFocusRingWidth; }
418 bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
419 uint8_t GetFocusRingStyle() const { return mFocusRingStyle; }
421 void SetContainer(nsIDocShell* aContainer);
423 virtual nsISupports* GetContainerWeakExternal() const;
424 nsISupports* GetContainerWeakInternal() const;
425 #ifdef MOZILLA_INTERNAL_API
426 nsISupports* GetContainerWeak() const
427 { return GetContainerWeakInternal(); }
428 #else
429 nsISupports* GetContainerWeak() const
430 { return GetContainerWeakExternal(); }
431 #endif
433 nsIDocShell* GetDocShell() const;
435 // XXX this are going to be replaced with set/get container
436 void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
437 nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
440 * Detach this pres context - i.e. cancel relevant timers,
441 * SetLinkHandler(null), SetContainer(null) etc.
442 * Only to be used by the DocumentViewer.
444 virtual void Detach();
447 * Get the visible area associated with this presentation context.
448 * This is the size of the visible area that is used for
449 * presenting the document. The returned value is in the standard
450 * nscoord units (as scaled by the device context).
452 nsRect GetVisibleArea() { return mVisibleArea; }
455 * Set the currently visible area. The units for r are standard
456 * nscoord units (as scaled by the device context).
458 void SetVisibleArea(const nsRect& r) {
459 if (!r.IsEqualEdges(mVisibleArea)) {
460 mVisibleArea = r;
461 // Visible area does not affect media queries when paginated.
462 if (!IsPaginated() && HasCachedStyleData()) {
463 mPendingViewportChange = true;
464 PostMediaFeatureValuesChangedEvent();
470 * Return true if this presentation context is a paginated
471 * context.
473 bool IsPaginated() const { return mPaginated; }
476 * Sets whether the presentation context can scroll for a paginated
477 * context.
479 void SetPaginatedScrolling(bool aResult);
482 * Return true if this presentation context can scroll for paginated
483 * context.
485 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
488 * Get/set the size of a page
490 nsSize GetPageSize() { return mPageSize; }
491 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
494 * Get/set whether this document should be treated as having real pages
495 * XXX This raises the obvious question of why a document that isn't a page
496 * is paginated; there isn't a good reason except history
498 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
499 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument)
500 { mIsRootPaginatedDocument = aIsRootPaginatedDocument; }
503 * Get/set the print scaling level; used by nsPageFrame to scale up
504 * pages. Set safe to call before reflow, get guaranteed to be set
505 * properly after reflow.
508 float GetPageScale() { return mPageScale; }
509 void SetPageScale(float aScale) { mPageScale = aScale; }
512 * Get/set the scaling facor to use when rendering the pages for print preview.
513 * Only safe to get after print preview set up; safe to set anytime.
514 * This is a scaling factor for the display of the print preview. It
515 * does not affect layout. It only affects the size of the onscreen pages
516 * in print preview.
517 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
519 float GetPrintPreviewScale() { return mPPScale; }
520 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
522 nsDeviceContext* DeviceContext() { return mDeviceContext; }
523 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
524 nsIAtom* GetLanguageFromCharset() { return mLanguage; }
526 float TextZoom() { return mTextZoom; }
527 void SetTextZoom(float aZoom) {
528 if (aZoom == mTextZoom)
529 return;
531 mTextZoom = aZoom;
532 if (HasCachedStyleData()) {
533 // Media queries could have changed, since we changed the meaning
534 // of 'em' units in them.
535 MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
540 * Get the minimum font size for the specified language. If aLanguage
541 * is nullptr, then the document's language is used. This combines
542 * the language-specific global preference with the per-presentation
543 * base minimum font size.
545 int32_t MinFontSize(nsIAtom *aLanguage) const {
546 const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
547 return std::max(mBaseMinFontSize, prefs->mMinimumFontSize);
551 * Get the per-presentation base minimum font size. This size is
552 * independent of the language-specific global preference.
554 int32_t BaseMinFontSize() const {
555 return mBaseMinFontSize;
559 * Set the per-presentation base minimum font size. This size is
560 * independent of the language-specific global preference.
562 void SetBaseMinFontSize(int32_t aMinFontSize) {
563 if (aMinFontSize == mBaseMinFontSize)
564 return;
566 mBaseMinFontSize = aMinFontSize;
567 if (HasCachedStyleData()) {
568 // Media queries could have changed, since we changed the meaning
569 // of 'em' units in them.
570 MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
574 float GetFullZoom() { return mFullZoom; }
575 void SetFullZoom(float aZoom);
577 nscoord GetAutoQualityMinFontSize() {
578 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
582 * Return the device's screen width in inches, for font size
583 * inflation.
585 * If |aChanged| is non-null, then aChanged is filled in with whether
586 * the return value has changed since either:
587 * a. the last time the function was called with non-null aChanged, or
588 * b. the first time the function was called.
590 float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr);
592 static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
593 int32_t AppUnitsPerDevPixel() const;
594 static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); }
596 static nscoord CSSPixelsToAppUnits(int32_t aPixels)
597 { return NSToCoordRoundWithClamp(float(aPixels) *
598 float(AppUnitsPerCSSPixel())); }
600 static nscoord CSSPixelsToAppUnits(float aPixels)
601 { return NSToCoordRoundWithClamp(aPixels *
602 float(AppUnitsPerCSSPixel())); }
604 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits)
605 { return NSAppUnitsToIntPixels(aAppUnits,
606 float(AppUnitsPerCSSPixel())); }
608 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits)
609 { return NSAppUnitsToFloatPixels(aAppUnits,
610 float(AppUnitsPerCSSPixel())); }
612 nscoord DevPixelsToAppUnits(int32_t aPixels) const
613 { return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel()); }
615 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const
616 { return NSAppUnitsToIntPixels(aAppUnits,
617 float(AppUnitsPerDevPixel())); }
619 int32_t CSSPixelsToDevPixels(int32_t aPixels)
620 { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }
622 float CSSPixelsToDevPixels(float aPixels)
624 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
625 float(AppUnitsPerDevPixel()));
628 int32_t DevPixelsToIntCSSPixels(int32_t aPixels)
629 { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); }
631 float DevPixelsToFloatCSSPixels(int32_t aPixels)
632 { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); }
634 // If there is a remainder, it is rounded to nearest app units.
635 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
637 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
639 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const
640 { return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
641 AppUnitsToGfxUnits(aAppRect.y),
642 AppUnitsToGfxUnits(aAppRect.width),
643 AppUnitsToGfxUnits(aAppRect.height)); }
645 static nscoord CSSTwipsToAppUnits(float aTwips)
646 { return NSToCoordRoundWithClamp(
647 mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); }
649 // Margin-specific version, since they often need TwipsToAppUnits
650 static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips)
651 { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
652 CSSTwipsToAppUnits(float(marginInTwips.right)),
653 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
654 CSSTwipsToAppUnits(float(marginInTwips.left))); }
656 static nscoord CSSPointsToAppUnits(float aPoints)
657 { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
658 POINTS_PER_INCH_FLOAT); }
660 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
661 { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
663 void SetViewportOverflowOverride(uint8_t aX, uint8_t aY)
665 mViewportStyleOverflow.mHorizontal = aX;
666 mViewportStyleOverflow.mVertical = aY;
668 mozilla::ScrollbarStyles GetViewportOverflowOverride()
670 return mViewportStyleOverflow;
674 * Set and get methods for controlling the background drawing
676 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
677 void SetBackgroundImageDraw(bool aCanDraw)
679 mDrawImageBackground = aCanDraw;
682 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
683 void SetBackgroundColorDraw(bool aCanDraw)
685 mDrawColorBackground = aCanDraw;
689 * Getter and setter for OMTA time counters
691 bool StyleUpdateForAllAnimationsIsUpToDate();
692 void TickLastStyleUpdateForAllAnimations();
695 * Check if bidi enabled (set depending on the presence of RTL
696 * characters or when default directionality is RTL).
697 * If enabled, we should apply the Unicode Bidi Algorithm
699 * @lina 07/12/2000
701 #ifdef MOZILLA_INTERNAL_API
702 bool BidiEnabled() const { return BidiEnabledInternal(); }
703 #else
704 bool BidiEnabled() const { return BidiEnabledExternal(); }
705 #endif
706 virtual bool BidiEnabledExternal() const;
707 bool BidiEnabledInternal() const;
710 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
712 * @lina 07/12/2000
714 void SetBidiEnabled() const;
717 * Set visual or implicit mode into the pres context.
719 * Visual directionality is a presentation method that displays text
720 * as if it were a uni-directional, according to the primary display
721 * direction only.
723 * Implicit directionality is a presentation method in which the
724 * direction is determined by the Bidi algorithm according to the
725 * category of the characters and the category of the adjacent
726 * characters, and according to their primary direction.
728 * @lina 05/02/2000
730 void SetVisualMode(bool aIsVisual)
732 mIsVisual = aIsVisual;
736 * Check whether the content should be treated as visual.
738 * @lina 05/02/2000
740 bool IsVisualMode() const { return mIsVisual; }
742 //Mohamed
745 * Set the Bidi options for the presentation context
747 void SetBidi(uint32_t aBidiOptions,
748 bool aForceRestyle = false);
751 * Get the Bidi options for the presentation context
752 * Not inline so consumers of nsPresContext are not forced to
753 * include nsIDocument.
755 uint32_t GetBidi() const;
758 * Render only Selection
760 void SetIsRenderingOnlySelection(bool aResult)
762 mIsRenderingOnlySelection = aResult;
765 bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; }
767 bool IsTopLevelWindowInactive();
770 * Obtain a native them for rendering our widgets (both form controls and html)
772 nsITheme* GetTheme();
775 * Notify the pres context that the theme has changed. An internal switch
776 * means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
777 * Otherwise, the OS is telling us that the native theme for the platform
778 * has changed.
780 void ThemeChanged();
783 * Notify the pres context that the resolution of the user interface has
784 * changed. This happens if a window is moved between HiDPI and non-HiDPI
785 * displays, so that the ratio of points to device pixels changes.
787 void UIResolutionChanged();
790 * Recursively notify all remote leaf descendants of a given message manager
791 * that the resolution of the user interface has changed.
793 void NotifyUIResolutionChanged(nsIMessageBroadcaster* aManager);
796 * Notify the pres context that a system color has changed
798 void SysColorChanged();
800 /** Printing methods below should only be used for Medium() == print **/
801 void SetPrintSettings(nsIPrintSettings *aPrintSettings);
803 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
805 /* Accessor for table of frame properties */
806 FramePropertyTable* PropertyTable() { return &mPropertyTable; }
808 /* Helper function that ensures that this prescontext is shown in its
809 docshell if it's the most recent prescontext for the docshell. Returns
810 whether the prescontext is now being shown.
812 bool EnsureVisible();
814 #ifdef MOZ_REFLOW_PERF
815 void CountReflows(const char * aName,
816 nsIFrame * aFrame);
817 #endif
820 * This table maps border-width enums 'thin', 'medium', 'thick'
821 * to actual nscoord values.
823 const nscoord* GetBorderWidthTable() { return mBorderWidthTable; }
825 gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; }
827 bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); }
828 bool IsScreen() { return (mMedium == nsGkAtoms::screen ||
829 mType == eContext_PageLayout ||
830 mType == eContext_PrintPreview); }
832 // Is this presentation in a chrome docshell?
833 bool IsChrome() const { return mIsChrome; }
834 bool IsChromeOriginImage() const { return mIsChromeOriginImage; }
835 void UpdateIsChrome();
837 // Public API for native theme code to get style internals.
838 virtual bool HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const;
840 // Is it OK to let the page specify colors and backgrounds?
841 bool UseDocumentColors() const {
842 return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome() || IsChromeOriginImage();
845 // Explicitly enable and disable paint flashing.
846 void SetPaintFlashing(bool aPaintFlashing) {
847 mPaintFlashing = aPaintFlashing;
848 mPaintFlashingInitialized = true;
851 // This method should be used instead of directly accessing mPaintFlashing,
852 // as that value may be out of date when mPaintFlashingInitialized is false.
853 bool GetPaintFlashing() const;
855 bool SupressingResizeReflow() const { return mSupressResizeReflow; }
857 virtual gfxUserFontSet* GetUserFontSetExternal();
858 gfxUserFontSet* GetUserFontSetInternal();
859 #ifdef MOZILLA_INTERNAL_API
860 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); }
861 #else
862 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); }
863 #endif
865 void FlushUserFontSet();
866 void RebuildUserFontSet(); // asynchronously
868 // Should be called whenever the set of fonts available in the user
869 // font set changes (e.g., because a new font loads, or because the
870 // user font set is changed and fonts become unavailable).
871 void UserFontSetUpdated();
873 void FlushCounterStyles();
874 void RebuildCounterStyles(); // asynchronously
876 // Ensure that it is safe to hand out CSS rules outside the layout
877 // engine by ensuring that all CSS style sheets have unique inners
878 // and, if necessary, synchronously rebuilding all style data.
879 void EnsureSafeToHandOutCSSRules();
881 void NotifyInvalidation(uint32_t aFlags);
882 void NotifyInvalidation(const nsRect& aRect, uint32_t aFlags);
883 // aRect is in device pixels
884 void NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags);
885 // aFlags are nsIPresShell::PAINT_ flags
886 void NotifyDidPaintForSubtree(uint32_t aFlags);
887 void FireDOMPaintEvent(nsInvalidateRequestList* aList);
889 // Callback for catching invalidations in ContainerLayers
890 // Passed to LayerProperties::ComputeDifference
891 static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer,
892 const nsIntRegion& aRegion);
893 void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer);
894 static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer);
895 bool IsDOMPaintEventPending();
896 void ClearMozAfterPaintEvents() {
897 mInvalidateRequestsSinceLastPaint.mRequests.Clear();
898 mUndeliveredInvalidateRequestsBeforeLastPaint.mRequests.Clear();
899 mAllInvalidated = false;
902 bool IsProcessingRestyles() const {
903 return mProcessingRestyles;
906 void SetProcessingRestyles(bool aProcessing) {
907 NS_ASSERTION(aProcessing != bool(mProcessingRestyles),
908 "should never nest");
909 mProcessingRestyles = aProcessing;
912 bool IsProcessingAnimationStyleChange() const {
913 return mProcessingAnimationStyleChange;
916 void SetProcessingAnimationStyleChange(bool aProcessing) {
917 NS_ASSERTION(aProcessing != bool(mProcessingAnimationStyleChange),
918 "should never nest");
919 mProcessingAnimationStyleChange = aProcessing;
923 * Notify the prescontext that the presshell is about to reflow a reflow root.
924 * The single argument indicates whether this reflow should be interruptible.
925 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
926 * will always return false. If aInterruptible is true then CheckForInterrupt
927 * will return true when a pending event is detected. This is for use by the
928 * presshell only. Reflow code wanting to prevent interrupts should use
929 * InterruptPreventer.
931 void ReflowStarted(bool aInterruptible);
934 * A class that can be used to temporarily disable reflow interruption.
936 class InterruptPreventer;
937 friend class InterruptPreventer;
938 class MOZ_STACK_CLASS InterruptPreventer {
939 public:
940 explicit InterruptPreventer(nsPresContext* aCtx) :
941 mCtx(aCtx),
942 mInterruptsEnabled(aCtx->mInterruptsEnabled),
943 mHasPendingInterrupt(aCtx->mHasPendingInterrupt)
945 mCtx->mInterruptsEnabled = false;
946 mCtx->mHasPendingInterrupt = false;
948 ~InterruptPreventer() {
949 mCtx->mInterruptsEnabled = mInterruptsEnabled;
950 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
953 private:
954 nsPresContext* mCtx;
955 bool mInterruptsEnabled;
956 bool mHasPendingInterrupt;
960 * Check for interrupts. This may return true if a pending event is
961 * detected. Once it has returned true, it will keep returning true
962 * until ReflowStarted is called. In all cases where this returns true,
963 * the passed-in frame (which should be the frame whose reflow will be
964 * interrupted if true is returned) will be passed to
965 * nsIPresShell::FrameNeedsToContinueReflow.
967 bool CheckForInterrupt(nsIFrame* aFrame);
969 * Returns true if CheckForInterrupt has returned true since the last
970 * ReflowStarted call. Cannot itself trigger an interrupt check.
972 bool HasPendingInterrupt() { return mHasPendingInterrupt; }
975 * If we have a presshell, and if the given content's current
976 * document is the same as our presshell's document, return the
977 * content's primary frame. Otherwise, return null. Only use this
978 * if you care about which presshell the primary frame is in.
980 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
982 void NotifyDestroyingFrame(nsIFrame* aFrame)
984 PropertyTable()->DeleteAllFor(aFrame);
987 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
988 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
989 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
992 bool IsRootContentDocument();
993 bool IsCrossProcessRootContentDocument();
995 bool IsGlyph() const {
996 return mIsGlyph;
999 void SetIsGlyph(bool aValue) {
1000 mIsGlyph = aValue;
1003 bool UsesRootEMUnits() const {
1004 return mUsesRootEMUnits;
1007 void SetUsesRootEMUnits(bool aValue) {
1008 mUsesRootEMUnits = aValue;
1011 bool UsesViewportUnits() const {
1012 return mUsesViewportUnits;
1015 void SetUsesViewportUnits(bool aValue) {
1016 mUsesViewportUnits = aValue;
1019 // true if there are OMTA transition updates for the current document which
1020 // have been throttled, and therefore some style information may not be up
1021 // to date
1022 bool ExistThrottledUpdates() const {
1023 return mExistThrottledUpdates;
1026 void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
1027 mExistThrottledUpdates = aExistThrottledUpdates;
1030 bool IsDeviceSizePageSize();
1032 bool HasWarnedAboutPositionedTableParts() const {
1033 return mHasWarnedAboutPositionedTableParts;
1036 void SetHasWarnedAboutPositionedTableParts() {
1037 mHasWarnedAboutPositionedTableParts = true;
1040 protected:
1041 friend class nsRunnableMethod<nsPresContext>;
1042 void ThemeChangedInternal();
1043 void SysColorChangedInternal();
1044 void UIResolutionChangedInternal();
1046 static bool
1047 UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument, void* aData);
1049 void SetImgAnimations(nsIContent *aParent, uint16_t aMode);
1050 void SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode,
1051 uint16_t aOldMode);
1052 void GetDocumentColorPreferences();
1054 void PreferenceChanged(const char* aPrefName);
1055 static void PrefChangedCallback(const char*, void*);
1057 void UpdateAfterPreferencesChanged();
1058 static void PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure);
1060 void GetUserPreferences();
1062 // Allow nsAutoPtr<LangGroupFontPrefs> dtor to access this protected struct's
1063 // dtor:
1064 struct LangGroupFontPrefs;
1065 friend class nsAutoPtr<LangGroupFontPrefs>;
1066 struct LangGroupFontPrefs {
1067 // Font sizes default to zero; they will be set in GetFontPreferences
1068 LangGroupFontPrefs()
1069 : mLangGroup(nullptr)
1070 , mMinimumFontSize(0)
1071 , mDefaultVariableFont(mozilla::eFamily_serif, NS_FONT_STYLE_NORMAL,
1072 NS_FONT_WEIGHT_NORMAL,
1073 NS_FONT_STRETCH_NORMAL, 0, 0)
1074 , mDefaultFixedFont(mozilla::eFamily_monospace, NS_FONT_STYLE_NORMAL,
1075 NS_FONT_WEIGHT_NORMAL,
1076 NS_FONT_STRETCH_NORMAL, 0, 0)
1077 , mDefaultSerifFont(mozilla::eFamily_serif, NS_FONT_STYLE_NORMAL,
1078 NS_FONT_WEIGHT_NORMAL,
1079 NS_FONT_STRETCH_NORMAL, 0, 0)
1080 , mDefaultSansSerifFont(mozilla::eFamily_sans_serif,
1081 NS_FONT_STYLE_NORMAL,
1082 NS_FONT_WEIGHT_NORMAL,
1083 NS_FONT_STRETCH_NORMAL, 0, 0)
1084 , mDefaultMonospaceFont(mozilla::eFamily_monospace, NS_FONT_STYLE_NORMAL,
1085 NS_FONT_WEIGHT_NORMAL,
1086 NS_FONT_STRETCH_NORMAL, 0, 0)
1087 , mDefaultCursiveFont(mozilla::eFamily_cursive, NS_FONT_STYLE_NORMAL,
1088 NS_FONT_WEIGHT_NORMAL,
1089 NS_FONT_STRETCH_NORMAL, 0, 0)
1090 , mDefaultFantasyFont(mozilla::eFamily_fantasy, NS_FONT_STYLE_NORMAL,
1091 NS_FONT_WEIGHT_NORMAL,
1092 NS_FONT_STRETCH_NORMAL, 0, 0)
1095 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
1096 size_t n = 0;
1097 LangGroupFontPrefs *curr = mNext;
1098 while (curr) {
1099 n += aMallocSizeOf(curr);
1101 // Measurement of the following members may be added later if DMD finds
1102 // it is worthwhile:
1103 // - mLangGroup
1104 // - mDefault*Font
1106 curr = curr->mNext;
1108 return n;
1111 nsCOMPtr<nsIAtom> mLangGroup;
1112 nscoord mMinimumFontSize;
1113 nsFont mDefaultVariableFont;
1114 nsFont mDefaultFixedFont;
1115 nsFont mDefaultSerifFont;
1116 nsFont mDefaultSansSerifFont;
1117 nsFont mDefaultMonospaceFont;
1118 nsFont mDefaultCursiveFont;
1119 nsFont mDefaultFantasyFont;
1120 nsAutoPtr<LangGroupFontPrefs> mNext;
1124 * Fetch the user's font preferences for the given aLanguage's
1125 * langugage group.
1127 const LangGroupFontPrefs* GetFontPrefsForLang(nsIAtom *aLanguage) const;
1129 void ResetCachedFontPrefs() {
1130 // Throw away any other LangGroupFontPrefs objects:
1131 mLangGroupFontPrefs.mNext = nullptr;
1133 // Make GetFontPreferences reinitialize mLangGroupFontPrefs:
1134 mLangGroupFontPrefs.mLangGroup = nullptr;
1137 void UpdateCharSet(const nsCString& aCharSet);
1139 public:
1140 void DoChangeCharSet(const nsCString& aCharSet);
1143 * Checks for MozAfterPaint listeners on the document
1145 bool MayHavePaintEventListener();
1148 * Checks for MozAfterPaint listeners on the document and
1149 * any subdocuments, except for subdocuments that are non-top-level
1150 * content documents.
1152 bool MayHavePaintEventListenerInSubDocument();
1154 protected:
1155 void InvalidateThebesLayers();
1156 void AppUnitsPerDevPixelChanged();
1158 void HandleRebuildUserFontSet() {
1159 mPostedFlushUserFontSet = false;
1160 FlushUserFontSet();
1163 void HandleRebuildCounterStyles() {
1164 mPostedFlushCounterStyles = false;
1165 FlushCounterStyles();
1168 bool HavePendingInputEvent();
1170 // Can't be inline because we can't include nsStyleSet.h.
1171 bool HasCachedStyleData();
1173 bool IsChromeSlow() const;
1175 // IMPORTANT: The ownership implicit in the following member variables
1176 // has been explicitly checked. If you add any members to this class,
1177 // please make the ownership explicit (pinkerton, scc).
1179 nsPresContextType mType;
1180 nsIPresShell* mShell; // [WEAK]
1181 nsCOMPtr<nsIDocument> mDocument;
1182 nsRefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1183 // better safe than sorry.
1184 // Cannot reintroduce cycles
1185 // since there is no dependency
1186 // from gfx back to layout.
1187 nsRefPtr<mozilla::EventStateManager> mEventManager;
1188 nsRefPtr<nsRefreshDriver> mRefreshDriver;
1189 nsRefPtr<nsTransitionManager> mTransitionManager;
1190 nsRefPtr<nsAnimationManager> mAnimationManager;
1191 nsRefPtr<mozilla::RestyleManager> mRestyleManager;
1192 nsRefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
1193 nsIAtom* mMedium; // initialized by subclass ctors;
1194 // weak pointer to static atom
1195 nsCOMPtr<nsIAtom> mMediaEmulated;
1197 nsILinkHandler* mLinkHandler; // [WEAK]
1199 // Formerly mLangGroup; moving from charset-oriented langGroup to
1200 // maintaining actual language settings everywhere (see bug 524107).
1201 // This may in fact hold a langGroup such as x-western rather than
1202 // a specific language, however (e.g, if it is inferred from the
1203 // charset rather than explicitly specified as a lang attribute).
1204 nsCOMPtr<nsIAtom> mLanguage;
1206 public:
1207 // The following are public member variables so that we can use them
1208 // with mozilla::AutoToggle or mozilla::AutoRestore.
1210 // Should we disable font size inflation because we're inside of
1211 // shrink-wrapping calculations on an inflation container?
1212 bool mInflationDisabledForShrinkWrap;
1214 protected:
1216 mozilla::WeakPtr<nsDocShell> mContainer;
1218 PRCList mDOMMediaQueryLists;
1220 // Base minimum font size, independent of the language-specific global preference. Defaults to 0
1221 int32_t mBaseMinFontSize;
1222 float mTextZoom; // Text zoom, defaults to 1.0
1223 float mFullZoom; // Page zoom, defaults to 1.0
1225 float mLastFontInflationScreenWidth;
1227 int32_t mCurAppUnitsPerDevPixel;
1228 int32_t mAutoQualityMinFontSizePixelsPref;
1230 nsCOMPtr<nsITheme> mTheme;
1231 nsCOMPtr<nsILanguageAtomService> mLangService;
1232 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1233 nsCOMPtr<nsITimer> mPrefChangedTimer;
1235 FramePropertyTable mPropertyTable;
1237 nsInvalidateRequestList mInvalidateRequestsSinceLastPaint;
1238 nsInvalidateRequestList mUndeliveredInvalidateRequestsBeforeLastPaint;
1240 // container for per-context fonts (downloadable, SVG, etc.)
1241 nsUserFontSet* mUserFontSet;
1243 // text performance metrics
1244 nsAutoPtr<gfxTextPerfMetrics> mTextPerf;
1246 nsRect mVisibleArea;
1247 nsSize mPageSize;
1248 float mPageScale;
1249 float mPPScale;
1251 nscolor mDefaultColor;
1252 nscolor mBackgroundColor;
1254 nscolor mLinkColor;
1255 nscolor mActiveLinkColor;
1256 nscolor mVisitedLinkColor;
1258 nscolor mFocusBackgroundColor;
1259 nscolor mFocusTextColor;
1261 nscolor mBodyTextColor;
1263 mozilla::ScrollbarStyles mViewportStyleOverflow;
1264 uint8_t mFocusRingWidth;
1266 bool mExistThrottledUpdates;
1268 uint16_t mImageAnimationMode;
1269 uint16_t mImageAnimationModePref;
1271 LangGroupFontPrefs mLangGroupFontPrefs;
1273 nscoord mBorderWidthTable[3];
1275 uint32_t mInterruptChecksToSkip;
1277 mozilla::TimeStamp mReflowStartTime;
1279 // last time we did a full style flush
1280 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1282 unsigned mHasPendingInterrupt : 1;
1283 unsigned mInterruptsEnabled : 1;
1284 unsigned mUseDocumentFonts : 1;
1285 unsigned mUseDocumentColors : 1;
1286 unsigned mUnderlineLinks : 1;
1287 unsigned mSendAfterPaintToContent : 1;
1288 unsigned mUseFocusColors : 1;
1289 unsigned mFocusRingOnAnything : 1;
1290 unsigned mFocusRingStyle : 1;
1291 unsigned mDrawImageBackground : 1;
1292 unsigned mDrawColorBackground : 1;
1293 unsigned mNeverAnimate : 1;
1294 unsigned mIsRenderingOnlySelection : 1;
1295 unsigned mPaginated : 1;
1296 unsigned mCanPaginatedScroll : 1;
1297 unsigned mDoScaledTwips : 1;
1298 unsigned mIsRootPaginatedDocument : 1;
1299 unsigned mPrefBidiDirection : 1;
1300 unsigned mPrefScrollbarSide : 2;
1301 unsigned mPendingSysColorChanged : 1;
1302 unsigned mPendingThemeChanged : 1;
1303 unsigned mPendingUIResolutionChanged : 1;
1304 unsigned mPendingMediaFeatureValuesChanged : 1;
1305 unsigned mPrefChangePendingNeedsReflow : 1;
1306 unsigned mIsEmulatingMedia : 1;
1307 // True if the requests in mInvalidateRequestsSinceLastPaint cover the
1308 // entire viewport
1309 unsigned mAllInvalidated : 1;
1311 // Are we currently drawing an SVG glyph?
1312 unsigned mIsGlyph : 1;
1314 // Does the associated document use root-em (rem) units?
1315 unsigned mUsesRootEMUnits : 1;
1316 // Does the associated document use viewport units (vw/vh/vmin/vmax)?
1317 unsigned mUsesViewportUnits : 1;
1319 // Has there been a change to the viewport's dimensions?
1320 unsigned mPendingViewportChange : 1;
1322 // Is the current mUserFontSet valid?
1323 unsigned mUserFontSetDirty : 1;
1324 // Has GetUserFontSet() been called?
1325 unsigned mGetUserFontSetCalled : 1;
1326 // Do we currently have an event posted to call FlushUserFontSet?
1327 unsigned mPostedFlushUserFontSet : 1;
1329 // Is the current mCounterStyleManager valid?
1330 unsigned mCounterStylesDirty : 1;
1331 // Do we currently have an event posted to call FlushCounterStyles?
1332 unsigned mPostedFlushCounterStyles: 1;
1334 // resize reflow is suppressed when the only change has been to zoom
1335 // the document rather than to change the document's dimensions
1336 unsigned mSupressResizeReflow : 1;
1338 unsigned mIsVisual : 1;
1340 unsigned mProcessingRestyles : 1;
1341 unsigned mProcessingAnimationStyleChange : 1;
1343 unsigned mFireAfterPaintEvents : 1;
1345 unsigned mIsChrome : 1;
1346 unsigned mIsChromeOriginImage : 1;
1348 // Should we paint flash in this context? Do not use this variable directly.
1349 // Use GetPaintFlashing() method instead.
1350 mutable unsigned mPaintFlashing : 1;
1351 mutable unsigned mPaintFlashingInitialized : 1;
1353 unsigned mHasWarnedAboutPositionedTableParts : 1;
1355 #ifdef DEBUG
1356 bool mInitialized;
1357 #endif
1360 protected:
1362 virtual ~nsPresContext();
1364 // these are private, use the list in nsFont.h if you want a public list
1365 enum {
1366 eDefaultFont_Variable,
1367 eDefaultFont_Fixed,
1368 eDefaultFont_Serif,
1369 eDefaultFont_SansSerif,
1370 eDefaultFont_Monospace,
1371 eDefaultFont_Cursive,
1372 eDefaultFont_Fantasy,
1373 eDefaultFont_COUNT
1376 nscolor MakeColorPref(const nsString& aColor);
1378 void LastRelease();
1380 #ifdef DEBUG
1381 private:
1382 friend struct nsAutoLayoutPhase;
1383 uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT];
1384 public:
1385 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1386 return mLayoutPhaseCount[aPhase];
1388 #endif
1392 class nsRootPresContext MOZ_FINAL : public nsPresContext {
1393 public:
1394 nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType);
1395 virtual ~nsRootPresContext();
1396 virtual void Detach() MOZ_OVERRIDE;
1399 * Ensure that NotifyDidPaintForSubtree is eventually called on this
1400 * object after a timeout.
1402 void EnsureEventualDidPaintEvent();
1404 void CancelDidPaintTimer()
1406 if (mNotifyDidPaintTimer) {
1407 mNotifyDidPaintTimer->Cancel();
1408 mNotifyDidPaintTimer = nullptr;
1413 * Registers a plugin to receive geometry updates (position and clip
1414 * region) so it can update its widget.
1415 * Callers must call UnregisterPluginForGeometryUpdates before
1416 * the aPlugin frame is destroyed.
1418 void RegisterPluginForGeometryUpdates(nsIContent* aPlugin);
1420 * Stops a plugin receiving geometry updates (position and clip
1421 * region). If the plugin was not already registered, this does
1422 * nothing.
1424 void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin);
1426 bool NeedToComputePluginGeometryUpdates()
1428 return mRegisteredPlugins.Count() > 0;
1431 * Compute geometry updates for each plugin given that aList is the display
1432 * list for aFrame. The updates are not yet applied;
1433 * ApplyPluginGeometryUpdates is responsible for that. In the meantime they
1434 * are stored on each nsObjectFrame.
1435 * This needs to be called even when aFrame is a popup, since although
1436 * windowed plugins aren't allowed in popups, windowless plugins are
1437 * and ComputePluginGeometryUpdates needs to be called for them.
1439 void ComputePluginGeometryUpdates(nsIFrame* aFrame,
1440 nsDisplayListBuilder* aBuilder,
1441 nsDisplayList* aList);
1444 * Apply the stored plugin geometry updates. This should normally be called
1445 * in DidPaint so the plugins are moved/clipped immediately after we've
1446 * updated our window, so they look in sync with our window.
1448 void ApplyPluginGeometryUpdates();
1450 virtual bool IsRoot() MOZ_OVERRIDE { return true; }
1453 * Increment DOM-modification generation counter to indicate that
1454 * the DOM has changed in a way that might lead to style changes/
1455 * reflows/frame creation and destruction.
1457 void IncrementDOMGeneration() { mDOMGeneration++; }
1460 * Get the current DOM generation counter.
1462 * See nsFrameManagerBase::GetGlobalGenerationNumber() for a
1463 * global generation number.
1465 uint32_t GetDOMGeneration() { return mDOMGeneration; }
1468 * Add a runnable that will get called before the next paint. They will get
1469 * run eventually even if painting doesn't happen. They might run well before
1470 * painting happens.
1472 void AddWillPaintObserver(nsIRunnable* aRunnable);
1475 * Run all runnables that need to get called before the next paint.
1477 void FlushWillPaintObservers();
1479 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
1481 protected:
1483 * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates.
1485 void InitApplyPluginGeometryTimer();
1487 * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates.
1489 void CancelApplyPluginGeometryTimer();
1491 class RunWillPaintObservers : public nsRunnable {
1492 public:
1493 explicit RunWillPaintObservers(nsRootPresContext* aPresContext) : mPresContext(aPresContext) {}
1494 void Revoke() { mPresContext = nullptr; }
1495 NS_IMETHOD Run() MOZ_OVERRIDE
1497 if (mPresContext) {
1498 mPresContext->FlushWillPaintObservers();
1500 return NS_OK;
1502 nsRootPresContext* mPresContext;
1505 friend class nsPresContext;
1507 nsCOMPtr<nsITimer> mNotifyDidPaintTimer;
1508 nsCOMPtr<nsITimer> mApplyPluginGeometryTimer;
1509 nsTHashtable<nsRefPtrHashKey<nsIContent> > mRegisteredPlugins;
1510 nsTArray<nsCOMPtr<nsIRunnable> > mWillPaintObservers;
1511 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1512 uint32_t mDOMGeneration;
1515 #ifdef MOZ_REFLOW_PERF
1517 #define DO_GLOBAL_REFLOW_COUNT(_name) \
1518 aPresContext->CountReflows((_name), (nsIFrame*)this);
1519 #else
1520 #define DO_GLOBAL_REFLOW_COUNT(_name)
1521 #endif // MOZ_REFLOW_PERF
1523 #endif /* nsPresContext_h___ */