| 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 27 matching lines...) Expand all Loading... |
| 38 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 39 #include "core/page/FrameView.h" | 39 #include "core/page/FrameView.h" |
| 40 | 40 |
| 41 namespace WebCore { | 41 namespace WebCore { |
| 42 | 42 |
| 43 static const int defaultFontSize = 10; | 43 static const int defaultFontSize = 10; |
| 44 static const char* const defaultFontFamily = "sans-serif"; | 44 static const char* const defaultFontFamily = "sans-serif"; |
| 45 | 45 |
| 46 class LoadFontCallback : public CSSSegmentedFontFace::LoadFontCallback { | 46 class LoadFontCallback : public CSSSegmentedFontFace::LoadFontCallback { |
| 47 public: | 47 public: |
| 48 static PassRefPtr<LoadFontCallback> create(int numLoading, PassRefPtr<VoidCa
llback> loadCallback, PassRefPtr<VoidCallback> errorCallback) | 48 static Result<LoadFontCallback> create(int numLoading, PassRefPtr<VoidCallba
ck> loadCallback, PassRefPtr<VoidCallback> errorCallback) |
| 49 { | 49 { |
| 50 return adoptRef<LoadFontCallback>(new LoadFontCallback(numLoading, loadC
allback, errorCallback)); | 50 return adopt(new LoadFontCallback(numLoading, loadCallback, errorCallbac
k)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static PassRefPtr<LoadFontCallback> createFromParams(const Dictionary& param
s, const FontFamily& family) | 53 static Result<LoadFontCallback> createFromParams(const Dictionary& params, c
onst FontFamily& family) |
| 54 { | 54 { |
| 55 RefPtr<VoidCallback> onsuccess; | 55 RefPtr<VoidCallback> onsuccess; |
| 56 RefPtr<VoidCallback> onerror; | 56 RefPtr<VoidCallback> onerror; |
| 57 params.get("onsuccess", onsuccess); | 57 params.get("onsuccess", onsuccess); |
| 58 params.get("onerror", onerror); | 58 params.get("onerror", onerror); |
| 59 if (!onsuccess && !onerror) | 59 if (!onsuccess && !onerror) |
| 60 return 0; | 60 return nullptr; |
| 61 int numFamilies = 0; | 61 int numFamilies = 0; |
| 62 for (const FontFamily* f = &family; f; f = f->next()) | 62 for (const FontFamily* f = &family; f; f = f->next()) |
| 63 numFamilies++; | 63 numFamilies++; |
| 64 return LoadFontCallback::create(numFamilies, onsuccess, onerror); | 64 return LoadFontCallback::create(numFamilies, onsuccess, onerror); |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void notifyLoaded(CSSSegmentedFontFace*) OVERRIDE; | 67 virtual void notifyLoaded(Handle<CSSSegmentedFontFace>) OVERRIDE; |
| 68 virtual void notifyError(CSSSegmentedFontFace*) OVERRIDE; | 68 virtual void notifyError(Handle<CSSSegmentedFontFace>) OVERRIDE; |
| 69 void loaded(Document*); | 69 void loaded(Document*); |
| 70 void error(Document*); | 70 void error(Document*); |
| 71 |
| 72 virtual void accept(Visitor*) const { } |
| 73 |
| 71 private: | 74 private: |
| 72 LoadFontCallback(int numLoading, PassRefPtr<VoidCallback> loadCallback, Pass
RefPtr<VoidCallback> errorCallback) | 75 LoadFontCallback(int numLoading, PassRefPtr<VoidCallback> loadCallback, Pass
RefPtr<VoidCallback> errorCallback) |
| 73 : m_numLoading(numLoading) | 76 : m_numLoading(numLoading) |
| 74 , m_errorOccured(false) | 77 , m_errorOccured(false) |
| 75 , m_loadCallback(loadCallback) | 78 , m_loadCallback(loadCallback) |
| 76 , m_errorCallback(errorCallback) | 79 , m_errorCallback(errorCallback) |
| 77 { } | 80 { } |
| 78 | 81 |
| 79 int m_numLoading; | 82 int m_numLoading; |
| 80 bool m_errorOccured; | 83 bool m_errorOccured; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 96 document->fontloader()->scheduleCallback(m_loadCallback.release()); | 99 document->fontloader()->scheduleCallback(m_loadCallback.release()); |
| 97 } | 100 } |
| 98 } | 101 } |
| 99 | 102 |
| 100 void LoadFontCallback::error(Document* document) | 103 void LoadFontCallback::error(Document* document) |
| 101 { | 104 { |
| 102 m_errorOccured = true; | 105 m_errorOccured = true; |
| 103 loaded(document); | 106 loaded(document); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void LoadFontCallback::notifyLoaded(CSSSegmentedFontFace* face) | 109 void LoadFontCallback::notifyLoaded(Handle<CSSSegmentedFontFace> face) |
| 107 { | 110 { |
| 108 loaded(face->fontSelector()->document()); | 111 loaded(face->fontSelector()->document()); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void LoadFontCallback::notifyError(CSSSegmentedFontFace* face) | 114 void LoadFontCallback::notifyError(Handle<CSSSegmentedFontFace> face) |
| 112 { | 115 { |
| 113 error(face->fontSelector()->document()); | 116 error(face->fontSelector()->document()); |
| 114 } | 117 } |
| 115 | 118 |
| 116 FontLoader::FontLoader(Document* document) | 119 FontLoader::FontLoader(Document* document) |
| 117 : ActiveDOMObject(document) | 120 : ActiveDOMObject(document) |
| 118 , m_document(document) | 121 , m_document(document) |
| 119 , m_loadingCount(0) | 122 , m_loadingCount(0) |
| 120 , m_timer(this, &FontLoader::timerFired) | 123 , m_timer(this, &FontLoader::timerFired) |
| 121 { | 124 { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 268 |
| 266 void FontLoader::loadFont(const Dictionary& params) | 269 void FontLoader::loadFont(const Dictionary& params) |
| 267 { | 270 { |
| 268 // FIXME: The text member of params is ignored. | 271 // FIXME: The text member of params is ignored. |
| 269 String fontString; | 272 String fontString; |
| 270 if (!params.get("font", fontString)) | 273 if (!params.get("font", fontString)) |
| 271 return; | 274 return; |
| 272 Font font; | 275 Font font; |
| 273 if (!resolveFontStyle(fontString, font)) | 276 if (!resolveFontStyle(fontString, font)) |
| 274 return; | 277 return; |
| 275 RefPtr<LoadFontCallback> callback = LoadFontCallback::createFromParams(param
s, font.family()); | 278 Handle<LoadFontCallback> callback = LoadFontCallback::createFromParams(param
s, font.family()); |
| 276 | 279 |
| 280 Handle<CSSSegmentedFontFace> face; |
| 277 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 281 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
| 278 CSSSegmentedFontFace* face = m_document->styleResolver()->fontSelector()
->getFontFace(font.fontDescription(), f->family()); | 282 face = m_document->styleResolver()->fontSelector()->getFontFace(font.fon
tDescription(), f->family()); |
| 279 if (!face) { | 283 if (!face) { |
| 280 if (callback) | 284 if (callback) |
| 281 callback->error(m_document); | 285 callback->error(m_document); |
| 282 continue; | 286 continue; |
| 283 } | 287 } |
| 284 face->loadFont(font.fontDescription(), callback); | 288 face->loadFont(font.fontDescription(), callback); |
| 285 } | 289 } |
| 286 } | 290 } |
| 287 | 291 |
| 288 bool FontLoader::checkFont(const String& fontString, const String&) | 292 bool FontLoader::checkFont(const String& fontString, const String&) |
| 289 { | 293 { |
| 290 // FIXME: The second parameter (text) is ignored. | 294 // FIXME: The second parameter (text) is ignored. |
| 291 Font font; | 295 Font font; |
| 292 if (!resolveFontStyle(fontString, font)) | 296 if (!resolveFontStyle(fontString, font)) |
| 293 return false; | 297 return false; |
| 298 Handle<CSSSegmentedFontFace> face; |
| 294 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 299 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
| 295 CSSSegmentedFontFace* face = m_document->styleResolver()->fontSelector()
->getFontFace(font.fontDescription(), f->family()); | 300 face = m_document->styleResolver()->fontSelector()->getFontFace(font.fon
tDescription(), f->family()); |
| 296 if (!face || !face->checkFont()) | 301 if (!face || !face->checkFont()) |
| 297 return false; | 302 return false; |
| 298 } | 303 } |
| 299 return true; | 304 return true; |
| 300 } | 305 } |
| 301 | 306 |
| 302 static void applyPropertyToCurrentStyle(StyleResolver* styleResolver, CSSPropert
yID id, const Handle<StylePropertySet>& parsedStyle) | 307 static void applyPropertyToCurrentStyle(StyleResolver* styleResolver, CSSPropert
yID id, const Handle<StylePropertySet>& parsedStyle) |
| 303 { | 308 { |
| 304 styleResolver->applyPropertyToCurrentStyle(id, Handle<CSSValue>(parsedStyle-
>getPropertyCSSValue(id)).raw()); | 309 styleResolver->applyPropertyToCurrentStyle(id, Handle<CSSValue>(parsedStyle-
>getPropertyCSSValue(id)).raw()); |
| 305 } | 310 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontSize, parsedStyle)
; | 349 applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontSize, parsedStyle)
; |
| 345 styleResolver->updateFont(); | 350 styleResolver->updateFont(); |
| 346 applyPropertyToCurrentStyle(styleResolver, CSSPropertyLineHeight, parsedStyl
e); | 351 applyPropertyToCurrentStyle(styleResolver, CSSPropertyLineHeight, parsedStyl
e); |
| 347 | 352 |
| 348 font = style->font(); | 353 font = style->font(); |
| 349 font.update(styleResolver->fontSelector()); | 354 font.update(styleResolver->fontSelector()); |
| 350 return true; | 355 return true; |
| 351 } | 356 } |
| 352 | 357 |
| 353 } // namespace WebCore | 358 } // namespace WebCore |
| OLD | NEW |