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/html/VoidCallback.h" |
35 #include "core/platform/Timer.h" | 36 #include "core/platform/Timer.h" |
36 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
37 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
38 #include "wtf/Vector.h" | 39 #include "wtf/Vector.h" |
39 | 40 |
41 // Mac OS X 10.6 SDK defines check() macro that interfares with our check() meth od | |
42 #ifdef check | |
43 #undef check | |
44 #endif | |
45 | |
40 namespace WebCore { | 46 namespace WebCore { |
41 | 47 |
42 class FontResource; | |
43 class CSSFontFaceSource; | 48 class CSSFontFaceSource; |
44 class Dictionary; | 49 class Dictionary; |
45 class Document; | 50 class Document; |
46 class Event; | 51 class Event; |
52 class ExceptionState; | |
47 class Font; | 53 class Font; |
54 class FontResource; | |
55 class FontsReadyPromiseResolver; | |
56 class LoadFontPromiseResolver; | |
48 class ScriptExecutionContext; | 57 class ScriptExecutionContext; |
49 | 58 |
50 class FontFaceSet : public RefCounted<FontFaceSet>, public ActiveDOMObject, publ ic EventTarget { | 59 class FontFaceSet : public RefCounted<FontFaceSet>, public ActiveDOMObject, publ ic EventTarget { |
51 public: | 60 public: |
52 static PassRefPtr<FontFaceSet> create(Document* document) | 61 static PassRefPtr<FontFaceSet> create(Document* document) |
53 { | 62 { |
54 return adoptRef<FontFaceSet>(new FontFaceSet(document)); | 63 return adoptRef<FontFaceSet>(new FontFaceSet(document)); |
55 } | 64 } |
56 virtual ~FontFaceSet(); | 65 virtual ~FontFaceSet(); |
57 | 66 |
58 DEFINE_ATTRIBUTE_EVENT_LISTENER(loading); | 67 DEFINE_ATTRIBUTE_EVENT_LISTENER(loading); |
59 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone); | 68 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone); |
60 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingerror); | 69 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingerror); |
61 | 70 |
62 bool checkFont(const String&, const String&); | 71 Vector<RefPtr<FontFace> > match(const String& font, const String& text, Exce ptionState&); |
63 void loadFont(const Dictionary&); | 72 bool check(const String& font, const String& text, ExceptionState&); |
64 void notifyWhenFontsReady(PassRefPtr<VoidCallback>); | 73 ScriptPromise load(const String& font, const String& text, ExceptionState&); |
74 ScriptPromise ready(); | |
65 | 75 |
66 bool loading() const { return m_loadingCount > 0 || m_shouldFireDoneEvent; } | 76 String status() const { return (m_loadingCount > 0 || m_shouldFireDoneEvent) ? "loading" : "loaded"; } |
67 | 77 |
68 virtual ScriptExecutionContext* scriptExecutionContext() const; | 78 virtual ScriptExecutionContext* scriptExecutionContext() const; |
69 virtual const AtomicString& interfaceName() const; | 79 virtual const AtomicString& interfaceName() const; |
70 | 80 |
71 using RefCounted<FontFaceSet>::ref; | 81 using RefCounted<FontFaceSet>::ref; |
72 using RefCounted<FontFaceSet>::deref; | 82 using RefCounted<FontFaceSet>::deref; |
73 | 83 |
74 Document* document() const; | 84 Document* document() const; |
75 | 85 |
76 void didLayout(); | 86 void didLayout(); |
77 void beginFontLoading(FontFace*); | 87 void beginFontLoading(FontFace*); |
78 void fontLoaded(FontFace*); | 88 void fontLoaded(FontFace*); |
79 void loadError(FontFace*); | 89 void loadError(FontFace*); |
80 void scheduleCallback(PassRefPtr<VoidCallback>); | 90 void scheduleResolve(LoadFontPromiseResolver*); |
81 | 91 |
82 private: | 92 private: |
83 class FontLoadHistogram { | 93 class FontLoadHistogram { |
84 public: | 94 public: |
85 FontLoadHistogram() : m_count(0), m_recorded(false) { } | 95 FontLoadHistogram() : m_count(0), m_recorded(false) { } |
86 void incrementCount() { m_count++; } | 96 void incrementCount() { m_count++; } |
87 void record(); | 97 void record(); |
88 | 98 |
89 private: | 99 private: |
90 int m_count; | 100 int m_count; |
91 bool m_recorded; | 101 bool m_recorded; |
92 }; | 102 }; |
93 | 103 |
94 FontFaceSet(Document*); | 104 FontFaceSet(Document*); |
95 | 105 |
96 virtual void refEventTarget() { ref(); } | 106 virtual void refEventTarget() { ref(); } |
97 virtual void derefEventTarget() { deref(); } | 107 virtual void derefEventTarget() { deref(); } |
98 virtual EventTargetData* eventTargetData(); | 108 virtual EventTargetData* eventTargetData(); |
99 virtual EventTargetData* ensureEventTargetData(); | 109 virtual EventTargetData* ensureEventTargetData(); |
100 | 110 |
101 void scheduleEvent(PassRefPtr<Event>); | 111 void scheduleEvent(PassRefPtr<Event>); |
102 void queueDoneEvent(FontFace*); | 112 void queueDoneEvent(FontFace*); |
103 void firePendingEvents(); | 113 void firePendingEvents(); |
104 void firePendingCallbacks(); | 114 void resolvePendingLoadPromises(); |
105 void fireDoneEventIfPossible(); | 115 void fireDoneEventIfPossible(); |
106 bool resolveFontStyle(const String&, Font&); | 116 bool resolveFontStyle(const String&, Font&); |
107 void timerFired(Timer<FontFaceSet>*); | 117 void timerFired(Timer<FontFaceSet>*); |
108 | 118 |
109 EventTargetData m_eventTargetData; | 119 EventTargetData m_eventTargetData; |
110 unsigned m_loadingCount; | 120 unsigned m_loadingCount; |
111 Vector<RefPtr<Event> > m_pendingEvents; | 121 Vector<RefPtr<Event> > m_pendingEvents; |
112 Vector<RefPtr<VoidCallback> > m_pendingCallbacks; | 122 Vector<RefPtr<LoadFontPromiseResolver> > m_pendingLoadPromises; |
yhirano
2013/09/18 11:49:45
I don't think m_pendingLoadPromises is a right nam
Kunihiko Sakamoto
2013/09/19 01:14:26
Renamed to m_pendingLoadResolvers.
| |
113 Vector<RefPtr<VoidCallback> > m_fontsReadyCallbacks; | 123 Vector<OwnPtr<FontsReadyPromiseResolver> > m_readyPromises; |
yhirano
2013/09/18 11:49:45
ditto
Kunihiko Sakamoto
2013/09/19 01:14:26
Changed to m_readyResolvers.
| |
114 FontFaceArray m_loadedFonts; | 124 FontFaceArray m_loadedFonts; |
115 FontFaceArray m_failedFonts; | 125 FontFaceArray m_failedFonts; |
116 bool m_shouldFireDoneEvent; | 126 bool m_shouldFireDoneEvent; |
117 Timer<FontFaceSet> m_timer; | 127 Timer<FontFaceSet> m_timer; |
118 FontLoadHistogram m_histogram; | 128 FontLoadHistogram m_histogram; |
119 }; | 129 }; |
120 | 130 |
121 } // namespace WebCore | 131 } // namespace WebCore |
122 | 132 |
123 #endif // FontFaceSet_h | 133 #endif // FontFaceSet_h |
OLD | NEW |