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/. */
7 /* code for loading in @font-face defined font data */
9 #ifndef nsFontFaceLoader_h_
10 #define nsFontFaceLoader_h_
12 #include "mozilla/Attributes.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/dom/FontFaceSetImpl.h"
16 #include "nsIFontLoadCompleteCallback.h"
17 #include "nsIStreamLoader.h"
18 #include "nsIChannel.h"
19 #include "nsIRequestObserver.h"
20 #include "gfxUserFontSet.h"
21 #include "nsHashKeys.h"
22 #include "nsTHashtable.h"
27 class nsFontFaceLoader final
: public nsIStreamLoaderObserver
,
28 public nsIRequestObserver
,
29 public nsIFontLoadCompleteCallback
{
31 nsFontFaceLoader(gfxUserFontEntry
* aUserFontEntry
, uint32_t aSrcIndex
,
32 mozilla::dom::FontFaceSetImpl
* aFontFaceSet
,
33 nsIChannel
* aChannel
);
36 NS_DECL_NSISTREAMLOADEROBSERVER
37 NS_DECL_NSIREQUESTOBSERVER
39 // cancel the load and remove its reference to mFontFaceSet
42 void DropChannel() { mChannel
= nullptr; }
44 void StartedLoading(nsIStreamLoader
* aStreamLoader
);
46 static void LoadTimerCallback(nsITimer
* aTimer
, void* aClosure
);
48 gfxUserFontEntry
* GetUserFontEntry() const { return mUserFontEntry
; }
50 // Called by the gfxUserFontEntry once it has finished the platform font
52 NS_IMETHODIMP
FontLoadComplete() final
;
55 virtual ~nsFontFaceLoader();
57 // helper method for determining the font-display value
58 mozilla::StyleFontDisplay
GetFontDisplay();
61 RefPtr
<gfxUserFontEntry
> mUserFontEntry
;
62 nsCOMPtr
<nsIURI
> mFontURI
;
63 // Cleared in FontFaceSet::~FontFaceSet, and on cancelation and such too.
64 mozilla::dom::FontFaceSetImpl
* MOZ_NON_OWNING_REF mFontFaceSet
;
65 nsCOMPtr
<nsIChannel
> mChannel
;
66 nsCOMPtr
<nsITimer
> mLoadTimer
;
67 mozilla::TimeStamp mStartTime
;
68 nsIStreamLoader
* mStreamLoader
;
70 bool mInStreamComplete
= false;
71 bool mInLoadTimerCallback
= false;
74 #endif /* !defined(nsFontFaceLoader_h_) */