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

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

Issue 18882002: [oilpan] Move 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // seem to be any such guarantee. 71 // seem to be any such guarantee.
72 72
73 ASSERT(m_document); 73 ASSERT(m_document);
74 fontCache()->addClient(this); 74 fontCache()->addClient(this);
75 } 75 }
76 76
77 CSSFontSelector::~CSSFontSelector() 77 CSSFontSelector::~CSSFontSelector()
78 { 78 {
79 clearDocument(); 79 clearDocument();
80 fontCache()->removeClient(this); 80 fontCache()->removeClient(this);
81
82 // FIXME(oilpan): This code iterates over all CSSSegmentedFontFace's CSSFont Selector owns
83 // and ask their CSSFontFace's to clear their lists of CSSFontFaceSource.
84 // When CSSFontSelector is moved to the managed heap we should move this
85 // clearing to the moment when StyleResolver is detached from the document ( by clearStyleResolver()).
86 for (HashMap<String, OwnPtr<SegmentedFontFaceHashMap>, WTF::FastAllocator, C aseFoldingHash>::iterator it = m_fonts.begin(); it != m_fonts.end(); ++it) {
87 SegmentedFontFaceHashMap* segmentedFontFaceHashMap = it->value.get();
88 for (SegmentedFontFaceHashMap::iterator it2 = segmentedFontFaceHashMap-> begin(); it2 != segmentedFontFaceHashMap->end(); ++it2)
89 it2->value->dispose();
90 }
81 } 91 }
82 92
83 bool CSSFontSelector::isEmpty() const 93 bool CSSFontSelector::isEmpty() const
84 { 94 {
85 return m_fonts.isEmpty(); 95 return m_fonts.isEmpty();
86 } 96 }
87 97
88 void CSSFontSelector::addFontFaceRule(const Handle<StyleRuleFontFace>& fontFaceR ule) 98 void CSSFontSelector::addFontFaceRule(const Handle<StyleRuleFontFace>& fontFaceR ule)
89 { 99 {
90 // Obtain the font-family property and the src property. Both must be defin ed. 100 // Obtain the font-family property and the src property. Both must be defin ed.
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName) 490 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName)
481 { 491 {
482 if (m_fontFaces.isEmpty()) { 492 if (m_fontFaces.isEmpty()) {
483 if (familyName.startsWith("-webkit-")) 493 if (familyName.startsWith("-webkit-"))
484 return fontDataForGenericFamily(m_document, fontDescription, familyN ame); 494 return fontDataForGenericFamily(m_document, fontDescription, familyN ame);
485 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) 495 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont())
486 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 496 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
487 return 0; 497 return 0;
488 } 498 }
489 499
490 CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName); 500 Handle<CSSSegmentedFontFace> face = getFontFace(fontDescription, familyName) ;
491 // If no face was found, then return 0 and let the OS come up with its best match for the name. 501 // If no face was found, then return 0 and let the OS come up with its best match for the name.
492 if (!face) { 502 if (!face) {
493 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our 503 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
494 // settings. 504 // settings.
495 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) 505 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont())
496 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); 506 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard");
497 return fontDataForGenericFamily(m_document, fontDescription, familyName) ; 507 return fontDataForGenericFamily(m_document, fontDescription, familyName) ;
498 } 508 }
499 509
500 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. 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.
501 return face->getFontData(fontDescription); 511 return face->getFontData(fontDescription);
502 } 512 }
503 513
504 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe scription, const AtomicString& family) 514 Result<CSSSegmentedFontFace> CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family)
505 { 515 {
506 Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family); 516 Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family);
507 if (!familyFontFaces || familyFontFaces->isEmpty()) 517 if (!familyFontFaces || familyFontFaces->isEmpty())
508 return 0; 518 return nullptr;
509 519
510 OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >& segmentedFontFace Cache = m_fonts.add(family, nullptr).iterator->value; 520 OwnPtr<HashMap<unsigned, Persistent<CSSSegmentedFontFace> > >& segmentedFont FaceCache = m_fonts.add(family, nullptr).iterator->value;
511 if (!segmentedFontFaceCache) 521 if (!segmentedFontFaceCache)
512 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, RefPtr<CSSSegmen tedFontFace> >); 522 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, Persistent<CSSSe gmentedFontFace> >());
513 523
514 FontTraitsMask traitsMask = fontDescription.traitsMask(); 524 FontTraitsMask traitsMask = fontDescription.traitsMask();
515 525
516 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask, 0).iterator->value; 526 Handle<CSSSegmentedFontFace> face = segmentedFontFaceCache->add(traitsMask, nullptr).iterator->value;
517 if (!face) { 527 if (!face) {
518 face = CSSSegmentedFontFace::create(this); 528 face = CSSSegmentedFontFace::create(this);
529 segmentedFontFaceCache->set(traitsMask, face);
519 530
520 // Collect all matching faces and sort them in order of preference. 531 // Collect all matching faces and sort them in order of preference.
521 Vector<CSSFontFace*, 32> candidateFontFaces; 532 Vector<CSSFontFace*, 32> candidateFontFaces;
522 for (int i = familyFontFaces->size() - 1; i >= 0; --i) { 533 for (int i = familyFontFaces->size() - 1; i >= 0; --i) {
523 CSSFontFace* candidate = familyFontFaces->at(i).get(); 534 CSSFontFace* candidate = familyFontFaces->at(i).get();
524 unsigned candidateTraitsMask = candidate->traitsMask(); 535 unsigned candidateTraitsMask = candidate->traitsMask();
525 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask)) 536 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask))
526 continue; 537 continue;
527 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) 538 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask))
528 continue; 539 continue;
(...skipping 18 matching lines...) Expand all
547 candidateFontFaces.append(candidate); 558 candidateFontFaces.append(candidate);
548 } 559 }
549 } 560 }
550 561
551 desiredTraitsMaskForComparison = traitsMask; 562 desiredTraitsMaskForComparison = traitsMask;
552 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces); 563 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces);
553 unsigned numCandidates = candidateFontFaces.size(); 564 unsigned numCandidates = candidateFontFaces.size();
554 for (unsigned i = 0; i < numCandidates; ++i) 565 for (unsigned i = 0; i < numCandidates; ++i)
555 face->appendFontFace(candidateFontFaces[i]); 566 face->appendFontFace(candidateFontFaces[i]);
556 } 567 }
557 return face.get(); 568 return face;
558 } 569 }
559 570
560 void CSSFontSelector::clearDocument() 571 void CSSFontSelector::clearDocument()
561 { 572 {
562 if (!m_document) { 573 if (!m_document) {
563 ASSERT(!m_beginLoadingTimer.isActive()); 574 ASSERT(!m_beginLoadingTimer.isActive());
564 ASSERT(m_fontsToBeginLoading.isEmpty()); 575 ASSERT(m_fontsToBeginLoading.isEmpty());
565 return; 576 return;
566 } 577 }
567 578
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 618 }
608 // Ensure that if the request count reaches zero, the frame loader will know about it. 619 // Ensure that if the request count reaches zero, the frame loader will know about it.
609 cachedResourceLoader->loadDone(0); 620 cachedResourceLoader->loadDone(0);
610 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched 621 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched
611 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly. 622 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly.
612 if (m_document && m_document->frame()) 623 if (m_document && m_document->frame())
613 m_document->frame()->loader()->checkLoadComplete(); 624 m_document->frame()->loader()->checkLoadComplete();
614 } 625 }
615 626
616 } 627 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698