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

Side by Side Diff: Source/core/css/CSSFontSelector.cpp

Issue 18375005: [oilpan] Move CSSFontFace and CSSSegmentedFontFace to the managed heap (Closed) Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 traitsMask |= FontVariantSmallCapsMask; 188 traitsMask |= FontVariantSmallCapsMask;
189 break; 189 break;
190 default: 190 default:
191 break; 191 break;
192 } 192 }
193 } 193 }
194 } else 194 } else
195 traitsMask |= FontVariantMask; 195 traitsMask |= FontVariantMask;
196 196
197 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace. 197 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace.
198 RefPtr<CSSFontFace> fontFace; 198 Handle<CSSFontFace> fontFace;
199 199
200 int srcLength = srcList->length(); 200 int srcLength = srcList->length();
201 201
202 bool foundSVGFont = false; 202 bool foundSVGFont = false;
203 203
204 for (int i = 0; i < srcLength; i++) { 204 for (int i = 0; i < srcLength; i++) {
205 // An item in the list either specifies a string (local font name) or a URL (remote font to download). 205 // An item in the list either specifies a string (local font name) or a URL (remote font to download).
206 CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->i temWithoutBoundsCheck(i)); 206 CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->i temWithoutBoundsCheck(i));
207 OwnPtr<CSSFontFaceSource> source; 207 OwnPtr<CSSFontFaceSource> source;
208 208
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 familyName = pictographFamily; 285 familyName = pictographFamily;
286 break; 286 break;
287 default: 287 default:
288 break; 288 break;
289 } 289 }
290 } 290 }
291 291
292 if (familyName.isEmpty()) 292 if (familyName.isEmpty())
293 continue; 293 continue;
294 294
295 OwnPtr<Vector<RefPtr<CSSFontFace> > >& familyFontFaces = m_fontFaces.add (familyName, nullptr).iterator->value; 295 OwnPtr<CSSFontFaceVectorCollection>& familyFontFaces = m_fontFaces.add(f amilyName, nullptr).iterator->value;
296 if (!familyFontFaces) { 296 if (!familyFontFaces) {
297 familyFontFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >); 297 familyFontFaces = adoptPtr(new CSSFontFaceVectorCollection);
298 298
299 ASSERT(!m_locallyInstalledFontFaces.contains(familyName)); 299 ASSERT(!m_locallyInstalledFontFaces.contains(familyName));
300 300
301 Vector<unsigned> locallyInstalledFontsTraitsMasks; 301 Vector<unsigned> locallyInstalledFontsTraitsMasks;
302 fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTrai tsMasks); 302 fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTrai tsMasks);
303 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsM asks.size()) { 303 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsM asks.size()) {
304 OwnPtr<Vector<RefPtr<CSSFontFace> > > familyLocallyInstalledFace s = adoptPtr(new Vector<RefPtr<CSSFontFace> >); 304 OwnPtr<CSSFontFaceVectorCollection> familyLocallyInstalledFaces = adoptPtr(new CSSFontFaceVectorCollection);
305 305
306 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) { 306 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) {
zerny-google 2013/07/02 14:24:04 Handle scope.
haraken 2013/07/02 14:31:30 Done.
307 RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true); 307 Handle<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true);
308 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName))); 308 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName)));
309 ASSERT(locallyInstalledFontFace->isValid()); 309 ASSERT(locallyInstalledFontFace->isValid());
310 familyLocallyInstalledFaces->append(locallyInstalledFontFace ); 310 (*familyLocallyInstalledFaces)->append(locallyInstalledFontF ace);
311 } 311 }
312 312
313 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release()); 313 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release());
314 } 314 }
315 } 315 }
316 316
317 familyFontFaces->append(fontFace); 317 (*familyFontFaces)->append(fontFace);
318 318
319 ++m_version; 319 ++m_version;
320 } 320 }
321 } 321 }
322 322
323 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t) 323 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t)
324 { 324 {
325 m_clients.add(client); 325 m_clients.add(client);
326 } 326 }
327 327
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 genericFamily = settings->standardFontFamily(script); 385 genericFamily = settings->standardFontFamily(script);
386 386
387 if (!genericFamily.isEmpty()) 387 if (!genericFamily.isEmpty())
388 return fontCache()->getCachedFontData(fontDescription, genericFamily); 388 return fontCache()->getCachedFontData(fontDescription, genericFamily);
389 389
390 return 0; 390 return 0;
391 } 391 }
392 392
393 static FontTraitsMask desiredTraitsMaskForComparison; 393 static FontTraitsMask desiredTraitsMaskForComparison;
394 394
395 static inline bool compareFontFaces(CSSFontFace* first, CSSFontFace* second) 395 static inline bool compareFontFaces(Handle<CSSFontFace> first, Handle<CSSFontFac e> second)
396 { 396 {
397 FontTraitsMask firstTraitsMask = first->traitsMask(); 397 FontTraitsMask firstTraitsMask = first->traitsMask();
398 FontTraitsMask secondTraitsMask = second->traitsMask(); 398 FontTraitsMask secondTraitsMask = second->traitsMask();
399 399
400 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask; 400 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask;
401 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask; 401 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask;
402 402
403 if (firstHasDesiredVariant != secondHasDesiredVariant) 403 if (firstHasDesiredVariant != secondHasDesiredVariant)
404 return firstHasDesiredVariant; 404 return firstHasDesiredVariant;
405 405
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName) 475 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName)
476 { 476 {
477 if (m_fontFaces.isEmpty()) { 477 if (m_fontFaces.isEmpty()) {
478 if (familyName.startsWith("-webkit-")) 478 if (familyName.startsWith("-webkit-"))
479 return fontDataForGenericFamily(m_document, fontDescription, familyN ame); 479 return fontDataForGenericFamily(m_document, fontDescription, familyN ame);
480 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) 480 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont())
481 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 481 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
482 return 0; 482 return 0;
483 } 483 }
484 484
485 CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName); 485 Handle<CSSSegmentedFontFace> face = getFontFace(fontDescription, familyName) ;
486 // If no face was found, then return 0 and let the OS come up with its best match for the name. 486 // If no face was found, then return 0 and let the OS come up with its best match for the name.
487 if (!face) { 487 if (!face) {
488 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our 488 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
489 // settings. 489 // settings.
490 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) 490 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont())
491 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 491 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
492 return fontDataForGenericFamily(m_document, fontDescription, familyName) ; 492 return fontDataForGenericFamily(m_document, fontDescription, familyName) ;
493 } 493 }
494 494
495 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. 495 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over.
496 return face->getFontData(fontDescription); 496 return face->getFontData(fontDescription);
497 } 497 }
498 498
499 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe scription, const AtomicString& family) 499 Result<CSSSegmentedFontFace> CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family)
500 { 500 {
501 Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family); 501 CSSFontFaceVectorCollection* familyFontFaces = m_fontFaces.get(family);
502 if (!familyFontFaces || familyFontFaces->isEmpty()) 502 if (!familyFontFaces || (*familyFontFaces)->isEmpty())
503 return 0; 503 return nullptr;
504 504
505 OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >& segmentedFontFace Cache = m_fonts.add(family, nullptr).iterator->value; 505 OwnPtr<HashMap<unsigned, Persistent<CSSSegmentedFontFace> > >& segmentedFont FaceCache = m_fonts.add(family, nullptr).iterator->value;
506 if (!segmentedFontFaceCache) 506 if (!segmentedFontFaceCache)
507 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, RefPtr<CSSSegmen tedFontFace> >); 507 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, Persistent<CSSSe gmentedFontFace> >);
508 508
509 FontTraitsMask traitsMask = fontDescription.traitsMask(); 509 FontTraitsMask traitsMask = fontDescription.traitsMask();
510 510
511 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask, 0).iterator->value; 511 Persistent<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsM ask, nullptr).iterator->value;
512 if (!face) { 512 if (!face) {
513 face = CSSSegmentedFontFace::create(this); 513 face = CSSSegmentedFontFace::create(this);
514 514
515 // Collect all matching faces and sort them in order of preference. 515 // Collect all matching faces and sort them in order of preference.
516 Vector<CSSFontFace*, 32> candidateFontFaces; 516 Vector<Handle<CSSFontFace>, 32> candidateFontFaces;
517 for (int i = familyFontFaces->size() - 1; i >= 0; --i) { 517 for (int i = (*familyFontFaces)->size() - 1; i >= 0; --i) {
518 CSSFontFace* candidate = familyFontFaces->at(i).get(); 518 Handle<CSSFontFace> candidate = (*familyFontFaces)->at(i);
519 unsigned candidateTraitsMask = candidate->traitsMask(); 519 unsigned candidateTraitsMask = candidate->traitsMask();
520 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask)) 520 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask))
521 continue; 521 continue;
522 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) 522 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask))
523 continue; 523 continue;
524 #if ENABLE(SVG_FONTS) 524 #if ENABLE(SVG_FONTS)
525 // For SVG Fonts that specify that they only support the "normal" va riant, we will assume they are incapable 525 // For SVG Fonts that specify that they only support the "normal" va riant, we will assume they are incapable
526 // of small-caps synthesis and just ignore the font face as a candid ate. 526 // of small-caps synthesis and just ignore the font face as a candid ate.
527 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask)) 527 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask))
528 continue; 528 continue;
529 #endif 529 #endif
530 candidateFontFaces.append(candidate); 530 candidateFontFaces.append(candidate);
531 } 531 }
532 532
533 if (Vector<RefPtr<CSSFontFace> >* familyLocallyInstalledFontFaces = m_lo callyInstalledFontFaces.get(family)) { 533 CSSFontFaceVectorCollection* familyLocallyInstalledFontFaces = m_locally InstalledFontFaces.get(family);
534 unsigned numLocallyInstalledFontFaces = familyLocallyInstalledFontFa ces->size(); 534 if (familyLocallyInstalledFontFaces) {
535 unsigned numLocallyInstalledFontFaces = (*familyLocallyInstalledFont Faces)->size();
535 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) { 536 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) {
zerny-google 2013/07/02 14:24:04 Handle scope
haraken 2013/07/02 14:31:30 Done.
536 CSSFontFace* candidate = familyLocallyInstalledFontFaces->at(i). get(); 537 Handle<CSSFontFace> candidate = (*familyLocallyInstalledFontFace s)->at(i);
537 unsigned candidateTraitsMask = candidate->traitsMask(); 538 unsigned candidateTraitsMask = candidate->traitsMask();
538 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) 539 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
539 continue; 540 continue;
540 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask)) 541 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask))
541 continue; 542 continue;
542 candidateFontFaces.append(candidate); 543 candidateFontFaces.append(candidate);
543 } 544 }
544 } 545 }
545 546
546 desiredTraitsMaskForComparison = traitsMask; 547 desiredTraitsMaskForComparison = traitsMask;
547 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces); 548 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces);
548 unsigned numCandidates = candidateFontFaces.size(); 549 unsigned numCandidates = candidateFontFaces.size();
549 for (unsigned i = 0; i < numCandidates; ++i) 550 for (unsigned i = 0; i < numCandidates; ++i)
550 face->appendFontFace(candidateFontFaces[i]); 551 face->appendFontFace(candidateFontFaces[i]);
551 } 552 }
552 return face.get(); 553 return face;
553 } 554 }
554 555
555 void CSSFontSelector::clearDocument() 556 void CSSFontSelector::clearDocument()
556 { 557 {
557 if (!m_document) { 558 if (!m_document) {
558 ASSERT(!m_beginLoadingTimer.isActive()); 559 ASSERT(!m_beginLoadingTimer.isActive());
559 ASSERT(m_fontsToBeginLoading.isEmpty()); 560 ASSERT(m_fontsToBeginLoading.isEmpty());
560 return; 561 return;
561 } 562 }
562 563
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 } 603 }
603 // Ensure that if the request count reaches zero, the frame loader will know about it. 604 // Ensure that if the request count reaches zero, the frame loader will know about it.
604 cachedResourceLoader->loadDone(0); 605 cachedResourceLoader->loadDone(0);
605 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched 606 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched
606 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly. 607 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly.
607 if (m_document && m_document->frame()) 608 if (m_document && m_document->frame())
608 m_document->frame()->loader()->checkLoadComplete(); 609 m_document->frame()->loader()->checkLoadComplete();
609 } 610 }
610 611
611 } 612 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698