Allow ports to override text track rendering style

https://bugs.webkit.org/show_bug.cgi?id=97800
<rdar://problem/12044964>

Reviewed by Maciej Stachowiak.

Source/WebCore:

* WebCore.exp.in: Export new WebkitSystemInterface functions.
* WebCore.xcodeproj/project.pbxproj: Add CaptionUserPreferences.h, CaptionUserPreferencesMac.mm,
    and CaptionUserPreferencesMac.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::updateSizes): Get rid of unnecessary member
    variable. Get caption font scale from theme instead of hard coding.
* html/shadow/MediaControlElements.h:

* html/track/TextTrack.cpp:
(WebCore::TextTrack::TextTrack): Change attributes from String to AtomicString.
(WebCore::TextTrack::isValidKindKeyword): Ditto.
(WebCore::TextTrack::setKind): Ditto.
(WebCore::TextTrack::setMode): Ditto.
(WebCore::TextTrack::mode): Ditto.
* html/track/TextTrack.h:
(WebCore::TextTrack::create): Ditto.
(WebCore::TextTrack::kind): Ditto.
(WebCore::TextTrack::label): Ditto.
(WebCore::TextTrack::setLabel): Ditto.
(WebCore::TextTrack::language): Ditto.
(WebCore::TextTrack::setLanguage): Ditto.

* 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:

* page/CaptionUserPreferences.h: Added.
* page/CaptionUserPreferencesMac.h: Added.
* page/CaptionUserPreferencesMac.mm: Added.
(WebCore::userCaptionPreferencesChangedNotificationCallback):
(WebCore::CaptionUserPreferencesMac::CaptionUserPreferencesMac):
(WebCore::CaptionUserPreferencesMac::~CaptionUserPreferencesMac):
(WebCore::CaptionUserPreferencesMac::userHasCaptionPreferences): New, passthrough to WKSI function.
(WebCore::CaptionUserPreferencesMac::userPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferencesMac::captionsWindowColor): Return Color with user's caption window color preference.
(WebCore::CaptionUserPreferencesMac::captionsBackgroundColor): Return Color with user's caption
    background color preference.
(WebCore::CaptionUserPreferencesMac::captionsTextColor): Return Color with user's caption text color preference.
(WebCore::CaptionUserPreferencesMac::captionsEdgeColorForTextColor): Return Color for text edge effect.
(WebCore::CaptionUserPreferencesMac::cssPropertyWithTextEdgeColor): Return String with CSS to set a text-shadow
    or webkit-text-stroke property.
(WebCore::CaptionUserPreferencesMac::cssColorProperty): Return a String with css to set a property
    with a color value.
(WebCore::CaptionUserPreferencesMac::captionsTextEdgeStyle): Return a String with css to style caption
    text with the user's preferred text edge stye.
(WebCore::CaptionUserPreferencesMac::captionsDefaultFont): Return a String with css to style caption
    text with the user's preferred font.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Return a String with css to style captions
    with the user's preferred style.
(WebCore::CaptionUserPreferencesMac::captionFontSizeScale): Return the user's preferred caption font scale.
(WebCore::CaptionUserPreferencesMac::captionPreferencesChanged): Notify listeners of caption preference change.
(WebCore::CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks): Add a caption preferences
    changes listener.
(WebCore::CaptionUserPreferencesMac::unregisterForCaptionPreferencesChangedCallbacks): Remove a caption preferences
    changes listener.
(WebCore::CaptionUserPreferencesMac::updateCaptionStyleSheetOveride): New, if theme has a captions style sheet override,
    inject it into the current page group, otherwise remove injected sheet.

* page/PageGroup.cpp:
(WebCore::PageGroup::captionPreferences):
(WebCore::PageGroup::registerForCaptionPreferencesChangedCallbacks): New, passthrough to platform specific function
    of the same name.
