Changeset 141790 in webkit


Ignore:
Timestamp:
Feb 4, 2013, 11:39:31 AM (12 years ago)
Author:
eric.carlson@apple.com
Message:

Update CaptionUserPreferences
https://bugs.webkit.org/show_bug.cgi?id=108783

Reviewed by Dean Jackson.

  • html/shadow/MediaControlElements.cpp:

(WebCore::MediaControlTextTrackContainerElement::updateSizes): Mark font size as important

when necessary.

  • page/CaptionUserPreferences.h:

(WebCore::CaptionUserPreferences::setUserPrefersCaptions): New, allow a port to remember that

the user has chosen to see captions.

(WebCore::CaptionUserPreferences::setPreferredLanguage): New, allow a port to remember the

user's preferred caption language.

(WebCore::CaptionUserPreferences::preferredLanguages): New, return a Vector of the user's

preferred caption languages.

  • page/CaptionUserPreferencesMac.h:
  • page/CaptionUserPreferencesMac.mm:
  • page/PageGroup.cpp:

(WebCore::PageGroup::captionPreferences):
(WebCore::PageGroup::captionFontSizeScale):

  • page/PageGroup.h:
  • platform/Language.cpp:

(WebCore::userPreferredLanguagesOverride): New, return the user preferred languages override

used during testing.

  • platform/Language.h:
  • platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.mm:

