/work/obj-fuzz/dist/include/nsPresContext.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* a presentation of a document, part 1 */ |
8 | | |
9 | | #ifndef nsPresContext_h___ |
10 | | #define nsPresContext_h___ |
11 | | |
12 | | #include "mozilla/Attributes.h" |
13 | | #include "mozilla/MediaFeatureChange.h" |
14 | | #include "mozilla/NotNull.h" |
15 | | #include "mozilla/ScrollStyles.h" |
16 | | #include "mozilla/UniquePtr.h" |
17 | | #include "mozilla/WeakPtr.h" |
18 | | #include "nsColor.h" |
19 | | #include "nsCoord.h" |
20 | | #include "nsCOMPtr.h" |
21 | | #include "nsIPresShell.h" |
22 | | #include "nsIPresShellInlines.h" |
23 | | #include "nsRect.h" |
24 | | #include "nsStringFwd.h" |
25 | | #include "nsFont.h" |
26 | | #include "gfxFontConstants.h" |
27 | | #include "nsAtom.h" |
28 | | #include "nsITimer.h" |
29 | | #include "nsCRT.h" |
30 | | #include "nsIWidgetListener.h" |
31 | | #include "nsLanguageAtomService.h" |
32 | | #include "nsGkAtoms.h" |
33 | | #include "nsCycleCollectionParticipant.h" |
34 | | #include "nsChangeHint.h" |
35 | | #include <algorithm> |
36 | | #include "gfxTypes.h" |
37 | | #include "gfxRect.h" |
38 | | #include "nsTArray.h" |
39 | | #include "nsAutoPtr.h" |
40 | | #include "mozilla/MemoryReporting.h" |
41 | | #include "mozilla/TimeStamp.h" |
42 | | #include "mozilla/AppUnits.h" |
43 | | #include "prclist.h" |
44 | | #include "nsThreadUtils.h" |
45 | | #include "nsIMessageManager.h" |
46 | | #include "Units.h" |
47 | | #include "prenv.h" |
48 | | #include "mozilla/StaticPresData.h" |
49 | | |
50 | | class nsBidi; |
51 | | class nsIPrintSettings; |
52 | | class nsDocShell; |
53 | | class nsIDocShell; |
54 | | class nsIDocument; |
55 | | class nsITheme; |
56 | | class nsIContent; |
57 | | class nsIFrame; |
58 | | class nsFrameManager; |
59 | | class nsILinkHandler; |
60 | | class nsAtom; |
61 | | class nsIRunnable; |
62 | | class gfxFontFeatureValueSet; |
63 | | class gfxUserFontEntry; |
64 | | class gfxUserFontSet; |
65 | | class gfxTextPerfMetrics; |
66 | | class nsCSSFontFeatureValuesRule; |
67 | | class nsPluginFrame; |
68 | | class nsTransitionManager; |
69 | | class nsAnimationManager; |
70 | | class nsRefreshDriver; |
71 | | class nsIWidget; |
72 | | class nsDeviceContext; |
73 | | class gfxMissingFontRecorder; |
74 | | |
75 | | namespace mozilla { |
76 | | class AnimationEventDispatcher; |
77 | | class EffectCompositor; |
78 | | class Encoding; |
79 | | class EventStateManager; |
80 | | class CounterStyleManager; |
81 | | class RestyleManager; |
82 | | namespace layers { |
83 | | class ContainerLayer; |
84 | | class LayerManager; |
85 | | } // namespace layers |
86 | | namespace dom { |
87 | | class Element; |
88 | | } // namespace dom |
89 | | } // namespace mozilla |
90 | | |
91 | | // supported values for cached bool types |
92 | | enum nsPresContext_CachedBoolPrefType { |
93 | | kPresContext_UseDocumentFonts = 1, |
94 | | kPresContext_UnderlineLinks |
95 | | }; |
96 | | |
97 | | // supported values for cached integer pref types |
98 | | enum nsPresContext_CachedIntPrefType { |
99 | | kPresContext_ScrollbarSide = 1, |
100 | | kPresContext_BidiDirection |
101 | | }; |
102 | | |
103 | | // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h) |
104 | | // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported. |
105 | | const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable |
106 | | const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed |
107 | | |
108 | | #ifdef DEBUG |
109 | | struct nsAutoLayoutPhase; |
110 | | |
111 | | enum nsLayoutPhase { |
112 | | eLayoutPhase_Paint, |
113 | | eLayoutPhase_DisplayListBuilding, // sometimes a subset of the paint phase |
114 | | eLayoutPhase_Reflow, |
115 | | eLayoutPhase_FrameC, |
116 | | eLayoutPhase_COUNT |
117 | | }; |
118 | | #endif |
119 | | |
120 | | /* Used by nsPresContext::HasAuthorSpecifiedRules */ |
121 | | #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0) |
122 | | #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1) |
123 | | #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2) |
124 | | |
125 | | class nsRootPresContext; |
126 | | |
127 | | // An interface for presentation contexts. Presentation contexts are |
128 | | // objects that provide an outer context for a presentation shell. |
129 | | |
130 | | class nsPresContext : public nsISupports, |
131 | | public mozilla::SupportsWeakPtr<nsPresContext> { |
132 | | public: |
133 | | using Encoding = mozilla::Encoding; |
134 | | template <typename T> using NotNull = mozilla::NotNull<T>; |
135 | | typedef mozilla::LangGroupFontPrefs LangGroupFontPrefs; |
136 | | typedef mozilla::ScrollStyles ScrollStyles; |
137 | | typedef mozilla::StaticPresData StaticPresData; |
138 | | using TransactionId = mozilla::layers::TransactionId; |
139 | | |
140 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL |
141 | | NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext) |
142 | | MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsPresContext) |
143 | | |
144 | | enum nsPresContextType { |
145 | | eContext_Galley, // unpaginated screen presentation |
146 | | eContext_PrintPreview, // paginated screen presentation |
147 | | eContext_Print, // paginated printer presentation |
148 | | eContext_PageLayout // paginated & editable. |
149 | | }; |
150 | | |
151 | | nsPresContext(nsIDocument* aDocument, nsPresContextType aType); |
152 | | |
153 | | /** |
154 | | * Initialize the presentation context from a particular device. |
155 | | */ |
156 | | nsresult Init(nsDeviceContext* aDeviceContext); |
157 | | |
158 | | /** |
159 | | * Set and detach presentation shell that this context is bound to. |
160 | | * A presentation context may only be bound to a single shell. |
161 | | */ |
162 | | void AttachShell(nsIPresShell* aShell); |
163 | | void DetachShell(); |
164 | | |
165 | | |
166 | 0 | nsPresContextType Type() const { return mType; } |
167 | | |
168 | | /** |
169 | | * Get the PresentationShell that this context is bound to. |
170 | | */ |
171 | | nsIPresShell* PresShell() const |
172 | 0 | { |
173 | 0 | NS_ASSERTION(mShell, "Null pres shell"); |
174 | 0 | return mShell; |
175 | 0 | } |
176 | | |
177 | 0 | nsIPresShell* GetPresShell() const { return mShell; } |
178 | | |
179 | | void DispatchCharSetChange(NotNull<const Encoding*> aCharSet); |
180 | | |
181 | | /** |
182 | | * Returns the parent prescontext for this one. Returns null if this is a |
183 | | * root. |
184 | | */ |
185 | | nsPresContext* GetParentPresContext(); |
186 | | |
187 | | /** |
188 | | * Returns the prescontext of the toplevel content document that contains |
189 | | * this presentation, or null if there isn't one. |
190 | | */ |
191 | | nsPresContext* GetToplevelContentDocumentPresContext(); |
192 | | |
193 | | /** |
194 | | * Returns the nearest widget for the root frame of this. |
195 | | * |
196 | | * @param aOffset If non-null the offset from the origin of the root |
197 | | * frame's view to the widget's origin (usually positive) |
198 | | * expressed in appunits of this will be returned in |
199 | | * aOffset. |
200 | | */ |
201 | | nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr); |
202 | | |
203 | | /** |
204 | | * Returns the root widget for this. |
205 | | * Note that the widget is a mediater with IME. |
206 | | */ |
207 | | nsIWidget* GetRootWidget(); |
208 | | |
209 | | /** |
210 | | * Return the presentation context for the root of the view manager |
211 | | * hierarchy that contains this presentation context, or nullptr if it can't |
212 | | * be found (e.g. it's detached). |
213 | | */ |
214 | | nsRootPresContext* GetRootPresContext(); |
215 | | |
216 | | virtual bool IsRoot() { return false; } |
217 | | |
218 | | nsIDocument* Document() const |
219 | 0 | { |
220 | 0 | NS_ASSERTION(!mShell || !mShell->GetDocument() || |
221 | 0 | mShell->GetDocument() == mDocument, |
222 | 0 | "nsPresContext doesn't have the same document as nsPresShell!"); |
223 | 0 | return mDocument; |
224 | 0 | } |
225 | | |
226 | | mozilla::ServoStyleSet* StyleSet() const |
227 | 0 | { return GetPresShell()->StyleSet(); } |
228 | | |
229 | | bool HasPendingMediaQueryUpdates() const |
230 | 0 | { |
231 | 0 | return !!mPendingMediaFeatureValuesChange; |
232 | 0 | } |
233 | | |
234 | | nsCSSFrameConstructor* FrameConstructor() |
235 | | { return PresShell()->FrameConstructor(); } |
236 | | |
237 | | mozilla::AnimationEventDispatcher* AnimationEventDispatcher() |
238 | 0 | { |
239 | 0 | return mAnimationEventDispatcher; |
240 | 0 | } |
241 | | |
242 | 0 | mozilla::EffectCompositor* EffectCompositor() { return mEffectCompositor; } |
243 | | nsTransitionManager* TransitionManager() { return mTransitionManager.get(); } |
244 | | nsAnimationManager* AnimationManager() { return mAnimationManager.get(); } |
245 | | const nsAnimationManager* AnimationManager() const { return mAnimationManager.get(); } |
246 | | |
247 | 0 | nsRefreshDriver* RefreshDriver() { return mRefreshDriver; } |
248 | | |
249 | 0 | mozilla::RestyleManager* RestyleManager() { |
250 | 0 | MOZ_ASSERT(mRestyleManager); |
251 | 0 | return mRestyleManager.get(); |
252 | 0 | } |
253 | | |
254 | | mozilla::CounterStyleManager* CounterStyleManager() const { |
255 | | return mCounterStyleManager; |
256 | | } |
257 | | |
258 | | /** |
259 | | * Rebuilds all style data by throwing out the old rule tree and |
260 | | * building a new one, and additionally applying aExtraHint (which |
261 | | * must not contain nsChangeHint_ReconstructFrame) to the root frame. |
262 | | * For aRestyleHint, see RestyleManager::RebuildAllStyleData. |
263 | | * Also rebuild the user font set and counter style manager. |
264 | | */ |
265 | | void RebuildAllStyleData(nsChangeHint aExtraHint, nsRestyleHint aRestyleHint); |
266 | | /** |
267 | | * Just like RebuildAllStyleData, except (1) asynchronous and (2) it |
268 | | * doesn't rebuild the user font set. |
269 | | */ |
270 | | void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint, |
271 | | nsRestyleHint aRestyleHint); |
272 | | |
273 | | |
274 | | /** |
275 | | * Handle changes in the values of media features (used in media |
276 | | * queries). |
277 | | * |
278 | | * There are three sensible values to use for aRestyleHint: |
279 | | * * nsRestyleHint(0) to rebuild style data, with rerunning of |
280 | | * selector matching, only if media features have changed |
281 | | * * eRestyle_ForceDescendants to force rebuilding of style data (but |
282 | | * still only rerun selector matching if media query results have |
283 | | * changed). (RebuildAllStyleData always adds |
284 | | * eRestyle_ForceDescendants internally, so here we're only using |
285 | | * it to distinguish from nsRestyleHint(0) whether we need to call |
286 | | * RebuildAllStyleData at all.) |
287 | | * * eRestyle_Subtree to force rebuilding of style data with |
288 | | * rerunning of selector matching |
289 | | * |
290 | | * For aChangeHint, see RestyleManager::RebuildAllStyleData. (Passing |
291 | | * a nonzero aChangeHint forces rebuilding style data even if |
292 | | * nsRestyleHint(0) is passed.) |
293 | | */ |
294 | | void MediaFeatureValuesChanged(const mozilla::MediaFeatureChange& aChange) |
295 | 0 | { |
296 | 0 | if (mShell) { |
297 | 0 | mShell->EnsureStyleFlush(); |
298 | 0 | } |
299 | 0 |
|
300 | 0 | if (!mPendingMediaFeatureValuesChange) { |
301 | 0 | mPendingMediaFeatureValuesChange.emplace(aChange); |
302 | 0 | return; |
303 | 0 | } |
304 | 0 | |
305 | 0 | *mPendingMediaFeatureValuesChange |= aChange; |
306 | 0 | } |
307 | | |
308 | | void FlushPendingMediaFeatureValuesChanged(); |
309 | | |
310 | | /** |
311 | | * Calls MediaFeatureValuesChanged for this pres context and all descendant |
312 | | * subdocuments that have a pres context. This should be used for media |
313 | | * features that must be updated in all subdocuments e.g. display-mode. |
314 | | */ |
315 | | void MediaFeatureValuesChangedAllDocuments(const mozilla::MediaFeatureChange&); |
316 | | |
317 | | /** |
318 | | * Updates the size mode on all remote children and recursively notifies this |
319 | | * document and all subdocuments (including remote children) that a media |
320 | | * feature value has changed. |
321 | | */ |
322 | | void SizeModeChanged(nsSizeMode aSizeMode); |
323 | | |
324 | | /** |
325 | | * Access compatibility mode for this context. This is the same as |
326 | | * our document's compatibility mode. |
327 | | */ |
328 | | nsCompatibility CompatibilityMode() const; |
329 | | |
330 | | /** |
331 | | * Notify the context that the document's compatibility mode has changed |
332 | | */ |
333 | | void CompatibilityModeChanged(); |
334 | | |
335 | | /** |
336 | | * Access the image animation mode for this context |
337 | | */ |
338 | 0 | uint16_t ImageAnimationMode() const { return mImageAnimationMode; } |
339 | | void SetImageAnimationMode(uint16_t aMode); |
340 | | |
341 | | /** |
342 | | * Get medium of presentation |
343 | | */ |
344 | | nsAtom* Medium() { |
345 | | if (!mIsEmulatingMedia) |
346 | | return mMedium; |
347 | | return mMediaEmulated; |
348 | | } |
349 | | |
350 | | /* |
351 | | * Render the document as if being viewed on a device with the specified |
352 | | * media type. |
353 | | */ |
354 | | void EmulateMedium(const nsAString& aMediaType); |
355 | | |
356 | | /* |
357 | | * Restore the viewer's natural medium |
358 | | */ |
359 | | void StopEmulatingMedium(); |
360 | | |
361 | | /** |
362 | | * Get the default font for the given language and generic font ID. |
363 | | * If aLanguage is nullptr, the document's language is used. |
364 | | * |
365 | | * See the comment in StaticPresData::GetDefaultFont. |
366 | | */ |
367 | | const nsFont* GetDefaultFont(uint8_t aFontID, |
368 | | nsAtom *aLanguage, bool* aNeedsToCache = nullptr) const |
369 | | { |
370 | | nsAtom* lang = aLanguage ? aLanguage : mLanguage.get(); |
371 | | const LangGroupFontPrefs* prefs = GetFontPrefsForLang(lang, aNeedsToCache); |
372 | | if (aNeedsToCache && *aNeedsToCache) { |
373 | | return nullptr; |
374 | | } |
375 | | return StaticPresData::Get()->GetDefaultFontHelper(aFontID, lang, prefs); |
376 | | } |
377 | | |
378 | | void ForceCacheLang(nsAtom *aLanguage); |
379 | | void CacheAllLangs(); |
380 | | |
381 | | /** Get a cached boolean pref, by its type */ |
382 | | // * - initially created for bugs 31816, 20760, 22963 |
383 | | bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const |
384 | | { |
385 | | // If called with a constant parameter, the compiler should optimize |
386 | | // this switch statement away. |
387 | | switch (aPrefType) { |
388 | | case kPresContext_UseDocumentFonts: |
389 | | return mUseDocumentFonts; |
390 | | case kPresContext_UnderlineLinks: |
391 | | return mUnderlineLinks; |
392 | | default: |
393 | | NS_ERROR("Invalid arg passed to GetCachedBoolPref"); |
394 | | } |
395 | | |
396 | | return false; |
397 | | } |
398 | | |
399 | | /** Get a cached integer pref, by its type */ |
400 | | // * - initially created for bugs 30910, 61883, 74186, 84398 |
401 | | int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const |
402 | | { |
403 | | // If called with a constant parameter, the compiler should optimize |
404 | | // this switch statement away. |
405 | | switch (aPrefType) { |
406 | | case kPresContext_ScrollbarSide: |
407 | | return mPrefScrollbarSide; |
408 | | case kPresContext_BidiDirection: |
409 | | return mPrefBidiDirection; |
410 | | default: |
411 | | NS_ERROR("invalid arg passed to GetCachedIntPref"); |
412 | | } |
413 | | |
414 | | return false; |
415 | | } |
416 | | |
417 | | /** |
418 | | * Get the default colors |
419 | | */ |
420 | 0 | nscolor DefaultColor() const { return mDefaultColor; } |
421 | | nscolor DefaultBackgroundColor() const { return mBackgroundColor; } |
422 | | nscolor DefaultLinkColor() const { return mLinkColor; } |
423 | | nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; } |
424 | | nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; } |
425 | | nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; } |
426 | | nscolor FocusTextColor() const { return mFocusTextColor; } |
427 | | |
428 | | /** |
429 | | * Body text color, for use in quirks mode only. |
430 | | */ |
431 | 0 | nscolor BodyTextColor() const { return mBodyTextColor; } |
432 | 0 | void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; } |
433 | | |
434 | | bool GetUseFocusColors() const { return mUseFocusColors; } |
435 | | uint8_t FocusRingWidth() const { return mFocusRingWidth; } |
436 | | bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; } |
437 | | uint8_t GetFocusRingStyle() const { return mFocusRingStyle; } |
438 | | |
439 | | void SetContainer(nsIDocShell* aContainer); |
440 | | |
441 | | nsISupports* GetContainerWeak() const; |
442 | | |
443 | | nsIDocShell* GetDocShell() const; |
444 | | |
445 | | // XXX this are going to be replaced with set/get container |
446 | 0 | void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; } |
447 | 0 | nsILinkHandler* GetLinkHandler() { return mLinkHandler; } |
448 | | |
449 | | /** |
450 | | * Detach this pres context - i.e. cancel relevant timers, |
451 | | * SetLinkHandler(null), SetContainer(null) etc. |
452 | | * Only to be used by the DocumentViewer. |
453 | | */ |
454 | | virtual void Detach(); |
455 | | |
456 | | /** |
457 | | * Get the visible area associated with this presentation context. |
458 | | * This is the size of the visible area that is used for |
459 | | * presenting the document. The returned value is in the standard |
460 | | * nscoord units (as scaled by the device context). |
461 | | */ |
462 | 0 | nsRect GetVisibleArea() const { return mVisibleArea; } |
463 | | |
464 | | /** |
465 | | * Set the currently visible area. The units for r are standard |
466 | | * nscoord units (as scaled by the device context). |
467 | | */ |
468 | 0 | void SetVisibleArea(const nsRect& r) { |
469 | 0 | if (!r.IsEqualEdges(mVisibleArea)) { |
470 | 0 | mVisibleArea = r; |
471 | 0 | // Visible area does not affect media queries when paginated. |
472 | 0 | if (!IsPaginated()) { |
473 | 0 | MediaFeatureValuesChanged({ |
474 | 0 | mozilla::MediaFeatureChangeReason::ViewportChange |
475 | 0 | }); |
476 | 0 | } |
477 | 0 | } |
478 | 0 | } |
479 | | |
480 | 0 | bool ShouldFireResizeEvent() const { |
481 | 0 | return !mLastResizeEventVisibleArea.IsEqualEdges(mVisibleArea); |
482 | 0 | } |
483 | | |
484 | 0 | void WillFireResizeEvent() { mLastResizeEventVisibleArea = mVisibleArea; } |
485 | | |
486 | | /** |
487 | | * Return true if this presentation context is a paginated |
488 | | * context. |
489 | | */ |
490 | 0 | bool IsPaginated() const { return mPaginated; } |
491 | | |
492 | | /** |
493 | | * Sets whether the presentation context can scroll for a paginated |
494 | | * context. |
495 | | */ |
496 | | void SetPaginatedScrolling(bool aResult); |
497 | | |
498 | | /** |
499 | | * Return true if this presentation context can scroll for paginated |
500 | | * context. |
501 | | */ |
502 | | bool HasPaginatedScrolling() const { return mCanPaginatedScroll; } |
503 | | |
504 | | /** |
505 | | * Get/set the size of a page |
506 | | */ |
507 | 0 | nsSize GetPageSize() { return mPageSize; } |
508 | | void SetPageSize(nsSize aSize) { mPageSize = aSize; } |
509 | | |
510 | | /** |
511 | | * Get/set whether this document should be treated as having real pages |
512 | | * XXX This raises the obvious question of why a document that isn't a page |
513 | | * is paginated; there isn't a good reason except history |
514 | | */ |
515 | 0 | bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; } |
516 | | void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) |
517 | | { mIsRootPaginatedDocument = aIsRootPaginatedDocument; } |
518 | | |
519 | | /** |
520 | | * Get/set the print scaling level; used by nsPageFrame to scale up |
521 | | * pages. Set safe to call before reflow, get guaranteed to be set |
522 | | * properly after reflow. |
523 | | */ |
524 | | |
525 | | float GetPageScale() { return mPageScale; } |
526 | | void SetPageScale(float aScale) { mPageScale = aScale; } |
527 | | |
528 | | /** |
529 | | * Get/set the scaling facor to use when rendering the pages for print preview. |
530 | | * Only safe to get after print preview set up; safe to set anytime. |
531 | | * This is a scaling factor for the display of the print preview. It |
532 | | * does not affect layout. It only affects the size of the onscreen pages |
533 | | * in print preview. |
534 | | * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview |
535 | | */ |
536 | | float GetPrintPreviewScale() { return mPPScale; } |
537 | | void SetPrintPreviewScale(float aScale) { mPPScale = aScale; } |
538 | | |
539 | 0 | nsDeviceContext* DeviceContext() const { return mDeviceContext; } |
540 | 0 | mozilla::EventStateManager* EventStateManager() { return mEventManager; } |
541 | 0 | nsAtom* GetLanguageFromCharset() const { return mLanguage; } |
542 | | already_AddRefed<nsAtom> GetContentLanguage() const; |
543 | | |
544 | | /** |
545 | | * Get/set a text zoom factor that is applied on top of the normal text zoom |
546 | | * set by the front-end/user. |
547 | | */ |
548 | 0 | float GetSystemFontScale() const { return mSystemFontScale; } |
549 | | void SetSystemFontScale(float aFontScale) { |
550 | | MOZ_ASSERT(aFontScale > 0.0f, "invalid font scale"); |
551 | | if (aFontScale == mSystemFontScale || IsPrintingOrPrintPreview()) { |
552 | | return; |
553 | | } |
554 | | |
555 | | mSystemFontScale = aFontScale; |
556 | | UpdateEffectiveTextZoom(); |
557 | | } |
558 | | |
559 | | /** |
560 | | * Get/set the text zoom factor in use. |
561 | | * This value should be used if you're interested in the pure text zoom value |
562 | | * controlled by the front-end, e.g. when transferring zoom levels to a new |
563 | | * document. |
564 | | * Code that wants to use this value for layouting and rendering purposes |
565 | | * should consider using EffectiveTextZoom() instead, so as to take the system |
566 | | * font scale into account as well. |
567 | | */ |
568 | 0 | float TextZoom() const { return mTextZoom; } |
569 | 0 | void SetTextZoom(float aZoom) { |
570 | 0 | MOZ_ASSERT(aZoom > 0.0f, "invalid zoom factor"); |
571 | 0 | if (aZoom == mTextZoom) |
572 | 0 | return; |
573 | 0 | |
574 | 0 | mTextZoom = aZoom; |
575 | 0 | UpdateEffectiveTextZoom(); |
576 | 0 | } |
577 | | |
578 | | protected: |
579 | | void UpdateEffectiveTextZoom(); |
580 | | |
581 | | public: |
582 | | /** |
583 | | * Corresponds to the product of text zoom and system font scale, limited |
584 | | * by zoom.maxPercent and minPercent. |
585 | | * As the system font scale is automatically set by the PresShell, code that |
586 | | * e.g. wants to transfer zoom levels to a new document should use TextZoom() |
587 | | * instead, which corresponds to the text zoom level that was actually set by |
588 | | * the front-end/user. |
589 | | */ |
590 | | float EffectiveTextZoom() const { return mEffectiveTextZoom; } |
591 | | |
592 | | /** |
593 | | * Get the minimum font size for the specified language. If aLanguage |
594 | | * is nullptr, then the document's language is used. This combines |
595 | | * the language-specific global preference with the per-presentation |
596 | | * base minimum font size. |
597 | | */ |
598 | | int32_t MinFontSize(nsAtom *aLanguage, bool* aNeedsToCache = nullptr) const { |
599 | | const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage, aNeedsToCache); |
600 | | if (aNeedsToCache && *aNeedsToCache) { |
601 | | return 0; |
602 | | } |
603 | | return std::max(mBaseMinFontSize, prefs->mMinimumFontSize); |
604 | | } |
605 | | |
606 | | /** |
607 | | * Get the per-presentation base minimum font size. This size is |
608 | | * independent of the language-specific global preference. |
609 | | */ |
610 | 0 | int32_t BaseMinFontSize() const { |
611 | 0 | return mBaseMinFontSize; |
612 | 0 | } |
613 | | |
614 | | /** |
615 | | * Set the per-presentation base minimum font size. This size is |
616 | | * independent of the language-specific global preference. |
617 | | */ |
618 | 0 | void SetBaseMinFontSize(int32_t aMinFontSize) { |
619 | 0 | if (aMinFontSize == mBaseMinFontSize) { |
620 | 0 | return; |
621 | 0 | } |
622 | 0 | |
623 | 0 | mBaseMinFontSize = aMinFontSize; |
624 | 0 |
|
625 | 0 | // Media queries could have changed, since we changed the meaning |
626 | 0 | // of 'em' units in them. |
627 | 0 | MediaFeatureValuesChanged({ |
628 | 0 | eRestyle_ForceDescendants, |
629 | 0 | NS_STYLE_HINT_REFLOW, |
630 | 0 | mozilla::MediaFeatureChangeReason::MinFontSizeChange |
631 | 0 | }); |
632 | 0 | } |
633 | | |
634 | 0 | float GetFullZoom() { return mFullZoom; } |
635 | | /** |
636 | | * Device full zoom differs from full zoom because it gets the zoom from |
637 | | * the device context, which may be using a different zoom due to rounding |
638 | | * of app units to device pixels. |
639 | | */ |
640 | | float GetDeviceFullZoom(); |
641 | | void SetFullZoom(float aZoom); |
642 | | |
643 | 0 | float GetOverrideDPPX() { return mOverrideDPPX; } |
644 | | void SetOverrideDPPX(float aDPPX); |
645 | | |
646 | | nscoord GetAutoQualityMinFontSize() { |
647 | | return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref); |
648 | | } |
649 | | |
650 | | /** |
651 | | * Return the device's screen size in inches, for font size |
652 | | * inflation. |
653 | | * |
654 | | * If |aChanged| is non-null, then aChanged is filled in with whether |
655 | | * the screen size value has changed since either: |
656 | | * a. the last time the function was called with non-null aChanged, or |
657 | | * b. the first time the function was called. |
658 | | */ |
659 | | gfxSize ScreenSizeInchesForFontInflation(bool* aChanged = nullptr); |
660 | | |
661 | | int32_t AppUnitsPerDevPixel() const; |
662 | | |
663 | | static nscoord CSSPixelsToAppUnits(int32_t aPixels) |
664 | 9 | { return NSToCoordRoundWithClamp(float(aPixels) * |
665 | 9 | float(mozilla::AppUnitsPerCSSPixel())); } |
666 | | |
667 | | static nscoord CSSPixelsToAppUnits(float aPixels) |
668 | 0 | { return NSToCoordRoundWithClamp(aPixels * |
669 | 0 | float(mozilla::AppUnitsPerCSSPixel())); } |
670 | | |
671 | | static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) |
672 | 0 | { return NSAppUnitsToIntPixels(aAppUnits, |
673 | 0 | float(mozilla::AppUnitsPerCSSPixel())); } |
674 | | |
675 | | static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) |
676 | 0 | { return NSAppUnitsToFloatPixels(aAppUnits, |
677 | 0 | float(mozilla::AppUnitsPerCSSPixel())); } |
678 | | |
679 | | static double AppUnitsToDoubleCSSPixels(nscoord aAppUnits) |
680 | 0 | { return NSAppUnitsToDoublePixels(aAppUnits, |
681 | 0 | double(mozilla::AppUnitsPerCSSPixel())); } |
682 | | |
683 | | nscoord DevPixelsToAppUnits(int32_t aPixels) const |
684 | 0 | { return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel()); } |
685 | | |
686 | | int32_t AppUnitsToDevPixels(nscoord aAppUnits) const |
687 | 0 | { return NSAppUnitsToIntPixels(aAppUnits, |
688 | 0 | float(AppUnitsPerDevPixel())); } |
689 | | |
690 | | float AppUnitsToFloatDevPixels(nscoord aAppUnits) |
691 | | { return aAppUnits / float(AppUnitsPerDevPixel()); } |
692 | | |
693 | | int32_t CSSPixelsToDevPixels(int32_t aPixels) |
694 | 0 | { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); } |
695 | | |
696 | | float CSSPixelsToDevPixels(float aPixels) |
697 | 0 | { |
698 | 0 | return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels), |
699 | 0 | float(AppUnitsPerDevPixel())); |
700 | 0 | } |
701 | | |
702 | | int32_t DevPixelsToIntCSSPixels(int32_t aPixels) |
703 | 0 | { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); } |
704 | | |
705 | | float DevPixelsToFloatCSSPixels(int32_t aPixels) |
706 | 0 | { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); } |
707 | | |
708 | | mozilla::CSSToLayoutDeviceScale CSSToDevPixelScale() const |
709 | 0 | { |
710 | 0 | return mozilla::CSSToLayoutDeviceScale( |
711 | 0 | float(mozilla::AppUnitsPerCSSPixel()) / float(AppUnitsPerDevPixel())); |
712 | 0 | } |
713 | | |
714 | | // If there is a remainder, it is rounded to nearest app units. |
715 | | nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const; |
716 | | |
717 | | gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const; |
718 | | |
719 | | gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const |
720 | 0 | { return gfxRect(AppUnitsToGfxUnits(aAppRect.x), |
721 | 0 | AppUnitsToGfxUnits(aAppRect.y), |
722 | 0 | AppUnitsToGfxUnits(aAppRect.Width()), |
723 | 0 | AppUnitsToGfxUnits(aAppRect.Height())); } |
724 | | |
725 | | static nscoord CSSTwipsToAppUnits(float aTwips) |
726 | 0 | { return NSToCoordRoundWithClamp( |
727 | 0 | mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); } |
728 | | |
729 | | // Margin-specific version, since they often need TwipsToAppUnits |
730 | | static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips) |
731 | | { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)), |
732 | | CSSTwipsToAppUnits(float(marginInTwips.right)), |
733 | | CSSTwipsToAppUnits(float(marginInTwips.bottom)), |
734 | | CSSTwipsToAppUnits(float(marginInTwips.left))); } |
735 | | |
736 | | static nscoord CSSPointsToAppUnits(float aPoints) |
737 | | { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() / |
738 | | POINTS_PER_INCH_FLOAT); } |
739 | | |
740 | | nscoord PhysicalMillimetersToAppUnits(float aMM) const; |
741 | | |
742 | | nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const |
743 | | { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); } |
744 | | |
745 | | /** |
746 | | * This checks the root element and the HTML BODY, if any, for an "overflow" |
747 | | * property that should be applied to the viewport. If one is found then we |
748 | | * return the element that we took the overflow from (which should then be |
749 | | * treated as "overflow: visible"), and we store the overflow style here. |
750 | | * If the document is in fullscreen, and the fullscreen element is not the |
751 | | * root, the scrollbar of viewport will be suppressed. |
752 | | * @return if scroll was propagated from some content node, the content node |
753 | | * it was propagated from. |
754 | | */ |
755 | | mozilla::dom::Element* UpdateViewportScrollStylesOverride(); |
756 | | |
757 | | /** |
758 | | * Returns the cached result from the last call to |
759 | | * UpdateViewportScrollStylesOverride() -- i.e. return the node |
760 | | * whose scrollbar styles we have propagated to the viewport (or nullptr if |
761 | | * there is no such node). |
762 | | */ |
763 | | mozilla::dom::Element* GetViewportScrollStylesOverrideElement() const { |
764 | | return mViewportScrollOverrideElement; |
765 | | } |
766 | | |
767 | | const ScrollStyles& GetViewportScrollStylesOverride() const |
768 | | { |
769 | | return mViewportScrollStyles; |
770 | | } |
771 | | |
772 | | /** |
773 | | * Check whether the given element would propagate its scrollbar styles to the |
774 | | * viewport in non-paginated mode. Must only be called if IsPaginated(). |
775 | | */ |
776 | | bool ElementWouldPropagateScrollStyles(const mozilla::dom::Element&); |
777 | | |
778 | | /** |
779 | | * Set and get methods for controlling the background drawing |
780 | | */ |
781 | | bool GetBackgroundImageDraw() const { return mDrawImageBackground; } |
782 | | void SetBackgroundImageDraw(bool aCanDraw) |
783 | | { |
784 | | mDrawImageBackground = aCanDraw; |
785 | | } |
786 | | |
787 | | bool GetBackgroundColorDraw() const { return mDrawColorBackground; } |
788 | | void SetBackgroundColorDraw(bool aCanDraw) |
789 | | { |
790 | | mDrawColorBackground = aCanDraw; |
791 | | } |
792 | | |
793 | | /** |
794 | | * Check if bidi enabled (set depending on the presence of RTL |
795 | | * characters or when default directionality is RTL). |
796 | | * If enabled, we should apply the Unicode Bidi Algorithm |
797 | | * |
798 | | * @lina 07/12/2000 |
799 | | */ |
800 | | bool BidiEnabled() const; |
801 | | |
802 | | /** |
803 | | * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm |
804 | | * |
805 | | * @lina 07/12/2000 |
806 | | */ |
807 | | void SetBidiEnabled() const; |
808 | | |
809 | | /** |
810 | | * Set visual or implicit mode into the pres context. |
811 | | * |
812 | | * Visual directionality is a presentation method that displays text |
813 | | * as if it were a uni-directional, according to the primary display |
814 | | * direction only. |
815 | | * |
816 | | * Implicit directionality is a presentation method in which the |
817 | | * direction is determined by the Bidi algorithm according to the |
818 | | * category of the characters and the category of the adjacent |
819 | | * characters, and according to their primary direction. |
820 | | * |
821 | | * @lina 05/02/2000 |
822 | | */ |
823 | | void SetVisualMode(bool aIsVisual) |
824 | | { |
825 | | mIsVisual = aIsVisual; |
826 | | } |
827 | | |
828 | | /** |
829 | | * Check whether the content should be treated as visual. |
830 | | * |
831 | | * @lina 05/02/2000 |
832 | | */ |
833 | | bool IsVisualMode() const { return mIsVisual; } |
834 | | |
835 | | enum class InteractionType : uint32_t { |
836 | | eClickInteraction, |
837 | | eKeyInteraction, |
838 | | eMouseMoveInteraction, |
839 | | eScrollInteraction |
840 | | }; |
841 | | |
842 | | void RecordInteractionTime(InteractionType aType, |
843 | | const mozilla::TimeStamp& aTimeStamp); |
844 | | |
845 | | void DisableInteractionTimeRecording() |
846 | | { |
847 | | mInteractionTimeEnabled = false; |
848 | | } |
849 | | |
850 | | //Mohamed |
851 | | |
852 | | /** |
853 | | * Set the Bidi options for the presentation context |
854 | | */ |
855 | | void SetBidi(uint32_t aBidiOptions); |
856 | | |
857 | | /** |
858 | | * Get the Bidi options for the presentation context |
859 | | * Not inline so consumers of nsPresContext are not forced to |
860 | | * include nsIDocument. |
861 | | */ |
862 | | uint32_t GetBidi() const; |
863 | | |
864 | | /** |
865 | | * Render only Selection |
866 | | */ |
867 | | void SetIsRenderingOnlySelection(bool aResult) |
868 | 0 | { |
869 | 0 | mIsRenderingOnlySelection = aResult; |
870 | 0 | } |
871 | | |
872 | | bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; } |
873 | | |
874 | | bool IsTopLevelWindowInactive(); |
875 | | |
876 | | /* |
877 | | * Obtain a native them for rendering our widgets (both form controls and html) |
878 | | */ |
879 | | nsITheme* GetTheme(); |
880 | | |
881 | | /* |
882 | | * Notify the pres context that the theme has changed. An internal switch |
883 | | * means it's one of our Mozilla themes that changed (e.g., Modern to Classic). |
884 | | * Otherwise, the OS is telling us that the native theme for the platform |
885 | | * has changed. |
886 | | */ |
887 | | void ThemeChanged(); |
888 | | |
889 | | /* |
890 | | * Notify the pres context that the resolution of the user interface has |
891 | | * changed. This happens if a window is moved between HiDPI and non-HiDPI |
892 | | * displays, so that the ratio of points to device pixels changes. |
893 | | * The notification happens asynchronously. |
894 | | */ |
895 | | void UIResolutionChanged(); |
896 | | |
897 | | /* |
898 | | * Like UIResolutionChanged() but invalidates values immediately. |
899 | | */ |
900 | | void UIResolutionChangedSync(); |
901 | | |
902 | | /* |
903 | | * Notify the pres context that a system color has changed |
904 | | */ |
905 | | void SysColorChanged(); |
906 | | |
907 | | /** Printing methods below should only be used for Medium() == print **/ |
908 | | void SetPrintSettings(nsIPrintSettings *aPrintSettings); |
909 | | |
910 | | nsIPrintSettings* GetPrintSettings() { return mPrintSettings; } |
911 | | |
912 | | /* Helper function that ensures that this prescontext is shown in its |
913 | | docshell if it's the most recent prescontext for the docshell. Returns |
914 | | whether the prescontext is now being shown. |
915 | | */ |
916 | | bool EnsureVisible(); |
917 | | |
918 | | #ifdef MOZ_REFLOW_PERF |
919 | | void CountReflows(const char * aName, |
920 | | nsIFrame * aFrame); |
921 | | #endif |
922 | | |
923 | | void ConstructedFrame() { |
924 | | ++mFramesConstructed; |
925 | | } |
926 | | void ReflowedFrame() { |
927 | | ++mFramesReflowed; |
928 | | } |
929 | | |
930 | 0 | uint64_t FramesConstructedCount() { |
931 | 0 | return mFramesConstructed; |
932 | 0 | } |
933 | 0 | uint64_t FramesReflowedCount() { |
934 | 0 | return mFramesReflowed; |
935 | 0 | } |
936 | | |
937 | | static nscoord GetBorderWidthForKeyword(unsigned int aBorderWidthKeyword) |
938 | | { |
939 | | // This table maps border-width enums 'thin', 'medium', 'thick' |
940 | | // to actual nscoord values. |
941 | | static const nscoord kBorderWidths[] = { |
942 | | CSSPixelsToAppUnits(1), |
943 | | CSSPixelsToAppUnits(3), |
944 | | CSSPixelsToAppUnits(5) |
945 | | }; |
946 | | MOZ_ASSERT(size_t(aBorderWidthKeyword) < mozilla::ArrayLength(kBorderWidths)); |
947 | | |
948 | | return kBorderWidths[aBorderWidthKeyword]; |
949 | | } |
950 | | |
951 | 0 | gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; } |
952 | | |
953 | 0 | bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); } |
954 | | bool IsScreen() { return (mMedium == nsGkAtoms::screen || |
955 | | mType == eContext_PageLayout || |
956 | | mType == eContext_PrintPreview); } |
957 | | bool IsPrintingOrPrintPreview() { return (mType == eContext_Print || mType == eContext_PrintPreview); } |
958 | | |
959 | | // Is this presentation in a chrome docshell? |
960 | | bool IsChrome() const { return mIsChrome; } |
961 | | bool IsChromeOriginImage() const { return mIsChromeOriginImage; } |
962 | | void UpdateIsChrome(); |
963 | | |
964 | | // Public API for native theme code to get style internals. |
965 | | bool HasAuthorSpecifiedRules(const nsIFrame *aFrame, |
966 | | uint32_t ruleTypeMask) const; |
967 | | |
968 | | // Is it OK to let the page specify colors and backgrounds? |
969 | | bool UseDocumentColors() const { |
970 | | MOZ_ASSERT(mUseDocumentColors || !(IsChrome() || IsChromeOriginImage()), |
971 | | "We should never have a chrome doc or image that can't use its colors."); |
972 | | return mUseDocumentColors; |
973 | | } |
974 | | |
975 | | // Explicitly enable and disable paint flashing. |
976 | 0 | void SetPaintFlashing(bool aPaintFlashing) { |
977 | 0 | mPaintFlashing = aPaintFlashing; |
978 | 0 | mPaintFlashingInitialized = true; |
979 | 0 | } |
980 | | |
981 | | // This method should be used instead of directly accessing mPaintFlashing, |
982 | | // as that value may be out of date when mPaintFlashingInitialized is false. |
983 | | bool GetPaintFlashing() const; |
984 | | |
985 | | bool SuppressingResizeReflow() const { return mSuppressResizeReflow; } |
986 | | |
987 | | gfxUserFontSet* GetUserFontSet(bool aFlushUserFontSet = true); |
988 | | |
989 | | // Should be called whenever the set of fonts available in the user |
990 | | // font set changes (e.g., because a new font loads, or because the |
991 | | // user font set is changed and fonts become unavailable). |
992 | | void UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont = nullptr); |
993 | | |
994 | | gfxMissingFontRecorder *MissingFontRecorder() { return mMissingFonts; } |
995 | | void NotifyMissingFonts(); |
996 | | |
997 | | void FlushCounterStyles(); |
998 | | void MarkCounterStylesDirty(); |
999 | | |
1000 | | void FlushFontFeatureValues(); |
1001 | | void MarkFontFeatureValuesDirty() |
1002 | | { |
1003 | | mFontFeatureValuesDirty = true; |
1004 | | } |
1005 | | |
1006 | | // Ensure that it is safe to hand out CSS rules outside the layout |
1007 | | // engine by ensuring that all CSS style sheets have unique inners |
1008 | | // and, if necessary, synchronously rebuilding all style data. |
1009 | | void EnsureSafeToHandOutCSSRules(); |
1010 | | |
1011 | | // Mark an area as invalidated, associated with a given transaction id (allocated |
1012 | | // by nsRefreshDriver::GetTransactionId). |
1013 | | // Invalidated regions will be dispatched to MozAfterPaint events when |
1014 | | // NotifyDidPaintForSubtree is called for the transaction id (or any higher id). |
1015 | | void NotifyInvalidation(TransactionId aTransactionId, const nsRect& aRect); |
1016 | | // aRect is in device pixels |
1017 | | void NotifyInvalidation(TransactionId aTransactionId, const nsIntRect& aRect); |
1018 | | void NotifyDidPaintForSubtree(TransactionId aTransactionId = TransactionId{0}, |
1019 | | const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp()); |
1020 | | void NotifyRevokingDidPaint(TransactionId aTransactionId); |
1021 | | void FireDOMPaintEvent(nsTArray<nsRect>* aList, |
1022 | | TransactionId aTransactionId, |
1023 | | mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp()); |
1024 | | |
1025 | | // Callback for catching invalidations in ContainerLayers |
1026 | | // Passed to LayerProperties::ComputeDifference |
1027 | | static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer, |
1028 | | const nsIntRegion* aRegion); |
1029 | | void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer); |
1030 | | static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer); |
1031 | | bool IsDOMPaintEventPending(); |
1032 | | |
1033 | | /** |
1034 | | * Returns the RestyleManager's restyle generation counter. |
1035 | | */ |
1036 | | uint64_t GetRestyleGeneration() const; |
1037 | | uint64_t GetUndisplayedRestyleGeneration() const; |
1038 | | |
1039 | | /** |
1040 | | * Returns whether there are any pending restyles or reflows. |
1041 | | */ |
1042 | | bool HasPendingRestyleOrReflow(); |
1043 | | |
1044 | | /** |
1045 | | * Notify the prescontext that the presshell is about to reflow a reflow root. |
1046 | | * The single argument indicates whether this reflow should be interruptible. |
1047 | | * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt |
1048 | | * will always return false. If aInterruptible is true then CheckForInterrupt |
1049 | | * will return true when a pending event is detected. This is for use by the |
1050 | | * presshell only. Reflow code wanting to prevent interrupts should use |
1051 | | * InterruptPreventer. |
1052 | | */ |
1053 | | void ReflowStarted(bool aInterruptible); |
1054 | | |
1055 | | /** |
1056 | | * A class that can be used to temporarily disable reflow interruption. |
1057 | | */ |
1058 | | class InterruptPreventer; |
1059 | | friend class InterruptPreventer; |
1060 | | class MOZ_STACK_CLASS InterruptPreventer { |
1061 | | public: |
1062 | | explicit InterruptPreventer(nsPresContext* aCtx) : |
1063 | | mCtx(aCtx), |
1064 | | mInterruptsEnabled(aCtx->mInterruptsEnabled), |
1065 | | mHasPendingInterrupt(aCtx->mHasPendingInterrupt) |
1066 | | { |
1067 | | mCtx->mInterruptsEnabled = false; |
1068 | | mCtx->mHasPendingInterrupt = false; |
1069 | | } |
1070 | | ~InterruptPreventer() { |
1071 | | mCtx->mInterruptsEnabled = mInterruptsEnabled; |
1072 | | mCtx->mHasPendingInterrupt = mHasPendingInterrupt; |
1073 | | } |
1074 | | |
1075 | | private: |
1076 | | nsPresContext* mCtx; |
1077 | | bool mInterruptsEnabled; |
1078 | | bool mHasPendingInterrupt; |
1079 | | }; |
1080 | | |
1081 | | /** |
1082 | | * Check for interrupts. This may return true if a pending event is |
1083 | | * detected. Once it has returned true, it will keep returning true |
1084 | | * until ReflowStarted is called. In all cases where this returns true, |
1085 | | * the passed-in frame (which should be the frame whose reflow will be |
1086 | | * interrupted if true is returned) will be passed to |
1087 | | * nsIPresShell::FrameNeedsToContinueReflow. |
1088 | | */ |
1089 | | bool CheckForInterrupt(nsIFrame* aFrame); |
1090 | | /** |
1091 | | * Returns true if CheckForInterrupt has returned true since the last |
1092 | | * ReflowStarted call. Cannot itself trigger an interrupt check. |
1093 | | */ |
1094 | | bool HasPendingInterrupt() { return mHasPendingInterrupt; } |
1095 | | /** |
1096 | | * Sets a flag that will trip a reflow interrupt. This only bypasses the |
1097 | | * interrupt timeout and the pending event check; other checks such as whether |
1098 | | * interrupts are enabled and the interrupt check skipping still take effect. |
1099 | | */ |
1100 | 0 | void SetPendingInterruptFromTest() { mPendingInterruptFromTest = true; } |
1101 | | |
1102 | | /** |
1103 | | * If we have a presshell, and if the given content's current |
1104 | | * document is the same as our presshell's document, return the |
1105 | | * content's primary frame. Otherwise, return null. Only use this |
1106 | | * if you care about which presshell the primary frame is in. |
1107 | | */ |
1108 | | nsIFrame* GetPrimaryFrameFor(nsIContent* aContent); |
1109 | | |
1110 | | virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
1111 | | virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { |
1112 | | return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); |
1113 | | } |
1114 | | |
1115 | | bool IsRootContentDocument() const; |
1116 | | |
1117 | | bool HadNonBlankPaint() const { |
1118 | | return mHadNonBlankPaint; |
1119 | | } |
1120 | | |
1121 | | void NotifyNonBlankPaint(); |
1122 | | void NotifyDOMContentFlushed(); |
1123 | | |
1124 | 0 | bool UsesRootEMUnits() const { |
1125 | 0 | return mUsesRootEMUnits; |
1126 | 0 | } |
1127 | | |
1128 | 0 | void SetUsesRootEMUnits(bool aValue) { |
1129 | 0 | mUsesRootEMUnits = aValue; |
1130 | 0 | } |
1131 | | |
1132 | | bool UsesExChUnits() const { |
1133 | | return mUsesExChUnits; |
1134 | | } |
1135 | | |
1136 | | void SetUsesExChUnits(bool aValue) { |
1137 | | mUsesExChUnits = aValue; |
1138 | | } |
1139 | | |
1140 | | // true if there are OMTA transition updates for the current document which |
1141 | | // have been throttled, and therefore some style information may not be up |
1142 | | // to date |
1143 | 0 | bool ExistThrottledUpdates() const { |
1144 | 0 | return mExistThrottledUpdates; |
1145 | 0 | } |
1146 | | |
1147 | 0 | void SetExistThrottledUpdates(bool aExistThrottledUpdates) { |
1148 | 0 | mExistThrottledUpdates = aExistThrottledUpdates; |
1149 | 0 | } |
1150 | | |
1151 | | bool IsDeviceSizePageSize(); |
1152 | | |
1153 | | bool HasWarnedAboutPositionedTableParts() const { |
1154 | | return mHasWarnedAboutPositionedTableParts; |
1155 | | } |
1156 | | |
1157 | | void SetHasWarnedAboutPositionedTableParts() { |
1158 | | mHasWarnedAboutPositionedTableParts = true; |
1159 | | } |
1160 | | |
1161 | | bool HasWarnedAboutTooLargeDashedOrDottedRadius() const { |
1162 | | return mHasWarnedAboutTooLargeDashedOrDottedRadius; |
1163 | | } |
1164 | | |
1165 | | void SetHasWarnedAboutTooLargeDashedOrDottedRadius() { |
1166 | | mHasWarnedAboutTooLargeDashedOrDottedRadius = true; |
1167 | | } |
1168 | | |
1169 | | nsBidi& GetBidiEngine(); |
1170 | | |
1171 | | gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const { |
1172 | | return mFontFeatureValuesLookup; |
1173 | | } |
1174 | | |
1175 | | protected: |
1176 | | friend class nsRunnableMethod<nsPresContext>; |
1177 | | void ThemeChangedInternal(); |
1178 | | void SysColorChangedInternal(); |
1179 | | void RefreshSystemMetrics(); |
1180 | | |
1181 | | // update device context's resolution from the widget |
1182 | | void UIResolutionChangedInternal(); |
1183 | | |
1184 | | // if aScale > 0.0, use it as resolution scale factor to the device context |
1185 | | // (otherwise get it from the widget) |
1186 | | void UIResolutionChangedInternalScale(double aScale); |
1187 | | |
1188 | | // aData here is a pointer to a double that holds the CSS to device-pixel |
1189 | | // scale factor from the parent, which will be applied to the subdocument's |
1190 | | // device context instead of retrieving a scale from the widget. |
1191 | | static bool |
1192 | | UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument, void* aData); |
1193 | | |
1194 | | void SetImgAnimations(nsIContent *aParent, uint16_t aMode); |
1195 | | void SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode, |
1196 | | uint16_t aOldMode); |
1197 | | void GetDocumentColorPreferences(); |
1198 | | |
1199 | | void PreferenceChanged(const char* aPrefName); |
1200 | | |
1201 | | void UpdateAfterPreferencesChanged(); |
1202 | | void DispatchPrefChangedRunnableIfNeeded(); |
1203 | | |
1204 | | void GetUserPreferences(); |
1205 | | |
1206 | | /** |
1207 | | * Fetch the user's font preferences for the given aLanguage's |
1208 | | * langugage group. |
1209 | | */ |
1210 | | const LangGroupFontPrefs* GetFontPrefsForLang(nsAtom *aLanguage, bool* aNeedsToCache = nullptr) const |
1211 | | { |
1212 | | nsAtom* lang = aLanguage ? aLanguage : mLanguage.get(); |
1213 | | return StaticPresData::Get()->GetFontPrefsForLangHelper(lang, &mLangGroupFontPrefs, aNeedsToCache); |
1214 | | } |
1215 | | |
1216 | | void UpdateCharSet(NotNull<const Encoding*> aCharSet); |
1217 | | |
1218 | | static bool NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData); |
1219 | | static bool NotifyRevokingDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData); |
1220 | | |
1221 | | |
1222 | | public: |
1223 | | // Used by the PresShell to force a reflow when some aspect of font info |
1224 | | // has been updated, potentially affecting font selection and layout. |
1225 | | void ForceReflowForFontInfoUpdate(); |
1226 | | |
1227 | | void DoChangeCharSet(NotNull<const Encoding*> aCharSet); |
1228 | | |
1229 | | /** |
1230 | | * Checks for MozAfterPaint listeners on the document |
1231 | | */ |
1232 | | bool MayHavePaintEventListener(); |
1233 | | |
1234 | | /** |
1235 | | * Checks for MozAfterPaint listeners on the document and |
1236 | | * any subdocuments, except for subdocuments that are non-top-level |
1237 | | * content documents. |
1238 | | */ |
1239 | | bool MayHavePaintEventListenerInSubDocument(); |
1240 | | |
1241 | | void InvalidatePaintedLayers(); |
1242 | | |
1243 | | protected: |
1244 | | // May be called multiple times (unlink, destructor) |
1245 | | void Destroy(); |
1246 | | |
1247 | | void AppUnitsPerDevPixelChanged(); |
1248 | | |
1249 | | bool HavePendingInputEvent(); |
1250 | | |
1251 | | // Creates a one-shot timer with the given aCallback & aDelay. |
1252 | | // Returns a refcounted pointer to the timer (or nullptr on failure). |
1253 | | already_AddRefed<nsITimer> CreateTimer(nsTimerCallbackFunc aCallback, |
1254 | | const char* aName, |
1255 | | uint32_t aDelay); |
1256 | | |
1257 | | struct TransactionInvalidations { |
1258 | | TransactionId mTransactionId; |
1259 | | nsTArray<nsRect> mInvalidations; |
1260 | | bool mIsWaitingForPreviousTransaction = false; |
1261 | | }; |
1262 | | TransactionInvalidations* GetInvalidations(TransactionId aTransactionId); |
1263 | | |
1264 | | // IMPORTANT: The ownership implicit in the following member variables |
1265 | | // has been explicitly checked. If you add any members to this class, |
1266 | | // please make the ownership explicit (pinkerton, scc). |
1267 | | |
1268 | | nsPresContextType mType; |
1269 | | // the nsPresShell owns a strong reference to the nsPresContext, and is responsible |
1270 | | // for nulling this pointer before it is destroyed |
1271 | | nsIPresShell* MOZ_NON_OWNING_REF mShell; // [WEAK] |
1272 | | nsCOMPtr<nsIDocument> mDocument; |
1273 | | RefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but |
1274 | | // better safe than sorry. |
1275 | | // Cannot reintroduce cycles |
1276 | | // since there is no dependency |
1277 | | // from gfx back to layout. |
1278 | | RefPtr<mozilla::EventStateManager> mEventManager; |
1279 | | RefPtr<nsRefreshDriver> mRefreshDriver; |
1280 | | RefPtr<mozilla::AnimationEventDispatcher> mAnimationEventDispatcher; |
1281 | | RefPtr<mozilla::EffectCompositor> mEffectCompositor; |
1282 | | mozilla::UniquePtr<nsTransitionManager> mTransitionManager; |
1283 | | mozilla::UniquePtr<nsAnimationManager> mAnimationManager; |
1284 | | mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager; |
1285 | | RefPtr<mozilla::CounterStyleManager> mCounterStyleManager; |
1286 | | nsAtom* MOZ_UNSAFE_REF("always a static atom") mMedium; // initialized by subclass ctors |
1287 | | RefPtr<nsAtom> mMediaEmulated; |
1288 | | RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup; |
1289 | | |
1290 | | // This pointer is nulled out through SetLinkHandler() in the destructors of |
1291 | | // the classes which set it. (using SetLinkHandler() again). |
1292 | | nsILinkHandler* MOZ_NON_OWNING_REF mLinkHandler; |
1293 | | |
1294 | | // Formerly mLangGroup; moving from charset-oriented langGroup to |
1295 | | // maintaining actual language settings everywhere (see bug 524107). |
1296 | | // This may in fact hold a langGroup such as x-western rather than |
1297 | | // a specific language, however (e.g, if it is inferred from the |
1298 | | // charset rather than explicitly specified as a lang attribute). |
1299 | | RefPtr<nsAtom> mLanguage; |
1300 | | |
1301 | | public: |
1302 | | // The following are public member variables so that we can use them |
1303 | | // with mozilla::AutoToggle or mozilla::AutoRestore. |
1304 | | |
1305 | | // Should we disable font size inflation because we're inside of |
1306 | | // shrink-wrapping calculations on an inflation container? |
1307 | | bool mInflationDisabledForShrinkWrap; |
1308 | | |
1309 | | protected: |
1310 | | |
1311 | | mozilla::WeakPtr<nsDocShell> mContainer; |
1312 | | |
1313 | | // Base minimum font size, independent of the language-specific global preference. Defaults to 0 |
1314 | | int32_t mBaseMinFontSize; |
1315 | | float mSystemFontScale; // Internal text zoom factor, defaults to 1.0 |
1316 | | float mTextZoom; // Text zoom, defaults to 1.0 |
1317 | | float mEffectiveTextZoom; // Text zoom * system font scale |
1318 | | float mFullZoom; // Page zoom, defaults to 1.0 |
1319 | | float mOverrideDPPX; // DPPX overrided, defaults to 0.0 |
1320 | | gfxSize mLastFontInflationScreenSize; |
1321 | | |
1322 | | int32_t mCurAppUnitsPerDevPixel; |
1323 | | int32_t mAutoQualityMinFontSizePixelsPref; |
1324 | | |
1325 | | nsCOMPtr<nsITheme> mTheme; |
1326 | | nsLanguageAtomService* mLangService; |
1327 | | nsCOMPtr<nsIPrintSettings> mPrintSettings; |
1328 | | |
1329 | | mozilla::UniquePtr<nsBidi> mBidiEngine; |
1330 | | |
1331 | | AutoTArray<TransactionInvalidations, 4> mTransactions; |
1332 | | |
1333 | | // text performance metrics |
1334 | | nsAutoPtr<gfxTextPerfMetrics> mTextPerf; |
1335 | | |
1336 | | nsAutoPtr<gfxMissingFontRecorder> mMissingFonts; |
1337 | | |
1338 | | nsRect mVisibleArea; |
1339 | | nsRect mLastResizeEventVisibleArea; |
1340 | | nsSize mPageSize; |
1341 | | float mPageScale; |
1342 | | float mPPScale; |
1343 | | |
1344 | | nscolor mDefaultColor; |
1345 | | nscolor mBackgroundColor; |
1346 | | |
1347 | | nscolor mLinkColor; |
1348 | | nscolor mActiveLinkColor; |
1349 | | nscolor mVisitedLinkColor; |
1350 | | |
1351 | | nscolor mFocusBackgroundColor; |
1352 | | nscolor mFocusTextColor; |
1353 | | |
1354 | | nscolor mBodyTextColor; |
1355 | | |
1356 | | // This is a non-owning pointer. May be null. If non-null, it's guaranteed to |
1357 | | // be pointing to an element that's still alive, because we'll reset it in |
1358 | | // UpdateViewportScrollStylesOverride() as part of the cleanup code when |
1359 | | // this element is removed from the document. (For <body> and the root |
1360 | | // element, this call happens in nsCSSFrameConstructor::ContentRemoved(). For |
1361 | | // fullscreen elements, it happens in the fullscreen-specific cleanup invoked |
1362 | | // by Element::UnbindFromTree().) |
1363 | | mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollOverrideElement; |
1364 | | ScrollStyles mViewportScrollStyles; |
1365 | | |
1366 | | uint8_t mFocusRingWidth; |
1367 | | |
1368 | | bool mExistThrottledUpdates; |
1369 | | |
1370 | | uint16_t mImageAnimationMode; |
1371 | | uint16_t mImageAnimationModePref; |
1372 | | |
1373 | | // Most documents will only use one (or very few) language groups. Rather |
1374 | | // than have the overhead of a hash lookup, we simply look along what will |
1375 | | // typically be a very short (usually of length 1) linked list. There are 31 |
1376 | | // language groups, so in the worst case scenario we'll need to traverse 31 |
1377 | | // link items. |
1378 | | LangGroupFontPrefs mLangGroupFontPrefs; |
1379 | | |
1380 | | bool mFontGroupCacheDirty; |
1381 | | nsTHashtable<nsRefPtrHashKey<nsAtom>> mLanguagesUsed; |
1382 | | |
1383 | | nscoord mBorderWidthTable[3]; |
1384 | | |
1385 | | uint32_t mInterruptChecksToSkip; |
1386 | | |
1387 | | // Counters for tests and tools that want to detect frame construction |
1388 | | // or reflow. |
1389 | | uint64_t mElementsRestyled; |
1390 | | uint64_t mFramesConstructed; |
1391 | | uint64_t mFramesReflowed; |
1392 | | |
1393 | | mozilla::TimeStamp mReflowStartTime; |
1394 | | |
1395 | | // Time of various first interaction types, used to report time from |
1396 | | // first paint of the top level content pres shell to first interaction. |
1397 | | mozilla::TimeStamp mFirstNonBlankPaintTime; |
1398 | | mozilla::TimeStamp mFirstClickTime; |
1399 | | mozilla::TimeStamp mFirstKeyTime; |
1400 | | mozilla::TimeStamp mFirstMouseMoveTime; |
1401 | | mozilla::TimeStamp mFirstScrollTime; |
1402 | | bool mInteractionTimeEnabled; |
1403 | | |
1404 | | // last time we did a full style flush |
1405 | | mozilla::TimeStamp mLastStyleUpdateForAllAnimations; |
1406 | | |
1407 | | unsigned mHasPendingInterrupt : 1; |
1408 | | unsigned mPendingInterruptFromTest : 1; |
1409 | | unsigned mInterruptsEnabled : 1; |
1410 | | unsigned mUseDocumentFonts : 1; |
1411 | | unsigned mUseDocumentColors : 1; |
1412 | | unsigned mUnderlineLinks : 1; |
1413 | | unsigned mSendAfterPaintToContent : 1; |
1414 | | unsigned mUseFocusColors : 1; |
1415 | | unsigned mFocusRingOnAnything : 1; |
1416 | | unsigned mFocusRingStyle : 1; |
1417 | | unsigned mDrawImageBackground : 1; |
1418 | | unsigned mDrawColorBackground : 1; |
1419 | | unsigned mNeverAnimate : 1; |
1420 | | unsigned mIsRenderingOnlySelection : 1; |
1421 | | unsigned mPaginated : 1; |
1422 | | unsigned mCanPaginatedScroll : 1; |
1423 | | unsigned mDoScaledTwips : 1; |
1424 | | unsigned mIsRootPaginatedDocument : 1; |
1425 | | unsigned mPrefBidiDirection : 1; |
1426 | | unsigned mPrefScrollbarSide : 2; |
1427 | | unsigned mPendingSysColorChanged : 1; |
1428 | | unsigned mPendingThemeChanged : 1; |
1429 | | unsigned mPendingUIResolutionChanged : 1; |
1430 | | unsigned mPrefChangePendingNeedsReflow : 1; |
1431 | | unsigned mPostedPrefChangedRunnable : 1; |
1432 | | unsigned mIsEmulatingMedia : 1; |
1433 | | |
1434 | | // Are we currently drawing an SVG glyph? |
1435 | | unsigned mIsGlyph : 1; |
1436 | | |
1437 | | // Does the associated document use root-em (rem) units? |
1438 | | unsigned mUsesRootEMUnits : 1; |
1439 | | // Does the associated document use ex or ch units? |
1440 | | unsigned mUsesExChUnits : 1; |
1441 | | |
1442 | | // Is the current mCounterStyleManager valid? |
1443 | | unsigned mCounterStylesDirty : 1; |
1444 | | |
1445 | | // Is the current mFontFeatureValuesLookup valid? |
1446 | | unsigned mFontFeatureValuesDirty : 1; |
1447 | | |
1448 | | // resize reflow is suppressed when the only change has been to zoom |
1449 | | // the document rather than to change the document's dimensions |
1450 | | unsigned mSuppressResizeReflow : 1; |
1451 | | |
1452 | | unsigned mIsVisual : 1; |
1453 | | |
1454 | | unsigned mIsChrome : 1; |
1455 | | unsigned mIsChromeOriginImage : 1; |
1456 | | |
1457 | | // Should we paint flash in this context? Do not use this variable directly. |
1458 | | // Use GetPaintFlashing() method instead. |
1459 | | mutable unsigned mPaintFlashing : 1; |
1460 | | mutable unsigned mPaintFlashingInitialized : 1; |
1461 | | |
1462 | | unsigned mHasWarnedAboutPositionedTableParts : 1; |
1463 | | |
1464 | | unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1; |
1465 | | |
1466 | | // Have we added quirk.css to the style set? |
1467 | | unsigned mQuirkSheetAdded : 1; |
1468 | | |
1469 | | // Is there a pref update to process once we have a container? |
1470 | | unsigned mNeedsPrefUpdate : 1; |
1471 | | |
1472 | | // Has NotifyNonBlankPaint been called on this PresContext? |
1473 | | unsigned mHadNonBlankPaint : 1; |
1474 | | |
1475 | | #ifdef DEBUG |
1476 | | unsigned mInitialized : 1; |
1477 | | #endif |
1478 | | |
1479 | | mozilla::Maybe<mozilla::MediaFeatureChange> mPendingMediaFeatureValuesChange; |
1480 | | |
1481 | | protected: |
1482 | | |
1483 | | virtual ~nsPresContext(); |
1484 | | |
1485 | | nscolor MakeColorPref(const nsString& aColor); |
1486 | | |
1487 | | void LastRelease(); |
1488 | | |
1489 | | #ifdef DEBUG |
1490 | | private: |
1491 | | friend struct nsAutoLayoutPhase; |
1492 | | uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT]; |
1493 | | public: |
1494 | | uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) { |
1495 | | return mLayoutPhaseCount[aPhase]; |
1496 | | } |
1497 | | #endif |
1498 | | |
1499 | | }; |
1500 | | |
1501 | | class nsRootPresContext final : public nsPresContext { |
1502 | | public: |
1503 | | nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType); |
1504 | | virtual ~nsRootPresContext(); |
1505 | | virtual void Detach() override; |
1506 | | |
1507 | | /** |
1508 | | * Registers a plugin to receive geometry updates (position and clip |
1509 | | * region) so it can update its widget. |
1510 | | * Callers must call UnregisterPluginForGeometryUpdates before |
1511 | | * the aPlugin frame is destroyed. |
1512 | | */ |
1513 | | void RegisterPluginForGeometryUpdates(nsIContent* aPlugin); |
1514 | | /** |
1515 | | * Stops a plugin receiving geometry updates (position and clip |
1516 | | * region). If the plugin was not already registered, this does |
1517 | | * nothing. |
1518 | | */ |
1519 | | void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin); |
1520 | | |
1521 | | bool NeedToComputePluginGeometryUpdates() |
1522 | | { |
1523 | | return mRegisteredPlugins.Count() > 0; |
1524 | | } |
1525 | | /** |
1526 | | * Compute geometry updates for each plugin given that aList is the display |
1527 | | * list for aFrame. The updates are not yet applied; |
1528 | | * ApplyPluginGeometryUpdates is responsible for that. In the meantime they |
1529 | | * are stored on each nsPluginFrame. |
1530 | | * This needs to be called even when aFrame is a popup, since although |
1531 | | * windowed plugins aren't allowed in popups, windowless plugins are |
1532 | | * and ComputePluginGeometryUpdates needs to be called for them. |
1533 | | * aBuilder and aList can be null. This indicates that all plugins are |
1534 | | * hidden because we're in a background tab. |
1535 | | */ |
1536 | | void ComputePluginGeometryUpdates(nsIFrame* aFrame, |
1537 | | nsDisplayListBuilder* aBuilder, |
1538 | | nsDisplayList* aList); |
1539 | | |
1540 | | /** |
1541 | | * Apply the stored plugin geometry updates. This should normally be called |
1542 | | * in DidPaint so the plugins are moved/clipped immediately after we've |
1543 | | * updated our window, so they look in sync with our window. |
1544 | | */ |
1545 | | void ApplyPluginGeometryUpdates(); |
1546 | | |
1547 | | /** |
1548 | | * Transfer stored plugin geometry updates to the compositor. Called during |
1549 | | * reflow, data is shipped over with layer updates. e10s specific. |
1550 | | */ |
1551 | | void CollectPluginGeometryUpdates(mozilla::layers::LayerManager* aLayerManager); |
1552 | | |
1553 | | virtual bool IsRoot() override { return true; } |
1554 | | |
1555 | | /** |
1556 | | * Add a runnable that will get called before the next paint. They will get |
1557 | | * run eventually even if painting doesn't happen. They might run well before |
1558 | | * painting happens. |
1559 | | */ |
1560 | | void AddWillPaintObserver(nsIRunnable* aRunnable); |
1561 | | |
1562 | | /** |
1563 | | * Run all runnables that need to get called before the next paint. |
1564 | | */ |
1565 | | void FlushWillPaintObservers(); |
1566 | | |
1567 | | virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; |
1568 | | |
1569 | | protected: |
1570 | | /** |
1571 | | * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates. |
1572 | | */ |
1573 | | void InitApplyPluginGeometryTimer(); |
1574 | | /** |
1575 | | * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates. |
1576 | | */ |
1577 | | void CancelApplyPluginGeometryTimer(); |
1578 | | |
1579 | | class RunWillPaintObservers : public mozilla::Runnable { |
1580 | | public: |
1581 | | explicit RunWillPaintObservers(nsRootPresContext* aPresContext) |
1582 | | : Runnable("nsPresContextType::RunWillPaintObservers") |
1583 | | , mPresContext(aPresContext) {} |
1584 | | void Revoke() { mPresContext = nullptr; } |
1585 | | NS_IMETHOD Run() override |
1586 | | { |
1587 | | if (mPresContext) { |
1588 | | mPresContext->FlushWillPaintObservers(); |
1589 | | } |
1590 | | return NS_OK; |
1591 | | } |
1592 | | // The lifetime of this reference is handled by an nsRevocableEventPtr |
1593 | | nsRootPresContext* MOZ_NON_OWNING_REF mPresContext; |
1594 | | }; |
1595 | | |
1596 | | friend class nsPresContext; |
1597 | | |
1598 | | nsCOMPtr<nsITimer> mApplyPluginGeometryTimer; |
1599 | | nsTHashtable<nsRefPtrHashKey<nsIContent> > mRegisteredPlugins; |
1600 | | nsTArray<nsCOMPtr<nsIRunnable> > mWillPaintObservers; |
1601 | | nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent; |
1602 | | }; |
1603 | | |
1604 | | #ifdef MOZ_REFLOW_PERF |
1605 | | |
1606 | | #define DO_GLOBAL_REFLOW_COUNT(_name) \ |
1607 | | aPresContext->CountReflows((_name), (nsIFrame*)this); |
1608 | | #else |
1609 | | #define DO_GLOBAL_REFLOW_COUNT(_name) |
1610 | | #endif // MOZ_REFLOW_PERF |
1611 | | |
1612 | | #endif /* nsPresContext_h___ */ |