layout/base/nsPresContext.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:4aae2525e474
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /* a presentation of a document, part 1 */
7
8 #ifndef nsPresContext_h___
9 #define nsPresContext_h___
10
11 #include "mozilla/Attributes.h"
12 #include "mozilla/WeakPtr.h"
13 #include "nsColor.h"
14 #include "nsCoord.h"
15 #include "nsCOMPtr.h"
16 #include "nsIPresShell.h"
17 #include "nsRect.h"
18 #include "nsFont.h"
19 #include "gfxFontConstants.h"
20 #include "nsIAtom.h"
21 #include "nsIObserver.h"
22 #include "nsITimer.h"
23 #include "nsCRT.h"
24 #include "FramePropertyTable.h"
25 #include "nsGkAtoms.h"
26 #include "nsCycleCollectionParticipant.h"
27 #include "nsChangeHint.h"
28 #include <algorithm>
29 // This also pulls in gfxTypes.h, which we cannot include directly.
30 #include "gfxRect.h"
31 #include "nsTArray.h"
32 #include "nsAutoPtr.h"
33 #include "mozilla/MemoryReporting.h"
34 #include "mozilla/TimeStamp.h"
35 #include "mozilla/AppUnits.h"
36 #include "prclist.h"
37 #include "nsThreadUtils.h"
38 #include "ScrollbarStyles.h"
39
40 class nsBidiPresUtils;
41 class nsAString;
42 class nsIPrintSettings;
43 class nsDocShell;
44 class nsIDocShell;
45 class nsIDocument;
46 class nsILanguageAtomService;
47 class nsITheme;
48 class nsIContent;
49 class nsIFrame;
50 class nsFrameManager;
51 class nsILinkHandler;
52 class nsIAtom;
53 class nsICSSPseudoComparator;
54 struct nsStyleBackground;
55 struct nsStyleBorder;
56 class nsIRunnable;
57 class gfxUserFontSet;
58 class gfxTextPerfMetrics;
59 class nsUserFontSet;
60 struct nsFontFaceRuleContainer;
61 class nsObjectFrame;
62 class nsTransitionManager;
63 class nsAnimationManager;
64 class nsRefreshDriver;
65 class nsIWidget;
66 class nsDeviceContext;
67
68 namespace mozilla {
69 class EventStateManager;
70 class RestyleManager;
71 namespace dom {
72 class MediaQueryList;
73 }
74 namespace layers {
75 class ContainerLayer;
76 }
77 }
78
79 // supported values for cached bool types
80 enum nsPresContext_CachedBoolPrefType {
81 kPresContext_UseDocumentColors = 1,
82 kPresContext_UseDocumentFonts,
83 kPresContext_UnderlineLinks
84 };
85
86 // supported values for cached integer pref types
87 enum nsPresContext_CachedIntPrefType {
88 kPresContext_ScrollbarSide = 1,
89 kPresContext_BidiDirection
90 };
91
92 // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
93 // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
94 const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable
95 const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed
96
97 #ifdef DEBUG
98 struct nsAutoLayoutPhase;
99
100 enum nsLayoutPhase {
101 eLayoutPhase_Paint,
102 eLayoutPhase_Reflow,
103 eLayoutPhase_FrameC,
104 eLayoutPhase_COUNT
105 };
106 #endif
107
108 class nsInvalidateRequestList {
109 public:
110 struct Request {
111 nsRect mRect;
112 uint32_t mFlags;
113 };
114
115 void TakeFrom(nsInvalidateRequestList* aList)
116 {
117 mRequests.MoveElementsFrom(aList->mRequests);
118 }
119 bool IsEmpty() { return mRequests.IsEmpty(); }
120
121 nsTArray<Request> mRequests;
122 };
123
124 /* Used by nsPresContext::HasAuthorSpecifiedRules */
125 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
126 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
127 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
128 #define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3)
129
130 class nsRootPresContext;
131
132 // An interface for presentation contexts. Presentation contexts are
133 // objects that provide an outer context for a presentation shell.
134
135 class nsPresContext : public nsIObserver {
136 public:
137 typedef mozilla::FramePropertyTable FramePropertyTable;
138
139 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
140 NS_DECL_NSIOBSERVER
141 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
142 NS_DECL_CYCLE_COLLECTION_CLASS(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 // Policies for rebuilding style data.
152 enum StyleRebuildType {
153 eRebuildStyleIfNeeded,
154 eAlwaysRebuildStyle
155 };
156
157 nsPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN;
158
159 /**
160 * Initialize the presentation context from a particular device.
161 */
162 NS_HIDDEN_(nsresult) Init(nsDeviceContext* aDeviceContext);
163
164 /**
165 * Set the presentation shell that this context is bound to.
166 * A presentation context may only be bound to a single shell.
167 */
168 NS_HIDDEN_(void) SetShell(nsIPresShell* aShell);
169
170
171 NS_HIDDEN_(nsPresContextType) Type() const { return mType; }
172
173 /**
174 * Get the PresentationShell that this context is bound to.
175 */
176 nsIPresShell* PresShell() const
177 {
178 NS_ASSERTION(mShell, "Null pres shell");
179 return mShell;
180 }
181
182 nsIPresShell* GetPresShell() const { return mShell; }
183
184 /**
185 * Returns the parent prescontext for this one. Returns null if this is a
186 * root.
187 */
188 nsPresContext* GetParentPresContext();
189
190 /**
191 * Returns the prescontext of the toplevel content document that contains
192 * this presentation, or null if there isn't one.
193 */
194 nsPresContext* GetToplevelContentDocumentPresContext();
195
196 /**
197 * Returns the nearest widget for the root frame of this.
198 *
199 * @param aOffset If non-null the offset from the origin of the root
200 * frame's view to the widget's origin (usually positive)
201 * expressed in appunits of this will be returned in
202 * aOffset.
203 */
204 nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
205
206 /**
207 * Returns the root widget for this.
208 * Note that the widget is a mediater with IME.
209 */
210 nsIWidget* GetRootWidget();
211
212 /**
213 * Return the presentation context for the root of the view manager
214 * hierarchy that contains this presentation context, or nullptr if it can't
215 * be found (e.g. it's detached).
216 */
217 nsRootPresContext* GetRootPresContext();
218 nsRootPresContext* GetDisplayRootPresContext();
219 virtual bool IsRoot() { return false; }
220
221 nsIDocument* Document() const
222 {
223 NS_ASSERTION(!mShell || !mShell->GetDocument() ||
224 mShell->GetDocument() == mDocument,
225 "nsPresContext doesn't have the same document as nsPresShell!");
226 return mDocument;
227 }
228
229 #ifdef MOZILLA_INTERNAL_API
230 nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); }
231
232 nsFrameManager* FrameManager()
233 { return PresShell()->FrameManager(); }
234
235 nsCSSFrameConstructor* FrameConstructor()
236 { return PresShell()->FrameConstructor(); }
237
238 nsTransitionManager* TransitionManager() { return mTransitionManager; }
239 nsAnimationManager* AnimationManager() { return mAnimationManager; }
240
241 nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
242
243 mozilla::RestyleManager* RestyleManager() { return mRestyleManager; }
244 #endif
245
246 /**
247 * Rebuilds all style data by throwing out the old rule tree and
248 * building a new one, and additionally applying aExtraHint (which
249 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
250 * Also rebuild the user font set.
251 */
252 void RebuildAllStyleData(nsChangeHint aExtraHint);
253 /**
254 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
255 * doesn't rebuild the user font set.
256 */
257 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint);
258
259 void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild,
260 nsChangeHint aChangeHint = nsChangeHint(0));
261 void PostMediaFeatureValuesChangedEvent();
262 NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent();
263 void FlushPendingMediaFeatureValuesChanged() {
264 if (mPendingMediaFeatureValuesChanged)
265 MediaFeatureValuesChanged(eRebuildStyleIfNeeded);
266 }
267
268 /**
269 * Support for window.matchMedia()
270 */
271 already_AddRefed<mozilla::dom::MediaQueryList>
272 MatchMedia(const nsAString& aMediaQueryList);
273
274 /**
275 * Access compatibility mode for this context. This is the same as
276 * our document's compatibility mode.
277 */
278 nsCompatibility CompatibilityMode() const;
279
280 /**
281 * Notify the context that the document's compatibility mode has changed
282 */
283 NS_HIDDEN_(void) CompatibilityModeChanged();
284
285 /**
286 * Access the image animation mode for this context
287 */
288 uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
289 virtual NS_HIDDEN_(void) SetImageAnimationModeExternal(uint16_t aMode);
290 NS_HIDDEN_(void) SetImageAnimationModeInternal(uint16_t aMode);
291 #ifdef MOZILLA_INTERNAL_API
292 void SetImageAnimationMode(uint16_t aMode)
293 { SetImageAnimationModeInternal(aMode); }
294 #else
295 void SetImageAnimationMode(uint16_t aMode)
296 { SetImageAnimationModeExternal(aMode); }
297 #endif
298
299 /**
300 * Get medium of presentation
301 */
302 nsIAtom* Medium() {
303 if (!mIsEmulatingMedia)
304 return mMedium;
305 return mMediaEmulated;
306 }
307
308 /*
309 * Render the document as if being viewed on a device with the specified
310 * media type.
311 */
312 void EmulateMedium(const nsAString& aMediaType);
313
314 /*
315 * Restore the viewer's natural medium
316 */
317 void StopEmulatingMedium();
318
319 void* AllocateFromShell(size_t aSize)
320 {
321 if (mShell)
322 return mShell->AllocateMisc(aSize);
323 return nullptr;
324 }
325
326 void FreeToShell(size_t aSize, void* aFreeChunk)
327 {
328 NS_ASSERTION(mShell, "freeing after shutdown");
329 if (mShell)
330 mShell->FreeMisc(aSize, aFreeChunk);
331 }
332
333 /**
334 * Get the default font for the given language and generic font ID.
335 * If aLanguage is nullptr, the document's language is used.
336 *
337 * This object is read-only, you must copy the font to modify it.
338 *
339 * When aFontID is kPresContext_DefaultVariableFontID or
340 * kPresContext_DefaultFixedFontID (which equals
341 * kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
342 * the nsFont returned has its name as a CSS generic family (serif or
343 * sans-serif for the former, monospace for the latter), and its size
344 * as the default font size for variable or fixed fonts for the
345 * language group.
346 *
347 * For aFontID corresponding to a CSS Generic, the nsFont returned has
348 * its name set to that generic font's name, and its size set to
349 * the user's preference for font size for that generic and the
350 * given language.
351 */
352 NS_HIDDEN_(const nsFont*) GetDefaultFont(uint8_t aFontID,
353 nsIAtom *aLanguage) const;
354
355 /** Get a cached boolean pref, by its type */
356 // * - initially created for bugs 31816, 20760, 22963
357 bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const
358 {
359 // If called with a constant parameter, the compiler should optimize
360 // this switch statement away.
361 switch (aPrefType) {
362 case kPresContext_UseDocumentFonts:
363 return mUseDocumentFonts;
364 case kPresContext_UseDocumentColors:
365 return mUseDocumentColors;
366 case kPresContext_UnderlineLinks:
367 return mUnderlineLinks;
368 default:
369 NS_ERROR("Invalid arg passed to GetCachedBoolPref");
370 }
371
372 return false;
373 }
374
375 /** Get a cached integer pref, by its type */
376 // * - initially created for bugs 30910, 61883, 74186, 84398
377 int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const
378 {
379 // If called with a constant parameter, the compiler should optimize
380 // this switch statement away.
381 switch (aPrefType) {
382 case kPresContext_ScrollbarSide:
383 return mPrefScrollbarSide;
384 case kPresContext_BidiDirection:
385 return mPrefBidiDirection;
386 default:
387 NS_ERROR("invalid arg passed to GetCachedIntPref");
388 }
389
390 return false;
391 }
392
393 /**
394 * Get the default colors
395 */
396 const nscolor DefaultColor() const { return mDefaultColor; }
397 const nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
398 const nscolor DefaultLinkColor() const { return mLinkColor; }
399 const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
400 const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
401 const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
402 const nscolor FocusTextColor() const { return mFocusTextColor; }
403
404 /**
405 * Body text color, for use in quirks mode only.
406 */
407 const nscolor BodyTextColor() const { return mBodyTextColor; }
408 void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; }
409
410 bool GetUseFocusColors() const { return mUseFocusColors; }
411 uint8_t FocusRingWidth() const { return mFocusRingWidth; }
412 bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
413 uint8_t GetFocusRingStyle() const { return mFocusRingStyle; }
414
415 NS_HIDDEN_(void) SetContainer(nsIDocShell* aContainer);
416
417 virtual nsISupports* GetContainerWeakExternal() const;
418 nsISupports* GetContainerWeakInternal() const;
419 #ifdef MOZILLA_INTERNAL_API
420 nsISupports* GetContainerWeak() const
421 { return GetContainerWeakInternal(); }
422 #else
423 nsISupports* GetContainerWeak() const
424 { return GetContainerWeakExternal(); }
425 #endif
426
427 nsIDocShell* GetDocShell() const;
428
429 // XXX this are going to be replaced with set/get container
430 void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
431 nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
432
433 /**
434 * Detach this pres context - i.e. cancel relevant timers,
435 * SetLinkHandler(null), SetContainer(null) etc.
436 * Only to be used by the DocumentViewer.
437 */
438 virtual void Detach();
439
440 /**
441 * Get the visible area associated with this presentation context.
442 * This is the size of the visible area that is used for
443 * presenting the document. The returned value is in the standard
444 * nscoord units (as scaled by the device context).
445 */
446 nsRect GetVisibleArea() { return mVisibleArea; }
447
448 /**
449 * Set the currently visible area. The units for r are standard
450 * nscoord units (as scaled by the device context).
451 */
452 void SetVisibleArea(const nsRect& r) {
453 if (!r.IsEqualEdges(mVisibleArea)) {
454 mVisibleArea = r;
455 // Visible area does not affect media queries when paginated.
456 if (!IsPaginated() && HasCachedStyleData()) {
457 mPendingViewportChange = true;
458 PostMediaFeatureValuesChangedEvent();
459 }
460 }
461 }
462
463 /**
464 * Return true if this presentation context is a paginated
465 * context.
466 */
467 bool IsPaginated() const { return mPaginated; }
468
469 /**
470 * Sets whether the presentation context can scroll for a paginated
471 * context.
472 */
473 NS_HIDDEN_(void) SetPaginatedScrolling(bool aResult);
474
475 /**
476 * Return true if this presentation context can scroll for paginated
477 * context.
478 */
479 bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
480
481 /**
482 * Get/set the size of a page
483 */
484 nsSize GetPageSize() { return mPageSize; }
485 void SetPageSize(nsSize aSize) { mPageSize = aSize; }
486
487 /**
488 * Get/set whether this document should be treated as having real pages
489 * XXX This raises the obvious question of why a document that isn't a page
490 * is paginated; there isn't a good reason except history
491 */
492 bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
493 void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument)
494 { mIsRootPaginatedDocument = aIsRootPaginatedDocument; }
495
496 /**
497 * Get/set the print scaling level; used by nsPageFrame to scale up
498 * pages. Set safe to call before reflow, get guaranteed to be set
499 * properly after reflow.
500 */
501
502 float GetPageScale() { return mPageScale; }
503 void SetPageScale(float aScale) { mPageScale = aScale; }
504
505 /**
506 * Get/set the scaling facor to use when rendering the pages for print preview.
507 * Only safe to get after print preview set up; safe to set anytime.
508 * This is a scaling factor for the display of the print preview. It
509 * does not affect layout. It only affects the size of the onscreen pages
510 * in print preview.
511 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
512 */
513 float GetPrintPreviewScale() { return mPPScale; }
514 void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
515
516 nsDeviceContext* DeviceContext() { return mDeviceContext; }
517 mozilla::EventStateManager* EventStateManager() { return mEventManager; }
518 nsIAtom* GetLanguageFromCharset() { return mLanguage; }
519
520 float TextZoom() { return mTextZoom; }
521 void SetTextZoom(float aZoom) {
522 if (aZoom == mTextZoom)
523 return;
524
525 mTextZoom = aZoom;
526 if (HasCachedStyleData()) {
527 // Media queries could have changed, since we changed the meaning
528 // of 'em' units in them.
529 MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
530 }
531 }
532
533 nsTArray<nsFont> mFontsUsed; // currently for font-count limiting only
534 nsTArray<nsFont> mFontsTried; // currently for font-count limiting only
535 void AddFontUse(const nsFont &font);
536 void AddFontAttempt(const nsFont &font);
537 PRBool FontUseCountReached(const nsFont &font);
538 PRBool FontAttemptCountReached(const nsFont &font);
539
540 /**
541 * Get the minimum font size for the specified language. If aLanguage
542 * is nullptr, then the document's language is used. This combines
543 * the language-specific global preference with the per-presentation
544 * base minimum font size.
545 */
546 int32_t MinFontSize(nsIAtom *aLanguage) const {
547 const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
548 return std::max(mBaseMinFontSize, prefs->mMinimumFontSize);
549 }
550
551 /**
552 * Get the per-presentation base minimum font size. This size is
553 * independent of the language-specific global preference.
554 */
555 int32_t BaseMinFontSize() const {
556 return mBaseMinFontSize;
557 }
558
559 /**
560 * Set the per-presentation base minimum font size. This size is
561 * independent of the language-specific global preference.
562 */
563 void SetBaseMinFontSize(int32_t aMinFontSize) {
564 if (aMinFontSize == mBaseMinFontSize)
565 return;
566
567 mBaseMinFontSize = aMinFontSize;
568 if (HasCachedStyleData()) {
569 // Media queries could have changed, since we changed the meaning
570 // of 'em' units in them.
571 MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
572 }
573 }
574
575 float GetFullZoom() { return mFullZoom; }
576 void SetFullZoom(float aZoom);
577
578 nscoord GetAutoQualityMinFontSize() {
579 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
580 }
581
582 /**
583 * Return the device's screen width in inches, for font size
584 * inflation.
585 *
586 * If |aChanged| is non-null, then aChanged is filled in with whether
587 * the return value has changed since either:
588 * a. the last time the function was called with non-null aChanged, or
589 * b. the first time the function was called.
590 */
591 float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr);
592
593 static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
594 int32_t AppUnitsPerDevPixel() const;
595 static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); }
596
597 static nscoord CSSPixelsToAppUnits(int32_t aPixels)
598 { return NSToCoordRoundWithClamp(float(aPixels) *
599 float(AppUnitsPerCSSPixel())); }
600
601 static nscoord CSSPixelsToAppUnits(float aPixels)
602 { return NSToCoordRoundWithClamp(aPixels *
603 float(AppUnitsPerCSSPixel())); }
604
605 static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits)
606 { return NSAppUnitsToIntPixels(aAppUnits,
607 float(AppUnitsPerCSSPixel())); }
608
609 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits)
610 { return NSAppUnitsToFloatPixels(aAppUnits,
611 float(AppUnitsPerCSSPixel())); }
612
613 nscoord DevPixelsToAppUnits(int32_t aPixels) const
614 { return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel()); }
615
616 int32_t AppUnitsToDevPixels(nscoord aAppUnits) const
617 { return NSAppUnitsToIntPixels(aAppUnits,
618 float(AppUnitsPerDevPixel())); }
619
620 int32_t CSSPixelsToDevPixels(int32_t aPixels)
621 { return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }
622
623 float CSSPixelsToDevPixels(float aPixels)
624 {
625 return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
626 float(AppUnitsPerDevPixel()));
627 }
628
629 int32_t DevPixelsToIntCSSPixels(int32_t aPixels)
630 { return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); }
631
632 float DevPixelsToFloatCSSPixels(int32_t aPixels)
633 { return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); }
634
635 // If there is a remainder, it is rounded to nearest app units.
636 nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
637
638 gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
639
640 gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const
641 { return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
642 AppUnitsToGfxUnits(aAppRect.y),
643 AppUnitsToGfxUnits(aAppRect.width),
644 AppUnitsToGfxUnits(aAppRect.height)); }
645
646 static nscoord CSSTwipsToAppUnits(float aTwips)
647 { return NSToCoordRoundWithClamp(
648 mozilla::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); }
649
650 // Margin-specific version, since they often need TwipsToAppUnits
651 static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips)
652 { return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
653 CSSTwipsToAppUnits(float(marginInTwips.right)),
654 CSSTwipsToAppUnits(float(marginInTwips.bottom)),
655 CSSTwipsToAppUnits(float(marginInTwips.left))); }
656
657 static nscoord CSSPointsToAppUnits(float aPoints)
658 { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
659 POINTS_PER_INCH_FLOAT); }
660
661 nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
662 { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
663
664 void SetViewportOverflowOverride(uint8_t aX, uint8_t aY)
665 {
666 mViewportStyleOverflow.mHorizontal = aX;
667 mViewportStyleOverflow.mVertical = aY;
668 }
669 mozilla::ScrollbarStyles GetViewportOverflowOverride()
670 {
671 return mViewportStyleOverflow;
672 }
673
674 /**
675 * Set and get methods for controlling the background drawing
676 */
677 bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
678 void SetBackgroundImageDraw(bool aCanDraw)
679 {
680 mDrawImageBackground = aCanDraw;
681 }
682
683 bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
684 void SetBackgroundColorDraw(bool aCanDraw)
685 {
686 mDrawColorBackground = aCanDraw;
687 }
688
689 /**
690 * Getter and setter for OMTA time counters
691 */
692 bool ThrottledTransitionStyleIsUpToDate() const;
693 void TickLastUpdateThrottledTransitionStyle();
694 bool ThrottledAnimationStyleIsUpToDate() const;
695 void TickLastUpdateThrottledAnimationStyle();
696 bool StyleUpdateForAllAnimationsIsUpToDate();
697 void TickLastStyleUpdateForAllAnimations();
698
699 /**
700 * Check if bidi enabled (set depending on the presence of RTL
701 * characters or when default directionality is RTL).
702 * If enabled, we should apply the Unicode Bidi Algorithm
703 *
704 * @lina 07/12/2000
705 */
706 #ifdef MOZILLA_INTERNAL_API
707 bool BidiEnabled() const { return BidiEnabledInternal(); }
708 #else
709 bool BidiEnabled() const { return BidiEnabledExternal(); }
710 #endif
711 virtual bool BidiEnabledExternal() const;
712 bool BidiEnabledInternal() const;
713
714 /**
715 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
716 *
717 * @lina 07/12/2000
718 */
719 NS_HIDDEN_(void) SetBidiEnabled() const;
720
721 /**
722 * Set visual or implicit mode into the pres context.
723 *
724 * Visual directionality is a presentation method that displays text
725 * as if it were a uni-directional, according to the primary display
726 * direction only.
727 *
728 * Implicit directionality is a presentation method in which the
729 * direction is determined by the Bidi algorithm according to the
730 * category of the characters and the category of the adjacent
731 * characters, and according to their primary direction.
732 *
733 * @lina 05/02/2000
734 */
735 void SetVisualMode(bool aIsVisual)
736 {
737 mIsVisual = aIsVisual;
738 }
739
740 /**
741 * Check whether the content should be treated as visual.
742 *
743 * @lina 05/02/2000
744 */
745 bool IsVisualMode() const { return mIsVisual; }
746
747 //Mohamed
748
749 /**
750 * Set the Bidi options for the presentation context
751 */
752 NS_HIDDEN_(void) SetBidi(uint32_t aBidiOptions,
753 bool aForceRestyle = false);
754
755 /**
756 * Get the Bidi options for the presentation context
757 * Not inline so consumers of nsPresContext are not forced to
758 * include nsIDocument.
759 */
760 NS_HIDDEN_(uint32_t) GetBidi() const;
761
762 /**
763 * Render only Selection
764 */
765 void SetIsRenderingOnlySelection(bool aResult)
766 {
767 mIsRenderingOnlySelection = aResult;
768 }
769
770 bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; }
771
772 NS_HIDDEN_(bool) IsTopLevelWindowInactive();
773
774 /*
775 * Obtain a native them for rendering our widgets (both form controls and html)
776 */
777 NS_HIDDEN_(nsITheme*) GetTheme();
778
779 /*
780 * Notify the pres context that the theme has changed. An internal switch
781 * means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
782 * Otherwise, the OS is telling us that the native theme for the platform
783 * has changed.
784 */
785 NS_HIDDEN_(void) ThemeChanged();
786
787 /*
788 * Notify the pres context that the resolution of the user interface has
789 * changed. This happens if a window is moved between HiDPI and non-HiDPI
790 * displays, so that the ratio of points to device pixels changes.
791 */
792 NS_HIDDEN_(void) UIResolutionChanged();
793
794 /*
795 * Notify the pres context that a system color has changed
796 */
797 NS_HIDDEN_(void) SysColorChanged();
798
799 /** Printing methods below should only be used for Medium() == print **/
800 NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings);
801
802 nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
803
804 /* Accessor for table of frame properties */
805 FramePropertyTable* PropertyTable() { return &mPropertyTable; }
806
807 /* Helper function that ensures that this prescontext is shown in its
808 docshell if it's the most recent prescontext for the docshell. Returns
809 whether the prescontext is now being shown.
810 */
811 NS_HIDDEN_(bool) EnsureVisible();
812
813 #ifdef MOZ_REFLOW_PERF
814 NS_HIDDEN_(void) CountReflows(const char * aName,
815 nsIFrame * aFrame);
816 #endif
817
818 /**
819 * This table maps border-width enums 'thin', 'medium', 'thick'
820 * to actual nscoord values.
821 */
822 const nscoord* GetBorderWidthTable() { return mBorderWidthTable; }
823
824 gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; }
825
826 bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); }
827 bool IsScreen() { return (mMedium == nsGkAtoms::screen ||
828 mType == eContext_PageLayout ||
829 mType == eContext_PrintPreview); }
830
831 // Is this presentation in a chrome docshell?
832 bool IsChrome() const { return mIsChrome; }
833 bool IsChromeOriginImage() const { return mIsChromeOriginImage; }
834 void UpdateIsChrome();
835
836 // Public API for native theme code to get style internals.
837 virtual bool HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const;
838
839 // Is it OK to let the page specify colors and backgrounds?
840 bool UseDocumentColors() const {
841 return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome() || IsChromeOriginImage();
842 }
843
844 // Explicitly enable and disable paint flashing.
845 void SetPaintFlashing(bool aPaintFlashing) {
846 mPaintFlashing = aPaintFlashing;
847 mPaintFlashingInitialized = true;
848 }
849
850 // This method should be used instead of directly accessing mPaintFlashing,
851 // as that value may be out of date when mPaintFlashingInitialized is false.
852 bool GetPaintFlashing() const;
853
854 bool SupressingResizeReflow() const { return mSupressResizeReflow; }
855
856 virtual NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetExternal();
857 NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetInternal();
858 #ifdef MOZILLA_INTERNAL_API
859 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); }
860 #else
861 gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); }
862 #endif
863
864 void FlushUserFontSet();
865 void RebuildUserFontSet(); // asynchronously
866
867 // Should be called whenever the set of fonts available in the user
868 // font set changes (e.g., because a new font loads, or because the
869 // user font set is changed and fonts become unavailable).
870 void UserFontSetUpdated();
871
872 // Ensure that it is safe to hand out CSS rules outside the layout
873 // engine by ensuring that all CSS style sheets have unique inners
874 // and, if necessary, synchronously rebuilding all style data.
875 void EnsureSafeToHandOutCSSRules();
876
877 void NotifyInvalidation(uint32_t aFlags);
878 void NotifyInvalidation(const nsRect& aRect, uint32_t aFlags);
879 // aRect is in device pixels
880 void NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags);
881 // aFlags are nsIPresShell::PAINT_ flags
882 void NotifyDidPaintForSubtree(uint32_t aFlags);
883 void FireDOMPaintEvent(nsInvalidateRequestList* aList);
884
885 // Callback for catching invalidations in ContainerLayers
886 // Passed to LayerProperties::ComputeDifference
887 static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer,
888 const nsIntRegion& aRegion);
889 void SetNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer);
890 static void ClearNotifySubDocInvalidationData(mozilla::layers::ContainerLayer* aContainer);
891 bool IsDOMPaintEventPending();
892 void ClearMozAfterPaintEvents() {
893 mInvalidateRequestsSinceLastPaint.mRequests.Clear();
894 mUndeliveredInvalidateRequestsBeforeLastPaint.mRequests.Clear();
895 mAllInvalidated = false;
896 }
897
898 bool IsProcessingRestyles() const {
899 return mProcessingRestyles;
900 }
901
902 void SetProcessingRestyles(bool aProcessing) {
903 NS_ASSERTION(aProcessing != bool(mProcessingRestyles),
904 "should never nest");
905 mProcessingRestyles = aProcessing;
906 }
907
908 bool IsProcessingAnimationStyleChange() const {
909 return mProcessingAnimationStyleChange;
910 }
911
912 void SetProcessingAnimationStyleChange(bool aProcessing) {
913 NS_ASSERTION(aProcessing != bool(mProcessingAnimationStyleChange),
914 "should never nest");
915 mProcessingAnimationStyleChange = aProcessing;
916 }
917
918 /**
919 * Notify the prescontext that the presshell is about to reflow a reflow root.
920 * The single argument indicates whether this reflow should be interruptible.
921 * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
922 * will always return false. If aInterruptible is true then CheckForInterrupt
923 * will return true when a pending event is detected. This is for use by the
924 * presshell only. Reflow code wanting to prevent interrupts should use
925 * InterruptPreventer.
926 */
927 void ReflowStarted(bool aInterruptible);
928
929 /**
930 * A class that can be used to temporarily disable reflow interruption.
931 */
932 class InterruptPreventer;
933 friend class InterruptPreventer;
934 class MOZ_STACK_CLASS InterruptPreventer {
935 public:
936 InterruptPreventer(nsPresContext* aCtx) :
937 mCtx(aCtx),
938 mInterruptsEnabled(aCtx->mInterruptsEnabled),
939 mHasPendingInterrupt(aCtx->mHasPendingInterrupt)
940 {
941 mCtx->mInterruptsEnabled = false;
942 mCtx->mHasPendingInterrupt = false;
943 }
944 ~InterruptPreventer() {
945 mCtx->mInterruptsEnabled = mInterruptsEnabled;
946 mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
947 }
948
949 private:
950 nsPresContext* mCtx;
951 bool mInterruptsEnabled;
952 bool mHasPendingInterrupt;
953 };
954
955 /**
956 * Check for interrupts. This may return true if a pending event is
957 * detected. Once it has returned true, it will keep returning true
958 * until ReflowStarted is called. In all cases where this returns true,
959 * the passed-in frame (which should be the frame whose reflow will be
960 * interrupted if true is returned) will be passed to
961 * nsIPresShell::FrameNeedsToContinueReflow.
962 */
963 bool CheckForInterrupt(nsIFrame* aFrame);
964 /**
965 * Returns true if CheckForInterrupt has returned true since the last
966 * ReflowStarted call. Cannot itself trigger an interrupt check.
967 */
968 bool HasPendingInterrupt() { return mHasPendingInterrupt; }
969
970 /**
971 * If we have a presshell, and if the given content's current
972 * document is the same as our presshell's document, return the
973 * content's primary frame. Otherwise, return null. Only use this
974 * if you care about which presshell the primary frame is in.
975 */
976 nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
977
978 void NotifyDestroyingFrame(nsIFrame* aFrame)
979 {
980 PropertyTable()->DeleteAllFor(aFrame);
981 }
982
983 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
984 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
985 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
986 }
987
988 bool IsRootContentDocument();
989 bool IsCrossProcessRootContentDocument();
990
991 bool IsGlyph() const {
992 return mIsGlyph;
993 }
994
995 void SetIsGlyph(bool aValue) {
996 mIsGlyph = aValue;
997 }
998
999 bool UsesRootEMUnits() const {
1000 return mUsesRootEMUnits;
1001 }
1002
1003 void SetUsesRootEMUnits(bool aValue) {
1004 mUsesRootEMUnits = aValue;
1005 }
1006
1007 bool UsesViewportUnits() const {
1008 return mUsesViewportUnits;
1009 }
1010
1011 void SetUsesViewportUnits(bool aValue) {
1012 mUsesViewportUnits = aValue;
1013 }
1014
1015 // true if there are OMTA transition updates for the current document which
1016 // have been throttled, and therefore some style information may not be up
1017 // to date
1018 bool ExistThrottledUpdates() const {
1019 return mExistThrottledUpdates;
1020 }
1021
1022 void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
1023 mExistThrottledUpdates = aExistThrottledUpdates;
1024 }
1025
1026 bool IsDeviceSizePageSize();
1027
1028 bool HasWarnedAboutPositionedTableParts() const {
1029 return mHasWarnedAboutPositionedTableParts;
1030 }
1031
1032 void SetHasWarnedAboutPositionedTableParts() {
1033 mHasWarnedAboutPositionedTableParts = true;
1034 }
1035
1036 protected:
1037 friend class nsRunnableMethod<nsPresContext>;
1038 NS_HIDDEN_(void) ThemeChangedInternal();
1039 NS_HIDDEN_(void) SysColorChangedInternal();
1040 NS_HIDDEN_(void) UIResolutionChangedInternal();
1041
1042 static NS_HIDDEN_(bool)
1043 UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument, void* aData);
1044
1045 NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, uint16_t aMode);
1046 NS_HIDDEN_(void) SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode,
1047 uint16_t aOldMode);
1048 NS_HIDDEN_(void) GetDocumentColorPreferences();
1049
1050 NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName);
1051 static NS_HIDDEN_(void) PrefChangedCallback(const char*, void*);
1052
1053 NS_HIDDEN_(void) UpdateAfterPreferencesChanged();
1054 static NS_HIDDEN_(void) PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure);
1055
1056 NS_HIDDEN_(void) GetUserPreferences();
1057
1058 // Allow nsAutoPtr<LangGroupFontPrefs> dtor to access this protected struct's
1059 // dtor:
1060 struct LangGroupFontPrefs;
1061 friend class nsAutoPtr<LangGroupFontPrefs>;
1062 struct LangGroupFontPrefs {
1063 // Font sizes default to zero; they will be set in GetFontPreferences
1064 LangGroupFontPrefs()
1065 : mLangGroup(nullptr)
1066 , mMinimumFontSize(0)
1067 , mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
1068 NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0)
1069 , mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL,
1070 NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
1071 NS_FONT_STRETCH_NORMAL, 0, 0)
1072 , mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
1073 NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0)
1074 , mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL,
1075 NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
1076 NS_FONT_STRETCH_NORMAL, 0, 0)
1077 , mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL,
1078 NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
1079 NS_FONT_STRETCH_NORMAL, 0, 0)
1080 , mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL,
1081 NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
1082 NS_FONT_STRETCH_NORMAL, 0, 0)
1083 , mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL,
1084 NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
1085 NS_FONT_STRETCH_NORMAL, 0, 0)
1086 {}
1087
1088 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
1089 size_t n = 0;
1090 LangGroupFontPrefs *curr = mNext;
1091 while (curr) {
1092 n += aMallocSizeOf(curr);
1093
1094 // Measurement of the following members may be added later if DMD finds
1095 // it is worthwhile:
1096 // - mLangGroup
1097 // - mDefault*Font
1098
1099 curr = curr->mNext;
1100 }
1101 return n;
1102 }
1103
1104 nsCOMPtr<nsIAtom> mLangGroup;
1105 nscoord mMinimumFontSize;
1106 nsFont mDefaultVariableFont;
1107 nsFont mDefaultFixedFont;
1108 nsFont mDefaultSerifFont;
1109 nsFont mDefaultSansSerifFont;
1110 nsFont mDefaultMonospaceFont;
1111 nsFont mDefaultCursiveFont;
1112 nsFont mDefaultFantasyFont;
1113 nsAutoPtr<LangGroupFontPrefs> mNext;
1114 };
1115
1116 /**
1117 * Fetch the user's font preferences for the given aLanguage's
1118 * langugage group.
1119 */
1120 const LangGroupFontPrefs* GetFontPrefsForLang(nsIAtom *aLanguage) const;
1121
1122 void ResetCachedFontPrefs() {
1123 // Throw away any other LangGroupFontPrefs objects:
1124 mLangGroupFontPrefs.mNext = nullptr;
1125
1126 // Make GetFontPreferences reinitialize mLangGroupFontPrefs:
1127 mLangGroupFontPrefs.mLangGroup = nullptr;
1128 }
1129
1130 NS_HIDDEN_(void) UpdateCharSet(const nsCString& aCharSet);
1131
1132 public:
1133 void DoChangeCharSet(const nsCString& aCharSet);
1134
1135 /**
1136 * Checks for MozAfterPaint listeners on the document
1137 */
1138 bool MayHavePaintEventListener();
1139
1140 /**
1141 * Checks for MozAfterPaint listeners on the document and
1142 * any subdocuments, except for subdocuments that are non-top-level
1143 * content documents.
1144 */
1145 bool MayHavePaintEventListenerInSubDocument();
1146
1147 protected:
1148 void InvalidateThebesLayers();
1149 void AppUnitsPerDevPixelChanged();
1150
1151 void HandleRebuildUserFontSet() {
1152 mPostedFlushUserFontSet = false;
1153 FlushUserFontSet();
1154 }
1155
1156 bool HavePendingInputEvent();
1157
1158 // Can't be inline because we can't include nsStyleSet.h.
1159 bool HasCachedStyleData();
1160
1161 bool IsChromeSlow() const;
1162
1163 // IMPORTANT: The ownership implicit in the following member variables
1164 // has been explicitly checked. If you add any members to this class,
1165 // please make the ownership explicit (pinkerton, scc).
1166
1167 nsPresContextType mType;
1168 nsIPresShell* mShell; // [WEAK]
1169 nsCOMPtr<nsIDocument> mDocument;
1170 nsRefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
1171 // better safe than sorry.
1172 // Cannot reintroduce cycles
1173 // since there is no dependency
1174 // from gfx back to layout.
1175 nsRefPtr<mozilla::EventStateManager> mEventManager;
1176 nsRefPtr<nsRefreshDriver> mRefreshDriver;
1177 nsRefPtr<nsTransitionManager> mTransitionManager;
1178 nsRefPtr<nsAnimationManager> mAnimationManager;
1179 nsRefPtr<mozilla::RestyleManager> mRestyleManager;
1180 nsIAtom* mMedium; // initialized by subclass ctors;
1181 // weak pointer to static atom
1182 nsCOMPtr<nsIAtom> mMediaEmulated;
1183
1184 nsILinkHandler* mLinkHandler; // [WEAK]
1185
1186 // Formerly mLangGroup; moving from charset-oriented langGroup to
1187 // maintaining actual language settings everywhere (see bug 524107).
1188 // This may in fact hold a langGroup such as x-western rather than
1189 // a specific language, however (e.g, if it is inferred from the
1190 // charset rather than explicitly specified as a lang attribute).
1191 nsCOMPtr<nsIAtom> mLanguage;
1192
1193 public:
1194 // The following are public member variables so that we can use them
1195 // with mozilla::AutoToggle or mozilla::AutoRestore.
1196
1197 // Should we disable font size inflation because we're inside of
1198 // shrink-wrapping calculations on an inflation container?
1199 bool mInflationDisabledForShrinkWrap;
1200
1201 protected:
1202
1203 mozilla::WeakPtr<nsDocShell> mContainer;
1204
1205 PRCList mDOMMediaQueryLists;
1206
1207 // Base minimum font size, independent of the language-specific global preference. Defaults to 0
1208 int32_t mBaseMinFontSize;
1209 float mTextZoom; // Text zoom, defaults to 1.0
1210 float mFullZoom; // Page zoom, defaults to 1.0
1211
1212 float mLastFontInflationScreenWidth;
1213
1214 int32_t mCurAppUnitsPerDevPixel;
1215 int32_t mAutoQualityMinFontSizePixelsPref;
1216
1217 nsCOMPtr<nsITheme> mTheme;
1218 nsCOMPtr<nsILanguageAtomService> mLangService;
1219 nsCOMPtr<nsIPrintSettings> mPrintSettings;
1220 nsCOMPtr<nsITimer> mPrefChangedTimer;
1221
1222 FramePropertyTable mPropertyTable;
1223
1224 nsInvalidateRequestList mInvalidateRequestsSinceLastPaint;
1225 nsInvalidateRequestList mUndeliveredInvalidateRequestsBeforeLastPaint;
1226
1227 // container for per-context fonts (downloadable, SVG, etc.)
1228 nsUserFontSet* mUserFontSet;
1229
1230 // text performance metrics
1231 nsAutoPtr<gfxTextPerfMetrics> mTextPerf;
1232
1233 nsRect mVisibleArea;
1234 nsSize mPageSize;
1235 float mPageScale;
1236 float mPPScale;
1237
1238 nscolor mDefaultColor;
1239 nscolor mBackgroundColor;
1240
1241 nscolor mLinkColor;
1242 nscolor mActiveLinkColor;
1243 nscolor mVisitedLinkColor;
1244
1245 nscolor mFocusBackgroundColor;
1246 nscolor mFocusTextColor;
1247
1248 nscolor mBodyTextColor;
1249
1250 mozilla::ScrollbarStyles mViewportStyleOverflow;
1251 uint8_t mFocusRingWidth;
1252
1253 bool mExistThrottledUpdates;
1254
1255 uint16_t mImageAnimationMode;
1256 uint16_t mImageAnimationModePref;
1257
1258 LangGroupFontPrefs mLangGroupFontPrefs;
1259
1260 nscoord mBorderWidthTable[3];
1261
1262 uint32_t mInterruptChecksToSkip;
1263
1264 mozilla::TimeStamp mReflowStartTime;
1265 PRInt32 mMaxFontAttempts;
1266 PRInt32 mMaxFonts;
1267
1268 // last time animations styles were flushed to their primary frames
1269 mozilla::TimeStamp mLastUpdateThrottledAnimationStyle;
1270 // last time transition styles were flushed to their primary frames
1271 mozilla::TimeStamp mLastUpdateThrottledTransitionStyle;
1272 // last time we did a full style flush
1273 mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
1274
1275 unsigned mHasPendingInterrupt : 1;
1276 unsigned mInterruptsEnabled : 1;
1277 unsigned mUseDocumentFonts : 1;
1278 unsigned mUseDocumentColors : 1;
1279 unsigned mUnderlineLinks : 1;
1280 unsigned mSendAfterPaintToContent : 1;
1281 unsigned mUseFocusColors : 1;
1282 unsigned mFocusRingOnAnything : 1;
1283 unsigned mFocusRingStyle : 1;
1284 unsigned mDrawImageBackground : 1;
1285 unsigned mDrawColorBackground : 1;
1286 unsigned mNeverAnimate : 1;
1287 unsigned mIsRenderingOnlySelection : 1;
1288 unsigned mPaginated : 1;
1289 unsigned mCanPaginatedScroll : 1;
1290 unsigned mDoScaledTwips : 1;
1291 unsigned mIsRootPaginatedDocument : 1;
1292 unsigned mPrefBidiDirection : 1;
1293 unsigned mPrefScrollbarSide : 2;
1294 unsigned mPendingSysColorChanged : 1;
1295 unsigned mPendingThemeChanged : 1;
1296 unsigned mPendingUIResolutionChanged : 1;
1297 unsigned mPendingMediaFeatureValuesChanged : 1;
1298 unsigned mPrefChangePendingNeedsReflow : 1;
1299 unsigned mIsEmulatingMedia : 1;
1300 // True if the requests in mInvalidateRequestsSinceLastPaint cover the
1301 // entire viewport
1302 unsigned mAllInvalidated : 1;
1303
1304 // Are we currently drawing an SVG glyph?
1305 unsigned mIsGlyph : 1;
1306
1307 // Does the associated document use root-em (rem) units?
1308 unsigned mUsesRootEMUnits : 1;
1309 // Does the associated document use viewport units (vw/vh/vmin/vmax)?
1310 unsigned mUsesViewportUnits : 1;
1311
1312 // Has there been a change to the viewport's dimensions?
1313 unsigned mPendingViewportChange : 1;
1314
1315 // Is the current mUserFontSet valid?
1316 unsigned mUserFontSetDirty : 1;
1317 // Has GetUserFontSet() been called?
1318 unsigned mGetUserFontSetCalled : 1;
1319 // Do we currently have an event posted to call FlushUserFontSet?
1320 unsigned mPostedFlushUserFontSet : 1;
1321
1322 // resize reflow is suppressed when the only change has been to zoom
1323 // the document rather than to change the document's dimensions
1324 unsigned mSupressResizeReflow : 1;
1325
1326 unsigned mIsVisual : 1;
1327
1328 unsigned mProcessingRestyles : 1;
1329 unsigned mProcessingAnimationStyleChange : 1;
1330
1331 unsigned mFireAfterPaintEvents : 1;
1332
1333 unsigned mIsChrome : 1;
1334 unsigned mIsChromeOriginImage : 1;
1335
1336 // Should we paint flash in this context? Do not use this variable directly.
1337 // Use GetPaintFlashing() method instead.
1338 mutable unsigned mPaintFlashing : 1;
1339 mutable unsigned mPaintFlashingInitialized : 1;
1340
1341 unsigned mHasWarnedAboutPositionedTableParts : 1;
1342
1343 #ifdef DEBUG
1344 bool mInitialized;
1345 #endif
1346
1347
1348 protected:
1349
1350 virtual ~nsPresContext() NS_HIDDEN;
1351
1352 // these are private, use the list in nsFont.h if you want a public list
1353 enum {
1354 eDefaultFont_Variable,
1355 eDefaultFont_Fixed,
1356 eDefaultFont_Serif,
1357 eDefaultFont_SansSerif,
1358 eDefaultFont_Monospace,
1359 eDefaultFont_Cursive,
1360 eDefaultFont_Fantasy,
1361 eDefaultFont_COUNT
1362 };
1363
1364 nscolor MakeColorPref(const nsString& aColor);
1365
1366 void LastRelease();
1367
1368 #ifdef DEBUG
1369 private:
1370 friend struct nsAutoLayoutPhase;
1371 uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT];
1372 public:
1373 uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
1374 return mLayoutPhaseCount[aPhase];
1375 }
1376 #endif
1377
1378 };
1379
1380 class nsRootPresContext MOZ_FINAL : public nsPresContext {
1381 public:
1382 nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN;
1383 virtual ~nsRootPresContext();
1384 virtual void Detach() MOZ_OVERRIDE;
1385
1386 /**
1387 * Ensure that NotifyDidPaintForSubtree is eventually called on this
1388 * object after a timeout.
1389 */
1390 void EnsureEventualDidPaintEvent();
1391
1392 void CancelDidPaintTimer()
1393 {
1394 if (mNotifyDidPaintTimer) {
1395 mNotifyDidPaintTimer->Cancel();
1396 mNotifyDidPaintTimer = nullptr;
1397 }
1398 }
1399
1400 /**
1401 * Registers a plugin to receive geometry updates (position and clip
1402 * region) so it can update its widget.
1403 * Callers must call UnregisterPluginForGeometryUpdates before
1404 * the aPlugin frame is destroyed.
1405 */
1406 void RegisterPluginForGeometryUpdates(nsIContent* aPlugin);
1407 /**
1408 * Stops a plugin receiving geometry updates (position and clip
1409 * region). If the plugin was not already registered, this does
1410 * nothing.
1411 */
1412 void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin);
1413
1414 bool NeedToComputePluginGeometryUpdates()
1415 {
1416 return mRegisteredPlugins.Count() > 0;
1417 }
1418 /**
1419 * Compute geometry updates for each plugin given that aList is the display
1420 * list for aFrame. The updates are not yet applied;
1421 * ApplyPluginGeometryUpdates is responsible for that. In the meantime they
1422 * are stored on each nsObjectFrame.
1423 * This needs to be called even when aFrame is a popup, since although
1424 * windowed plugins aren't allowed in popups, windowless plugins are
1425 * and ComputePluginGeometryUpdates needs to be called for them.
1426 */
1427 void ComputePluginGeometryUpdates(nsIFrame* aFrame,
1428 nsDisplayListBuilder* aBuilder,
1429 nsDisplayList* aList);
1430
1431 /**
1432 * Apply the stored plugin geometry updates. This should normally be called
1433 * in DidPaint so the plugins are moved/clipped immediately after we've
1434 * updated our window, so they look in sync with our window.
1435 */
1436 void ApplyPluginGeometryUpdates();
1437
1438 virtual bool IsRoot() MOZ_OVERRIDE { return true; }
1439
1440 /**
1441 * Increment DOM-modification generation counter to indicate that
1442 * the DOM has changed in a way that might lead to style changes/
1443 * reflows/frame creation and destruction.
1444 */
1445 void IncrementDOMGeneration() { mDOMGeneration++; }
1446
1447 /**
1448 * Get the current DOM generation counter.
1449 *
1450 * See nsFrameManagerBase::GetGlobalGenerationNumber() for a
1451 * global generation number.
1452 */
1453 uint32_t GetDOMGeneration() { return mDOMGeneration; }
1454
1455 /**
1456 * Add a runnable that will get called before the next paint. They will get
1457 * run eventually even if painting doesn't happen. They might run well before
1458 * painting happens.
1459 */
1460 void AddWillPaintObserver(nsIRunnable* aRunnable);
1461
1462 /**
1463 * Run all runnables that need to get called before the next paint.
1464 */
1465 void FlushWillPaintObservers();
1466
1467 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
1468
1469 protected:
1470 /**
1471 * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates.
1472 */
1473 void InitApplyPluginGeometryTimer();
1474 /**
1475 * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates.
1476 */
1477 void CancelApplyPluginGeometryTimer();
1478
1479 class RunWillPaintObservers : public nsRunnable {
1480 public:
1481 RunWillPaintObservers(nsRootPresContext* aPresContext) : mPresContext(aPresContext) {}
1482 void Revoke() { mPresContext = nullptr; }
1483 NS_IMETHOD Run() MOZ_OVERRIDE
1484 {
1485 if (mPresContext) {
1486 mPresContext->FlushWillPaintObservers();
1487 }
1488 return NS_OK;
1489 }
1490 nsRootPresContext* mPresContext;
1491 };
1492
1493 friend class nsPresContext;
1494
1495 nsCOMPtr<nsITimer> mNotifyDidPaintTimer;
1496 nsCOMPtr<nsITimer> mApplyPluginGeometryTimer;
1497 nsTHashtable<nsRefPtrHashKey<nsIContent> > mRegisteredPlugins;
1498 nsTArray<nsCOMPtr<nsIRunnable> > mWillPaintObservers;
1499 nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
1500 uint32_t mDOMGeneration;
1501 };
1502
1503 #ifdef MOZ_REFLOW_PERF
1504
1505 #define DO_GLOBAL_REFLOW_COUNT(_name) \
1506 aPresContext->CountReflows((_name), (nsIFrame*)this);
1507 #else
1508 #define DO_GLOBAL_REFLOW_COUNT(_name)
1509 #endif // MOZ_REFLOW_PERF
1510
1511 #endif /* nsPresContext_h___ */

mercurial