(WebCore::InbandTextTrackPrivateAVFObjC::kind):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r141789 r141790  
     12013-02-04  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Update CaptionUserPreferences
     4        https://bugs.webkit.org/show_bug.cgi?id=108783
     5
     6        Reviewed by Dean Jackson.
     7
     8        * html/shadow/MediaControlElements.cpp:
     9        (WebCore::MediaControlTextTrackContainerElement::updateSizes): Mark font size as important
     10            when necessary.
     11        * page/CaptionUserPreferences.h:
     12        (WebCore::CaptionUserPreferences::setUserPrefersCaptions): New, allow a port to remember that
     13            the user has chosen to see captions.
     14        (WebCore::CaptionUserPreferences::setPreferredLanguage): New, allow a port to remember the
     15            user's preferred caption language.
     16        (WebCore::CaptionUserPreferences::preferredLanguages): New, return a Vector of the user's
     17            preferred caption languages.
     18        * page/CaptionUserPreferencesMac.h:
     19        * page/CaptionUserPreferencesMac.mm:
     20        * page/PageGroup.cpp:
     21        (WebCore::PageGroup::captionPreferences):
     22        (WebCore::PageGroup::captionFontSizeScale):
     23        * page/PageGroup.h:
     24        * platform/Language.cpp:
     25        (WebCore::userPreferredLanguagesOverride): New, return the user preferred languages override
     26            used during testing.
     27        * platform/Language.h:
     28        * platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.mm:
     29        (WebCore::InbandTextTrackPrivateAVFObjC::kind):
     30
    1312013-02-04  Tim Horton  <timothy_horton@apple.com>
    232
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r141066 r141790  
    13641364    float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width());
    13651365
    1366     float fontSize = smallestDimension * (document()->page()->group().captionFontSizeScale());
     1366    bool important;
     1367    float fontSize = smallestDimension * (document()->page()->group().captionFontSizeScale(important));
    13671368    if (fontSize != m_fontSize) {
    13681369        m_fontSize = fontSize;
    1369         setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
     1370        setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px", important);
    13701371    }
    13711372}
  • trunk/Source/WebCore/page/CaptionUserPreferences.h

    r132349 r141790  
    2929#if ENABLE(VIDEO_TRACK)
    3030
     31#include "Language.h"
    3132#include <wtf/PassOwnPtr.h>
    3233#include <wtf/text/AtomicString.h>
     
    4950
    5051    virtual bool userPrefersCaptions() const { return false; }
     52    virtual void setUserPrefersCaptions(bool) { }
    5153    virtual bool userHasCaptionPreferences() const { return false; }
    52     virtual float captionFontSizeScale() const { return 0.05f; }
     54    virtual float captionFontSizeScale(bool& important) const { important = false; return 0.05f; }
    5355    virtual String captionsStyleSheetOverride() const { return emptyString(); }
    5456    virtual void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
    5557    virtual void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
     58
     59    virtual void setPreferredLanguage(String) const { }
     60    virtual Vector<String> preferredLanguages() const { return platformUserPreferredLanguages(); }
    5661
    5762    PageGroup* pageGroup() { return m_pageGroup; }
  • trunk/Source/WebCore/page/CaptionUserPreferencesMac.h

    r132349 r141790  
    2727#define CaptionUserPreferencesMac_h
    2828
    29 #if ENABLE(VIDEO_TRACK)
     29#if ENABLE(VIDEO_TRACK) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    3030
    3131#include "CSSPropertyNames.h"
     
    4242
    4343    virtual bool userPrefersCaptions() const OVERRIDE;
    44     virtual bool userHasCaptionPreferences() const OVERRIDE;
    45     virtual float captionFontSizeScale() const OVERRIDE;
     44    virtual void setUserPrefersCaptions(bool) OVERRIDE;
     45    virtual bool userHasCaptionPreferences() const OVERRIDE { return true; }
     46    virtual float captionFontSizeScale(bool&) const OVERRIDE;
    4647    virtual String captionsStyleSheetOverride() const OVERRIDE;
    4748    virtual void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
    4849    virtual void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
     50
     51    virtual void setPreferredLanguage(String) const OVERRIDE;
     52    virtual Vector<String> preferredLanguages() const OVERRIDE;
    4953
    5054    void captionPreferencesChanged();
     
    5357    CaptionUserPreferencesMac(PageGroup*);
    5458
    55     Color captionsWindowColor() const;
    56     Color captionsBackgroundColor() const;
    57     Color captionsTextColor() const;
    58     String captionsDefaultFont() const;
     59    String captionsWindowCSS() const;
     60    String captionsBackgroundCSS() const;
     61    String captionsTextColorCSS() const;
     62    Color captionsTextColor(bool&) const;
     63    String captionsDefaultFontCSS() const;
    5964    Color captionsEdgeColorForTextColor(const Color&) const;
    60     String captionsTextEdgeStyle() const;
    61     String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&, const Color&) const;
    62     String cssColorProperty(CSSPropertyID, const Color&) const;
     65    String windowRoundedCornerRadiusCSS() const;
     66    String captionsTextEdgeCSS() const;
     67    String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&, const Color&, bool) const;
     68    String colorPropertyCSS(CSSPropertyID, const Color&, bool) const;
    6369
    6470    void updateCaptionStyleSheetOveride();
  • trunk/Source/WebCore/page/CaptionUserPreferencesMac.mm

    r138784 r141790  
    2626#import "config.h"
    2727
    28 #if ENABLE(VIDEO_TRACK)
     28#if ENABLE(VIDEO_TRACK) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    2929
    3030#import "CaptionUserPreferencesMac.h"
    3131
    3232#import "ColorMac.h"
     33#import "CoreText/CoreText.h"
    3334#import "DOMWrapperWorld.h"
    3435#import "FloatConversion.h"
    3536#import "KURL.h"
     37#import "MediaAccessibility/MediaAccessibility.h"
    3638#import "PageGroup.h"
     39#import "SoftLinking.h"
    3740#import "TextTrackCue.h"
    3841#import "UserStyleSheetTypes.h"
    39 #import "WebCoreSystemInterface.h"
    4042#import <wtf/RetainPtr.h>
    4143#import <wtf/text/StringBuilder.h>
    4244
     45SOFT_LINK_FRAMEWORK_OPTIONAL(MediaAccessibility)
     46
     47SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetShowCaptions, bool, (MACaptionAppearanceDomain domain), (domain))
     48SOFT_LINK(MediaAccessibility, MACaptionAppearanceSetShowCaptions, void, (MACaptionAppearanceDomain domain, bool showCaptions), (domain, showCaptions))
     49SOFT_LINK(MediaAccessibility, MACaptionAppearanceCopyForegroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     50SOFT_LINK(MediaAccessibility, MACaptionAppearanceCopyBackgroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     51SOFT_LINK(MediaAccessibility, MACaptionAppearanceCopyWindowColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     52SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetForegroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     53SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetBackgroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     54SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetWindowOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     55SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetWindowRoundedCornerRadius, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     56SOFT_LINK(MediaAccessibility, MACaptionAppearanceCopyFontDescriptorForStyle, CTFontDescriptorRef, (MACaptionAppearanceDomain domain,  MACaptionAppearanceBehavior *behavior, MACaptionAppearanceFontStyle fontStyle), (domain, behavior, fontStyle))
     57SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetRelativeCharacterSize, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     58SOFT_LINK(MediaAccessibility, MACaptionAppearanceGetTextEdgeStyle, MACaptionAppearanceTextEdgeStyle, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
     59SOFT_LINK(MediaAccessibility, MACaptionAppearanceAddSelectedLanguage, bool, (MACaptionAppearanceDomain domain, CFStringRef language), (domain, language));
     60SOFT_LINK(MediaAccessibility, MACaptionAppearanceCopySelectedLanguages, CFArrayRef, (MACaptionAppearanceDomain domain), (domain));
     61
     62SOFT_LINK_POINTER(MediaAccessibility, kMAXCaptionAppearanceSettingsChangedNotification, CFStringRef)
     63#define kMAXCaptionAppearanceSettingsChangedNotification getkMAXCaptionAppearanceSettingsChangedNotification()
     64
    4365using namespace std;
    4466
     
    4971    static_cast<CaptionUserPreferencesMac*>(observer)->captionPreferencesChanged();
    5072}
    51 
    5273
    5374CaptionUserPreferencesMac::CaptionUserPreferencesMac(PageGroup* group)
     
    5980CaptionUserPreferencesMac::~CaptionUserPreferencesMac()
    6081{
    61     if (wkCaptionAppearanceGetSettingsChangedNotification())
    62         CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, wkCaptionAppearanceGetSettingsChangedNotification(), NULL);
    63 }
    64 
    65 bool CaptionUserPreferencesMac::userHasCaptionPreferences() const
    66 {
    67     return wkCaptionAppearanceHasUserPreferences();
     82    if (kMAXCaptionAppearanceSettingsChangedNotification)
     83        CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kMAXCaptionAppearanceSettingsChangedNotification, NULL);
    6884}
    6985
    7086bool CaptionUserPreferencesMac::userPrefersCaptions() const
    7187{
    72     return wkCaptionAppearanceShowCaptionsWhenAvailable();
     88    return MACaptionAppearanceGetShowCaptions(kMACaptionAppearanceDomainUser);
     89}
     90
     91void CaptionUserPreferencesMac::setUserPrefersCaptions(bool preference)
     92{
     93    MACaptionAppearanceSetShowCaptions(kMACaptionAppearanceDomainUser, preference);
    7394}
    7495
     
    7798    ASSERT(!m_captionPreferenceChangeListeners.contains(listener));
    7899
    79     if (!wkCaptionAppearanceGetSettingsChangedNotification())
     100    if (!kMAXCaptionAppearanceSettingsChangedNotification)
    80101        return;
    81102   
    82103    if (!m_listeningForPreferenceChanges) {
    83104        m_listeningForPreferenceChanges = true;
    84         CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, wkCaptionAppearanceGetSettingsChangedNotification(), NULL, CFNotificationSuspensionBehaviorCoalesce);
     105        CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, NULL, CFNotificationSuspensionBehaviorCoalesce);
    85106        updateCaptionStyleSheetOveride();
    86107    }
     
    91112void CaptionUserPreferencesMac::unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
    92113{
    93     if (wkCaptionAppearanceGetSettingsChangedNotification())
     114    if (kMAXCaptionAppearanceSettingsChangedNotification)
    94115        m_captionPreferenceChangeListeners.remove(listener);
    95116}
    96117
    97 Color CaptionUserPreferencesMac::captionsWindowColor() const
    98 {
    99     RetainPtr<CGColorRef> color(AdoptCF, wkCaptionAppearanceCopyWindowColor());
     118String CaptionUserPreferencesMac::captionsWindowCSS() const
     119{
     120    MACaptionAppearanceBehavior behavior;
     121    RetainPtr<CGColorRef> color(AdoptCF, MACaptionAppearanceCopyWindowColor(kMACaptionAppearanceDomainUser, &behavior));
     122
    100123    Color windowColor(color.get());
    101124    if (!windowColor.isValid())
    102125        windowColor = Color::transparent;
    103    
    104     CGFloat opacity;
    105     if (wkCaptionAppearanceGetWindowOpacity(&opacity))
    106         return Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast<int>(opacity * 255));
    107    
    108     if (!color)
    109         return Color();
    110    
    111     return windowColor;
    112 }
    113 
    114 Color CaptionUserPreferencesMac::captionsBackgroundColor() const
     126
     127    CGFloat opacity = MACaptionAppearanceGetWindowOpacity(kMACaptionAppearanceDomainUser, &behavior);
     128    return colorPropertyCSS(CSSPropertyBackgroundColor, Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast<int>(opacity * 255)), behavior == kMACaptionAppearanceBehaviorUseValue);
     129}
     130
     131String CaptionUserPreferencesMac::captionsBackgroundCSS() const
    115132{
    116133    // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-past-nodes
    117134    // and webkit-media-text-track-future-nodes.
    118135    DEFINE_STATIC_LOCAL(Color, defaultBackgroundColor, (Color(0, 0, 0, 0.8 * 255)));
    119    
    120     RetainPtr<CGColorRef> color(AdoptCF, wkCaptionAppearanceCopyBackgroundColor());
     136
     137    MACaptionAppearanceBehavior behavior;
     138
     139    RetainPtr<CGColorRef> color(AdoptCF, MACaptionAppearanceCopyBackgroundColor(kMACaptionAppearanceDomainUser, &behavior));
    121140    Color backgroundColor(color.get());
    122     if (!backgroundColor.isValid()) {
     141    if (!backgroundColor.isValid())
    123142        backgroundColor = defaultBackgroundColor;
    124     }
    125    
    126     CGFloat opacity;
    127     if (wkCaptionAppearanceGetBackgroundOpacity(&opacity))
    128         return Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast<int>(opacity * 255));
    129    
    130     if (!color)
    131         return Color();
    132    
    133     return backgroundColor;
    134 }
    135 
    136 Color CaptionUserPreferencesMac::captionsTextColor() const
    137 {
    138     RetainPtr<CGColorRef> color(AdoptCF, wkCaptionAppearanceCopyForegroundColor());
     143
     144    CGFloat opacity = MACaptionAppearanceGetBackgroundOpacity(kMACaptionAppearanceDomainUser, 0);
     145    return colorPropertyCSS(CSSPropertyBackgroundColor, Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast<int>(opacity * 255)), behavior == kMACaptionAppearanceBehaviorUseValue);
     146}
     147
     148Color CaptionUserPreferencesMac::captionsTextColor(bool& important) const
     149{
     150    MACaptionAppearanceBehavior behavior;
     151    RetainPtr<CGColorRef> color(AdoptCF, MACaptionAppearanceCopyForegroundColor(kMACaptionAppearanceDomainUser, &behavior));
    139152    Color textColor(color.get());
    140     if (!textColor.isValid()) {
     153    if (!textColor.isValid())
    141154        // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-container.
    142155        textColor = Color::white;
    143     }
    144    
    145     CGFloat opacity;
    146     if (wkCaptionAppearanceGetForegroundOpacity(&opacity))
    147         return Color(textColor.red(), textColor.green(), textColor.blue(), static_cast<int>(opacity * 255));
    148    
    149     if (!color)
    150         return Color();
    151    
    152     return textColor;
    153 }
    154 
     156   
     157    CGFloat opacity = MACaptionAppearanceGetForegroundOpacity(kMACaptionAppearanceDomainUser, &behavior);
     158    important = behavior == kMACaptionAppearanceBehaviorUseValue;
     159    return Color(textColor.red(), textColor.green(), textColor.blue(), static_cast<int>(opacity * 255));
     160}
     161   
     162String CaptionUserPreferencesMac::captionsTextColorCSS() const
     163{
     164    bool important;
     165    Color textColor = captionsTextColor(important);
     166
     167    if (!textColor.isValid())
     168        return emptyString();
     169
     170    return colorPropertyCSS(CSSPropertyColor, textColor, important);
     171}
     172   
     173String CaptionUserPreferencesMac::windowRoundedCornerRadiusCSS() const
     174{
     175    MACaptionAppearanceBehavior behavior;
     176    CGFloat radius = MACaptionAppearanceGetWindowRoundedCornerRadius(kMACaptionAppearanceDomainUser, &behavior);
     177    if (!radius)
     178        return emptyString();
     179
     180    StringBuilder builder;
     181    builder.append(getPropertyNameString(CSSPropertyBorderRadius));
     182    builder.append(':');
     183    builder.append(String::format("%.02f", radius));
     184    if (behavior == kMACaptionAppearanceBehaviorUseValue)
     185        builder.append(" !important");
     186    builder.append(';');
     187
     188    return builder.toString();
     189}
     190   
    155191Color CaptionUserPreferencesMac::captionsEdgeColorForTextColor(const Color& textColor) const
    156192{
     
    164200}
    165201
    166 String CaptionUserPreferencesMac::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String& value, const Color& textColor) const
     202String CaptionUserPreferencesMac::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String& value, const Color& textColor, bool important) const
    167203{
    168204    StringBuilder builder;
     
    173209    builder.append(' ');
    174210    builder.append(captionsEdgeColorForTextColor(textColor).serialized());
     211    if (important)
     212        builder.append(" !important");
    175213    builder.append(';');
    176214   
     
    178216}
    179217
    180 String CaptionUserPreferencesMac::cssColorProperty(CSSPropertyID id, const Color& color) const
     218String CaptionUserPreferencesMac::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const
    181219{
    182220    StringBuilder builder;
     
    185223    builder.append(':');
    186224    builder.append(color.serialized());
     225    if (important)
     226        builder.append(" !important");
    187227    builder.append(';');
    188228   
     
    190230}
    191231
    192 String CaptionUserPreferencesMac::captionsTextEdgeStyle() const
     232String CaptionUserPreferencesMac::captionsTextEdgeCSS() const
    193233{
    194234    DEFINE_STATIC_LOCAL(const String, edgeStyleRaised, (" -.05em -.05em 0 ", String::ConstructFromLiteral));
     
    196236    DEFINE_STATIC_LOCAL(const String, edgeStyleDropShadow, (" .075em .075em 0 ", String::ConstructFromLiteral));
    197237    DEFINE_STATIC_LOCAL(const String, edgeStyleUniform, (" .03em ", String::ConstructFromLiteral));
    198    
    199     Color color = captionsTextColor();
     238
     239    bool unused;
     240    Color color = captionsTextColor(unused);
    200241    if (!color.isValid())
    201242        color.setNamedColor("black");
    202243    color = captionsEdgeColorForTextColor(color);
    203    
    204     wkCaptionTextEdgeStyle textEdgeStyle = static_cast<wkCaptionTextEdgeStyle>(wkCaptionAppearanceGetTextEdgeStyle());
     244
     245    MACaptionAppearanceBehavior behavior;
     246    MACaptionAppearanceTextEdgeStyle textEdgeStyle = MACaptionAppearanceGetTextEdgeStyle(kMACaptionAppearanceDomainUser, &behavior);
    205247    switch (textEdgeStyle) {
    206         case wkCaptionTextEdgeStyleUndefined:
    207         case wkCaptionTextEdgeStyleNone:
     248        case kMACaptionAppearanceTextEdgeStyleUndefined:
     249        case kMACaptionAppearanceTextEdgeStyleNone:
    208250            return emptyString();
    209251           
    210         case wkCaptionTextEdgeStyleRaised:
    211             return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color);
    212         case wkCaptionTextEdgeStyleDepressed:
    213             return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color);
    214         case wkCaptionTextEdgeStyleDropShadow:
    215             return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color);
    216         case wkCaptionTextEdgeStyleUniform:
    217             return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, edgeStyleUniform, color);
     252        case kMACaptionAppearanceTextEdgeStyleRaised:
     253            return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color, behavior == kMACaptionAppearanceBehaviorUseValue);
     254        case kMACaptionAppearanceTextEdgeStyleDepressed:
     255            return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color, behavior == kMACaptionAppearanceBehaviorUseValue);
     256        case kMACaptionAppearanceTextEdgeStyleDropShadow:
     257            return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color, behavior == kMACaptionAppearanceBehaviorUseValue);
     258        case kMACaptionAppearanceTextEdgeStyleUniform:
     259            return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, edgeStyleUniform, color, behavior == kMACaptionAppearanceBehaviorUseValue);
    218260           
    219         case wkCaptionTextEdgeStyleMax:
    220             ASSERT_NOT_REACHED();
    221261        default:
    222262            ASSERT_NOT_REACHED();
     
    227267}
    228268
    229 String CaptionUserPreferencesMac::captionsDefaultFont() const
    230 {
    231     RetainPtr<CGFontRef> font(AdoptCF, wkCaptionAppearanceCopyFontForStyle(wkCaptionFontStyleDefault));
     269String CaptionUserPreferencesMac::captionsDefaultFontCSS() const
     270{
     271    MACaptionAppearanceBehavior behavior;
     272   
     273    RetainPtr<CTFontDescriptorRef> font(AdoptCF, MACaptionAppearanceCopyFontDescriptorForStyle(kMACaptionAppearanceDomainUser, &behavior, kMACaptionAppearanceFontStyleDefault));
    232274    if (!font)
    233275        return emptyString();
    234    
    235     RetainPtr<CFStringRef> name(AdoptCF, CGFontCopyPostScriptName(font.get()));
     276
     277    RetainPtr<CFTypeRef> name(AdoptCF, CTFontDescriptorCopyAttribute(font.get(), kCTFontNameAttribute));
    236278    if (!name)
    237279        return emptyString();
     
    241283    builder.append(getPropertyNameString(CSSPropertyFontFamily));
    242284    builder.append(": \"");
    243     builder.append(name.get());
    244     builder.append("\";");
     285    builder.append(static_cast<CFStringRef>(name.get()));
     286    builder.append('"');
     287    if (behavior == kMACaptionAppearanceBehaviorUseValue)
     288        builder.append(" !important");
     289    builder.append(';');
    245290   
    246291    return builder.toString();
     
    250295{
    251296    StringBuilder captionsOverrideStyleSheet;
    252    
    253     Color color = captionsBackgroundColor();
    254     if (color.isValid()) {
     297
     298    String background = captionsBackgroundCSS();
     299    if (!background.isEmpty()) {
    255300        captionsOverrideStyleSheet.append(" video::");
    256301        captionsOverrideStyleSheet.append(TextTrackCue::allNodesShadowPseudoId());
    257302        captionsOverrideStyleSheet.append('{');
    258         captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
     303        captionsOverrideStyleSheet.append(background);
    259304        captionsOverrideStyleSheet.append('}');
    260305    }
    261    
    262     color = captionsWindowColor();
    263     if (color.isValid()) {
     306
     307    String windowColor = captionsWindowCSS();
     308    String windowCornerRadius = windowRoundedCornerRadiusCSS();
     309    String captionsColor = captionsTextColorCSS();
     310    String edgeStyle = captionsTextEdgeCSS();
     311    String fontName = captionsDefaultFontCSS();
     312    if (!captionsColor.isEmpty() || !windowColor.isEmpty() || !windowCornerRadius.isEmpty() || !edgeStyle.isEmpty() || !fontName.isEmpty()) {
    264313        captionsOverrideStyleSheet.append(" video::");
    265314        captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId());
    266315        captionsOverrideStyleSheet.append('{');
    267         captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
    268         captionsOverrideStyleSheet.append('}');
    269     }
    270    
    271     color = captionsTextColor();
    272     String edgeStyle = captionsTextEdgeStyle();
    273     String fontName = captionsDefaultFont();
    274     if (color.isValid() || !edgeStyle.isEmpty() || !fontName.isEmpty()) {
    275         captionsOverrideStyleSheet.append(" video::");
    276         captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId());
    277         captionsOverrideStyleSheet.append('{');
    278        
    279         if (color.isValid())
    280             captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyColor, color));
     316
     317        if (!windowColor.isEmpty())
     318            captionsOverrideStyleSheet.append(windowColor);
     319        if (!windowCornerRadius.isEmpty())
     320            captionsOverrideStyleSheet.append(windowCornerRadius);
     321        if (!captionsColor.isEmpty())
     322            captionsOverrideStyleSheet.append(captionsColor);
    281323        if (!edgeStyle.isEmpty())
    282324            captionsOverrideStyleSheet.append(edgeStyle);
    283325        if (!fontName.isEmpty())
    284326            captionsOverrideStyleSheet.append(fontName);
    285        
     327
    286328        captionsOverrideStyleSheet.append('}');
    287329    }
    288    
     330
    289331    return captionsOverrideStyleSheet.toString();
    290332}
    291333
    292 float CaptionUserPreferencesMac::captionFontSizeScale() const
    293 {
    294     CGFloat characterScale = CaptionUserPreferences::captionFontSizeScale();
    295     CGFloat scaleAdjustment;
    296    
    297     if (!wkCaptionAppearanceGetRelativeCharacterSize(&scaleAdjustment))
     334float CaptionUserPreferencesMac::captionFontSizeScale(bool& important) const
     335{
     336    MACaptionAppearanceBehavior behavior;
     337    CGFloat characterScale = CaptionUserPreferences::captionFontSizeScale(important);
     338    CGFloat scaleAdjustment = MACaptionAppearanceGetRelativeCharacterSize(kMACaptionAppearanceDomainUser, &behavior);
     339
     340    if (!scaleAdjustment)
    298341        return characterScale;
    299    
     342
     343    important = behavior == kMACaptionAppearanceBehaviorUseValue;
    300344#if defined(__LP64__) && __LP64__
    301345    return narrowPrecisionToFloat(scaleAdjustment * characterScale);
     
    323367    pageGroup()->removeUserStyleSheetFromWorld(mainThreadNormalWorld(), captionsStyleSheetURL);
    324368   
    325     if (!userHasCaptionPreferences())
    326         return;
    327    
    328369    String captionsOverrideStyleSheet = captionsStyleSheetOverride();
    329370    if (captionsOverrideStyleSheet.isEmpty())
     
    334375}
    335376
     377void CaptionUserPreferencesMac::setPreferredLanguage(String language) const
     378{
     379    MACaptionAppearanceAddSelectedLanguage(kMACaptionAppearanceDomainUser, language.createCFString().get());
     380}
     381
     382Vector<String> CaptionUserPreferencesMac::preferredLanguages() const
     383{
     384    Vector<String> override = userPreferredLanguagesOverride();
     385    if (!override.isEmpty())
     386        return override;
     387
     388    RetainPtr<CFArrayRef> languages(AdoptCF, MACaptionAppearanceCopySelectedLanguages(kMACaptionAppearanceDomainUser));
     389    CFIndex languageCount = CFArrayGetCount(languages.get());
     390
     391    if (!languageCount)
     392        return CaptionUserPreferences::preferredLanguages();
     393
     394    Vector<String> userPreferredLanguages(languageCount);
     395    for (CFIndex i = 0; i < languageCount; i++)
     396        userPreferredLanguages.append(static_cast<CFStringRef>(CFArrayGetValueAtIndex(languages.get(), i)));
     397
     398    return userPreferredLanguages;
     399}
     400
    336401}
    337402
  • trunk/Source/WebCore/page/PageGroup.cpp

    r136323 r141790  
    4040
    4141#if ENABLE(VIDEO_TRACK)
    42 #if PLATFORM(MAC)
     42#if PLATFORM(MAC) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    4343#include "CaptionUserPreferencesMac.h"
    4444#else
     
    421421{
    422422    if (!m_captionPreferences)
    423 #if PLATFORM(MAC)
     423#if PLATFORM(MAC) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    424424        m_captionPreferences = CaptionUserPreferencesMac::create(this);
    425425#else
     
    452452}
    453453
    454 float PageGroup::captionFontSizeScale()
    455 {
    456     return captionPreferences()->captionFontSizeScale();
     454float PageGroup::captionFontSizeScale(bool& important)
     455{
     456    return captionPreferences()->captionFontSizeScale(important);
    457457}
    458458
  • trunk/Source/WebCore/page/PageGroup.h

    r136323 r141790  
    112112        bool userPrefersCaptions();
    113113        bool userHasCaptionPreferences();
    114         float captionFontSizeScale();
     114        float captionFontSizeScale(bool&);
    115115        void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*);
    116116        void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*);
  • trunk/Source/WebCore/platform/Language.cpp

    r134507 r141790  
    7575    DEFINE_STATIC_LOCAL(Vector<String>, override, ());
    7676    return override;
     77}
     78
     79Vector<String> userPreferredLanguagesOverride()
     80{
     81    return preferredLanguagesOverride();
    7782}
    7883
  • trunk/Source/WebCore/platform/Language.h

    r134507 r141790  
    3434String defaultLanguage();
    3535Vector<String> userPreferredLanguages();
     36Vector<String> userPreferredLanguagesOverride();
    3637void overrideUserPreferredLanguages(const Vector<String>&);
    3738String preferredLanguageFromList(const Vector<String>&);
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.mm

    r137161 r141790  
    6161SOFT_LINK_POINTER(AVFoundation, AVMetadataKeySpaceCommon, NSString *)
    6262SOFT_LINK_POINTER(AVFoundation, AVMediaTypeSubtitle, NSString *)
    63 SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicContainsOnlyForcedSubtitles, NSString *)
     63SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicTranscribesSpokenDialogForAccessibility, NSString *)
     64SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicDescribesMusicAndSoundForAccessibility, NSString *)
    6465#define AVMetadataItem getAVMetadataItemClass()
    6566#define AVPlayerItemLegibleOutput getAVPlayerItemLegibleOutputClass()
     
    6869#define AVMetadataKeySpaceCommon getAVMetadataKeySpaceCommon()
    6970#define AVMediaTypeSubtitle getAVMediaTypeSubtitle()
    70 #define AVMediaCharacteristicContainsOnlyForcedSubtitles getAVMediaCharacteristicContainsOnlyForcedSubtitles()
     71#define AVMediaCharacteristicTranscribesSpokenDialogForAccessibility getAVMediaCharacteristicTranscribesSpokenDialogForAccessibility()
     72#define AVMediaCharacteristicDescribesMusicAndSoundForAccessibility getAVMediaCharacteristicDescribesMusicAndSoundForAccessibility()
    7173
    7274using namespace WebCore;
     
    9597    if ([mediaType isEqualToString:AVMediaTypeClosedCaption])
    9698        return Captions;
    97     if ([mediaType isEqualToString:AVMediaTypeSubtitle])
     99    if ([mediaType isEqualToString:AVMediaTypeSubtitle]) {
     100
     101        // An "SDH" track is a subtitle track created for the deaf or hard-of-hearing. "captions" in WebVTT are
     102        // "labeled as appropriate for the hard-of-hearing", so tag SDH sutitles as "captions".
     103        if ([m_mediaSelectionOption hasMediaCharacteristic:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility])
     104            return Captions;
     105        if ([m_mediaSelectionOption hasMediaCharacteristic:AVMediaCharacteristicDescribesMusicAndSoundForAccessibility])
     106            return Captions;
     107       
    98108        return Subtitles;
     109    }
    99110
    100111    return Captions;
Note: See TracChangeset for help on using the changeset viewer.