Clean up some CSS & Font code
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Nov 2015 00:52:46 +0000 (00:52 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Nov 2015 00:52:46 +0000 (00:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150767

Reviewed by Darin Adler.

This patch migrates some CSS code to use references instead of pointers.
It also migrates some Font code to use RefPtr instead of PassRefPtr.

No new tests because there is no behavior change.

* css/CSSDefaultStyleSheets.cpp:
(WebCore::CSSDefaultStyleSheets::loadFullDefaultStyle):
(WebCore::CSSDefaultStyleSheets::loadSimpleDefaultStyle):
(WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):
* css/CSSFontSelector.cpp:
(WebCore::createFontFace):
(WebCore::CSSFontSelector::addFontFaceRule):
* css/CSSFontSelector.h:
* css/DocumentRuleSets.cpp:
(WebCore::DocumentRuleSets::initUserStyle):
(WebCore::DocumentRuleSets::collectRulesFromUserStyleSheets):
(WebCore::DocumentRuleSets::appendAuthorStyleSheets):
* css/RuleSet.cpp:
(WebCore::RuleSet::addChildRules):
(WebCore::RuleSet::addRulesFromSheet):
* css/RuleSet.h:
* css/StyleInvalidationAnalysis.cpp:
(WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
* platform/graphics/Font.cpp:
(WebCore::Font::verticalRightOrientationFont):
(WebCore::Font::uprightOrientationFont):
(WebCore::Font::smallCapsFont):
(WebCore::Font::emphasisMarkFont):
(WebCore::Font::brokenIdeographFont):
(WebCore::Font::nonSyntheticItalicFont):
(WebCore::Font::createScaledFont):
* platform/graphics/Font.h:
(WebCore::Font::variantFont):
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::Font::platformCreateScaledFont):
* svg/SVGFontFaceElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191871 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSDefaultStyleSheets.cpp
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/css/DocumentRuleSets.cpp
Source/WebCore/css/RuleSet.cpp
Source/WebCore/css/RuleSet.h
Source/WebCore/css/StyleInvalidationAnalysis.cpp
Source/WebCore/platform/graphics/Font.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/FontCascadeFonts.cpp
Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm
Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp
Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
Source/WebCore/svg/SVGFontFaceElement.h

index d89972e582cd2aae91e1146bc7d0c220334a843d..5807ad09b0afa2371f451473c752033027eb04fc 100644 (file)
@@ -1,3 +1,47 @@
+2015-11-01  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Clean up some CSS & Font code
+        https://bugs.webkit.org/show_bug.cgi?id=150767
+
+        Reviewed by Darin Adler.
+
+        This patch migrates some CSS code to use references instead of pointers.
+        It also migrates some Font code to use RefPtr instead of PassRefPtr.
+
+        No new tests because there is no behavior change.
+
+        * css/CSSDefaultStyleSheets.cpp:
+        (WebCore::CSSDefaultStyleSheets::loadFullDefaultStyle):
+        (WebCore::CSSDefaultStyleSheets::loadSimpleDefaultStyle):
+        (WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):
+        * css/CSSFontSelector.cpp:
+        (WebCore::createFontFace):
+        (WebCore::CSSFontSelector::addFontFaceRule):
+        * css/CSSFontSelector.h:
+        * css/DocumentRuleSets.cpp:
+        (WebCore::DocumentRuleSets::initUserStyle):
+        (WebCore::DocumentRuleSets::collectRulesFromUserStyleSheets):
+        (WebCore::DocumentRuleSets::appendAuthorStyleSheets):
+        * css/RuleSet.cpp:
+        (WebCore::RuleSet::addChildRules):
+        (WebCore::RuleSet::addRulesFromSheet):
+        * css/RuleSet.h:
+        * css/StyleInvalidationAnalysis.cpp:
+        (WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::verticalRightOrientationFont):
+        (WebCore::Font::uprightOrientationFont):
+        (WebCore::Font::smallCapsFont):
+        (WebCore::Font::emphasisMarkFont):
+        (WebCore::Font::brokenIdeographFont):
+        (WebCore::Font::nonSyntheticItalicFont):
+        (WebCore::Font::createScaledFont):
+        * platform/graphics/Font.h:
+        (WebCore::Font::variantFont):
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::Font::platformCreateScaledFont):
+        * svg/SVGFontFaceElement.h:
+
 2015-11-01  Darin Adler  <darin@apple.com>
 
         Remove some dead and unneeded code (ScrollbarThemeSafari, RenderThemeSafari, OPENCL, a little color space logic)
index 283efacd01846f5a9fdf1a9751eb52c5c73ca907..30c4f56a99b87668548386e1505050be300ec53e 100644 (file)
@@ -127,13 +127,13 @@ void CSSDefaultStyleSheets::loadFullDefaultStyle()
     // Strict-mode rules.
     String defaultRules = String(htmlUserAgentStyleSheet, sizeof(htmlUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraDefaultStyleSheet();
     defaultStyleSheet = parseUASheet(defaultRules);
-    defaultStyle->addRulesFromSheet(defaultStyleSheet, screenEval());
-    defaultPrintStyle->addRulesFromSheet(defaultStyleSheet, printEval());
+    defaultStyle->addRulesFromSheet(*defaultStyleSheet, screenEval());
+    defaultPrintStyle->addRulesFromSheet(*defaultStyleSheet, printEval());
 
     // Quirks-mode rules.
     String quirksRules = String(quirksUserAgentStyleSheet, sizeof(quirksUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraQuirksStyleSheet();
     quirksStyleSheet = parseUASheet(quirksRules);
-    defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet, screenEval());
+    defaultQuirksStyle->addRulesFromSheet(*quirksStyleSheet, screenEval());
 }
 
 void CSSDefaultStyleSheets::loadSimpleDefaultStyle()
@@ -147,7 +147,7 @@ void CSSDefaultStyleSheets::loadSimpleDefaultStyle()
     defaultQuirksStyle = std::make_unique<RuleSet>().release();
 
     simpleDefaultStyleSheet = parseUASheet(simpleUserAgentStyleSheet, strlen(simpleUserAgentStyleSheet));
-    defaultStyle->addRulesFromSheet(simpleDefaultStyleSheet, screenEval());
+    defaultStyle->addRulesFromSheet(*simpleDefaultStyleSheet, screenEval());
 
     // No need to initialize quirks sheet yet as there are no quirk rules for elements allowed in simple default style.
 }
@@ -166,7 +166,7 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element& element,
                 if (plugInsRules.isEmpty())
                     plugInsRules = String(plugInsUserAgentStyleSheet, sizeof(plugInsUserAgentStyleSheet));
                 plugInsStyleSheet = parseUASheet(plugInsRules);
-                defaultStyle->addRulesFromSheet(plugInsStyleSheet, screenEval());
+                defaultStyle->addRulesFromSheet(*plugInsStyleSheet, screenEval());
                 changedDefaultStyle = true;
             }
         }
