OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
6 * | 6 * |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
23 * DAMAGE. | 23 * DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef FontFaceSet_h | 26 #ifndef FontFaceSet_h |
27 #define FontFaceSet_h | 27 #define FontFaceSet_h |
28 | 28 |
| 29 #include "bindings/v8/ScriptPromise.h" |
29 #include "core/css/FontFace.h" | 30 #include "core/css/FontFace.h" |
30 #include "core/dom/ActiveDOMObject.h" | 31 #include "core/dom/ActiveDOMObject.h" |
31 #include "core/dom/EventListener.h" | 32 #include "core/dom/EventListener.h" |
32 #include "core/dom/EventNames.h" | 33 #include "core/dom/EventNames.h" |
33 #include "core/dom/EventTarget.h" | 34 #include "core/dom/EventTarget.h" |
34 #include "core/html/VoidCallback.h" | |
35 #include "core/platform/Timer.h" | 35 #include "core/platform/Timer.h" |
36 #include "wtf/PassRefPtr.h" | 36 #include "wtf/PassRefPtr.h" |
37 #include "wtf/RefCounted.h" | 37 #include "wtf/RefCounted.h" |
38 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
39 | 39 |
| 40 // Mac OS X 10.6 SDK defines check() macro that interfares with our check() meth
od |
| 41 #ifdef check |
| 42 #undef check |
| 43 #endif |
| 44 |
40 namespace WebCore { | 45 namespace WebCore { |
41 | 46 |
42 class FontResource; | |
43 class CSSFontFaceSource; | 47 class CSSFontFaceSource; |
44 class Dictionary; | 48 class Dictionary; |
45 class Document; | 49 class Document; |
46 class Event; | 50 class Event; |
| 51 class ExceptionState; |
47 class Font; | 52 class Font; |
| 53 class FontResource; |
| 54 class FontsReadyPromiseResolver; |
| 55 class LoadFontPromiseResolver; |
48 class ScriptExecutionContext; | 56 class ScriptExecutionContext; |
49 | 57 |
50 class FontFaceSet : public RefCounted<FontFaceSet>, public ActiveDOMObject, publ
ic EventTarget { | 58 class FontFaceSet : public RefCounted<FontFaceSet>, public ActiveDOMObject, publ
ic EventTarget { |
51 public: | 59 public: |
52 static PassRefPtr<FontFaceSet> create(Document* document) | 60 static PassRefPtr<FontFaceSet> create(Document* document) |
53 { | 61 { |
54 return adoptRef<FontFaceSet>(new FontFaceSet(document)); | 62 return adoptRef<FontFaceSet>(new FontFaceSet(document)); |
55 } | 63 } |
56 virtual ~FontFaceSet(); | 64 virtual ~FontFaceSet(); |
57 | 65 |
58 DEFINE_ATTRIBUTE_EVENT_LISTENER(loading); | 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(loading); |
59 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone); | 67 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone); |
60 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingerror); | 68 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingerror); |
61 | 69 |
62 bool checkFont(const String&, const String&); | 70 Vector<RefPtr<FontFace> > match(const String& font, const String& text, Exce
ptionState&); |
63 void loadFont(const Dictionary&); | 71 bool check(const String& font, const String& text, ExceptionState&); |
64 void notifyWhenFontsReady(PassRefPtr<VoidCallback>); | 72 ScriptPromise load(const String& font, const String& text, ExceptionState&); |
| 73 ScriptPromise ready(); |
65 | 74 |
66 bool loading() const { return m_loadingCount > 0 || m_shouldFireDoneEvent; } | 75 AtomicString status() const; |
67 | 76 |
68 virtual ScriptExecutionContext* scriptExecutionContext() const; | 77 virtual ScriptExecutionContext* scriptExecutionContext() const; |
69 virtual const AtomicString& interfaceName() const; | 78 virtual const AtomicString& interfaceName() const; |
70 | 79 |
71 using RefCounted<FontFaceSet>::ref; | 80 using RefCounted<FontFaceSet>::ref; |
72 using RefCounted<FontFaceSet>::deref; | 81 using RefCounted<FontFaceSet>::deref; |
73 | 82 |
74 Document* document() const; | 83 Document* document() const; |
75 | 84 |
76 void didLayout(); | 85 void didLayout(); |
77 void beginFontLoading(FontFace*); | 86 void beginFontLoading(FontFace*); |
78 void fontLoaded(FontFace*); | 87 void fontLoaded(FontFace*); |
79 void loadError(FontFace*); | 88 void loadError(FontFace*); |
80 void scheduleCallback(PassRefPtr<VoidCallback>); | 89 void scheduleResolve(LoadFontPromiseResolver*); |
81 | 90 |
82 private: | 91 private: |
83 class FontLoadHistogram { | 92 class FontLoadHistogram { |
84 public: | 93 public: |
85 FontLoadHistogram() : m_count(0), m_recorded(false) { } | 94 FontLoadHistogram() : m_count(0), m_recorded(false) { } |
86 void incrementCount() { m_count++; } | 95 void incrementCount() { m_count++; } |
87 void record(); | 96 void record(); |
88 | 97 |
89 private: | 98 private: |
90 int m_count; | 99 int m_count; |
91 bool m_recorded; | 100 bool m_recorded; |
92 }; | 101 }; |
93 | 102 |
94 FontFaceSet(Document*); | 103 FontFaceSet(Document*); |
95 | 104 |
96 virtual void refEventTarget() { ref(); } | 105 virtual void refEventTarget() { ref(); } |
97 virtual void derefEventTarget() { deref(); } | 106 virtual void derefEventTarget() { deref(); } |
98 virtual EventTargetData* eventTargetData(); | 107 virtual EventTargetData* eventTargetData(); |
99 virtual EventTargetData* ensureEventTargetData(); | 108 virtual EventTargetData* ensureEventTargetData(); |
100 | 109 |
101 void scheduleEvent(PassRefPtr<Event>); | 110 void scheduleEvent(PassRefPtr<Event>); |
102 void queueDoneEvent(FontFace*); | 111 void queueDoneEvent(FontFace*); |
103 void firePendingEvents(); | 112 void firePendingEvents(); |
104 void firePendingCallbacks(); | 113 void resolvePendingLoadPromises(); |
105 void fireDoneEventIfPossible(); | 114 void fireDoneEventIfPossible(); |
106 bool resolveFontStyle(const String&, Font&); | 115 bool resolveFontStyle(const String&, Font&); |
107 void timerFired(Timer<FontFaceSet>*); | 116 void timerFired(Timer<FontFaceSet>*); |
108 | 117 |
109 EventTargetData m_eventTargetData; | 118 EventTargetData m_eventTargetData; |
110 unsigned m_loadingCount; | 119 unsigned m_loadingCount; |
111 Vector<RefPtr<Event> > m_pendingEvents; | 120 Vector<RefPtr<Event> > m_pendingEvents; |
112 Vector<RefPtr<VoidCallback> > m_pendingCallbacks; | 121 Vector<RefPtr<LoadFontPromiseResolver> > m_pendingLoadResolvers; |
113 Vector<RefPtr<VoidCallback> > m_fontsReadyCallbacks; | 122 Vector<OwnPtr<FontsReadyPromiseResolver> > m_readyResolvers; |
114 FontFaceArray m_loadedFonts; | 123 FontFaceArray m_loadedFonts; |
115 FontFaceArray m_failedFonts; | 124 FontFaceArray m_failedFonts; |
116 bool m_shouldFireDoneEvent; | 125 bool m_shouldFireDoneEvent; |
117 Timer<FontFaceSet> m_timer; | 126 Timer<FontFaceSet> m_timer; |
118 FontLoadHistogram m_histogram; | 127 FontLoadHistogram m_histogram; |
119 }; | 128 }; |
120 | 129 |
121 } // namespace WebCore | 130 } // namespace WebCore |
122 | 131 |
123 #endif // FontFaceSet_h | 132 #endif // FontFaceSet_h |
OLD | NEW |