FontFaceSetDocumentImpl.h (3884B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_FontFaceSetDocumentImpl_h 8 #define mozilla_dom_FontFaceSetDocumentImpl_h 9 10 #include "mozilla/dom/FontFaceSetImpl.h" 11 #include "nsICSSLoaderObserver.h" 12 #include "nsIDOMEventListener.h" 13 14 namespace mozilla::dom { 15 16 class FontFaceSetDocumentImpl final : public FontFaceSetImpl, 17 public nsIDOMEventListener, 18 public nsICSSLoaderObserver { 19 NS_DECL_ISUPPORTS_INHERITED 20 21 public: 22 NS_DECL_NSIDOMEVENTLISTENER 23 24 FontFaceSetDocumentImpl(FontFaceSet* aOwner, dom::Document* aDocument); 25 26 void Initialize(); 27 void Destroy() override; 28 29 bool IsOnOwningThread() override; 30 #ifdef DEBUG 31 void AssertIsOnOwningThread() override; 32 #endif 33 void DispatchToOwningThread(const char* aName, 34 std::function<void()>&& aFunc) override; 35 36 void RefreshStandardFontLoadPrincipal() override; 37 38 dom::Document* GetDocument() const override { return mDocument; } 39 40 already_AddRefed<URLExtraData> GetURLExtraData() override; 41 42 // gfxUserFontSet 43 44 nsresult StartLoad(gfxUserFontEntry* aUserFontEntry, 45 uint32_t aSrcIndex) override; 46 47 bool IsFontLoadAllowed(const gfxFontFaceSrc&) override; 48 49 FontVisibilityProvider* GetFontVisibilityProvider() const override; 50 51 bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules) override; 52 53 StyleLockedFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry) override; 54 55 /** 56 * Notification method called by the nsPresContext to indicate that the 57 * refresh driver ticked and flushed style and layout. 58 * were just flushed. 59 */ 60 void DidRefresh() override; 61 62 // nsICSSLoaderObserver 63 NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasDeferred, 64 nsresult aStatus) override; 65 66 // For ServoStyleSet to know ahead of time whether a font is loadable. 67 void CacheFontLoadability() override; 68 69 void EnsureReady() override; 70 71 bool Add(FontFaceImpl* aFontFace, ErrorResult& aRv) override; 72 73 void FlushUserFontSet() override; 74 void MarkUserFontSetDirty() override; 75 76 private: 77 ~FontFaceSetDocumentImpl() override; 78 79 uint64_t GetInnerWindowID() override; 80 81 void RemoveDOMContentLoadedListener(); 82 83 nsresult CreateChannelForSyncLoadFontData( 84 nsIChannel** aOutChannel, gfxUserFontEntry* aFontToLoad, 85 const gfxFontFaceSrc* aFontFaceSrc) override; 86 87 // search for @font-face rule that matches a userfont font entry 88 StyleLockedFontFaceRule* FindRuleForUserFontEntry( 89 gfxUserFontEntry* aUserFontEntry) override; 90 91 void FindMatchingFontFaces(const nsTHashSet<FontFace*>& aMatchingFaces, 92 nsTArray<FontFace*>& aFontFaces) override; 93 94 /* Returns whether the font set was modified. */ 95 bool InsertRuleFontFace(StyleLockedFontFaceRule*, StyleOrigin, 96 nsTArray<FontFaceRecord>& aOldRecords); 97 98 // Helper function for HasLoadingFontFaces. 99 void UpdateHasLoadingFontFaces() override; 100 101 /** 102 * Returns whether there might be any pending font loads, which should cause 103 * the mReady Promise not to be resolved yet. 104 */ 105 bool MightHavePendingFontLoads() override; 106 107 #ifdef DEBUG 108 bool HasRuleFontFace(FontFaceImpl* aFontFace); 109 #endif 110 111 TimeStamp GetNavigationStartTimeStamp() override; 112 113 // The document this is a FontFaceSet for. 114 RefPtr<dom::Document> mDocument; 115 116 // The @font-face rule backed FontFace objects in the FontFaceSet. 117 nsTArray<FontFaceRecord> mRuleFaces; 118 }; 119 120 } // namespace mozilla::dom 121 122 #endif // !defined(mozilla_dom_FontFaceSetDocumentImpl_h)