Changeset 213285 in webkit


Ignore:
Timestamp:
Mar 2, 2017 10:08:41 AM (7 years ago)
Author:
jonlee@apple.com
Message:

Improve consistency of captions rendering on Mac
https://bugs.webkit.org/show_bug.cgi?id=169071

Reviewed by Eric Carlson.

  • page/CaptionUserPreferencesMediaAF.h:

(WebCore::CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor): Deleted.
(WebCore::CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor): Deleted.

  • page/CaptionUserPreferencesMediaAF.cpp:

(WebCore::appendCSS): Helper function to add a CSS rule with a provided StringBuilder.
(WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS): Refactor to use
appendCSS.
(WebCore::CaptionUserPreferencesMediaAF::colorPropertyCSS): Ditto.
(WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): Update text edge styles.

  • Add a blur to the shadow
  • Drop shadow style includes 1px text border
  • Always use black for the text edge color

Also convert the stroke rules to using the CSS property and values instead of straight strings.
(WebCore::CaptionUserPreferencesMediaAF::captionsStyleSheetOverride): Fly-by fix of a typo.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r213284 r213285  
     12017-03-02  Jon Lee  <jonlee@apple.com>
     2
     3        Improve consistency of captions rendering on Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=169071
     5
     6        Reviewed by Eric Carlson.
     7
     8        * page/CaptionUserPreferencesMediaAF.h:
     9        (WebCore::CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor): Deleted.
     10        (WebCore::CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor): Deleted.
     11
     12        * page/CaptionUserPreferencesMediaAF.cpp:
     13        (WebCore::appendCSS): Helper function to add a CSS rule with a provided StringBuilder.
     14        (WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS): Refactor to use
     15        appendCSS.
     16        (WebCore::CaptionUserPreferencesMediaAF::colorPropertyCSS): Ditto.
     17        (WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): Update text edge styles.
     18        - Add a blur to the shadow
     19        - Drop shadow style includes 1px text border
     20        - Always use black for the text edge color
     21        Also convert the stroke rules to using the CSS property and values instead of straight strings.
     22        (WebCore::CaptionUserPreferencesMediaAF::captionsStyleSheetOverride): Fly-by fix of a typo.
     23
    1242017-03-02  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp

    r212562 r213285  
    328328    return colorPropertyCSS(CSSPropertyColor, textColor, important);
    329329}
     330
     331static void appendCSS(StringBuilder& builder, CSSPropertyID id, const String& value, bool important)
     332{
     333    builder.append(getPropertyNameString(id));
     334    builder.append(':');
     335    builder.append(value);
     336    if (important)
     337        builder.appendLiteral(" !important");
     338    builder.append(';');
     339}
    330340   
    331341String CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS() const
     
    337347
    338348    StringBuilder builder;
    339     builder.append(getPropertyNameString(CSSPropertyBorderRadius));
    340     builder.append(String::format(":%.02fpx", radius));
    341     if (behavior == kMACaptionAppearanceBehaviorUseValue)
    342         builder.appendLiteral(" !important");
    343     builder.append(';');
    344 
     349    appendCSS(builder, CSSPropertyBorderRadius, String::format("%.02fpx", radius), behavior == kMACaptionAppearanceBehaviorUseValue);
    345350    return builder.toString();
    346351}
    347    
    348 Color CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor(const Color& textColor) const
    349 {
    350     int distanceFromWhite = differenceSquared(textColor, Color::white);
    351     int distanceFromBlack = differenceSquared(textColor, Color::black);
    352    
    353     if (distanceFromWhite < distanceFromBlack)
    354         return textColor.dark();
    355    
    356     return textColor.light();
    357 }
    358 
    359 String CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String& value, const Color& textColor, bool important) const
     352
     353String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const
    360354{
    361355    StringBuilder builder;
    362    
    363     builder.append(getPropertyNameString(id));
    364     builder.append(':');
    365     builder.append(value);
    366     builder.append(' ');
    367     builder.append(captionsEdgeColorForTextColor(textColor).serialized());
    368     if (important)
    369         builder.appendLiteral(" !important");
    370     builder.append(';');
    371     if (id == CSSPropertyWebkitTextStroke) {
    372         builder.append(" paint-order: stroke;");
    373         builder.append(" stroke-linejoin: round;");
    374         builder.append(" stroke-linecap: round;");
    375     }
    376    
    377     return builder.toString();
    378 }
    379 
    380 String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const
    381 {
    382     StringBuilder builder;
    383    
    384     builder.append(getPropertyNameString(id));
    385     builder.append(':');
    386     builder.append(color.serialized());
    387     if (important)
    388         builder.appendLiteral(" !important");
    389     builder.append(';');
    390    
     356    appendCSS(builder, id, color.serialized(), important);
    391357    return builder.toString();
    392358}
     
    418384String CaptionUserPreferencesMediaAF::captionsTextEdgeCSS() const
    419385{
    420     static NeverDestroyed<const String> edgeStyleRaised(ASCIILiteral(" -.05em -.05em 0 "));
    421     static NeverDestroyed<const String> edgeStyleDepressed(ASCIILiteral(" .05em .05em 0 "));
    422     static NeverDestroyed<const String> edgeStyleDropShadow(ASCIILiteral(" .075em .075em 0 "));
    423 
    424     bool unused;
    425     Color color = captionsTextColor(unused);
    426     if (!color.isValid())
    427         color = Color { Color::black };
    428     color = captionsEdgeColorForTextColor(color);
     386    static NeverDestroyed<const String> edgeStyleRaised(ASCIILiteral(" -.1em -.1em .16em "));
     387    static NeverDestroyed<const String> edgeStyleDepressed(ASCIILiteral(" .1em .1em .16em "));
     388    static NeverDestroyed<const String> edgeStyleDropShadow(ASCIILiteral(" 0 .1em .16em "));
    429389
    430390    MACaptionAppearanceBehavior behavior;
    431391    MACaptionAppearanceTextEdgeStyle textEdgeStyle = MACaptionAppearanceGetTextEdgeStyle(kMACaptionAppearanceDomainUser, &behavior);
    432     switch (textEdgeStyle) {
    433     case kMACaptionAppearanceTextEdgeStyleUndefined:
    434     case kMACaptionAppearanceTextEdgeStyleNone:
     392   
     393    if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleUndefined || textEdgeStyle == kMACaptionAppearanceTextEdgeStyleNone)
    435394        return emptyString();
    436            
    437     case kMACaptionAppearanceTextEdgeStyleRaised:
    438         return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color, behavior == kMACaptionAppearanceBehaviorUseValue);
    439     case kMACaptionAppearanceTextEdgeStyleDepressed:
    440         return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color, behavior == kMACaptionAppearanceBehaviorUseValue);
    441     case kMACaptionAppearanceTextEdgeStyleDropShadow:
    442         return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color, behavior == kMACaptionAppearanceBehaviorUseValue);
    443     case kMACaptionAppearanceTextEdgeStyleUniform:
    444         return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, strokeWidth(), color, behavior == kMACaptionAppearanceBehaviorUseValue);
    445    
    446     default:
    447         ASSERT_NOT_REACHED();
    448         break;
    449     }
    450    
    451     return emptyString();
     395
     396    StringBuilder builder;
     397    bool important = behavior == kMACaptionAppearanceBehaviorUseValue;
     398    if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleRaised)
     399        appendCSS(builder, CSSPropertyTextShadow, makeString(edgeStyleRaised.get(), " black"), important);
     400    else if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDepressed)
     401        appendCSS(builder, CSSPropertyTextShadow, makeString(edgeStyleDepressed.get(), " black"), important);
     402    else if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDropShadow)
     403        appendCSS(builder, CSSPropertyTextShadow, makeString(edgeStyleDropShadow.get(), " black"), important);
     404
     405    if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDropShadow || textEdgeStyle == kMACaptionAppearanceTextEdgeStyleUniform) {
     406        if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDropShadow)
     407            appendCSS(builder, CSSPropertyWebkitTextStroke, ".03em black", important);
     408        else
     409            appendCSS(builder, CSSPropertyWebkitTextStroke, makeString(strokeWidth(), " black"), important);
     410
     411        appendCSS(builder, CSSPropertyPaintOrder, getValueName(CSSValueStroke), important);
     412        appendCSS(builder, CSSPropertyStrokeLinejoin, getValueName(CSSValueRound), important);
     413        appendCSS(builder, CSSPropertyStrokeLinecap, getValueName(CSSValueRound), important);
     414    }
     415   
     416    return builder.toString();
    452417}
    453418
     
    621586#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
    622587
    623     LOG(Media, "CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting sytle to:\n%s", captionsOverrideStyleSheet.toString().utf8().data());
     588    LOG(Media, "CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting style to:\n%s", captionsOverrideStyleSheet.toString().utf8().data());
    624589
    625590    return captionsOverrideStyleSheet.toString();
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h

    r211803 r213285  
    8080    Color captionsTextColor(bool&) const;
    8181    String captionsDefaultFontCSS() const;
    82     Color captionsEdgeColorForTextColor(const Color&) const;
    8382    String windowRoundedCornerRadiusCSS() const;
    8483    String strokeWidth() const;
    8584    String captionsTextEdgeCSS() const;
    86     String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&, const Color&, bool) const;
    8785    String colorPropertyCSS(CSSPropertyID, const Color&, bool) const;
    8886    Timer m_updateStyleSheetTimer;
Note: See TracChangeset for help on using the changeset viewer.