@@ -177,8 +177,8 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element& element,
                 if (mediaRules.isEmpty())
                     mediaRules = String(mediaControlsUserAgentStyleSheet, sizeof(mediaControlsUserAgentStyleSheet)) + RenderTheme::themeForPage(element.document().page())->extraMediaControlsStyleSheet();
                 mediaControlsStyleSheet = parseUASheet(mediaRules);
-                defaultStyle->addRulesFromSheet(mediaControlsStyleSheet, screenEval());
-                defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet, printEval());
+                defaultStyle->addRulesFromSheet(*mediaControlsStyleSheet, screenEval());
+                defaultPrintStyle->addRulesFromSheet(*mediaControlsStyleSheet, printEval());
                 changedDefaultStyle = true;
             }
         }
@@ -188,8 +188,8 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element& element,
             if (!imageControlsStyleSheet) {
                 String imageControlsRules = RenderTheme::themeForPage(element.document().page())->imageControlsStyleSheet();
                 imageControlsStyleSheet = parseUASheet(imageControlsRules);
-                defaultStyle->addRulesFromSheet(imageControlsStyleSheet, screenEval());
-                defaultPrintStyle->addRulesFromSheet(imageControlsStyleSheet, printEval());
+                defaultStyle->addRulesFromSheet(*imageControlsStyleSheet, screenEval());
+                defaultPrintStyle->addRulesFromSheet(*imageControlsStyleSheet, printEval());
                 changedDefaultStyle = true;
             }
         }
