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

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

Issue 18856015: [oilpan] Move CSSFontFace 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 traitsMask |= FontVariantSmallCapsMask; 199 traitsMask |= FontVariantSmallCapsMask;
200 break; 200 break;
201 default: 201 default:
202 break; 202 break;
203 } 203 }
204 } 204 }
205 } else 205 } else
206 traitsMask |= FontVariantMask; 206 traitsMask |= FontVariantMask;
207 207
208 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace. 208 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace.
209 RefPtr<CSSFontFace> fontFace; 209 Handle<CSSFontFace> fontFace;
210 210
211 int srcLength = srcList->length(); 211 int srcLength = srcList->length();
212 212
213 bool foundSVGFont = false; 213 bool foundSVGFont = false;
214 214
215 Handle<CSSFontFaceSrcValue> item; 215 Handle<CSSFontFaceSrcValue> item;
216 for (int i = 0; i < srcLength; i++) { 216 for (int i = 0; i < srcLength; i++) {
217 HandleScope scope; 217 HandleScope scope;
218 // An item in the list either specifies a string (local font name) or a URL (remote font to download). 218 // An item in the list either specifies a string (local font name) or a URL (remote font to download).
219 item = Handle<CSSFontFaceSrcValue>::cast(srcList->itemWithoutBoundsCheck (i)); 219 item = Handle<CSSFontFaceSrcValue>::cast(srcList->itemWithoutBoundsCheck (i));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 familyName = pictographFamily; 300 familyName = pictographFamily;
301 break; 301 break;
302 default: 302 default:
303 break; 303 break;
304 } 304 }
305 } 305 }
306 306
307 if (familyName.isEmpty()) 307 if (familyName.isEmpty())
308 continue; 308 continue;
309 309
310 OwnPtr<Vector<RefPtr<CSSFontFace> > >& familyFontFaces = m_fontFaces.add (familyName, nullptr).iterator->value; 310 // FIXME(oilpan): Using a raw pointer is safe because we're inside CSSFo ntSelector's
311 // method and the CSSFontSelector keeps lifetime of the collection.
312 CSSFontFaceVectorCollection* familyFontFaces = m_fontFaces.add(familyNam e, nullptr).iterator->value.get();
311 if (!familyFontFaces) { 313 if (!familyFontFaces) {
312 familyFontFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >); 314 familyFontFaces = new CSSFontFaceVectorCollection;
315 m_fontFaces.set(familyName, adoptPtr(familyFontFaces));
313 316
314 ASSERT(!m_locallyInstalledFontFaces.contains(familyName)); 317 ASSERT(!m_locallyInstalledFontFaces.contains(familyName));
315 318
316 Vector<unsigned> locallyInstalledFontsTraitsMasks; 319 Vector<unsigned> locallyInstalledFontsTraitsMasks;
317 fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTrai tsMasks); 320 fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTrai tsMasks);
318 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsM asks.size()) { 321 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsM asks.size()) {
319 OwnPtr<Vector<RefPtr<CSSFontFace> > > familyLocallyInstalledFace s = adoptPtr(new Vector<RefPtr<CSSFontFace> >); 322 OwnPtr<CSSFontFaceVectorCollection> familyLocallyInstalledFaces = adoptPtr(new CSSFontFaceVectorCollection);
320 323
321 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) { 324 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) {
322 RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true); 325 HandleScope scope;
326 Handle<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true);
323 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName))); 327 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName)));
324 ASSERT(locallyInstalledFontFace->isValid()); 328 ASSERT(locallyInstalledFontFace->isValid());
325 familyLocallyInstalledFaces->append(locallyInstalledFontFace ); 329 (*familyLocallyInstalledFaces)->append(locallyInstalledFontF ace);
326 } 330 }
327 331
328 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release()); 332 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release());
329 } 333 }
330 } 334 }
331 335
332 familyFontFaces->append(fontFace); 336 (*familyFontFaces)->append(fontFace);
333 337
334 ++m_version; 338 ++m_version;
335 } 339 }
336 } 340 }
337 341
338 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t) 342 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t)
339 { 343 {
340 m_clients.add(client); 344 m_clients.add(client);
341 } 345 }
342 346
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 genericFamily = settings->standardFontFamily(script); 404 genericFamily = settings->standardFontFamily(script);
401 405
402 if (!genericFamily.isEmpty()) 406 if (!genericFamily.isEmpty())
403 return fontCache()->getCachedFontData(fontDescription, genericFamily); 407 return fontCache()->getCachedFontData(fontDescription, genericFamily);
404 408
405 return 0; 409 return 0;
406 } 410 }
407 411
408 static FontTraitsMask desiredTraitsMaskForComparison; 412 static FontTraitsMask desiredTraitsMaskForComparison;
409 413
410 static inline bool compareFontFaces(CSSFontFace* first, CSSFontFace* second) 414 static inline bool compareFontFaces(Handle<CSSFontFace> first, Handle<CSSFontFac e> second)
411 { 415 {
412 FontTraitsMask firstTraitsMask = first->traitsMask(); 416 FontTraitsMask firstTraitsMask = first->traitsMask();
413 FontTraitsMask secondTraitsMask = second->traitsMask(); 417 FontTraitsMask secondTraitsMask = second->traitsMask();
414 418
415 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask; 419 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask;
416 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask; 420 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask;
417 421
418 if (firstHasDesiredVariant != secondHasDesiredVariant) 422 if (firstHasDesiredVariant != secondHasDesiredVariant)
419 return firstHasDesiredVariant; 423 return firstHasDesiredVariant;
420 424
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 510 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
507 return fontDataForGenericFamily(m_document, fontDescription, familyName) ; 511 return fontDataForGenericFamily(m_document, fontDescription, familyName) ;
508 } 512 }
509 513
510 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. 514 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over.
511 return face->getFontData(fontDescription); 515 return face->getFontData(fontDescription);
512 } 516 }
513 517
514 Result<CSSSegmentedFontFace> CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family) 518 Result<CSSSegmentedFontFace> CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family)
515 { 519 {
516 Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family); 520 // FIXME(oilpan): Using a raw pointer is safe because we're inside CSSFontSe lector's
517 if (!familyFontFaces || familyFontFaces->isEmpty()) 521 // method and the CSSFontSelector keeps lifetime of the collection.
522 CSSFontFaceVectorCollection* familyFontFaces = m_fontFaces.get(family);
523 if (!familyFontFaces || (*familyFontFaces)->isEmpty())
518 return nullptr; 524 return nullptr;
519 525
520 OwnPtr<HashMap<unsigned, Persistent<CSSSegmentedFontFace> > >& segmentedFont FaceCache = m_fonts.add(family, nullptr).iterator->value; 526 OwnPtr<HashMap<unsigned, Persistent<CSSSegmentedFontFace> > >& segmentedFont FaceCache = m_fonts.add(family, nullptr).iterator->value;
521 if (!segmentedFontFaceCache) 527 if (!segmentedFontFaceCache)
522 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, Persistent<CSSSe gmentedFontFace> >()); 528 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, Persistent<CSSSe gmentedFontFace> >());
523 529
524 FontTraitsMask traitsMask = fontDescription.traitsMask(); 530 FontTraitsMask traitsMask = fontDescription.traitsMask();
525 531
526 Handle<CSSSegmentedFontFace> face = segmentedFontFaceCache->add(traitsMask, nullptr).iterator->value; 532 Handle<CSSSegmentedFontFace> face = segmentedFontFaceCache->add(traitsMask, nullptr).iterator->value;
527 if (!face) { 533 if (!face) {
528 face = CSSSegmentedFontFace::create(this); 534 face = CSSSegmentedFontFace::create(this);
529 segmentedFontFaceCache->set(traitsMask, face); 535 segmentedFontFaceCache->set(traitsMask, face);
530 536
531 // Collect all matching faces and sort them in order of preference. 537 // Collect all matching faces and sort them in order of preference.
532 Vector<CSSFontFace*, 32> candidateFontFaces; 538 CollectionRoot<Vector<Member<CSSFontFace>, 32> > candidateFontFaces;
533 for (int i = familyFontFaces->size() - 1; i >= 0; --i) { 539 for (int i = (*familyFontFaces)->size() - 1; i >= 0; --i) {
534 CSSFontFace* candidate = familyFontFaces->at(i).get(); 540 HandleScope scope;
541 Handle<CSSFontFace> candidate = (*familyFontFaces)->at(i);
535 unsigned candidateTraitsMask = candidate->traitsMask(); 542 unsigned candidateTraitsMask = candidate->traitsMask();
536 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask)) 543 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask))
537 continue; 544 continue;
538 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) 545 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask))
539 continue; 546 continue;
540 #if ENABLE(SVG_FONTS) 547 #if ENABLE(SVG_FONTS)
541 // For SVG Fonts that specify that they only support the "normal" va riant, we will assume they are incapable 548 // For SVG Fonts that specify that they only support the "normal" va riant, we will assume they are incapable
542 // of small-caps synthesis and just ignore the font face as a candid ate. 549 // of small-caps synthesis and just ignore the font face as a candid ate.
543 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask)) 550 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask))
544 continue; 551 continue;
545 #endif 552 #endif
546 candidateFontFaces.append(candidate); 553 candidateFontFaces->append(candidate);
547 } 554 }
548 555
549 if (Vector<RefPtr<CSSFontFace> >* familyLocallyInstalledFontFaces = m_lo callyInstalledFontFaces.get(family)) { 556 CSSFontFaceVectorCollection* familyLocallyInstalledFontFaces = m_locally InstalledFontFaces.get(family);
550 unsigned numLocallyInstalledFontFaces = familyLocallyInstalledFontFa ces->size(); 557 if (familyLocallyInstalledFontFaces) {
558 unsigned numLocallyInstalledFontFaces = (*familyLocallyInstalledFont Faces)->size();
551 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) { 559 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) {
552 CSSFontFace* candidate = familyLocallyInstalledFontFaces->at(i). get(); 560 Handle<CSSFontFace> candidate = (*familyLocallyInstalledFontFace s)->at(i);
553 unsigned candidateTraitsMask = candidate->traitsMask(); 561 unsigned candidateTraitsMask = candidate->traitsMask();
554 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) 562 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask))
555 continue; 563 continue;
556 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask)) 564 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask))
557 continue; 565 continue;
558 candidateFontFaces.append(candidate); 566 candidateFontFaces->append(candidate);
559 } 567 }
560 } 568 }
561 569
562 desiredTraitsMaskForComparison = traitsMask; 570 desiredTraitsMaskForComparison = traitsMask;
563 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces); 571 stable_sort(candidateFontFaces->begin(), candidateFontFaces->end(), comp areFontFaces);
564 unsigned numCandidates = candidateFontFaces.size(); 572 unsigned numCandidates = candidateFontFaces->size();
565 for (unsigned i = 0; i < numCandidates; ++i) 573 for (unsigned i = 0; i < numCandidates; ++i)
566 face->appendFontFace(candidateFontFaces[i]); 574 face->appendFontFace(candidateFontFaces->at(i));
567 } 575 }
568 return face; 576 return face;
569 } 577 }
570 578
571 void CSSFontSelector::clearDocument() 579 void CSSFontSelector::clearDocument()
572 { 580 {
573 if (!m_document) { 581 if (!m_document) {
574 ASSERT(!m_beginLoadingTimer.isActive()); 582 ASSERT(!m_beginLoadingTimer.isActive());
575 ASSERT(m_fontsToBeginLoading.isEmpty()); 583 ASSERT(m_fontsToBeginLoading.isEmpty());
576 return; 584 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 626 }
619 // Ensure that if the request count reaches zero, the frame loader will know about it. 627 // Ensure that if the request count reaches zero, the frame loader will know about it.
620 cachedResourceLoader->loadDone(0); 628 cachedResourceLoader->loadDone(0);
621 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched 629 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched
622 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly. 630 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly.
623 if (m_document && m_document->frame()) 631 if (m_document && m_document->frame())
624 m_document->frame()->loader()->checkLoadComplete(); 632 m_document->frame()->loader()->checkLoadComplete();
625 } 633 }
626 634
627 } 635 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698