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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 Document* FontFaceSet::document() const { | 130 Document* FontFaceSet::document() const { |
131 return toDocument(getExecutionContext()); | 131 return toDocument(getExecutionContext()); |
132 } | 132 } |
133 | 133 |
134 bool FontFaceSet::inActiveDocumentContext() const { | 134 bool FontFaceSet::inActiveDocumentContext() const { |
135 ExecutionContext* context = getExecutionContext(); | 135 ExecutionContext* context = getExecutionContext(); |
136 return context && toDocument(context)->isActive(); | 136 return context && toDocument(context)->isActive(); |
137 } | 137 } |
138 | 138 |
139 void FontFaceSet::addFontFacesToFontFaceCache(CSSFontSelector* fontSelector) { | 139 void FontFaceSet::addFontFacesToFontFaceCache(FontFaceCache* fontFaceCache, |
140 FontFaceCache* fontFaceCache = document()->fontFaceCache(); | 140 CSSFontSelector* fontSelector) { |
141 for (const auto& fontFace : m_nonCSSConnectedFaces) | 141 for (const auto& fontFace : m_nonCSSConnectedFaces) |
142 fontFaceCache->addFontFace(fontSelector, fontFace, false); | 142 fontFaceCache->addFontFace(fontSelector, fontFace, false); |
143 } | 143 } |
144 | 144 |
145 const AtomicString& FontFaceSet::interfaceName() const { | 145 const AtomicString& FontFaceSet::interfaceName() const { |
146 return EventTargetNames::FontFaceSet; | 146 return EventTargetNames::FontFaceSet; |
147 } | 147 } |
148 | 148 |
149 ExecutionContext* FontFaceSet::getExecutionContext() const { | 149 ExecutionContext* FontFaceSet::getExecutionContext() const { |
150 return SuspendableObject::getExecutionContext(); | 150 return SuspendableObject::getExecutionContext(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 ExceptionState&) { | 251 ExceptionState&) { |
252 ASSERT(fontFace); | 252 ASSERT(fontFace); |
253 if (!inActiveDocumentContext()) | 253 if (!inActiveDocumentContext()) |
254 return this; | 254 return this; |
255 if (m_nonCSSConnectedFaces.contains(fontFace)) | 255 if (m_nonCSSConnectedFaces.contains(fontFace)) |
256 return this; | 256 return this; |
257 if (isCSSConnectedFontFace(fontFace)) | 257 if (isCSSConnectedFontFace(fontFace)) |
258 return this; | 258 return this; |
259 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 259 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
260 m_nonCSSConnectedFaces.add(fontFace); | 260 m_nonCSSConnectedFaces.add(fontFace); |
261 document()->fontFaceCache()->addFontFace(fontSelector, fontFace, false); | 261 fontSelector->fontFaceCache()->addFontFace(fontSelector, fontFace, false); |
262 if (fontFace->loadStatus() == FontFace::Loading) | 262 if (fontFace->loadStatus() == FontFace::Loading) |
263 addToLoadingFonts(fontFace); | 263 addToLoadingFonts(fontFace); |
264 fontSelector->fontFaceInvalidated(); | 264 fontSelector->fontFaceInvalidated(); |
265 return this; | 265 return this; |
266 } | 266 } |
267 | 267 |
268 void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) { | 268 void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) { |
269 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) | 269 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) |
270 return; | 270 return; |
271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
272 FontFaceCache* fontFaceCache = document()->fontFaceCache(); | 272 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); |
273 for (const auto& fontFace : m_nonCSSConnectedFaces) { | 273 for (const auto& fontFace : m_nonCSSConnectedFaces) { |
274 fontFaceCache->removeFontFace(fontFace.get(), false); | 274 fontFaceCache->removeFontFace(fontFace.get(), false); |
275 if (fontFace->loadStatus() == FontFace::Loading) | 275 if (fontFace->loadStatus() == FontFace::Loading) |
276 removeFromLoadingFonts(fontFace); | 276 removeFromLoadingFonts(fontFace); |
277 } | 277 } |
278 m_nonCSSConnectedFaces.clear(); | 278 m_nonCSSConnectedFaces.clear(); |
279 fontSelector->fontFaceInvalidated(); | 279 fontSelector->fontFaceInvalidated(); |
280 } | 280 } |
281 | 281 |
282 bool FontFaceSet::deleteForBinding(ScriptState*, | 282 bool FontFaceSet::deleteForBinding(ScriptState*, |
283 FontFace* fontFace, | 283 FontFace* fontFace, |
284 ExceptionState&) { | 284 ExceptionState&) { |
285 ASSERT(fontFace); | 285 ASSERT(fontFace); |
286 if (!inActiveDocumentContext()) | 286 if (!inActiveDocumentContext()) |
287 return false; | 287 return false; |
288 HeapListHashSet<Member<FontFace>>::iterator it = | 288 HeapListHashSet<Member<FontFace>>::iterator it = |
289 m_nonCSSConnectedFaces.find(fontFace); | 289 m_nonCSSConnectedFaces.find(fontFace); |
290 if (it != m_nonCSSConnectedFaces.end()) { | 290 if (it != m_nonCSSConnectedFaces.end()) { |
291 m_nonCSSConnectedFaces.remove(it); | 291 m_nonCSSConnectedFaces.remove(it); |
292 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 292 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
293 document()->fontFaceCache()->removeFontFace(fontFace, false); | 293 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); |
294 if (fontFace->loadStatus() == FontFace::Loading) | 294 if (fontFace->loadStatus() == FontFace::Loading) |
295 removeFromLoadingFonts(fontFace); | 295 removeFromLoadingFonts(fontFace); |
296 fontSelector->fontFaceInvalidated(); | 296 fontSelector->fontFaceInvalidated(); |
297 return true; | 297 return true; |
298 } | 298 } |
299 return false; | 299 return false; |
300 } | 300 } |
301 | 301 |
302 bool FontFaceSet::hasForBinding(ScriptState*, | 302 bool FontFaceSet::hasForBinding(ScriptState*, |
303 FontFace* fontFace, | 303 FontFace* fontFace, |
304 ExceptionState&) const { | 304 ExceptionState&) const { |
305 ASSERT(fontFace); | 305 ASSERT(fontFace); |
306 if (!inActiveDocumentContext()) | 306 if (!inActiveDocumentContext()) |
307 return false; | 307 return false; |
308 return m_nonCSSConnectedFaces.contains(fontFace) || | 308 return m_nonCSSConnectedFaces.contains(fontFace) || |
309 isCSSConnectedFontFace(fontFace); | 309 isCSSConnectedFontFace(fontFace); |
310 } | 310 } |
311 | 311 |
312 const HeapListHashSet<Member<FontFace>>& FontFaceSet::cssConnectedFontFaceList() | 312 const HeapListHashSet<Member<FontFace>>& FontFaceSet::cssConnectedFontFaceList() |
313 const { | 313 const { |
314 Document* document = this->document(); | 314 Document* document = this->document(); |
315 document->updateActiveStyle(); | 315 document->updateActiveStyle(); |
316 return document->fontFaceCache()->cssConnectedFontFaces(); | 316 return document->styleEngine() |
| 317 .fontSelector() |
| 318 ->fontFaceCache() |
| 319 ->cssConnectedFontFaces(); |
317 } | 320 } |
318 | 321 |
319 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const { | 322 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const { |
320 return cssConnectedFontFaceList().contains(fontFace); | 323 return cssConnectedFontFaceList().contains(fontFace); |
321 } | 324 } |
322 | 325 |
323 size_t FontFaceSet::size() const { | 326 size_t FontFaceSet::size() const { |
324 if (!inActiveDocumentContext()) | 327 if (!inActiveDocumentContext()) |
325 return m_nonCSSConnectedFaces.size(); | 328 return m_nonCSSConnectedFaces.size(); |
326 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size(); | 329 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 Font font; | 374 Font font; |
372 if (!resolveFontStyle(fontString, font)) { | 375 if (!resolveFontStyle(fontString, font)) { |
373 ScriptPromiseResolver* resolver = | 376 ScriptPromiseResolver* resolver = |
374 ScriptPromiseResolver::create(scriptState); | 377 ScriptPromiseResolver::create(scriptState); |
375 ScriptPromise promise = resolver->promise(); | 378 ScriptPromise promise = resolver->promise(); |
376 resolver->reject(DOMException::create( | 379 resolver->reject(DOMException::create( |
377 SyntaxError, "Could not resolve '" + fontString + "' as a font.")); | 380 SyntaxError, "Could not resolve '" + fontString + "' as a font.")); |
378 return promise; | 381 return promise; |
379 } | 382 } |
380 | 383 |
381 FontFaceCache* fontFaceCache = document()->fontFaceCache(); | 384 FontFaceCache* fontFaceCache = |
| 385 document()->styleEngine().fontSelector()->fontFaceCache(); |
382 FontFaceArray faces; | 386 FontFaceArray faces; |
383 for (const FontFamily* f = &font.getFontDescription().family(); f; | 387 for (const FontFamily* f = &font.getFontDescription().family(); f; |
384 f = f->next()) { | 388 f = f->next()) { |
385 CSSSegmentedFontFace* segmentedFontFace = | 389 CSSSegmentedFontFace* segmentedFontFace = |
386 fontFaceCache->get(font.getFontDescription(), f->family()); | 390 fontFaceCache->get(font.getFontDescription(), f->family()); |
387 if (segmentedFontFace) | 391 if (segmentedFontFace) |
388 segmentedFontFace->match(text, faces); | 392 segmentedFontFace->match(text, faces); |
389 } | 393 } |
390 | 394 |
391 LoadFontPromiseResolver* resolver = | 395 LoadFontPromiseResolver* resolver = |
(...skipping 11 matching lines...) Expand all Loading... |
403 return false; | 407 return false; |
404 | 408 |
405 Font font; | 409 Font font; |
406 if (!resolveFontStyle(fontString, font)) { | 410 if (!resolveFontStyle(fontString, font)) { |
407 exceptionState.throwDOMException( | 411 exceptionState.throwDOMException( |
408 SyntaxError, "Could not resolve '" + fontString + "' as a font."); | 412 SyntaxError, "Could not resolve '" + fontString + "' as a font."); |
409 return false; | 413 return false; |
410 } | 414 } |
411 | 415 |
412 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 416 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
413 FontFaceCache* fontFaceCache = document()->fontFaceCache(); | 417 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); |
414 | 418 |
415 bool hasLoadedFaces = false; | 419 bool hasLoadedFaces = false; |
416 for (const FontFamily* f = &font.getFontDescription().family(); f; | 420 for (const FontFamily* f = &font.getFontDescription().family(); f; |
417 f = f->next()) { | 421 f = f->next()) { |
418 CSSSegmentedFontFace* face = | 422 CSSSegmentedFontFace* face = |
419 fontFaceCache->get(font.getFontDescription(), f->family()); | 423 fontFaceCache->get(font.getFontDescription(), f->family()); |
420 if (face) { | 424 if (face) { |
421 if (!face->checkFont(text)) | 425 if (!face->checkFont(text)) |
422 return false; | 426 return false; |
423 hasLoadedFaces = true; | 427 hasLoadedFaces = true; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 visitor->trace(m_failedFonts); | 561 visitor->trace(m_failedFonts); |
558 visitor->trace(m_nonCSSConnectedFaces); | 562 visitor->trace(m_nonCSSConnectedFaces); |
559 visitor->trace(m_asyncRunner); | 563 visitor->trace(m_asyncRunner); |
560 EventTargetWithInlineData::trace(visitor); | 564 EventTargetWithInlineData::trace(visitor); |
561 Supplement<Document>::trace(visitor); | 565 Supplement<Document>::trace(visitor); |
562 SuspendableObject::trace(visitor); | 566 SuspendableObject::trace(visitor); |
563 FontFace::LoadFontCallback::trace(visitor); | 567 FontFace::LoadFontCallback::trace(visitor); |
564 } | 568 } |
565 | 569 |
566 } // namespace blink | 570 } // namespace blink |
OLD | NEW |