Changeset 176751 in webkit


Ignore:
Timestamp:
Dec 3, 2014, 1:01:36 PM (11 years ago)
Author:
Antti Koivisto
Message:

Remove genericFamily enum from FontDescription
https://bugs.webkit.org/show_bug.cgi?id=139207

Reviewed by Andreas Kling.

We use predefined AtomicStrings for generic families. The side enum adds no information.

  • css/CSSFontSelector.cpp:

(WebCore::resolveGenericFamily):
(WebCore::CSSFontSelector::getFontData):

Match the existing quirk where the default font can be replaced by @font-face rule but user generic families can't.

(WebCore::CSSFontSelector::resolvesFamilyFor):
(WebCore::fontDataForGenericFamily): Deleted.

  • css/DeprecatedStyleBuilder.cpp:

(WebCore::ApplyPropertyFontFamily::applyInheritValue):
(WebCore::ApplyPropertyFontFamily::applyInitialValue):
(WebCore::ApplyPropertyFontFamily::applyValue):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::checkForGenericFamilyChange):

Remove the explicit monospace check, earlier useFixedDefaultSize check is equivalent.

(WebCore::StyleResolver::initializeFontStyle):

  • platform/graphics/FontDescription.h:

(WebCore::FontDescription::FontDescription):
(WebCore::FontDescription::useFixedDefaultSize):
(WebCore::FontDescription::setWeight):
(WebCore::FontDescription::equalForTextAutoSizing):
(WebCore::FontDescription::operator==):
(WebCore::FontDescription::genericFamily): Deleted.
(WebCore::FontDescription::setGenericFamily): Deleted.

  • platform/mac/ThemeMac.mm:

(WebCore::ThemeMac::controlFont):

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::adjustStyle):

Reset the lineheight unconditionally for buttons.
This always happened before because the explicitly set generic family made the font compare false.

  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::systemFont):

  • rendering/RenderThemeMac.mm:

(WebCore::RenderThemeMac::systemFont):
(WebCore::RenderThemeMac::setFontFromControlSize):

  • style/StyleResolveForDocument.cpp:

(WebCore::Style::resolveForDocument):

Resolve document style for final value immediately as it can't be affected by @font-face rules.

