forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsPresContext.h
1459 lines (1217 loc) · 47.9 KB
/
nsPresContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* a presentation of a document, part 1 */
#ifndef nsPresContext_h___
#define nsPresContext_h___
#include "mozilla/Attributes.h"
#include "nsISupports.h"
#include "nsColor.h"
#include "nsCoord.h"
#include "nsCOMPtr.h"
#include "nsIPresShell.h"
#include "nsRect.h"
#include "nsDeviceContext.h"
#include "nsFont.h"
#include "nsIObserver.h"
#include "nsITimer.h"
#include "nsCRT.h"
#include "FramePropertyTable.h"
#include "nsGkAtoms.h"
#include "nsRefPtrHashtable.h"
#include "nsCycleCollectionParticipant.h"
#include "nsChangeHint.h"
// This also pulls in gfxTypes.h, which we cannot include directly.
#include "gfxRect.h"
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "nsIWidget.h"
#include "mozilla/TimeStamp.h"
#include "prclist.h"
#include "Layers.h"
#include "nsRefreshDriver.h"
#ifdef IBMBIDI
class nsBidiPresUtils;
#endif // IBMBIDI
struct nsRect;
class imgIRequest;
class nsAString;
class nsIPrintSettings;
class nsIDocument;
class nsILanguageAtomService;
class nsITheme;
class nsIContent;
class nsFontMetrics;
class nsIFrame;
class nsFrameManager;
class nsILinkHandler;
class nsStyleContext;
class nsIAtom;
class nsEventStateManager;
class nsIURI;
class nsICSSPseudoComparator;
struct nsStyleBackground;
struct nsStyleBorder;
class nsIRunnable;
class gfxUserFontSet;
class nsUserFontSet;
struct nsFontFaceRuleContainer;
class nsObjectFrame;
class nsTransitionManager;
class nsAnimationManager;
class imgIContainer;
class nsIDOMMediaQueryList;
#ifdef MOZ_REFLOW_PERF
class nsRenderingContext;
#endif
// supported values for cached bool types
enum nsPresContext_CachedBoolPrefType {
kPresContext_UseDocumentColors = 1,
kPresContext_UseDocumentFonts,
kPresContext_UnderlineLinks
};
// supported values for cached integer pref types
enum nsPresContext_CachedIntPrefType {
kPresContext_ScrollbarSide = 1,
kPresContext_BidiDirection
};
// IDs for the default variable and fixed fonts (not to be changed, see nsFont.h)
// To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are also supported.
const uint8_t kPresContext_DefaultVariableFont_ID = 0x00; // kGenericFont_moz_variable
const uint8_t kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fixed
#ifdef DEBUG
struct nsAutoLayoutPhase;
enum nsLayoutPhase {
eLayoutPhase_Paint,
eLayoutPhase_Reflow,
eLayoutPhase_FrameC,
eLayoutPhase_COUNT
};
#endif
class nsInvalidateRequestList {
public:
struct Request {
nsRect mRect;
uint32_t mFlags;
};
void TakeFrom(nsInvalidateRequestList* aList)
{
mRequests.MoveElementsFrom(aList->mRequests);
}
bool IsEmpty() { return mRequests.IsEmpty(); }
nsTArray<Request> mRequests;
};
/**
* Layer UserData for ContainerLayers that want to be notified
* of local invalidations of them and their descendant layers.
* Pass a callback to ComputeDifferences to have these called.
*/
class ContainerLayerPresContext : public mozilla::layers::LayerUserData {
public:
nsPresContext* mPresContext;
};
extern uint8_t gNotifySubDocInvalidationData;
/* Used by nsPresContext::HasAuthorSpecifiedRules */
#define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
#define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
#define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
#define NS_AUTHOR_SPECIFIED_TEXT_SHADOW (1 << 3)
class nsRootPresContext;
// An interface for presentation contexts. Presentation contexts are
// objects that provide an outer context for a presentation shell.
class nsPresContext : public nsIObserver {
public:
typedef mozilla::FramePropertyTable FramePropertyTable;
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
enum nsPresContextType {
eContext_Galley, // unpaginated screen presentation
eContext_PrintPreview, // paginated screen presentation
eContext_Print, // paginated printer presentation
eContext_PageLayout // paginated & editable.
};
// Policies for rebuilding style data.
enum StyleRebuildType {
eRebuildStyleIfNeeded,
eAlwaysRebuildStyle
};
nsPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN;
/**
* Initialize the presentation context from a particular device.
*/
NS_HIDDEN_(nsresult) Init(nsDeviceContext* aDeviceContext);
/**
* Set the presentation shell that this context is bound to.
* A presentation context may only be bound to a single shell.
*/
NS_HIDDEN_(void) SetShell(nsIPresShell* aShell);
NS_HIDDEN_(nsPresContextType) Type() const { return mType; }
/**
* Get the PresentationShell that this context is bound to.
*/
nsIPresShell* PresShell() const
{
NS_ASSERTION(mShell, "Null pres shell");
return mShell;
}
nsIPresShell* GetPresShell() const { return mShell; }
/**
* Returns the parent prescontext for this one. Returns null if this is a
* root.
*/
nsPresContext* GetParentPresContext();
/**
* Returns the prescontext of the toplevel content document that contains
* this presentation, or null if there isn't one.
*/
nsPresContext* GetToplevelContentDocumentPresContext();
/**
* Returns the nearest widget for the root frame of this.
*
* @param aOffset If non-null the offset from the origin of the root
* frame's view to the widget's origin (usually positive)
* expressed in appunits of this will be returned in
* aOffset.
*/
nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
/**
* Return the presentation context for the root of the view manager
* hierarchy that contains this presentation context, or nullptr if it can't
* be found (e.g. it's detached).
*/
nsRootPresContext* GetRootPresContext();
nsRootPresContext* GetDisplayRootPresContext();
virtual bool IsRoot() { return false; }
nsIDocument* Document() const
{
NS_ASSERTION(!mShell || !mShell->GetDocument() ||
mShell->GetDocument() == mDocument,
"nsPresContext doesn't have the same document as nsPresShell!");
return mDocument;
}
#ifdef _IMPL_NS_LAYOUT
nsStyleSet* StyleSet() { return GetPresShell()->StyleSet(); }
nsFrameManager* FrameManager()
{ return GetPresShell()->FrameManager(); }
nsTransitionManager* TransitionManager() { return mTransitionManager; }
nsAnimationManager* AnimationManager() { return mAnimationManager; }
nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
#endif
/**
* Rebuilds all style data by throwing out the old rule tree and
* building a new one, and additionally applying aExtraHint (which
* must not contain nsChangeHint_ReconstructFrame) to the root frame.
* Also rebuild the user font set.
*/
void RebuildAllStyleData(nsChangeHint aExtraHint);
/**
* Just like RebuildAllStyleData, except (1) asynchronous and (2) it
* doesn't rebuild the user font set.
*/
void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint);
void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild,
nsChangeHint aChangeHint = nsChangeHint(0));
void PostMediaFeatureValuesChangedEvent();
NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent();
void FlushPendingMediaFeatureValuesChanged() {
if (mPendingMediaFeatureValuesChanged)
MediaFeatureValuesChanged(eRebuildStyleIfNeeded);
}
/**
* Support for window.matchMedia()
*/
void MatchMedia(const nsAString& aMediaQueryList,
nsIDOMMediaQueryList** aResult);
/**
* Access compatibility mode for this context. This is the same as
* our document's compatibility mode.
*/
nsCompatibility CompatibilityMode() const;
/**
* Notify the context that the document's compatibility mode has changed
*/
NS_HIDDEN_(void) CompatibilityModeChanged();
/**
* Access the image animation mode for this context
*/
uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
virtual NS_HIDDEN_(void) SetImageAnimationModeExternal(uint16_t aMode);
NS_HIDDEN_(void) SetImageAnimationModeInternal(uint16_t aMode);
#ifdef _IMPL_NS_LAYOUT
void SetImageAnimationMode(uint16_t aMode)
{ SetImageAnimationModeInternal(aMode); }
#else
void SetImageAnimationMode(uint16_t aMode)
{ SetImageAnimationModeExternal(aMode); }
#endif
/**
* Get medium of presentation
*/
nsIAtom* Medium() { return mMedium; }
void* AllocateFromShell(size_t aSize)
{
if (mShell)
return mShell->AllocateMisc(aSize);
return nullptr;
}
void FreeToShell(size_t aSize, void* aFreeChunk)
{
NS_ASSERTION(mShell, "freeing after shutdown");
if (mShell)
mShell->FreeMisc(aSize, aFreeChunk);
}
/**
* Get the default font for the given language and generic font ID.
* If aLanguage is nullptr, the document's language is used.
*
* This object is read-only, you must copy the font to modify it.
*
* When aFontID is kPresContext_DefaultVariableFontID or
* kPresContext_DefaultFixedFontID (which equals
* kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
* the nsFont returned has its name as a CSS generic family (serif or
* sans-serif for the former, monospace for the latter), and its size
* as the default font size for variable or fixed fonts for the
* language group.
*
* For aFontID corresponding to a CSS Generic, the nsFont returned has
* its name set to that generic font's name, and its size set to
* the user's preference for font size for that generic and the
* given language.
*/
NS_HIDDEN_(const nsFont*) GetDefaultFont(uint8_t aFontID,
nsIAtom *aLanguage) const;
/** Get a cached boolean pref, by its type */
// * - initially created for bugs 31816, 20760, 22963
bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const
{
// If called with a constant parameter, the compiler should optimize
// this switch statement away.
switch (aPrefType) {
case kPresContext_UseDocumentFonts:
return mUseDocumentFonts;
case kPresContext_UseDocumentColors:
return mUseDocumentColors;
case kPresContext_UnderlineLinks:
return mUnderlineLinks;
default:
NS_ERROR("Invalid arg passed to GetCachedBoolPref");
}
return false;
}
/** Get a cached integer pref, by its type */
// * - initially created for bugs 30910, 61883, 74186, 84398
int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const
{
// If called with a constant parameter, the compiler should optimize
// this switch statement away.
switch (aPrefType) {
case kPresContext_ScrollbarSide:
return mPrefScrollbarSide;
case kPresContext_BidiDirection:
return mPrefBidiDirection;
default:
NS_ERROR("invalid arg passed to GetCachedIntPref");
}
return false;
}
/**
* Get the default colors
*/
const nscolor DefaultColor() const { return mDefaultColor; }
const nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
const nscolor DefaultLinkColor() const { return mLinkColor; }
const nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
const nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
const nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
const nscolor FocusTextColor() const { return mFocusTextColor; }
/**
* Body text color, for use in quirks mode only.
*/
const nscolor BodyTextColor() const { return mBodyTextColor; }
void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; }
bool GetUseFocusColors() const { return mUseFocusColors; }
uint8_t FocusRingWidth() const { return mFocusRingWidth; }
bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
uint8_t GetFocusRingStyle() const { return mFocusRingStyle; }
NS_HIDDEN_(void) SetContainer(nsISupports* aContainer);
virtual NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerExternal() const;
NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerInternal() const;
#ifdef _IMPL_NS_LAYOUT
already_AddRefed<nsISupports> GetContainer() const
{ return GetContainerInternal(); }
#else
already_AddRefed<nsISupports> GetContainer() const
{ return GetContainerExternal(); }
#endif
// XXX this are going to be replaced with set/get container
void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
/**
* Get the visible area associated with this presentation context.
* This is the size of the visible area that is used for
* presenting the document. The returned value is in the standard
* nscoord units (as scaled by the device context).
*/
nsRect GetVisibleArea() { return mVisibleArea; }
/**
* Set the currently visible area. The units for r are standard
* nscoord units (as scaled by the device context).
*/
void SetVisibleArea(const nsRect& r) {
if (!r.IsEqualEdges(mVisibleArea)) {
mVisibleArea = r;
// Visible area does not affect media queries when paginated.
if (!IsPaginated() && HasCachedStyleData()) {
mPendingViewportChange = true;
PostMediaFeatureValuesChangedEvent();
}
}
}
/**
* Return true if this presentation context is a paginated
* context.
*/
bool IsPaginated() const { return mPaginated; }
/**
* Sets whether the presentation context can scroll for a paginated
* context.
*/
NS_HIDDEN_(void) SetPaginatedScrolling(bool aResult);
/**
* Return true if this presentation context can scroll for paginated
* context.
*/
bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
/**
* Get/set the size of a page
*/
nsSize GetPageSize() { return mPageSize; }
void SetPageSize(nsSize aSize) { mPageSize = aSize; }
/**
* Get/set whether this document should be treated as having real pages
* XXX This raises the obvious question of why a document that isn't a page
* is paginated; there isn't a good reason except history
*/
bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument)
{ mIsRootPaginatedDocument = aIsRootPaginatedDocument; }
/**
* Get/set the print scaling level; used by nsPageFrame to scale up
* pages. Set safe to call before reflow, get guaranteed to be set
* properly after reflow.
*/
float GetPageScale() { return mPageScale; }
void SetPageScale(float aScale) { mPageScale = aScale; }
/**
* Get/set the scaling facor to use when rendering the pages for print preview.
* Only safe to get after print preview set up; safe to set anytime.
* This is a scaling factor for the display of the print preview. It
* does not affect layout. It only affects the size of the onscreen pages
* in print preview.
* XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
*/
float GetPrintPreviewScale() { return mPPScale; }
void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
nsDeviceContext* DeviceContext() { return mDeviceContext; }
nsEventStateManager* EventStateManager() { return mEventManager; }
nsIAtom* GetLanguageFromCharset() { return mLanguage; }
float TextZoom() { return mTextZoom; }
void SetTextZoom(float aZoom) {
if (aZoom == mTextZoom)
return;
mTextZoom = aZoom;
if (HasCachedStyleData()) {
// Media queries could have changed, since we changed the meaning
// of 'em' units in them.
MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
}
}
/**
* Get the minimum font size for the specified language. If aLanguage
* is nullptr, then the document's language is used.
*/
int32_t MinFontSize(nsIAtom *aLanguage) const {
const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
return NS_MAX(mMinFontSize, prefs->mMinimumFontSize);
}
void SetMinFontSize(int32_t aMinFontSize) {
if (aMinFontSize == mMinFontSize)
return;
mMinFontSize = aMinFontSize;
if (HasCachedStyleData()) {
// Media queries could have changed, since we changed the meaning
// of 'em' units in them.
MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
}
}
float GetFullZoom() { return mFullZoom; }
void SetFullZoom(float aZoom);
nscoord GetAutoQualityMinFontSize() {
return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
}
/**
* Return the device's screen width in inches, for font size
* inflation.
*
* If |aChanged| is non-null, then aChanged is filled in with whether
* the return value has changed since either:
* a. the last time the function was called with non-null aChanged, or
* b. the first time the function was called.
*/
float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr);
static int32_t AppUnitsPerCSSPixel() { return nsDeviceContext::AppUnitsPerCSSPixel(); }
uint32_t AppUnitsPerDevPixel() const { return mDeviceContext->AppUnitsPerDevPixel(); }
static int32_t AppUnitsPerCSSInch() { return nsDeviceContext::AppUnitsPerCSSInch(); }
static nscoord CSSPixelsToAppUnits(int32_t aPixels)
{ return NSIntPixelsToAppUnits(aPixels,
nsDeviceContext::AppUnitsPerCSSPixel()); }
static nscoord CSSPixelsToAppUnits(float aPixels)
{ return NSFloatPixelsToAppUnits(aPixels,
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits)
{ return NSAppUnitsToIntPixels(aAppUnits,
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
static float AppUnitsToFloatCSSPixels(nscoord aAppUnits)
{ return NSAppUnitsToFloatPixels(aAppUnits,
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
nscoord DevPixelsToAppUnits(int32_t aPixels) const
{ return NSIntPixelsToAppUnits(aPixels,
mDeviceContext->AppUnitsPerDevPixel()); }
int32_t AppUnitsToDevPixels(nscoord aAppUnits) const
{ return NSAppUnitsToIntPixels(aAppUnits,
float(mDeviceContext->AppUnitsPerDevPixel())); }
int32_t CSSPixelsToDevPixels(int32_t aPixels)
{ return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }
float CSSPixelsToDevPixels(float aPixels)
{
return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
float(mDeviceContext->AppUnitsPerDevPixel()));
}
int32_t DevPixelsToIntCSSPixels(int32_t aPixels)
{ return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); }
float DevPixelsToFloatCSSPixels(int32_t aPixels)
{ return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); }
// If there is a remainder, it is rounded to nearest app units.
nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
{ return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits); }
gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const
{ return mDeviceContext->AppUnitsToGfxUnits(aAppUnits); }
gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const
{ return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
AppUnitsToGfxUnits(aAppRect.y),
AppUnitsToGfxUnits(aAppRect.width),
AppUnitsToGfxUnits(aAppRect.height)); }
static nscoord CSSTwipsToAppUnits(float aTwips)
{ return NSToCoordRoundWithClamp(
nsDeviceContext::AppUnitsPerCSSInch() * NS_TWIPS_TO_INCHES(aTwips)); }
// Margin-specific version, since they often need TwipsToAppUnits
static nsMargin CSSTwipsToAppUnits(const nsIntMargin &marginInTwips)
{ return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.left)),
CSSTwipsToAppUnits(float(marginInTwips.top)),
CSSTwipsToAppUnits(float(marginInTwips.right)),
CSSTwipsToAppUnits(float(marginInTwips.bottom))); }
static nscoord CSSPointsToAppUnits(float aPoints)
{ return NSToCoordRound(aPoints * nsDeviceContext::AppUnitsPerCSSInch() /
POINTS_PER_INCH_FLOAT); }
nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
{ return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
struct ScrollbarStyles {
// Always one of NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
// or NS_STYLE_OVERFLOW_AUTO.
uint8_t mHorizontal, mVertical;
ScrollbarStyles(uint8_t h, uint8_t v) : mHorizontal(h), mVertical(v) {}
ScrollbarStyles() {}
bool operator==(const ScrollbarStyles& aStyles) const {
return aStyles.mHorizontal == mHorizontal && aStyles.mVertical == mVertical;
}
bool operator!=(const ScrollbarStyles& aStyles) const {
return aStyles.mHorizontal != mHorizontal || aStyles.mVertical != mVertical;
}
};
void SetViewportOverflowOverride(uint8_t aX, uint8_t aY)
{
mViewportStyleOverflow.mHorizontal = aX;
mViewportStyleOverflow.mVertical = aY;
}
ScrollbarStyles GetViewportOverflowOverride()
{
return mViewportStyleOverflow;
}
/**
* Set and get methods for controlling the background drawing
*/
bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
void SetBackgroundImageDraw(bool aCanDraw)
{
mDrawImageBackground = aCanDraw;
}
bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
void SetBackgroundColorDraw(bool aCanDraw)
{
mDrawColorBackground = aCanDraw;
}
/**
* Getter and setter for OMTA time counters
*/
bool ThrottledStyleIsUpToDate() const {
return mLastUpdateThrottledStyle == mRefreshDriver->MostRecentRefresh();
}
void TickLastUpdateThrottledStyle() {
mLastUpdateThrottledStyle = mRefreshDriver->MostRecentRefresh();
}
bool StyleUpdateForAllAnimationsIsUpToDate() const {
return mLastStyleUpdateForAllAnimations == mRefreshDriver->MostRecentRefresh();
}
void TickLastStyleUpdateForAllAnimations() {
mLastStyleUpdateForAllAnimations = mRefreshDriver->MostRecentRefresh();
}
#ifdef IBMBIDI
/**
* Check if bidi enabled (set depending on the presence of RTL
* characters or when default directionality is RTL).
* If enabled, we should apply the Unicode Bidi Algorithm
*
* @lina 07/12/2000
*/
#ifdef _IMPL_NS_LAYOUT
bool BidiEnabled() const { return BidiEnabledInternal(); }
#else
bool BidiEnabled() const { return BidiEnabledExternal(); }
#endif
virtual bool BidiEnabledExternal() const;
bool BidiEnabledInternal() const;
/**
* Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
*
* @lina 07/12/2000
*/
NS_HIDDEN_(void) SetBidiEnabled() const;
/**
* Set visual or implicit mode into the pres context.
*
* Visual directionality is a presentation method that displays text
* as if it were a uni-directional, according to the primary display
* direction only.
*
* Implicit directionality is a presentation method in which the
* direction is determined by the Bidi algorithm according to the
* category of the characters and the category of the adjacent
* characters, and according to their primary direction.
*
* @lina 05/02/2000
*/
void SetVisualMode(bool aIsVisual)
{
mIsVisual = aIsVisual;
}
/**
* Check whether the content should be treated as visual.
*
* @lina 05/02/2000
*/
bool IsVisualMode() const { return mIsVisual; }
//Mohamed
/**
* Set the Bidi options for the presentation context
*/
NS_HIDDEN_(void) SetBidi(uint32_t aBidiOptions,
bool aForceRestyle = false);
/**
* Get the Bidi options for the presentation context
* Not inline so consumers of nsPresContext are not forced to
* include nsIDocument.
*/
NS_HIDDEN_(uint32_t) GetBidi() const;
#endif // IBMBIDI
/**
* Render only Selection
*/
void SetIsRenderingOnlySelection(bool aResult)
{
mIsRenderingOnlySelection = aResult;
}
bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; }
NS_HIDDEN_(bool) IsTopLevelWindowInactive();
/*
* Obtain a native them for rendering our widgets (both form controls and html)
*/
NS_HIDDEN_(nsITheme*) GetTheme();
/*
* Notify the pres context that the theme has changed. An internal switch
* means it's one of our Mozilla themes that changed (e.g., Modern to Classic).
* Otherwise, the OS is telling us that the native theme for the platform
* has changed.
*/
NS_HIDDEN_(void) ThemeChanged();
/*
* Notify the pres context that the resolution of the user interface has
* changed. This happens if a window is moved between HiDPI and non-HiDPI
* displays, so that the ratio of points to device pixels changes.
*/
NS_HIDDEN_(void) UIResolutionChanged();
/*
* Notify the pres context that a system color has changed
*/
NS_HIDDEN_(void) SysColorChanged();
/** Printing methods below should only be used for Medium() == print **/
NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings);
nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
/* Accessor for table of frame properties */
FramePropertyTable* PropertyTable() { return &mPropertyTable; }
/* Helper function that ensures that this prescontext is shown in its
docshell if it's the most recent prescontext for the docshell. Returns
whether the prescontext is now being shown.
*/
NS_HIDDEN_(bool) EnsureVisible();
#ifdef MOZ_REFLOW_PERF
NS_HIDDEN_(void) CountReflows(const char * aName,
nsIFrame * aFrame);
#endif
/**
* This table maps border-width enums 'thin', 'medium', 'thick'
* to actual nscoord values.
*/
const nscoord* GetBorderWidthTable() { return mBorderWidthTable; }
bool IsDynamic() { return (mType == eContext_PageLayout || mType == eContext_Galley); }
bool IsScreen() { return (mMedium == nsGkAtoms::screen ||
mType == eContext_PageLayout ||
mType == eContext_PrintPreview); }
// Is this presentation in a chrome docshell?
bool IsChrome() const
{
return mIsChromeIsCached ? mIsChrome : IsChromeSlow();
}
virtual void InvalidateIsChromeCacheExternal();
void InvalidateIsChromeCacheInternal() { mIsChromeIsCached = false; }
#ifdef _IMPL_NS_LAYOUT
void InvalidateIsChromeCache()
{ InvalidateIsChromeCacheInternal(); }
#else
void InvalidateIsChromeCache()
{ InvalidateIsChromeCacheExternal(); }
#endif
// Public API for native theme code to get style internals.
virtual bool HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const;
// Is it OK to let the page specify colors and backgrounds?
bool UseDocumentColors() const {
return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome();
}
bool SupressingResizeReflow() const { return mSupressResizeReflow; }
virtual NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetExternal();
NS_HIDDEN_(gfxUserFontSet*) GetUserFontSetInternal();
#ifdef _IMPL_NS_LAYOUT
gfxUserFontSet* GetUserFontSet() { return GetUserFontSetInternal(); }
#else
gfxUserFontSet* GetUserFontSet() { return GetUserFontSetExternal(); }
#endif
void FlushUserFontSet();
void RebuildUserFontSet(); // asynchronously
// Should be called whenever the set of fonts available in the user
// font set changes (e.g., because a new font loads, or because the
// user font set is changed and fonts become unavailable).
void UserFontSetUpdated();
// Ensure that it is safe to hand out CSS rules outside the layout
// engine by ensuring that all CSS style sheets have unique inners
// and, if necessary, synchronously rebuilding all style data.
// Returns true on success and false on failure (not safe).
bool EnsureSafeToHandOutCSSRules();
void NotifyInvalidation(uint32_t aFlags);
void NotifyInvalidation(const nsRect& aRect, uint32_t aFlags);
// aRect is in device pixels
void NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags);
// aFlags are nsIPresShell::PAINT_ flags
void NotifyDidPaintForSubtree(uint32_t aFlags);
void FireDOMPaintEvent(nsInvalidateRequestList* aList);
// Callback for catching invalidations in ContainerLayers
// Passed to LayerProperties::ComputeDifference
static void NotifySubDocInvalidation(mozilla::layers::ContainerLayer* aContainer,
const nsIntRegion& aRegion);
bool IsDOMPaintEventPending();
void ClearMozAfterPaintEvents() {
mInvalidateRequestsSinceLastPaint.mRequests.Clear();
mUndeliveredInvalidateRequestsBeforeLastPaint.mRequests.Clear();
mAllInvalidated = false;
}
bool IsProcessingRestyles() const {
return mProcessingRestyles;
}
void SetProcessingRestyles(bool aProcessing) {
NS_ASSERTION(aProcessing != bool(mProcessingRestyles),
"should never nest");
mProcessingRestyles = aProcessing;
}
bool IsProcessingAnimationStyleChange() const {
return mProcessingAnimationStyleChange;
}
void SetProcessingAnimationStyleChange(bool aProcessing) {
NS_ASSERTION(aProcessing != bool(mProcessingAnimationStyleChange),
"should never nest");
mProcessingAnimationStyleChange = aProcessing;
}
/**
* Notify the prescontext that the presshell is about to reflow a reflow root.
* The single argument indicates whether this reflow should be interruptible.
* If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
* will always return false. If aInterruptible is true then CheckForInterrupt
* will return true when a pending event is detected. This is for use by the
* presshell only. Reflow code wanting to prevent interrupts should use
* InterruptPreventer.
*/
void ReflowStarted(bool aInterruptible);
/**
* A class that can be used to temporarily disable reflow interruption.
*/
class InterruptPreventer;
friend class InterruptPreventer;
class NS_STACK_CLASS InterruptPreventer {
public:
InterruptPreventer(nsPresContext* aCtx) :
mCtx(aCtx),
mInterruptsEnabled(aCtx->mInterruptsEnabled),
mHasPendingInterrupt(aCtx->mHasPendingInterrupt)
{
mCtx->mInterruptsEnabled = false;
mCtx->mHasPendingInterrupt = false;
}
~InterruptPreventer() {
mCtx->mInterruptsEnabled = mInterruptsEnabled;
mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
}
private:
nsPresContext* mCtx;
bool mInterruptsEnabled;
bool mHasPendingInterrupt;
};
/**
* Check for interrupts. This may return true if a pending event is
* detected. Once it has returned true, it will keep returning true
* until ReflowStarted is called. In all cases where this returns true,
* the passed-in frame (which should be the frame whose reflow will be
* interrupted if true is returned) will be passed to
* nsIPresShell::FrameNeedsToContinueReflow.
*/
bool CheckForInterrupt(nsIFrame* aFrame);
/**
* Returns true if CheckForInterrupt has returned true since the last
* ReflowStarted call. Cannot itself trigger an interrupt check.
*/
bool HasPendingInterrupt() { return mHasPendingInterrupt; }
/**
* If we have a presshell, and if the given content's current
* document is the same as our presshell's document, return the
* content's primary frame. Otherwise, return null. Only use this
* if you care about which presshell the primary frame is in.
*/
nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
void NotifyDestroyingFrame(nsIFrame* aFrame)
{
PropertyTable()->DeleteAllFor(aFrame);
}
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const {
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
bool IsRootContentDocument();
bool IsCrossProcessRootContentDocument();
bool IsGlyph() const {
return mIsGlyph;
}
void SetIsGlyph(bool aValue) {
mIsGlyph = aValue;
}
bool UsesRootEMUnits() const {
return mUsesRootEMUnits;
}
void SetUsesRootEMUnits(bool aValue) {
mUsesRootEMUnits = aValue;
}
bool UsesViewportUnits() const {
return mUsesViewportUnits;
}
void SetUsesViewportUnits(bool aValue) {
mUsesViewportUnits = aValue;
}
// true if there are OMTA transition updates for the current document which
// have been throttled, and therefore some style information may not be up
// to date
bool ExistThrottledUpdates() const {
return mExistThrottledUpdates;
}
void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
mExistThrottledUpdates = aExistThrottledUpdates;
}