| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are met: | |
| 6 * | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 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 | |
| 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 | |
| 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 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 | |
| 23 * DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef SKY_ENGINE_CORE_CSS_FONTFACESET_H_ | |
| 27 #define SKY_ENGINE_CORE_CSS_FONTFACESET_H_ | |
| 28 | |
| 29 #include "sky/engine/core/css/FontFace.h" | |
| 30 #include "sky/engine/core/dom/ActiveDOMObject.h" | |
| 31 #include "sky/engine/core/events/EventListener.h" | |
| 32 #include "sky/engine/core/events/EventTarget.h" | |
| 33 #include "sky/engine/platform/AsyncMethodRunner.h" | |
| 34 #include "sky/engine/platform/RefCountedSupplement.h" | |
| 35 #include "sky/engine/wtf/PassRefPtr.h" | |
| 36 #include "sky/engine/wtf/RefCounted.h" | |
| 37 #include "sky/engine/wtf/Vector.h" | |
| 38 | |
| 39 // Mac OS X 10.6 SDK defines check() macro that interfares with our check() meth
od | |
| 40 #ifdef check | |
| 41 #undef check | |
| 42 #endif | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 class CSSFontFace; | |
| 47 class CSSFontFaceSource; | |
| 48 class CSSFontSelector; | |
| 49 class Dictionary; | |
| 50 class Document; | |
| 51 class ExceptionState; | |
| 52 class Font; | |
| 53 class FontFaceCache; | |
| 54 class FontResource; | |
| 55 class ExecutionContext; | |
| 56 | |
| 57 class FontFaceSet final : public RefCountedSupplement<Document, FontFaceSet>, pu
blic ActiveDOMObject, public EventTargetWithInlineData { | |
| 58 DEFINE_EVENT_TARGET_REFCOUNTING(RefCounted<FontFaceSet>); | |
| 59 typedef RefCountedSupplement<Document, FontFaceSet> SupplementType; | |
| 60 DEFINE_WRAPPERTYPEINFO(); | |
| 61 public: | |
| 62 virtual ~FontFaceSet(); | |
| 63 | |
| 64 bool check(const String& font, const String& text, ExceptionState&); | |
| 65 | |
| 66 void add(FontFace*, ExceptionState&); | |
| 67 void clear(); | |
| 68 bool remove(FontFace*, ExceptionState&); | |
| 69 bool has(FontFace*, ExceptionState&) const; | |
| 70 | |
| 71 unsigned long size() const; | |
| 72 AtomicString status() const; | |
| 73 | |
| 74 virtual ExecutionContext* executionContext() const override; | |
| 75 virtual const AtomicString& interfaceName() const override; | |
| 76 | |
| 77 Document* document() const; | |
| 78 | |
| 79 void didLayout(); | |
| 80 void beginFontLoading(FontFace*); | |
| 81 void fontLoaded(FontFace*); | |
| 82 void loadError(FontFace*); | |
| 83 | |
| 84 // ActiveDOMObject | |
| 85 virtual void suspend() override; | |
| 86 virtual void resume() override; | |
| 87 virtual void stop() override; | |
| 88 | |
| 89 static PassRefPtr<FontFaceSet> from(Document&); | |
| 90 static void didLayout(Document&); | |
| 91 | |
| 92 void addFontFacesToFontFaceCache(FontFaceCache*, CSSFontSelector*); | |
| 93 | |
| 94 private: | |
| 95 static PassRefPtr<FontFaceSet> create(Document& document) | |
| 96 { | |
| 97 return adoptRef(new FontFaceSet(document)); | |
| 98 } | |
| 99 | |
| 100 class FontLoadHistogram { | |
| 101 public: | |
| 102 enum Status { NoWebFonts, HadBlankText, DidNotHaveBlankText, Reported }; | |
| 103 FontLoadHistogram() : m_status(NoWebFonts), m_count(0), m_recorded(false
) { } | |
| 104 void incrementCount() { m_count++; } | |
| 105 void updateStatus(FontFace*); | |
| 106 void record(); | |
| 107 | |
| 108 private: | |
| 109 Status m_status; | |
| 110 int m_count; | |
| 111 bool m_recorded; | |
| 112 }; | |
| 113 | |
| 114 FontFaceSet(Document&); | |
| 115 | |
| 116 bool hasLoadedFonts() const { return !m_loadedFonts.isEmpty() || !m_failedFo
nts.isEmpty(); } | |
| 117 | |
| 118 bool inActiveDocumentContext() const; | |
| 119 void addToLoadingFonts(PassRefPtr<FontFace>); | |
| 120 void removeFromLoadingFonts(PassRefPtr<FontFace>); | |
| 121 void fireLoadingEvent(); | |
| 122 void fireDoneEventIfPossible(); | |
| 123 bool resolveFontStyle(const String&, Font&); | |
| 124 void handlePendingEventsAndPromisesSoon(); | |
| 125 void handlePendingEventsAndPromises(); | |
| 126 const ListHashSet<RefPtr<FontFace> >& cssConnectedFontFaceList() const; | |
| 127 bool isCSSConnectedFontFace(FontFace*) const; | |
| 128 | |
| 129 HashSet<RefPtr<FontFace> > m_loadingFonts; | |
| 130 bool m_shouldFireLoadingEvent; | |
| 131 FontFaceArray m_loadedFonts; | |
| 132 FontFaceArray m_failedFonts; | |
| 133 ListHashSet<RefPtr<FontFace> > m_nonCSSConnectedFaces; | |
| 134 | |
| 135 AsyncMethodRunner<FontFaceSet> m_asyncRunner; | |
| 136 | |
| 137 FontLoadHistogram m_histogram; | |
| 138 }; | |
| 139 | |
| 140 } // namespace blink | |
| 141 | |
| 142 #endif // SKY_ENGINE_CORE_CSS_FONTFACESET_H_ | |
| OLD | NEW |