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

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
« no previous file with comments | « Source/core/css/CSSFontSelector.h ('k') | Source/core/css/CSSSegmentedFontFace.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
307 RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true); 307 HandleScope scope;
308 Handle<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true);
308 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName))); 309 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName)));
309 ASSERT(locallyInstalledFontFace->isValid()); 310 ASSERT(locallyInstalledFontFace->isValid());
310 familyLocallyInstalledFaces->append(locallyInstalledFontFace ); 311 (*familyLocallyInstalledFaces)->append(locallyInstalledFontF ace);
311 } 312 }
312 313
313 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release()); 314 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release());
314 } 315 }
315 } 316 }
316 317
317 familyFontFaces->append(fontFace); 318 (*familyFontFaces)->append(fontFace);
318 319
319 ++m_version; 320 ++m_version;
320 } 321 }
321 } 322 }
322 323
323 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t) 324 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t)
324 { 325 {
325 m_clients.add(client); 326 m_clients.add(client);
326 } 327 }
327 328
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 genericFamily = settings->standardFontFamily(script); 386 genericFamily = settings->standardFontFamily(script);
386 387
387 if (!genericFamily.isEmpty()) 388 if (!genericFamily.isEmpty())
388 return fontCache()->getCachedFontData(fontDescription, genericFamily); 389 return fontCache()->getCachedFontData(fontDescription, genericFamily);
389 390
390 return 0; 391 return 0;
391 } 392 }
392 393
393 static FontTraitsMask desiredTraitsMaskForComparison; 394 static FontTraitsMask desiredTraitsMaskForComparison;
394 395
395 static inline bool compareFontFaces(CSSFontFace* first, CSSFontFace* second) 396 static inline bool compareFontFaces(Handle<CSSFontFace> first, Handle<CSSFontFac e> second)
396 { 397 {
397 FontTraitsMask firstTraitsMask = first->traitsMask(); 398 FontTraitsMask firstTraitsMask = first->traitsMask();
398 FontTraitsMask secondTraitsMask = second->traitsMask(); 399 FontTraitsMask secondTraitsMask = second->traitsMask();
399 400
400 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask; 401 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask;
401 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask; 402 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask;
402 403
403 if (firstHasDesiredVariant != secondHasDesiredVariant) 404 if (firstHasDesiredVariant != secondHasDesiredVariant)
404 return firstHasDesiredVariant; 405 return firstHasDesiredVariant;
405 406
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName) 476 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName)
476 { 477 {
477 if (m_fontFaces.isEmpty()) { 478 if (m_fontFaces.isEmpty()) {
478 if (familyName.startsWith("-webkit-")) 479 if (familyName.startsWith("-webkit-"))
479 return fontDataForGenericFamily(m_document, fontDescription, familyN ame); 480 return fontDataForGenericFamily(m_document, fontDescription, familyN ame);
480 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) 481 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont())
481 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 482 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
482 return 0; 483 return 0;
483 } 484 }
484 485
485 CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName); 486 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. 487 // If no face was found, then return 0 and let the OS come up with its best match for the name.
487 if (!face) { 488 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 489 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
489 // settings. 490 // settings.
490 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) 491 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont())
491 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 492 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
492 return fontDataForGenericFamily(m_document, fontDescription, familyName) ; 493 return fontDataForGenericFamily(m_document, fontDescription, familyName) ;
493 } 494 }
494 495
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 // 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); 497 return face->getFontData(fontDescription);
497 } 498 }
498 499
499 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe scription, const AtomicString& family) 500 Result<CSSSegmentedFontFace> CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family)
500 { 501 {
501 Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family); 502 CSSFontFaceVectorCollection* familyFontFaces = m_fontFaces.get(family);
502 if (!familyFontFaces || familyFontFaces->isEmpty()) 503 if (!familyFontFaces || (*familyFontFaces)->isEmpty())
503 return 0; 504 return nullptr;
504 505
505 OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >& segmentedFontFace Cache = m_fonts.add(family, nullptr).iterator->value; 506 OwnPtr<HashMap<unsigned, Persistent<CSSSegmentedFontFace> > >& segmentedFont FaceCache = m_fonts.add(family, nullptr).iterator->value;
Mads Ager (chromium) 2013/07/03 06:30:42 And here is another one.
506 if (!segmentedFontFaceCache) 507 if (!segmentedFontFaceCache)
507 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, RefPtr<CSSSegmen tedFontFace> >); 508 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, Persistent<CSSSe gmentedFontFace> >);
508 509
509 FontTraitsMask traitsMask = fontDescription.traitsMask(); 510 FontTraitsMask traitsMask = fontDescription.traitsMask();
510 511
511 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask, 0).iterator->value; 512 Persistent<CSSSegmentedFontFace> face = segmentedFontFaceCache->add(traitsMa sk, nullptr).iterator->value;
Mads Ager (chromium) 2013/07/03 06:30:42 This should just be Handle instead of Persistent.
haraken 2013/07/03 07:46:02 Done.
512 if (!face) { 513 if (face)
513 face = CSSSegmentedFontFace::create(this); 514 return face;
514 515
515 // Collect all matching faces and sort them in order of preference. 516 face = CSSSegmentedFontFace::create(this);
516 Vector<CSSFontFace*, 32> candidateFontFaces; 517 segmentedFontFaceCache->set(traitsMask, face);
517 for (int i = familyFontFaces->size() - 1; i >= 0; --i) { 518
518 CSSFontFace* candidate = familyFontFaces->at(i).get(); 519 // Collect all matching faces and sort them in order of preference.
520 Vector<Handle<CSSFontFace>, 32> candidateFontFaces;
521 for (int i = (*familyFontFaces)->size() - 1; i >= 0; --i) {
522 HandleScope scope;
523 Handle<CSSFontFace> candidate = (*familyFontFaces)->at(i);
524 unsigned candidateTraitsMask = candidate->traitsMask();
525 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontSt yleNormalMask))
526 continue;
527 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & Font VariantNormalMask))
528 continue;
529 #if ENABLE(SVG_FONTS)
530 // For SVG Fonts that specify that they only support the "normal" varian t, we will assume they are incapable
531 // of small-caps synthesis and just ignore the font face as a candidate.
532 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSmallC apsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask))
533 continue;
534 #endif
535 candidateFontFaces.append(candidate);
536 }
537
538 CSSFontFaceVectorCollection* familyLocallyInstalledFontFaces = m_locallyInst alledFontFaces.get(family);
539 if (familyLocallyInstalledFontFaces) {
540 unsigned numLocallyInstalledFontFaces = (*familyLocallyInstalledFontFace s)->size();
541 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) {
542 Handle<CSSFontFace> candidate = (*familyLocallyInstalledFontFaces)-> at(i);
519 unsigned candidateTraitsMask = candidate->traitsMask(); 543 unsigned candidateTraitsMask = candidate->traitsMask();
520 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask)) 544 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask))
521 continue; 545 continue;
522 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) 546 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask))
523 continue; 547 continue;
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
526 // of small-caps synthesis and just ignore the font face as a candid ate.
527 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask))
528 continue;
529 #endif
530 candidateFontFaces.append(candidate); 548 candidateFontFaces.append(candidate);
531 } 549 }
550 }
532 551
533 if (Vector<RefPtr<CSSFontFace> >* familyLocallyInstalledFontFaces = m_lo callyInstalledFontFaces.get(family)) { 552 desiredTraitsMaskForComparison = traitsMask;
534 unsigned numLocallyInstalledFontFaces = familyLocallyInstalledFontFa ces->size(); 553 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compareFon tFaces);
535 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) { 554 unsigned numCandidates = candidateFontFaces.size();
536 CSSFontFace* candidate = familyLocallyInstalledFontFaces->at(i). get(); 555 for (unsigned i = 0; i < numCandidates; ++i)
537 unsigned candidateTraitsMask = candidate->traitsMask(); 556 face->appendFontFace(candidateFontFaces[i]);
538 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) 557 return face;
539 continue;
540 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask))
541 continue;
542 candidateFontFaces.append(candidate);
543 }
544 }
545
546 desiredTraitsMaskForComparison = traitsMask;
547 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces);
548 unsigned numCandidates = candidateFontFaces.size();
549 for (unsigned i = 0; i < numCandidates; ++i)
550 face->appendFontFace(candidateFontFaces[i]);
551 }
552 return face.get();
553 } 558 }
554 559
555 void CSSFontSelector::clearDocument() 560 void CSSFontSelector::clearDocument()
556 { 561 {
557 if (!m_document) { 562 if (!m_document) {
558 ASSERT(!m_beginLoadingTimer.isActive()); 563 ASSERT(!m_beginLoadingTimer.isActive());
559 ASSERT(m_fontsToBeginLoading.isEmpty()); 564 ASSERT(m_fontsToBeginLoading.isEmpty());
560 return; 565 return;
561 } 566 }
562 567
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 } 607 }
603 // Ensure that if the request count reaches zero, the frame loader will know about it. 608 // Ensure that if the request count reaches zero, the frame loader will know about it.
604 cachedResourceLoader->loadDone(0); 609 cachedResourceLoader->loadDone(0);
605 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched 610 // 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. 611 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly.
607 if (m_document && m_document->frame()) 612 if (m_document && m_document->frame())
608 m_document->frame()->loader()->checkLoadComplete(); 613 m_document->frame()->loader()->checkLoadComplete();
609 } 614 }
610 615
611 } 616 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSFontSelector.h ('k') | Source/core/css/CSSSegmentedFontFace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698