tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FontFace.h (4500B)


      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_FontFace_h
      8 #define mozilla_dom_FontFace_h
      9 
     10 #include "gfxUserFontSet.h"
     11 #include "mozilla/GlobalTeardownObserver.h"
     12 #include "mozilla/ServoStyleConsts.h"
     13 #include "mozilla/dom/FontFaceBinding.h"
     14 #include "nsWrapperCache.h"
     15 
     16 class gfxFontFaceBufferSource;
     17 class nsIGlobalObject;
     18 
     19 namespace mozilla {
     20 struct CSSFontFaceDescriptors;
     21 class PostTraversalTask;
     22 struct StyleLockedFontFaceRule;
     23 
     24 namespace dom {
     25 class CSSFontFaceRule;
     26 class FontFaceBufferSource;
     27 struct FontFaceDescriptors;
     28 class FontFaceImpl;
     29 class FontFaceSet;
     30 class FontFaceSetImpl;
     31 class Promise;
     32 class UTF8StringOrArrayBufferOrArrayBufferView;
     33 
     34 enum class FontFaceLoadedRejectReason : uint8_t { Syntax, Network };
     35 struct FontFaceLoadedRejection {
     36  const FontFaceLoadedRejectReason mReason;
     37  nsCString mMessage;
     38 };
     39 
     40 class FontFace final : public GlobalTeardownObserver, public nsWrapperCache {
     41  friend class mozilla::PostTraversalTask;
     42 
     43 public:
     44  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     45  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)
     46 
     47  void DisconnectFromOwner() final;
     48 
     49  nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
     50  JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
     51 
     52  static already_AddRefed<FontFace> CreateForRule(
     53      nsIGlobalObject* aGlobal, FontFaceSet* aFontFaceSet,
     54      StyleLockedFontFaceRule* aRule);
     55 
     56  // Web IDL
     57  static already_AddRefed<FontFace> Constructor(
     58      const GlobalObject& aGlobal, const nsACString& aFamily,
     59      const UTF8StringOrArrayBufferOrArrayBufferView& aSource,
     60      const FontFaceDescriptors& aDescriptors, ErrorResult& aRV);
     61 
     62  void GetFamily(nsACString& aResult);
     63  void SetFamily(const nsACString& aValue, ErrorResult& aRv);
     64  void GetStyle(nsACString& aResult);
     65  void SetStyle(const nsACString& aValue, ErrorResult& aRv);
     66  void GetWeight(nsACString& aResult);
     67  void SetWeight(const nsACString& aValue, ErrorResult& aRv);
     68  void GetStretch(nsACString& aResult);
     69  void SetStretch(const nsACString& aValue, ErrorResult& aRv);
     70  void GetUnicodeRange(nsACString& aResult);
     71  void SetUnicodeRange(const nsACString& aValue, ErrorResult& aRv);
     72  void GetVariant(nsACString& aResult);
     73  void SetVariant(const nsACString& aValue, ErrorResult& aRv);
     74  void GetFeatureSettings(nsACString& aResult);
     75  void SetFeatureSettings(const nsACString& aValue, ErrorResult& aRv);
     76  void GetVariationSettings(nsACString& aResult);
     77  void SetVariationSettings(const nsACString& aValue, ErrorResult& aRv);
     78  void GetDisplay(nsACString& aResult);
     79  void SetDisplay(const nsACString& aValue, ErrorResult& aRv);
     80  void GetAscentOverride(nsACString& aResult);
     81  void SetAscentOverride(const nsACString& aValue, ErrorResult& aRv);
     82  void GetDescentOverride(nsACString& aResult);
     83  void SetDescentOverride(const nsACString& aValue, ErrorResult& aRv);
     84  void GetLineGapOverride(nsACString& aResult);
     85  void SetLineGapOverride(const nsACString& aValue, ErrorResult& aRv);
     86  void GetSizeAdjust(nsACString& aResult);
     87  void SetSizeAdjust(const nsACString& aValue, ErrorResult& aRv);
     88 
     89  FontFaceLoadStatus Status();
     90  Promise* Load(ErrorResult& aRv);
     91  Promise* GetLoaded(ErrorResult& aRv);
     92 
     93  FontFaceImpl* GetImpl() const { return mImpl; }
     94 
     95  void Destroy();
     96  void MaybeResolve();
     97 
     98  void MaybeReject(FontFaceLoadedRejectReason, nsCString&& aRejectMessage);
     99 
    100 private:
    101  explicit FontFace(nsIGlobalObject* aParent);
    102  ~FontFace();
    103 
    104  /**
    105   * Returns and takes ownership of the buffer storing the font data.
    106   */
    107  void TakeBuffer(uint8_t*& aBuffer, uint32_t& aLength);
    108 
    109  // Creates mLoaded if it doesn't already exist. It may immediately resolve or
    110  // reject mLoaded based on mStatus and mLoadedRejection.
    111  void EnsurePromise();
    112 
    113  RefPtr<FontFaceImpl> mImpl;
    114 
    115  // A Promise that is fulfilled once the font represented by this FontFace is
    116  // loaded, and is rejected if the load fails. This promise is created lazily
    117  // when JS asks for it.
    118  RefPtr<Promise> mLoaded;
    119 
    120  // Saves the rejection code for mLoaded if mLoaded hasn't been created yet.
    121  UniquePtr<FontFaceLoadedRejection> mLoadedRejection;
    122 };
    123 
    124 }  // namespace dom
    125 }  // namespace mozilla
    126 
    127 #endif  // !defined(mozilla_dom_FontFace_h)