1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 /* a presentation of a document, part 1 */
41 #ifndef nsPresContext_h___
42 #define nsPresContext_h___
44 #include "nsISupports.h"
47 #include "nsAString.h"
49 #include "nsIPresShell.h"
51 #include "nsIDeviceContext.h"
53 #include "nsIWeakReference.h"
55 #include "nsILanguageAtomService.h"
56 #include "nsIObserver.h"
59 #include "nsIPrintSettings.h"
60 #include "nsPropertyTable.h"
61 #include "nsGkAtoms.h"
62 #include "nsIDocument.h"
63 #include "nsInterfaceHashtable.h"
64 #include "nsCycleCollectionParticipant.h"
65 #include "nsChangeHint.h"
66 // This also pulls in gfxTypes.h, which we cannot include directly.
70 #include "nsAutoPtr.h"
74 class nsBidiPresUtils
;
89 class nsIEventStateManager
;
92 class nsICSSPseudoComparator
;
94 struct nsStyleBackground
;
95 template <class T
> class nsRunnableMethod
;
98 struct nsFontFaceRuleContainer
;
100 #ifdef MOZ_REFLOW_PERF
101 class nsIRenderingContext
;
105 eWidgetType_Button
= 1,
106 eWidgetType_Checkbox
= 2,
107 eWidgetType_Radio
= 3,
111 enum nsLanguageSpecificTransformType
{
112 eLanguageSpecificTransformType_Unknown
= -1,
113 eLanguageSpecificTransformType_None
= 0,
114 eLanguageSpecificTransformType_Japanese
117 // supported values for cached bool types
118 enum nsPresContext_CachedBoolPrefType
{
119 kPresContext_UseDocumentColors
= 1,
120 kPresContext_UseDocumentFonts
,
121 kPresContext_UnderlineLinks
124 // supported values for cached integer pref types
125 enum nsPresContext_CachedIntPrefType
{
126 kPresContext_MinimumFontSize
= 1,
127 kPresContext_ScrollbarSide
,
128 kPresContext_BidiDirection
131 // IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
132 // To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
133 const PRUint8 kPresContext_DefaultVariableFont_ID
= 0x00; // kGenericFont_moz_variable
134 const PRUint8 kPresContext_DefaultFixedFont_ID
= 0x01; // kGenericFont_moz_fixed
137 struct nsAutoLayoutPhase
;
147 /* Used by nsPresContext::HasAuthorSpecifiedRules */
148 #define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
149 #define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
150 #define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
152 // An interface for presentation contexts. Presentation contexts are
153 // objects that provide an outer context for a presentation shell.
155 class nsPresContext
: public nsIObserver
{
157 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
159 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
160 NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext
)
162 enum nsPresContextType
{
163 eContext_Galley
, // unpaginated screen presentation
164 eContext_PrintPreview
, // paginated screen presentation
165 eContext_Print
, // paginated printer presentation
166 eContext_PageLayout
// paginated & editable.
169 nsPresContext(nsIDocument
* aDocument
, nsPresContextType aType
) NS_HIDDEN
;
172 * Initialize the presentation context from a particular device.
174 NS_HIDDEN_(nsresult
) Init(nsIDeviceContext
* aDeviceContext
);
177 * Set the presentation shell that this context is bound to.
178 * A presentation context may only be bound to a single shell.
180 NS_HIDDEN_(void) SetShell(nsIPresShell
* aShell
);
183 NS_HIDDEN_(nsPresContextType
) Type() const { return mType
; }
186 * Get the PresentationShell that this context is bound to.
188 nsIPresShell
* PresShell() const
190 NS_ASSERTION(mShell
, "Null pres shell");
194 nsIPresShell
* GetPresShell() const { return mShell
; }
196 // Find the prescontext for the root of the view manager hierarchy that contains
198 nsPresContext
* RootPresContext();
200 nsIDocument
* Document() const
202 NS_ASSERTION(!mShell
|| !mShell
->GetDocument() ||
203 mShell
->GetDocument() == mDocument
,
204 "nsPresContext doesn't have the same document as nsPresShell!");
208 nsIViewManager
* GetViewManager() { return GetPresShell()->GetViewManager(); }
209 #ifdef _IMPL_NS_LAYOUT
210 nsStyleSet
* StyleSet() { return GetPresShell()->StyleSet(); }
212 nsFrameManager
* FrameManager()
213 { return GetPresShell()->FrameManager(); }
217 * Rebuilds all style data by throwing out the old rule tree and
218 * building a new one, and additionally applying aExtraHint (which
219 * must not contain nsChangeHint_ReconstructFrame) to the root frame.
220 * Also rebuild the user font set.
222 void RebuildAllStyleData(nsChangeHint aExtraHint
);
224 * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
225 * doesn't rebuild the user font set.
227 void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint
);
229 void MediaFeatureValuesChanged(PRBool aCallerWillRebuildStyleData
);
230 void PostMediaFeatureValuesChangedEvent();
231 NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent();
232 void FlushPendingMediaFeatureValuesChanged() {
233 if (mPendingMediaFeatureValuesChanged
)
234 MediaFeatureValuesChanged(PR_FALSE
);
238 * Access compatibility mode for this context. This is the same as
239 * our document's compatibility mode.
241 nsCompatibility
CompatibilityMode() const {
242 return Document()->GetCompatibilityMode();
245 * Notify the context that the document's compatibility mode has changed
247 NS_HIDDEN_(void) CompatibilityModeChanged();
250 * Access the image animation mode for this context
252 PRUint16
ImageAnimationMode() const { return mImageAnimationMode
; }
253 void RestoreImageAnimationMode() { SetImageAnimationMode(mImageAnimationModePref
); }
254 virtual NS_HIDDEN_(void) SetImageAnimationModeExternal(PRUint16 aMode
);
255 NS_HIDDEN_(void) SetImageAnimationModeInternal(PRUint16 aMode
);
256 #ifdef _IMPL_NS_LAYOUT
257 void SetImageAnimationMode(PRUint16 aMode
)
258 { SetImageAnimationModeInternal(aMode
); }
260 void SetImageAnimationMode(PRUint16 aMode
)
261 { SetImageAnimationModeExternal(aMode
); }
265 * Get cached look and feel service. This is faster than obtaining it
266 * through the service manager.
268 nsILookAndFeel
* LookAndFeel() { return mLookAndFeel
; }
271 * Get medium of presentation
273 nsIAtom
* Medium() { return mMedium
; }
275 void* AllocateFromShell(size_t aSize
)
278 return mShell
->AllocateFrame(aSize
);
282 void FreeToShell(size_t aSize
, void* aFreeChunk
)
285 mShell
->FreeFrame(aSize
, aFreeChunk
);
289 * Get the font metrics for a given font.
291 NS_HIDDEN_(already_AddRefed
<nsIFontMetrics
>)
292 GetMetricsFor(const nsFont
& aFont
);
295 * Get the default font corresponding to the given ID. This object is
296 * read-only, you must copy the font to modify it.
298 * When aFontID is kPresContext_DefaultVariableFontID or
299 * kPresContext_DefaultFixedFontID (which equals
300 * kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
301 * the nsFont returned has its name as a CSS generic family (serif or
302 * sans-serif for the former, monospace for the latter), and its size
303 * as the default font size for variable or fixed fonts for the pres
304 * context's language group.
306 * For aFontID corresponds to a CSS Generic, the nsFont returned has
307 * its name as the name or names of the fonts in the user's
308 * preferences for the given generic and the pres context's language
309 * group, and its size set to the default variable font size.
311 NS_HIDDEN_(const nsFont
*) GetDefaultFont(PRUint8 aFontID
) const;
313 /** Get a cached boolean pref, by its type */
314 // * - initially created for bugs 31816, 20760, 22963
315 PRBool
GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType
) const
317 // If called with a constant parameter, the compiler should optimize
318 // this switch statement away.
320 case kPresContext_UseDocumentFonts
:
321 return mUseDocumentFonts
;
322 case kPresContext_UseDocumentColors
:
323 return mUseDocumentColors
;
324 case kPresContext_UnderlineLinks
:
325 return mUnderlineLinks
;
327 NS_ERROR("Invalid arg passed to GetCachedBoolPref");
333 /** Get a cached integer pref, by its type */
334 // * - initially created for bugs 30910, 61883, 74186, 84398
335 PRInt32
GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType
) const
337 // If called with a constant parameter, the compiler should optimize
338 // this switch statement away.
340 case kPresContext_MinimumFontSize
:
341 return mMinimumFontSize
;
342 case kPresContext_ScrollbarSide
:
343 return mPrefScrollbarSide
;
344 case kPresContext_BidiDirection
:
345 return mPrefBidiDirection
;
347 NS_ERROR("invalid arg passed to GetCachedIntPref");
354 * Access Nav's magic font scaler value
356 PRInt32
FontScaler() const { return mFontScaler
; }
359 * Get the default colors
361 const nscolor
DefaultColor() const { return mDefaultColor
; }
362 const nscolor
DefaultBackgroundColor() const { return mBackgroundColor
; }
363 const nscolor
DefaultLinkColor() const { return mLinkColor
; }
364 const nscolor
DefaultActiveLinkColor() const { return mActiveLinkColor
; }
365 const nscolor
DefaultVisitedLinkColor() const { return mVisitedLinkColor
; }
366 const nscolor
FocusBackgroundColor() const { return mFocusBackgroundColor
; }
367 const nscolor
FocusTextColor() const { return mFocusTextColor
; }
369 PRBool
GetUseFocusColors() const { return mUseFocusColors
; }
370 PRUint8
FocusRingWidth() const { return mFocusRingWidth
; }
371 PRBool
GetFocusRingOnAnything() const { return mFocusRingOnAnything
; }
372 PRUint8
GetFocusRingStyle() const { return mFocusRingStyle
; }
376 * Set up observers so that aTargetFrame will be invalidated when
377 * aImage loads, where aImage is its background image. Only a single
378 * image will be tracked per frame.
380 NS_HIDDEN_(imgIRequest
*) LoadImage(imgIRequest
* aImage
,
381 nsIFrame
* aTargetFrame
);
383 * Set up observers so that aTargetFrame will be invalidated or
384 * reflowed (as appropriate) when aImage loads, where aImage is its
385 * *border* image. Only a single image will be tracked per frame.
387 NS_HIDDEN_(imgIRequest
*) LoadBorderImage(imgIRequest
* aImage
,
388 nsIFrame
* aTargetFrame
);
391 typedef nsInterfaceHashtable
<nsVoidPtrHashKey
, nsImageLoader
> ImageLoaderTable
;
393 NS_HIDDEN_(imgIRequest
*) DoLoadImage(ImageLoaderTable
& aTable
,
395 nsIFrame
* aTargetFrame
,
396 PRBool aReflowOnLoad
);
398 NS_HIDDEN_(void) DoStopImageFor(ImageLoaderTable
& aTable
,
399 nsIFrame
* aTargetFrame
);
402 NS_HIDDEN_(void) StopBackgroundImageFor(nsIFrame
* aTargetFrame
)
403 { DoStopImageFor(mImageLoaders
, aTargetFrame
); }
404 NS_HIDDEN_(void) StopBorderImageFor(nsIFrame
* aTargetFrame
)
405 { DoStopImageFor(mBorderImageLoaders
, aTargetFrame
); }
407 * This method is called when a frame is being destroyed to
408 * ensure that the image load gets disassociated from the prescontext
410 NS_HIDDEN_(void) StopImagesFor(nsIFrame
* aTargetFrame
);
412 NS_HIDDEN_(void) SetContainer(nsISupports
* aContainer
);
414 virtual NS_HIDDEN_(already_AddRefed
<nsISupports
>) GetContainerExternal() const;
415 NS_HIDDEN_(already_AddRefed
<nsISupports
>) GetContainerInternal() const;
416 #ifdef _IMPL_NS_LAYOUT
417 already_AddRefed
<nsISupports
> GetContainer() const
418 { return GetContainerInternal(); }
420 already_AddRefed
<nsISupports
> GetContainer() const
421 { return GetContainerExternal(); }
424 // XXX this are going to be replaced with set/get container
425 void SetLinkHandler(nsILinkHandler
* aHandler
) { mLinkHandler
= aHandler
; }
426 nsILinkHandler
* GetLinkHandler() { return mLinkHandler
; }
429 * Get the visible area associated with this presentation context.
430 * This is the size of the visible area that is used for
431 * presenting the document. The returned value is in the standard
432 * nscoord units (as scaled by the device context).
434 nsRect
GetVisibleArea() { return mVisibleArea
; }
437 * Set the currently visible area. The units for r are standard
438 * nscoord units (as scaled by the device context).
440 void SetVisibleArea(const nsRect
& r
) {
442 PostMediaFeatureValuesChangedEvent();
446 * Return true if this presentation context is a paginated
449 PRBool
IsPaginated() const { return mPaginated
; }
451 PRBool
GetRenderedPositionVaryingContent() const { return mRenderedPositionVaryingContent
; }
452 void SetRenderedPositionVaryingContent() { mRenderedPositionVaryingContent
= PR_TRUE
; }
455 * Sets whether the presentation context can scroll for a paginated
458 NS_HIDDEN_(void) SetPaginatedScrolling(PRBool aResult
);
461 * Return true if this presentation context can scroll for paginated
464 PRBool
HasPaginatedScrolling() const { return mCanPaginatedScroll
; }
467 * Get/set the size of a page
469 nsSize
GetPageSize() { return mPageSize
; }
470 void SetPageSize(nsSize aSize
) { mPageSize
= aSize
; }
473 * Get/set whether this document should be treated as having real pages
474 * XXX This raises the obvious question of why a document that isn't a page
475 * is paginated; there isn't a good reason except history
477 PRBool
IsRootPaginatedDocument() { return mIsRootPaginatedDocument
; }
478 void SetIsRootPaginatedDocument(PRBool aIsRootPaginatedDocument
)
479 { mIsRootPaginatedDocument
= aIsRootPaginatedDocument
; }
482 * Get/set the print scaling level; used by nsPageFrame to scale up
483 * pages. Set safe to call before reflow, get guaranteed to be set
484 * properly after reflow.
487 float GetPageScale() { return mPageScale
; }
488 void SetPageScale(float aScale
) { mPageScale
= aScale
; }
491 * Get/set the scaling facor to use when rendering the pages for print preview.
492 * Only safe to get after print preview set up; safe to set anytime.
493 * This is a scaling factor for the display of the print preview. It
494 * does not affect layout. It only affects the size of the onscreen pages
496 * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
498 float GetPrintPreviewScale() { return mPPScale
; }
499 void SetPrintPreviewScale(float aScale
) { mPPScale
= aScale
; }
501 nsIDeviceContext
* DeviceContext() { return mDeviceContext
; }
502 nsIEventStateManager
* EventStateManager() { return mEventManager
; }
503 nsIAtom
* GetLangGroup() { return mLangGroup
; }
505 float TextZoom() { return mTextZoom
; }
506 void SetTextZoom(float aZoom
) {
508 RebuildAllStyleData(NS_STYLE_HINT_REFLOW
);
511 float GetFullZoom() { return mFullZoom
; }
512 void SetFullZoom(float aZoom
);
514 nscoord
GetAutoQualityMinFontSize() {
515 return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref
);
518 static PRInt32
AppUnitsPerCSSPixel() { return nsIDeviceContext::AppUnitsPerCSSPixel(); }
519 PRInt32
AppUnitsPerDevPixel() const { return mDeviceContext
->AppUnitsPerDevPixel(); }
520 PRInt32
AppUnitsPerInch() const { return mDeviceContext
->AppUnitsPerInch(); }
522 static nscoord
CSSPixelsToAppUnits(PRInt32 aPixels
)
523 { return NSIntPixelsToAppUnits(aPixels
,
524 nsIDeviceContext::AppUnitsPerCSSPixel()); }
526 static nscoord
CSSPixelsToAppUnits(float aPixels
)
527 { return NSFloatPixelsToAppUnits(aPixels
,
528 float(nsIDeviceContext::AppUnitsPerCSSPixel())); }
530 static PRInt32
AppUnitsToIntCSSPixels(nscoord aAppUnits
)
531 { return NSAppUnitsToIntPixels(aAppUnits
,
532 float(nsIDeviceContext::AppUnitsPerCSSPixel())); }
534 static float AppUnitsToFloatCSSPixels(nscoord aAppUnits
)
535 { return NSAppUnitsToFloatPixels(aAppUnits
,
536 float(nsIDeviceContext::AppUnitsPerCSSPixel())); }
538 nscoord
DevPixelsToAppUnits(PRInt32 aPixels
) const
539 { return NSIntPixelsToAppUnits(aPixels
,
540 mDeviceContext
->AppUnitsPerDevPixel()); }
542 PRInt32
AppUnitsToDevPixels(nscoord aAppUnits
) const
543 { return NSAppUnitsToIntPixels(aAppUnits
,
544 float(mDeviceContext
->AppUnitsPerDevPixel())); }
546 // If there is a remainder, it is rounded to nearest app units.
547 nscoord
GfxUnitsToAppUnits(gfxFloat aGfxUnits
) const
548 { return mDeviceContext
->GfxUnitsToAppUnits(aGfxUnits
); }
550 gfxFloat
AppUnitsToGfxUnits(nscoord aAppUnits
) const
551 { return mDeviceContext
->AppUnitsToGfxUnits(aAppUnits
); }
553 gfxRect
AppUnitsToGfxUnits(const nsRect
& aAppRect
) const
554 { return gfxRect(AppUnitsToGfxUnits(aAppRect
.x
),
555 AppUnitsToGfxUnits(aAppRect
.y
),
556 AppUnitsToGfxUnits(aAppRect
.width
),
557 AppUnitsToGfxUnits(aAppRect
.height
)); }
559 nscoord
TwipsToAppUnits(PRInt32 aTwips
) const
560 { return NSToCoordRound(NS_TWIPS_TO_INCHES(aTwips
) *
561 mDeviceContext
->AppUnitsPerInch()); }
563 // Margin-specific version, since they often need TwipsToAppUnits
564 nsMargin
TwipsToAppUnits(const nsMargin
&marginInTwips
) const
565 { return nsMargin(TwipsToAppUnits(marginInTwips
.left
),
566 TwipsToAppUnits(marginInTwips
.top
),
567 TwipsToAppUnits(marginInTwips
.right
),
568 TwipsToAppUnits(marginInTwips
.bottom
)); }
570 nscoord
PointsToAppUnits(float aPoints
) const
571 { return NSToCoordRound(aPoints
* mDeviceContext
->AppUnitsPerInch() /
572 POINTS_PER_INCH_FLOAT
); }
574 nscoord
RoundAppUnitsToNearestDevPixels(nscoord aAppUnits
) const
575 { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits
)); }
577 struct ScrollbarStyles
{
578 // Always one of NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
579 // or NS_STYLE_OVERFLOW_AUTO.
580 PRUint8 mHorizontal
, mVertical
;
581 ScrollbarStyles(PRUint8 h
, PRUint8 v
) : mHorizontal(h
), mVertical(v
) {}
584 void SetViewportOverflowOverride(PRUint8 aX
, PRUint8 aY
)
586 mViewportStyleOverflow
.mHorizontal
= aX
;
587 mViewportStyleOverflow
.mVertical
= aY
;
589 ScrollbarStyles
GetViewportOverflowOverride()
591 return mViewportStyleOverflow
;
595 * Set and get methods for controlling the background drawing
597 PRBool
GetBackgroundImageDraw() const { return mDrawImageBackground
; }
598 void SetBackgroundImageDraw(PRBool aCanDraw
)
600 NS_ASSERTION(!(aCanDraw
& ~1), "Value must be true or false");
601 mDrawImageBackground
= aCanDraw
;
604 PRBool
GetBackgroundColorDraw() const { return mDrawColorBackground
; }
605 void SetBackgroundColorDraw(PRBool aCanDraw
)
607 NS_ASSERTION(!(aCanDraw
& ~1), "Value must be true or false");
608 mDrawColorBackground
= aCanDraw
;
613 * Check if bidi enabled (set depending on the presence of RTL
614 * characters or when default directionality is RTL).
615 * If enabled, we should apply the Unicode Bidi Algorithm
619 virtual NS_HIDDEN_(PRBool
) BidiEnabledExternal() const;
620 NS_HIDDEN_(PRBool
) BidiEnabledInternal() const;
621 #ifdef _IMPL_NS_LAYOUT
622 PRBool
BidiEnabled() const { return BidiEnabledInternal(); }
624 PRBool
BidiEnabled() const { return BidiEnabledExternal(); }
628 * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
632 NS_HIDDEN_(void) SetBidiEnabled() const;
635 * Set visual or implicit mode into the pres context.
637 * Visual directionality is a presentation method that displays text
638 * as if it were a uni-directional, according to the primary display
641 * Implicit directionality is a presentation method in which the
642 * direction is determined by the Bidi algorithm according to the
643 * category of the characters and the category of the adjacent
644 * characters, and according to their primary direction.
648 void SetVisualMode(PRBool aIsVisual
)
650 NS_ASSERTION(!(aIsVisual
& ~1), "Value must be true or false");
651 mIsVisual
= aIsVisual
;
655 * Check whether the content should be treated as visual.
659 PRBool
IsVisualMode() const { return mIsVisual
; }
664 * Get a Bidi presentation utilities object
666 NS_HIDDEN_(nsBidiPresUtils
*) GetBidiUtils();
669 * Set the Bidi options for the presentation context
671 NS_HIDDEN_(void) SetBidi(PRUint32 aBidiOptions
,
672 PRBool aForceRestyle
= PR_FALSE
);
675 * Get the Bidi options for the presentation context
676 * Not inline so consumers of nsPresContext are not forced to
677 * include nsIDocument.
679 NS_HIDDEN_(PRUint32
) GetBidi() const;
683 * Render only Selection
685 void SetIsRenderingOnlySelection(PRBool aResult
)
687 NS_ASSERTION(!(aResult
& ~1), "Value must be true or false");
688 mIsRenderingOnlySelection
= aResult
;
691 PRBool
IsRenderingOnlySelection() const { return mIsRenderingOnlySelection
; }
694 * Obtain a native them for rendering our widgets (both form controls and html)
696 NS_HIDDEN_(nsITheme
*) GetTheme();
699 * Notify the pres context that the theme has changed. An internal switch
700 * means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
701 * Otherwise, the OS is telling us that the native theme for the platform
704 NS_HIDDEN_(void) ThemeChanged();
707 * Notify the pres context that a system color has changed
709 NS_HIDDEN_(void) SysColorChanged();
711 /** Printing methods below should only be used for Medium() == print **/
712 NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings
*aPrintSettings
);
714 nsIPrintSettings
* GetPrintSettings() { return mPrintSettings
; }
716 /* Accessor for table of frame properties */
717 nsPropertyTable
* PropertyTable() { return &mPropertyTable
; }
719 /* Helper function that ensures that this prescontext is shown in its
720 docshell if it's the most recent prescontext for the docshell. Returns
721 whether the prescontext is now being shown.
723 @param aUnsuppressFocus If this is false, then focus will not be
724 unsuppressed when PR_TRUE is returned. It's the caller's responsibility
725 to unsuppress focus in that case.
727 NS_HIDDEN_(PRBool
) EnsureVisible(PRBool aUnsuppressFocus
);
729 #ifdef MOZ_REFLOW_PERF
730 NS_HIDDEN_(void) CountReflows(const char * aName
,
735 * This table maps border-width enums 'thin', 'medium', 'thick'
736 * to actual nscoord values.
738 const nscoord
* GetBorderWidthTable() { return mBorderWidthTable
; }
740 PRBool
IsDynamic() { return (mType
== eContext_PageLayout
|| mType
== eContext_Galley
); }
741 PRBool
IsScreen() { return (mMedium
== nsGkAtoms::screen
||
742 mType
== eContext_PageLayout
||
743 mType
== eContext_PrintPreview
); }
745 // Is this presentation in a chrome docshell?
746 PRBool
IsChrome() const;
748 // Public API for native theme code to get style internals.
749 virtual PRBool
HasAuthorSpecifiedRules(nsIFrame
*aFrame
, PRUint32 ruleTypeMask
) const;
751 // Is it OK to let the page specify colors and backgrounds?
752 PRBool
UseDocumentColors() const {
753 return GetCachedBoolPref(kPresContext_UseDocumentColors
) || IsChrome();
756 PRBool
SupressingResizeReflow() const { return mSupressResizeReflow
; }
758 virtual NS_HIDDEN_(gfxUserFontSet
*) GetUserFontSetExternal();
759 NS_HIDDEN_(gfxUserFontSet
*) GetUserFontSetInternal();
760 #ifdef _IMPL_NS_LAYOUT
761 gfxUserFontSet
* GetUserFontSet() { return GetUserFontSetInternal(); }
763 gfxUserFontSet
* GetUserFontSet() { return GetUserFontSetExternal(); }
766 void FlushUserFontSet();
767 void RebuildUserFontSet(); // asynchronously
769 // Should be called whenever the set of fonts available in the user
770 // font set changes (e.g., because a new font loads, or because the
771 // user font set is changed and fonts become unavailable).
772 void UserFontSetUpdated();
774 void NotifyInvalidation(const nsRect
& aRect
, PRBool aIsCrossDoc
);
775 void FireDOMPaintEvent();
778 friend class nsRunnableMethod
<nsPresContext
>;
779 NS_HIDDEN_(void) ThemeChangedInternal();
780 NS_HIDDEN_(void) SysColorChangedInternal();
782 NS_HIDDEN_(void) SetImgAnimations(nsIContent
*aParent
, PRUint16 aMode
);
783 NS_HIDDEN_(void) GetDocumentColorPreferences();
785 NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName
);
786 static NS_HIDDEN_(int) PrefChangedCallback(const char*, void*);
788 NS_HIDDEN_(void) UpdateAfterPreferencesChanged();
789 static NS_HIDDEN_(void) PrefChangedUpdateTimerCallback(nsITimer
*aTimer
, void *aClosure
);
791 NS_HIDDEN_(void) GetUserPreferences();
792 NS_HIDDEN_(void) GetFontPreferences();
794 NS_HIDDEN_(void) UpdateCharSet(const nsAFlatCString
& aCharSet
);
796 void HandleRebuildUserFontSet() {
797 mPostedFlushUserFontSet
= PR_FALSE
;
801 // IMPORTANT: The ownership implicit in the following member variables
802 // has been explicitly checked. If you add any members to this class,
803 // please make the ownership explicit (pinkerton, scc).
805 nsPresContextType mType
;
806 nsIPresShell
* mShell
; // [WEAK]
807 nsCOMPtr
<nsIDocument
> mDocument
;
808 nsIDeviceContext
* mDeviceContext
; // [STRONG] could be weak, but
809 // better safe than sorry.
810 // Cannot reintroduce cycles
811 // since there is no dependency
812 // from gfx back to layout.
813 nsIEventStateManager
* mEventManager
; // [STRONG]
814 nsILookAndFeel
* mLookAndFeel
; // [STRONG]
815 nsIAtom
* mMedium
; // initialized by subclass ctors;
816 // weak pointer to static atom
818 nsILinkHandler
* mLinkHandler
; // [WEAK]
819 nsIAtom
* mLangGroup
; // [STRONG]
821 ImageLoaderTable mImageLoaders
;
822 ImageLoaderTable mBorderImageLoaders
;
823 nsWeakPtr mContainer
;
825 float mTextZoom
; // Text zoom, defaults to 1.0
826 float mFullZoom
; // Page zoom, defaults to 1.0
828 PRInt32 mCurAppUnitsPerDevPixel
;
829 PRInt32 mAutoQualityMinFontSizePixelsPref
;
832 nsBidiPresUtils
* mBidiUtils
;
835 nsCOMPtr
<nsITheme
> mTheme
;
836 nsCOMPtr
<nsILanguageAtomService
> mLangService
;
837 nsCOMPtr
<nsIPrintSettings
> mPrintSettings
;
838 nsCOMPtr
<nsITimer
> mPrefChangedTimer
;
840 nsPropertyTable mPropertyTable
;
842 nsRegion mSameDocDirtyRegion
;
843 nsRegion mCrossDocDirtyRegion
;
845 // container for per-context fonts (downloadable, SVG, etc.)
846 gfxUserFontSet
* mUserFontSet
;
847 // The list of @font-face rules that we put into mUserFontSet
848 nsTArray
<nsFontFaceRuleContainer
> mFontFaceRules
;
851 nscoord mMinimumFontSize
;
858 nscolor mDefaultColor
;
859 nscolor mBackgroundColor
;
862 nscolor mActiveLinkColor
;
863 nscolor mVisitedLinkColor
;
865 nscolor mFocusBackgroundColor
;
866 nscolor mFocusTextColor
;
868 ScrollbarStyles mViewportStyleOverflow
;
869 PRUint8 mFocusRingWidth
;
871 PRUint16 mImageAnimationMode
;
872 PRUint16 mImageAnimationModePref
;
874 nsFont mDefaultVariableFont
;
875 nsFont mDefaultFixedFont
;
876 nsFont mDefaultSerifFont
;
877 nsFont mDefaultSansSerifFont
;
878 nsFont mDefaultMonospaceFont
;
879 nsFont mDefaultCursiveFont
;
880 nsFont mDefaultFantasyFont
;
882 nscoord mBorderWidthTable
[3];
884 unsigned mUseDocumentFonts
: 1;
885 unsigned mUseDocumentColors
: 1;
886 unsigned mUnderlineLinks
: 1;
887 unsigned mUseFocusColors
: 1;
888 unsigned mFocusRingOnAnything
: 1;
889 unsigned mFocusRingStyle
: 1;
890 unsigned mDrawImageBackground
: 1;
891 unsigned mDrawColorBackground
: 1;
892 unsigned mNeverAnimate
: 1;
893 unsigned mIsRenderingOnlySelection
: 1;
894 unsigned mNoTheme
: 1;
895 unsigned mPaginated
: 1;
896 unsigned mCanPaginatedScroll
: 1;
897 unsigned mDoScaledTwips
: 1;
898 unsigned mEnableJapaneseTransform
: 1;
899 unsigned mIsRootPaginatedDocument
: 1;
900 unsigned mPrefBidiDirection
: 1;
901 unsigned mPrefScrollbarSide
: 2;
902 unsigned mPendingSysColorChanged
: 1;
903 unsigned mPendingThemeChanged
: 1;
904 unsigned mPendingMediaFeatureValuesChanged
: 1;
905 unsigned mPrefChangePendingNeedsReflow
: 1;
906 unsigned mRenderedPositionVaryingContent
: 1;
908 // Is the current mUserFontSet valid?
909 unsigned mUserFontSetDirty
: 1;
910 // Has GetUserFontSet() been called?
911 unsigned mGetUserFontSetCalled
: 1;
912 // Do we currently have an event posted to call FlushUserFontSet?
913 unsigned mPostedFlushUserFontSet
: 1;
915 // resize reflow is supressed when the only change has been to zoom
916 // the document rather than to change the document's dimensions
917 unsigned mSupressResizeReflow
: 1;
920 unsigned mIsVisual
: 1;
930 ~nsPresContext() NS_HIDDEN
;
932 // these are private, use the list in nsFont.h if you want a public list
934 eDefaultFont_Variable
,
937 eDefaultFont_SansSerif
,
938 eDefaultFont_Monospace
,
939 eDefaultFont_Cursive
,
940 eDefaultFont_Fantasy
,
946 friend struct nsAutoLayoutPhase
;
947 PRUint32 mLayoutPhaseCount
[eLayoutPhase_COUNT
];
949 PRUint32
LayoutPhaseCount(nsLayoutPhase aPhase
) {
950 return mLayoutPhaseCount
[aPhase
];
958 struct nsAutoLayoutPhase
{
959 nsAutoLayoutPhase(nsPresContext
* aPresContext
, nsLayoutPhase aPhase
)
960 : mPresContext(aPresContext
), mPhase(aPhase
), mCount(0)
968 NS_ASSERTION(mCount
== 0, "imbalanced");
974 case eLayoutPhase_Paint
:
975 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_Paint
] == 0,
976 "recurring into paint");
977 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_Reflow
] == 0,
978 "painting in the middle of reflow");
979 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_FrameC
] == 0,
980 "painting in the middle of frame construction");
982 case eLayoutPhase_Reflow
:
983 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_Paint
] == 0,
984 "reflowing in the middle of a paint");
985 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_Reflow
] == 0,
986 "recurring into reflow");
987 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_FrameC
] == 0,
988 "reflowing in the middle of frame construction");
990 case eLayoutPhase_FrameC
:
991 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_Paint
] == 0,
992 "constructing frames in the middle of a paint");
993 NS_ASSERTION(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_Reflow
] == 0,
994 "constructing frames in the middle of reflow");
995 // The nsXBLService::LoadBindings call in ConstructFrameInternal
996 // makes us hit this one too often to be an NS_ASSERTION,
997 // despite how scary it is.
998 NS_WARN_IF_FALSE(mPresContext
->mLayoutPhaseCount
[eLayoutPhase_FrameC
] == 0,
999 "recurring into frame construction");
1004 ++(mPresContext
->mLayoutPhaseCount
[mPhase
]);
1010 NS_ASSERTION(mCount
> 0 && mPresContext
->mLayoutPhaseCount
[mPhase
] > 0,
1012 --(mPresContext
->mLayoutPhaseCount
[mPhase
]);
1017 nsPresContext
*mPresContext
;
1018 nsLayoutPhase mPhase
;
1022 #define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
1023 nsAutoLayoutPhase autoLayoutPhase((pc_), (eLayoutPhase_##phase_))
1024 #define LAYOUT_PHASE_TEMP_EXIT() \
1026 autoLayoutPhase.Exit(); \
1028 #define LAYOUT_PHASE_TEMP_REENTER() \
1030 autoLayoutPhase.Enter(); \
1035 #define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
1036 PR_BEGIN_MACRO PR_END_MACRO
1037 #define LAYOUT_PHASE_TEMP_EXIT() \
1038 PR_BEGIN_MACRO PR_END_MACRO
1039 #define LAYOUT_PHASE_TEMP_REENTER() \
1040 PR_BEGIN_MACRO PR_END_MACRO
1044 #ifdef MOZ_REFLOW_PERF
1046 #define DO_GLOBAL_REFLOW_COUNT(_name) \
1047 aPresContext->CountReflows((_name), (nsIFrame*)this);
1049 #define DO_GLOBAL_REFLOW_COUNT(_name)
1050 #endif // MOZ_REFLOW_PERF
1052 #endif /* nsPresContext_h___ */