Changeset 130556 in webkit


Ignore:
Timestamp:
Oct 5, 2012 2:57:04 PM (11 years ago)
Author:
jer.noble@apple.com
Message:

Allow ports to override text track rendering style
https://bugs.webkit.org/show_bug.cgi?id=97800
<rdar://problem/12044964>

Patch by Eric Carlson <eric.carlson@apple.com> on 2012-10-04
Reviewed by Silvia Pfeiffer.

Source/WebCore:

  • WebCore.exp.in: Export new WebkitSystemInterface functions.
  • WebCore.xcodeproj/project.pbxproj: Add CaptionPreferencesChangedListener.h.
  • css/mediaControls.css: Rearrange the caption CSS so it is possible to style the cue window,

background, and text independently.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_disableCaptions with theme->userPrefersCaptions().
(WebCore::HTMLMediaElement::attach): Register for caption preferences change callbacks.
(WebCore::HTMLMediaElement::detach): Unregister for caption preferences change callbacks.
(WebCore::HTMLMediaElement::userPrefersCaptions): Return theme->userPrefersCaptions().
(WebCore::HTMLMediaElement::userIsInterestedInThisTrackKind): Consider userPrefersCaptions().
(WebCore::HTMLMediaElement::setClosedCaptionsVisible): Move the code that marks all tracks as

un-configured to markCaptionAndSubtitleTracksAsUnconfigured so it can be reused.

(WebCore::HTMLMediaElement::captionPreferencesChanged): New, force a reevaluation of all text tracks.
(WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): New, code moved from

setClosedCaptionsVisible

  • html/HTMLMediaElement.h: Inherit from CaptionPreferencesChangedListener.
  • html/shadow/MediaControlElements.cpp:

(WebCore::MediaControlTextTrackContainerElement::userCaptionPreferencesChanged): New, if theme

has a captions style sheet override, inject it into the current page group, otherwise
remove injected sheet.

(WebCore::MediaControlTextTrackContainerElement::updateSizes): Get rid of unnecessary member

variable. Get caption font scale from theme instead of hard coding.

  • html/shadow/MediaControlElements.h:
  • html/shadow/MediaControlRootElement.cpp:

(WebCore::MediaControlRootElement::userCaptionPreferencesChanged): New.
(WebCore::MediaControlRootElement::updateTextTrackDisplay):

  • html/shadow/MediaControlRootElement.h: Add userCaptionPreferencesChanged, minor cleanup.
  • html/shadow/MediaControls.h:

(WebCore::MediaControls::userCaptionPreferencesChanged): New.

  • html/track/TextTrackCue.cpp:

(WebCore::TextTrackCueBox::TextTrackCueBox): Set the shadow pseudo id.
(WebCore::TextTrackCueBox::textTrackCueBoxShadowPseudoId): New, class method to return the

shadow pseudo id so it can be used elsewhere.

(WebCore::TextTrackCueBox::shadowPseudoId): Call textTrackCueBoxShadowPseudoId.
(WebCore::TextTrackCue::pastNodesShadowPseudoId): New, class method to return the

shadow pseudo id so it can be used elsewhere.

(WebCore::TextTrackCue::futureNodesShadowPseudoId): Ditto.
(WebCore::TextTrackCue::updateDisplayTree):

  • html/track/TextTrackCue.h:
  • platform/mac/WebCoreSystemInterface.h: Updated.
  • platform/mac/WebCoreSystemInterface.mm: Ditto.
  • rendering/CaptionPreferencesChangedListener.h: Added.
  • rendering/RenderTheme.h:

(WebCore::RenderTheme::userPrefersCaptions): New, default do-nothing implementation.
(WebCore::RenderTheme::userHasCaptionPreferences): Ditto.
(WebCore::RenderTheme::captionFontSizeScale): Ditto.
(WebCore::RenderTheme::captionsStyleSheetOverride): Ditto.
(WebCore::RenderTheme::registerForCaptionPreferencesChangedCallbacks): Ditto.
(WebCore::RenderTheme::unregisterForCaptionPreferencesChangedCallbacks): Ditto.

  • rendering/RenderThemeMac.h:
  • rendering/RenderThemeMac.mm:

(WebCore::userCaptionPreferencesChangedNotificationCallback): New, receives preference changed notifications.
(WebCore::RenderThemeMac::RenderThemeMac): Initialize m_listeningForCaptionPreferenceNotifications.
(WebCore::RenderThemeMac::~RenderThemeMac): Unregister for notifications if necessary.
(WebCore::RenderThemeMac::userHasCaptionPreferences): New, passthrough to WKSI function.
(WebCore::RenderThemeMac::userPrefersCaptions): Ditto.
(WebCore::RenderThemeMac::captionsWindowColor): Return Color with user's caption window color preference.
(WebCore::RenderThemeMac::captionsBackgroundColor): Return Color with user's caption

background color preference.

(WebCore::RenderThemeMac::captionsTextColor): Return Color with user's caption text color preference.
(WebCore::RenderThemeMac::captionsEdgeColorForTextColor): Return Color for text edge effect.
(WebCore::RenderThemeMac::cssPropertyWithTextEdgeColor): Return String with CSS to set a text-shadow

or webkit-text-stroke property.

(WebCore::RenderThemeMac::cssColorProperty): Return a String with css to set a property

with a color value.

(WebCore::RenderThemeMac::captionsTextEdgeStyle): Return a String with css to style caption

text with the user's preferred text edge stye.

(WebCore::RenderThemeMac::captionsDefaultFont): Return a String with css to style caption

text with the user's preferred font.

(WebCore::RenderThemeMac::captionsStyleSheetOverride): Return a String with css to style captions

with the user's preferred style.

(WebCore::RenderThemeMac::captionFontSizeScale): Return the user's preferred caption font scale.
(WebCore::RenderThemeMac::captionPreferencesChanged): Notify listeners of caption preference change.
(WebCore::RenderThemeMac::registerForCaptionPreferencesChangedCallbacks): Add a caption preferences

changes listener.

(WebCore::RenderThemeMac::unregisterForCaptionPreferencesChangedCallbacks): Remove a caption preferences

changes listener.

Source/WebKit/mac:

Add WCSI support for new WKSI caption functions.

  • WebCoreSupport/WebSystemInterface.mm:

(InitWebCoreSystemInterface): Initialize new WKSI function pointers.

Source/WebKit2:

  • WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:

(InitWebCoreSystemInterface): Initialize new WKSI function pointers.

WebKitLibraries:

Update WKSI header with SPI for getting the user caption appearance preferences.

  • WebKitSystemInterface.h:

LayoutTests:

  • media/track/track-cue-rendering-expected.txt: Update results for caption css changes.
  • media/track/track-cue-rendering.html:
  • platform/chromium/TestExpectations: Skip tests that need to be rebaselined.
