2014-10-02 06:32:05 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_FontFace_h
|
|
|
|
#define mozilla_dom_FontFace_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/FontFaceBinding.h"
|
2014-10-02 06:32:06 +04:00
|
|
|
#include "gfxUserFontSet.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2016-08-17 04:37:48 +03:00
|
|
|
#include "nsCSSPropertyID.h"
|
2014-10-02 06:32:07 +04:00
|
|
|
#include "nsCSSValue.h"
|
2014-10-02 06:32:06 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2014-10-02 06:32:05 +04:00
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
class gfxFontFaceBufferSource;
|
2014-10-02 06:32:06 +04:00
|
|
|
class nsCSSFontFaceRule;
|
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
namespace mozilla {
|
2014-10-02 06:32:07 +04:00
|
|
|
struct CSSFontFaceDescriptors;
|
2014-10-02 06:32:05 +04:00
|
|
|
namespace dom {
|
2014-10-02 06:32:09 +04:00
|
|
|
class FontFaceBufferSource;
|
2014-10-02 06:32:05 +04:00
|
|
|
struct FontFaceDescriptors;
|
2014-10-02 06:32:08 +04:00
|
|
|
class FontFaceSet;
|
2014-10-02 06:32:05 +04:00
|
|
|
class Promise;
|
|
|
|
class StringOrArrayBufferOrArrayBufferView;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-10-02 06:32:05 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class FontFace final : public nsISupports,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache
|
2014-10-02 06:32:05 +04:00
|
|
|
{
|
2014-10-02 06:32:09 +04:00
|
|
|
friend class mozilla::dom::FontFaceBufferSource;
|
2014-10-02 06:32:06 +04:00
|
|
|
friend class Entry;
|
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
class Entry final : public gfxUserFontEntry {
|
2014-10-02 06:32:08 +04:00
|
|
|
friend class FontFace;
|
|
|
|
|
2014-10-02 06:32:06 +04:00
|
|
|
public:
|
|
|
|
Entry(gfxUserFontSet* aFontSet,
|
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
|
|
|
uint32_t aWeight,
|
|
|
|
int32_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-10-02 06:32:06 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
uint32_t aLanguageOverride,
|
2016-01-07 08:03:05 +03:00
|
|
|
gfxSparseBitSet* aUnicodeRanges,
|
|
|
|
uint8_t aFontDisplay)
|
2014-10-02 06:32:06 +04:00
|
|
|
: gfxUserFontEntry(aFontSet, aFontFaceSrcList, aWeight, aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
aStyle, aFeatureSettings, aLanguageOverride,
|
2016-01-07 08:03:05 +03:00
|
|
|
aUnicodeRanges, aFontDisplay) {}
|
2014-10-02 06:32:06 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetLoadState(UserFontLoadState aLoadState) override;
|
2015-10-16 09:10:14 +03:00
|
|
|
virtual void GetUserFontSets(nsTArray<gfxUserFontSet*>& aResult) override;
|
2016-02-02 18:36:30 +03:00
|
|
|
const AutoTArray<FontFace*,1>& GetFontFaces() { return mFontFaces; }
|
2014-10-02 06:32:06 +04:00
|
|
|
|
|
|
|
protected:
|
2014-10-02 06:32:08 +04:00
|
|
|
// The FontFace objects that use this user font entry. We need to store
|
|
|
|
// an array of these, not just a single pointer, since the user font
|
|
|
|
// cache can return the same entry for different FontFaces that have
|
|
|
|
// the same descriptor values and come from the same origin.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<FontFace*,1> mFontFaces;
|
2014-10-02 06:32:06 +04:00
|
|
|
};
|
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const { return mParent; }
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-10-02 06:32:05 +04:00
|
|
|
|
2014-10-09 11:03:56 +04:00
|
|
|
static already_AddRefed<FontFace>
|
2015-06-27 04:39:54 +03:00
|
|
|
CreateForRule(nsISupports* aGlobal, FontFaceSet* aFontFaceSet,
|
2014-10-09 11:03:56 +04:00
|
|
|
nsCSSFontFaceRule* aRule);
|
2014-10-02 06:32:06 +04:00
|
|
|
|
2014-10-02 06:32:07 +04:00
|
|
|
nsCSSFontFaceRule* GetRule() { return mRule; }
|
|
|
|
|
|
|
|
void GetDesc(nsCSSFontDesc aDescID, nsCSSValue& aResult) const;
|
|
|
|
|
2015-06-27 04:41:10 +03:00
|
|
|
gfxUserFontEntry* CreateUserFontEntry();
|
2014-10-02 06:32:08 +04:00
|
|
|
gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
|
|
|
|
void SetUserFontEntry(gfxUserFontEntry* aEntry);
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
/**
|
2015-10-16 09:10:14 +03:00
|
|
|
* Returns whether this object is in the specified FontFaceSet.
|
2014-10-02 06:32:09 +04:00
|
|
|
*/
|
2015-10-16 09:10:14 +03:00
|
|
|
bool IsInFontFaceSet(FontFaceSet* aFontFaceSet) const;
|
2014-10-02 06:32:08 +04:00
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
void AddFontFaceSet(FontFaceSet* aFontFaceSet);
|
|
|
|
void RemoveFontFaceSet(FontFaceSet* aFontFaceSet);
|
2014-10-02 06:32:09 +04:00
|
|
|
|
2014-10-02 06:32:08 +04:00
|
|
|
/**
|
|
|
|
* Gets the family name of the FontFace as a raw string (such as 'Times', as
|
|
|
|
* opposed to GetFamily, which returns a CSS-escaped string, such as
|
|
|
|
* '"Times"'). Returns whether a valid family name was available.
|
|
|
|
*/
|
|
|
|
bool GetFamilyName(nsString& aResult);
|
|
|
|
|
2014-10-02 06:32:08 +04:00
|
|
|
/**
|
|
|
|
* Returns whether this object is CSS-connected, i.e. reflecting an
|
|
|
|
* @font-face rule.
|
|
|
|
*/
|
2014-10-02 06:32:10 +04:00
|
|
|
bool HasRule() const { return mRule; }
|
2014-10-02 06:32:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Breaks the connection between this FontFace and its @font-face rule.
|
|
|
|
*/
|
|
|
|
void DisconnectFromRule();
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
/**
|
|
|
|
* Returns whether there is an ArrayBuffer or ArrayBufferView of font
|
|
|
|
* data.
|
|
|
|
*/
|
|
|
|
bool HasFontData() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a gfxFontFaceBufferSource to represent the font data
|
|
|
|
* in this object.
|
|
|
|
*/
|
|
|
|
already_AddRefed<gfxFontFaceBufferSource> CreateBufferSource();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a pointer to and the length of the font data stored in the
|
|
|
|
* ArrayBuffer or ArrayBufferView.
|
|
|
|
*/
|
|
|
|
bool GetData(uint8_t*& aBuffer, uint32_t& aLength);
|
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
// Web IDL
|
|
|
|
static already_AddRefed<FontFace>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aFamily,
|
|
|
|
const mozilla::dom::StringOrArrayBufferOrArrayBufferView& aSource,
|
|
|
|
const mozilla::dom::FontFaceDescriptors& aDescriptors,
|
|
|
|
ErrorResult& aRV);
|
|
|
|
|
|
|
|
void GetFamily(nsString& aResult);
|
|
|
|
void SetFamily(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
|
|
|
void GetStyle(nsString& aResult);
|
|
|
|
void SetStyle(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
|
|
|
void GetWeight(nsString& aResult);
|
|
|
|
void SetWeight(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
|
|
|
void GetStretch(nsString& aResult);
|
|
|
|
void SetStretch(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
|
|
|
void GetUnicodeRange(nsString& aResult);
|
|
|
|
void SetUnicodeRange(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
|
|
|
void GetVariant(nsString& aResult);
|
|
|
|
void SetVariant(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
|
|
|
void GetFeatureSettings(nsString& aResult);
|
|
|
|
void SetFeatureSettings(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
2016-01-07 08:03:05 +03:00
|
|
|
void GetDisplay(nsString& aResult);
|
|
|
|
void SetDisplay(const nsAString& aValue, mozilla::ErrorResult& aRv);
|
2014-10-02 06:32:05 +04:00
|
|
|
|
|
|
|
mozilla::dom::FontFaceLoadStatus Status();
|
2014-10-02 06:32:07 +04:00
|
|
|
mozilla::dom::Promise* Load(mozilla::ErrorResult& aRv);
|
|
|
|
mozilla::dom::Promise* GetLoaded(mozilla::ErrorResult& aRv);
|
2014-10-02 06:32:05 +04:00
|
|
|
|
|
|
|
private:
|
2015-06-27 04:39:54 +03:00
|
|
|
FontFace(nsISupports* aParent, FontFaceSet* aFontFaceSet);
|
2014-10-02 06:32:05 +04:00
|
|
|
~FontFace();
|
|
|
|
|
2015-03-27 13:13:21 +03:00
|
|
|
void InitializeSource(const StringOrArrayBufferOrArrayBufferView& aSource);
|
2014-10-02 06:32:09 +04:00
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
// Helper function for Load.
|
|
|
|
void DoLoad();
|
|
|
|
|
2014-10-02 06:32:07 +04:00
|
|
|
/**
|
|
|
|
* Parses a @font-face descriptor value, storing the result in aResult.
|
|
|
|
* Returns whether the parsing was successful.
|
|
|
|
*/
|
|
|
|
bool ParseDescriptor(nsCSSFontDesc aDescID, const nsAString& aString,
|
|
|
|
nsCSSValue& aResult);
|
|
|
|
|
|
|
|
// Helper function for the descriptor setter methods.
|
|
|
|
void SetDescriptor(nsCSSFontDesc aFontDesc,
|
|
|
|
const nsAString& aValue,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
/**
|
|
|
|
* Sets all of the descriptor values in mDescriptors using values passed
|
|
|
|
* to the JS constructor.
|
|
|
|
*/
|
|
|
|
bool SetDescriptors(const nsAString& aFamily,
|
|
|
|
const FontFaceDescriptors& aDescriptors);
|
|
|
|
|
2014-10-02 06:32:06 +04:00
|
|
|
/**
|
|
|
|
* Sets the current loading status.
|
|
|
|
*/
|
|
|
|
void SetStatus(mozilla::dom::FontFaceLoadStatus aStatus);
|
|
|
|
|
2014-10-02 06:32:07 +04:00
|
|
|
void GetDesc(nsCSSFontDesc aDescID,
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID aPropID,
|
2014-10-02 06:32:07 +04:00
|
|
|
nsString& aResult) const;
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
/**
|
|
|
|
* Returns and takes ownership of the buffer storing the font data.
|
|
|
|
*/
|
|
|
|
void TakeBuffer(uint8_t*& aBuffer, uint32_t& aLength);
|
|
|
|
|
2016-10-14 02:01:52 +03:00
|
|
|
// Acts like mLoaded->MaybeReject(aResult), except it doesn't create mLoaded
|
|
|
|
// if it doesn't already exist.
|
|
|
|
void Reject(nsresult aResult);
|
|
|
|
|
|
|
|
// Creates mLoaded if it doesn't already exist. It may immediately resolve or
|
|
|
|
// reject mLoaded based on mStatus and mLoadedRejection.
|
|
|
|
void EnsurePromise();
|
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2014-10-02 06:32:06 +04:00
|
|
|
|
2016-10-14 02:01:52 +03:00
|
|
|
// A Promise that is fulfilled once the font represented by this FontFace is
|
|
|
|
// loaded, and is rejected if the load fails. This promise is created lazily
|
|
|
|
// when JS asks for it.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::Promise> mLoaded;
|
2014-10-02 06:32:06 +04:00
|
|
|
|
2016-10-14 02:01:52 +03:00
|
|
|
// Saves the rejection code for mLoaded if mLoaded hasn't been created yet.
|
|
|
|
nsresult mLoadedRejection;
|
|
|
|
|
2014-10-02 06:32:06 +04:00
|
|
|
// The @font-face rule this FontFace object is reflecting, if it is a
|
2014-10-02 06:32:10 +04:00
|
|
|
// rule backed FontFace.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsCSSFontFaceRule> mRule;
|
2014-10-02 06:32:06 +04:00
|
|
|
|
2014-10-02 06:32:08 +04:00
|
|
|
// The FontFace object's user font entry. This is initially null, but is set
|
|
|
|
// during FontFaceSet::UpdateRules and when a FontFace is explicitly loaded.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Entry> mUserFontEntry;
|
2014-10-02 06:32:08 +04:00
|
|
|
|
2014-10-02 06:32:06 +04:00
|
|
|
// The current load status of the font represented by this FontFace.
|
|
|
|
// Note that we can't just reflect the value of the gfxUserFontEntry's
|
|
|
|
// status, since the spec sometimes requires us to go through the event
|
|
|
|
// loop before updating the status, rather than doing it immediately.
|
|
|
|
mozilla::dom::FontFaceLoadStatus mStatus;
|
2014-10-02 06:32:07 +04:00
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
// Represents where a FontFace's data is coming from.
|
|
|
|
enum SourceType {
|
|
|
|
eSourceType_FontFaceRule = 1,
|
|
|
|
eSourceType_URLs,
|
|
|
|
eSourceType_Buffer
|
|
|
|
};
|
|
|
|
|
|
|
|
// Where the font data for this FontFace is coming from.
|
|
|
|
SourceType mSourceType;
|
|
|
|
|
|
|
|
// If the FontFace was constructed with an ArrayBuffer(View), this is a
|
|
|
|
// copy of the data from it.
|
|
|
|
uint8_t* mSourceBuffer;
|
|
|
|
uint32_t mSourceBufferLength;
|
|
|
|
|
2014-10-02 06:32:07 +04:00
|
|
|
// The values corresponding to the font face descriptors, if we are not
|
2014-10-02 06:32:10 +04:00
|
|
|
// a rule backed FontFace object. For rule backed objects, we use
|
2014-10-02 06:32:07 +04:00
|
|
|
// the descriptors stored in mRule.
|
|
|
|
nsAutoPtr<mozilla::CSSFontFaceDescriptors> mDescriptors;
|
2014-10-02 06:32:08 +04:00
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
// The primary FontFaceSet this FontFace is associated with,
|
|
|
|
// regardless of whether it is currently "in" the set.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FontFaceSet> mFontFaceSet;
|
2014-10-02 06:32:08 +04:00
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
// Other FontFaceSets (apart from mFontFaceSet) that this FontFace
|
|
|
|
// appears in.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<FontFaceSet>> mOtherFontFaceSets;
|
2015-10-16 09:10:14 +03:00
|
|
|
|
|
|
|
// Whether this FontFace appears in mFontFaceSet.
|
2014-10-02 06:32:08 +04:00
|
|
|
bool mInFontFaceSet;
|
2014-10-02 06:32:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_FontFace_h)
|