19bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)/* 29bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 39bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * 49bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 59bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * modification, are permitted provided that the following conditions are 69bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * met: 79bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * 89bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 99bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * in the documentation and/or other materials provided with the 139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * distribution. 149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * this software without specific prior written permission. 179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * 189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) */ 309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#ifndef FontFace_h 329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#define FontFace_h 339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "bindings/v8/ScriptPromise.h" 355d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/CSSPropertyNames.h" 369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#include "core/css/CSSValue.h" 37d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/dom/DOMError.h" 38d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "platform/fonts/FontTraits.h" 399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#include "wtf/PassRefPtr.h" 409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#include "wtf/RefCounted.h" 419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#include "wtf/text/WTFString.h" 429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)namespace WebCore { 449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class CSSFontFace; 469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class CSSValueList; 479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class Dictionary; 489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class Document; 499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class ExceptionState; 50a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class FontFaceReadyPromiseResolver; 519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class StylePropertySet; 529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class StyleRuleFontFace; 539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 54f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liuclass FontFace : public RefCountedWillBeGarbageCollectedFinalized<FontFace> { 559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)public: 569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) enum LoadStatus { Unloaded, Loading, Loaded, Error }; 579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 58f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, PassRefPtr<ArrayBuffer> source, const Dictionary&, ExceptionState&); 59f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, PassRefPtr<ArrayBufferView>, const Dictionary&, ExceptionState&); 60f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, const String& source, const Dictionary&, ExceptionState&); 61f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu static PassRefPtrWillBeRawPtr<FontFace> create(Document*, const StyleRuleFontFace*); 629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ~FontFace(); 649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const AtomicString& family() const { return m_family; } 669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String style() const; 679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String weight() const; 689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String stretch() const; 699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String unicodeRange() const; 709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String variant() const; 719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String featureSettings() const; 729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: Changing these attributes should affect font matching. 7409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setFamily(ExecutionContext*, const AtomicString& s, ExceptionState&) { m_family = s; } 7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setStyle(ExecutionContext*, const String&, ExceptionState&); 7609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setWeight(ExecutionContext*, const String&, ExceptionState&); 7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setStretch(ExecutionContext*, const String&, ExceptionState&); 7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setUnicodeRange(ExecutionContext*, const String&, ExceptionState&); 7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setVariant(ExecutionContext*, const String&, ExceptionState&); 8009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setFeatureSettings(ExecutionContext*, const String&, ExceptionState&); 819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) String status() const; 83d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) ScriptPromise loaded(ScriptState* scriptState) { return fontStatusPromise(scriptState); } 849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 85d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) ScriptPromise load(ScriptState*); 86a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LoadStatus loadStatus() const { return m_status; } 88a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setLoadStatus(LoadStatus); 89d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DOMError* error() const { return m_error.get(); } 90d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) FontTraits traits() const; 9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) CSSFontFace* cssFontFace() { return m_cssFontFace.get(); } 929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 93d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void trace(Visitor*); 94d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 95d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) bool hadBlankText() const; 96d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 97323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) class LoadFontCallback : public RefCountedWillBeGarbageCollectedFinalized<LoadFontCallback> { 9843e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) public: 9943e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) virtual ~LoadFontCallback() { } 10043e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) virtual void notifyLoaded(FontFace*) = 0; 10143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) virtual void notifyError(FontFace*) = 0; 102323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) virtual void trace(Visitor*) { } 10343e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) }; 104323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) void loadWithCallback(PassRefPtrWillBeRawPtr<LoadFontCallback>, ExecutionContext*); 10543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) 1069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)private: 107d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) FontFace(); 1089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 109d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void initCSSFontFace(Document*, PassRefPtrWillBeRawPtr<CSSValue> src); 110d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void initCSSFontFace(const unsigned char* data, unsigned size); 11109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setPropertyFromString(const Document*, const String&, CSSPropertyID, ExceptionState&); 112d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) bool setPropertyFromStyle(const StylePropertySet&, CSSPropertyID); 113d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) bool setPropertyValue(PassRefPtrWillBeRawPtr<CSSValue>, CSSPropertyID); 1149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool setFamilyValue(CSSValueList*); 115a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void resolveReadyPromises(); 11643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) void loadInternal(ExecutionContext*); 117d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) ScriptPromise fontStatusPromise(ScriptState*); 1189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 119a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) AtomicString m_family; 120d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_src; 121d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_style; 122d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_weight; 123d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_stretch; 124d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_unicodeRange; 125d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_variant; 126d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<CSSValue> m_featureSettings; 1279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LoadStatus m_status; 128d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<DOMError> m_error; 129a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 130a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) Vector<OwnPtr<FontFaceReadyPromiseResolver> > m_readyResolvers; 131f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu OwnPtrWillBeMember<CSSFontFace> m_cssFontFace; 132323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) WillBeHeapVector<RefPtrWillBeMember<LoadFontCallback> > m_callbacks; 1339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)}; 1349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 135f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liutypedef WillBeHeapVector<RefPtrWillBeMember<FontFace> > FontFaceArray; 1369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} // namespace WebCore 1389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#endif // FontFace_h 140