Changeset 187626 in webkit


Ignore:
Timestamp:
Jul 30, 2015 5:12:38 PM (9 years ago)
Author:
mmaxfield@apple.com
Message:

Move locale information into FontDescription
https://bugs.webkit.org/show_bug.cgi?id=147457

Reviewed by Andreas Kling.

Currently, the "lang" attribute on a node sets locale information in RenderStyle.
Font selection is sensitive to this locale information, and occurs deep within
platform/ code, far away from RenderStyle. Because every RenderStyle owns a
FontDescription, and font selection can consult with FontDescriptions, it makes
sense to move the variable from RenderStyle to FontDescription, and provide
convenience methods on RenderStyle which inspect its FontDescription for locale
information.

This patch is in preparation for correctly obeying locale information when
performing font fallback.

No new tests because there is no behavior change.

  • css/CSSPropertyNames.in:
  • css/StyleBuilderCustom.h:

(WebCore::StyleBuilderCustom::applyValueWebkitLocale):

  • platform/graphics/FontCache.h:

(WebCore::FontDescriptionKey::FontDescriptionKey):
(WebCore::FontDescriptionKey::operator==):

  • platform/graphics/FontCascade.cpp:
  • platform/graphics/FontDescription.cpp:

(WebCore::FontDescription::FontDescription):
(WebCore::FontDescription::setLocale):

  • platform/graphics/FontDescription.h:

(WebCore::FontDescription::locale):
(WebCore::FontDescription::initialLocale):
(WebCore::FontDescription::operator==):
(WebCore::FontDescription::FontDescription): Deleted.
(WebCore::FontDescription::setScript): Deleted.

  • platform/text/LocaleToScriptMappingDefault.cpp:

(WebCore::localeToScriptCodeForFontSelection):

  • rendering/style/RenderStyle.cpp:

(WebCore::RenderStyle::changeRequiresLayout): Deleted.

  • rendering/style/RenderStyle.h:
  • rendering/style/StyleRareInheritedData.cpp:

(WebCore::StyleRareInheritedData::StyleRareInheritedData): Deleted.
(WebCore::StyleRareInheritedData::operator==): Deleted.

  • rendering/style/StyleRareInheritedData.h:
  • style/StyleResolveForDocument.cpp:

(WebCore::Style::resolveForDocument):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r187622 r187626  
     12015-07-30  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Move locale information into FontDescription
     4        https://bugs.webkit.org/show_bug.cgi?id=147457
     5
     6        Reviewed by Andreas Kling.
     7
     8        Currently, the "lang" attribute on a node sets locale information in RenderStyle.
     9        Font selection is sensitive to this locale information, and occurs deep within
     10        platform/ code, far away from RenderStyle. Because every RenderStyle owns a
     11        FontDescription, and font selection can consult with FontDescriptions, it makes
     12        sense to move the variable from RenderStyle to FontDescription, and provide
     13        convenience methods on RenderStyle which inspect its FontDescription for locale
     14        information.
     15
     16        This patch is in preparation for correctly obeying locale information when
     17        performing font fallback.
     18
     19        No new tests because there is no behavior change.
     20
     21        * css/CSSPropertyNames.in:
     22        * css/StyleBuilderCustom.h:
     23        (WebCore::StyleBuilderCustom::applyValueWebkitLocale):
     24        * platform/graphics/FontCache.h:
     25        (WebCore::FontDescriptionKey::FontDescriptionKey):
     26        (WebCore::FontDescriptionKey::operator==):
     27        * platform/graphics/FontCascade.cpp:
     28        * platform/graphics/FontDescription.cpp:
     29        (WebCore::FontDescription::FontDescription):
     30        (WebCore::FontDescription::setLocale):
     31        * platform/graphics/FontDescription.h:
     32        (WebCore::FontDescription::locale):
     33        (WebCore::FontDescription::initialLocale):
     34        (WebCore::FontDescription::operator==):
     35        (WebCore::FontDescription::FontDescription): Deleted.
     36        (WebCore::FontDescription::setScript): Deleted.
     37        * platform/text/LocaleToScriptMappingDefault.cpp:
     38        (WebCore::localeToScriptCodeForFontSelection):
     39        * rendering/style/RenderStyle.cpp:
     40        (WebCore::RenderStyle::changeRequiresLayout): Deleted.
     41        * rendering/style/RenderStyle.h:
     42        * rendering/style/StyleRareInheritedData.cpp:
     43        (WebCore::StyleRareInheritedData::StyleRareInheritedData): Deleted.
     44        (WebCore::StyleRareInheritedData::operator==): Deleted.
     45        * rendering/style/StyleRareInheritedData.h:
     46        * style/StyleResolveForDocument.cpp:
     47        (WebCore::Style::resolveForDocument):
     48
    1492015-07-30  Anders Carlsson  <andersca@apple.com>
    250
  • trunk/Source/WebCore/css/CSSPropertyNames.in

    r187110 r187626  
    110110-webkit-font-smoothing [Inherited, FontProperty]
    111111-webkit-font-variant-ligatures [Inherited, Custom=All]
    112 -webkit-locale [Inherited, Custom=Value]
     112-webkit-locale [Inherited, FontProperty, Custom=Value]
    113113-webkit-text-orientation [Inherited, Custom=Value]
    114114-epub-text-orientation = -webkit-text-orientation
  • trunk/Source/WebCore/css/StyleBuilderCustom.h

    r187110 r187626  
    4141#include "Frame.h"
    4242#include "HTMLElement.h"
    43 #include "LocaleToScriptMapping.h"
    4443#include "Rect.h"
    4544#include "RenderTheme.h"
     
    692691{
    693692    auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
    694 
    695     if (primitiveValue.getValueID() == CSSValueAuto)
    696         styleResolver.style()->setLocale(nullAtom);
    697     else
    698         styleResolver.style()->setLocale(primitiveValue.getStringValue());
    699693   
    700694    FontDescription fontDescription = styleResolver.style()->fontDescription();
    701     fontDescription.setScript(localeToScriptCodeForFontSelection(styleResolver.style()->locale()));
     695    if (primitiveValue.getValueID() == CSSValueAuto)
     696        fontDescription.setLocale(nullAtom);
     697    else
     698        fontDescription.setLocale(primitiveValue.getStringValue());
    702699    styleResolver.setFontDescription(fontDescription);
    703700}
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r187615 r187626  
    7272        , weight(0)
    7373        , flags(0)
     74        , localeHash(0)
    7475    { }
    7576    FontDescriptionKey(const FontDescription& description)
     
    7778        , weight(description.weight())
    7879        , flags(makeFlagKey(description))
     80        , localeHash(description.locale().isNull() ? 0 : description.locale().impl()->existingHash())
    7981    { }
    8082    static unsigned makeFlagKey(const FontDescription& description)
     
    9294    bool operator==(const FontDescriptionKey& other) const
    9395    {
    94         return size == other.size && weight == other.weight && flags == other.flags;
     96        return size == other.size && weight == other.weight && flags == other.flags && localeHash == other.localeHash;
    9597    }
    9698    bool operator!=(const FontDescriptionKey& other) const
     
    105107    unsigned weight;
    106108    unsigned flags;
     109    unsigned localeHash; // FIXME: Here, and every client of us, makes hashes of hashes.
    107110};
    108111
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r187615 r187626  
    179179
    180180struct FontCascadeCacheKey {
    181     // This part of the key is shared with the lower level FontCache (caching FontData objects).
    182     FontDescriptionKey fontDescriptionKey;
     181    FontDescriptionKey fontDescriptionKey; // Shared with the lower level FontCache (caching Font objects)
    183182    Vector<AtomicString, 3> families;
    184183    unsigned fontSelectorId;
     
    242241}
    243242
     243// FIXME: Why can't we just teach HashMap about FontCascadeCacheKey instead of hashing a hash?
    244244static unsigned computeFontCascadeCacheHash(const FontCascadeCacheKey& key)
    245245{
  • trunk/Source/WebCore/platform/graphics/FontDescription.cpp

    r178149 r187626  
     1
    12/*
    23 * Copyright (C) 2007 Nicholas Shanks <contact@nickshanks.com>
     
    3031#include "config.h"
    3132#include "FontDescription.h"
     33#include "LocaleToScriptMapping.h"
    3234
    3335namespace WebCore {
    3436
    3537struct SameSizeAsFontDescription {
    36     void* pointers[2];
     38    void* pointers[3];
    3739    float sizes[2];
    38     // FXIME: Make them fit into one word.
     40    // FIXME: Make them fit into one word.
    3941    uint32_t bitfields;
    4042    uint32_t bitfields2 : 8;
     
    4244
    4345COMPILE_ASSERT(sizeof(FontDescription) == sizeof(SameSizeAsFontDescription), FontDescription_should_stay_small);
     46
     47FontDescription::FontDescription()
     48    : m_orientation(Horizontal)
     49    , m_nonCJKGlyphOrientation(NonCJKGlyphOrientationVerticalRight)
     50    , m_widthVariant(RegularWidth)
     51    , m_italic(FontItalicOff)
     52    , m_smallCaps(FontSmallCapsOff)
     53    , m_isAbsoluteSize(false)
     54    , m_weight(FontWeightNormal)
     55    , m_renderingMode(NormalRenderingMode)
     56    , m_kerning(AutoKerning)
     57    , m_commonLigaturesState(NormalLigaturesState)
     58    , m_discretionaryLigaturesState(NormalLigaturesState)
     59    , m_historicalLigaturesState(NormalLigaturesState)
     60    , m_keywordSize(0)
     61    , m_fontSmoothing(AutoSmoothing)
     62    , m_textRendering(AutoTextRendering)
     63    , m_isSpecifiedFont(false)
     64    , m_script(localeToScriptCodeForFontSelection(m_locale))
     65    , m_fontSynthesis(initialFontSynthesis())
     66{
     67}
    4468
    4569FontWeight FontDescription::lighterWeight(void) const
     
    95119}
    96120
     121void FontDescription::setLocale(const AtomicString& locale)
     122{
     123    m_locale = locale;
     124    m_script = localeToScriptCodeForFontSelection(m_locale);
     125}
     126
    97127#if ENABLE(IOS_TEXT_AUTOSIZING)
    98128bool FontDescription::familiesEqualForTextAutoSizing(const FontDescription& other) const
  • trunk/Source/WebCore/platform/graphics/FontDescription.h

    r183494 r187626  
    4545    enum LigaturesState { NormalLigaturesState, DisabledLigaturesState, EnabledLigaturesState };
    4646
    47     FontDescription()
    48         : m_families(1)
    49         , m_specifiedSize(0)
    50         , m_computedSize(0)
    51         , m_orientation(Horizontal)
    52         , m_nonCJKGlyphOrientation(NonCJKGlyphOrientationVerticalRight)
    53         , m_widthVariant(RegularWidth)
    54         , m_italic(FontItalicOff)
    55         , m_smallCaps(FontSmallCapsOff)
    56         , m_isAbsoluteSize(false)
    57         , m_weight(FontWeightNormal)
    58         , m_renderingMode(NormalRenderingMode)
    59         , m_kerning(AutoKerning)
    60         , m_commonLigaturesState(NormalLigaturesState)
    61         , m_discretionaryLigaturesState(NormalLigaturesState)
    62         , m_historicalLigaturesState(NormalLigaturesState)
    63         , m_keywordSize(0)
    64         , m_fontSmoothing(AutoSmoothing)
    65         , m_textRendering(AutoTextRendering)
    66         , m_isSpecifiedFont(false)
    67         , m_script(USCRIPT_COMMON)
    68         , m_fontSynthesis(initialFontSynthesis())
    69     {
    70     }
     47    WEBCORE_EXPORT FontDescription();
    7148
    7249    bool operator==(const FontDescription&) const;
     
    10481    TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); }
    10582    UScriptCode script() const { return static_cast<UScriptCode>(m_script); }
     83    const AtomicString& locale() const { return m_locale; }
    10684
    10785    FontTraitsMask traitsMask() const;
     
    148126    void setNonCJKGlyphOrientation(NonCJKGlyphOrientation orientation) { m_nonCJKGlyphOrientation = orientation; }
    149127    void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; }
    150     void setScript(UScriptCode s) { m_script = s; }
     128    void setLocale(const AtomicString&);
    151129    void setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) { m_featureSettings = settings; }
    152130    void setFontSynthesis(FontSynthesis fontSynthesis) { m_fontSynthesis = fontSynthesis; }
     
    171149    static TextRenderingMode initialTextRenderingMode() { return AutoTextRendering; }
    172150    static FontSynthesis initialFontSynthesis() { return FontSynthesisWeight | FontSynthesisStyle; }
     151    static const AtomicString& initialLocale() { return nullAtom; }
    173152
    174153private:
    175     RefCountedArray<AtomicString> m_families;
     154    RefCountedArray<AtomicString> m_families { 1 };
    176155    RefPtr<FontFeatureSettings> m_featureSettings;
    177 
    178     float m_specifiedSize;   // Specified CSS value. Independent of rendering issues such as integer
     156    AtomicString m_locale { initialLocale() };
     157
     158    float m_specifiedSize { 0 };   // Specified CSS value. Independent of rendering issues such as integer
    179159                             // rounding, minimum font sizes, and zooming.
    180     float m_computedSize;    // Computed size adjusted for the minimum font size and the zoom factor. 
     160    float m_computedSize { 0 };    // Computed size adjusted for the minimum font size and the zoom factor.
    181161
    182162    unsigned m_orientation : 1; // FontOrientation - Whether the font is rendering on a horizontal line or a vertical line.
     
    230210        && m_nonCJKGlyphOrientation == other.m_nonCJKGlyphOrientation
    231211        && m_widthVariant == other.m_widthVariant
    232         && m_script == other.m_script
     212        && m_locale == other.m_locale
    233213        && m_featureSettings == other.m_featureSettings
    234214        && m_fontSynthesis == other.m_fontSynthesis;
  • trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp

    r165607 r187626  
    3434#include <wtf/HashMap.h>
    3535#include <wtf/HashSet.h>
     36#include <wtf/NeverDestroyed.h>
    3637#include <wtf/text/StringHash.h>
    3738
     
    390391UScriptCode localeToScriptCodeForFontSelection(const String& locale)
    391392{
    392     DEPRECATED_DEFINE_STATIC_LOCAL(LocaleScriptMap, localeScriptMap, ());
    393     if (localeScriptMap.isEmpty()) {
     393    static NeverDestroyed<LocaleScriptMap> localeScriptMap;
     394    if (localeScriptMap.get().isEmpty()) {
    394395        for (size_t i = 0; i < sizeof(localeScriptList) / sizeof(LocaleScript); ++i)
    395             localeScriptMap.set(ASCIILiteral(localeScriptList[i].locale), localeScriptList[i].script);
     396            localeScriptMap.get().set(ASCIILiteral(localeScriptList[i].locale), localeScriptList[i].script);
    396397    }
    397398
    398399    String canonicalLocale = locale.lower().replace('-', '_');
    399400    while (!canonicalLocale.isEmpty()) {
    400         LocaleScriptMap::iterator it = localeScriptMap.find(canonicalLocale);
    401         if (it != localeScriptMap.end())
     401        LocaleScriptMap::iterator it = localeScriptMap.get().find(canonicalLocale);
     402        if (it != localeScriptMap.get().end())
    402403            return it->value;
    403404        size_t pos = canonicalLocale.reverseFind('_');
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r187110 r187626  
    577577            || rareInheritedData->hyphenationLimitAfter != other.rareInheritedData->hyphenationLimitAfter
    578578            || rareInheritedData->hyphenationString != other.rareInheritedData->hyphenationString
    579             || rareInheritedData->locale != other.rareInheritedData->locale
    580579            || rareInheritedData->m_rubyPosition != other.rareInheritedData->m_rubyPosition
    581580            || rareInheritedData->textEmphasisMark != other.rareInheritedData->textEmphasisMark
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r187110 r187626  
    999999    short hyphenationLimitLines() const { return rareInheritedData->hyphenationLimitLines; }
    10001000    const AtomicString& hyphenationString() const { return rareInheritedData->hyphenationString; }
    1001     const AtomicString& locale() const { return rareInheritedData->locale; }
     1001    const AtomicString& locale() const { return fontDescription().locale(); }
    10021002    EBorderFit borderFit() const { return static_cast<EBorderFit>(rareNonInheritedData->m_borderFit); }
    10031003    EResize resize() const { return static_cast<EResize>(rareInheritedData->resize); }
     
    15731573    void setHyphenationLimitLines(short limit) { SET_VAR(rareInheritedData, hyphenationLimitLines, limit); }
    15741574    void setHyphenationString(const AtomicString& h) { SET_VAR(rareInheritedData, hyphenationString, h); }
    1575     void setLocale(const AtomicString& locale) { SET_VAR(rareInheritedData, locale, locale); }
    15761575    void setBorderFit(EBorderFit b) { SET_VAR(rareNonInheritedData, m_borderFit, b); }
    15771576    void setResize(EResize r) { SET_VAR(rareInheritedData, resize, r); }
     
    19671966    static short initialHyphenationLimitLines() { return -1; }
    19681967    static const AtomicString& initialHyphenationString() { return nullAtom; }
    1969     static const AtomicString& initialLocale() { return nullAtom; }
    19701968    static EBorderFit initialBorderFit() { return BorderFitBorder; }
    19711969    static EResize initialResize() { return RESIZE_NONE; }
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp

    r187110 r187626  
    207207    , hyphenationLimitAfter(o.hyphenationLimitAfter)
    208208    , hyphenationLimitLines(o.hyphenationLimitLines)
    209     , locale(o.locale)
    210209    , textEmphasisCustomMark(o.textEmphasisCustomMark)
    211210    , m_lineGrid(o.m_lineGrid)
     
    303302#endif
    304303        && hyphenationString == o.hyphenationString
    305         && locale == o.locale
    306304        && textEmphasisCustomMark == o.textEmphasisCustomMark
    307305        && quotesDataEquivalent(quotes.get(), o.quotes.get())
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h

    r187110 r187626  
    140140    short hyphenationLimitLines;
    141141
    142     AtomicString locale;
    143 
    144142    AtomicString textEmphasisCustomMark;
    145143    RefPtr<QuotesData> quotes;
  • trunk/Source/WebCore/style/StyleResolveForDocument.cpp

    r179368 r187626  
    6060    documentStyle.get().setZoom(!document.printing() ? renderView.frame().pageZoomFactor() : 1);
    6161    documentStyle.get().setPageScaleTransform(renderView.frame().frameScaleFactor());
    62     documentStyle.get().setLocale(document.contentLanguage());
     62    FontDescription documentFontDescription = documentStyle.get().fontDescription();
     63    documentFontDescription.setLocale(document.contentLanguage());
     64    documentStyle.get().setFontDescription(WTF::move(documentFontDescription));
    6365
    6466    // This overrides any -webkit-user-modify inherited from the parent iframe.
     
    98100
    99101    FontDescription fontDescription;
    100     fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle.get().locale()));
     102    fontDescription.setLocale(document.contentLanguage());
    101103    fontDescription.setRenderingMode(settings.fontRenderingMode());
    102104    fontDescription.setOneFamily(standardFamily);
Note: See TracChangeset for help on using the changeset viewer.