@@ -198,8 +198,8 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element& element,
         if (!svgStyleSheet) {
             // SVG rules.
             svgStyleSheet = parseUASheet(svgUserAgentStyleSheet, sizeof(svgUserAgentStyleSheet));
-            defaultStyle->addRulesFromSheet(svgStyleSheet, screenEval());
-            defaultPrintStyle->addRulesFromSheet(svgStyleSheet, printEval());
+            defaultStyle->addRulesFromSheet(*svgStyleSheet, screenEval());
+            defaultPrintStyle->addRulesFromSheet(*svgStyleSheet, printEval());
             changedDefaultStyle = true;
         }
     }
@@ -208,8 +208,8 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element& element,
         if (!mathMLStyleSheet) {
             // MathML rules.
             mathMLStyleSheet = parseUASheet(mathmlUserAgentStyleSheet, sizeof(mathmlUserAgentStyleSheet));
-            defaultStyle->addRulesFromSheet(mathMLStyleSheet, screenEval());
-            defaultPrintStyle->addRulesFromSheet(mathMLStyleSheet, printEval());
+            defaultStyle->addRulesFromSheet(*mathMLStyleSheet, screenEval());
+            defaultPrintStyle->addRulesFromSheet(*mathMLStyleSheet, printEval());
             changedDefaultStyle = true;
         }
     }
@@ -219,8 +219,8 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element& element,
     if (!fullscreenStyleSheet && element.document().webkitIsFullScreen()) {
         String fullscreenRules = String(fullscreenUserAgentStyleSheet, sizeof(fullscreenUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraFullScreenStyleSheet();
         fullscreenStyleSheet = parseUASheet(fullscreenRules);
-        defaultStyle->addRulesFromSheet(fullscreenStyleSheet, screenEval());
-        defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet, screenEval());
+        defaultStyle->addRulesFromSheet(*fullscreenStyleSheet, screenEval());
+        defaultQuirksStyle->addRulesFromSheet(*fullscreenStyleSheet, screenEval());
         changedDefaultStyle = true;
     }
 #endif // ENABLE(FULLSCREEN_API)
index b868e848a8463c9b3436e9b7e62fc268f18854b5..1e09964b7bbd4ead2eac90ddf3ef564730fcefa8 100644 (file)
@@ -178,13 +178,13 @@ static Optional<FontTraitsMask> computeTraitsMask(const StyleProperties& style)
     return static_cast<FontTraitsMask>(traitsMask);
 }
 