(WebCore::PageGroup::unregisterForCaptionPreferencesChangedCallbacks): Ditto.
(WebCore::PageGroup::userPrefersCaptions): Ditto.
(WebCore::PageGroup::userHasCaptionPreferences): Ditto.
(WebCore::PageGroup::captionFontSizeScale): Ditto.
* page/PageGroup.h:

* platform/mac/WebCoreSystemInterface.h: Updated.
* platform/mac/WebCoreSystemInterface.mm: Ditto.

Source/WebKit/mac:

* 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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@132349 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 26d8856e
2012-10-24 Eric Carlson <eric.carlson@apple.com>
Allow ports to override text track rendering style
https://bugs.webkit.org/show_bug.cgi?id=97800
<rdar://problem/12044964>
Reviewed by Maciej Stachowiak.
* 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.
2012-10-24 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Introduce workspace provider as a content providing backend for project.
......@@ -49,7 +49,7 @@ RUN(video.height = 1440)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '72px') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontFamily == 'sans-serif') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).color == 'rgba(255, 255, 255, 0)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).color == 'rgb(255, 255, 255)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor == 'rgba(0, 0, 0, 0.796875)'), OBSERVED 'rgba(0, 0, 0, 0.8)' FAIL
END OF TEST
......@@ -32,7 +32,7 @@
testFontSize(2560, 1440);
testExpected("getComputedStyle(textTrackDisplayElement(video)).fontFamily", "sans-serif");
testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgba(255, 255, 255, 0)");
testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgb(255, 255, 255)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.796875)");
endTest();
......
......@@ -3984,6 +3984,11 @@ webkit.org/b/95121 fast/borders/border-image-side-reduction.html [ ImageOnlyFail
# css3-conditionals support is not yet enabled.
webkit.org/b/86146 css3/supports.html
# Require rebaselining after webkit.org/b/97800
webkit.org/b/89167 media/track/track-cue-rendering-horizontal.html [ Failure ]
webkit.org/b/89167 media/track/track-cue-rendering-vertical.html [ Failure ]
webkit.org/b/89167 media/track/track-cue-rendering.html [ Failure ]
webkit.org/b/98686 editing/pasteboard/data-transfer-items.html [ Failure ]
webkit.org/b/23166 [ Android Mac Win ] fast/css/background-clip-radius-values.html [ Pass ImageOnlyFailure ]
......
2012-10-24 Eric Carlson <eric.carlson@apple.com>
Allow ports to override text track rendering style
https://bugs.webkit.org/show_bug.cgi?id=97800
<rdar://problem/12044964>
Reviewed by Maciej Stachowiak.
* WebCore.exp.in: Export new WebkitSystemInterface functions.
* WebCore.xcodeproj/project.pbxproj: Add CaptionUserPreferences.h, CaptionUserPreferencesMac.mm,
and CaptionUserPreferencesMac.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::updateSizes): Get rid of unnecessary member
variable. Get caption font scale from theme instead of hard coding.
* html/shadow/MediaControlElements.h:
* html/track/TextTrack.cpp:
(WebCore::TextTrack::TextTrack): Change attributes from String to AtomicString.
(WebCore::TextTrack::isValidKindKeyword): Ditto.
(WebCore::TextTrack::setKind): Ditto.
(WebCore::TextTrack::setMode): Ditto.
(WebCore::TextTrack::mode): Ditto.
* html/track/TextTrack.h:
(WebCore::TextTrack::create): Ditto.
(WebCore::TextTrack::kind): Ditto.
(WebCore::TextTrack::label): Ditto.
(WebCore::TextTrack::setLabel): Ditto.
(WebCore::TextTrack::language): Ditto.
(WebCore::TextTrack::setLanguage): Ditto.
* 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:
* page/CaptionUserPreferences.h: Added.
* page/CaptionUserPreferencesMac.h: Added.
* page/CaptionUserPreferencesMac.mm: Added.
(WebCore::userCaptionPreferencesChangedNotificationCallback):
(WebCore::CaptionUserPreferencesMac::CaptionUserPreferencesMac):
(WebCore::CaptionUserPreferencesMac::~CaptionUserPreferencesMac):
(WebCore::CaptionUserPreferencesMac::userHasCaptionPreferences): New, passthrough to WKSI function.
(WebCore::CaptionUserPreferencesMac::userPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferencesMac::captionsWindowColor): Return Color with user's caption window color preference.
(WebCore::CaptionUserPreferencesMac::captionsBackgroundColor): Return Color with user's caption
background color preference.
(WebCore::CaptionUserPreferencesMac::captionsTextColor): Return Color with user's caption text color preference.
(WebCore::CaptionUserPreferencesMac::captionsEdgeColorForTextColor): Return Color for text edge effect.
(WebCore::CaptionUserPreferencesMac::cssPropertyWithTextEdgeColor): Return String with CSS to set a text-shadow
or webkit-text-stroke property.
(WebCore::CaptionUserPreferencesMac::cssColorProperty): Return a String with css to set a property
with a color value.
(WebCore::CaptionUserPreferencesMac::captionsTextEdgeStyle): Return a String with css to style caption
text with the user's preferred text edge stye.
(WebCore::CaptionUserPreferencesMac::captionsDefaultFont): Return a String with css to style caption
text with the user's preferred font.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Return a String with css to style captions
with the user's preferred style.
(WebCore::CaptionUserPreferencesMac::captionFontSizeScale): Return the user's preferred caption font scale.
(WebCore::CaptionUserPreferencesMac::captionPreferencesChanged): Notify listeners of caption preference change.
(WebCore::CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks): Add a caption preferences
changes listener.
(WebCore::CaptionUserPreferencesMac::unregisterForCaptionPreferencesChangedCallbacks): Remove a caption preferences
changes listener.
(WebCore::CaptionUserPreferencesMac::updateCaptionStyleSheetOveride): New, if theme has a captions style sheet override,
inject it into the current page group, otherwise remove injected sheet.
* page/PageGroup.cpp:
(WebCore::PageGroup::captionPreferences):
(WebCore::PageGroup::registerForCaptionPreferencesChangedCallbacks): New, passthrough to platform specific function
of the same name.
(WebCore::PageGroup::unregisterForCaptionPreferencesChangedCallbacks): Ditto.
(WebCore::PageGroup::userPrefersCaptions): Ditto.
(WebCore::PageGroup::userHasCaptionPreferences): Ditto.
(WebCore::PageGroup::captionFontSizeScale): Ditto.
* page/PageGroup.h:
* platform/mac/WebCoreSystemInterface.h: Updated.
* platform/mac/WebCoreSystemInterface.mm: Ditto.
2012-10-24 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Introduce workspace provider as a content providing backend for project.
......@@ -2625,3 +2625,18 @@ __ZN7WebCore27AlternativeTextUIController16showAlternativesEP6NSViewRKNS_9FloatR
__ZN7WebCore24TextAlternativeWithRangeC1EP18NSTextAlternatives8_NSRange
__ZN7WebCore32collectDictationTextAlternativesEP18NSAttributedStringRN3WTF6VectorINS_24TextAlternativeWithRangeELm0EEE
#endif
#if ENABLE(VIDEO_TRACK)
_wkCaptionAppearanceHasUserPreferences
_wkCaptionAppearanceShowCaptionsWhenAvailable
_wkCaptionAppearanceCopyForegroundColor
_wkCaptionAppearanceCopyBackgroundColor
_wkCaptionAppearanceCopyWindowColor
_wkCaptionAppearanceGetForegroundOpacity
_wkCaptionAppearanceGetBackgroundOpacity
_wkCaptionAppearanceGetWindowOpacity
_wkCaptionAppearanceCopyFontForStyle
_wkCaptionAppearanceGetRelativeCharacterSize
_wkCaptionAppearanceGetTextEdgeStyle
_wkCaptionAppearanceGetSettingsChangedNotification
#endif
......@@ -122,6 +122,9 @@
07846342145B151A00A58DF1 /* JSTrackEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07846340145B151A00A58DF1 /* JSTrackEvent.cpp */; };
07846343145B151A00A58DF1 /* JSTrackEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 07846341145B151A00A58DF1 /* JSTrackEvent.h */; };
07846385145B1B8E00A58DF1 /* JSTrackCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 07846384145B1B8E00A58DF1 /* JSTrackCustom.h */; };
079D0868162F20E800DB8658 /* CaptionUserPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = 079D0867162F20E800DB8658 /* CaptionUserPreferences.h */; settings = {ATTRIBUTES = (Private, ); }; };
079D086B162F21F900DB8658 /* CaptionUserPreferencesMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 079D0869162F21F900DB8658 /* CaptionUserPreferencesMac.h */; };
079D086C162F21F900DB8658 /* CaptionUserPreferencesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 079D086A162F21F900DB8658 /* CaptionUserPreferencesMac.mm */; };
07A6D1EB1491137700051D0C /* MediaFragmentURIParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07A6D1E91491137700051D0C /* MediaFragmentURIParser.cpp */; };
07A6D1EC1491137700051D0C /* MediaFragmentURIParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 07A6D1EA1491137700051D0C /* MediaFragmentURIParser.h */; };
07B0113F1032242200FBDC33 /* AccessibilityMediaControls.h in Headers */ = {isa = PBXBuildFile; fileRef = 07B0113E1032242200FBDC33 /* AccessibilityMediaControls.h */; };
......@@ -7162,6 +7165,9 @@
07846340145B151A00A58DF1 /* JSTrackEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTrackEvent.cpp; sourceTree = "<group>"; };
07846341145B151A00A58DF1 /* JSTrackEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTrackEvent.h; sourceTree = "<group>"; };
07846384145B1B8E00A58DF1 /* JSTrackCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTrackCustom.h; sourceTree = "<group>"; };
079D0867162F20E800DB8658 /* CaptionUserPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CaptionUserPreferences.h; sourceTree = "<group>"; };
079D0869162F21F900DB8658 /* CaptionUserPreferencesMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CaptionUserPreferencesMac.h; sourceTree = "<group>"; };
079D086A162F21F900DB8658 /* CaptionUserPreferencesMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CaptionUserPreferencesMac.mm; sourceTree = "<group>"; };
079F5E4B0F3BEBEA005E0782 /* MediaPlayerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivate.h; sourceTree = "<group>"; };
07A6D1E91491137700051D0C /* MediaFragmentURIParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaFragmentURIParser.cpp; sourceTree = "<group>"; };
07A6D1EA1491137700051D0C /* MediaFragmentURIParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaFragmentURIParser.h; sourceTree = "<group>"; };
......@@ -15801,6 +15807,9 @@
BC124EE40C2641CD009E2349 /* BarInfo.cpp */,
BC124EE50C2641CD009E2349 /* BarInfo.h */,
BC124EE60C2641CD009E2349 /* BarInfo.idl */,
079D0867162F20E800DB8658 /* CaptionUserPreferences.h */,
079D0869162F21F900DB8658 /* CaptionUserPreferencesMac.h */,
079D086A162F21F900DB8658 /* CaptionUserPreferencesMac.mm */,
14D8238A0AF92DF60004F057 /* Chrome.cpp */,
14D823500AF92A790004F057 /* Chrome.h */,
14D824060AF93AEB0004F057 /* ChromeClient.h */,
......@@ -22524,6 +22533,8 @@
49C7B9DD1042D32F0009D447 /* CanvasRenderingContext.h in Headers */,
49484FCB102CF23C00187DD3 /* CanvasRenderingContext2D.h in Headers */,
49484FCE102CF23C00187DD3 /* CanvasStyle.h in Headers */,
079D0868162F20E800DB8658 /* CaptionUserPreferences.h in Headers */,
079D086B162F21F900DB8658 /* CaptionUserPreferencesMac.h in Headers */,
6550B69E099DF0270090D781 /* CDATASection.h in Headers */,
97BC69DD1505F076001B74AC /* ChangeVersionWrapper.h in Headers */,
FD315FFF12B0267600C1A359 /* ChannelMergerNode.h in Headers */,
......@@ -26145,6 +26156,7 @@
49C7B9DC1042D32F0009D447 /* CanvasRenderingContext.cpp in Sources */,
49484FCA102CF23C00187DD3 /* CanvasRenderingContext2D.cpp in Sources */,
49484FCD102CF23C00187DD3 /* CanvasStyle.cpp in Sources */,
079D086C162F21F900DB8658 /* CaptionUserPreferencesMac.mm in Sources */,
6550B69D099DF0270090D781 /* CDATASection.cpp in Sources */,
97BC69DC1505F076001B74AC /* ChangeVersionWrapper.cpp in Sources */,
FD315FFE12B0267600C1A359 /* ChannelMergerNode.cpp in Sources */,
......@@ -216,7 +216,7 @@ video::-webkit-media-text-track-container {
font-size: 22px;
font-family: sans-serif;
text-align: center;
color: rgba(255, 255, 255, 0);
color: rgba(255, 255, 255, 1);
letter-spacing: normal;
word-spacing: normal;
......@@ -234,8 +234,6 @@ video::-webkit-media-text-track-past-nodes {
background-color: rgba(0, 0, 0, 0.8);
padding: 2px 2px;
white-space: pre-wrap;
}
video::-webkit-media-text-track-future-nodes {
......@@ -246,11 +244,10 @@ video::-webkit-media-text-track-future-nodes {
margin-left: -2px;
padding: 2px 2px 2px 0px;
white-space: pre-wrap;
}
video::-webkit-media-text-track-display {
position: absolute;
color: rgba(255, 255, 255, 1);
overflow: hidden;
white-space: pre-wrap;
}
......@@ -69,6 +69,7 @@
#include "MIMETypeRegistry.h"
#include "NodeRenderingContext.h"
#include "Page.h"
#include "PageGroup.h"
#include "RenderVideo.h"
#include "RenderView.h"
#include "ScriptController.h"
......@@ -281,6 +282,14 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
setHasCustomCallbacks();
addElementToDocumentMap(this, document);
#if ENABLE(VIDEO_TRACK)
if (document->page()) {
PageGroup& group = document->page()->group();
if (group.userHasCaptionPreferences())
m_disableCaptions = !group.userPrefersCaptions();
}
#endif
}
HTMLMediaElement::~HTMLMediaElement()
......@@ -541,6 +550,20 @@ void HTMLMediaElement::attach()
frame->loader()->client()->hideMediaPlayerProxyPlugin(m_proxyWidget.get());
}
#endif
#if ENABLE(VIDEO_TRACK)
if (document()->page())
document()->page()->group().registerForCaptionPreferencesChangedCallbacks(this);
#endif
}
void HTMLMediaElement::detach()
{
#if ENABLE(VIDEO_TRACK)
if (document()->page())
document()->page()->group().unregisterForCaptionPreferencesChangedCallbacks(this);
#endif
HTMLElement::detach();
}
void HTMLMediaElement::didRecalcStyle(StyleChange)
......@@ -2812,28 +2835,30 @@ void HTMLMediaElement::willRemoveTrack(HTMLTrackElement* trackElement)
m_textTracksWhenResourceSelectionBegan.remove(index);
}
bool HTMLMediaElement::userIsInterestedInThisLanguage(const String&) const
bool HTMLMediaElement::userPrefersCaptions() const
{
// FIXME: check the user's language preference - bugs.webkit.org/show_bug.cgi?id=74121
return true;
Page* page = document()->page();
if (!page)
return false;
PageGroup& group = page->group();
return group.userHasCaptionPreferences() && group.userPrefersCaptions();
}
bool HTMLMediaElement::userIsInterestedInThisTrackKind(String kind) const
{
// If ... the user has indicated an interest in having a track with this text track kind, text track language, ...
if (m_disableCaptions)
return false;
Settings* settings = document()->settings();
if (!settings)
return false;
bool userPrefersCaptionsOrSubtitles = m_closedCaptionsVisible || userPrefersCaptions();
if (kind == TextTrack::subtitlesKeyword())
return settings->shouldDisplaySubtitles() || m_closedCaptionsVisible;
return (settings && settings->shouldDisplaySubtitles()) || userPrefersCaptionsOrSubtitles;
if (kind == TextTrack::captionsKeyword())
return settings->shouldDisplayCaptions() || m_closedCaptionsVisible;
return (settings && settings->shouldDisplayCaptions()) || userPrefersCaptionsOrSubtitles;
if (kind == TextTrack::descriptionsKeyword())
return settings->shouldDisplayTextDescriptions() || m_closedCaptionsVisible;
return settings && settings->shouldDisplayTextDescriptions();
return false;
}
......@@ -3998,22 +4023,8 @@ void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
#if ENABLE(VIDEO_TRACK)
if (RuntimeEnabledFeatures::webkitVideoTrackEnabled()) {
m_disableCaptions = !m_closedCaptionsVisible;
// Mark all track elements as not "configured" so that configureTextTracks()
// will reconsider which tracks to display in light of new user preferences
// (e.g. default tracks should not be displayed if the user has turned off
// captions and non-default tracks should be displayed based on language
// preferences if the user has turned captions on).
for (Node* node = firstChild(); node; node = node->nextSibling()) {
if (!node->hasTagName(trackTag))
continue;
HTMLTrackElement* trackElement = static_cast<HTMLTrackElement*>(node);
if (trackElement->kind() == TextTrack::captionsKeyword()
|| trackElement->kind() == TextTrack::subtitlesKeyword())
trackElement->setHasBeenConfigured(false);
}
configureTextTracks();
markCaptionAndSubtitleTracksAsUnconfigured();
}
#else
if (hasMediaControls())
......@@ -4201,6 +4212,39 @@ void HTMLMediaElement::updateClosedCaptionsControls()
mediaControls()->updateTextTrackDisplay();
}
}
void HTMLMediaElement::captionPreferencesChanged()
{
if (!isVideo())
return;
markCaptionAndSubtitleTracksAsUnconfigured();
}
void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured()
{
// Mark all track elements as not "configured" so that configureTextTracks()
// will reconsider which tracks to display in light of new user preferences
// (e.g. default tracks should not be displayed if the user has turned off
// captions and non-default tracks should be displayed based on language
// preferences if the user has turned captions on).
for (RefPtr<Node> node = firstChild(); node; node = node->nextSibling()) {
if (!node->hasTagName(trackTag))
continue;
HTMLTrackElement* trackElement = static_cast<HTMLTrackElement*>(node.get());
RefPtr<TextTrack> textTrack = trackElement->track();
if (!textTrack)
continue;
String kind = textTrack->kind();
if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captionsKeyword())
trackElement->setHasBeenConfigured(false);
}
configureTextTracks();
}
#endif
void* HTMLMediaElement::preDispatchEventHandler(Event* event)
......
......@@ -40,6 +40,7 @@
#endif
#if ENABLE(VIDEO_TRACK)
#include "CaptionUserPreferences.h"
#include "PODIntervalTree.h"
#include "TextTrack.h"
#include "TextTrackCue.h"
......@@ -78,7 +79,7 @@ typedef Vector<CueIntervalTree::IntervalType> CueList;
class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, public MediaPlayerSupportsTypeClient, private MediaCanStartListener, public ActiveDOMObject, public MediaControllerInterface
#if ENABLE(VIDEO_TRACK)
, private TextTrackClient
, private TextTrackClient, private CaptionPreferencesChangedListener
#endif
{
public:
......@@ -240,6 +241,7 @@ public:
void configureTextTracks();
void configureTextTrackGroup(const TrackGroup&) const;
bool userPrefersCaptions() const;
bool userIsInterestedInThisTrackKind(String) const;
bool textTracksAreReady() const;
void configureTextTrackDisplay();
......@@ -325,7 +327,8 @@ protected:
virtual void parseAttribute(const Attribute&) OVERRIDE;
virtual void finishParsingChildren();
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual void attach();
virtual void attach() OVERRIDE;
virtual void detach() OVERRIDE;
virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
......@@ -474,12 +477,14 @@ private:
#if ENABLE(VIDEO_TRACK)
void updateActiveTextTrackCues(float);
bool userIsInterestedInThisLanguage(const String&) const;
HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
bool ignoreTrackDisplayUpdateRequests() const { return m_ignoreTrackDisplayUpdate > 0; }
void beginIgnoringTrackDisplayUpdateRequests() { ++m_ignoreTrackDisplayUpdate; }
void endIgnoringTrackDisplayUpdateRequests() { ASSERT(m_ignoreTrackDisplayUpdate); --m_ignoreTrackDisplayUpdate; }
void markCaptionAndSubtitleTracksAsUnconfigured();
virtual void captionPreferencesChanged() OVERRIDE;
#endif
// These "internal" functions do not check user gesture restrictions.
......
......@@ -45,9 +45,11 @@
#include "HTMLVideoElement.h"
#include "LayoutRepainter.h"
#include "LocalizedStrings.h"
#include "MediaControlRootElement.h"
#include "MediaControls.h"
#include "MouseEvent.h"
#include "Page.h"
#include "PageGroup.h"
#include "RenderDeprecatedFlexibleBox.h"
#include "RenderInline.h"
#include "RenderMedia.h"
......@@ -1383,22 +1385,18 @@ void MediaControlTextTrackContainerElement::updateDisplay()
hasChildNodes() ? show() : hide();
}
static const float mimimumFontSize = 16;
static const float videoHeightFontSizePercentage = .05;
static const float trackBottomMultiplier = .9;
void MediaControlTextTrackContainerElement::updateSizes()
{
HTMLMediaElement* mediaElement = toParentMediaElement(this);
if (!mediaElement || !mediaElement->renderer() || !mediaElement->renderer()->isVideo())
return;
IntRect videoBox = toRenderVideo(mediaElement->renderer())->videoBox();
if (m_videoDisplaySize == videoBox)
if (!document()->page())
return;
m_videoDisplaySize = videoBox;
float fontSize = m_videoDisplaySize.size().height() * videoHeightFontSizePercentage;
IntRect videoBox = toRenderVideo(mediaElement->renderer())->videoBox();
float fontSize = videoBox.size().height() * (document()->page()->group().captionFontSizeScale());
if (fontSize != m_fontSize) {
m_fontSize = fontSize;
setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
......
......@@ -94,7 +94,7 @@ const AtomicString& TextTrack::showingKeyword()
return ended;
}
TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const String& kind, const String& label, const String& language, TextTrackType type)
TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const AtomicString& kind, const AtomicString& label, const AtomicString& language, TextTrackType type)
: TrackBase(context, TrackBase::TextTrack)
, m_cues(0)
, m_mediaElement(0)
......@@ -117,7 +117,7 @@ TextTrack::~TextTrack()
clearClient();
}
bool TextTrack::isValidKindKeyword(const String& value)
bool TextTrack::isValidKindKeyword(const AtomicString& value)
{
if (equalIgnoringCase(value, subtitlesKeyword()))
return true;
......@@ -133,7 +133,7 @@ bool TextTrack::isValidKindKeyword(const String& value)
return false;
}
void TextTrack::setKind(const String& kind)
void TextTrack::setKind(const AtomicString& kind)
{
String oldKind = m_kind;
......@@ -146,7 +146,7 @@ void TextTrack::setKind(const String& kind)
m_client->textTrackKindChanged(this);
}
void TextTrack::setMode(const String& mode)
void TextTrack::setMode(const AtomicString& mode)
{
// On setting, if the new value isn't equal to what the attribute would currently
// return, the new value must be processed as follows ...
......@@ -174,7 +174,7 @@ void TextTrack::setMode(const String& mode)
m_client->textTrackModeChanged(this);
}
String TextTrack::mode() const
AtomicString TextTrack::mode() const
{
// The text track "showing" and "showing by default" modes return the string "showing".
if (m_showingByDefault)
......
......@@ -54,7 +54,7 @@ public:
class TextTrack : public TrackBase {
public:
static PassRefPtr<TextTrack> create(ScriptExecutionContext* context, TextTrackClient* client, const String& kind, const String& label, const String& language)
static PassRefPtr<TextTrack> create(ScriptExecutionContext* context, TextTrackClient* client, const AtomicString& kind, const AtomicString& label, const AtomicString& language)
{
return adoptRef(new TextTrack(context, client, kind, label, language, AddTrack));
}
......@@ -63,28 +63,28 @@ public:
void setMediaElement(HTMLMediaElement* element) { m_mediaElement = element; }
HTMLMediaElement* mediaElement() { return m_mediaElement; }
String kind() const { return m_kind; }
void setKind(const String&);
AtomicString kind() const { return m_kind; }
void setKind(const AtomicString&);
static const AtomicString& subtitlesKeyword();
static const AtomicString& captionsKeyword();
static const AtomicString& descriptionsKeyword();
static const AtomicString& chaptersKeyword();
static const AtomicString& metadataKeyword();
static bool isValidKindKeyword(const String&);
static bool isValidKindKeyword(const AtomicString&);
String label() const { return m_label; }
void setLabel(const String& label) { m_label = label; }
AtomicString label() const { return m_label; }
void setLabel(const AtomicString& label) { m_label = label; }
String language() const { return m_language; }
void setLanguage(const String& language) { m_language = language; }
AtomicString language() const { return m_language; }
void setLanguage(const AtomicString& language) { m_language = language; }
static const AtomicString& disabledKeyword();
static const AtomicString& hiddenKeyword();
static const AtomicString& showingKeyword();
String mode() const;
void setMode(const String&);
AtomicString mode() const;
void setMode(const AtomicString&);
bool showingByDefault() const { return m_showingByDefault; }
void setShowingByDefault(bool showing) { m_showingByDefault = showing; }
......@@ -116,17 +116,17 @@ public:
bool isRendered();
protected:
TextTrack(ScriptExecutionContext*, TextTrackClient*, const String& kind, const String& label, const String& language, TextTrackType);
TextTrack(ScriptExecutionContext*, TextTrackClient*, const AtomicString& kind, const AtomicString& label, const AtomicString& language, TextTrackType);
RefPtr<TextTrackCueList> m_cues;
private:
TextTrackCueList* ensureTextTrackCueList();
HTMLMediaElement* m_mediaElement;
String m_kind;
String m_label;
String m_language;
String m_mode;
AtomicString m_kind;
AtomicString m_label;
AtomicString m_language;
AtomicString m_mode;
TextTrackClient* m_client;
TextTrackType m_trackType;
ReadinessState m_readinessState;
......
......@@ -95,6 +95,7 @@ TextTrackCueBox::TextTrackCueBox(Document* document, TextTrackCue* cue)
: HTMLElement(divTag, document)
, m_cue(cue)
{
setShadowPseudoId(shadowPseudoId());
}
TextTrackCue* TextTrackCueBox::getCue() const
......@@ -167,12 +168,17 @@ void TextTrackCueBox::applyCSSProperties()
}
}
const AtomicString& TextTrackCueBox::shadowPseudoId() const
const AtomicString& TextTrackCueBox::textTrackCueBoxShadowPseudoId()
{
DEFINE_STATIC_LOCAL(const AtomicString, trackDisplayBoxShadowPseudoId, ("-webkit-media-text-track-display"));
return trackDisplayBoxShadowPseudoId;
}
const AtomicString& TextTrackCueBox::shadowPseudoId() const
{
return textTrackCueBoxShadowPseudoId();
}
RenderObject* TextTrackCueBox::createRenderer(RenderArena* arena, RenderStyle*)