Location:
trunk
Files:
1 added
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r130555 r130556  
     12012-10-04  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Allow ports to override text track rendering style
     4        https://bugs.webkit.org/show_bug.cgi?id=97800
     5        <rdar://problem/12044964>
     6
     7        Reviewed by Silvia Pfeiffer.
     8
     9        * media/track/track-cue-rendering-expected.txt: Update results for caption css changes.
     10        * media/track/track-cue-rendering.html:
     11        * platform/chromium/TestExpectations: Skip tests that need to be rebaselined.
     12
    1132012-10-05  Takashi Sakamoto  <tasak@google.com>
    214
  • trunk/LayoutTests/media/track/track-cue-rendering-expected.txt

    r122694 r130556  
    5050
    5151EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontFamily == 'sans-serif') OK
    52 EXPECTED (getComputedStyle(textTrackDisplayElement(video)).color == 'rgba(255, 255, 255, 0)') OK
     52EXPECTED (getComputedStyle(textTrackDisplayElement(video)).color == 'rgb(255, 255, 255)') OK
    5353EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor == 'rgba(0, 0, 0, 0.796875)'), OBSERVED 'rgba(0, 0, 0, 0.8)' FAIL
    5454END OF TEST
  • trunk/LayoutTests/media/track/track-cue-rendering.html

    r114760 r130556  
    3333
    3434            testExpected("getComputedStyle(textTrackDisplayElement(video)).fontFamily", "sans-serif");
    35             testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgba(255, 255, 255, 0)");
     35            testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgb(255, 255, 255)");
    3636            testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.796875)");
    3737
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r130542 r130556  
    37903790webkit.org/b/98545 [ Mac ] fast/text/international/text-spliced-font.html [ Failure ]
    37913791webkit.org/b/98545 [ Mac ] fast/writing-mode/Kusa-Makura-background-canvas.html [ Failure ]
     3792
     3793# Need to be updated after webkit.org/b/97800
     3794webkit.org/b/89167 media/track/track-cue-rendering-horizontal.html [ Failure ]
     3795webkit.org/b/89167 media/track/track-cue-rendering-vertical.html [ Failure ]
     3796webkit.org/b/89167 media/track/track-cue-rendering.html [ Failure ]
     3797
  • trunk/Source/WebCore/ChangeLog

    r130555 r130556  
     12012-10-04  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Allow ports to override text track rendering style
     4        https://bugs.webkit.org/show_bug.cgi?id=97800
     5        <rdar://problem/12044964>
     6
     7        Reviewed by Silvia Pfeiffer.
     8
     9        * WebCore.exp.in: Export new WebkitSystemInterface functions.
     10        * WebCore.xcodeproj/project.pbxproj: Add CaptionPreferencesChangedListener.h.
     11
     12        * css/mediaControls.css: Rearrange the caption CSS so it is possible to style the cue window,
     13            background, and text independently.
     14
     15        * html/HTMLMediaElement.cpp:
     16        (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_disableCaptions with theme->userPrefersCaptions().
     17        (WebCore::HTMLMediaElement::attach): Register for caption preferences change callbacks.
     18        (WebCore::HTMLMediaElement::detach): Unregister for caption preferences change callbacks.
     19        (WebCore::HTMLMediaElement::userPrefersCaptions): Return theme->userPrefersCaptions().
     20        (WebCore::HTMLMediaElement::userIsInterestedInThisTrackKind): Consider userPrefersCaptions().
     21        (WebCore::HTMLMediaElement::setClosedCaptionsVisible): Move the code that marks all tracks as
     22            un-configured to markCaptionAndSubtitleTracksAsUnconfigured so it can be reused.
     23        (WebCore::HTMLMediaElement::captionPreferencesChanged): New, force a reevaluation of all text tracks.
     24        (WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): New, code moved from
     25            setClosedCaptionsVisible
     26        * html/HTMLMediaElement.h: Inherit from CaptionPreferencesChangedListener.
     27
     28        * html/shadow/MediaControlElements.cpp:
     29        (WebCore::MediaControlTextTrackContainerElement::userCaptionPreferencesChanged): New, if theme
     30            has a captions style sheet override, inject it into the current page group, otherwise
     31            remove injected sheet.
     32        (WebCore::MediaControlTextTrackContainerElement::updateSizes): Get rid of unnecessary member
     33            variable. Get caption font scale from theme instead of hard coding.
     34        * html/shadow/MediaControlElements.h:
     35
     36        * html/shadow/MediaControlRootElement.cpp:
     37        (WebCore::MediaControlRootElement::userCaptionPreferencesChanged): New.
     38        (WebCore::MediaControlRootElement::updateTextTrackDisplay):
     39        * html/shadow/MediaControlRootElement.h: Add userCaptionPreferencesChanged, minor cleanup.
     40
     41        * html/shadow/MediaControls.h:
     42        (WebCore::MediaControls::userCaptionPreferencesChanged): New.
     43
     44        * html/track/TextTrackCue.cpp:
     45        (WebCore::TextTrackCueBox::TextTrackCueBox): Set the shadow pseudo id.
     46        (WebCore::TextTrackCueBox::textTrackCueBoxShadowPseudoId): New, class method to return the
     47            shadow pseudo id so it can be used elsewhere.
     48        (WebCore::TextTrackCueBox::shadowPseudoId): Call textTrackCueBoxShadowPseudoId.
     49        (WebCore::TextTrackCue::pastNodesShadowPseudoId): New, class method to return the
     50            shadow pseudo id so it can be used elsewhere.
     51        (WebCore::TextTrackCue::futureNodesShadowPseudoId): Ditto.
     52        (WebCore::TextTrackCue::updateDisplayTree):
     53        * html/track/TextTrackCue.h:
     54
     55        * platform/mac/WebCoreSystemInterface.h: Updated.
     56        * platform/mac/WebCoreSystemInterface.mm: Ditto.
     57
     58        * rendering/CaptionPreferencesChangedListener.h: Added.
     59
     60        * rendering/RenderTheme.h:
     61        (WebCore::RenderTheme::userPrefersCaptions): New, default do-nothing implementation.
     62        (WebCore::RenderTheme::userHasCaptionPreferences): Ditto.
     63        (WebCore::RenderTheme::captionFontSizeScale): Ditto.
     64        (WebCore::RenderTheme::captionsStyleSheetOverride): Ditto.
     65        (WebCore::RenderTheme::registerForCaptionPreferencesChangedCallbacks): Ditto.
     66        (WebCore::RenderTheme::unregisterForCaptionPreferencesChangedCallbacks): Ditto.
     67
     68        * rendering/RenderThemeMac.h:
     69        * rendering/RenderThemeMac.mm:
     70        (WebCore::userCaptionPreferencesChangedNotificationCallback): New, receives preference changed notifications.
     71        (WebCore::RenderThemeMac::RenderThemeMac): Initialize m_listeningForCaptionPreferenceNotifications.
     72        (WebCore::RenderThemeMac::~RenderThemeMac): Unregister for notifications if necessary.
     73        (WebCore::RenderThemeMac::userHasCaptionPreferences): New, passthrough to WKSI function.
     74        (WebCore::RenderThemeMac::userPrefersCaptions): Ditto.
     75        (WebCore::RenderThemeMac::captionsWindowColor): Return Color with user's caption window color preference.
     76        (WebCore::RenderThemeMac::captionsBackgroundColor): Return Color with user's caption
     77            background color preference.
     78        (WebCore::RenderThemeMac::captionsTextColor): Return Color with user's caption text color preference.
     79        (WebCore::RenderThemeMac::captionsEdgeColorForTextColor): Return Color for text edge effect.
     80        (WebCore::RenderThemeMac::cssPropertyWithTextEdgeColor): Return String with CSS to set a text-shadow
     81            or webkit-text-stroke property.
     82        (WebCore::RenderThemeMac::cssColorProperty): Return a String with css to set a property
     83            with a color value.
     84        (WebCore::RenderThemeMac::captionsTextEdgeStyle): Return a String with css to style caption
     85            text with the user's preferred text edge stye.
     86        (WebCore::RenderThemeMac::captionsDefaultFont): Return a String with css to style caption
     87            text with the user's preferred font.
     88        (WebCore::RenderThemeMac::captionsStyleSheetOverride): Return a String with css to style captions
     89            with the user's preferred style.
     90        (WebCore::RenderThemeMac::captionFontSizeScale): Return the user's preferred caption font scale.
     91        (WebCore::RenderThemeMac::captionPreferencesChanged): Notify listeners of caption preference change.
     92        (WebCore::RenderThemeMac::registerForCaptionPreferencesChangedCallbacks): Add a caption preferences
     93            changes listener.
     94        (WebCore::RenderThemeMac::unregisterForCaptionPreferencesChangedCallbacks): Remove a caption preferences
     95            changes listener.
     96
    1972012-10-05  Takashi Sakamoto  <tasak@google.com>
    298
  • trunk/Source/WebCore/WebCore.exp.in

    r130400 r130556  
    25832583__ZN7WebCore32collectDictationTextAlternativesEP18NSAttributedStringRN3WTF6VectorINS_24TextAlternativeWithRangeELm0EEE
    25842584#endif
     2585
     2586#if ENABLE(VIDEO_TRACK)
     2587_wkCaptionAppearanceHasUserPreferences
     2588_wkCaptionAppearanceShowCaptionsWhenAvailable
     2589_wkCaptionAppearanceCopyForegroundColor
     2590_wkCaptionAppearanceCopyBackgroundColor
     2591_wkCaptionAppearanceCopyWindowColor
     2592_wkCaptionAppearanceGetForegroundOpacity
     2593_wkCaptionAppearanceGetBackgroundOpacity
     2594_wkCaptionAppearanceGetWindowOpacity
     2595_wkCaptionAppearanceCopyFontForStyle
     2596_wkCaptionAppearanceGetRelativeCharacterSize
     2597_wkCaptionAppearanceGetTextEdgeStyle
     2598_wkCaptionAppearanceGetSettingsChangedNotification
     2599#endif
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r130471 r130556  
    58575857                CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
    58585858                CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
     5859                CD2565BA161E46A90055634D /* CaptionPreferencesChangedListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 07EC38B816154C1A00E8146D /* CaptionPreferencesChangedListener.h */; settings = {ATTRIBUTES = (Private, ); }; };
    58595860                CD27F6E51457685A0078207D /* JSMediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E2145767580078207D /* JSMediaController.cpp */; };
    58605861                CD27F6E7145770D30078207D /* MediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E6145770D30078207D /* MediaController.cpp */; };
     
    71487149                07E117061489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTextTrackCueCustom.cpp; sourceTree = "<group>"; };
    71497150                07E38A0B148FCF0C006E1ECC /* JSTextTrackCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTextTrackCustom.h; sourceTree = "<group>"; };
     7151                07EC38B816154C1A00E8146D /* CaptionPreferencesChangedListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CaptionPreferencesChangedListener.h; sourceTree = "<group>"; };
    71507152                0806E57912893045007CED32 /* SVGMatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGMatrix.h; sourceTree = "<group>"; };
    71517153                080E49211255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextLayoutEngineBaseline.cpp; sourceTree = "<group>"; };
     
    2130621308                                BCEA4815097D93020094C9E4 /* break_lines.cpp */,
    2130721309                                BCEA4816097D93020094C9E4 /* break_lines.h */,
     21310                                07EC38B816154C1A00E8146D /* CaptionPreferencesChangedListener.h */,
    2130821311                                BCDD454D1236C95C009A7985 /* ColumnInfo.h */,
    2130921312                                9392F14F0AD1862300691BD4 /* CounterNode.cpp */,
     
    2553825541                                931CBD0F161A44E900E4C874 /* ScrollingStateScrollingNode.h in Headers */,
    2553925542                                931CBD11161A44E900E4C874 /* ScrollingStateTree.h in Headers */,
     25543                                CD2565BA161E46A90055634D /* CaptionPreferencesChangedListener.h in Headers */,
    2554025544                        );
    2554125545                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/css/mediaControls.css

    r126372 r130556  
    217217    font-family: sans-serif;
    218218    text-align: center;
    219     color: rgba(255, 255, 255, 0);
     219    color: rgba(255, 255, 255, 1);
    220220
    221221    letter-spacing: normal;
     
    235235    background-color: rgba(0, 0, 0, 0.8);
    236236    padding: 2px 2px;
    237 
    238     white-space: pre-wrap;
    239237}
    240238
     
    247245    margin-left: -2px;
    248246    padding: 2px 2px 2px 0px;
    249 
    250     white-space: pre-wrap;
    251247}
    252248
    253249video::-webkit-media-text-track-display {
    254250    position: absolute;
    255     color: rgba(255, 255, 255, 1);
    256 }
     251    overflow: hidden;
     252    white-space: pre-wrap;
     253}
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r130084 r130556  
    7070#include "NodeRenderingContext.h"
    7171#include "Page.h"
     72#include "RenderTheme.h"
    7273#include "RenderVideo.h"
    7374#include "RenderView.h"
     
    282283    setHasCustomCallbacks();
    283284    addElementToDocumentMap(this, document);
     285
     286#if ENABLE(VIDEO_TRACK)
     287    if (document->page()) {
     288        RenderTheme* theme = document->page()->theme();
     289        if (theme->userHasCaptionPreferences())
     290            m_disableCaptions = !theme->userPrefersCaptions();
     291    }
     292#endif
    284293}
    285294
     
    542551    }
    543552#endif
     553
     554#if ENABLE(VIDEO_TRACK)
     555    if (document()->page())
     556        document()->page()->theme()->registerForCaptionPreferencesChangedCallbacks(this);
     557#endif
     558}
     559
     560void HTMLMediaElement::detach()
     561{
     562#if ENABLE(VIDEO_TRACK)
     563    if (document()->page())
     564        document()->page()->theme()->unregisterForCaptionPreferencesChangedCallbacks(this);
     565#endif
     566    HTMLElement::detach();
    544567}
    545568
     
    27842807}
    27852808
    2786 bool HTMLMediaElement::userIsInterestedInThisLanguage(const String&) const
    2787 {
    2788     // FIXME: check the user's language preference - bugs.webkit.org/show_bug.cgi?id=74121
    2789     return true;
     2809bool HTMLMediaElement::userPrefersCaptions() const
     2810{
     2811    Page* page = document()->page();
     2812    if (!page)
     2813        return false;
     2814
     2815    RenderTheme* theme = page->theme();
     2816    return theme->userHasCaptionPreferences() && theme->userPrefersCaptions();
    27902817}
    27912818
    27922819bool HTMLMediaElement::userIsInterestedInThisTrackKind(String kind) const
    27932820{
    2794     // If ... the user has indicated an interest in having a track with this text track kind, text track language, ...
    27952821    if (m_disableCaptions)
    27962822        return false;
    27972823
    27982824    Settings* settings = document()->settings();
    2799     if (!settings)
    2800         return false;
     2825    bool userPrefersCaptionsOrSubtitles = m_closedCaptionsVisible || userPrefersCaptions();
    28012826
    28022827    if (kind == TextTrack::subtitlesKeyword())
    2803         return settings->shouldDisplaySubtitles() || m_closedCaptionsVisible;
     2828        return (settings && settings->shouldDisplaySubtitles()) || userPrefersCaptionsOrSubtitles;
    28042829    if (kind == TextTrack::captionsKeyword())
    2805         return settings->shouldDisplayCaptions() || m_closedCaptionsVisible;
     2830        return (settings && settings->shouldDisplayCaptions()) || userPrefersCaptionsOrSubtitles;
    28062831    if (kind == TextTrack::descriptionsKeyword())
    2807         return settings->shouldDisplayTextDescriptions() || m_closedCaptionsVisible;
     2832        return settings && settings->shouldDisplayTextDescriptions();
    28082833
    28092834    return false;
     
    39703995    if (RuntimeEnabledFeatures::webkitVideoTrackEnabled()) {
    39713996        m_disableCaptions = !m_closedCaptionsVisible;
    3972        
    3973         // Mark all track elements as not "configured" so that configureTextTracks()
    3974         // will reconsider which tracks to display in light of new user preferences
    3975         // (e.g. default tracks should not be displayed if the user has turned off
    3976         // captions and non-default tracks should be displayed based on language
    3977         // preferences if the user has turned captions on).
    3978         for (Node* node = firstChild(); node; node = node->nextSibling()) {
    3979             if (!node->hasTagName(trackTag))
    3980                 continue;
    3981             HTMLTrackElement* trackElement = static_cast<HTMLTrackElement*>(node);
    3982             if (trackElement->kind() == TextTrack::captionsKeyword()
    3983                 || trackElement->kind() == TextTrack::subtitlesKeyword())
    3984                 trackElement->setHasBeenConfigured(false);
    3985         }
    3986 
     3997
     3998        markCaptionAndSubtitleTracksAsUnconfigured();
    39873999        configureTextTracks();
     4000
     4001        if (!m_disableCaptions && (hasMediaControls() || createMediaControls()))
     4002            mediaControls()->userCaptionPreferencesChanged();
    39884003    }
    39894004#else
     
    41734188    }
    41744189}
     4190
     4191void HTMLMediaElement::captionPreferencesChanged()
     4192{
     4193    if (!isVideo())
     4194        return;
     4195
     4196    markCaptionAndSubtitleTracksAsUnconfigured();
     4197    configureTextTracks();
     4198
     4199    if (!hasMediaControls() && !createMediaControls())
     4200        return;
     4201    mediaControls()->userCaptionPreferencesChanged();
     4202}
     4203
     4204void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured()
     4205{
     4206    // Mark all track elements as not "configured" so that configureTextTracks()
     4207    // will reconsider which tracks to display in light of new user preferences
     4208    // (e.g. default tracks should not be displayed if the user has turned off
     4209    // captions and non-default tracks should be displayed based on language
     4210    // preferences if the user has turned captions on).
     4211    for (RefPtr<Node> node = firstChild(); node; node = node->nextSibling()) {
     4212        if (!node->hasTagName(trackTag))
     4213            continue;
     4214       
     4215        HTMLTrackElement* trackElement = static_cast<HTMLTrackElement*>(node.get());
     4216        RefPtr<TextTrack> textTrack = trackElement->track();
     4217        if (!textTrack)
     4218            continue;
     4219       
     4220        String kind = textTrack->kind();
     4221
     4222        if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captionsKeyword())
     4223            trackElement->setHasBeenConfigured(false);
     4224    }
     4225}
     4226
    41754227#endif
    41764228
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r128323 r130556  
    3131#include "HTMLElement.h"
    3232#include "ActiveDOMObject.h"
     33#include "CaptionPreferencesChangedListener.h"
    3334#include "GenericEventQueue.h"
    3435#include "MediaCanStartListener.h"
     
    7980class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, public MediaPlayerSupportsTypeClient, private MediaCanStartListener, public ActiveDOMObject, public MediaControllerInterface
    8081#if ENABLE(VIDEO_TRACK)
    81     , private TextTrackClient
     82    , private TextTrackClient, private CaptionPreferencesChangedListener
    8283#endif
    8384{
     
    241242    void configureTextTrackGroup(const TrackGroup&) const;
    242243
     244    bool userPrefersCaptions() const;
    243245    bool userIsInterestedInThisTrackKind(String) const;
    244246    bool textTracksAreReady() const;
     
    326328    virtual void finishParsingChildren();
    327329    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    328     virtual void attach();
     330    virtual void attach() OVERRIDE;
     331    virtual void detach() OVERRIDE;
    329332
    330333    virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
     
    475478#if ENABLE(VIDEO_TRACK)
    476479    void updateActiveTextTrackCues(float);
    477     bool userIsInterestedInThisLanguage(const String&) const;
    478480    HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
    479481
     
    481483    void beginIgnoringTrackDisplayUpdateRequests() { ++m_ignoreTrackDisplayUpdate; }
    482484    void endIgnoringTrackDisplayUpdateRequests() { ASSERT(m_ignoreTrackDisplayUpdate); --m_ignoreTrackDisplayUpdate; }
     485
     486    void markCaptionAndSubtitleTracksAsUnconfigured();
     487    virtual void captionPreferencesChanged() OVERRIDE;
    483488#endif
    484489
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r126372 r130556  
    4646#include "LayoutRepainter.h"
    4747#include "LocalizedStrings.h"
     48#include "MediaControlRootElement.h"
    4849#include "MediaControls.h"
    4950#include "MouseEvent.h"
    5051#include "Page.h"
     52#include "PageGroup.h"
    5153#include "RenderDeprecatedFlexibleBox.h"
    5254#include "RenderInline.h"
     
    13111313}
    13121314
     1315void MediaControlTextTrackContainerElement::userCaptionPreferencesChanged()
     1316{
     1317    DEFINE_STATIC_LOCAL(KURL, captionsStyleSheetURL, (ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23"));
     1318
     1319    Page* page = document()->page();
     1320    if (!page)
     1321        return;
     1322
     1323    RenderTheme* theme = page->theme();
     1324    HTMLMediaElement* mediaElement = toParentMediaElement(this);
     1325
     1326    mediaElement->setNeedsStyleRecalc();
     1327
     1328    page->group().removeUserStyleSheetFromWorld(mainThreadNormalWorld(), captionsStyleSheetURL);
     1329
     1330    if (!mediaElement->closedCaptionsVisible() && !theme->userHasCaptionPreferences())
     1331        return;
     1332
     1333    String captionsOverrideStyleSheet = theme->captionsStyleSheetOverride();
     1334    if (captionsOverrideStyleSheet.isEmpty())
     1335        return;
     1336
     1337    page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), captionsOverrideStyleSheet, captionsStyleSheetURL, adoptPtr(new Vector<String>), adoptPtr(new Vector<String>),
     1338        InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocuments);
     1339}
     1340
    13131341void MediaControlTextTrackContainerElement::updateDisplay()
    13141342{
     
    13771405}
    13781406
    1379 static const float mimimumFontSize = 16;
    1380 static const float videoHeightFontSizePercentage = .05;
    1381 static const float trackBottomMultiplier = .9;
    1382 
    13831407void MediaControlTextTrackContainerElement::updateSizes()
    13841408{
     
    13871411        return;
    13881412
     1413    if (!document()->page())
     1414        return;
     1415
    13891416    IntRect videoBox = toRenderVideo(mediaElement->renderer())->videoBox();
    1390     if (m_videoDisplaySize == videoBox)
    1391         return;
    1392     m_videoDisplaySize = videoBox;
    1393 
    1394     float fontSize = m_videoDisplaySize.size().height() * videoHeightFontSizePercentage;
     1417
     1418    float fontSize = videoBox.size().height() * (document()->page()->theme()->captionFontSizeScale());
    13951419    if (fontSize != m_fontSize) {
    13961420        m_fontSize = fontSize;
  • trunk/Source/WebCore/html/shadow/MediaControlElements.h

    r124022 r130556  
    538538    static PassRefPtr<MediaControlTextTrackContainerElement> create(Document*);
    539539
     540    void userCaptionPreferencesChanged();
    540541    void updateDisplay();
    541542    void updateSizes();
     
    548549    virtual const AtomicString& shadowPseudoId() const;
    549550
    550     IntRect m_videoDisplaySize;
     551    void updateCaptionAppearance();
     552
    551553    float m_fontSize;
    552554};
  • trunk/Source/WebCore/html/shadow/MediaControlRootElement.cpp

    r125590 r130556  
    631631}
    632632
     633void MediaControlRootElement::userCaptionPreferencesChanged()
     634{
     635    if (m_textDisplayContainer)
     636        m_textDisplayContainer->userCaptionPreferencesChanged();
     637}
     638
    633639void MediaControlRootElement::showTextTrackDisplay()
    634640{
     
    651657
    652658    m_textDisplayContainer->updateDisplay();
    653 
    654659}
    655660#endif
  • trunk/Source/WebCore/html/shadow/MediaControlRootElement.h

    r126477 r130556  
    106106#if ENABLE(VIDEO_TRACK)
    107107    void createTextTrackDisplay();
    108     void showTextTrackDisplay();
    109     void hideTextTrackDisplay();
    110     void updateTextTrackDisplay();
     108    virtual void userCaptionPreferencesChanged() OVERRIDE;
     109    virtual void showTextTrackDisplay() OVERRIDE;
     110    virtual void hideTextTrackDisplay() OVERRIDE;
     111    virtual void updateTextTrackDisplay() OVERRIDE;
    111112#endif
    112113
  • trunk/Source/WebCore/html/shadow/MediaControls.h

    r104658 r130556  
    7474
    7575#if ENABLE(VIDEO_TRACK)
     76    virtual void userCaptionPreferencesChanged() { };
    7677    virtual void showTextTrackDisplay() = 0;
    7778    virtual void hideTextTrackDisplay() = 0;
  • trunk/Source/WebCore/html/track/TextTrack.cpp

    r126786 r130556  
    9595}
    9696
    97 TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const String& kind, const String& label, const String& language, TextTrackType type)
     97TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const AtomicString& kind, const AtomicString& label, const AtomicString& language, TextTrackType type)
    9898    : TrackBase(context, TrackBase::TextTrack)
    9999    , m_cues(0)
     
    118118}
    119119
    120 bool TextTrack::isValidKindKeyword(const String& value)
     120bool TextTrack::isValidKindKeyword(const AtomicString& value)
    121121{
    122122    if (equalIgnoringCase(value, subtitlesKeyword()))
     
    134134}
    135135
    136 void TextTrack::setKind(const String& kind)
     136void TextTrack::setKind(const AtomicString& kind)
    137137{
    138138    String oldKind = m_kind;
     
    147147}
    148148
    149 void TextTrack::setMode(const String& mode)
     149void TextTrack::setMode(const AtomicString& mode)
    150150{
    151151    // On setting, if the new value isn't equal to what the attribute would currently
     
    175175}
    176176
    177 String TextTrack::mode() const
     177AtomicString TextTrack::mode() const
    178178{
    179179    // The text track "showing" and "showing by default" modes return the string "showing".
  • trunk/Source/WebCore/html/track/TextTrack.h

    r126786 r130556  
    5555class TextTrack : public TrackBase {
    5656public:
    57     static PassRefPtr<TextTrack> create(ScriptExecutionContext* context, TextTrackClient* client, const String& kind, const String& label, const String& language)
     57    static PassRefPtr<TextTrack> create(ScriptExecutionContext* context, TextTrackClient* client, const AtomicString& kind, const AtomicString& label, const AtomicString& language)
    5858    {
    5959        return adoptRef(new TextTrack(context, client, kind, label, language, AddTrack));
     
    6464    HTMLMediaElement* mediaElement() { return m_mediaElement; }
    6565
    66     String kind() const { return m_kind; }
    67     void setKind(const String&);
     66    AtomicString kind() const { return m_kind; }
     67    void setKind(const AtomicString&);
    6868
    6969    static const AtomicString& subtitlesKeyword();
     
    7272    static const AtomicString& chaptersKeyword();
    7373    static const AtomicString& metadataKeyword();
    74     static bool isValidKindKeyword(const String&);
     74    static bool isValidKindKeyword(const AtomicString&);
    7575
    76     String label() const { return m_label; }
    77     void setLabel(const String& label) { m_label = label; }
     76    AtomicString label() const { return m_label; }
     77    void setLabel(const AtomicString& label) { m_label = label; }
    7878
    79     String language() const { return m_language; }
    80     void setLanguage(const String& language) { m_language = language; }
     79    AtomicString language() const { return m_language; }
     80    void setLanguage(const AtomicString& language) { m_language = language; }
    8181
    8282    static const AtomicString& disabledKeyword();
     
    8484    static const AtomicString& showingKeyword();
    8585
    86     String mode() const;
    87     void setMode(const String&);
     86    AtomicString mode() const;
     87    void setMode(const AtomicString&);
    8888
    8989    bool showingByDefault() const { return m_showingByDefault; }
     
    117117
    118118protected:
    119     TextTrack(ScriptExecutionContext*, TextTrackClient*, const String& kind, const String& label, const String& language, TextTrackType);
     119    TextTrack(ScriptExecutionContext*, TextTrackClient*, const AtomicString& kind, const AtomicString& label, const AtomicString& language, TextTrackType);
    120120
    121121    RefPtr<TextTrackCueList> m_cues;
     
    124124    TextTrackCueList* ensureTextTrackCueList();
    125125    HTMLMediaElement* m_mediaElement;
    126     String m_kind;
    127     String m_label;
    128     String m_language;
    129     String m_mode;
     126    AtomicString m_kind;
     127    AtomicString m_label;
     128    AtomicString m_language;
     129    AtomicString m_mode;
    130130    TextTrackClient* m_client;
    131131    TextTrackType m_trackType;
  • trunk/Source/WebCore/html/track/TextTrackCue.cpp

    r129400 r130556  
    9696    , m_cue(cue)
    9797{
     98    setShadowPseudoId(shadowPseudoId());
    9899}
    99100
     
    168169}
    169170
    170 const AtomicString& TextTrackCueBox::shadowPseudoId() const
     171const AtomicString& TextTrackCueBox::textTrackCueBoxShadowPseudoId()
    171172{
    172173    DEFINE_STATIC_LOCAL(const AtomicString, trackDisplayBoxShadowPseudoId, ("-webkit-media-text-track-display"));
     
    174175}
    175176
     177const AtomicString& TextTrackCueBox::shadowPseudoId() const
     178{
     179    return textTrackCueBoxShadowPseudoId();
     180}
     181
    176182RenderObject* TextTrackCueBox::createRenderer(RenderArena* arena, RenderStyle*)
    177183{
     
    180186
    181187// ----------------------------
     188
     189const AtomicString& TextTrackCue::pastNodesShadowPseudoId()
     190{
     191    DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("-webkit-media-text-track-past-nodes", AtomicString::ConstructFromLiteral));
     192    return subtitles;
     193}
     194
     195const AtomicString& TextTrackCue::futureNodesShadowPseudoId()
     196{
     197    DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("-webkit-media-text-track-future-nodes", AtomicString::ConstructFromLiteral));
     198    return subtitles;
     199}
    182200
    183201TextTrackCue::TextTrackCue(ScriptExecutionContext* context, double start, double end, const String& content)
     
    653671    DEFINE_STATIC_LOCAL(const String, timestampTag, (ASCIILiteral("timestamp")));
    654672
    655     DEFINE_STATIC_LOCAL(const AtomicString, trackPastNodesShadowPseudoId, ("-webkit-media-text-track-past-nodes"));
    656     DEFINE_STATIC_LOCAL(const AtomicString, trackFutureNodesShadowPseudoId, ("-webkit-media-text-track-future-nodes"));
    657 
    658673    if (!track()->isRendered())
    659674      return;
     
    663678    // Clear the contents of the two sets.
    664679    m_futureDocumentNodes->removeChildren();
    665     m_futureDocumentNodes->setShadowPseudoId(trackFutureNodesShadowPseudoId);
     680    m_futureDocumentNodes->setShadowPseudoId(futureNodesShadowPseudoId());
    666681
    667682    m_pastDocumentNodes->removeChildren();
    668     m_pastDocumentNodes->setShadowPseudoId(trackPastNodesShadowPseudoId);
     683    m_pastDocumentNodes->setShadowPseudoId(pastNodesShadowPseudoId());
    669684
    670685    // Update the two sets containing past and future WebVTT objects.
  • trunk/Source/WebCore/html/track/TextTrackCue.h

    r126372 r130556  
    6161
    6262    virtual const AtomicString& shadowPseudoId() const OVERRIDE;
     63    static const AtomicString& textTrackCueBoxShadowPseudoId();
    6364
    6465private:
     
    8081
    8182    virtual ~TextTrackCue();
     83
     84    static const AtomicString& pastNodesShadowPseudoId();
     85    static const AtomicString& futureNodesShadowPseudoId();
    8286
    8387    TextTrack* track() const;
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h

    r129566 r130556  
    331331#endif
    332332
     333typedef enum {
     334    wkCaptionFontStyleDefault = 0,
     335    wkCaptionFontStyleMonospacedWithSerif,
     336    wkCaptionFontStyleProportionalWithSerif,
     337    wkCaptionFontStyleMonospacedWithoutSerif,
     338    wkCaptionFontStyleProportionalWithoutSerif,
     339    wkCaptionFontStyleCasual,
     340    wkCaptionFontStyleCursive,
     341    wkCaptionFontStyleSmallCapital,
     342    wkCaptionFontStyleMax
     343} wkCaptionFontStyle;
     344
     345typedef enum {
     346    wkCaptionTextEdgeStyleUndefined = 0,
     347    wkCaptionTextEdgeStyleNone,
     348    wkCaptionTextEdgeStyleRaised,
     349    wkCaptionTextEdgeStyleDepressed,
     350    wkCaptionTextEdgeStyleUniform,
     351    wkCaptionTextEdgeStyleDropShadow,
     352    wkCaptionTextEdgeStyleMax
     353} wkCaptionTextEdgeStyle;
     354
     355extern bool (*wkCaptionAppearanceHasUserPreferences)(void);
     356extern bool (*wkCaptionAppearanceShowCaptionsWhenAvailable)(void);
     357extern CGColorRef(*wkCaptionAppearanceCopyForegroundColor)(void);
     358extern CGColorRef(*wkCaptionAppearanceCopyBackgroundColor)(void);
     359extern CGColorRef(*wkCaptionAppearanceCopyWindowColor)(void);
     360extern bool(*wkCaptionAppearanceGetForegroundOpacity)(CGFloat*);
     361extern bool(*wkCaptionAppearanceGetBackgroundOpacity)(CGFloat*);
     362extern bool(*wkCaptionAppearanceGetWindowOpacity)(CGFloat*);
     363extern CGFontRef(*wkCaptionAppearanceCopyFontForStyle)(int);
     364extern bool(*wkCaptionAppearanceGetRelativeCharacterSize)(CGFloat*);
     365extern int(*wkCaptionAppearanceGetTextEdgeStyle)(void);
     366extern CFStringRef(*wkCaptionAppearanceGetSettingsChangedNotification)(void);
    333367}
    334368
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm

    r129566 r130556  
    210210#endif
    211211
     212bool (*wkCaptionAppearanceHasUserPreferences)(void);
     213bool (*wkCaptionAppearanceShowCaptionsWhenAvailable)(void);
     214CGColorRef(*wkCaptionAppearanceCopyForegroundColor)(void);
     215CGColorRef(*wkCaptionAppearanceCopyBackgroundColor)(void);
     216CGColorRef(*wkCaptionAppearanceCopyWindowColor)(void);
     217bool(*wkCaptionAppearanceGetForegroundOpacity)(CGFloat*);
     218bool(*wkCaptionAppearanceGetBackgroundOpacity)(CGFloat*);
     219bool(*wkCaptionAppearanceGetWindowOpacity)(CGFloat*);
     220CGFontRef(*wkCaptionAppearanceCopyFontForStyle)(int);
     221bool(*wkCaptionAppearanceGetRelativeCharacterSize)(CGFloat*);
     222int(*wkCaptionAppearanceGetTextEdgeStyle)(void);
     223CFStringRef(*wkCaptionAppearanceGetSettingsChangedNotification)(void);
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r130369 r130556  
    4646#if ENABLE(PROGRESS_ELEMENT)
    4747class RenderProgress;
     48#endif
     49#if ENABLE(VIDEO_TRACK)
     50class CaptionPreferencesChangedListener;
    4851#endif
    4952class CSSStyleSheet;
     
    229232    virtual int sliderTickOffsetFromTrackCenter() const = 0;
    230233    void paintSliderTicks(RenderObject*, const PaintInfo&, const IntRect&);
     234#endif
     235
     236#if ENABLE(VIDEO_TRACK)
     237    virtual bool userPrefersCaptions() const { return false; }
     238    virtual bool userHasCaptionPreferences() const { return false; }
     239    virtual float captionFontSizeScale() const { return 0.05; }
     240    virtual String captionsStyleSheetOverride() const { return emptyString(); }
     241    virtual void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
     242    virtual void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
    231243#endif
    232244
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r123300 r130556  
    102102    // A view associated to the contained document. Subclasses may not have such a view and return a fake.
    103103    virtual NSView* documentViewFor(RenderObject*) const;
     104
     105#if ENABLE(VIDEO_TRACK)
     106    void captionPreferencesChanged();
     107#endif
     108
    104109protected:
    105110    RenderThemeMac();
     
    179184    virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const OVERRIDE;
    180185#endif
     186
     187#if ENABLE(VIDEO_TRACK)
     188    virtual bool userPrefersCaptions() const OVERRIDE;
     189    virtual bool userHasCaptionPreferences() const OVERRIDE;
     190    virtual float captionFontSizeScale() const OVERRIDE;
     191    virtual String captionsStyleSheetOverride() const OVERRIDE;
     192    virtual void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
     193    virtual void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
     194#endif
    181195   
    182196    virtual bool shouldShowPlaceholderWhenFocused() const;
     
    238252#endif
    239253
     254#if ENABLE(VIDEO_TRACK)
     255    Color captionsWindowColor() const;
     256    Color captionsBackgroundColor() const;
     257    Color captionsTextColor() const;
     258    String captionsDefaultFont() const;
     259    Color captionsEdgeColorForTextColor(const Color&) const;
     260    String captionsTextEdgeStyle() const;
     261    String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&, const Color&) const;
     262    String cssColorProperty(CSSPropertyID, const Color&) const;
     263#endif
     264
    240265private:
    241266    mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
     
    253278
    254279    RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
     280
     281#if ENABLE(VIDEO_TRACK)
     282    HashSet<CaptionPreferencesChangedListener*> m_captionPreferenceChangeListeners;
     283    bool m_listeningForCaptionPreferenceNotifications;
     284#endif
    255285};
    256286
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r126926 r130556  
    2828#import "Element.h"
    2929#import "FileList.h"
     30#import "FloatConversion.h"
    3031#import "FrameView.h"
    3132#import "GraphicsContextCG.h"
     
    152153#endif
    153154
     155static void userCaptionPreferencesChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void *, CFDictionaryRef)
     156{
     157    static_cast<RenderThemeMac*>(observer)->captionPreferencesChanged();
     158}
     159
    154160PassRefPtr<RenderTheme> RenderThemeMac::create()
    155161{
     
    161167    , m_isSliderThumbVerticalPressed(false)
    162168    , m_notificationObserver(AdoptNS, [[WebCoreRenderThemeNotificationObserver alloc] initWithTheme:this])
     169#if ENABLE(VIDEO_TRACK)
     170    , m_listeningForCaptionPreferenceNotifications(false)
     171#endif
    163172{
    164173    [[NSNotificationCenter defaultCenter] addObserver:m_notificationObserver.get()
     
    171180{
    172181    [[NSNotificationCenter defaultCenter] removeObserver:m_notificationObserver.get()];
     182
     183#if ENABLE(VIDEO_TRACK)
     184    if (m_listeningForCaptionPreferenceNotifications)
     185        CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, wkCaptionAppearanceGetSettingsChangedNotification(), NULL);
     186#endif
    173187}
    174188
     
    21292143}
    21302144
     2145#if ENABLE(VIDEO_TRACK)
     2146bool RenderThemeMac::userHasCaptionPreferences() const
     2147{
     2148    return wkCaptionAppearanceHasUserPreferences();
     2149}
     2150
     2151bool RenderThemeMac::userPrefersCaptions() const
     2152{
     2153    return wkCaptionAppearanceShowCaptionsWhenAvailable();
     2154}
     2155
     2156Color RenderThemeMac::captionsWindowColor() const
     2157{
     2158    RetainPtr<CGColorRef> color(AdoptCF, wkCaptionAppearanceCopyWindowColor());
     2159    Color windowColor(color.get());
     2160    if (!windowColor.isValid())
     2161        windowColor = Color::transparent;
     2162   
     2163    CGFloat opacity;
     2164    if (wkCaptionAppearanceGetWindowOpacity(&opacity))
     2165        return Color(windowColor.red(), windowColor.green(), windowColor.blue(), opacity * 255);
     2166   
     2167    if (!color)
     2168        return Color();
     2169
     2170    return windowColor;
     2171}
     2172
     2173Color RenderThemeMac::captionsBackgroundColor() const
     2174{
     2175    // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-past-nodes
     2176    // and webkit-media-text-track-future-nodes.
     2177    DEFINE_STATIC_LOCAL(Color, defaultBackgroundColor, (Color(0, 0, 0, 0.8 * 255)));
     2178
     2179    RetainPtr<CGColorRef> color(AdoptCF, wkCaptionAppearanceCopyBackgroundColor());
     2180    Color backgroundColor(color.get());
     2181    if (!backgroundColor.isValid()) {
     2182        backgroundColor = defaultBackgroundColor;
     2183    }
     2184
     2185    CGFloat opacity;
     2186    if (wkCaptionAppearanceGetBackgroundOpacity(&opacity))
     2187        return Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), opacity * 255);
     2188
     2189    if (!color)
     2190        return Color();
     2191   
     2192    return backgroundColor;
     2193}
     2194
     2195Color RenderThemeMac::captionsTextColor() const
     2196{
     2197    RetainPtr<CGColorRef> color(AdoptCF, wkCaptionAppearanceCopyForegroundColor());
     2198    Color textColor(color.get());
     2199    if (!textColor.isValid()) {
     2200        // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-container.
     2201        textColor = Color::white;
     2202    }
     2203   
     2204    CGFloat opacity;
     2205    if (wkCaptionAppearanceGetForegroundOpacity(&opacity))
     2206        return Color(textColor.red(), textColor.green(), textColor.blue(), opacity * 255);
     2207   
     2208    if (!color)
     2209        return Color();
     2210   
     2211    return textColor;
     2212}
     2213
     2214Color RenderThemeMac::captionsEdgeColorForTextColor(const Color& textColor) const
     2215{
     2216    int distanceFromWhite = differenceSquared(textColor, Color::white);
     2217    int distanceFromBlack = differenceSquared(textColor, Color::black);
     2218   
     2219    if (distanceFromWhite < distanceFromBlack)
     2220        return textColor.dark();
     2221   
     2222    return textColor.light();
     2223}
     2224
     2225String RenderThemeMac::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String& value, const Color& textColor) const
     2226{
     2227    StringBuilder builder;
     2228   
     2229    builder.append(getPropertyNameString(id));
     2230    builder.append(':');
     2231    builder.append(value);
     2232    builder.append(' ');
     2233    builder.append(captionsEdgeColorForTextColor(textColor).serialized());
     2234    builder.append(';');
     2235
     2236    return builder.toString();
     2237}
     2238   
     2239String RenderThemeMac::cssColorProperty(CSSPropertyID id, const Color& color) const
     2240{
     2241    StringBuilder builder;
     2242   
     2243    builder.append(getPropertyNameString(id));
     2244    builder.append(':');
     2245    builder.append(color.serialized());
     2246    builder.append(';');
     2247   
     2248    return builder.toString();
     2249}
     2250
     2251String RenderThemeMac::captionsTextEdgeStyle() const
     2252{
     2253    DEFINE_STATIC_LOCAL(const String, edgeStyleRaised, (" -.05em -.05em 0 ", String::ConstructFromLiteral));
     2254    DEFINE_STATIC_LOCAL(const String, edgeStyleDepressed, (" .05em .05em 0 ", String::ConstructFromLiteral));
     2255    DEFINE_STATIC_LOCAL(const String, edgeStyleDropShadow, (" .075em .075em 0 ", String::ConstructFromLiteral));
     2256    DEFINE_STATIC_LOCAL(const String, edgeStyleUniform, (" .03em ", String::ConstructFromLiteral));
     2257
     2258    Color color = captionsTextColor();
     2259    if (!color.isValid())
     2260        color.setNamedColor("black");
     2261    color = captionsEdgeColorForTextColor(color);
     2262
     2263    wkCaptionTextEdgeStyle textEdgeStyle = static_cast<wkCaptionTextEdgeStyle>(wkCaptionAppearanceGetTextEdgeStyle());
     2264    switch (textEdgeStyle) {
     2265    case wkCaptionTextEdgeStyleUndefined:
     2266    case wkCaptionTextEdgeStyleNone:
     2267        return emptyString();
     2268
     2269    case wkCaptionTextEdgeStyleRaised:
     2270        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color);
     2271    case wkCaptionTextEdgeStyleDepressed:
     2272        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color);
     2273    case wkCaptionTextEdgeStyleDropShadow:
     2274        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color);
     2275    case wkCaptionTextEdgeStyleUniform:
     2276        return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, edgeStyleUniform, color);
     2277
     2278    case wkCaptionTextEdgeStyleMax:
     2279        ASSERT_NOT_REACHED();
     2280    default:
     2281        ASSERT_NOT_REACHED();
     2282        break;
     2283    }
     2284
     2285    return emptyString();
     2286}
     2287
     2288String RenderThemeMac::captionsDefaultFont() const
     2289{
     2290    RetainPtr<CGFontRef> font(AdoptCF, wkCaptionAppearanceCopyFontForStyle(wkCaptionFontStyleDefault));
     2291    if (!font)
     2292        return emptyString();
     2293
     2294    RetainPtr<CFStringRef> name(AdoptCF, CGFontCopyPostScriptName(font.get()));
     2295    if (!name)
     2296        return emptyString();
     2297
     2298    StringBuilder builder;
     2299   
     2300    builder.append(getPropertyNameString(CSSPropertyFontFamily));
     2301    builder.append(": \"");
     2302    builder.append(name.get());
     2303    builder.append("\";");
     2304   
     2305    return builder.toString();
     2306}
     2307
     2308String RenderThemeMac::captionsStyleSheetOverride() const
     2309{
     2310    StringBuilder captionsOverrideStyleSheet;
     2311
     2312    Color color = captionsBackgroundColor();
     2313    if (color.isValid()) {
     2314        captionsOverrideStyleSheet.append(" video::");
     2315        captionsOverrideStyleSheet.append(TextTrackCue::pastNodesShadowPseudoId());
     2316        captionsOverrideStyleSheet.append('{');
     2317        captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
     2318        captionsOverrideStyleSheet.append('}');
     2319
     2320        captionsOverrideStyleSheet.append(" video::");
     2321        captionsOverrideStyleSheet.append(TextTrackCue::futureNodesShadowPseudoId());
     2322        captionsOverrideStyleSheet.append('{');
     2323        captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
     2324        captionsOverrideStyleSheet.append('}');
     2325    }
     2326
     2327    color = captionsWindowColor();
     2328    if (color.isValid()) {
     2329        captionsOverrideStyleSheet.append(" video::");
     2330        captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId());
     2331        captionsOverrideStyleSheet.append('{');
     2332        captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
     2333        captionsOverrideStyleSheet.append('}');
     2334    }
     2335
     2336    color = captionsTextColor();
     2337    String edgeStyle = captionsTextEdgeStyle();
     2338    String fontName = captionsDefaultFont();
     2339    if (color.isValid() || !edgeStyle.isEmpty() || !fontName.isEmpty()) {
     2340        captionsOverrideStyleSheet.append(" video::");
     2341        captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId());
     2342        captionsOverrideStyleSheet.append('{');
     2343
     2344        if (color.isValid())
     2345            captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyColor, color));
     2346        if (!edgeStyle.isEmpty())
     2347            captionsOverrideStyleSheet.append(edgeStyle);
     2348        if (!fontName.isEmpty())
     2349            captionsOverrideStyleSheet.append(fontName);
     2350
     2351        captionsOverrideStyleSheet.append('}');
     2352    }
     2353
     2354    return captionsOverrideStyleSheet.toString();
     2355}
     2356
     2357float RenderThemeMac::captionFontSizeScale() const
     2358{
     2359    CGFloat characterScale = RenderTheme::captionFontSizeScale();
     2360    CGFloat scaleAdjustment;
     2361   
     2362    if (!wkCaptionAppearanceGetRelativeCharacterSize(&scaleAdjustment))
     2363        return characterScale;
     2364   
     2365    return narrowPrecisionToFloat(scaleAdjustment * characterScale);
     2366}
     2367
     2368void RenderThemeMac::captionPreferencesChanged()
     2369{
     2370    for (HashSet<CaptionPreferencesChangedListener*>::iterator i = m_captionPreferenceChangeListeners.begin(); i != m_captionPreferenceChangeListeners.end(); ++i)
     2371        (*i)->captionPreferencesChanged();
     2372}
     2373
     2374void RenderThemeMac::registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
     2375{
     2376    if (!wkCaptionAppearanceGetSettingsChangedNotification())
     2377        return;
     2378   
     2379    if (!m_listeningForCaptionPreferenceNotifications) {
     2380        m_listeningForCaptionPreferenceNotifications = true;
     2381        CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, wkCaptionAppearanceGetSettingsChangedNotification(), NULL, CFNotificationSuspensionBehaviorCoalesce);
     2382    }
     2383   
     2384    m_captionPreferenceChangeListeners.add(listener);
     2385}
     2386   
     2387void RenderThemeMac::unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
     2388{
     2389     if (wkCaptionAppearanceGetSettingsChangedNotification())
     2390        m_captionPreferenceChangeListeners.remove(listener);
     2391}
     2392#endif // ENABLE(VIDEO_TRACK)
     2393
    21312394#endif // ENABLE(VIDEO)
    21322395
  • trunk/Source/WebKit/mac/ChangeLog

    r130523 r130556  
     12012-10-04  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Allow ports to override text track rendering style
     4        https://bugs.webkit.org/show_bug.cgi?id=97800
     5        <rdar://problem/12044964>
     6
     7        Reviewed by Silvia Pfeiffer.
     8
     9        Add WCSI support for new WKSI caption functions.
     10
     11        * WebCoreSupport/WebSystemInterface.mm:
     12        (InitWebCoreSystemInterface): Initialize new WKSI function pointers.
     13
    1142012-10-04  Jon Lee  <jonlee@apple.com>
    215
  • trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm

    r129566 r130556  
    206206#endif
    207207
     208    INIT(CaptionAppearanceHasUserPreferences);
     209    INIT(CaptionAppearanceShowCaptionsWhenAvailable);
     210    INIT(CaptionAppearanceCopyForegroundColor);
     211    INIT(CaptionAppearanceCopyBackgroundColor);
     212    INIT(CaptionAppearanceCopyWindowColor);
     213    INIT(CaptionAppearanceGetForegroundOpacity);
     214    INIT(CaptionAppearanceGetBackgroundOpacity);
     215    INIT(CaptionAppearanceGetWindowOpacity);
     216    INIT(CaptionAppearanceCopyFontForStyle);
     217    INIT(CaptionAppearanceGetRelativeCharacterSize);
     218    INIT(CaptionAppearanceGetTextEdgeStyle);
     219    INIT(CaptionAppearanceGetSettingsChangedNotification);
     220
    208221#endif
    209222    didInit = true;
  • trunk/Source/WebKit2/ChangeLog

    r130525 r130556  
     12012-10-04  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Allow ports to override text track rendering style
     4        https://bugs.webkit.org/show_bug.cgi?id=97800
     5        <rdar://problem/12044964>
     6
     7        Reviewed by Silvia Pfeiffer.
     8
     9        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
     10        (InitWebCoreSystemInterface): Initialize new WKSI function pointers.
     11
    1122012-10-05  José Dapena Paz  <jdapena@igalia.com>
    213
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

    r129566 r130556  
    187187#endif
    188188
     189        INIT(CaptionAppearanceHasUserPreferences);
     190        INIT(CaptionAppearanceShowCaptionsWhenAvailable);
     191        INIT(CaptionAppearanceCopyForegroundColor);
     192        INIT(CaptionAppearanceCopyBackgroundColor);
     193        INIT(CaptionAppearanceCopyWindowColor);
     194        INIT(CaptionAppearanceGetForegroundOpacity);
     195        INIT(CaptionAppearanceGetBackgroundOpacity);
     196        INIT(CaptionAppearanceGetWindowOpacity);
     197        INIT(CaptionAppearanceCopyFontForStyle);
     198        INIT(CaptionAppearanceGetRelativeCharacterSize);
     199        INIT(CaptionAppearanceGetTextEdgeStyle);
     200        INIT(CaptionAppearanceGetSettingsChangedNotification);
    189201    });
    190202}
  • trunk/WebKitLibraries/ChangeLog

    r129917 r130556  
     12012-10-04  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Allow ports to override text track rendering style
     4        https://bugs.webkit.org/show_bug.cgi?id=97800
     5        <rdar://problem/12044964>
     6
     7        Reviewed by Silvia Pfeiffer.
     8
     9        Update WKSI header with SPI for getting the user caption appearance preferences.
     10
     11        * WebKitSystemInterface.h:
     12
    1132012-09-28  Eric Carlson  <eric.carlson@apple.com>
    214
  • trunk/WebKitLibraries/WebKitSystemInterface.h

    r129565 r130556  
    11/*     
    22    WebKitSystemInterface.h
    3     Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
     3    Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
    44
    55    Public header file.
     
    510510#endif
    511511
     512typedef enum {
     513    WKCaptionFontStyleDefault = 0,
     514    WKCaptionFontStyleMonospacedWithSerif,
     515    WKCaptionFontStyleProportionalWithSerif,
     516    WKCaptionFontStyleMonospacedWithoutSerif,
     517    WKCaptionFontStyleProportionalWithoutSerif,
     518    WKCaptionFontStyleCasual,
     519    WKCaptionFontStyleCursive,
     520    WKCaptionFontStyleSmallCapital,
     521    WKCaptionFontStyleMax
     522} WKCaptionFontStyle;
     523
     524typedef enum {
     525    WKCaptionTextEdgeStyleUndefined = 0,
     526    WKCaptionTextEdgeStyleNone,
     527    WKCaptionTextEdgeStyleRaised,
     528    WKCaptionTextEdgeStyleDepressed,
     529    WKCaptionTextEdgeStyleUniform,
     530    WKCaptionTextEdgeStyleDropShadow,
     531    WKCaptionTextEdgeStyleMax
     532} WKCaptionTextEdgeStyle;
     533
     534bool WKCaptionAppearanceHasUserPreferences(void);
     535bool WKCaptionAppearanceShowCaptionsWhenAvailable(void);
     536CGColorRef WKCaptionAppearanceCopyForegroundColor(void);
     537CGColorRef WKCaptionAppearanceCopyBackgroundColor(void);
     538CGColorRef WKCaptionAppearanceCopyWindowColor(void);
     539bool WKCaptionAppearanceGetForegroundOpacity(CGFloat*);
     540bool WKCaptionAppearanceGetBackgroundOpacity(CGFloat*);
     541bool WKCaptionAppearanceGetWindowOpacity(CGFloat*);
     542CGFontRef WKCaptionAppearanceCopyFontForStyle(int fontStyle);
     543bool WKCaptionAppearanceGetRelativeCharacterSize(CGFloat*);
     544int WKCaptionAppearanceGetTextEdgeStyle(void);
     545CFStringRef WKCaptionAppearanceGetSettingsChangedNotification(void);
     546
    512547#ifdef __cplusplus
    513548}
Note: See TracChangeset for help on using the changeset viewer.