Location:
trunk/Source/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176750 r176751  
     12014-12-03  Antti Koivisto  <antti@apple.com>
     2
     3        Remove genericFamily enum from FontDescription
     4        https://bugs.webkit.org/show_bug.cgi?id=139207
     5
     6        Reviewed by Andreas Kling.
     7
     8        We use predefined AtomicStrings for generic families. The side enum adds no information.
     9
     10        * css/CSSFontSelector.cpp:
     11        (WebCore::resolveGenericFamily):
     12        (WebCore::CSSFontSelector::getFontData):
     13
     14            Match the existing quirk where the default font can be replaced by @font-face rule but user generic families can't.
     15
     16        (WebCore::CSSFontSelector::resolvesFamilyFor):
     17        (WebCore::fontDataForGenericFamily): Deleted.
     18        * css/DeprecatedStyleBuilder.cpp:
     19        (WebCore::ApplyPropertyFontFamily::applyInheritValue):
     20        (WebCore::ApplyPropertyFontFamily::applyInitialValue):
     21        (WebCore::ApplyPropertyFontFamily::applyValue):
     22        * css/StyleResolver.cpp:
     23        (WebCore::StyleResolver::checkForGenericFamilyChange):
     24
     25            Remove the explicit monospace check, earlier useFixedDefaultSize check is equivalent.
     26
     27        (WebCore::StyleResolver::initializeFontStyle):
     28        * platform/graphics/FontDescription.h:
     29        (WebCore::FontDescription::FontDescription):
     30        (WebCore::FontDescription::useFixedDefaultSize):
     31        (WebCore::FontDescription::setWeight):
     32        (WebCore::FontDescription::equalForTextAutoSizing):
     33        (WebCore::FontDescription::operator==):
     34        (WebCore::FontDescription::genericFamily): Deleted.
     35        (WebCore::FontDescription::setGenericFamily): Deleted.
     36        * platform/mac/ThemeMac.mm:
     37        (WebCore::ThemeMac::controlFont):
     38        * rendering/RenderTheme.cpp:
     39        (WebCore::RenderTheme::adjustStyle):
     40
     41            Reset the lineheight unconditionally for buttons.
     42            This always happened before because the explicitly set generic family made the font compare false.
     43
     44        * rendering/RenderThemeIOS.mm:
     45        (WebCore::RenderThemeIOS::systemFont):
     46        * rendering/RenderThemeMac.mm:
     47        (WebCore::RenderThemeMac::systemFont):
     48        (WebCore::RenderThemeMac::setFontFromControlSize):
     49        * style/StyleResolveForDocument.cpp:
     50        (WebCore::Style::resolveForDocument):
     51
     52            Resolve document style for final value immediately as it can't be affected by @font-face rules.
     53
    1542014-12-03  Zalan Bujtas  <zalan@apple.com>
    255
  • trunk/Source/WebCore/css/CSSFontSelector.cpp

    r176459 r176751  
    361361}
    362362
    363 static PassRefPtr<SimpleFontData> fontDataForGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
     363static const AtomicString& resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomicString& familyName)
    364364{
    365365    if (!document || !document->frame())
    366         return 0;
     366        return familyName;
    367367
    368368    const Settings& settings = document->frame()->settings();
    369369
    370     AtomicString genericFamily;
    371370    UScriptCode script = fontDescription.script();
    372 
    373371    if (familyName == serifFamily)
    374         genericFamily = settings.serifFontFamily(script);
    375     else if (familyName == sansSerifFamily)
    376         genericFamily = settings.sansSerifFontFamily(script);
    377     else if (familyName == cursiveFamily)
    378         genericFamily = settings.cursiveFontFamily(script);
    379     else if (familyName == fantasyFamily)
    380         genericFamily = settings.fantasyFontFamily(script);
    381     else if (familyName == monospaceFamily)
    382         genericFamily = settings.fixedFontFamily(script);
    383     else if (familyName == pictographFamily)
    384         genericFamily = settings.pictographFontFamily(script);
    385     else if (familyName == standardFamily)
    386         genericFamily = settings.standardFontFamily(script);
    387 
    388     if (!genericFamily.isEmpty())
    389         return fontCache().getCachedFontData(fontDescription, genericFamily);
    390 
    391     return nullptr;
     372        return settings.serifFontFamily(script);
     373    if (familyName == sansSerifFamily)
     374        return settings.sansSerifFontFamily(script);
     375    if (familyName == cursiveFamily)
     376        return settings.cursiveFontFamily(script);
     377    if (familyName == fantasyFamily)
     378        return settings.fantasyFontFamily(script);
     379    if (familyName == monospaceFamily)
     380        return settings.fixedFontFamily(script);
     381    if (familyName == pictographFamily)
     382        return settings.pictographFontFamily(script);
     383    if (familyName == standardFamily)
     384        return settings.standardFontFamily(script);
     385
     386    return familyName;
    392387}
    393388
     
    476471PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName)
    477472{
    478     if (m_fontFaces.isEmpty()) {
    479         if (familyName.startsWith("-webkit-"))
    480             return fontDataForGenericFamily(m_document, fontDescription, familyName);
    481         if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
    482             return fontDataForGenericFamily(m_document, fontDescription, standardFamily);
    483         return 0;
    484     }
    485 
    486     CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName);
    487     // If no face was found, then return 0 and let the OS come up with its best match for the name.
     473    // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too.
     474    bool resolveGenericFamilyFirst = familyName == standardFamily;
     475
     476    AtomicString familyForLookup = resolveGenericFamilyFirst ? resolveGenericFamily(m_document, fontDescription, familyName) : familyName;
     477    CSSSegmentedFontFace* face = getFontFace(fontDescription, familyForLookup);
    488478    if (!face) {
    489         // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
    490         // settings.
    491         if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
    492             return fontDataForGenericFamily(m_document, fontDescription, standardFamily);
    493         return fontDataForGenericFamily(m_document, fontDescription, familyName);
    494     }
    495 
    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.
     479        if (!resolveGenericFamilyFirst)
     480            familyForLookup = resolveGenericFamily(m_document, fontDescription, familyName);
     481        return fontCache().getCachedFontData(fontDescription, familyForLookup);
     482    }
     483
    497484    return face->getFontData(fontDescription);
    498485}
     
    614601    for (unsigned i = 0; i < description.familyCount(); ++i) {
    615602        const AtomicString& familyName = description.familyAt(i);
    616         if (description.genericFamily() == FontDescription::StandardFamily && !description.isSpecifiedFont())
    617             return true;
    618603        if (familyName.isEmpty())
    619604            continue;
  • trunk/Source/WebCore/css/StyleBuilderCustom.h

    r176721 r176751  
    900900    if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
    901901        styleResolver.setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, false, styleResolver.document()));
    902     fontDescription.setGenericFamily(initialDesc.genericFamily());
    903902    if (!initialDesc.firstFamily().isEmpty())
    904903        fontDescription.setFamilies(initialDesc.families());
     
    912911    FontDescription parentFontDescription = styleResolver.parentStyle()->fontDescription();
    913912
    914     fontDescription.setGenericFamily(parentFontDescription.genericFamily());
    915913    fontDescription.setFamilies(parentFontDescription.families());
    916914    fontDescription.setIsSpecifiedFont(parentFontDescription.isSpecifiedFont());
     
    925923    // Before mapping in a new font-family property, we should reset the generic family.
    926924    bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
    927     fontDescription.setGenericFamily(FontDescription::NoFamily);
    928925
    929926    Vector<AtomicString> families;
     
    932929    for (auto& item : valueList) {
    933930        auto& contentValue = downcast<CSSPrimitiveValue>(item.get());
    934         AtomicString face;
     931        AtomicString family;
     932        bool isGenericFamily = false;
    935933        if (contentValue.isString())
    936             face = contentValue.getStringValue();
    937         else if (Settings* settings = styleResolver.document().settings()) {
     934            family = contentValue.getStringValue();
     935        else {
    938936            switch (contentValue.getValueID()) {
    939937            case CSSValueWebkitBody:
    940                 face = settings->standardFontFamily();
     938                if (Settings* settings = styleResolver.document().settings())
     939                    family = settings->standardFontFamily();
    941940                break;
    942941            case CSSValueSerif:
    943                 face = serifFamily;
    944                 fontDescription.setGenericFamily(FontDescription::SerifFamily);
     942                family = serifFamily;
     943                isGenericFamily = true;
    945944                break;
    946945            case CSSValueSansSerif:
    947                 face = sansSerifFamily;
    948                 fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
     946                family = sansSerifFamily;
     947                isGenericFamily = true;
    949948                break;
    950949            case CSSValueCursive:
    951                 face = cursiveFamily;
    952                 fontDescription.setGenericFamily(FontDescription::CursiveFamily);
     950                family = cursiveFamily;
     951                isGenericFamily = true;
    953952                break;
    954953            case CSSValueFantasy:
    955                 face = fantasyFamily;
    956                 fontDescription.setGenericFamily(FontDescription::FantasyFamily);
     954                family = fantasyFamily;
     955                isGenericFamily = true;
    957956                break;
    958957            case CSSValueMonospace:
    959                 face = monospaceFamily;
    960                 fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
     958                family = monospaceFamily;
     959                isGenericFamily = true;
    961960                break;
    962961            case CSSValueWebkitPictograph:
    963                 face = pictographFamily;
    964                 fontDescription.setGenericFamily(FontDescription::PictographFamily);
     962                family = pictographFamily;
     963                isGenericFamily = true;
    965964                break;
    966965            default:
     
    969968        }
    970969
    971         if (face.isEmpty())
     970        if (family.isEmpty())
    972971            continue;
    973972        if (families.isEmpty())
    974             fontDescription.setIsSpecifiedFont(fontDescription.genericFamily() == FontDescription::NoFamily);
    975         families.uncheckedAppend(face);
     973            fontDescription.setIsSpecifiedFont(!isGenericFamily);
     974        families.uncheckedAppend(family);
    976975    }
    977976
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r176621 r176751  
    31403140    if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())
    31413141        return;
    3142 
    3143     // For now, lump all families but monospace together.
    3144     if (childFont.genericFamily() != FontDescription::MonospaceFamily
    3145         && parentFont.genericFamily() != FontDescription::MonospaceFamily)
    3146         return;
    3147 
    31483142    // We know the parent is monospace or the child is monospace, and that font
    31493143    // size was unspecified. We want to scale our font size as appropriate.
     
    31713165{
    31723166    FontDescription fontDescription;
    3173     fontDescription.setGenericFamily(FontDescription::StandardFamily);
    31743167    fontDescription.setRenderingMode(settings->fontRenderingMode());
    31753168    fontDescription.setUsePrinterFont(document().printing() || !settings->screenFontSubstitutionEnabled());
    3176     const AtomicString& standardFontFamily = documentSettings()->standardFontFamily();
    3177     if (!standardFontFamily.isEmpty())
    3178         fontDescription.setOneFamily(standardFontFamily);
     3169    fontDescription.setOneFamily(standardFamily);
    31793170    fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
    31803171    setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueMedium, false, document()));
  • trunk/Source/WebCore/platform/efl/RenderThemeEfl.cpp

    r176070 r176751  
    992992    fontDescription.setSpecifiedSize(defaultFontSize);
    993993    fontDescription.setIsAbsoluteSize(true);
    994     fontDescription.setGenericFamily(FontDescription::NoFamily);
    995994    fontDescription.setWeight(FontWeightNormal);
    996995    fontDescription.setItalic(false);
  • trunk/Source/WebCore/platform/graphics/FontDescription.h

    r163310 r176751  
    7070class FontDescription {
    7171public:
    72     enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily,
    73                              MonospaceFamily, CursiveFamily, FantasyFamily, PictographFamily };
    74 
    7572    enum Kerning { AutoKerning, NormalKerning, NoneKerning };
    7673
     
    8885        , m_isAbsoluteSize(false)
    8986        , m_weight(FontWeightNormal)
    90         , m_genericFamily(NoFamily)
    9187        , m_usePrinterFont(false)
    9288        , m_renderingMode(NormalRenderingMode)
     
    120116    FontWeight lighterWeight() const;
    121117    FontWeight bolderWeight() const;
    122     GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
    123118    bool usePrinterFont() const { return m_usePrinterFont; }
    124119    // only use fixed default size when there is only one font family, and that family is "monospace"
    125     bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily && familyCount() == 1 && firstFamily() == monospaceFamily; }
     120    bool useFixedDefaultSize() const { return familyCount() == 1 && firstFamily() == monospaceFamily; }
    126121    FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); }
    127122    Kerning kerning() const { return static_cast<Kerning>(m_kerning); }
     
    153148    void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
    154149    void setWeight(FontWeight w) { m_weight = w; }
    155     void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; }
    156150    void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
    157151    void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; }
     
    179173            && m_smallCaps == other.m_smallCaps
    180174            && m_isAbsoluteSize == other.m_isAbsoluteSize
    181             && m_genericFamily == other.m_genericFamily
    182175            && m_usePrinterFont == other.m_usePrinterFont;
    183176    }
     
    202195                                  // (logical sizes like "medium" don't count).
    203196    unsigned m_weight : 8; // FontWeight
    204     unsigned m_genericFamily : 3; // GenericFamilyType
    205197    unsigned m_usePrinterFont : 1;
    206198
     
    231223        && m_isAbsoluteSize == other.m_isAbsoluteSize
    232224        && m_weight == other.m_weight
    233         && m_genericFamily == other.m_genericFamily
    234225        && m_usePrinterFont == other.m_usePrinterFont
    235226        && m_renderingMode == other.m_renderingMode
  • trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r175013 r176751  
    120120        return family.string();
    121121
    122     switch (fontDescription.genericFamily()) {
    123     case FontDescription::StandardFamily:
    124     case FontDescription::SerifFamily:
     122    if (family == standardFamily || family == serifFamily)
    125123        return "serif";
    126     case FontDescription::SansSerifFamily:
     124    if (family == sansSerifFamily)
    127125        return "sans-serif";
    128     case FontDescription::MonospaceFamily:
     126    if (family == monospaceFamily)
    129127        return "monospace";
    130     case FontDescription::CursiveFamily:
     128    if (family == cursiveFamily)
    131129        return "cursive";
    132     case FontDescription::FantasyFamily:
     130    if (family == fantasyFamily)
    133131        return "fantasy";
    134     case FontDescription::NoFamily:
    135     default:
    136         return "";
    137     }
     132    return "";
    138133}
    139134
  • trunk/Source/WebCore/platform/mac/ThemeMac.mm

    r173441 r176751  
    684684            FontDescription fontDescription;
    685685            fontDescription.setIsAbsoluteSize(true);
    686             fontDescription.setGenericFamily(FontDescription::SerifFamily);
    687686
    688687            NSFont* nsFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSizeForFont(font)]];
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r174917 r176751  
    171171        FontDescription controlFont = m_theme->controlFont(part, style.font(), style.effectiveZoom());
    172172        if (controlFont != style.font().fontDescription()) {
    173             // Reset our line-height
    174             style.setLineHeight(RenderStyle::initialLineHeight());
    175 
    176173            // Now update our font.
    177174            if (style.setFontDescription(controlFont))
    178175                style.font().update(0);
    179176        }
    180 
     177        // Reset our line-height
     178        style.setLineHeight(RenderStyle::initialLineHeight());
    181179        style.setInsideDefaultButton(part == DefaultButtonPart);
    182180    }
  • trunk/Source/WebCore/rendering/RenderThemeGtk.cpp

    r175095 r176751  
    108108    fontDescription.setSpecifiedSize(size);
    109109    fontDescription.setIsAbsoluteSize(true);
    110     fontDescription.setGenericFamily(FontDescription::NoFamily);
    111110    fontDescription.setWeight(FontWeightNormal);
    112111    fontDescription.setItalic(false);
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r176229 r176751  
    12311231        RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr));
    12321232        cachedDesc->setIsAbsoluteSize(true);
    1233         cachedDesc->setGenericFamily(FontDescription::NoFamily);
    12341233        cachedDesc->setOneFamily(textStyle);
    12351234        cachedDesc->setSpecifiedSize(CTFontGetSize(font.get()));
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r175147 r176751  
    391391        NSFontManager *fontManager = [NSFontManager sharedFontManager];
    392392        cachedDesc->setIsAbsoluteSize(true);
    393         cachedDesc->setGenericFamily(FontDescription::NoFamily);
    394393        cachedDesc->setOneFamily([font webCoreFamilyName]);
    395394        cachedDesc->setSpecifiedSize([font pointSize]);
     
    809808    FontDescription fontDescription;
    810809    fontDescription.setIsAbsoluteSize(true);
    811     fontDescription.setGenericFamily(FontDescription::SerifFamily);
    812810
    813811    NSFont* font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSize]];
  • trunk/Source/WebCore/rendering/RenderThemeSafari.cpp

    r174875 r176751  
    244244    if (fontSize) {
    245245        cachedDesc->setIsAbsoluteSize(true);
    246         cachedDesc->setGenericFamily(FontDescription::NoFamily);
    247246        cachedDesc->setOneFamily("Lucida Grande");
    248247        cachedDesc->setSpecifiedSize(fontSize);
     
    393392    FontDescription fontDescription;
    394393    fontDescription.setIsAbsoluteSize(true);
    395     fontDescription.setGenericFamily(FontDescription::SerifFamily);
    396394
    397395    float fontSize = systemFontSizeForControlSize(controlSize);
  • trunk/Source/WebCore/rendering/RenderThemeWin.cpp

    r174875 r176751  
    324324{   
    325325    fontDescription.setIsAbsoluteSize(true);
    326     fontDescription.setGenericFamily(FontDescription::NoFamily);
    327326    fontDescription.setOneFamily(String(logFont.lfFaceName));
    328327    fontDescription.setSpecifiedSize(fontSize);
  • trunk/Source/WebCore/style/StyleResolveForDocument.cpp

    r175583 r176751  
    100100    fontDescription.setUsePrinterFont(document.printing() || !settings.screenFontSubstitutionEnabled());
    101101    fontDescription.setRenderingMode(settings.fontRenderingMode());
    102     const AtomicString& standardFont = settings.standardFontFamily(fontDescription.script());
    103     if (!standardFont.isEmpty()) {
    104         fontDescription.setGenericFamily(FontDescription::StandardFamily);
    105         fontDescription.setOneFamily(standardFont);
    106     }
     102    fontDescription.setOneFamily(standardFamily);
     103
    107104    fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
    108105    int size = fontSizeForKeyword(CSSValueMedium, false, document);
Note: See TracChangeset for help on using the changeset viewer.