1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/nsPresContext.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1511 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* a presentation of a document, part 1 */ 1.10 + 1.11 +#ifndef nsPresContext_h___ 1.12 +#define nsPresContext_h___ 1.13 + 1.14 +#include "mozilla/Attributes.h" 1.15 +#include "mozilla/WeakPtr.h" 1.16 +#include "nsColor.h" 1.17 +#include "nsCoord.h" 1.18 +#include "nsCOMPtr.h" 1.19 +#include "nsIPresShell.h" 1.20 +#include "nsRect.h" 1.21 +#include "nsFont.h" 1.22 +#include "gfxFontConstants.h" 1.23 +#include "nsIAtom.h" 1.24 +#include "nsIObserver.h" 1.25 +#include "nsITimer.h" 1.26 +#include "nsCRT.h" 1.27 +#include "FramePropertyTable.h" 1.28 +#include "nsGkAtoms.h" 1.29 +#include "nsCycleCollectionParticipant.h" 1.30 +#include "nsChangeHint.h" 1.31 +#include <algorithm> 1.32 +// This also pulls in gfxTypes.h, which we cannot include directly. 1.33 +#include "gfxRect.h" 1.34 +#include "nsTArray.h" 1.35 +#include "nsAutoPtr.h" 1.36 +#include "mozilla/MemoryReporting.h" 1.37 +#include "mozilla/TimeStamp.h" 1.38 +#include "mozilla/AppUnits.h" 1.39 +#include "prclist.h" 1.40 +#include "nsThreadUtils.h" 1.41 +#include "ScrollbarStyles.h" 1.42 + 1.43 +class nsBidiPresUtils; 1.44 +class nsAString; 1.45 +class nsIPrintSettings; 1.46 +class nsDocShell; 1.47 +class nsIDocShell; 1.48 +class nsIDocument; 1.49 +class nsILanguageAtomService; 1.50 +class nsITheme; 1.51 +class nsIContent; 1.52 +class nsIFrame; 1.53 +class nsFrameManager; 1.54 +class nsILinkHandler; 1.55 +class nsIAtom; 1.56 +class nsICSSPseudoComparator; 1.57 +struct nsStyleBackground; 1.58 +struct nsStyleBorder; 1.59 +class nsIRunnable; 1.60 +class gfxUserFontSet; 1.61 +class gfxTextPerfMetrics; 1.62 +class nsUserFontSet; 1.63 +struct nsFontFaceRuleContainer; 1.64 +class nsObjectFrame; 1.65 +class nsTransitionManager; 1.66 +class nsAnimationManager; 1.67 +class nsRefreshDriver; 1.68 +class nsIWidget; 1.69 +class nsDeviceContext; 1.70 + 1.71 +namespace mozilla { 1.72 +class EventStateManager; 1.73 +class RestyleManager; 1.74 +namespace dom { 1.75 +class MediaQueryList; 1.76 +} 1.77 +namespace layers { 1.78 +class ContainerLayer; 1.79 +} 1.80 +} 1.81 + 1.82 +// supported values for cached bool types 1.83 +enum nsPresContext_CachedBoolPrefType { 1.84 + kPresContext_UseDocumentColors = 1, 1.85 + kPresContext_UseDocumentFonts, 1.86 + kPresContext_UnderlineLinks 1.87 +}; 1.88 + 1.89 +// supported values for cached integer pref types 1.90 +enum nsPresContext_CachedIntPrefType { 1.91 + kPresContext_ScrollbarSide = 1, 1.92 + kPresContext_BidiDirection 1.93 +}; 1.94 + 1.95 +// IDs for the default variable and fixed fonts (not to be changed, see nsFont.h) 1.96 +// To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported. 1.97 +const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable 1.98 +const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed 1.99 + 1.100 +#ifdef DEBUG 1.101 +struct nsAutoLayoutPhase; 1.102 + 1.103 +enum nsLayoutPhase { 1.104 + eLayoutPhase_Paint, 1.105 + eLayoutPhase_Reflow, 1.106 + eLayoutPhase_FrameC, 1.107 + eLayoutPhase_COUNT 1.108 +}; 1.109 +#endif 1.110 + 1.111 +class nsInvalidateRequestList { 1.112 +public: 1.113 + struct Request { 1.114 + nsRect mRect; 1.115 + uint32_t mFlags; 1.116 + }; 1.117 + 1.118 + void TakeFrom(nsInvalidateRequestList* aList) 1.119 + { 1.120 + mRequests.MoveElementsFrom(aList->mRequests); 1.121 + } 1.122 + bool IsEmpty() { return mRequests.IsEmpty(); } 1.123 + 1.124 + nsTArray<Request> mRequests; 1.125 +}; 1.126 + 1.127 +/* Used by nsPresContext::HasAuthorSpecifiedRules */ 1.128 +#define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0) 1.129 +#define NS_AUTHOR_SPECIFIED_BORDER (1 << 1) 1.130 +#define NS_AUTHOR_SPECIFIED_PADDING (1 << 2) 1.131 +#define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3) 1.132 + 1.133 +class nsRootPresContext; 1.134 + 1.135 +// An interface for presentation contexts. Presentation contexts are 1.136 +// objects that provide an outer context for a presentation shell. 1.137 + 1.138 +class nsPresContext : public nsIObserver { 1.139 +public: 1.140 + typedef mozilla::FramePropertyTable FramePropertyTable; 1.141 + 1.142 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.143 + NS_DECL_NSIOBSERVER 1.144 + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW 1.145 + NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext) 1.146 + 1.147 + enum nsPresContextType { 1.148 + eContext_Galley, // unpaginated screen presentation 1.149 + eContext_PrintPreview, // paginated screen presentation 1.150 + eContext_Print, // paginated printer presentation 1.151 + eContext_PageLayout // paginated & editable. 1.152 + }; 1.153 + 1.154 + // Policies for rebuilding style data. 1.155 + enum StyleRebuildType { 1.156 + eRebuildStyleIfNeeded, 1.157 + eAlwaysRebuildStyle 1.158 + }; 1.159 + 1.160 + nsPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN; 1.161 + 1.162 + /** 1.163 + * Initialize the presentation context from a particular device. 1.164 + */ 1.165 + NS_HIDDEN_(nsresult) Init(nsDeviceContext* aDeviceContext); 1.166 + 1.167 + /** 1.168 + * Set the presentation shell that this context is bound to. 1.169 + * A presentation context may only be bound to a single shell. 1.170 + */ 1.171 + NS_HIDDEN_(void) SetShell(nsIPresShell* aShell); 1.172 + 1.173 + 1.174 + NS_HIDDEN_(nsPresContextType) Type() const { return mType; } 1.175 + 1.176 + /** 1.177 + * Get the PresentationShell that this context is bound to. 1.178 + */ 1.179 + nsIPresShell* PresShell() const 1.180 + { 1.181 + NS_ASSERTION(mShell, "Null pres shell"); 1.182 + return mShell; 1.183 + } 1.184 + 1.185 + nsIPresShell* GetPresShell() const { return mShell; } 1.186 + 1.187 + /** 1.188 + * Returns the parent prescontext for this one. Returns null if this is a 1.189 + * root. 1.190 + */ 1.191 + nsPresContext* GetParentPresContext(); 1.192 + 1.193 + /** 1.194 + * Returns the prescontext of the toplevel content document that contains 1.195 + * this presentation, or null if there isn't one. 1.196 + */ 1.197 + nsPresContext* GetToplevelContentDocumentPresContext(); 1.198 + 1.199 + /** 1.200 + * Returns the nearest widget for the root frame of this. 1.201 + * 1.202 + * @param aOffset If non-null the offset from the origin of the root 1.203 + * frame's view to the widget's origin (usually positive) 1.204 + * expressed in appunits of this will be returned in 1.205 + * aOffset. 1.206 + */ 1.207 + nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr); 1.208 + 1.209 + /** 1.210 + * Returns the root widget for this. 1.211 + * Note that the widget is a mediater with IME. 1.212 + */ 1.213 + nsIWidget* GetRootWidget(); 1.214 + 1.215 + /** 1.216 + * Return the presentation context for the root of the view manager 1.217 + * hierarchy that contains this presentation context, or nullptr if it can't 1.218 + * be found (e.g. it's detached). 1.219 + */ 1.220 + nsRootPresContext* GetRootPresContext(); 1.221 + nsRootPresContext* GetDisplayRootPresContext(); 1.222 + virtual bool IsRoot() { return false; } 1.223 + 1.224 + nsIDocument* Document() const 1.225 + { 1.226 + NS_ASSERTION(!mShell || !mShell->GetDocument() || 1.227 + mShell->GetDocument() == mDocument, 1.228 + "nsPresContext doesn't have the same document as nsPresShell!"); 1.229 + return mDocument; 1.230 + } 1.231 + 1.232 +#ifdef MOZILLA_INTERNAL_API 1.233 + nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); } 1.234 + 1.235 + nsFrameManager* FrameManager() 1.236 + { return PresShell()->FrameManager(); } 1.237 + 1.238 + nsCSSFrameConstructor* FrameConstructor() 1.239 + { return PresShell()->FrameConstructor(); } 1.240 + 1.241 + nsTransitionManager* TransitionManager() { return mTransitionManager; } 1.242 + nsAnimationManager* AnimationManager() { return mAnimationManager; } 1.243 + 1.244 + nsRefreshDriver* RefreshDriver() { return mRefreshDriver; } 1.245 + 1.246 + mozilla::RestyleManager* RestyleManager() { return mRestyleManager; } 1.247 +#endif 1.248 + 1.249 + /** 1.250 + * Rebuilds all style data by throwing out the old rule tree and 1.251 + * building a new one, and additionally applying aExtraHint (which 1.252 + * must not contain nsChangeHint_ReconstructFrame) to the root frame. 1.253 + * Also rebuild the user font set. 1.254 + */ 1.255 + void RebuildAllStyleData(nsChangeHint aExtraHint); 1.256 + /** 1.257 + * Just like RebuildAllStyleData, except (1) asynchronous and (2) it 1.258 + * doesn't rebuild the user font set. 1.259 + */ 1.260 + void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint); 1.261 + 1.262 + void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild, 1.263 + nsChangeHint aChangeHint = nsChangeHint(0)); 1.264 + void PostMediaFeatureValuesChangedEvent(); 1.265 + NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent(); 1.266 + void FlushPendingMediaFeatureValuesChanged() { 1.267 + if (mPendingMediaFeatureValuesChanged) 1.268 + MediaFeatureValuesChanged(eRebuildStyleIfNeeded); 1.269 + } 1.270 + 1.271 + /** 1.272 + * Support for window.matchMedia() 1.273 + */ 1.274 + already_AddRefed<mozilla::dom::MediaQueryList> 1.275 + MatchMedia(const nsAString& aMediaQueryList); 1.276 + 1.277 + /** 1.278 + * Access compatibility mode for this context. This is the same as 1.279 + * our document's compatibility mode. 1.280 + */ 1.281 + nsCompatibility CompatibilityMode() const; 1.282 + 1.283 + /** 1.284 + * Notify the context that the document's compatibility mode has changed 1.285 + */ 1.286 + NS_HIDDEN_(void) CompatibilityModeChanged(); 1.287 + 1.288 + /** 1.289 + * Access the image animation mode for this context 1.290 + */ 1.291 + uint16_t ImageAnimationMode() const { return mImageAnimationMode; } 1.292 + virtual NS_HIDDEN_(void) SetImageAnimationModeExternal(uint16_t aMode); 1.293 + NS_HIDDEN_(void) SetImageAnimationModeInternal(uint16_t aMode); 1.294 +#ifdef MOZILLA_INTERNAL_API 1.295 + void SetImageAnimationMode(uint16_t aMode) 1.296 + { SetImageAnimationModeInternal(aMode); } 1.297 +#else 1.298 + void SetImageAnimationMode(uint16_t aMode) 1.299 + { SetImageAnimationModeExternal(aMode); } 1.300 +#endif 1.301 + 1.302 + /** 1.303 + * Get medium of presentation 1.304 + */ 1.305 + nsIAtom* Medium() { 1.306 + if (!mIsEmulatingMedia) 1.307 + return mMedium; 1.308 + return mMediaEmulated; 1.309 + } 1.310 + 1.311 + /* 1.312 + * Render the document as if being viewed on a device with the specified 1.313 + * media type. 1.314 + */ 1.315 + void EmulateMedium(const nsAString& aMediaType); 1.316 + 1.317 + /* 1.318 + * Restore the viewer's natural medium 1.319 + */ 1.320 + void StopEmulatingMedium(); 1.321 + 1.322 + void* AllocateFromShell(size_t aSize) 1.323 + { 1.324 + if (mShell) 1.325 + return mShell->AllocateMisc(aSize); 1.326 + return nullptr; 1.327 + } 1.328 + 1.329 + void FreeToShell(size_t aSize, void* aFreeChunk) 1.330 + { 1.331 + NS_ASSERTION(mShell, "freeing after shutdown"); 1.332 + if (mShell) 1.333 + mShell->FreeMisc(aSize, aFreeChunk); 1.334 + } 1.335 + 1.336 + /** 1.337 + * Get the default font for the given language and generic font ID. 1.338 + * If aLanguage is nullptr, the document's language is used. 1.339 + * 1.340 + * This object is read-only, you must copy the font to modify it. 1.341 + * 1.342 + * When aFontID is kPresContext_DefaultVariableFontID or 1.343 + * kPresContext_DefaultFixedFontID (which equals 1.344 + * kGenericFont_moz_fixed, which is used for the -moz-fixed generic), 1.345 + * the nsFont returned has its name as a CSS generic family (serif or 1.346 + * sans-serif for the former, monospace for the latter), and its size 1.347 + * as the default font size for variable or fixed fonts for the 1.348 + * language group. 1.349 + * 1.350 + * For aFontID corresponding to a CSS Generic, the nsFont returned has 1.351 + * its name set to that generic font's name, and its size set to 1.352 + * the user's preference for font size for that generic and the 1.353 + * given language. 1.354 + */ 1.355 + NS_HIDDEN_(const nsFont*) GetDefaultFont(uint8_t aFontID, 1.356 + nsIAtom *aLanguage) const; 1.357 + 1.358 + /** Get a cached boolean pref, by its type */ 1.359 + // * - initially created for bugs 31816, 20760, 22963 1.360 + bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const 1.361 + { 1.362 + // If called with a constant parameter, the compiler should optimize 1.363 + // this switch statement away. 1.364 + switch (aPrefType) { 1.365 + case kPresContext_UseDocumentFonts: 1.366 + return mUseDocumentFonts; 1.367 + case kPresContext_UseDocumentColors: 1.368 + return mUseDocumentColors; 1.369 + case kPresContext_UnderlineLinks: 1.370 + return mUnderlineLinks; 1.371 + default: 1.372 + NS_ERROR("Invalid arg passed to GetCachedBoolPref"); 1.373 + } 1.374 + 1.375 + return false; 1.376 + } 1.377 + 1.378 + /** Get a cached integer pref, by its type */ 1.379 + // * - initially created for bugs 30910, 61883, 74186, 84398 1.380 + int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const 1.381 + { 1.382 + // If called with a constant parameter, the compiler should optimize 1.383 + // this switch statement away. 1.384 + switch (aPrefType) { 1.385 + case kPresContext_ScrollbarSide: 1.386 + return mPrefScrollbarSide; 1.387 + case kPresContext_BidiDirection: 1.388 + return mPrefBidiDirection; 1.389 + default: 1.390 + NS_ERROR("invalid arg passed to GetCachedIntPref"); 1.391 + } 1.392 + 1.393 + return false; 1.394 + } 1.395 + 1.396 + /** 1.397 + * Get the default colors 1.398 + */ 1.399 + const nscolor DefaultColor() const { return mDefaultColor; } 1.400 + const nscolor DefaultBackgroundColor() const { return mBackgroundColor; } 1.401 + const nscolor DefaultLinkColor() const { return mLinkColor; } 1.402 + const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; } 1.403 + const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; } 1.404 + const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; } 1.405 + const nscolor FocusTextColor() const { return mFocusTextColor; } 1.406 + 1.407 + /** 1.408 + * Body text color, for use in quirks mode only. 1.409 + */ 1.410 + const nscolor BodyTextColor() const { return mBodyTextColor; } 1.411 + void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; } 1.412 + 1.413 + bool GetUseFocusColors() const { return mUseFocusColors; } 1.414 + uint8_t FocusRingWidth() const { return mFocusRingWidth; } 1.415 + bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; } 1.416 + uint8_t GetFocusRingStyle() const { return mFocusRingStyle; } 1.417 + 1.418 + NS_HIDDEN_(void) SetContainer(nsIDocShell* aContainer); 1.419 + 1.420 + virtual nsISupports* GetContainerWeakExternal() const; 1.421 + nsISupports* GetContainerWeakInternal() const; 1.422 +#ifdef MOZILLA_INTERNAL_API 1.423 + nsISupports* GetContainerWeak() const 1.424 + { return GetContainerWeakInternal(); } 1.425 +#else 1.426 + nsISupports* GetContainerWeak() const 1.427 + { return GetContainerWeakExternal(); } 1.428 +#endif 1.429 + 1.430 + nsIDocShell* GetDocShell() const; 1.431 + 1.432 + // XXX this are going to be replaced with set/get container 1.433 + void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; } 1.434 + nsILinkHandler* GetLinkHandler() { return mLinkHandler; } 1.435 + 1.436 + /** 1.437 + * Detach this pres context - i.e. cancel relevant timers, 1.438 + * SetLinkHandler(null), SetContainer(null) etc. 1.439 + * Only to be used by the DocumentViewer. 1.440 + */ 1.441 + virtual void Detach(); 1.442 + 1.443 + /** 1.444 + * Get the visible area associated with this presentation context. 1.445 + * This is the size of the visible area that is used for 1.446 + * presenting the document. The returned value is in the standard 1.447 + * nscoord units (as scaled by the device context). 1.448 + */ 1.449 + nsRect GetVisibleArea() { return mVisibleArea; } 1.450 + 1.451 + /** 1.452 + * Set the currently visible area. The units for r are standard 1.453 + * nscoord units (as scaled by the device context). 1.454 + */ 1.455 + void SetVisibleArea(const nsRect& r) { 1.456 + if (!r.IsEqualEdges(mVisibleArea)) { 1.457 + mVisibleArea = r; 1.458 + // Visible area does not affect media queries when paginated. 1.459 + if (!IsPaginated() && HasCachedStyleData()) { 1.460 + mPendingViewportChange = true; 1.461 + PostMediaFeatureValuesChangedEvent(); 1.462 + } 1.463 + } 1.464 + } 1.465 + 1.466 + /** 1.467 + * Return true if this presentation context is a paginated 1.468 + * context. 1.469 + */ 1.470 + bool IsPaginated() const { return mPaginated; } 1.471 + 1.472 + /** 1.473 + * Sets whether the presentation context can scroll for a paginated 1.474 + * context. 1.475 + */ 1.476 + NS_HIDDEN_(void) SetPaginatedScrolling(bool aResult); 1.477 + 1.478 + /** 1.479 + * Return true if this presentation context can scroll for paginated 1.480 + * context. 1.481 + */ 1.482 + bool HasPaginatedScrolling() const { return mCanPaginatedScroll; } 1.483 + 1.484 + /** 1.485 + * Get/set the size of a page 1.486 + */ 1.487 + nsSize GetPageSize() { return mPageSize; } 1.488 + void SetPageSize(nsSize aSize) { mPageSize = aSize; } 1.489 + 1.490 + /** 1.491 + * Get/set whether this document should be treated as having real pages 1.492 + * XXX This raises the obvious question of why a document that isn't a page 1.493 + * is paginated; there isn't a good reason except history 1.494 + */ 1.495 + bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; } 1.496 + void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) 1.497 + { mIsRootPaginatedDocument = aIsRootPaginatedDocument; } 1.498 + 1.499 + /** 1.500 + * Get/set the print scaling level; used by nsPageFrame to scale up 1.501 + * pages. Set safe to call before reflow, get guaranteed to be set 1.502 + * properly after reflow. 1.503 + */ 1.504 + 1.505 + float GetPageScale() { return mPageScale; } 1.506 + void SetPageScale(float aScale) { mPageScale = aScale; } 1.507 + 1.508 + /** 1.509 + * Get/set the scaling facor to use when rendering the pages for print preview. 1.510 + * Only safe to get after print preview set up; safe to set anytime. 1.511 + * This is a scaling factor for the display of the print preview. It 1.512 + * does not affect layout. It only affects the size of the onscreen pages 1.513 + * in print preview. 1.514 + * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview 1.515 + */ 1.516 + float GetPrintPreviewScale() { return mPPScale; } 1.517 + void SetPrintPreviewScale(float aScale) { mPPScale = aScale; } 1.518 + 1.519 + nsDeviceContext* DeviceContext() { return mDeviceContext; } 1.520 + mozilla::EventStateManager* EventStateManager() { return mEventManager; } 1.521 + nsIAtom* GetLanguageFromCharset() { return mLanguage; } 1.522 + 1.523 + float TextZoom() { return mTextZoom; } 1.524 + void SetTextZoom(float aZoom) { 1.525 + if (aZoom == mTextZoom) 1.526 + return; 1.527 + 1.528 + mTextZoom = aZoom; 1.529 + if (HasCachedStyleData()) { 1.530 + // Media queries could have changed, since we changed the meaning 1.531 + // of 'em' units in them. 1.532 + MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); 1.533 + } 1.534 + } 1.535 + 1.536 + nsTArray<nsFont> mFontsUsed; // currently for font-count limiting only 1.537 + nsTArray<nsFont> mFontsTried; // currently for font-count limiting only 1.538 + void AddFontUse(const nsFont &font); 1.539 + void AddFontAttempt(const nsFont &font); 1.540 + PRBool FontUseCountReached(const nsFont &font); 1.541 + PRBool FontAttemptCountReached(const nsFont &font); 1.542 + 1.543 + /** 1.544 + * Get the minimum font size for the specified language. If aLanguage 1.545 + * is nullptr, then the document's language is used. This combines 1.546 + * the language-specific global preference with the per-presentation 1.547 + * base minimum font size. 1.548 + */ 1.549 + int32_t MinFontSize(nsIAtom *aLanguage) const { 1.550 + const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage); 1.551 + return std::max(mBaseMinFontSize, prefs->mMinimumFontSize); 1.552 + } 1.553 + 1.554 + /** 1.555 + * Get the per-presentation base minimum font size. This size is 1.556 + * independent of the language-specific global preference. 1.557 + */ 1.558 + int32_t BaseMinFontSize() const { 1.559 + return mBaseMinFontSize; 1.560 + } 1.561 + 1.562 + /** 1.563 + * Set the per-presentation base minimum font size. This size is 1.564 + * independent of the language-specific global preference. 1.565 + */ 1.566 + void SetBaseMinFontSize(int32_t aMinFontSize) { 1.567 + if (aMinFontSize == mBaseMinFontSize) 1.568 + return; 1.569 + 1.570 + mBaseMinFontSize = aMinFontSize; 1.571 + if (HasCachedStyleData()) { 1.572 + // Media queries could have changed, since we changed the meaning 1.573 + // of 'em' units in them. 1.574 + MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); 1.575 + } 1.576 + } 1.577 + 1.578 + float GetFullZoom() { return mFullZoom; } 1.579 + void SetFullZoom(float aZoom); 1.580 + 1.581 + nscoord GetAutoQualityMinFontSize() { 1.582 + return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref); 1.583 + } 1.584 + 1.585 + /** 1.586 + * Return the device's screen width in inches, for font size 1.587 + * inflation. 1.588 + * 1.589 + * If |aChanged| is non-null, then aChanged is filled in with whether 1.590 + * the return value has changed since either: 1.591 + * a. the last time the function was called with non-null aChanged, or 1.592 + * b. the first time the function was called. 1.593 + */ 1.594 + float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr); 1.595 + 1.596 + static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); } 1.597 + int32_t AppUnitsPerDevPixel() const; 1.598 + static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); } 1.599 + 1.600 + static nscoord CSSPixelsToAppUnits(int32_t aPixels) 1.601 + { return NSToCoordRoundWithClamp(float(aPixels) * 1.602 + float(AppUnitsPerCSSPixel())); } 1.603 + 1.604 + static nscoord CSSPixelsToAppUnits(float aPixels) 1.605 + { return NSToCoordRoundWithClamp(aPixels * 1.606 + float(AppUnitsPerCSSPixel())); } 1.607 + 1.608 + static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) 1.609 + { return NSAppUnitsToIntPixels(aAppUnits, 1.610 + float(AppUnitsPerCSSPixel())); } 1.611 + 1.612 + static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) 1.613 + { return NSAppUnitsToFloatPixels(aAppUnits, 1.614 + float(AppUnitsPerCSSPixel())); } 1.615 + 1.616 + nscoord DevPixelsToAppUnits(int32_t aPixels) const 1.617 + { return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel()); } 1.618 + 1.619 + int32_t AppUnitsToDevPixels(nscoord aAppUnits) const 1.620 + { return NSAppUnitsToIntPixels(aAppUnits, 1.621 + float(AppUnitsPerDevPixel())); } 1.622 + 1.623 + int32_t CSSPixelsToDevPixels(int32_t aPixels) 1.624 + { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); } 1.625 + 1.626 + float CSSPixelsToDevPixels(float aPixels) 1.627 + { 1.628 + return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels), 1.629 + float(AppUnitsPerDevPixel())); 1.630 + } 1.631 + 1.632 + int32_t DevPixelsToIntCSSPixels(int32_t aPixels) 1.633 + { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); } 1.634 + 1.635 + float DevPixelsToFloatCSSPixels(int32_t aPixels) 1.636 + { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); } 1.637 + 1.638 + // If there is a remainder, it is rounded to nearest app units. 1.639 + nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const; 1.640 + 1.641 + gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const; 1.642 + 1.643 + gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const 1.644 + { return gfxRect(AppUnitsToGfxUnits(aAppRect.x), 1.645 + AppUnitsToGfxUnits(aAppRect.y), 1.646 + AppUnitsToGfxUnits(aAppRect.width), 1.647 + AppUnitsToGfxUnits(aAppRect.height)); } 1.648 + 1.649 + static nscoord CSSTwipsToAppUnits(float aTwips) 1.650 + { return NSToCoordRoundWithClamp( 1.651 + mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); } 1.652 + 1.653 + // Margin-specific version, since they often need TwipsToAppUnits 1.654 + static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips) 1.655 + { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)), 1.656 + CSSTwipsToAppUnits(float(marginInTwips.right)), 1.657 + CSSTwipsToAppUnits(float(marginInTwips.bottom)), 1.658 + CSSTwipsToAppUnits(float(marginInTwips.left))); } 1.659 + 1.660 + static nscoord CSSPointsToAppUnits(float aPoints) 1.661 + { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() / 1.662 + POINTS_PER_INCH_FLOAT); } 1.663 + 1.664 + nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const 1.665 + { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); } 1.666 + 1.667 + void SetViewportOverflowOverride(uint8_t aX, uint8_t aY) 1.668 + { 1.669 + mViewportStyleOverflow.mHorizontal = aX; 1.670 + mViewportStyleOverflow.mVertical = aY; 1.671 + } 1.672 + mozilla::ScrollbarStyles GetViewportOverflowOverride() 1.673 + { 1.674 + return mViewportStyleOverflow; 1.675 + } 1.676 + 1.677 + /** 1.678 + * Set and get methods for controlling the background drawing 1.679 + */ 1.680 + bool GetBackgroundImageDraw() const { return mDrawImageBackground; } 1.681 + void SetBackgroundImageDraw(bool aCanDraw) 1.682 + { 1.683 + mDrawImageBackground = aCanDraw; 1.684 + } 1.685 + 1.686 + bool GetBackgroundColorDraw() const { return mDrawColorBackground; } 1.687 + void SetBackgroundColorDraw(bool aCanDraw) 1.688 + { 1.689 + mDrawColorBackground = aCanDraw; 1.690 + } 1.691 + 1.692 + /** 1.693 + * Getter and setter for OMTA time counters 1.694 + */ 1.695 + bool ThrottledTransitionStyleIsUpToDate() const; 1.696 + void TickLastUpdateThrottledTransitionStyle(); 1.697 + bool ThrottledAnimationStyleIsUpToDate() const; 1.698 + void TickLastUpdateThrottledAnimationStyle(); 1.699 + bool StyleUpdateForAllAnimationsIsUpToDate(); 1.700 + void TickLastStyleUpdateForAllAnimations(); 1.701 + 1.702 + /** 1.703 + * Check if bidi enabled (set depending on the presence of RTL 1.704 + * characters or when default directionality is RTL). 1.705 + * If enabled, we should apply the Unicode Bidi Algorithm 1.706 + * 1.707 + * @lina 07/12/2000 1.708 + */ 1.709 +#ifdef MOZILLA_INTERNAL_API 1.710 + bool BidiEnabled() const { return BidiEnabledInternal(); } 1.711 +#else 1.712 + bool BidiEnabled() const { return BidiEnabledExternal(); } 1.713 +#endif 1.714 + virtual bool BidiEnabledExternal() const; 1.715 + bool BidiEnabledInternal() const; 1.716 + 1.717 + /** 1.718 + * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm 1.719 + * 1.720 + * @lina 07/12/2000 1.721 + */ 1.722 + NS_HIDDEN_(void) SetBidiEnabled() const; 1.723 + 1.724 + /** 1.725 + * Set visual or implicit mode into the pres context. 1.726 + * 1.727 + * Visual directionality is a presentation method that displays text 1.728 + * as if it were a uni-directional, according to the primary display 1.729 + * direction only. 1.730 + * 1.731 + * Implicit directionality is a presentation method in which the 1.732 + * direction is determined by the Bidi algorithm according to the 1.733 + * category of the characters and the category of the adjacent 1.734 + * characters, and according to their primary direction. 1.735 + * 1.736 + * @lina 05/02/2000 1.737 + */ 1.738 + void SetVisualMode(bool aIsVisual) 1.739 + { 1.740 + mIsVisual = aIsVisual; 1.741 + } 1.742 + 1.743 + /** 1.744 + * Check whether the content should be treated as visual. 1.745 + * 1.746 + * @lina 05/02/2000 1.747 + */ 1.748 + bool IsVisualMode() const { return mIsVisual; } 1.749 + 1.750 +//Mohamed 1.751 + 1.752 + /** 1.753 + * Set the Bidi options for the presentation context 1.754 + */ 1.755 + NS_HIDDEN_(void) SetBidi(uint32_t aBidiOptions, 1.756 + bool aForceRestyle = false); 1.757 + 1.758 + /** 1.759 + * Get the Bidi options for the presentation context 1.760 + * Not inline so consumers of nsPresContext are not forced to 1.761 + * include nsIDocument. 1.762 + */ 1.763 + NS_HIDDEN_(uint32_t) GetBidi() const; 1.764 + 1.765 + /** 1.766 + * Render only Selection 1.767 + */ 1.768 + void SetIsRenderingOnlySelection(bool aResult) 1.769 + { 1.770 + mIsRenderingOnlySelection = aResult; 1.771 + } 1.772 + 1.773 + bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; } 1.774 + 1.775 + NS_HIDDEN_(bool) IsTopLevelWindowInactive(); 1.776 + 1.777 + /* 1.778 + * Obtain a native them for rendering our widgets (both form controls and html) 1.779 + */ 1.780 + NS_HIDDEN_(nsITheme*) GetTheme(); 1.781 + 1.782 + /* 1.783 + * Notify the pres context that the theme has changed. An internal switch 1.784 + * means it's one of our Mozilla themes that changed (e.g., Modern to Classic). 1.785 + * Otherwise, the OS is telling us that the native theme for the platform 1.786 + * has changed. 1.787 + */ 1.788 + NS_HIDDEN_(void) ThemeChanged(); 1.789 + 1.790 + /* 1.791 + * Notify the pres context that the resolution of the user interface has 1.792 + * changed. This happens if a window is moved between HiDPI and non-HiDPI 1.793 + * displays, so that the ratio of points to device pixels changes. 1.794 + */ 1.795 + NS_HIDDEN_(void) UIResolutionChanged(); 1.796 + 1.797 + /* 1.798 + * Notify the pres context that a system color has changed 1.799 + */ 1.800 + NS_HIDDEN_(void) SysColorChanged(); 1.801 + 1.802 + /** Printing methods below should only be used for Medium() == print **/ 1.803 + NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings); 1.804 + 1.805 + nsIPrintSettings* GetPrintSettings() { return mPrintSettings; } 1.806 + 1.807 + /* Accessor for table of frame properties */ 1.808 + FramePropertyTable* PropertyTable() { return &mPropertyTable; } 1.809 + 1.810 + /* Helper function that ensures that this prescontext is shown in its 1.811 + docshell if it's the most recent prescontext for the docshell. Returns 1.812 + whether the prescontext is now being shown. 1.813 + */ 1.814 + NS_HIDDEN_(bool) EnsureVisible(); 1.815 + 1.816 +#ifdef MOZ_REFLOW_PERF 1.817 + NS_HIDDEN_(void) CountReflows(const char * aName, 1.818 + nsIFrame * aFrame); 1.819 +#endif 1.820 + 1.821 + /** 1.822 + * This table maps border-width enums 'thin', 'medium', 'thick' 1.823 + * to actual nscoord values. 1.824 + */ 1.825 + const nscoord* GetBorderWidthTable() { return mBorderWidthTable; } 1.826 + 1.827 + gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; } 1.828 + 1.829 + bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); } 1.830 + bool IsScreen() { return (mMedium == nsGkAtoms::screen || 1.831 + mType == eContext_PageLayout || 1.832 + mType == eContext_PrintPreview); } 1.833 + 1.834 + // Is this presentation in a chrome docshell? 1.835 + bool IsChrome() const { return mIsChrome; } 1.836 + bool IsChromeOriginImage() const { return mIsChromeOriginImage; } 1.837 + void UpdateIsChrome(); 1.838 + 1.839 + // Public API for native theme code to get style internals. 1.840 + virtual bool HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const; 1.841 + 1.842 + // Is it OK to let the page specify colors and backgrounds? 1.843 + bool UseDocumentColors() const { 1.844 + return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome() || IsChromeOriginImage(); 1.845 + } 1.846 + 1.847 + // Explicitly enable and disable paint flashing. 1.848 + void SetPaintFlashing(bool aPaintFlashing) { 1.849 + mPaintFlashing = aPaintFlashing; 1.850 + mPaintFlashingInitialized = true; 1.851 + } 1.852 + 1.853 + // This method should be used instead of directly accessing mPaintFlashing, 1.854 + // as that value may be out of date when mPaintFlashingInitialized is false. 1.855 + bool GetPaintFlashing() const; 1.856 + 1.857 + bool SupressingResizeReflow() const { return mSupressResizeReflow; } 1.858 + 1.859 + virtual NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetExternal(); 1.860 + NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetInternal(); 1.861 +#ifdef MOZILLA_INTERNAL_API 1.862 + gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); } 1.863 +#else 1.864 + gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); } 1.865 +#endif 1.866 + 1.867 + void FlushUserFontSet(); 1.868 + void RebuildUserFontSet(); // asynchronously 1.869 + 1.870 + // Should be called whenever the set of fonts available in the user 1.871 + // font set changes (e.g., because a new font loads, or because the 1.872 + // user font set is changed and fonts become unavailable). 1.873 + void UserFontSetUpdated(); 1.874 + 1.875 + // Ensure that it is safe to hand out CSS rules outside the layout 1.876 + // engine by ensuring that all CSS style sheets have unique inners 1.877 + // and, if necessary, synchronously rebuilding all style data. 1.878 + void EnsureSafeToHandOutCSSRules(); 1.879 + 1.880 + void NotifyInvalidation(uint32_t aFlags); 1.881 + void NotifyInvalidation(const nsRect& aRect, uint32_t aFlags); 1.882 + // aRect is in device pixels 1.883 + void NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags); 1.884 + // aFlags are nsIPresShell::PAINT_ flags 1.885 + void NotifyDidPaintForSubtree(uint32_t aFlags); 1.886 + void FireDOMPaintEvent(nsInvalidateRequestList* aList); 1.887 + 1.888 + // Callback for catching invalidations in ContainerLayers 1.889 + // Passed to LayerProperties::ComputeDifference 1.890 + static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer, 1.891 + const nsIntRegion& aRegion); 1.892 + void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer); 1.893 + static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer); 1.894 + bool IsDOMPaintEventPending(); 1.895 + void ClearMozAfterPaintEvents() { 1.896 + mInvalidateRequestsSinceLastPaint.mRequests.Clear(); 1.897 + mUndeliveredInvalidateRequestsBeforeLastPaint.mRequests.Clear(); 1.898 + mAllInvalidated = false; 1.899 + } 1.900 + 1.901 + bool IsProcessingRestyles() const { 1.902 + return mProcessingRestyles; 1.903 + } 1.904 + 1.905 + void SetProcessingRestyles(bool aProcessing) { 1.906 + NS_ASSERTION(aProcessing != bool(mProcessingRestyles), 1.907 + "should never nest"); 1.908 + mProcessingRestyles = aProcessing; 1.909 + } 1.910 + 1.911 + bool IsProcessingAnimationStyleChange() const { 1.912 + return mProcessingAnimationStyleChange; 1.913 + } 1.914 + 1.915 + void SetProcessingAnimationStyleChange(bool aProcessing) { 1.916 + NS_ASSERTION(aProcessing != bool(mProcessingAnimationStyleChange), 1.917 + "should never nest"); 1.918 + mProcessingAnimationStyleChange = aProcessing; 1.919 + } 1.920 + 1.921 + /** 1.922 + * Notify the prescontext that the presshell is about to reflow a reflow root. 1.923 + * The single argument indicates whether this reflow should be interruptible. 1.924 + * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt 1.925 + * will always return false. If aInterruptible is true then CheckForInterrupt 1.926 + * will return true when a pending event is detected. This is for use by the 1.927 + * presshell only. Reflow code wanting to prevent interrupts should use 1.928 + * InterruptPreventer. 1.929 + */ 1.930 + void ReflowStarted(bool aInterruptible); 1.931 + 1.932 + /** 1.933 + * A class that can be used to temporarily disable reflow interruption. 1.934 + */ 1.935 + class InterruptPreventer; 1.936 + friend class InterruptPreventer; 1.937 + class MOZ_STACK_CLASS InterruptPreventer { 1.938 + public: 1.939 + InterruptPreventer(nsPresContext* aCtx) : 1.940 + mCtx(aCtx), 1.941 + mInterruptsEnabled(aCtx->mInterruptsEnabled), 1.942 + mHasPendingInterrupt(aCtx->mHasPendingInterrupt) 1.943 + { 1.944 + mCtx->mInterruptsEnabled = false; 1.945 + mCtx->mHasPendingInterrupt = false; 1.946 + } 1.947 + ~InterruptPreventer() { 1.948 + mCtx->mInterruptsEnabled = mInterruptsEnabled; 1.949 + mCtx->mHasPendingInterrupt = mHasPendingInterrupt; 1.950 + } 1.951 + 1.952 + private: 1.953 + nsPresContext* mCtx; 1.954 + bool mInterruptsEnabled; 1.955 + bool mHasPendingInterrupt; 1.956 + }; 1.957 + 1.958 + /** 1.959 + * Check for interrupts. This may return true if a pending event is 1.960 + * detected. Once it has returned true, it will keep returning true 1.961 + * until ReflowStarted is called. In all cases where this returns true, 1.962 + * the passed-in frame (which should be the frame whose reflow will be 1.963 + * interrupted if true is returned) will be passed to 1.964 + * nsIPresShell::FrameNeedsToContinueReflow. 1.965 + */ 1.966 + bool CheckForInterrupt(nsIFrame* aFrame); 1.967 + /** 1.968 + * Returns true if CheckForInterrupt has returned true since the last 1.969 + * ReflowStarted call. Cannot itself trigger an interrupt check. 1.970 + */ 1.971 + bool HasPendingInterrupt() { return mHasPendingInterrupt; } 1.972 + 1.973 + /** 1.974 + * If we have a presshell, and if the given content's current 1.975 + * document is the same as our presshell's document, return the 1.976 + * content's primary frame. Otherwise, return null. Only use this 1.977 + * if you care about which presshell the primary frame is in. 1.978 + */ 1.979 + nsIFrame* GetPrimaryFrameFor(nsIContent* aContent); 1.980 + 1.981 + void NotifyDestroyingFrame(nsIFrame* aFrame) 1.982 + { 1.983 + PropertyTable()->DeleteAllFor(aFrame); 1.984 + } 1.985 + 1.986 + virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 1.987 + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { 1.988 + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); 1.989 + } 1.990 + 1.991 + bool IsRootContentDocument(); 1.992 + bool IsCrossProcessRootContentDocument(); 1.993 + 1.994 + bool IsGlyph() const { 1.995 + return mIsGlyph; 1.996 + } 1.997 + 1.998 + void SetIsGlyph(bool aValue) { 1.999 + mIsGlyph = aValue; 1.1000 + } 1.1001 + 1.1002 + bool UsesRootEMUnits() const { 1.1003 + return mUsesRootEMUnits; 1.1004 + } 1.1005 + 1.1006 + void SetUsesRootEMUnits(bool aValue) { 1.1007 + mUsesRootEMUnits = aValue; 1.1008 + } 1.1009 + 1.1010 + bool UsesViewportUnits() const { 1.1011 + return mUsesViewportUnits; 1.1012 + } 1.1013 + 1.1014 + void SetUsesViewportUnits(bool aValue) { 1.1015 + mUsesViewportUnits = aValue; 1.1016 + } 1.1017 + 1.1018 + // true if there are OMTA transition updates for the current document which 1.1019 + // have been throttled, and therefore some style information may not be up 1.1020 + // to date 1.1021 + bool ExistThrottledUpdates() const { 1.1022 + return mExistThrottledUpdates; 1.1023 + } 1.1024 + 1.1025 + void SetExistThrottledUpdates(bool aExistThrottledUpdates) { 1.1026 + mExistThrottledUpdates = aExistThrottledUpdates; 1.1027 + } 1.1028 + 1.1029 + bool IsDeviceSizePageSize(); 1.1030 + 1.1031 + bool HasWarnedAboutPositionedTableParts() const { 1.1032 + return mHasWarnedAboutPositionedTableParts; 1.1033 + } 1.1034 + 1.1035 + void SetHasWarnedAboutPositionedTableParts() { 1.1036 + mHasWarnedAboutPositionedTableParts = true; 1.1037 + } 1.1038 + 1.1039 +protected: 1.1040 + friend class nsRunnableMethod<nsPresContext>; 1.1041 + NS_HIDDEN_(void) ThemeChangedInternal(); 1.1042 + NS_HIDDEN_(void) SysColorChangedInternal(); 1.1043 + NS_HIDDEN_(void) UIResolutionChangedInternal(); 1.1044 + 1.1045 + static NS_HIDDEN_(bool) 1.1046 + UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument, void* aData); 1.1047 + 1.1048 + NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, uint16_t aMode); 1.1049 + NS_HIDDEN_(void) SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode, 1.1050 + uint16_t aOldMode); 1.1051 + NS_HIDDEN_(void) GetDocumentColorPreferences(); 1.1052 + 1.1053 + NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName); 1.1054 + static NS_HIDDEN_(void) PrefChangedCallback(const char*, void*); 1.1055 + 1.1056 + NS_HIDDEN_(void) UpdateAfterPreferencesChanged(); 1.1057 + static NS_HIDDEN_(void) PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure); 1.1058 + 1.1059 + NS_HIDDEN_(void) GetUserPreferences(); 1.1060 + 1.1061 + // Allow nsAutoPtr<LangGroupFontPrefs> dtor to access this protected struct's 1.1062 + // dtor: 1.1063 + struct LangGroupFontPrefs; 1.1064 + friend class nsAutoPtr<LangGroupFontPrefs>; 1.1065 + struct LangGroupFontPrefs { 1.1066 + // Font sizes default to zero; they will be set in GetFontPreferences 1.1067 + LangGroupFontPrefs() 1.1068 + : mLangGroup(nullptr) 1.1069 + , mMinimumFontSize(0) 1.1070 + , mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, 1.1071 + NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0) 1.1072 + , mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, 1.1073 + NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 1.1074 + NS_FONT_STRETCH_NORMAL, 0, 0) 1.1075 + , mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, 1.1076 + NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0) 1.1077 + , mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, 1.1078 + NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 1.1079 + NS_FONT_STRETCH_NORMAL, 0, 0) 1.1080 + , mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, 1.1081 + NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 1.1082 + NS_FONT_STRETCH_NORMAL, 0, 0) 1.1083 + , mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, 1.1084 + NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 1.1085 + NS_FONT_STRETCH_NORMAL, 0, 0) 1.1086 + , mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, 1.1087 + NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 1.1088 + NS_FONT_STRETCH_NORMAL, 0, 0) 1.1089 + {} 1.1090 + 1.1091 + size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { 1.1092 + size_t n = 0; 1.1093 + LangGroupFontPrefs *curr = mNext; 1.1094 + while (curr) { 1.1095 + n += aMallocSizeOf(curr); 1.1096 + 1.1097 + // Measurement of the following members may be added later if DMD finds 1.1098 + // it is worthwhile: 1.1099 + // - mLangGroup 1.1100 + // - mDefault*Font 1.1101 + 1.1102 + curr = curr->mNext; 1.1103 + } 1.1104 + return n; 1.1105 + } 1.1106 + 1.1107 + nsCOMPtr<nsIAtom> mLangGroup; 1.1108 + nscoord mMinimumFontSize; 1.1109 + nsFont mDefaultVariableFont; 1.1110 + nsFont mDefaultFixedFont; 1.1111 + nsFont mDefaultSerifFont; 1.1112 + nsFont mDefaultSansSerifFont; 1.1113 + nsFont mDefaultMonospaceFont; 1.1114 + nsFont mDefaultCursiveFont; 1.1115 + nsFont mDefaultFantasyFont; 1.1116 + nsAutoPtr<LangGroupFontPrefs> mNext; 1.1117 + }; 1.1118 + 1.1119 + /** 1.1120 + * Fetch the user's font preferences for the given aLanguage's 1.1121 + * langugage group. 1.1122 + */ 1.1123 + const LangGroupFontPrefs* GetFontPrefsForLang(nsIAtom *aLanguage) const; 1.1124 + 1.1125 + void ResetCachedFontPrefs() { 1.1126 + // Throw away any other LangGroupFontPrefs objects: 1.1127 + mLangGroupFontPrefs.mNext = nullptr; 1.1128 + 1.1129 + // Make GetFontPreferences reinitialize mLangGroupFontPrefs: 1.1130 + mLangGroupFontPrefs.mLangGroup = nullptr; 1.1131 + } 1.1132 + 1.1133 + NS_HIDDEN_(void) UpdateCharSet(const nsCString& aCharSet); 1.1134 + 1.1135 +public: 1.1136 + void DoChangeCharSet(const nsCString& aCharSet); 1.1137 + 1.1138 + /** 1.1139 + * Checks for MozAfterPaint listeners on the document 1.1140 + */ 1.1141 + bool MayHavePaintEventListener(); 1.1142 + 1.1143 + /** 1.1144 + * Checks for MozAfterPaint listeners on the document and 1.1145 + * any subdocuments, except for subdocuments that are non-top-level 1.1146 + * content documents. 1.1147 + */ 1.1148 + bool MayHavePaintEventListenerInSubDocument(); 1.1149 + 1.1150 +protected: 1.1151 + void InvalidateThebesLayers(); 1.1152 + void AppUnitsPerDevPixelChanged(); 1.1153 + 1.1154 + void HandleRebuildUserFontSet() { 1.1155 + mPostedFlushUserFontSet = false; 1.1156 + FlushUserFontSet(); 1.1157 + } 1.1158 + 1.1159 + bool HavePendingInputEvent(); 1.1160 + 1.1161 + // Can't be inline because we can't include nsStyleSet.h. 1.1162 + bool HasCachedStyleData(); 1.1163 + 1.1164 + bool IsChromeSlow() const; 1.1165 + 1.1166 + // IMPORTANT: The ownership implicit in the following member variables 1.1167 + // has been explicitly checked. If you add any members to this class, 1.1168 + // please make the ownership explicit (pinkerton, scc). 1.1169 + 1.1170 + nsPresContextType mType; 1.1171 + nsIPresShell* mShell; // [WEAK] 1.1172 + nsCOMPtr<nsIDocument> mDocument; 1.1173 + nsRefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but 1.1174 + // better safe than sorry. 1.1175 + // Cannot reintroduce cycles 1.1176 + // since there is no dependency 1.1177 + // from gfx back to layout. 1.1178 + nsRefPtr<mozilla::EventStateManager> mEventManager; 1.1179 + nsRefPtr<nsRefreshDriver> mRefreshDriver; 1.1180 + nsRefPtr<nsTransitionManager> mTransitionManager; 1.1181 + nsRefPtr<nsAnimationManager> mAnimationManager; 1.1182 + nsRefPtr<mozilla::RestyleManager> mRestyleManager; 1.1183 + nsIAtom* mMedium; // initialized by subclass ctors; 1.1184 + // weak pointer to static atom 1.1185 + nsCOMPtr<nsIAtom> mMediaEmulated; 1.1186 + 1.1187 + nsILinkHandler* mLinkHandler; // [WEAK] 1.1188 + 1.1189 + // Formerly mLangGroup; moving from charset-oriented langGroup to 1.1190 + // maintaining actual language settings everywhere (see bug 524107). 1.1191 + // This may in fact hold a langGroup such as x-western rather than 1.1192 + // a specific language, however (e.g, if it is inferred from the 1.1193 + // charset rather than explicitly specified as a lang attribute). 1.1194 + nsCOMPtr<nsIAtom> mLanguage; 1.1195 + 1.1196 +public: 1.1197 + // The following are public member variables so that we can use them 1.1198 + // with mozilla::AutoToggle or mozilla::AutoRestore. 1.1199 + 1.1200 + // Should we disable font size inflation because we're inside of 1.1201 + // shrink-wrapping calculations on an inflation container? 1.1202 + bool mInflationDisabledForShrinkWrap; 1.1203 + 1.1204 +protected: 1.1205 + 1.1206 + mozilla::WeakPtr<nsDocShell> mContainer; 1.1207 + 1.1208 + PRCList mDOMMediaQueryLists; 1.1209 + 1.1210 + // Base minimum font size, independent of the language-specific global preference. Defaults to 0 1.1211 + int32_t mBaseMinFontSize; 1.1212 + float mTextZoom; // Text zoom, defaults to 1.0 1.1213 + float mFullZoom; // Page zoom, defaults to 1.0 1.1214 + 1.1215 + float mLastFontInflationScreenWidth; 1.1216 + 1.1217 + int32_t mCurAppUnitsPerDevPixel; 1.1218 + int32_t mAutoQualityMinFontSizePixelsPref; 1.1219 + 1.1220 + nsCOMPtr<nsITheme> mTheme; 1.1221 + nsCOMPtr<nsILanguageAtomService> mLangService; 1.1222 + nsCOMPtr<nsIPrintSettings> mPrintSettings; 1.1223 + nsCOMPtr<nsITimer> mPrefChangedTimer; 1.1224 + 1.1225 + FramePropertyTable mPropertyTable; 1.1226 + 1.1227 + nsInvalidateRequestList mInvalidateRequestsSinceLastPaint; 1.1228 + nsInvalidateRequestList mUndeliveredInvalidateRequestsBeforeLastPaint; 1.1229 + 1.1230 + // container for per-context fonts (downloadable, SVG, etc.) 1.1231 + nsUserFontSet* mUserFontSet; 1.1232 + 1.1233 + // text performance metrics 1.1234 + nsAutoPtr<gfxTextPerfMetrics> mTextPerf; 1.1235 + 1.1236 + nsRect mVisibleArea; 1.1237 + nsSize mPageSize; 1.1238 + float mPageScale; 1.1239 + float mPPScale; 1.1240 + 1.1241 + nscolor mDefaultColor; 1.1242 + nscolor mBackgroundColor; 1.1243 + 1.1244 + nscolor mLinkColor; 1.1245 + nscolor mActiveLinkColor; 1.1246 + nscolor mVisitedLinkColor; 1.1247 + 1.1248 + nscolor mFocusBackgroundColor; 1.1249 + nscolor mFocusTextColor; 1.1250 + 1.1251 + nscolor mBodyTextColor; 1.1252 + 1.1253 + mozilla::ScrollbarStyles mViewportStyleOverflow; 1.1254 + uint8_t mFocusRingWidth; 1.1255 + 1.1256 + bool mExistThrottledUpdates; 1.1257 + 1.1258 + uint16_t mImageAnimationMode; 1.1259 + uint16_t mImageAnimationModePref; 1.1260 + 1.1261 + LangGroupFontPrefs mLangGroupFontPrefs; 1.1262 + 1.1263 + nscoord mBorderWidthTable[3]; 1.1264 + 1.1265 + uint32_t mInterruptChecksToSkip; 1.1266 + 1.1267 + mozilla::TimeStamp mReflowStartTime; 1.1268 + PRInt32 mMaxFontAttempts; 1.1269 + PRInt32 mMaxFonts; 1.1270 + 1.1271 + // last time animations styles were flushed to their primary frames 1.1272 + mozilla::TimeStamp mLastUpdateThrottledAnimationStyle; 1.1273 + // last time transition styles were flushed to their primary frames 1.1274 + mozilla::TimeStamp mLastUpdateThrottledTransitionStyle; 1.1275 + // last time we did a full style flush 1.1276 + mozilla::TimeStamp mLastStyleUpdateForAllAnimations; 1.1277 + 1.1278 + unsigned mHasPendingInterrupt : 1; 1.1279 + unsigned mInterruptsEnabled : 1; 1.1280 + unsigned mUseDocumentFonts : 1; 1.1281 + unsigned mUseDocumentColors : 1; 1.1282 + unsigned mUnderlineLinks : 1; 1.1283 + unsigned mSendAfterPaintToContent : 1; 1.1284 + unsigned mUseFocusColors : 1; 1.1285 + unsigned mFocusRingOnAnything : 1; 1.1286 + unsigned mFocusRingStyle : 1; 1.1287 + unsigned mDrawImageBackground : 1; 1.1288 + unsigned mDrawColorBackground : 1; 1.1289 + unsigned mNeverAnimate : 1; 1.1290 + unsigned mIsRenderingOnlySelection : 1; 1.1291 + unsigned mPaginated : 1; 1.1292 + unsigned mCanPaginatedScroll : 1; 1.1293 + unsigned mDoScaledTwips : 1; 1.1294 + unsigned mIsRootPaginatedDocument : 1; 1.1295 + unsigned mPrefBidiDirection : 1; 1.1296 + unsigned mPrefScrollbarSide : 2; 1.1297 + unsigned mPendingSysColorChanged : 1; 1.1298 + unsigned mPendingThemeChanged : 1; 1.1299 + unsigned mPendingUIResolutionChanged : 1; 1.1300 + unsigned mPendingMediaFeatureValuesChanged : 1; 1.1301 + unsigned mPrefChangePendingNeedsReflow : 1; 1.1302 + unsigned mIsEmulatingMedia : 1; 1.1303 + // True if the requests in mInvalidateRequestsSinceLastPaint cover the 1.1304 + // entire viewport 1.1305 + unsigned mAllInvalidated : 1; 1.1306 + 1.1307 + // Are we currently drawing an SVG glyph? 1.1308 + unsigned mIsGlyph : 1; 1.1309 + 1.1310 + // Does the associated document use root-em (rem) units? 1.1311 + unsigned mUsesRootEMUnits : 1; 1.1312 + // Does the associated document use viewport units (vw/vh/vmin/vmax)? 1.1313 + unsigned mUsesViewportUnits : 1; 1.1314 + 1.1315 + // Has there been a change to the viewport's dimensions? 1.1316 + unsigned mPendingViewportChange : 1; 1.1317 + 1.1318 + // Is the current mUserFontSet valid? 1.1319 + unsigned mUserFontSetDirty : 1; 1.1320 + // Has GetUserFontSet() been called? 1.1321 + unsigned mGetUserFontSetCalled : 1; 1.1322 + // Do we currently have an event posted to call FlushUserFontSet? 1.1323 + unsigned mPostedFlushUserFontSet : 1; 1.1324 + 1.1325 + // resize reflow is suppressed when the only change has been to zoom 1.1326 + // the document rather than to change the document's dimensions 1.1327 + unsigned mSupressResizeReflow : 1; 1.1328 + 1.1329 + unsigned mIsVisual : 1; 1.1330 + 1.1331 + unsigned mProcessingRestyles : 1; 1.1332 + unsigned mProcessingAnimationStyleChange : 1; 1.1333 + 1.1334 + unsigned mFireAfterPaintEvents : 1; 1.1335 + 1.1336 + unsigned mIsChrome : 1; 1.1337 + unsigned mIsChromeOriginImage : 1; 1.1338 + 1.1339 + // Should we paint flash in this context? Do not use this variable directly. 1.1340 + // Use GetPaintFlashing() method instead. 1.1341 + mutable unsigned mPaintFlashing : 1; 1.1342 + mutable unsigned mPaintFlashingInitialized : 1; 1.1343 + 1.1344 + unsigned mHasWarnedAboutPositionedTableParts : 1; 1.1345 + 1.1346 +#ifdef DEBUG 1.1347 + bool mInitialized; 1.1348 +#endif 1.1349 + 1.1350 + 1.1351 +protected: 1.1352 + 1.1353 + virtual ~nsPresContext() NS_HIDDEN; 1.1354 + 1.1355 + // these are private, use the list in nsFont.h if you want a public list 1.1356 + enum { 1.1357 + eDefaultFont_Variable, 1.1358 + eDefaultFont_Fixed, 1.1359 + eDefaultFont_Serif, 1.1360 + eDefaultFont_SansSerif, 1.1361 + eDefaultFont_Monospace, 1.1362 + eDefaultFont_Cursive, 1.1363 + eDefaultFont_Fantasy, 1.1364 + eDefaultFont_COUNT 1.1365 + }; 1.1366 + 1.1367 + nscolor MakeColorPref(const nsString& aColor); 1.1368 + 1.1369 + void LastRelease(); 1.1370 + 1.1371 +#ifdef DEBUG 1.1372 +private: 1.1373 + friend struct nsAutoLayoutPhase; 1.1374 + uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT]; 1.1375 +public: 1.1376 + uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) { 1.1377 + return mLayoutPhaseCount[aPhase]; 1.1378 + } 1.1379 +#endif 1.1380 + 1.1381 +}; 1.1382 + 1.1383 +class nsRootPresContext MOZ_FINAL : public nsPresContext { 1.1384 +public: 1.1385 + nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN; 1.1386 + virtual ~nsRootPresContext(); 1.1387 + virtual void Detach() MOZ_OVERRIDE; 1.1388 + 1.1389 + /** 1.1390 + * Ensure that NotifyDidPaintForSubtree is eventually called on this 1.1391 + * object after a timeout. 1.1392 + */ 1.1393 + void EnsureEventualDidPaintEvent(); 1.1394 + 1.1395 + void CancelDidPaintTimer() 1.1396 + { 1.1397 + if (mNotifyDidPaintTimer) { 1.1398 + mNotifyDidPaintTimer->Cancel(); 1.1399 + mNotifyDidPaintTimer = nullptr; 1.1400 + } 1.1401 + } 1.1402 + 1.1403 + /** 1.1404 + * Registers a plugin to receive geometry updates (position and clip 1.1405 + * region) so it can update its widget. 1.1406 + * Callers must call UnregisterPluginForGeometryUpdates before 1.1407 + * the aPlugin frame is destroyed. 1.1408 + */ 1.1409 + void RegisterPluginForGeometryUpdates(nsIContent* aPlugin); 1.1410 + /** 1.1411 + * Stops a plugin receiving geometry updates (position and clip 1.1412 + * region). If the plugin was not already registered, this does 1.1413 + * nothing. 1.1414 + */ 1.1415 + void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin); 1.1416 + 1.1417 + bool NeedToComputePluginGeometryUpdates() 1.1418 + { 1.1419 + return mRegisteredPlugins.Count() > 0; 1.1420 + } 1.1421 + /** 1.1422 + * Compute geometry updates for each plugin given that aList is the display 1.1423 + * list for aFrame. The updates are not yet applied; 1.1424 + * ApplyPluginGeometryUpdates is responsible for that. In the meantime they 1.1425 + * are stored on each nsObjectFrame. 1.1426 + * This needs to be called even when aFrame is a popup, since although 1.1427 + * windowed plugins aren't allowed in popups, windowless plugins are 1.1428 + * and ComputePluginGeometryUpdates needs to be called for them. 1.1429 + */ 1.1430 + void ComputePluginGeometryUpdates(nsIFrame* aFrame, 1.1431 + nsDisplayListBuilder* aBuilder, 1.1432 + nsDisplayList* aList); 1.1433 + 1.1434 + /** 1.1435 + * Apply the stored plugin geometry updates. This should normally be called 1.1436 + * in DidPaint so the plugins are moved/clipped immediately after we've 1.1437 + * updated our window, so they look in sync with our window. 1.1438 + */ 1.1439 + void ApplyPluginGeometryUpdates(); 1.1440 + 1.1441 + virtual bool IsRoot() MOZ_OVERRIDE { return true; } 1.1442 + 1.1443 + /** 1.1444 + * Increment DOM-modification generation counter to indicate that 1.1445 + * the DOM has changed in a way that might lead to style changes/ 1.1446 + * reflows/frame creation and destruction. 1.1447 + */ 1.1448 + void IncrementDOMGeneration() { mDOMGeneration++; } 1.1449 + 1.1450 + /** 1.1451 + * Get the current DOM generation counter. 1.1452 + * 1.1453 + * See nsFrameManagerBase::GetGlobalGenerationNumber() for a 1.1454 + * global generation number. 1.1455 + */ 1.1456 + uint32_t GetDOMGeneration() { return mDOMGeneration; } 1.1457 + 1.1458 + /** 1.1459 + * Add a runnable that will get called before the next paint. They will get 1.1460 + * run eventually even if painting doesn't happen. They might run well before 1.1461 + * painting happens. 1.1462 + */ 1.1463 + void AddWillPaintObserver(nsIRunnable* aRunnable); 1.1464 + 1.1465 + /** 1.1466 + * Run all runnables that need to get called before the next paint. 1.1467 + */ 1.1468 + void FlushWillPaintObservers(); 1.1469 + 1.1470 + virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; 1.1471 + 1.1472 +protected: 1.1473 + /** 1.1474 + * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates. 1.1475 + */ 1.1476 + void InitApplyPluginGeometryTimer(); 1.1477 + /** 1.1478 + * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates. 1.1479 + */ 1.1480 + void CancelApplyPluginGeometryTimer(); 1.1481 + 1.1482 + class RunWillPaintObservers : public nsRunnable { 1.1483 + public: 1.1484 + RunWillPaintObservers(nsRootPresContext* aPresContext) : mPresContext(aPresContext) {} 1.1485 + void Revoke() { mPresContext = nullptr; } 1.1486 + NS_IMETHOD Run() MOZ_OVERRIDE 1.1487 + { 1.1488 + if (mPresContext) { 1.1489 + mPresContext->FlushWillPaintObservers(); 1.1490 + } 1.1491 + return NS_OK; 1.1492 + } 1.1493 + nsRootPresContext* mPresContext; 1.1494 + }; 1.1495 + 1.1496 + friend class nsPresContext; 1.1497 + 1.1498 + nsCOMPtr<nsITimer> mNotifyDidPaintTimer; 1.1499 + nsCOMPtr<nsITimer> mApplyPluginGeometryTimer; 1.1500 + nsTHashtable<nsRefPtrHashKey<nsIContent> > mRegisteredPlugins; 1.1501 + nsTArray<nsCOMPtr<nsIRunnable> > mWillPaintObservers; 1.1502 + nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent; 1.1503 + uint32_t mDOMGeneration; 1.1504 +}; 1.1505 + 1.1506 +#ifdef MOZ_REFLOW_PERF 1.1507 + 1.1508 +#define DO_GLOBAL_REFLOW_COUNT(_name) \ 1.1509 + aPresContext->CountReflows((_name), (nsIFrame*)this); 1.1510 +#else 1.1511 +#define DO_GLOBAL_REFLOW_COUNT(_name) 1.1512 +#endif // MOZ_REFLOW_PERF 1.1513 + 1.1514 +#endif /* nsPresContext_h___ */