michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* a presentation of a document, part 1 */ michael@0: michael@0: #ifndef nsPresContext_h___ michael@0: #define nsPresContext_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/WeakPtr.h" michael@0: #include "nsColor.h" michael@0: #include "nsCoord.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIPresShell.h" michael@0: #include "nsRect.h" michael@0: #include "nsFont.h" michael@0: #include "gfxFontConstants.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsITimer.h" michael@0: #include "nsCRT.h" michael@0: #include "FramePropertyTable.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsChangeHint.h" michael@0: #include michael@0: // This also pulls in gfxTypes.h, which we cannot include directly. michael@0: #include "gfxRect.h" michael@0: #include "nsTArray.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/TimeStamp.h" michael@0: #include "mozilla/AppUnits.h" michael@0: #include "prclist.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "ScrollbarStyles.h" michael@0: michael@0: class nsBidiPresUtils; michael@0: class nsAString; michael@0: class nsIPrintSettings; michael@0: class nsDocShell; michael@0: class nsIDocShell; michael@0: class nsIDocument; michael@0: class nsILanguageAtomService; michael@0: class nsITheme; michael@0: class nsIContent; michael@0: class nsIFrame; michael@0: class nsFrameManager; michael@0: class nsILinkHandler; michael@0: class nsIAtom; michael@0: class nsICSSPseudoComparator; michael@0: struct nsStyleBackground; michael@0: struct nsStyleBorder; michael@0: class nsIRunnable; michael@0: class gfxUserFontSet; michael@0: class gfxTextPerfMetrics; michael@0: class nsUserFontSet; michael@0: struct nsFontFaceRuleContainer; michael@0: class nsObjectFrame; michael@0: class nsTransitionManager; michael@0: class nsAnimationManager; michael@0: class nsRefreshDriver; michael@0: class nsIWidget; michael@0: class nsDeviceContext; michael@0: michael@0: namespace mozilla { michael@0: class EventStateManager; michael@0: class RestyleManager; michael@0: namespace dom { michael@0: class MediaQueryList; michael@0: } michael@0: namespace layers { michael@0: class ContainerLayer; michael@0: } michael@0: } michael@0: michael@0: // supported values for cached bool types michael@0: enum nsPresContext_CachedBoolPrefType { michael@0: kPresContext_UseDocumentColors = 1, michael@0: kPresContext_UseDocumentFonts, michael@0: kPresContext_UnderlineLinks michael@0: }; michael@0: michael@0: // supported values for cached integer pref types michael@0: enum nsPresContext_CachedIntPrefType { michael@0: kPresContext_ScrollbarSide = 1, michael@0: kPresContext_BidiDirection michael@0: }; michael@0: michael@0: // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h) michael@0: // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported. michael@0: const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable michael@0: const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed michael@0: michael@0: #ifdef DEBUG michael@0: struct nsAutoLayoutPhase; michael@0: michael@0: enum nsLayoutPhase { michael@0: eLayoutPhase_Paint, michael@0: eLayoutPhase_Reflow, michael@0: eLayoutPhase_FrameC, michael@0: eLayoutPhase_COUNT michael@0: }; michael@0: #endif michael@0: michael@0: class nsInvalidateRequestList { michael@0: public: michael@0: struct Request { michael@0: nsRect mRect; michael@0: uint32_t mFlags; michael@0: }; michael@0: michael@0: void TakeFrom(nsInvalidateRequestList* aList) michael@0: { michael@0: mRequests.MoveElementsFrom(aList->mRequests); michael@0: } michael@0: bool IsEmpty() { return mRequests.IsEmpty(); } michael@0: michael@0: nsTArray mRequests; michael@0: }; michael@0: michael@0: /* Used by nsPresContext::HasAuthorSpecifiedRules */ michael@0: #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0) michael@0: #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1) michael@0: #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2) michael@0: #define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3) michael@0: michael@0: class nsRootPresContext; michael@0: michael@0: // An interface for presentation contexts. Presentation contexts are michael@0: // objects that provide an outer context for a presentation shell. michael@0: michael@0: class nsPresContext : public nsIObserver { michael@0: public: michael@0: typedef mozilla::FramePropertyTable FramePropertyTable; michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_NSIOBSERVER michael@0: NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW michael@0: NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext) michael@0: michael@0: enum nsPresContextType { michael@0: eContext_Galley, // unpaginated screen presentation michael@0: eContext_PrintPreview, // paginated screen presentation michael@0: eContext_Print, // paginated printer presentation michael@0: eContext_PageLayout // paginated & editable. michael@0: }; michael@0: michael@0: // Policies for rebuilding style data. michael@0: enum StyleRebuildType { michael@0: eRebuildStyleIfNeeded, michael@0: eAlwaysRebuildStyle michael@0: }; michael@0: michael@0: nsPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN; michael@0: michael@0: /** michael@0: * Initialize the presentation context from a particular device. michael@0: */ michael@0: NS_HIDDEN_(nsresult) Init(nsDeviceContext* aDeviceContext); michael@0: michael@0: /** michael@0: * Set the presentation shell that this context is bound to. michael@0: * A presentation context may only be bound to a single shell. michael@0: */ michael@0: NS_HIDDEN_(void) SetShell(nsIPresShell* aShell); michael@0: michael@0: michael@0: NS_HIDDEN_(nsPresContextType) Type() const { return mType; } michael@0: michael@0: /** michael@0: * Get the PresentationShell that this context is bound to. michael@0: */ michael@0: nsIPresShell* PresShell() const michael@0: { michael@0: NS_ASSERTION(mShell, "Null pres shell"); michael@0: return mShell; michael@0: } michael@0: michael@0: nsIPresShell* GetPresShell() const { return mShell; } michael@0: michael@0: /** michael@0: * Returns the parent prescontext for this one. Returns null if this is a michael@0: * root. michael@0: */ michael@0: nsPresContext* GetParentPresContext(); michael@0: michael@0: /** michael@0: * Returns the prescontext of the toplevel content document that contains michael@0: * this presentation, or null if there isn't one. michael@0: */ michael@0: nsPresContext* GetToplevelContentDocumentPresContext(); michael@0: michael@0: /** michael@0: * Returns the nearest widget for the root frame of this. michael@0: * michael@0: * @param aOffset If non-null the offset from the origin of the root michael@0: * frame's view to the widget's origin (usually positive) michael@0: * expressed in appunits of this will be returned in michael@0: * aOffset. michael@0: */ michael@0: nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr); michael@0: michael@0: /** michael@0: * Returns the root widget for this. michael@0: * Note that the widget is a mediater with IME. michael@0: */ michael@0: nsIWidget* GetRootWidget(); michael@0: michael@0: /** michael@0: * Return the presentation context for the root of the view manager michael@0: * hierarchy that contains this presentation context, or nullptr if it can't michael@0: * be found (e.g. it's detached). michael@0: */ michael@0: nsRootPresContext* GetRootPresContext(); michael@0: nsRootPresContext* GetDisplayRootPresContext(); michael@0: virtual bool IsRoot() { return false; } michael@0: michael@0: nsIDocument* Document() const michael@0: { michael@0: NS_ASSERTION(!mShell || !mShell->GetDocument() || michael@0: mShell->GetDocument() == mDocument, michael@0: "nsPresContext doesn't have the same document as nsPresShell!"); michael@0: return mDocument; michael@0: } michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); } michael@0: michael@0: nsFrameManager* FrameManager() michael@0: { return PresShell()->FrameManager(); } michael@0: michael@0: nsCSSFrameConstructor* FrameConstructor() michael@0: { return PresShell()->FrameConstructor(); } michael@0: michael@0: nsTransitionManager* TransitionManager() { return mTransitionManager; } michael@0: nsAnimationManager* AnimationManager() { return mAnimationManager; } michael@0: michael@0: nsRefreshDriver* RefreshDriver() { return mRefreshDriver; } michael@0: michael@0: mozilla::RestyleManager* RestyleManager() { return mRestyleManager; } michael@0: #endif michael@0: michael@0: /** michael@0: * Rebuilds all style data by throwing out the old rule tree and michael@0: * building a new one, and additionally applying aExtraHint (which michael@0: * must not contain nsChangeHint_ReconstructFrame) to the root frame. michael@0: * Also rebuild the user font set. michael@0: */ michael@0: void RebuildAllStyleData(nsChangeHint aExtraHint); michael@0: /** michael@0: * Just like RebuildAllStyleData, except (1) asynchronous and (2) it michael@0: * doesn't rebuild the user font set. michael@0: */ michael@0: void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint); michael@0: michael@0: void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild, michael@0: nsChangeHint aChangeHint = nsChangeHint(0)); michael@0: void PostMediaFeatureValuesChangedEvent(); michael@0: NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent(); michael@0: void FlushPendingMediaFeatureValuesChanged() { michael@0: if (mPendingMediaFeatureValuesChanged) michael@0: MediaFeatureValuesChanged(eRebuildStyleIfNeeded); michael@0: } michael@0: michael@0: /** michael@0: * Support for window.matchMedia() michael@0: */ michael@0: already_AddRefed michael@0: MatchMedia(const nsAString& aMediaQueryList); michael@0: michael@0: /** michael@0: * Access compatibility mode for this context. This is the same as michael@0: * our document's compatibility mode. michael@0: */ michael@0: nsCompatibility CompatibilityMode() const; michael@0: michael@0: /** michael@0: * Notify the context that the document's compatibility mode has changed michael@0: */ michael@0: NS_HIDDEN_(void) CompatibilityModeChanged(); michael@0: michael@0: /** michael@0: * Access the image animation mode for this context michael@0: */ michael@0: uint16_t ImageAnimationMode() const { return mImageAnimationMode; } michael@0: virtual NS_HIDDEN_(void) SetImageAnimationModeExternal(uint16_t aMode); michael@0: NS_HIDDEN_(void) SetImageAnimationModeInternal(uint16_t aMode); michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: void SetImageAnimationMode(uint16_t aMode) michael@0: { SetImageAnimationModeInternal(aMode); } michael@0: #else michael@0: void SetImageAnimationMode(uint16_t aMode) michael@0: { SetImageAnimationModeExternal(aMode); } michael@0: #endif michael@0: michael@0: /** michael@0: * Get medium of presentation michael@0: */ michael@0: nsIAtom* Medium() { michael@0: if (!mIsEmulatingMedia) michael@0: return mMedium; michael@0: return mMediaEmulated; michael@0: } michael@0: michael@0: /* michael@0: * Render the document as if being viewed on a device with the specified michael@0: * media type. michael@0: */ michael@0: void EmulateMedium(const nsAString& aMediaType); michael@0: michael@0: /* michael@0: * Restore the viewer's natural medium michael@0: */ michael@0: void StopEmulatingMedium(); michael@0: michael@0: void* AllocateFromShell(size_t aSize) michael@0: { michael@0: if (mShell) michael@0: return mShell->AllocateMisc(aSize); michael@0: return nullptr; michael@0: } michael@0: michael@0: void FreeToShell(size_t aSize, void* aFreeChunk) michael@0: { michael@0: NS_ASSERTION(mShell, "freeing after shutdown"); michael@0: if (mShell) michael@0: mShell->FreeMisc(aSize, aFreeChunk); michael@0: } michael@0: michael@0: /** michael@0: * Get the default font for the given language and generic font ID. michael@0: * If aLanguage is nullptr, the document's language is used. michael@0: * michael@0: * This object is read-only, you must copy the font to modify it. michael@0: * michael@0: * When aFontID is kPresContext_DefaultVariableFontID or michael@0: * kPresContext_DefaultFixedFontID (which equals michael@0: * kGenericFont_moz_fixed, which is used for the -moz-fixed generic), michael@0: * the nsFont returned has its name as a CSS generic family (serif or michael@0: * sans-serif for the former, monospace for the latter), and its size michael@0: * as the default font size for variable or fixed fonts for the michael@0: * language group. michael@0: * michael@0: * For aFontID corresponding to a CSS Generic, the nsFont returned has michael@0: * its name set to that generic font's name, and its size set to michael@0: * the user's preference for font size for that generic and the michael@0: * given language. michael@0: */ michael@0: NS_HIDDEN_(const nsFont*) GetDefaultFont(uint8_t aFontID, michael@0: nsIAtom *aLanguage) const; michael@0: michael@0: /** Get a cached boolean pref, by its type */ michael@0: // * - initially created for bugs 31816, 20760, 22963 michael@0: bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const michael@0: { michael@0: // If called with a constant parameter, the compiler should optimize michael@0: // this switch statement away. michael@0: switch (aPrefType) { michael@0: case kPresContext_UseDocumentFonts: michael@0: return mUseDocumentFonts; michael@0: case kPresContext_UseDocumentColors: michael@0: return mUseDocumentColors; michael@0: case kPresContext_UnderlineLinks: michael@0: return mUnderlineLinks; michael@0: default: michael@0: NS_ERROR("Invalid arg passed to GetCachedBoolPref"); michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: /** Get a cached integer pref, by its type */ michael@0: // * - initially created for bugs 30910, 61883, 74186, 84398 michael@0: int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const michael@0: { michael@0: // If called with a constant parameter, the compiler should optimize michael@0: // this switch statement away. michael@0: switch (aPrefType) { michael@0: case kPresContext_ScrollbarSide: michael@0: return mPrefScrollbarSide; michael@0: case kPresContext_BidiDirection: michael@0: return mPrefBidiDirection; michael@0: default: michael@0: NS_ERROR("invalid arg passed to GetCachedIntPref"); michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: /** michael@0: * Get the default colors michael@0: */ michael@0: const nscolor DefaultColor() const { return mDefaultColor; } michael@0: const nscolor DefaultBackgroundColor() const { return mBackgroundColor; } michael@0: const nscolor DefaultLinkColor() const { return mLinkColor; } michael@0: const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; } michael@0: const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; } michael@0: const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; } michael@0: const nscolor FocusTextColor() const { return mFocusTextColor; } michael@0: michael@0: /** michael@0: * Body text color, for use in quirks mode only. michael@0: */ michael@0: const nscolor BodyTextColor() const { return mBodyTextColor; } michael@0: void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; } michael@0: michael@0: bool GetUseFocusColors() const { return mUseFocusColors; } michael@0: uint8_t FocusRingWidth() const { return mFocusRingWidth; } michael@0: bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; } michael@0: uint8_t GetFocusRingStyle() const { return mFocusRingStyle; } michael@0: michael@0: NS_HIDDEN_(void) SetContainer(nsIDocShell* aContainer); michael@0: michael@0: virtual nsISupports* GetContainerWeakExternal() const; michael@0: nsISupports* GetContainerWeakInternal() const; michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: nsISupports* GetContainerWeak() const michael@0: { return GetContainerWeakInternal(); } michael@0: #else michael@0: nsISupports* GetContainerWeak() const michael@0: { return GetContainerWeakExternal(); } michael@0: #endif michael@0: michael@0: nsIDocShell* GetDocShell() const; michael@0: michael@0: // XXX this are going to be replaced with set/get container michael@0: void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; } michael@0: nsILinkHandler* GetLinkHandler() { return mLinkHandler; } michael@0: michael@0: /** michael@0: * Detach this pres context - i.e. cancel relevant timers, michael@0: * SetLinkHandler(null), SetContainer(null) etc. michael@0: * Only to be used by the DocumentViewer. michael@0: */ michael@0: virtual void Detach(); michael@0: michael@0: /** michael@0: * Get the visible area associated with this presentation context. michael@0: * This is the size of the visible area that is used for michael@0: * presenting the document. The returned value is in the standard michael@0: * nscoord units (as scaled by the device context). michael@0: */ michael@0: nsRect GetVisibleArea() { return mVisibleArea; } michael@0: michael@0: /** michael@0: * Set the currently visible area. The units for r are standard michael@0: * nscoord units (as scaled by the device context). michael@0: */ michael@0: void SetVisibleArea(const nsRect& r) { michael@0: if (!r.IsEqualEdges(mVisibleArea)) { michael@0: mVisibleArea = r; michael@0: // Visible area does not affect media queries when paginated. michael@0: if (!IsPaginated() && HasCachedStyleData()) { michael@0: mPendingViewportChange = true; michael@0: PostMediaFeatureValuesChangedEvent(); michael@0: } michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Return true if this presentation context is a paginated michael@0: * context. michael@0: */ michael@0: bool IsPaginated() const { return mPaginated; } michael@0: michael@0: /** michael@0: * Sets whether the presentation context can scroll for a paginated michael@0: * context. michael@0: */ michael@0: NS_HIDDEN_(void) SetPaginatedScrolling(bool aResult); michael@0: michael@0: /** michael@0: * Return true if this presentation context can scroll for paginated michael@0: * context. michael@0: */ michael@0: bool HasPaginatedScrolling() const { return mCanPaginatedScroll; } michael@0: michael@0: /** michael@0: * Get/set the size of a page michael@0: */ michael@0: nsSize GetPageSize() { return mPageSize; } michael@0: void SetPageSize(nsSize aSize) { mPageSize = aSize; } michael@0: michael@0: /** michael@0: * Get/set whether this document should be treated as having real pages michael@0: * XXX This raises the obvious question of why a document that isn't a page michael@0: * is paginated; there isn't a good reason except history michael@0: */ michael@0: bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; } michael@0: void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) michael@0: { mIsRootPaginatedDocument = aIsRootPaginatedDocument; } michael@0: michael@0: /** michael@0: * Get/set the print scaling level; used by nsPageFrame to scale up michael@0: * pages. Set safe to call before reflow, get guaranteed to be set michael@0: * properly after reflow. michael@0: */ michael@0: michael@0: float GetPageScale() { return mPageScale; } michael@0: void SetPageScale(float aScale) { mPageScale = aScale; } michael@0: michael@0: /** michael@0: * Get/set the scaling facor to use when rendering the pages for print preview. michael@0: * Only safe to get after print preview set up; safe to set anytime. michael@0: * This is a scaling factor for the display of the print preview. It michael@0: * does not affect layout. It only affects the size of the onscreen pages michael@0: * in print preview. michael@0: * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview michael@0: */ michael@0: float GetPrintPreviewScale() { return mPPScale; } michael@0: void SetPrintPreviewScale(float aScale) { mPPScale = aScale; } michael@0: michael@0: nsDeviceContext* DeviceContext() { return mDeviceContext; } michael@0: mozilla::EventStateManager* EventStateManager() { return mEventManager; } michael@0: nsIAtom* GetLanguageFromCharset() { return mLanguage; } michael@0: michael@0: float TextZoom() { return mTextZoom; } michael@0: void SetTextZoom(float aZoom) { michael@0: if (aZoom == mTextZoom) michael@0: return; michael@0: michael@0: mTextZoom = aZoom; michael@0: if (HasCachedStyleData()) { michael@0: // Media queries could have changed, since we changed the meaning michael@0: // of 'em' units in them. michael@0: MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); michael@0: } michael@0: } michael@0: michael@0: nsTArray mFontsUsed; // currently for font-count limiting only michael@0: nsTArray mFontsTried; // currently for font-count limiting only michael@0: void AddFontUse(const nsFont &font); michael@0: void AddFontAttempt(const nsFont &font); michael@0: PRBool FontUseCountReached(const nsFont &font); michael@0: PRBool FontAttemptCountReached(const nsFont &font); michael@0: michael@0: /** michael@0: * Get the minimum font size for the specified language. If aLanguage michael@0: * is nullptr, then the document's language is used. This combines michael@0: * the language-specific global preference with the per-presentation michael@0: * base minimum font size. michael@0: */ michael@0: int32_t MinFontSize(nsIAtom *aLanguage) const { michael@0: const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage); michael@0: return std::max(mBaseMinFontSize, prefs->mMinimumFontSize); michael@0: } michael@0: michael@0: /** michael@0: * Get the per-presentation base minimum font size. This size is michael@0: * independent of the language-specific global preference. michael@0: */ michael@0: int32_t BaseMinFontSize() const { michael@0: return mBaseMinFontSize; michael@0: } michael@0: michael@0: /** michael@0: * Set the per-presentation base minimum font size. This size is michael@0: * independent of the language-specific global preference. michael@0: */ michael@0: void SetBaseMinFontSize(int32_t aMinFontSize) { michael@0: if (aMinFontSize == mBaseMinFontSize) michael@0: return; michael@0: michael@0: mBaseMinFontSize = aMinFontSize; michael@0: if (HasCachedStyleData()) { michael@0: // Media queries could have changed, since we changed the meaning michael@0: // of 'em' units in them. michael@0: MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); michael@0: } michael@0: } michael@0: michael@0: float GetFullZoom() { return mFullZoom; } michael@0: void SetFullZoom(float aZoom); michael@0: michael@0: nscoord GetAutoQualityMinFontSize() { michael@0: return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref); michael@0: } michael@0: michael@0: /** michael@0: * Return the device's screen width in inches, for font size michael@0: * inflation. michael@0: * michael@0: * If |aChanged| is non-null, then aChanged is filled in with whether michael@0: * the return value has changed since either: michael@0: * a. the last time the function was called with non-null aChanged, or michael@0: * b. the first time the function was called. michael@0: */ michael@0: float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr); michael@0: michael@0: static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); } michael@0: int32_t AppUnitsPerDevPixel() const; michael@0: static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); } michael@0: michael@0: static nscoord CSSPixelsToAppUnits(int32_t aPixels) michael@0: { return NSToCoordRoundWithClamp(float(aPixels) * michael@0: float(AppUnitsPerCSSPixel())); } michael@0: michael@0: static nscoord CSSPixelsToAppUnits(float aPixels) michael@0: { return NSToCoordRoundWithClamp(aPixels * michael@0: float(AppUnitsPerCSSPixel())); } michael@0: michael@0: static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) michael@0: { return NSAppUnitsToIntPixels(aAppUnits, michael@0: float(AppUnitsPerCSSPixel())); } michael@0: michael@0: static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) michael@0: { return NSAppUnitsToFloatPixels(aAppUnits, michael@0: float(AppUnitsPerCSSPixel())); } michael@0: michael@0: nscoord DevPixelsToAppUnits(int32_t aPixels) const michael@0: { return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel()); } michael@0: michael@0: int32_t AppUnitsToDevPixels(nscoord aAppUnits) const michael@0: { return NSAppUnitsToIntPixels(aAppUnits, michael@0: float(AppUnitsPerDevPixel())); } michael@0: michael@0: int32_t CSSPixelsToDevPixels(int32_t aPixels) michael@0: { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); } michael@0: michael@0: float CSSPixelsToDevPixels(float aPixels) michael@0: { michael@0: return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels), michael@0: float(AppUnitsPerDevPixel())); michael@0: } michael@0: michael@0: int32_t DevPixelsToIntCSSPixels(int32_t aPixels) michael@0: { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); } michael@0: michael@0: float DevPixelsToFloatCSSPixels(int32_t aPixels) michael@0: { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); } michael@0: michael@0: // If there is a remainder, it is rounded to nearest app units. michael@0: nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const; michael@0: michael@0: gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const; michael@0: michael@0: gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const michael@0: { return gfxRect(AppUnitsToGfxUnits(aAppRect.x), michael@0: AppUnitsToGfxUnits(aAppRect.y), michael@0: AppUnitsToGfxUnits(aAppRect.width), michael@0: AppUnitsToGfxUnits(aAppRect.height)); } michael@0: michael@0: static nscoord CSSTwipsToAppUnits(float aTwips) michael@0: { return NSToCoordRoundWithClamp( michael@0: mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); } michael@0: michael@0: // Margin-specific version, since they often need TwipsToAppUnits michael@0: static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips) michael@0: { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)), michael@0: CSSTwipsToAppUnits(float(marginInTwips.right)), michael@0: CSSTwipsToAppUnits(float(marginInTwips.bottom)), michael@0: CSSTwipsToAppUnits(float(marginInTwips.left))); } michael@0: michael@0: static nscoord CSSPointsToAppUnits(float aPoints) michael@0: { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() / michael@0: POINTS_PER_INCH_FLOAT); } michael@0: michael@0: nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const michael@0: { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); } michael@0: michael@0: void SetViewportOverflowOverride(uint8_t aX, uint8_t aY) michael@0: { michael@0: mViewportStyleOverflow.mHorizontal = aX; michael@0: mViewportStyleOverflow.mVertical = aY; michael@0: } michael@0: mozilla::ScrollbarStyles GetViewportOverflowOverride() michael@0: { michael@0: return mViewportStyleOverflow; michael@0: } michael@0: michael@0: /** michael@0: * Set and get methods for controlling the background drawing michael@0: */ michael@0: bool GetBackgroundImageDraw() const { return mDrawImageBackground; } michael@0: void SetBackgroundImageDraw(bool aCanDraw) michael@0: { michael@0: mDrawImageBackground = aCanDraw; michael@0: } michael@0: michael@0: bool GetBackgroundColorDraw() const { return mDrawColorBackground; } michael@0: void SetBackgroundColorDraw(bool aCanDraw) michael@0: { michael@0: mDrawColorBackground = aCanDraw; michael@0: } michael@0: michael@0: /** michael@0: * Getter and setter for OMTA time counters michael@0: */ michael@0: bool ThrottledTransitionStyleIsUpToDate() const; michael@0: void TickLastUpdateThrottledTransitionStyle(); michael@0: bool ThrottledAnimationStyleIsUpToDate() const; michael@0: void TickLastUpdateThrottledAnimationStyle(); michael@0: bool StyleUpdateForAllAnimationsIsUpToDate(); michael@0: void TickLastStyleUpdateForAllAnimations(); michael@0: michael@0: /** michael@0: * Check if bidi enabled (set depending on the presence of RTL michael@0: * characters or when default directionality is RTL). michael@0: * If enabled, we should apply the Unicode Bidi Algorithm michael@0: * michael@0: * @lina 07/12/2000 michael@0: */ michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: bool BidiEnabled() const { return BidiEnabledInternal(); } michael@0: #else michael@0: bool BidiEnabled() const { return BidiEnabledExternal(); } michael@0: #endif michael@0: virtual bool BidiEnabledExternal() const; michael@0: bool BidiEnabledInternal() const; michael@0: michael@0: /** michael@0: * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm michael@0: * michael@0: * @lina 07/12/2000 michael@0: */ michael@0: NS_HIDDEN_(void) SetBidiEnabled() const; michael@0: michael@0: /** michael@0: * Set visual or implicit mode into the pres context. michael@0: * michael@0: * Visual directionality is a presentation method that displays text michael@0: * as if it were a uni-directional, according to the primary display michael@0: * direction only. michael@0: * michael@0: * Implicit directionality is a presentation method in which the michael@0: * direction is determined by the Bidi algorithm according to the michael@0: * category of the characters and the category of the adjacent michael@0: * characters, and according to their primary direction. michael@0: * michael@0: * @lina 05/02/2000 michael@0: */ michael@0: void SetVisualMode(bool aIsVisual) michael@0: { michael@0: mIsVisual = aIsVisual; michael@0: } michael@0: michael@0: /** michael@0: * Check whether the content should be treated as visual. michael@0: * michael@0: * @lina 05/02/2000 michael@0: */ michael@0: bool IsVisualMode() const { return mIsVisual; } michael@0: michael@0: //Mohamed michael@0: michael@0: /** michael@0: * Set the Bidi options for the presentation context michael@0: */ michael@0: NS_HIDDEN_(void) SetBidi(uint32_t aBidiOptions, michael@0: bool aForceRestyle = false); michael@0: michael@0: /** michael@0: * Get the Bidi options for the presentation context michael@0: * Not inline so consumers of nsPresContext are not forced to michael@0: * include nsIDocument. michael@0: */ michael@0: NS_HIDDEN_(uint32_t) GetBidi() const; michael@0: michael@0: /** michael@0: * Render only Selection michael@0: */ michael@0: void SetIsRenderingOnlySelection(bool aResult) michael@0: { michael@0: mIsRenderingOnlySelection = aResult; michael@0: } michael@0: michael@0: bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; } michael@0: michael@0: NS_HIDDEN_(bool) IsTopLevelWindowInactive(); michael@0: michael@0: /* michael@0: * Obtain a native them for rendering our widgets (both form controls and html) michael@0: */ michael@0: NS_HIDDEN_(nsITheme*) GetTheme(); michael@0: michael@0: /* michael@0: * Notify the pres context that the theme has changed. An internal switch michael@0: * means it's one of our Mozilla themes that changed (e.g., Modern to Classic). michael@0: * Otherwise, the OS is telling us that the native theme for the platform michael@0: * has changed. michael@0: */ michael@0: NS_HIDDEN_(void) ThemeChanged(); michael@0: michael@0: /* michael@0: * Notify the pres context that the resolution of the user interface has michael@0: * changed. This happens if a window is moved between HiDPI and non-HiDPI michael@0: * displays, so that the ratio of points to device pixels changes. michael@0: */ michael@0: NS_HIDDEN_(void) UIResolutionChanged(); michael@0: michael@0: /* michael@0: * Notify the pres context that a system color has changed michael@0: */ michael@0: NS_HIDDEN_(void) SysColorChanged(); michael@0: michael@0: /** Printing methods below should only be used for Medium() == print **/ michael@0: NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings); michael@0: michael@0: nsIPrintSettings* GetPrintSettings() { return mPrintSettings; } michael@0: michael@0: /* Accessor for table of frame properties */ michael@0: FramePropertyTable* PropertyTable() { return &mPropertyTable; } michael@0: michael@0: /* Helper function that ensures that this prescontext is shown in its michael@0: docshell if it's the most recent prescontext for the docshell. Returns michael@0: whether the prescontext is now being shown. michael@0: */ michael@0: NS_HIDDEN_(bool) EnsureVisible(); michael@0: michael@0: #ifdef MOZ_REFLOW_PERF michael@0: NS_HIDDEN_(void) CountReflows(const char * aName, michael@0: nsIFrame * aFrame); michael@0: #endif michael@0: michael@0: /** michael@0: * This table maps border-width enums 'thin', 'medium', 'thick' michael@0: * to actual nscoord values. michael@0: */ michael@0: const nscoord* GetBorderWidthTable() { return mBorderWidthTable; } michael@0: michael@0: gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; } michael@0: michael@0: bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); } michael@0: bool IsScreen() { return (mMedium == nsGkAtoms::screen || michael@0: mType == eContext_PageLayout || michael@0: mType == eContext_PrintPreview); } michael@0: michael@0: // Is this presentation in a chrome docshell? michael@0: bool IsChrome() const { return mIsChrome; } michael@0: bool IsChromeOriginImage() const { return mIsChromeOriginImage; } michael@0: void UpdateIsChrome(); michael@0: michael@0: // Public API for native theme code to get style internals. michael@0: virtual bool HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const; michael@0: michael@0: // Is it OK to let the page specify colors and backgrounds? michael@0: bool UseDocumentColors() const { michael@0: return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome() || IsChromeOriginImage(); michael@0: } michael@0: michael@0: // Explicitly enable and disable paint flashing. michael@0: void SetPaintFlashing(bool aPaintFlashing) { michael@0: mPaintFlashing = aPaintFlashing; michael@0: mPaintFlashingInitialized = true; michael@0: } michael@0: michael@0: // This method should be used instead of directly accessing mPaintFlashing, michael@0: // as that value may be out of date when mPaintFlashingInitialized is false. michael@0: bool GetPaintFlashing() const; michael@0: michael@0: bool SupressingResizeReflow() const { return mSupressResizeReflow; } michael@0: michael@0: virtual NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetExternal(); michael@0: NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetInternal(); michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); } michael@0: #else michael@0: gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); } michael@0: #endif michael@0: michael@0: void FlushUserFontSet(); michael@0: void RebuildUserFontSet(); // asynchronously michael@0: michael@0: // Should be called whenever the set of fonts available in the user michael@0: // font set changes (e.g., because a new font loads, or because the michael@0: // user font set is changed and fonts become unavailable). michael@0: void UserFontSetUpdated(); michael@0: michael@0: // Ensure that it is safe to hand out CSS rules outside the layout michael@0: // engine by ensuring that all CSS style sheets have unique inners michael@0: // and, if necessary, synchronously rebuilding all style data. michael@0: void EnsureSafeToHandOutCSSRules(); michael@0: michael@0: void NotifyInvalidation(uint32_t aFlags); michael@0: void NotifyInvalidation(const nsRect& aRect, uint32_t aFlags); michael@0: // aRect is in device pixels michael@0: void NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags); michael@0: // aFlags are nsIPresShell::PAINT_ flags michael@0: void NotifyDidPaintForSubtree(uint32_t aFlags); michael@0: void FireDOMPaintEvent(nsInvalidateRequestList* aList); michael@0: michael@0: // Callback for catching invalidations in ContainerLayers michael@0: // Passed to LayerProperties::ComputeDifference michael@0: static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer, michael@0: const nsIntRegion& aRegion); michael@0: void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer); michael@0: static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer); michael@0: bool IsDOMPaintEventPending(); michael@0: void ClearMozAfterPaintEvents() { michael@0: mInvalidateRequestsSinceLastPaint.mRequests.Clear(); michael@0: mUndeliveredInvalidateRequestsBeforeLastPaint.mRequests.Clear(); michael@0: mAllInvalidated = false; michael@0: } michael@0: michael@0: bool IsProcessingRestyles() const { michael@0: return mProcessingRestyles; michael@0: } michael@0: michael@0: void SetProcessingRestyles(bool aProcessing) { michael@0: NS_ASSERTION(aProcessing != bool(mProcessingRestyles), michael@0: "should never nest"); michael@0: mProcessingRestyles = aProcessing; michael@0: } michael@0: michael@0: bool IsProcessingAnimationStyleChange() const { michael@0: return mProcessingAnimationStyleChange; michael@0: } michael@0: michael@0: void SetProcessingAnimationStyleChange(bool aProcessing) { michael@0: NS_ASSERTION(aProcessing != bool(mProcessingAnimationStyleChange), michael@0: "should never nest"); michael@0: mProcessingAnimationStyleChange = aProcessing; michael@0: } michael@0: michael@0: /** michael@0: * Notify the prescontext that the presshell is about to reflow a reflow root. michael@0: * The single argument indicates whether this reflow should be interruptible. michael@0: * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt michael@0: * will always return false. If aInterruptible is true then CheckForInterrupt michael@0: * will return true when a pending event is detected. This is for use by the michael@0: * presshell only. Reflow code wanting to prevent interrupts should use michael@0: * InterruptPreventer. michael@0: */ michael@0: void ReflowStarted(bool aInterruptible); michael@0: michael@0: /** michael@0: * A class that can be used to temporarily disable reflow interruption. michael@0: */ michael@0: class InterruptPreventer; michael@0: friend class InterruptPreventer; michael@0: class MOZ_STACK_CLASS InterruptPreventer { michael@0: public: michael@0: InterruptPreventer(nsPresContext* aCtx) : michael@0: mCtx(aCtx), michael@0: mInterruptsEnabled(aCtx->mInterruptsEnabled), michael@0: mHasPendingInterrupt(aCtx->mHasPendingInterrupt) michael@0: { michael@0: mCtx->mInterruptsEnabled = false; michael@0: mCtx->mHasPendingInterrupt = false; michael@0: } michael@0: ~InterruptPreventer() { michael@0: mCtx->mInterruptsEnabled = mInterruptsEnabled; michael@0: mCtx->mHasPendingInterrupt = mHasPendingInterrupt; michael@0: } michael@0: michael@0: private: michael@0: nsPresContext* mCtx; michael@0: bool mInterruptsEnabled; michael@0: bool mHasPendingInterrupt; michael@0: }; michael@0: michael@0: /** michael@0: * Check for interrupts. This may return true if a pending event is michael@0: * detected. Once it has returned true, it will keep returning true michael@0: * until ReflowStarted is called. In all cases where this returns true, michael@0: * the passed-in frame (which should be the frame whose reflow will be michael@0: * interrupted if true is returned) will be passed to michael@0: * nsIPresShell::FrameNeedsToContinueReflow. michael@0: */ michael@0: bool CheckForInterrupt(nsIFrame* aFrame); michael@0: /** michael@0: * Returns true if CheckForInterrupt has returned true since the last michael@0: * ReflowStarted call. Cannot itself trigger an interrupt check. michael@0: */ michael@0: bool HasPendingInterrupt() { return mHasPendingInterrupt; } michael@0: michael@0: /** michael@0: * If we have a presshell, and if the given content's current michael@0: * document is the same as our presshell's document, return the michael@0: * content's primary frame. Otherwise, return null. Only use this michael@0: * if you care about which presshell the primary frame is in. michael@0: */ michael@0: nsIFrame* GetPrimaryFrameFor(nsIContent* aContent); michael@0: michael@0: void NotifyDestroyingFrame(nsIFrame* aFrame) michael@0: { michael@0: PropertyTable()->DeleteAllFor(aFrame); michael@0: } michael@0: michael@0: virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { michael@0: return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); michael@0: } michael@0: michael@0: bool IsRootContentDocument(); michael@0: bool IsCrossProcessRootContentDocument(); michael@0: michael@0: bool IsGlyph() const { michael@0: return mIsGlyph; michael@0: } michael@0: michael@0: void SetIsGlyph(bool aValue) { michael@0: mIsGlyph = aValue; michael@0: } michael@0: michael@0: bool UsesRootEMUnits() const { michael@0: return mUsesRootEMUnits; michael@0: } michael@0: michael@0: void SetUsesRootEMUnits(bool aValue) { michael@0: mUsesRootEMUnits = aValue; michael@0: } michael@0: michael@0: bool UsesViewportUnits() const { michael@0: return mUsesViewportUnits; michael@0: } michael@0: michael@0: void SetUsesViewportUnits(bool aValue) { michael@0: mUsesViewportUnits = aValue; michael@0: } michael@0: michael@0: // true if there are OMTA transition updates for the current document which michael@0: // have been throttled, and therefore some style information may not be up michael@0: // to date michael@0: bool ExistThrottledUpdates() const { michael@0: return mExistThrottledUpdates; michael@0: } michael@0: michael@0: void SetExistThrottledUpdates(bool aExistThrottledUpdates) { michael@0: mExistThrottledUpdates = aExistThrottledUpdates; michael@0: } michael@0: michael@0: bool IsDeviceSizePageSize(); michael@0: michael@0: bool HasWarnedAboutPositionedTableParts() const { michael@0: return mHasWarnedAboutPositionedTableParts; michael@0: } michael@0: michael@0: void SetHasWarnedAboutPositionedTableParts() { michael@0: mHasWarnedAboutPositionedTableParts = true; michael@0: } michael@0: michael@0: protected: michael@0: friend class nsRunnableMethod; michael@0: NS_HIDDEN_(void) ThemeChangedInternal(); michael@0: NS_HIDDEN_(void) SysColorChangedInternal(); michael@0: NS_HIDDEN_(void) UIResolutionChangedInternal(); michael@0: michael@0: static NS_HIDDEN_(bool) michael@0: UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument, void* aData); michael@0: michael@0: NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, uint16_t aMode); michael@0: NS_HIDDEN_(void) SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode, michael@0: uint16_t aOldMode); michael@0: NS_HIDDEN_(void) GetDocumentColorPreferences(); michael@0: michael@0: NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName); michael@0: static NS_HIDDEN_(void) PrefChangedCallback(const char*, void*); michael@0: michael@0: NS_HIDDEN_(void) UpdateAfterPreferencesChanged(); michael@0: static NS_HIDDEN_(void) PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure); michael@0: michael@0: NS_HIDDEN_(void) GetUserPreferences(); michael@0: michael@0: // Allow nsAutoPtr dtor to access this protected struct's michael@0: // dtor: michael@0: struct LangGroupFontPrefs; michael@0: friend class nsAutoPtr; michael@0: struct LangGroupFontPrefs { michael@0: // Font sizes default to zero; they will be set in GetFontPreferences michael@0: LangGroupFontPrefs() michael@0: : mLangGroup(nullptr) michael@0: , mMinimumFontSize(0) michael@0: , mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, michael@0: NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: , mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, michael@0: NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, michael@0: NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: , mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, michael@0: NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: , mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, michael@0: NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, michael@0: NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: , mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, michael@0: NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, michael@0: NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: , mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, michael@0: NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, michael@0: NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: , mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, michael@0: NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, michael@0: NS_FONT_STRETCH_NORMAL, 0, 0) michael@0: {} michael@0: michael@0: size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { michael@0: size_t n = 0; michael@0: LangGroupFontPrefs *curr = mNext; michael@0: while (curr) { michael@0: n += aMallocSizeOf(curr); michael@0: michael@0: // Measurement of the following members may be added later if DMD finds michael@0: // it is worthwhile: michael@0: // - mLangGroup michael@0: // - mDefault*Font michael@0: michael@0: curr = curr->mNext; michael@0: } michael@0: return n; michael@0: } michael@0: michael@0: nsCOMPtr mLangGroup; michael@0: nscoord mMinimumFontSize; michael@0: nsFont mDefaultVariableFont; michael@0: nsFont mDefaultFixedFont; michael@0: nsFont mDefaultSerifFont; michael@0: nsFont mDefaultSansSerifFont; michael@0: nsFont mDefaultMonospaceFont; michael@0: nsFont mDefaultCursiveFont; michael@0: nsFont mDefaultFantasyFont; michael@0: nsAutoPtr mNext; michael@0: }; michael@0: michael@0: /** michael@0: * Fetch the user's font preferences for the given aLanguage's michael@0: * langugage group. michael@0: */ michael@0: const LangGroupFontPrefs* GetFontPrefsForLang(nsIAtom *aLanguage) const; michael@0: michael@0: void ResetCachedFontPrefs() { michael@0: // Throw away any other LangGroupFontPrefs objects: michael@0: mLangGroupFontPrefs.mNext = nullptr; michael@0: michael@0: // Make GetFontPreferences reinitialize mLangGroupFontPrefs: michael@0: mLangGroupFontPrefs.mLangGroup = nullptr; michael@0: } michael@0: michael@0: NS_HIDDEN_(void) UpdateCharSet(const nsCString& aCharSet); michael@0: michael@0: public: michael@0: void DoChangeCharSet(const nsCString& aCharSet); michael@0: michael@0: /** michael@0: * Checks for MozAfterPaint listeners on the document michael@0: */ michael@0: bool MayHavePaintEventListener(); michael@0: michael@0: /** michael@0: * Checks for MozAfterPaint listeners on the document and michael@0: * any subdocuments, except for subdocuments that are non-top-level michael@0: * content documents. michael@0: */ michael@0: bool MayHavePaintEventListenerInSubDocument(); michael@0: michael@0: protected: michael@0: void InvalidateThebesLayers(); michael@0: void AppUnitsPerDevPixelChanged(); michael@0: michael@0: void HandleRebuildUserFontSet() { michael@0: mPostedFlushUserFontSet = false; michael@0: FlushUserFontSet(); michael@0: } michael@0: michael@0: bool HavePendingInputEvent(); michael@0: michael@0: // Can't be inline because we can't include nsStyleSet.h. michael@0: bool HasCachedStyleData(); michael@0: michael@0: bool IsChromeSlow() const; michael@0: michael@0: // IMPORTANT: The ownership implicit in the following member variables michael@0: // has been explicitly checked. If you add any members to this class, michael@0: // please make the ownership explicit (pinkerton, scc). michael@0: michael@0: nsPresContextType mType; michael@0: nsIPresShell* mShell; // [WEAK] michael@0: nsCOMPtr mDocument; michael@0: nsRefPtr mDeviceContext; // [STRONG] could be weak, but michael@0: // better safe than sorry. michael@0: // Cannot reintroduce cycles michael@0: // since there is no dependency michael@0: // from gfx back to layout. michael@0: nsRefPtr mEventManager; michael@0: nsRefPtr mRefreshDriver; michael@0: nsRefPtr mTransitionManager; michael@0: nsRefPtr mAnimationManager; michael@0: nsRefPtr mRestyleManager; michael@0: nsIAtom* mMedium; // initialized by subclass ctors; michael@0: // weak pointer to static atom michael@0: nsCOMPtr mMediaEmulated; michael@0: michael@0: nsILinkHandler* mLinkHandler; // [WEAK] michael@0: michael@0: // Formerly mLangGroup; moving from charset-oriented langGroup to michael@0: // maintaining actual language settings everywhere (see bug 524107). michael@0: // This may in fact hold a langGroup such as x-western rather than michael@0: // a specific language, however (e.g, if it is inferred from the michael@0: // charset rather than explicitly specified as a lang attribute). michael@0: nsCOMPtr mLanguage; michael@0: michael@0: public: michael@0: // The following are public member variables so that we can use them michael@0: // with mozilla::AutoToggle or mozilla::AutoRestore. michael@0: michael@0: // Should we disable font size inflation because we're inside of michael@0: // shrink-wrapping calculations on an inflation container? michael@0: bool mInflationDisabledForShrinkWrap; michael@0: michael@0: protected: michael@0: michael@0: mozilla::WeakPtr mContainer; michael@0: michael@0: PRCList mDOMMediaQueryLists; michael@0: michael@0: // Base minimum font size, independent of the language-specific global preference. Defaults to 0 michael@0: int32_t mBaseMinFontSize; michael@0: float mTextZoom; // Text zoom, defaults to 1.0 michael@0: float mFullZoom; // Page zoom, defaults to 1.0 michael@0: michael@0: float mLastFontInflationScreenWidth; michael@0: michael@0: int32_t mCurAppUnitsPerDevPixel; michael@0: int32_t mAutoQualityMinFontSizePixelsPref; michael@0: michael@0: nsCOMPtr mTheme; michael@0: nsCOMPtr mLangService; michael@0: nsCOMPtr mPrintSettings; michael@0: nsCOMPtr mPrefChangedTimer; michael@0: michael@0: FramePropertyTable mPropertyTable; michael@0: michael@0: nsInvalidateRequestList mInvalidateRequestsSinceLastPaint; michael@0: nsInvalidateRequestList mUndeliveredInvalidateRequestsBeforeLastPaint; michael@0: michael@0: // container for per-context fonts (downloadable, SVG, etc.) michael@0: nsUserFontSet* mUserFontSet; michael@0: michael@0: // text performance metrics michael@0: nsAutoPtr mTextPerf; michael@0: michael@0: nsRect mVisibleArea; michael@0: nsSize mPageSize; michael@0: float mPageScale; michael@0: float mPPScale; michael@0: michael@0: nscolor mDefaultColor; michael@0: nscolor mBackgroundColor; michael@0: michael@0: nscolor mLinkColor; michael@0: nscolor mActiveLinkColor; michael@0: nscolor mVisitedLinkColor; michael@0: michael@0: nscolor mFocusBackgroundColor; michael@0: nscolor mFocusTextColor; michael@0: michael@0: nscolor mBodyTextColor; michael@0: michael@0: mozilla::ScrollbarStyles mViewportStyleOverflow; michael@0: uint8_t mFocusRingWidth; michael@0: michael@0: bool mExistThrottledUpdates; michael@0: michael@0: uint16_t mImageAnimationMode; michael@0: uint16_t mImageAnimationModePref; michael@0: michael@0: LangGroupFontPrefs mLangGroupFontPrefs; michael@0: michael@0: nscoord mBorderWidthTable[3]; michael@0: michael@0: uint32_t mInterruptChecksToSkip; michael@0: michael@0: mozilla::TimeStamp mReflowStartTime; michael@0: PRInt32 mMaxFontAttempts; michael@0: PRInt32 mMaxFonts; michael@0: michael@0: // last time animations styles were flushed to their primary frames michael@0: mozilla::TimeStamp mLastUpdateThrottledAnimationStyle; michael@0: // last time transition styles were flushed to their primary frames michael@0: mozilla::TimeStamp mLastUpdateThrottledTransitionStyle; michael@0: // last time we did a full style flush michael@0: mozilla::TimeStamp mLastStyleUpdateForAllAnimations; michael@0: michael@0: unsigned mHasPendingInterrupt : 1; michael@0: unsigned mInterruptsEnabled : 1; michael@0: unsigned mUseDocumentFonts : 1; michael@0: unsigned mUseDocumentColors : 1; michael@0: unsigned mUnderlineLinks : 1; michael@0: unsigned mSendAfterPaintToContent : 1; michael@0: unsigned mUseFocusColors : 1; michael@0: unsigned mFocusRingOnAnything : 1; michael@0: unsigned mFocusRingStyle : 1; michael@0: unsigned mDrawImageBackground : 1; michael@0: unsigned mDrawColorBackground : 1; michael@0: unsigned mNeverAnimate : 1; michael@0: unsigned mIsRenderingOnlySelection : 1; michael@0: unsigned mPaginated : 1; michael@0: unsigned mCanPaginatedScroll : 1; michael@0: unsigned mDoScaledTwips : 1; michael@0: unsigned mIsRootPaginatedDocument : 1; michael@0: unsigned mPrefBidiDirection : 1; michael@0: unsigned mPrefScrollbarSide : 2; michael@0: unsigned mPendingSysColorChanged : 1; michael@0: unsigned mPendingThemeChanged : 1; michael@0: unsigned mPendingUIResolutionChanged : 1; michael@0: unsigned mPendingMediaFeatureValuesChanged : 1; michael@0: unsigned mPrefChangePendingNeedsReflow : 1; michael@0: unsigned mIsEmulatingMedia : 1; michael@0: // True if the requests in mInvalidateRequestsSinceLastPaint cover the michael@0: // entire viewport michael@0: unsigned mAllInvalidated : 1; michael@0: michael@0: // Are we currently drawing an SVG glyph? michael@0: unsigned mIsGlyph : 1; michael@0: michael@0: // Does the associated document use root-em (rem) units? michael@0: unsigned mUsesRootEMUnits : 1; michael@0: // Does the associated document use viewport units (vw/vh/vmin/vmax)? michael@0: unsigned mUsesViewportUnits : 1; michael@0: michael@0: // Has there been a change to the viewport's dimensions? michael@0: unsigned mPendingViewportChange : 1; michael@0: michael@0: // Is the current mUserFontSet valid? michael@0: unsigned mUserFontSetDirty : 1; michael@0: // Has GetUserFontSet() been called? michael@0: unsigned mGetUserFontSetCalled : 1; michael@0: // Do we currently have an event posted to call FlushUserFontSet? michael@0: unsigned mPostedFlushUserFontSet : 1; michael@0: michael@0: // resize reflow is suppressed when the only change has been to zoom michael@0: // the document rather than to change the document's dimensions michael@0: unsigned mSupressResizeReflow : 1; michael@0: michael@0: unsigned mIsVisual : 1; michael@0: michael@0: unsigned mProcessingRestyles : 1; michael@0: unsigned mProcessingAnimationStyleChange : 1; michael@0: michael@0: unsigned mFireAfterPaintEvents : 1; michael@0: michael@0: unsigned mIsChrome : 1; michael@0: unsigned mIsChromeOriginImage : 1; michael@0: michael@0: // Should we paint flash in this context? Do not use this variable directly. michael@0: // Use GetPaintFlashing() method instead. michael@0: mutable unsigned mPaintFlashing : 1; michael@0: mutable unsigned mPaintFlashingInitialized : 1; michael@0: michael@0: unsigned mHasWarnedAboutPositionedTableParts : 1; michael@0: michael@0: #ifdef DEBUG michael@0: bool mInitialized; michael@0: #endif michael@0: michael@0: michael@0: protected: michael@0: michael@0: virtual ~nsPresContext() NS_HIDDEN; michael@0: michael@0: // these are private, use the list in nsFont.h if you want a public list michael@0: enum { michael@0: eDefaultFont_Variable, michael@0: eDefaultFont_Fixed, michael@0: eDefaultFont_Serif, michael@0: eDefaultFont_SansSerif, michael@0: eDefaultFont_Monospace, michael@0: eDefaultFont_Cursive, michael@0: eDefaultFont_Fantasy, michael@0: eDefaultFont_COUNT michael@0: }; michael@0: michael@0: nscolor MakeColorPref(const nsString& aColor); michael@0: michael@0: void LastRelease(); michael@0: michael@0: #ifdef DEBUG michael@0: private: michael@0: friend struct nsAutoLayoutPhase; michael@0: uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT]; michael@0: public: michael@0: uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) { michael@0: return mLayoutPhaseCount[aPhase]; michael@0: } michael@0: #endif michael@0: michael@0: }; michael@0: michael@0: class nsRootPresContext MOZ_FINAL : public nsPresContext { michael@0: public: michael@0: nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN; michael@0: virtual ~nsRootPresContext(); michael@0: virtual void Detach() MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Ensure that NotifyDidPaintForSubtree is eventually called on this michael@0: * object after a timeout. michael@0: */ michael@0: void EnsureEventualDidPaintEvent(); michael@0: michael@0: void CancelDidPaintTimer() michael@0: { michael@0: if (mNotifyDidPaintTimer) { michael@0: mNotifyDidPaintTimer->Cancel(); michael@0: mNotifyDidPaintTimer = nullptr; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Registers a plugin to receive geometry updates (position and clip michael@0: * region) so it can update its widget. michael@0: * Callers must call UnregisterPluginForGeometryUpdates before michael@0: * the aPlugin frame is destroyed. michael@0: */ michael@0: void RegisterPluginForGeometryUpdates(nsIContent* aPlugin); michael@0: /** michael@0: * Stops a plugin receiving geometry updates (position and clip michael@0: * region). If the plugin was not already registered, this does michael@0: * nothing. michael@0: */ michael@0: void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin); michael@0: michael@0: bool NeedToComputePluginGeometryUpdates() michael@0: { michael@0: return mRegisteredPlugins.Count() > 0; michael@0: } michael@0: /** michael@0: * Compute geometry updates for each plugin given that aList is the display michael@0: * list for aFrame. The updates are not yet applied; michael@0: * ApplyPluginGeometryUpdates is responsible for that. In the meantime they michael@0: * are stored on each nsObjectFrame. michael@0: * This needs to be called even when aFrame is a popup, since although michael@0: * windowed plugins aren't allowed in popups, windowless plugins are michael@0: * and ComputePluginGeometryUpdates needs to be called for them. michael@0: */ michael@0: void ComputePluginGeometryUpdates(nsIFrame* aFrame, michael@0: nsDisplayListBuilder* aBuilder, michael@0: nsDisplayList* aList); michael@0: michael@0: /** michael@0: * Apply the stored plugin geometry updates. This should normally be called michael@0: * in DidPaint so the plugins are moved/clipped immediately after we've michael@0: * updated our window, so they look in sync with our window. michael@0: */ michael@0: void ApplyPluginGeometryUpdates(); michael@0: michael@0: virtual bool IsRoot() MOZ_OVERRIDE { return true; } michael@0: michael@0: /** michael@0: * Increment DOM-modification generation counter to indicate that michael@0: * the DOM has changed in a way that might lead to style changes/ michael@0: * reflows/frame creation and destruction. michael@0: */ michael@0: void IncrementDOMGeneration() { mDOMGeneration++; } michael@0: michael@0: /** michael@0: * Get the current DOM generation counter. michael@0: * michael@0: * See nsFrameManagerBase::GetGlobalGenerationNumber() for a michael@0: * global generation number. michael@0: */ michael@0: uint32_t GetDOMGeneration() { return mDOMGeneration; } michael@0: michael@0: /** michael@0: * Add a runnable that will get called before the next paint. They will get michael@0: * run eventually even if painting doesn't happen. They might run well before michael@0: * painting happens. michael@0: */ michael@0: void AddWillPaintObserver(nsIRunnable* aRunnable); michael@0: michael@0: /** michael@0: * Run all runnables that need to get called before the next paint. michael@0: */ michael@0: void FlushWillPaintObservers(); michael@0: michael@0: virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: /** michael@0: * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates. michael@0: */ michael@0: void InitApplyPluginGeometryTimer(); michael@0: /** michael@0: * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates. michael@0: */ michael@0: void CancelApplyPluginGeometryTimer(); michael@0: michael@0: class RunWillPaintObservers : public nsRunnable { michael@0: public: michael@0: RunWillPaintObservers(nsRootPresContext* aPresContext) : mPresContext(aPresContext) {} michael@0: void Revoke() { mPresContext = nullptr; } michael@0: NS_IMETHOD Run() MOZ_OVERRIDE michael@0: { michael@0: if (mPresContext) { michael@0: mPresContext->FlushWillPaintObservers(); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: nsRootPresContext* mPresContext; michael@0: }; michael@0: michael@0: friend class nsPresContext; michael@0: michael@0: nsCOMPtr mNotifyDidPaintTimer; michael@0: nsCOMPtr mApplyPluginGeometryTimer; michael@0: nsTHashtable > mRegisteredPlugins; michael@0: nsTArray > mWillPaintObservers; michael@0: nsRevocableEventPtr mWillPaintFallbackEvent; michael@0: uint32_t mDOMGeneration; michael@0: }; michael@0: michael@0: #ifdef MOZ_REFLOW_PERF michael@0: michael@0: #define DO_GLOBAL_REFLOW_COUNT(_name) \ michael@0: aPresContext->CountReflows((_name), (nsIFrame*)this); michael@0: #else michael@0: #define DO_GLOBAL_REFLOW_COUNT(_name) michael@0: #endif // MOZ_REFLOW_PERF michael@0: michael@0: #endif /* nsPresContext_h___ */