Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: third_party/WebKit/Source/core/css/FontFaceSet.cpp

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 PassRefPtrWillBeRawPtr<LoadFontPromiseResolver> create(FontFaceArray faces, ScriptState* scriptState) 52 static RawPtr<LoadFontPromiseResolver> create(FontFaceArray faces, ScriptSta te* scriptState)
53 { 53 {
54 return adoptRefWillBeNoop(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
63 DECLARE_VIRTUAL_TRACE(); 63 DECLARE_VIRTUAL_TRACE();
64 64
65 private: 65 private:
66 LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState) 66 LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState)
67 : m_numLoading(faces.size()) 67 : m_numLoading(faces.size())
68 , m_errorOccured(false) 68 , m_errorOccured(false)
69 , m_resolver(ScriptPromiseResolver::create(scriptState)) 69 , m_resolver(ScriptPromiseResolver::create(scriptState))
70 { 70 {
71 m_fontFaces.swap(faces); 71 m_fontFaces.swap(faces);
72 } 72 }
73 73
74 WillBeHeapVector<RefPtrWillBeMember<FontFace>> m_fontFaces; 74 HeapVector<Member<FontFace>> m_fontFaces;
75 int m_numLoading; 75 int m_numLoading;
76 bool m_errorOccured; 76 bool m_errorOccured;
77 PersistentWillBeMember<ScriptPromiseResolver> m_resolver; 77 Member<ScriptPromiseResolver> m_resolver;
78 }; 78 };
79 79
80 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) 80 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context)
81 { 81 {
82 if (!m_numLoading) { 82 if (!m_numLoading) {
83 m_resolver->resolve(m_fontFaces); 83 m_resolver->resolve(m_fontFaces);
84 return; 84 return;
85 } 85 }
86 86
87 for (size_t i = 0; i < m_fontFaces.size(); i++) 87 for (size_t i = 0; i < m_fontFaces.size(); i++)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(PassRefPtrWillBeRawPtr<FontFace> fontFace) 238 void FontFaceSet::addToLoadingFonts(RawPtr<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->state() != ReadyProperty::Pending) 243 if (m_ready->state() != 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(PassRefPtrWillBeRawPtr<FontFace> fontFa ce) 250 void FontFaceSet::removeFromLoadingFonts(RawPtr<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 PassRefPtrWillBeRawPtr<FontFaceSet> FontFaceSet::addForBinding(ScriptState*, Fon tFace* fontFace, ExceptionState&) 262 RawPtr<FontFaceSet> FontFaceSet::addForBinding(ScriptState*, FontFace* fontFace, ExceptionState&)
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 17 matching lines...) Expand all
290 } 290 }
291 m_nonCSSConnectedFaces.clear(); 291 m_nonCSSConnectedFaces.clear();
292 fontSelector->fontFaceInvalidated(); 292 fontSelector->fontFaceInvalidated();
293 } 293 }
294 294
295 bool FontFaceSet::deleteForBinding(ScriptState*, FontFace* fontFace, ExceptionSt ate&) 295 bool FontFaceSet::deleteForBinding(ScriptState*, FontFace* fontFace, ExceptionSt ate&)
296 { 296 {
297 ASSERT(fontFace); 297 ASSERT(fontFace);
298 if (!inActiveDocumentContext()) 298 if (!inActiveDocumentContext())
299 return false; 299 return false;
300 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>::iterator it = m_nonCSSC onnectedFaces.find(fontFace); 300 HeapListHashSet<Member<FontFace>>::iterator it = m_nonCSSConnectedFaces.find (fontFace);
301 if (it != m_nonCSSConnectedFaces.end()) { 301 if (it != m_nonCSSConnectedFaces.end()) {
302 m_nonCSSConnectedFaces.remove(it); 302 m_nonCSSConnectedFaces.remove(it);
303 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector() ; 303 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector() ;
304 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); 304 fontSelector->fontFaceCache()->removeFontFace(fontFace, false);
305 if (fontFace->loadStatus() == FontFace::Loading) 305 if (fontFace->loadStatus() == FontFace::Loading)
306 removeFromLoadingFonts(fontFace); 306 removeFromLoadingFonts(fontFace);
307 fontSelector->fontFaceInvalidated(); 307 fontSelector->fontFaceInvalidated();
308 return true; 308 return true;
309 } 309 }
310 return false; 310 return false;
311 } 311 }
312 312
313 bool FontFaceSet::hasForBinding(ScriptState*, FontFace* fontFace, ExceptionState &) const 313 bool FontFaceSet::hasForBinding(ScriptState*, FontFace* fontFace, ExceptionState &) const
314 { 314 {
315 ASSERT(fontFace); 315 ASSERT(fontFace);
316 if (!inActiveDocumentContext()) 316 if (!inActiveDocumentContext())
317 return false; 317 return false;
318 return m_nonCSSConnectedFaces.contains(fontFace) || isCSSConnectedFontFace(f ontFace); 318 return m_nonCSSConnectedFaces.contains(fontFace) || isCSSConnectedFontFace(f ontFace);
319 } 319 }
320 320
321 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>& FontFaceSet::cssConne ctedFontFaceList() const 321 const HeapListHashSet<Member<FontFace>>& FontFaceSet::cssConnectedFontFaceList() const
322 { 322 {
323 Document* d = document(); 323 Document* d = document();
324 d->ensureStyleResolver(); // Flush pending style changes. 324 d->ensureStyleResolver(); // Flush pending style changes.
325 return d->styleEngine().fontSelector()->fontFaceCache()->cssConnectedFontFac es(); 325 return d->styleEngine().fontSelector()->fontFaceCache()->cssConnectedFontFac es();
326 } 326 }
327 327
328 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const 328 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const
329 { 329 {
330 return cssConnectedFontFaceList().contains(fontFace); 330 return cssConnectedFontFaceList().contains(fontFace);
331 } 331 }
(...skipping 13 matching lines...) Expand all
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 RefPtrWillBeRawPtr<FontFaceSetLoadEvent> doneEvent = nullptr; 355 RawPtr<FontFaceSetLoadEvent> doneEvent = nullptr;
356 RefPtrWillBeRawPtr<FontFaceSetLoadEvent> errorEvent = nullptr; 356 RawPtr<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
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.fontDescription().family(); f; f = f->next( )) { 388 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next( )) {
389 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe scription(), f->family()); 389 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe scription(), f->family());
390 if (segmentedFontFace) 390 if (segmentedFontFace)
391 segmentedFontFace->match(text, faces); 391 segmentedFontFace->match(text, faces);
392 } 392 }
393 393
394 RefPtrWillBeRawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolv er::create(faces, scriptState); 394 RawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolver::create(f aces, scriptState);
395 ScriptPromise promise = resolver->promise(); 395 ScriptPromise promise = resolver->promise();
396 resolver->loadFonts(executionContext()); // After this, resolver->promise() may return null. 396 resolver->loadFonts(executionContext()); // 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
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 RefPtrWillBeRawPtr<MutableStylePropertySet> parsedStyle = MutableStyleProper tySet::create(HTMLStandardMode); 438 RawPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat e(HTMLStandardMode);
439 CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, fontString, true, 0); 439 CSSParser::parseValue(parsedStyle.get(), 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
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 PassRefPtrWillBeRawPtr<FontFaceSet> FontFaceSet::from(Document& document) 497 RawPtr<FontFaceSet> FontFaceSet::from(Document& document)
498 { 498 {
499 RefPtrWillBeRawPtr<FontFaceSet> fonts = static_cast<FontFaceSet*>(Supplement Type::from(document, supplementName())); 499 RawPtr<FontFaceSet> fonts = static_cast<FontFaceSet*>(SupplementType::from(d ocument, supplementName()));
500 if (!fonts) { 500 if (!fonts) {
501 fonts = FontFaceSet::create(document); 501 fonts = FontFaceSet::create(document);
502 SupplementType::provideTo(document, supplementName(), fonts); 502 SupplementType::provideTo(document, supplementName(), fonts);
503 } 503 }
504 504
505 return fonts.release(); 505 return fonts.release();
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*>(SupplementType::from(docu ment, supplementName()))) 510 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(SupplementType::from(docu ment, 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 {
516 // Setlike should iterate each item in insertion order, and items should 516 // Setlike should iterate each item in insertion order, and items should
517 // be keep on up to date. But since blink does not have a way to hook up CSS 517 // be keep on up to date. But since blink does not have a way to hook up CSS
518 // modification, take a snapshot here, and make it ordered as follows. 518 // modification, take a snapshot here, and make it ordered as follows.
519 WillBeHeapVector<RefPtrWillBeMember<FontFace>> fontFaces; 519 HeapVector<Member<FontFace>> fontFaces;
520 if (inActiveDocumentContext()) { 520 if (inActiveDocumentContext()) {
521 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>& cssConnectedF aces = cssConnectedFontFaceList(); 521 const HeapListHashSet<Member<FontFace>>& cssConnectedFaces = cssConnecte dFontFaceList();
522 fontFaces.reserveInitialCapacity(cssConnectedFaces.size() + m_nonCSSConn ectedFaces.size()); 522 fontFaces.reserveInitialCapacity(cssConnectedFaces.size() + m_nonCSSConn ectedFaces.size());
523 for (const auto& fontFace : cssConnectedFaces) 523 for (const auto& fontFace : cssConnectedFaces)
524 fontFaces.append(fontFace); 524 fontFaces.append(fontFace);
525 for (const auto& fontFace : m_nonCSSConnectedFaces) 525 for (const auto& fontFace : m_nonCSSConnectedFaces)
526 fontFaces.append(fontFace); 526 fontFaces.append(fontFace);
527 } 527 }
528 return new IterationSource(fontFaces); 528 return new IterationSource(fontFaces);
529 } 529 }
530 530
531 bool FontFaceSet::IterationSource::next(ScriptState*, RefPtrWillBeMember<FontFac e>& key, RefPtrWillBeMember<FontFace>& value, ExceptionState&) 531 bool FontFaceSet::IterationSource::next(ScriptState*, Member<FontFace>& key, Mem ber<FontFace>& value, ExceptionState&)
532 { 532 {
533 if (m_fontFaces.size() <= m_index) 533 if (m_fontFaces.size() <= m_index)
534 return false; 534 return false;
535 key = value = m_fontFaces[m_index++]; 535 key = value = m_fontFaces[m_index++];
536 return true; 536 return true;
537 } 537 }
538 538
539 DEFINE_TRACE(FontFaceSet) 539 DEFINE_TRACE(FontFaceSet)
540 { 540 {
541 #if ENABLE(OILPAN) 541 #if ENABLE(OILPAN)
542 visitor->trace(m_ready); 542 visitor->trace(m_ready);
543 visitor->trace(m_loadingFonts); 543 visitor->trace(m_loadingFonts);
544 visitor->trace(m_loadedFonts); 544 visitor->trace(m_loadedFonts);
545 visitor->trace(m_failedFonts); 545 visitor->trace(m_failedFonts);
546 visitor->trace(m_nonCSSConnectedFaces); 546 visitor->trace(m_nonCSSConnectedFaces);
547 visitor->trace(m_asyncRunner); 547 visitor->trace(m_asyncRunner);
548 HeapSupplement<Document>::trace(visitor); 548 HeapSupplement<Document>::trace(visitor);
549 #endif 549 #endif
550 EventTargetWithInlineData::trace(visitor); 550 EventTargetWithInlineData::trace(visitor);
551 ActiveDOMObject::trace(visitor); 551 ActiveDOMObject::trace(visitor);
552 } 552 }
553 553
554 } // namespace blink 554 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698