summaryrefslogtreecommitdiffstats
path: root/layout/style/FontFaceSetDocumentImpl.h
blob: d32103e203ea8ea964f12a91e75b7770806e0353 (plain)
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
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef mozilla_dom_FontFaceSetDocumentImpl_h
#define mozilla_dom_FontFaceSetDocumentImpl_h

#include "mozilla/dom/FontFaceSetImpl.h"
#include "nsICSSLoaderObserver.h"
#include "nsIDOMEventListener.h"

namespace mozilla::dom {

class FontFaceSetDocumentImpl final : public FontFaceSetImpl,
                                      public nsIDOMEventListener,
                                      public nsICSSLoaderObserver {
  NS_DECL_ISUPPORTS_INHERITED

 public:
  NS_DECL_NSIDOMEVENTLISTENER

  FontFaceSetDocumentImpl(FontFaceSet* aOwner, dom::Document* aDocument);

  void Initialize();
  void Destroy() override;

  bool IsOnOwningThread() override;
#ifdef DEBUG
  void AssertIsOnOwningThread() override;
#endif
  void DispatchToOwningThread(const char* aName,
                              std::function<void()>&& aFunc) override;

  void RefreshStandardFontLoadPrincipal() override;

  dom::Document* GetDocument() const override { return mDocument; }

  already_AddRefed<URLExtraData> GetURLExtraData() override;

  // gfxUserFontSet

  nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
                     uint32_t aSrcIndex) override;

  bool IsFontLoadAllowed(const gfxFontFaceSrc&) override;

  nsPresContext* GetPresContext() const override;

  bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules) override;

  StyleLockedFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry) override;

  /**
   * Notification method called by the nsPresContext to indicate that the
   * refresh driver ticked and flushed style and layout.
   * were just flushed.
   */
  void DidRefresh() override;

  // nsICSSLoaderObserver
  NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasDeferred,
                              nsresult aStatus) override;

  // For ServoStyleSet to know ahead of time whether a font is loadable.
  void CacheFontLoadability() override;

  void EnsureReady() override;

  bool Add(FontFaceImpl* aFontFace, ErrorResult& aRv) override;

  void FlushUserFontSet() override;
  void MarkUserFontSetDirty() override;

 private:
  ~FontFaceSetDocumentImpl() override;

  uint64_t GetInnerWindowID() override;

  void RemoveDOMContentLoadedListener();

  nsresult CreateChannelForSyncLoadFontData(
      nsIChannel** aOutChannel, gfxUserFontEntry* aFontToLoad,
      const gfxFontFaceSrc* aFontFaceSrc) override;

  // search for @font-face rule that matches a userfont font entry
  StyleLockedFontFaceRule* FindRuleForUserFontEntry(
      gfxUserFontEntry* aUserFontEntry) override;

  void FindMatchingFontFaces(const nsTHashSet<FontFace*>& aMatchingFaces,
                             nsTArray<FontFace*>& aFontFaces) override;

  void InsertRuleFontFace(FontFaceImpl* aFontFace, FontFace* aFontFaceOwner,
                          StyleOrigin aOrigin,
                          nsTArray<FontFaceRecord>& aOldRecords,
                          bool& aFontSetModified);

  // Helper function for HasLoadingFontFaces.
  void UpdateHasLoadingFontFaces() override;

  /**
   * Returns whether there might be any pending font loads, which should cause
   * the mReady Promise not to be resolved yet.
   */
  bool MightHavePendingFontLoads() override;

#ifdef DEBUG
  bool HasRuleFontFace(FontFaceImpl* aFontFace);
#endif

  TimeStamp GetNavigationStartTimeStamp() override;

  // The document this is a FontFaceSet for.
  RefPtr<dom::Document> mDocument;

  // The @font-face rule backed FontFace objects in the FontFaceSet.
  nsTArray<FontFaceRecord> mRuleFaces;
};

}  // namespace mozilla::dom

#endif  // !defined(mozilla_dom_FontFaceSetDocumentImpl_h)