-static Ref<CSSFontFace> createFontFace(CSSValueList& srcList, FontTraitsMask traitsMask, Document* document, const StyleRuleFontFace* fontFaceRule, bool isInitiatingElementInUserAgentShadowTree)
+static Ref<CSSFontFace> createFontFace(CSSValueList& srcList, FontTraitsMask traitsMask, Document* document, const StyleRuleFontFace& fontFaceRule, bool isInitiatingElementInUserAgentShadowTree)
 {
     RefPtr<CSSFontFaceRule> rule;
 #if ENABLE(FONT_LOAD_EVENTS)
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=112116 - This CSSFontFaceRule has no parent.
     if (RuntimeEnabledFeatures::sharedFeatures().fontLoadEventsEnabled())
-        rule = static_pointer_cast<CSSFontFaceRule>(fontFaceRule->createCSSOMWrapper());
+        rule = static_pointer_cast<CSSFontFaceRule>(fontFaceRule.createCSSOMWrapper());
 #else
     UNUSED_PARAM(fontFaceRule);
 #endif
@@ -203,7 +203,7 @@ static Ref<CSSFontFace> createFontFace(CSSValueList& srcList, FontTraitsMask tra
         foundSVGFont = item.isSVGFontFaceSrc() || item.svgFontFaceElement();
 #endif
         if (!item.isLocal()) {
-            Settings* settings = document ? document->frame() ? &document->frame()->settings() : 0 : 0;
+            Settings* settings = document ? document->settings() : nullptr;
             bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
             if (allowDownloading && item.isSupportedFormat() && document) {
                 CachedFont* cachedFont = item.cachedFont(document, foundSVGFont, isInitiatingElementInUserAgentShadowTree);
@@ -277,9 +277,9 @@ static Vector<Ref<CSSFontFace>> constructFamilyFontFaces(const String& familyNam
     return result;
 }
 
-void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule, bool isInitiatingElementInUserAgentShadowTree)
+void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace& fontFaceRule, bool isInitiatingElementInUserAgentShadowTree)
 {
-    const StyleProperties& style = fontFaceRule->properties();
+    const StyleProperties& style = fontFaceRule.properties();
     RefPtr<CSSValue> fontFamily = style.getPropertyCSSValue(CSSPropertyFontFamily);
     RefPtr<CSSValue> src = style.getPropertyCSSValue(CSSPropertySrc);
     RefPtr<CSSValue> unicodeRange = style.getPropertyCSSValue(CSSPropertyUnicodeRange);
index c1ad9559e3da48a8e7b8c1465e86849793281fec..6f130f758a976395e791c3f244bb70e53ed7038d 100644 (file)
@@ -66,7 +66,7 @@ public:
 
     void clearDocument();
 
-    void addFontFaceRule(const StyleRuleFontFace*, bool isInitiatingElementInUserAgentShadowTree);
+    void addFontFaceRule(const StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree);
 
     void fontLoaded();
     virtual void fontCacheInvalidated() override;
index 44aa598f3b8ca2ec816d067f004eda3d66577ed7..b5f90c61cb218b9e686847d139a0f813db6194b5 100644 (file)
@@ -50,7 +50,7 @@ void DocumentRuleSets::initUserStyle(ExtensionStyleSheets& extensionStyleSheets,
 {
     auto tempUserStyle = std::make_unique<RuleSet>();
     if (CSSStyleSheet* pageUserSheet = extensionStyleSheets.pageUserSheet())
-        tempUserStyle->addRulesFromSheet(&pageUserSheet->contents(), medium, &resolver);
+        tempUserStyle->addRulesFromSheet(pageUserSheet->contents(), medium, &resolver);
     collectRulesFromUserStyleSheets(extensionStyleSheets.injectedUserStyleSheets(), *tempUserStyle, medium, resolver);
     collectRulesFromUserStyleSheets(extensionStyleSheets.documentUserStyleSheets(), *tempUserStyle, medium, resolver);
     if (tempUserStyle->ruleCount() > 0 || tempUserStyle->pageRules().size() > 0)
@@ -61,7 +61,7 @@ void DocumentRuleSets::collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSSt
 {
     for (unsigned i = 0; i < userSheets.size(); ++i) {
         ASSERT(userSheets[i]->contents().isUserStyleSheet());
-        userStyle.addRulesFromSheet(&userSheets[i]->contents(), medium, &resolver);
+        userStyle.addRulesFromSheet(userSheets[i]->contents(), medium, &resolver);
     }
 }
 
@@ -91,7 +91,7 @@ void DocumentRuleSets::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet
         ASSERT(!cssSheet->disabled());
         if (cssSheet->mediaQueries() && !medium->eval(cssSheet->mediaQueries(), resolver))
             continue;
-        m_authorStyle->addRulesFromSheet(&cssSheet->contents(), *medium, resolver);
+        m_authorStyle->addRulesFromSheet(cssSheet->contents(), *medium, resolver);
         inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet.get());
     }
     m_authorStyle->shrinkToFit();
index b4af108f0837fbb5a968404dd230dc176e316477..bd2723498df6810f147743f017f375f44456a190 100644 (file)
@@ -339,7 +339,7 @@ void RuleSet::addChildRules(const Vector<RefPtr<StyleRuleBase>>& rules, const Me
                 addChildRules(mediaRule.childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
         } else if (is<StyleRuleFontFace>(*rule) && resolver) {
             // Add this font face to our set.
-            resolver->document().fontSelector().addFontFaceRule(downcast<StyleRuleFontFace>(rule.get()), isInitiatingElementInUserAgentShadowTree);
+            resolver->document().fontSelector().addFontFaceRule(downcast<StyleRuleFontFace>(*rule.get()), isInitiatingElementInUserAgentShadowTree);
             resolver->invalidateMatchedPropertiesCache();
         } else if (is<StyleRuleKeyframes>(*rule) && resolver)
             resolver->addKeyframeStyle(downcast<StyleRuleKeyframes>(rule.get()));
@@ -358,24 +358,20 @@ void RuleSet::addChildRules(const Vector<RefPtr<StyleRuleBase>>& rules, const Me
     }
 }
 
-void RuleSet::addRulesFromSheet(StyleSheetContents* sheet, const MediaQueryEvaluator& medium, StyleResolver* resolver)
+void RuleSet::addRulesFromSheet(StyleSheetContents& sheet, const MediaQueryEvaluator& medium, StyleResolver* resolver)
 {
-    ASSERT(sheet);
-
-    const Vector<RefPtr<StyleRuleImport>>& importRules = sheet->importRules();
-    for (unsigned i = 0; i < importRules.size(); ++i) {
-        StyleRuleImport* importRule = importRules[i].get();
-        if (importRule->styleSheet() && (!importRule->mediaQueries() || medium.eval(importRule->mediaQueries(), resolver)))
-            addRulesFromSheet(importRule->styleSheet(), medium, resolver);
+    for (auto& rule : sheet.importRules()) {
+        if (rule->styleSheet() && (!rule->mediaQueries() || medium.eval(rule->mediaQueries(), resolver)))
+            addRulesFromSheet(*rule->styleSheet(), medium, resolver);
     }
 
-    bool hasDocumentSecurityOrigin = resolver && resolver->document().securityOrigin()->canRequest(sheet->baseURL());
+    bool hasDocumentSecurityOrigin = resolver && resolver->document().securityOrigin()->canRequest(sheet.baseURL());
     AddRuleFlags addRuleFlags = static_cast<AddRuleFlags>((hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : 0));
 
     // FIXME: Skip Content Security Policy check when stylesheet is in a user agent shadow tree.
     // See <https://bugs.webkit.org/show_bug.cgi?id=146663>.
     bool isInitiatingElementInUserAgentShadowTree = false;
-    addChildRules(sheet->childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
+    addChildRules(sheet.childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
 
     if (m_autoShrinkToFitEnabled)
         shrinkToFit();
index 2c7454e8367df6048bf38e7b50324f5e0304dc8c..3e6190a8ac40ebcda053e2c1940c55a87e5bec07 100644 (file)
@@ -159,7 +159,7 @@ public:
     typedef Vector<RuleData, 1> RuleDataVector;
     typedef HashMap<AtomicStringImpl*, std::unique_ptr<RuleDataVector>> AtomRuleMap;
 
-    void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, StyleResolver* = 0);
+    void addRulesFromSheet(StyleSheetContents&, const MediaQueryEvaluator&, StyleResolver* = 0);
 
     void addStyleRule(StyleRule*, AddRuleFlags);
     void addRule(StyleRule*, unsigned selectorIndex, AddRuleFlags);
index 2b90b232145bf9ecbd14bfcbe11f9d28d46285a7..7c2030c65c441351b544154fba901846bae405c4 100644 (file)
@@ -82,7 +82,7 @@ StyleInvalidationAnalysis::StyleInvalidationAnalysis(const Vector<StyleSheetCont
 
     m_ruleSets.resetAuthorStyle();
     for (auto& sheet : sheets)
-        m_ruleSets.authorStyle()->addRulesFromSheet(sheet, mediaQueryEvaluator);
+        m_ruleSets.authorStyle()->addRulesFromSheet(*sheet, mediaQueryEvaluator);
 
     m_hasShadowPseudoElementRulesInAuthorSheet = m_ruleSets.authorStyle()->hasShadowPseudoElementRules();
 }
index 506544d683089de0ed9ae30a5fdf0004a0f3b98e..86f20b62f0831354ce584522f22fa5fc5bc5c8b8 100644 (file)
@@ -265,7 +265,7 @@ GlyphData Font::glyphDataForCharacter(UChar32 character) const
     return page->glyphDataForCharacter(character);
 }
 
-PassRefPtr<Font> Font::verticalRightOrientationFont() const
+const Font& Font::verticalRightOrientationFont() const
 {
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
@@ -275,40 +275,40 @@ PassRefPtr<Font> Font::verticalRightOrientationFont() const
         m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, isCustomFont(), false, true);
     }
     ASSERT(m_derivedFontData->verticalRightOrientation != this);
-    return m_derivedFontData->verticalRightOrientation;
+    return *m_derivedFontData->verticalRightOrientation;
 }
 
-PassRefPtr<Font> Font::uprightOrientationFont() const
+const Font& Font::uprightOrientationFont() const
 {
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->uprightOrientation)
         m_derivedFontData->uprightOrientation = create(m_platformData, isCustomFont(), false, true);
     ASSERT(m_derivedFontData->uprightOrientation != this);
-    return m_derivedFontData->uprightOrientation;
+    return *m_derivedFontData->uprightOrientation;
 }
 
-PassRefPtr<Font> Font::smallCapsFont(const FontDescription& fontDescription) const
+const Font* Font::smallCapsFont(const FontDescription& fontDescription) const
 {
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->smallCaps)
         m_derivedFontData->smallCaps = createScaledFont(fontDescription, smallCapsFontSizeMultiplier);
     ASSERT(m_derivedFontData->smallCaps != this);
-    return m_derivedFontData->smallCaps;
+    return m_derivedFontData->smallCaps.get();
 }
 
-PassRefPtr<Font> Font::emphasisMarkFont(const FontDescription& fontDescription) const
+const Font* Font::emphasisMarkFont(const FontDescription& fontDescription) const
 {
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->emphasisMark)
         m_derivedFontData->emphasisMark = createScaledFont(fontDescription, emphasisMarkFontSizeMultiplier);
     ASSERT(m_derivedFontData->emphasisMark != this);
-    return m_derivedFontData->emphasisMark;
+    return m_derivedFontData->emphasisMark.get();
 }
 
