| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/css/FontFaceSet.h" | 27 #include "core/css/FontFaceSet.h" |
| 28 | 28 |
| 29 #include "RuntimeEnabledFeatures.h" | 29 #include "RuntimeEnabledFeatures.h" |
| 30 #include "bindings/v8/Dictionary.h" | 30 #include "bindings/v8/Dictionary.h" |
| 31 #include "bindings/v8/NewScriptState.h" | 31 #include "bindings/v8/NewScriptState.h" |
| 32 #include "bindings/v8/ScriptPromiseResolver.h" | 32 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
| 33 #include "core/css/CSSFontFaceLoadEvent.h" | 33 #include "core/css/CSSFontFaceLoadEvent.h" |
| 34 #include "core/css/CSSFontSelector.h" | 34 #include "core/css/CSSFontSelector.h" |
| 35 #include "core/css/parser/BisonCSSParser.h" | 35 #include "core/css/parser/BisonCSSParser.h" |
| 36 #include "core/css/CSSSegmentedFontFace.h" | 36 #include "core/css/CSSSegmentedFontFace.h" |
| 37 #include "core/css/FontFaceCache.h" | 37 #include "core/css/FontFaceCache.h" |
| 38 #include "core/css/StylePropertySet.h" | 38 #include "core/css/StylePropertySet.h" |
| 39 #include "core/css/resolver/StyleResolver.h" | 39 #include "core/css/resolver/StyleResolver.h" |
| 40 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
| 41 #include "core/dom/StyleEngine.h" | 41 #include "core/dom/StyleEngine.h" |
| 42 #include "core/frame/FrameView.h" | 42 #include "core/frame/FrameView.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 void loadFonts(ExecutionContext*); | 58 void loadFonts(ExecutionContext*); |
| 59 ScriptPromise promise() { return m_resolver->promise(); } | 59 ScriptPromise promise() { return m_resolver->promise(); } |
| 60 | 60 |
| 61 virtual void notifyLoaded(FontFace*) OVERRIDE; | 61 virtual void notifyLoaded(FontFace*) OVERRIDE; |
| 62 virtual void notifyError(FontFace*) OVERRIDE; | 62 virtual void notifyError(FontFace*) OVERRIDE; |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 LoadFontPromiseResolver(FontFaceArray faces, ExecutionContext* context) | 65 LoadFontPromiseResolver(FontFaceArray faces, ExecutionContext* context) |
| 66 : m_numLoading(faces.size()) | 66 : m_numLoading(faces.size()) |
| 67 , m_errorOccured(false) | 67 , m_errorOccured(false) |
| 68 , m_scriptState(NewScriptState::current(toIsolate(context))) | 68 , m_resolver(ScriptPromiseResolverWithContext::create(NewScriptState::cu
rrent(toIsolate(context)))) |
| 69 , m_resolver(ScriptPromiseResolver::create(context)) | |
| 70 { | 69 { |
| 71 m_fontFaces.swap(faces); | 70 m_fontFaces.swap(faces); |
| 72 } | 71 } |
| 73 | 72 |
| 74 FontFaceArray m_fontFaces; | 73 FontFaceArray m_fontFaces; |
| 75 int m_numLoading; | 74 int m_numLoading; |
| 76 bool m_errorOccured; | 75 bool m_errorOccured; |
| 77 RefPtr<NewScriptState> m_scriptState; | 76 RefPtr<ScriptPromiseResolverWithContext> m_resolver; |
| 78 RefPtr<ScriptPromiseResolver> m_resolver; | |
| 79 }; | 77 }; |
| 80 | 78 |
| 81 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) | 79 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) |
| 82 { | 80 { |
| 83 if (!m_numLoading) { | 81 if (!m_numLoading) { |
| 84 m_resolver->resolve(m_fontFaces); | 82 m_resolver->resolve(m_fontFaces); |
| 85 return; | 83 return; |
| 86 } | 84 } |
| 87 | 85 |
| 88 for (size_t i = 0; i < m_fontFaces.size(); i++) | 86 for (size_t i = 0; i < m_fontFaces.size(); i++) |
| 89 m_fontFaces[i]->loadWithCallback(this, context); | 87 m_fontFaces[i]->loadWithCallback(this, context); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void LoadFontPromiseResolver::notifyLoaded(FontFace* fontFace) | 90 void LoadFontPromiseResolver::notifyLoaded(FontFace* fontFace) |
| 93 { | 91 { |
| 94 m_numLoading--; | 92 m_numLoading--; |
| 95 if (m_numLoading || m_errorOccured) | 93 if (m_numLoading || m_errorOccured) |
| 96 return; | 94 return; |
| 97 | 95 |
| 98 NewScriptState::Scope scope(m_scriptState.get()); | |
| 99 m_resolver->resolve(m_fontFaces); | 96 m_resolver->resolve(m_fontFaces); |
| 100 } | 97 } |
| 101 | 98 |
| 102 void LoadFontPromiseResolver::notifyError(FontFace* fontFace) | 99 void LoadFontPromiseResolver::notifyError(FontFace* fontFace) |
| 103 { | 100 { |
| 104 m_numLoading--; | 101 m_numLoading--; |
| 105 if (!m_errorOccured) { | 102 if (!m_errorOccured) { |
| 106 m_errorOccured = true; | 103 m_errorOccured = true; |
| 107 NewScriptState::Scope scope(m_scriptState.get()); | |
| 108 m_resolver->reject(fontFace->error()); | 104 m_resolver->reject(fontFace->error()); |
| 109 } | 105 } |
| 110 } | 106 } |
| 111 | 107 |
| 112 class FontsReadyPromiseResolver { | 108 class FontsReadyPromiseResolver { |
| 113 public: | 109 public: |
| 114 static PassOwnPtr<FontsReadyPromiseResolver> create(ExecutionContext* contex
t) | 110 static PassOwnPtr<FontsReadyPromiseResolver> create(ExecutionContext* contex
t) |
| 115 { | 111 { |
| 116 return adoptPtr(new FontsReadyPromiseResolver(context)); | 112 return adoptPtr(new FontsReadyPromiseResolver(context)); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void resolve(PassRefPtr<FontFaceSet> fontFaceSet) | 115 void resolve(PassRefPtr<FontFaceSet> fontFaceSet) |
| 120 { | 116 { |
| 121 NewScriptState::Scope scope(m_scriptState.get()); | |
| 122 m_resolver->resolve(fontFaceSet); | 117 m_resolver->resolve(fontFaceSet); |
| 123 } | 118 } |
| 124 | 119 |
| 125 ScriptPromise promise() { return m_resolver->promise(); } | 120 ScriptPromise promise() { return m_resolver->promise(); } |
| 126 | 121 |
| 127 private: | 122 private: |
| 128 FontsReadyPromiseResolver(ExecutionContext* context) | 123 FontsReadyPromiseResolver(ExecutionContext* context) |
| 129 : m_scriptState(NewScriptState::current(toIsolate(context))) | 124 : m_resolver(ScriptPromiseResolverWithContext::create(NewScriptState::cu
rrent(toIsolate(context)))) |
| 130 , m_resolver(ScriptPromiseResolver::create(context)) | |
| 131 { | 125 { |
| 132 } | 126 } |
| 133 | 127 |
| 134 RefPtr<NewScriptState> m_scriptState; | 128 RefPtr<ScriptPromiseResolverWithContext> m_resolver; |
| 135 RefPtr<ScriptPromiseResolver> m_resolver; | |
| 136 }; | 129 }; |
| 137 | 130 |
| 138 FontFaceSet::FontFaceSet(Document& document) | 131 FontFaceSet::FontFaceSet(Document& document) |
| 139 : ActiveDOMObject(&document) | 132 : ActiveDOMObject(&document) |
| 140 , m_shouldFireLoadingEvent(false) | 133 , m_shouldFireLoadingEvent(false) |
| 141 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) | 134 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) |
| 142 { | 135 { |
| 143 suspendIfNeeded(); | 136 suspendIfNeeded(); |
| 144 } | 137 } |
| 145 | 138 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 fonts->didLayout(); | 565 fonts->didLayout(); |
| 573 } | 566 } |
| 574 | 567 |
| 575 #if ENABLE(OILPAN) | 568 #if ENABLE(OILPAN) |
| 576 void FontFaceSet::trace(Visitor* visitor) | 569 void FontFaceSet::trace(Visitor* visitor) |
| 577 { | 570 { |
| 578 } | 571 } |
| 579 #endif | 572 #endif |
| 580 | 573 |
| 581 } // namespace WebCore | 574 } // namespace WebCore |
| OLD | NEW |