| 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 29 matching lines...) Expand all Loading... |
| 40 #include "core/frame/FrameView.h" | 40 #include "core/frame/FrameView.h" |
| 41 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
| 42 #include "core/style/StyleInheritedData.h" | 42 #include "core/style/StyleInheritedData.h" |
| 43 #include "platform/Histogram.h" | 43 #include "platform/Histogram.h" |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 static const int defaultFontSize = 10; | 47 static const int defaultFontSize = 10; |
| 48 static const char defaultFontFamily[] = "sans-serif"; | 48 static const char defaultFontFamily[] = "sans-serif"; |
| 49 | 49 |
| 50 class LoadFontPromiseResolver final : public FontFace::LoadFontCallback { | 50 class LoadFontPromiseResolver final : public GarbageCollectedFinalized<LoadFontP
romiseResolver>, public FontFace::LoadFontCallback { |
| 51 USING_GARBAGE_COLLECTED_MIXIN(LoadFontPromiseResolver); |
| 51 public: | 52 public: |
| 52 static LoadFontPromiseResolver* create(FontFaceArray faces, ScriptState* scr
iptState) | 53 static LoadFontPromiseResolver* create(FontFaceArray faces, ScriptState* scr
iptState) |
| 53 { | 54 { |
| 54 return new LoadFontPromiseResolver(faces, scriptState); | 55 return new LoadFontPromiseResolver(faces, scriptState); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void loadFonts(ExecutionContext*); | 58 void loadFonts(ExecutionContext*); |
| 58 ScriptPromise promise() { return m_resolver->promise(); } | 59 ScriptPromise promise() { return m_resolver->promise(); } |
| 59 | 60 |
| 60 void notifyLoaded(FontFace*) override; | 61 void notifyLoaded(FontFace*) override; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 { | 212 { |
| 212 m_asyncRunner->stop(); | 213 m_asyncRunner->stop(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void FontFaceSet::beginFontLoading(FontFace* fontFace) | 216 void FontFaceSet::beginFontLoading(FontFace* fontFace) |
| 216 { | 217 { |
| 217 m_histogram.incrementCount(); | 218 m_histogram.incrementCount(); |
| 218 addToLoadingFonts(fontFace); | 219 addToLoadingFonts(fontFace); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void FontFaceSet::fontLoaded(FontFace* fontFace) | 222 void FontFaceSet::notifyLoaded(FontFace* fontFace) |
| 222 { | 223 { |
| 223 m_histogram.updateStatus(fontFace); | 224 m_histogram.updateStatus(fontFace); |
| 224 m_loadedFonts.append(fontFace); | 225 m_loadedFonts.append(fontFace); |
| 225 removeFromLoadingFonts(fontFace); | 226 removeFromLoadingFonts(fontFace); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void FontFaceSet::loadError(FontFace* fontFace) | 229 void FontFaceSet::notifyError(FontFace* fontFace) |
| 229 { | 230 { |
| 230 m_histogram.updateStatus(fontFace); | 231 m_histogram.updateStatus(fontFace); |
| 231 m_failedFonts.append(fontFace); | 232 m_failedFonts.append(fontFace); |
| 232 removeFromLoadingFonts(fontFace); | 233 removeFromLoadingFonts(fontFace); |
| 233 } | 234 } |
| 234 | 235 |
| 235 size_t FontFaceSet::approximateBlankCharacterCount() const | 236 size_t FontFaceSet::approximateBlankCharacterCount() const |
| 236 { | 237 { |
| 237 size_t count = 0; | 238 size_t count = 0; |
| 238 for (auto& fontFace : m_loadingFonts) | 239 for (auto& fontFace : m_loadingFonts) |
| 239 count += fontFace->approximateBlankCharacterCount(); | 240 count += fontFace->approximateBlankCharacterCount(); |
| 240 return count; | 241 return count; |
| 241 } | 242 } |
| 242 | 243 |
| 243 void FontFaceSet::addToLoadingFonts(FontFace* fontFace) | 244 void FontFaceSet::addToLoadingFonts(FontFace* fontFace) |
| 244 { | 245 { |
| 245 if (!m_isLoading) { | 246 if (!m_isLoading) { |
| 246 m_isLoading = true; | 247 m_isLoading = true; |
| 247 m_shouldFireLoadingEvent = true; | 248 m_shouldFireLoadingEvent = true; |
| 248 if (m_ready->getState() != ReadyProperty::Pending) | 249 if (m_ready->getState() != ReadyProperty::Pending) |
| 249 m_ready->reset(); | 250 m_ready->reset(); |
| 250 handlePendingEventsAndPromisesSoon(); | 251 handlePendingEventsAndPromisesSoon(); |
| 251 } | 252 } |
| 252 m_loadingFonts.add(fontFace); | 253 m_loadingFonts.add(fontFace); |
| 254 fontFace->addCallback(this); |
| 253 } | 255 } |
| 254 | 256 |
| 255 void FontFaceSet::removeFromLoadingFonts(FontFace* fontFace) | 257 void FontFaceSet::removeFromLoadingFonts(FontFace* fontFace) |
| 256 { | 258 { |
| 257 m_loadingFonts.remove(fontFace); | 259 m_loadingFonts.remove(fontFace); |
| 258 if (m_loadingFonts.isEmpty()) | 260 if (m_loadingFonts.isEmpty()) |
| 259 handlePendingEventsAndPromisesSoon(); | 261 handlePendingEventsAndPromisesSoon(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) | 264 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 { | 549 { |
| 548 visitor->trace(m_ready); | 550 visitor->trace(m_ready); |
| 549 visitor->trace(m_loadingFonts); | 551 visitor->trace(m_loadingFonts); |
| 550 visitor->trace(m_loadedFonts); | 552 visitor->trace(m_loadedFonts); |
| 551 visitor->trace(m_failedFonts); | 553 visitor->trace(m_failedFonts); |
| 552 visitor->trace(m_nonCSSConnectedFaces); | 554 visitor->trace(m_nonCSSConnectedFaces); |
| 553 visitor->trace(m_asyncRunner); | 555 visitor->trace(m_asyncRunner); |
| 554 EventTargetWithInlineData::trace(visitor); | 556 EventTargetWithInlineData::trace(visitor); |
| 555 Supplement<Document>::trace(visitor); | 557 Supplement<Document>::trace(visitor); |
| 556 ActiveDOMObject::trace(visitor); | 558 ActiveDOMObject::trace(visitor); |
| 559 FontFace::LoadFontCallback::trace(visitor); |
| 557 } | 560 } |
| 558 | 561 |
| 559 } // namespace blink | 562 } // namespace blink |
| OLD | NEW |