-PassRefPtr<Font> Font::brokenIdeographFont() const
+const Font& Font::brokenIdeographFont() const
 {
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
@@ -317,10 +317,10 @@ PassRefPtr<Font> Font::brokenIdeographFont() const
         m_derivedFontData->brokenIdeograph->m_isBrokenIdeographFallback = true;
     }
     ASSERT(m_derivedFontData->brokenIdeograph != this);
-    return m_derivedFontData->brokenIdeograph;
+    return *m_derivedFontData->brokenIdeograph;
 }
 
-PassRefPtr<Font> Font::nonSyntheticItalicFont() const
+const Font& Font::nonSyntheticItalicFont() const
 {
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
@@ -332,7 +332,7 @@ PassRefPtr<Font> Font::nonSyntheticItalicFont() const
         m_derivedFontData->nonSyntheticItalic = create(nonSyntheticItalicFontPlatformData, isCustomFont());
     }
     ASSERT(m_derivedFontData->nonSyntheticItalic != this);
-    return m_derivedFontData->nonSyntheticItalic;
+    return *m_derivedFontData->nonSyntheticItalic;
 }
 
 #ifndef NDEBUG
@@ -363,7 +363,7 @@ Font::DerivedFontData::~DerivedFontData()
 {
 }
 
-PassRefPtr<Font> Font::createScaledFont(const FontDescription& fontDescription, float scaleFactor) const
+RefPtr<Font> Font::createScaledFont(const FontDescription& fontDescription, float scaleFactor) const
 {
     if (isSVGFont())
         return nullptr;
index bc78eff34f56797e0d2ae145a04831060e68f4a1..536b36d2fa19b34e2a293314883f02db18f74026 100644 (file)
@@ -100,12 +100,12 @@ public:
     const OpenTypeVerticalData* verticalData() const { return m_verticalData.get(); }
 #endif
 
-    PassRefPtr<Font> smallCapsFont(const FontDescription&) const;
-    PassRefPtr<Font> emphasisMarkFont(const FontDescription&) const;
-    PassRefPtr<Font> brokenIdeographFont() const;
-    PassRefPtr<Font> nonSyntheticItalicFont() const;
+    const Font* smallCapsFont(const FontDescription&) const;
+    const Font* emphasisMarkFont(const FontDescription&) const;
+    const Font& brokenIdeographFont() const;
+    const Font& nonSyntheticItalicFont() const;
 
-    PassRefPtr<Font> variantFont(const FontDescription& description, FontVariant variant) const
+    const Font* variantFont(const FontDescription& description, FontVariant variant) const
     {
         switch (variant) {
         case SmallCapsVariant:
@@ -113,7 +113,7 @@ public:
         case EmphasisMarkVariant:
             return emphasisMarkFont(description);
         case BrokenIdeographVariant:
-            return brokenIdeographFont();
+            return &brokenIdeographFont();
         case AutoVariant:
         case NormalVariant:
             break;
@@ -122,8 +122,8 @@ public:
         return const_cast<Font*>(this);
     }
 
-    PassRefPtr<Font> verticalRightOrientationFont() const;
-    PassRefPtr<Font> uprightOrientationFont() const;
+    const Font& verticalRightOrientationFont() const;
+    const Font& uprightOrientationFont() const;
 
     bool hasVerticalGlyphs() const { return m_hasVerticalGlyphs; }
     bool isTextOrientationFallback() const { return m_isTextOrientationFallback; }
@@ -228,8 +228,8 @@ private:
 
     void initCharWidths();
 
-    PassRefPtr<Font> createScaledFont(const FontDescription&, float scaleFactor) const;
-    PassRefPtr<Font> platformCreateScaledFont(const FontDescription&, float scaleFactor) const;
+    RefPtr<Font> createScaledFont(const FontDescription&, float scaleFactor) const;
+    RefPtr<Font> platformCreateScaledFont(const FontDescription&, float scaleFactor) const;
 
     void removeFromSystemFallbackCache();
 
index 2e6368009439a435110e382934bb61efd25527f1..a289cf4ad455b07219af1e9cfa2bed0a041bbf1c 100644 (file)
@@ -285,7 +285,7 @@ static bool shouldIgnoreRotation(UChar32 character)
 #if PLATFORM(COCOA) || USE(CAIRO)
 static GlyphData glyphDataForCJKCharacterWithoutSyntheticItalic(UChar32 character, GlyphData& data)
 {
-    GlyphData nonItalicData = data.font->nonSyntheticItalicFont()->glyphDataForCharacter(character);
+    GlyphData nonItalicData = data.font->nonSyntheticItalicFont().glyphDataForCharacter(character);
     if (nonItalicData.font)
         return nonItalicData;
     return data;
@@ -295,7 +295,7 @@ static GlyphData glyphDataForCJKCharacterWithoutSyntheticItalic(UChar32 characte
 static GlyphData glyphDataForNonCJKCharacterWithGlyphOrientation(UChar32 character, NonCJKGlyphOrientation orientation, const GlyphData& data)
 {
     if (orientation == NonCJKGlyphOrientationUpright || shouldIgnoreRotation(character)) {
-        GlyphData uprightData = data.font->uprightOrientationFont()->glyphDataForCharacter(character);
+        GlyphData uprightData = data.font->uprightOrientationFont().glyphDataForCharacter(character);
         // If the glyphs are the same, then we know we can just use the horizontal glyph rotated vertically to be upright.
         if (data.glyph == uprightData.glyph)
             return data;
@@ -304,7 +304,7 @@ static GlyphData glyphDataForNonCJKCharacterWithGlyphOrientation(UChar32 charact
         if (uprightData.font)
             return uprightData;
     } else if (orientation == NonCJKGlyphOrientationVerticalRight) {
-        GlyphData verticalRightData = data.font->verticalRightOrientationFont()->glyphDataForCharacter(character);
+        GlyphData verticalRightData = data.font->verticalRightOrientationFont().glyphDataForCharacter(character);
         // If the glyphs are distinct, we will make the assumption that the font has a vertical-right glyph baked
         // into it.
         if (data.glyph != verticalRightData.glyph)
@@ -363,11 +363,9 @@ GlyphData FontCascadeFonts::glyphDataForVariant(UChar32 c, const FontCascadeDesc
         if (data.font) {
             // The variantFont function should not normally return 0.
             // But if it does, we will just render the capital letter big.
-            RefPtr<Font> variantFont = data.font->variantFont(description, variant);
-            if (!variantFont)
-                return data;
-
-            return variantFont->glyphDataForCharacter(c);
+            if (const Font* variantFont = data.font->variantFont(description, variant))
+                return variantFont->glyphDataForCharacter(c);
+            return data;
         }
     }
 
index 8d17d3fb7743f99952214befaad41ccc0d598867..6838695bdc374d70e591f8018530ac5f5b1fba87 100644 (file)
@@ -719,21 +719,21 @@ const Font* FontCascade::fontForCombiningCharacterSequence(const UChar* characte
             if (font->platformData().orientation() == Vertical) {
                 if (isCJKIdeographOrSymbol(baseCharacter) && !font->hasVerticalGlyphs()) {
                     variant = BrokenIdeographVariant;
-                    font = font->brokenIdeographFont().get();
+                    font = &font->brokenIdeographFont();
                 } else if (m_fontDescription.nonCJKGlyphOrientation() == NonCJKGlyphOrientationVerticalRight) {
-                    Font* verticalRightFont = font->verticalRightOrientationFont().get();
-                    Glyph verticalRightGlyph = verticalRightFont->glyphForCharacter(baseCharacter);
+                    const Font& verticalRightFont = font->verticalRightOrientationFont();
+                    Glyph verticalRightGlyph = verticalRightFont.glyphForCharacter(baseCharacter);
                     if (verticalRightGlyph == baseCharacterGlyphData.glyph)
-                        font = verticalRightFont;
+                        font = &verticalRightFont;
                 } else {
-                    Font* uprightFont = font->uprightOrientationFont().get();
-                    Glyph uprightGlyph = uprightFont->glyphForCharacter(baseCharacter);
+                    const Font& uprightFont = font->uprightOrientationFont();
+                    Glyph uprightGlyph = uprightFont.glyphForCharacter(baseCharacter);
                     if (uprightGlyph != baseCharacterGlyphData.glyph)
-                        font = uprightFont;
+                        font = &uprightFont;
                 }
             }
         } else {
-            if (const Font* variantFont = font->variantFont(m_fontDescription, variant).get())
+            if (const Font* variantFont = font->variantFont(m_fontDescription, variant))
                 font = variantFont;
         }
 
index e985fbcc0466f7b1d6bb813869bed725c792a06a..51edd84fda50113276e52bab43bdb30624655ba4 100644 (file)
@@ -245,7 +245,7 @@ void Font::platformInit()
         else
             xHeight = scaleEmToUnits(CGFontGetXHeight(m_platformData.cgFont()), unitsPerEm) * pointSize;
     } else
-        xHeight = verticalRightOrientationFont()->fontMetrics().xHeight();
+        xHeight = verticalRightOrientationFont().fontMetrics().xHeight();
 
     m_fontMetrics.setUnitsPerEm(unitsPerEm);
     m_fontMetrics.setAscent(ascent);
@@ -308,7 +308,7 @@ void Font::platformDestroy()
 {
 }
 
-PassRefPtr<Font> Font::platformCreateScaledFont(const FontDescription&, float scaleFactor) const
+RefPtr<Font> Font::platformCreateScaledFont(const FontDescription&, float scaleFactor) const
 {
 #if !CORETEXT_WEB_FONTS
     if (isCustomFont()) {
index 55a1d72701dec63b1114ad97893b6317c5b0340c..709b2598b212c90b9479b471ceb5f6d5b62f6a02 100644 (file)
@@ -115,7 +115,7 @@ void Font::platformCharWidthInit()
     initCharWidths();
 }
 
-PassRefPtr<Font> Font::platformCreateScaledFont(const FontDescription& fontDescription, float scaleFactor) const
+RefPtr<Font> Font::platformCreateScaledFont(const FontDescription& fontDescription, float scaleFactor) const
 {
     ASSERT(m_platformData.scaledFont());
     FontDescription scaledFontDescription = fontDescription;
index b3722f27a2243d2b701483e5601b81240c01fc1d..fb6c345c1c76e5e171b06f5758137fed94af38e5 100644 (file)
@@ -122,7 +122,7 @@ void Font::platformDestroy()
     delete m_scriptFontProperties;
 }
 
-PassRefPtr<Font> Font::platformCreateScaledFont(const FontDescription& fontDescription, float scaleFactor) const
+RefPtr<Font> Font::platformCreateScaledFont(const FontDescription& fontDescription, float scaleFactor) const
 {
     float scaledSize = scaleFactor * m_platformData.size();
     if (isCustomFont()) {
index 50044f50f0a17065853d9bd9169c2cb9fba11afc..d28283a33b9e35f5b8c3064ad66f378cf6568808 100644 (file)
@@ -50,7 +50,7 @@ public:
     SVGFontElement* associatedFontElement() const;
     void rebuildFontFace();
     
-    StyleRuleFontFace* fontFaceRule() const { return m_fontFaceRule.get(); }
+    const StyleRuleFontFace& fontFaceRule() const { return m_fontFaceRule.get(); }
 
 private:
     SVGFontFaceElement(const QualifiedName&, Document&);
@@ -63,7 +63,7 @@ private:
 
     virtual bool rendererIsNeeded(const RenderStyle&) override { return false; }
 
-    RefPtr<StyleRuleFontFace> m_fontFaceRule;
+    Ref<StyleRuleFontFace> m_fontFaceRule;
     SVGFontElement* m_fontElement;
 };