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

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