Chromium Code Reviews| 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/core/v8/Iterable.h" | |
| 29 #include "bindings/core/v8/ScriptPromise.h" | 30 #include "bindings/core/v8/ScriptPromise.h" |
| 30 #include "core/css/FontFace.h" | 31 #include "core/css/FontFace.h" |
| 31 #include "core/css/FontFaceSetForEachCallback.h" | 32 #include "core/css/FontFaceSetForEachCallback.h" |
| 32 #include "core/dom/ActiveDOMObject.h" | 33 #include "core/dom/ActiveDOMObject.h" |
| 33 #include "core/events/EventListener.h" | 34 #include "core/events/EventListener.h" |
| 34 #include "core/events/EventTarget.h" | 35 #include "core/events/EventTarget.h" |
| 35 #include "platform/AsyncMethodRunner.h" | 36 #include "platform/AsyncMethodRunner.h" |
| 36 #include "platform/RefCountedSupplement.h" | 37 #include "platform/RefCountedSupplement.h" |
| 37 #include "wtf/Allocator.h" | 38 #include "wtf/Allocator.h" |
| 38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 50 class CSSFontFaceSource; | 51 class CSSFontFaceSource; |
| 51 class CSSFontSelector; | 52 class CSSFontSelector; |
| 52 class Dictionary; | 53 class Dictionary; |
| 53 class Document; | 54 class Document; |
| 54 class ExceptionState; | 55 class ExceptionState; |
| 55 class Font; | 56 class Font; |
| 56 class FontFaceCache; | 57 class FontFaceCache; |
| 57 class FontResource; | 58 class FontResource; |
| 58 class ExecutionContext; | 59 class ExecutionContext; |
| 59 | 60 |
| 61 using FontFaceSetIterable = PairIterable<RefPtrWillBeMember<FontFace>, RefPtrWil lBeMember<FontFace>>; | |
| 62 | |
| 60 #if ENABLE(OILPAN) | 63 #if ENABLE(OILPAN) |
| 61 class FontFaceSet final : public EventTargetWithInlineData, public HeapSupplemen t<Document>, public ActiveDOMObject { | 64 class FontFaceSet final : public EventTargetWithInlineData, public HeapSupplemen t<Document>, public ActiveDOMObject, public FontFaceSetIterable { |
| 62 USING_GARBAGE_COLLECTED_MIXIN(FontFaceSet); | 65 USING_GARBAGE_COLLECTED_MIXIN(FontFaceSet); |
| 63 using SupplementType = HeapSupplement<Document>; | 66 using SupplementType = HeapSupplement<Document>; |
| 64 #else | 67 #else |
| 65 class FontFaceSet final : public EventTargetWithInlineData, public RefCountedSup plement<Document, FontFaceSet>, public ActiveDOMObject { | 68 class FontFaceSet final : public EventTargetWithInlineData, public RefCountedSup plement<Document, FontFaceSet>, public ActiveDOMObject, public FontFaceSetIterab le { |
| 66 REFCOUNTED_EVENT_TARGET(FontFaceSet); | 69 REFCOUNTED_EVENT_TARGET(FontFaceSet); |
| 67 using SupplementType = RefCountedSupplement<Document, FontFaceSet>; | 70 using SupplementType = RefCountedSupplement<Document, FontFaceSet>; |
| 68 #endif | 71 #endif |
| 69 DEFINE_WRAPPERTYPEINFO(); | 72 DEFINE_WRAPPERTYPEINFO(); |
| 70 public: | 73 public: |
| 71 ~FontFaceSet() override; | 74 ~FontFaceSet() override; |
| 72 | 75 |
| 73 DEFINE_ATTRIBUTE_EVENT_LISTENER(loading); | 76 DEFINE_ATTRIBUTE_EVENT_LISTENER(loading); |
| 74 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone); | 77 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone); |
| 75 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingerror); | 78 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingerror); |
| 76 | 79 |
| 77 bool check(const String& font, const String& text, ExceptionState&); | 80 bool check(const String& font, const String& text, ExceptionState&); |
| 78 ScriptPromise load(ScriptState*, const String& font, const String& text); | 81 ScriptPromise load(ScriptState*, const String& font, const String& text); |
| 79 ScriptPromise ready(ScriptState*); | 82 ScriptPromise ready(ScriptState*); |
| 80 | 83 |
| 81 void add(FontFace*, ExceptionState&); | 84 void add(FontFace*, ExceptionState&); |
| 82 void clear(); | 85 void clear(); |
| 83 bool remove(FontFace*, ExceptionState&); | 86 bool remove(FontFace*, ExceptionState&); |
| 84 void forEach(FontFaceSetForEachCallback*, const ScriptValue& thisArg) const; | 87 bool hasForBinding(ScriptState*, FontFace*, ExceptionState&) const; |
| 85 void forEach(FontFaceSetForEachCallback*) const; | |
| 86 bool has(FontFace*, ExceptionState&) const; | |
| 87 | 88 |
| 88 unsigned long size() const; | 89 size_t size() const; |
| 89 AtomicString status() const; | 90 AtomicString status() const; |
| 90 | 91 |
| 91 ExecutionContext* executionContext() const override; | 92 ExecutionContext* executionContext() const override; |
| 92 const AtomicString& interfaceName() const override; | 93 const AtomicString& interfaceName() const override; |
| 93 | 94 |
| 94 Document* document() const; | 95 Document* document() const; |
| 95 | 96 |
| 96 void didLayout(); | 97 void didLayout(); |
| 97 void beginFontLoading(FontFace*); | 98 void beginFontLoading(FontFace*); |
| 98 void fontLoaded(FontFace*); | 99 void fontLoaded(FontFace*); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 109 void addFontFacesToFontFaceCache(FontFaceCache*, CSSFontSelector*); | 110 void addFontFacesToFontFaceCache(FontFaceCache*, CSSFontSelector*); |
| 110 | 111 |
| 111 DECLARE_VIRTUAL_TRACE(); | 112 DECLARE_VIRTUAL_TRACE(); |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 static PassRefPtrWillBeRawPtr<FontFaceSet> create(Document& document) | 115 static PassRefPtrWillBeRawPtr<FontFaceSet> create(Document& document) |
| 115 { | 116 { |
| 116 return adoptRefWillBeNoop(new FontFaceSet(document)); | 117 return adoptRefWillBeNoop(new FontFaceSet(document)); |
| 117 } | 118 } |
| 118 | 119 |
| 120 FontFaceSetIterable::IterationSource* startIteration(ScriptState*, Exception State&) override; | |
| 121 | |
| 122 class IterationSource final : public FontFaceSetIterable::IterationSource { | |
|
haraken
2015/10/19 07:13:08
Add WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED().
Takashi Toyoshima
2015/10/19 07:51:44
Done.
Any guideline to use the macro? Should I use
haraken
2015/10/19 07:56:05
Sorry, I noticed that FontFaceSetIterable::Iterati
| |
| 123 public: | |
| 124 explicit IterationSource(const WillBeHeapVector<RefPtrWillBeMember<FontF ace>>& fontFaces) | |
| 125 : m_index(0) | |
| 126 , m_fontFaces(fontFaces) { } | |
| 127 bool next(ScriptState*, RefPtrWillBeMember<FontFace>&, RefPtrWillBeMembe r<FontFace>&, ExceptionState&) override; | |
| 128 | |
| 129 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 130 { | |
| 131 visitor->trace(m_fontFaces); | |
| 132 FontFaceSetIterable::IterationSource::trace(visitor); | |
| 133 } | |
| 134 | |
| 135 private: | |
| 136 size_t m_index; | |
| 137 WillBeHeapVector<RefPtrWillBeMember<FontFace>> m_fontFaces; | |
| 138 }; | |
| 139 | |
| 119 class FontLoadHistogram { | 140 class FontLoadHistogram { |
| 120 DISALLOW_ALLOCATION(); | 141 DISALLOW_ALLOCATION(); |
| 121 public: | 142 public: |
| 122 enum Status { NoWebFonts, HadBlankText, DidNotHaveBlankText, Reported }; | 143 enum Status { NoWebFonts, HadBlankText, DidNotHaveBlankText, Reported }; |
| 123 FontLoadHistogram() : m_status(NoWebFonts), m_count(0), m_recorded(false ) { } | 144 FontLoadHistogram() : m_status(NoWebFonts), m_count(0), m_recorded(false ) { } |
| 124 void incrementCount() { m_count++; } | 145 void incrementCount() { m_count++; } |
| 125 void updateStatus(FontFace*); | 146 void updateStatus(FontFace*); |
| 126 void record(); | 147 void record(); |
| 127 | 148 |
| 128 private: | 149 private: |
| 129 Status m_status; | 150 Status m_status; |
| 130 int m_count; | 151 int m_count; |
| 131 bool m_recorded; | 152 bool m_recorded; |
| 132 }; | 153 }; |
| 133 | 154 |
| 134 FontFaceSet(Document&); | 155 FontFaceSet(Document&); |
| 135 | 156 |
| 136 bool inActiveDocumentContext() const; | 157 bool inActiveDocumentContext() const; |
| 137 void forEachInternal(FontFaceSetForEachCallback*, const ScriptValue* thisArg ) const; | |
| 138 void addToLoadingFonts(PassRefPtrWillBeRawPtr<FontFace>); | 158 void addToLoadingFonts(PassRefPtrWillBeRawPtr<FontFace>); |
| 139 void removeFromLoadingFonts(PassRefPtrWillBeRawPtr<FontFace>); | 159 void removeFromLoadingFonts(PassRefPtrWillBeRawPtr<FontFace>); |
| 140 void fireLoadingEvent(); | 160 void fireLoadingEvent(); |
| 141 void fireDoneEventIfPossible(); | 161 void fireDoneEventIfPossible(); |
| 142 bool resolveFontStyle(const String&, Font&); | 162 bool resolveFontStyle(const String&, Font&); |
| 143 void handlePendingEventsAndPromisesSoon(); | 163 void handlePendingEventsAndPromisesSoon(); |
| 144 void handlePendingEventsAndPromises(); | 164 void handlePendingEventsAndPromises(); |
| 145 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>& cssConnectedFontF aceList() const; | 165 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>& cssConnectedFontF aceList() const; |
| 146 bool isCSSConnectedFontFace(FontFace*) const; | 166 bool isCSSConnectedFontFace(FontFace*) const; |
| 147 bool shouldSignalReady() const; | 167 bool shouldSignalReady() const; |
| 148 | 168 |
| 149 using ReadyProperty = ScriptPromiseProperty<RawPtrWillBeMember<FontFaceSet>, RawPtrWillBeMember<FontFaceSet>, Member<DOMException>>; | 169 using ReadyProperty = ScriptPromiseProperty<RawPtrWillBeMember<FontFaceSet>, RawPtrWillBeMember<FontFaceSet>, Member<DOMException>>; |
| 150 | 170 |
| 151 WillBeHeapHashSet<RefPtrWillBeMember<FontFace>> m_loadingFonts; | 171 WillBeHeapHashSet<RefPtrWillBeMember<FontFace>> m_loadingFonts; |
| 152 bool m_shouldFireLoadingEvent; | 172 bool m_shouldFireLoadingEvent; |
| 153 bool m_isLoading; | 173 bool m_isLoading; |
| 154 PersistentWillBeMember<ReadyProperty> m_ready; | 174 PersistentWillBeMember<ReadyProperty> m_ready; |
| 155 FontFaceArray m_loadedFonts; | 175 FontFaceArray m_loadedFonts; |
| 156 FontFaceArray m_failedFonts; | 176 FontFaceArray m_failedFonts; |
| 157 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>> m_nonCSSConnectedFaces; | 177 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>> m_nonCSSConnectedFaces; |
| 158 | 178 |
| 159 AsyncMethodRunner<FontFaceSet> m_asyncRunner; | 179 AsyncMethodRunner<FontFaceSet> m_asyncRunner; |
| 160 | 180 |
| 161 FontLoadHistogram m_histogram; | 181 FontLoadHistogram m_histogram; |
| 162 }; | 182 }; |
| 163 | 183 |
| 164 } // namespace blink | 184 } // namespace blink |
| 165 | 185 |
| 166 #endif // FontFaceSet_h | 186 #endif // FontFaceSet_h |
| OLD | NEW |