| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 FontFace::LoadFontCallback { |
| 51 public: | 51 public: |
| 52 static RawPtr<LoadFontPromiseResolver> create(FontFaceArray faces, ScriptSta
te* scriptState) | 52 static LoadFontPromiseResolver* create(FontFaceArray faces, ScriptState* scr
iptState) |
| 53 { | 53 { |
| 54 return new LoadFontPromiseResolver(faces, scriptState); | 54 return new LoadFontPromiseResolver(faces, scriptState); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void loadFonts(ExecutionContext*); | 57 void loadFonts(ExecutionContext*); |
| 58 ScriptPromise promise() { return m_resolver->promise(); } | 58 ScriptPromise promise() { return m_resolver->promise(); } |
| 59 | 59 |
| 60 void notifyLoaded(FontFace*) override; | 60 void notifyLoaded(FontFace*) override; |
| 61 void notifyError(FontFace*) override; | 61 void notifyError(FontFace*) override; |
| 62 | 62 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 removeFromLoadingFonts(fontFace); | 228 removeFromLoadingFonts(fontFace); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void FontFaceSet::loadError(FontFace* fontFace) | 231 void FontFaceSet::loadError(FontFace* fontFace) |
| 232 { | 232 { |
| 233 m_histogram.updateStatus(fontFace); | 233 m_histogram.updateStatus(fontFace); |
| 234 m_failedFonts.append(fontFace); | 234 m_failedFonts.append(fontFace); |
| 235 removeFromLoadingFonts(fontFace); | 235 removeFromLoadingFonts(fontFace); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void FontFaceSet::addToLoadingFonts(RawPtr<FontFace> fontFace) | 238 void FontFaceSet::addToLoadingFonts(FontFace* fontFace) |
| 239 { | 239 { |
| 240 if (!m_isLoading) { | 240 if (!m_isLoading) { |
| 241 m_isLoading = true; | 241 m_isLoading = true; |
| 242 m_shouldFireLoadingEvent = true; | 242 m_shouldFireLoadingEvent = true; |
| 243 if (m_ready->getState() != ReadyProperty::Pending) | 243 if (m_ready->getState() != ReadyProperty::Pending) |
| 244 m_ready->reset(); | 244 m_ready->reset(); |
| 245 handlePendingEventsAndPromisesSoon(); | 245 handlePendingEventsAndPromisesSoon(); |
| 246 } | 246 } |
| 247 m_loadingFonts.add(fontFace); | 247 m_loadingFonts.add(fontFace); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void FontFaceSet::removeFromLoadingFonts(RawPtr<FontFace> fontFace) | 250 void FontFaceSet::removeFromLoadingFonts(FontFace* fontFace) |
| 251 { | 251 { |
| 252 m_loadingFonts.remove(fontFace); | 252 m_loadingFonts.remove(fontFace); |
| 253 if (m_loadingFonts.isEmpty()) | 253 if (m_loadingFonts.isEmpty()) |
| 254 handlePendingEventsAndPromisesSoon(); | 254 handlePendingEventsAndPromisesSoon(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) | 257 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) |
| 258 { | 258 { |
| 259 return m_ready->promise(scriptState->world()); | 259 return m_ready->promise(scriptState->world()); |
| 260 } | 260 } |
| 261 | 261 |
| 262 RawPtr<FontFaceSet> FontFaceSet::addForBinding(ScriptState*, FontFace* fontFace,
ExceptionState&) | 262 FontFaceSet* FontFaceSet::addForBinding(ScriptState*, FontFace* fontFace, Except
ionState&) |
| 263 { | 263 { |
| 264 ASSERT(fontFace); | 264 ASSERT(fontFace); |
| 265 if (!inActiveDocumentContext()) | 265 if (!inActiveDocumentContext()) |
| 266 return this; | 266 return this; |
| 267 if (m_nonCSSConnectedFaces.contains(fontFace)) | 267 if (m_nonCSSConnectedFaces.contains(fontFace)) |
| 268 return this; | 268 return this; |
| 269 if (isCSSConnectedFontFace(fontFace)) | 269 if (isCSSConnectedFontFace(fontFace)) |
| 270 return this; | 270 return this; |
| 271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
| 272 m_nonCSSConnectedFaces.add(fontFace); | 272 m_nonCSSConnectedFaces.add(fontFace); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 return; | 345 return; |
| 346 | 346 |
| 347 // If the layout was invalidated in between when we thought layout | 347 // If the layout was invalidated in between when we thought layout |
| 348 // was updated and when we're ready to fire the event, just wait | 348 // was updated and when we're ready to fire the event, just wait |
| 349 // until after the next layout before firing events. | 349 // until after the next layout before firing events. |
| 350 Document* d = document(); | 350 Document* d = document(); |
| 351 if (!d->view() || d->view()->needsLayout()) | 351 if (!d->view() || d->view()->needsLayout()) |
| 352 return; | 352 return; |
| 353 | 353 |
| 354 if (m_isLoading) { | 354 if (m_isLoading) { |
| 355 RawPtr<FontFaceSetLoadEvent> doneEvent = nullptr; | 355 FontFaceSetLoadEvent* doneEvent = nullptr; |
| 356 RawPtr<FontFaceSetLoadEvent> errorEvent = nullptr; | 356 FontFaceSetLoadEvent* errorEvent = nullptr; |
| 357 doneEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames::loa
dingdone, m_loadedFonts); | 357 doneEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames::loa
dingdone, m_loadedFonts); |
| 358 m_loadedFonts.clear(); | 358 m_loadedFonts.clear(); |
| 359 if (!m_failedFonts.isEmpty()) { | 359 if (!m_failedFonts.isEmpty()) { |
| 360 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames
::loadingerror, m_failedFonts); | 360 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames
::loadingerror, m_failedFonts); |
| 361 m_failedFonts.clear(); | 361 m_failedFonts.clear(); |
| 362 } | 362 } |
| 363 m_isLoading = false; | 363 m_isLoading = false; |
| 364 dispatchEvent(doneEvent); | 364 dispatchEvent(doneEvent); |
| 365 if (errorEvent) | 365 if (errorEvent) |
| 366 dispatchEvent(errorEvent); | 366 dispatchEvent(errorEvent); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 384 } | 384 } |
| 385 | 385 |
| 386 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon
tFaceCache(); | 386 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon
tFaceCache(); |
| 387 FontFaceArray faces; | 387 FontFaceArray faces; |
| 388 for (const FontFamily* f = &font.getFontDescription().family(); f; f = f->ne
xt()) { | 388 for (const FontFamily* f = &font.getFontDescription().family(); f; f = f->ne
xt()) { |
| 389 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.getFon
tDescription(), f->family()); | 389 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.getFon
tDescription(), f->family()); |
| 390 if (segmentedFontFace) | 390 if (segmentedFontFace) |
| 391 segmentedFontFace->match(text, faces); | 391 segmentedFontFace->match(text, faces); |
| 392 } | 392 } |
| 393 | 393 |
| 394 RawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolver::create(f
aces, scriptState); | 394 LoadFontPromiseResolver* resolver = LoadFontPromiseResolver::create(faces, s
criptState); |
| 395 ScriptPromise promise = resolver->promise(); | 395 ScriptPromise promise = resolver->promise(); |
| 396 resolver->loadFonts(getExecutionContext()); // After this, resolver->promise
() may return null. | 396 resolver->loadFonts(getExecutionContext()); // After this, resolver->promise
() may return null. |
| 397 return promise; | 397 return promise; |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) | 400 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) |
| 401 { | 401 { |
| 402 if (!inActiveDocumentContext()) | 402 if (!inActiveDocumentContext()) |
| 403 return false; | 403 return false; |
| 404 | 404 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 428 } | 428 } |
| 429 return false; | 429 return false; |
| 430 } | 430 } |
| 431 | 431 |
| 432 bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font) | 432 bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font) |
| 433 { | 433 { |
| 434 if (fontString.isEmpty()) | 434 if (fontString.isEmpty()) |
| 435 return false; | 435 return false; |
| 436 | 436 |
| 437 // Interpret fontString in the same way as the 'font' attribute of CanvasRen
deringContext2D. | 437 // Interpret fontString in the same way as the 'font' attribute of CanvasRen
deringContext2D. |
| 438 RawPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat
e(HTMLStandardMode); | 438 MutableStylePropertySet* parsedStyle = MutableStylePropertySet::create(HTMLS
tandardMode); |
| 439 CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, fontString, true,
0); | 439 CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true, 0); |
| 440 if (parsedStyle->isEmpty()) | 440 if (parsedStyle->isEmpty()) |
| 441 return false; | 441 return false; |
| 442 | 442 |
| 443 String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont); | 443 String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont); |
| 444 if (fontValue == "inherit" || fontValue == "initial") | 444 if (fontValue == "inherit" || fontValue == "initial") |
| 445 return false; | 445 return false; |
| 446 | 446 |
| 447 RefPtr<ComputedStyle> style = ComputedStyle::create(); | 447 RefPtr<ComputedStyle> style = ComputedStyle::create(); |
| 448 | 448 |
| 449 FontFamily fontFamily; | 449 FontFamily fontFamily; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 hadBlankTextHistogram.count(m_status == HadBlankText ? 1 : 0); | 487 hadBlankTextHistogram.count(m_status == HadBlankText ? 1 : 0); |
| 488 m_status = Reported; | 488 m_status = Reported; |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 | 491 |
| 492 static const char* supplementName() | 492 static const char* supplementName() |
| 493 { | 493 { |
| 494 return "FontFaceSet"; | 494 return "FontFaceSet"; |
| 495 } | 495 } |
| 496 | 496 |
| 497 RawPtr<FontFaceSet> FontFaceSet::from(Document& document) | 497 FontFaceSet* FontFaceSet::from(Document& document) |
| 498 { | 498 { |
| 499 RawPtr<FontFaceSet> fonts = static_cast<FontFaceSet*>(Supplement<Document>::
from(document, supplementName())); | 499 FontFaceSet* fonts = static_cast<FontFaceSet*>(Supplement<Document>::from(do
cument, supplementName())); |
| 500 if (!fonts) { | 500 if (!fonts) { |
| 501 fonts = FontFaceSet::create(document); | 501 fonts = FontFaceSet::create(document); |
| 502 Supplement<Document>::provideTo(document, supplementName(), fonts); | 502 Supplement<Document>::provideTo(document, supplementName(), fonts); |
| 503 } | 503 } |
| 504 | 504 |
| 505 return fonts.release(); | 505 return fonts; |
| 506 } | 506 } |
| 507 | 507 |
| 508 void FontFaceSet::didLayout(Document& document) | 508 void FontFaceSet::didLayout(Document& document) |
| 509 { | 509 { |
| 510 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(Supplement<Document>::fro
m(document, supplementName()))) | 510 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(Supplement<Document>::fro
m(document, supplementName()))) |
| 511 fonts->didLayout(); | 511 fonts->didLayout(); |
| 512 } | 512 } |
| 513 | 513 |
| 514 FontFaceSetIterable::IterationSource* FontFaceSet::startIteration(ScriptState*,
ExceptionState&) | 514 FontFaceSetIterable::IterationSource* FontFaceSet::startIteration(ScriptState*,
ExceptionState&) |
| 515 { | 515 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 543 visitor->trace(m_loadedFonts); | 543 visitor->trace(m_loadedFonts); |
| 544 visitor->trace(m_failedFonts); | 544 visitor->trace(m_failedFonts); |
| 545 visitor->trace(m_nonCSSConnectedFaces); | 545 visitor->trace(m_nonCSSConnectedFaces); |
| 546 visitor->trace(m_asyncRunner); | 546 visitor->trace(m_asyncRunner); |
| 547 EventTargetWithInlineData::trace(visitor); | 547 EventTargetWithInlineData::trace(visitor); |
| 548 Supplement<Document>::trace(visitor); | 548 Supplement<Document>::trace(visitor); |
| 549 ActiveDOMObject::trace(visitor); | 549 ActiveDOMObject::trace(visitor); |
| 550 } | 550 } |
| 551 | 551 |
| 552 } // namespace blink | 552 } // namespace blink |
| OLD | NEW |