[Mac] user caption styles not applied to correct element

https://bugs.webkit.org/show_bug.cgi?id=114230

Reviewed by Jer Noble.

Source/WebCore: 

Test: media/track/track-css-user-override.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::updateActiveTextTrackCues): Drive by clean-up so we don't log excessively.

* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::MediaControlTextTrackContainerElement): Initialize
    new member variables.
(WebCore::MediaControlTextTrackContainerElement::updateDisplay): Set cue font size when it is
    inserted into the tree.
(WebCore::MediaControlTextTrackContainerElement::updateTimerFired): Update the font size of 
    all active cues.
(WebCore::MediaControlTextTrackContainerElement::updateSizes): Set size-relative CSS properties
    after a time because this can be called during layout.
* html/shadow/MediaControlElements.h:

* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::textTrackPreferencesChanged): Call closedCaptionTracksChanged before updateSizes.

* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::setFontSize): New, set the cue's font size.
* html/track/TextTrackCue.h:

* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties): Set cue properties on the cue element
    instead of on the cue box to match what we do for the "cue" pseudo element.
(WebCore::TextTrackCueGeneric::setFontSize): New, set the cue's font size.
* html/track/TextTrackCueGeneric.h:

* html/track/TextTrackList.cpp:
(TextTrackList::remove): Drive-by cleanup, don't ASSERT when the media element is NULL.

* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::setCaptionsStyleSheetOverride): New, allow user CSS overrides
    to be tested in DRT.
(WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride): New, generate a user style
    sheet override. Moved here from CaptionUserPreferencesMac.
* page/CaptionUserPreferences.h:

* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::captionsBackgroundCSS): Don't ignore background color importance.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Implement even when we don't 
    have the media accessibility framework so this can be tested in DRT. Apply all cue properties
    to the element used for the "cue" pseudo element.

* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::didLoadingProgress): Drive-by cleanup, remove logging
    because this method is called so frequently and the logging is not especially useful.
(WebCore::MediaPlayerPrivateAVFoundation::updateStates): Only log when the ready/network
    state changes because this method is called so frequently.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformLayer): Drive-by cleanup, remove logging
    because this method is called so frequently and the logging is not especially useful.
(WebCore::MediaPlayerPrivateAVFoundationObjC::setCurrentTrack): Make the logging more useful.

* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState): Reset captions style sheet override.
(WebCore::Internals::captionsStyleSheetOverride): New, return the captions style sheet override.
(WebCore::Internals::setCaptionsStyleSheetOverride): New, override the captions style sheet override.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests: 

* media/track/track-css-user-override-expected.txt: Added.
* media/track/track-css-user-override.html: Added.
* media/track/track-cue-container-rendering-position-expected.txt:
* media/track/track-cue-container-rendering-position.html:
* media/track/track-cue-rendering-expected.txt:
* media/track/track-cue-rendering.html: Font size is not applied instantly when a video element is
    resized, so check after a very short delay.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148050 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ce1e8dbe
2013-04-09 Eric Carlson <eric.carlson@apple.com>
[Mac] user caption styles not applied to correct element
https://bugs.webkit.org/show_bug.cgi?id=114230
Reviewed by Jer Noble.
* media/track/track-css-user-override-expected.txt: Added.
* media/track/track-css-user-override.html: Added.
* media/track/track-cue-container-rendering-position-expected.txt:
* media/track/track-cue-container-rendering-position.html:
* media/track/track-cue-rendering-expected.txt:
* media/track/track-cue-rendering.html: Font size is not applied instantly when a video element is
resized, so check after a very short delay.
2013-04-09 Simon Fraser <simon.fraser@apple.com> 2013-04-09 Simon Fraser <simon.fraser@apple.com>
Repaint rect too small on elements with shadows Repaint rect too small on elements with shadows
internals.captionsStyleSheetOverride = function captionsStyleSheetOverride() { [native code] }
Test that style to all cues is applied correctly.
EVENT(canplaythrough)
EVENT(seeked)
** Check style in .vtt file **
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).color == 'rgb(255, 255, 255)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor == 'rgba(0, 0, 0, 0.8)') OK
** Add style to the document **
RUN(stylesheet.insertRule('video::cue { color: purple; background-color: lime; }', 0))
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).color == 'rgb(128, 0, 128)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor == 'rgb(0, 255, 0)') OK
** Add an override, without '!important' **
RUN(internals.setCaptionsStyleSheetOverride('video::cue { color: blue; background-color: yellow; }'))
internals.captionsStyleSheetOverride = function captionsStyleSheetOverride() { [native code] }
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).color == 'rgb(128, 0, 128)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor == 'rgb(0, 255, 0)') OK
** Mark background-color '!important' **
RUN(internals.setCaptionsStyleSheetOverride('video::cue { color: blue ; background-color: yellow !important; }'))
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).color == 'rgb(128, 0, 128)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor == 'rgb(255, 255, 0)') OK
** Mark color '!important' **
RUN(stylesheet.insertRule('video::cue { color: blue !important; background-color: yellow !important; }', 0))
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).color == 'rgb(0, 0, 255)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor == 'rgb(255, 255, 0)') OK
END OF TEST
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src=../media-file.js></script>
<script src=../video-test.js></script>
<script src=../media-controls.js></script>
<script>
var seekCount = 0;
function seeked()
{
var currentCue = textTrackDisplayElement(video, 'cue');
consoleWrite("<br>** Check style in .vtt file **");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).color", "rgb(255, 255, 255)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor", "rgba(0, 0, 0, 0.8)");
consoleWrite("<br>** Add style to the document **");
var styleElement = document.createElement("style");
document.head.appendChild(styleElement);
stylesheet = styleElement.sheet;
run("stylesheet.insertRule('video::cue { color: purple; background-color: lime; }', 0)");
document.body.offsetTop;
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).color", "rgb(128, 0, 128)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor", "rgb(0, 255, 0)");
consoleWrite("<br>** Add an override, without '!important' **");
document.body.offsetTop;
run("internals.setCaptionsStyleSheetOverride('video::cue { color: blue; background-color: yellow; }')");
consoleWrite("internals.captionsStyleSheetOverride = " + internals.captionsStyleSheetOverride);
document.body.offsetTop;
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).color", "rgb(128, 0, 128)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor", "rgb(0, 255, 0)");
consoleWrite("<br>** Mark background-color '!important' **");
run("internals.setCaptionsStyleSheetOverride('video::cue { color: blue ; background-color: yellow !important; }')");
document.body.offsetTop;
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).color", "rgb(128, 0, 128)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor", "rgb(255, 255, 0)");
consoleWrite("<br>** Mark color '!important' **");
run("stylesheet.insertRule('video::cue { color: blue !important; background-color: yellow !important; }', 0)");
document.body.offsetTop;
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).color", "rgb(0, 0, 255)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'cue')).backgroundColor", "rgb(255, 255, 0)");
consoleWrite("");
endTest();
}
function loaded()
{
consoleWrite("<br>internals.captionsStyleSheetOverride = " + internals.captionsStyleSheetOverride);
consoleWrite("Test that style to all cues is applied correctly.");
findMediaElement();
video.src = findMediaFile('video', '../content/test');
waitForEvent('seeked', seeked);
waitForEvent('canplaythrough', function() { video.currentTime = .5; });
}
</script>
</head>
<body onload="loaded()">
<video controls >
<track src="captions-webvtt/styling.vtt" kind="captions" default>
</video>
</body>
</html>
The top of the text track container should be in the bottom 25% of the video element. The top of the text track container should be in the bottom 30% of the video element.
EVENT(canplaythrough) EVENT(canplaythrough)
EXPECTED (cueDisplayElement.offsetTop > (video.videoHeight * .75) == 'true') OK EXPECTED (cueDisplayElement.offsetTop > (video.videoHeight * .70) == 'true') OK
END OF TEST END OF TEST
...@@ -20,13 +20,14 @@ ...@@ -20,13 +20,14 @@
consoleWrite(""); consoleWrite("");
cueDisplayElement = textTrackDisplayElement(video, 'display', 0); cueDisplayElement = textTrackDisplayElement(video, 'display', 0);
testExpected("cueDisplayElement.offsetTop > (video.videoHeight * .75)", true); document.body.offsetTop;
testExpected("cueDisplayElement.offsetTop > (video.videoHeight * .70)", true);
endTest(); endTest();
} }
function loaded() function loaded()
{ {
consoleWrite("The top of the text track container should be in the bottom 25% of the video element."); consoleWrite("The top of the text track container should be in the bottom 30% of the video element.");
findMediaElement(); findMediaElement();
video.src = findMediaFile('video', '../content/test'); video.src = findMediaFile('video', '../content/test');
......
...@@ -34,22 +34,23 @@ EXPECTED (2 * testCueDisplayBox.offsetLeft == video.videoWidth - testCueDisplayB ...@@ -34,22 +34,23 @@ EXPECTED (2 * testCueDisplayBox.offsetLeft == video.videoWidth - testCueDisplayB
Test the cue display colors and font. Test the cue display colors and font.
RUN(video.width = 320) RUN(video.width = 320)
RUN(video.height = 240) RUN(video.height = 240)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '12px') OK EXPECTED (getComputedStyle(currentCue).fontSize == '12px') OK
RUN(video.width = 640) RUN(video.width = 640)
RUN(video.height = 480) RUN(video.height = 480)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '24px') OK EXPECTED (getComputedStyle(currentCue).fontSize == '24px') OK
RUN(video.width = 960)
RUN(video.height = 720)
EXPECTED (getComputedStyle(currentCue).fontSize == '36px') OK
RUN(video.width = 1280) RUN(video.width = 1280)
RUN(video.height = 960) RUN(video.height = 960)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '48px') OK EXPECTED (getComputedStyle(currentCue).fontSize == '48px') OK
RUN(video.width = 2560) EXPECTED (getComputedStyle(currentCue).fontFamily == 'sans-serif') OK
RUN(video.height = 1440) EXPECTED (getComputedStyle(currentCue).color == 'rgb(255, 255, 255)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '72px') OK EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor == 'rgba(0, 0, 0, 0.8)') OK
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontFamily == 'sans-serif') 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 END OF TEST
...@@ -12,29 +12,33 @@ ...@@ -12,29 +12,33 @@
var testTrack; var testTrack;
var testCueDisplayBox; var testCueDisplayBox;
var seekedCount = 0; var seekedCount = 0;
var resizeCount = 1;
var info = [ "Lorem", "ipsum", "dolor", "sit" ]; var info = [ "Lorem", "ipsum", "dolor", "sit" ];
function testFontSize(width, height) function setVideoSize(width, height)
{ {
run("video.width = " + width); run("video.width = " + width);
run("video.height = " + height); run("video.height = " + height);
document.body.offsetTop;
testExpected("getComputedStyle(textTrackDisplayElement(video)).fontSize", parseInt(height * 0.05) + "px");
consoleWrite("");
} }
function testCueStyle() function resizeTest()
{ {
consoleWrite("<br>Test the cue display colors and font."); document.body.offsetTop;
testFontSize(320, 240); currentCue = textTrackDisplayElement(video, 'cue');
testFontSize(640, 480); testExpected("getComputedStyle(currentCue).fontSize", parseInt(240 * resizeCount * 0.05) + "px");
testFontSize(1280, 960); consoleWrite("");
testFontSize(2560, 1440);
if (++resizeCount < 5) {
setVideoSize(320 * resizeCount, 240 * resizeCount);
setTimeout(resizeTest, 10);
return
}
testExpected("getComputedStyle(textTrackDisplayElement(video)).fontFamily", "sans-serif"); testExpected("getComputedStyle(currentCue).fontFamily", "sans-serif");
testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgb(255, 255, 255)"); testExpected("getComputedStyle(currentCue).color", "rgb(255, 255, 255)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.796875)"); testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.8)");
consoleWrite("");
endTest(); endTest();
// Resize the video so it is easier to interact with it manually, if necessary. // Resize the video so it is easier to interact with it manually, if necessary.
...@@ -42,6 +46,13 @@ ...@@ -42,6 +46,13 @@
video.height = 240; video.height = 240;
} }
function testCueStyle()
{
consoleWrite("<br>Test the cue display colors and font.");
setVideoSize(320, 240);
setTimeout(resizeTest, 10);
}
function seeked() function seeked()
{ {
if (testEnded) if (testEnded)
......
2013-04-09 Eric Carlson <eric.carlson@apple.com>
[Mac] user caption styles not applied to correct element
https://bugs.webkit.org/show_bug.cgi?id=114230
Reviewed by Jer Noble.
Test: media/track/track-css-user-override.html
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::updateActiveTextTrackCues): Drive by clean-up so we don't log excessively.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::MediaControlTextTrackContainerElement): Initialize
new member variables.
(WebCore::MediaControlTextTrackContainerElement::updateDisplay): Set cue font size when it is
inserted into the tree.
(WebCore::MediaControlTextTrackContainerElement::updateTimerFired): Update the font size of
all active cues.
(WebCore::MediaControlTextTrackContainerElement::updateSizes): Set size-relative CSS properties
after a time because this can be called during layout.
* html/shadow/MediaControlElements.h:
* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::textTrackPreferencesChanged): Call closedCaptionTracksChanged before updateSizes.
* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::setFontSize): New, set the cue's font size.
* html/track/TextTrackCue.h:
* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties): Set cue properties on the cue element
instead of on the cue box to match what we do for the "cue" pseudo element.
(WebCore::TextTrackCueGeneric::setFontSize): New, set the cue's font size.
* html/track/TextTrackCueGeneric.h:
* html/track/TextTrackList.cpp:
(TextTrackList::remove): Drive-by cleanup, don't ASSERT when the media element is NULL.
* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::setCaptionsStyleSheetOverride): New, allow user CSS overrides
to be tested in DRT.
(WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride): New, generate a user style
sheet override. Moved here from CaptionUserPreferencesMac.
* page/CaptionUserPreferences.h:
* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::captionsBackgroundCSS): Don't ignore background color importance.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Implement even when we don't
have the media accessibility framework so this can be tested in DRT. Apply all cue properties
to the element used for the "cue" pseudo element.
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::didLoadingProgress): Drive-by cleanup, remove logging
because this method is called so frequently and the logging is not especially useful.
(WebCore::MediaPlayerPrivateAVFoundation::updateStates): Only log when the ready/network
state changes because this method is called so frequently.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformLayer): Drive-by cleanup, remove logging
because this method is called so frequently and the logging is not especially useful.
(WebCore::MediaPlayerPrivateAVFoundationObjC::setCurrentTrack): Make the logging more useful.
* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState): Reset captions style sheet override.
(WebCore::Internals::captionsStyleSheetOverride): New, return the captions style sheet override.
(WebCore::Internals::setCaptionsStyleSheetOverride): New, override the captions style sheet override.
* testing/Internals.h:
* testing/Internals.idl:
2013-04-08 Simon Fraser <simon.fraser@apple.com> 2013-04-08 Simon Fraser <simon.fraser@apple.com>
Repaint rect too small on elements with shadows Repaint rect too small on elements with shadows
...@@ -1081,8 +1081,6 @@ static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a, ...@@ -1081,8 +1081,6 @@ static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a,
void HTMLMediaElement::updateActiveTextTrackCues(float movieTime) void HTMLMediaElement::updateActiveTextTrackCues(float movieTime)
{ {
LOG(Media, "HTMLMediaElement::updateActiveTextTracks");
// 4.8.10.8 Playing the media resource // 4.8.10.8 Playing the media resource
// If the current playback position changes while the steps are running, // If the current playback position changes while the steps are running,
...@@ -1091,6 +1089,8 @@ void HTMLMediaElement::updateActiveTextTrackCues(float movieTime) ...@@ -1091,6 +1089,8 @@ void HTMLMediaElement::updateActiveTextTrackCues(float movieTime)
if (ignoreTrackDisplayUpdateRequests()) if (ignoreTrackDisplayUpdateRequests())
return; return;
LOG(Media, "HTMLMediaElement::updateActiveTextTracks");
// 1 - Let current cues be a list of cues, initialized to contain all the // 1 - Let current cues be a list of cues, initialized to contain all the
// cues of all the hidden, showing, or showing by default text tracks of the // cues of all the hidden, showing, or showing by default text tracks of the
// media element (not the disabled ones) whose start times are less than or // media element (not the disabled ones) whose start times are less than or
......
...@@ -1188,7 +1188,9 @@ const AtomicString& MediaControlCurrentTimeDisplayElement::shadowPseudoId() cons ...@@ -1188,7 +1188,9 @@ const AtomicString& MediaControlCurrentTimeDisplayElement::shadowPseudoId() cons
MediaControlTextTrackContainerElement::MediaControlTextTrackContainerElement(Document* document) MediaControlTextTrackContainerElement::MediaControlTextTrackContainerElement(Document* document)
: MediaControlDivElement(document, MediaTextTrackDisplayContainer) : MediaControlDivElement(document, MediaTextTrackDisplayContainer)
, m_updateTimer(this, &MediaControlTextTrackContainerElement::updateTimerFired)
, m_fontSize(0) , m_fontSize(0)
, m_fontSizeIsImportant(false)
{ {
} }
...@@ -1275,9 +1277,11 @@ void MediaControlTextTrackContainerElement::updateDisplay() ...@@ -1275,9 +1277,11 @@ void MediaControlTextTrackContainerElement::updateDisplay()
continue; continue;
RefPtr<TextTrackCueBox> displayBox = cue->getDisplayTree(m_videoDisplaySize.size()); RefPtr<TextTrackCueBox> displayBox = cue->getDisplayTree(m_videoDisplaySize.size());
if (displayBox->hasChildNodes() && !contains(static_cast<Node*>(displayBox.get()))) if (displayBox->hasChildNodes() && !contains(static_cast<Node*>(displayBox.get()))) {
// Note: the display tree of a cue is removed when the active flag of the cue is unset. // Note: the display tree of a cue is removed when the active flag of the cue is unset.
appendChild(displayBox, ASSERT_NO_EXCEPTION, AttachNow); appendChild(displayBox, ASSERT_NO_EXCEPTION, AttachNow);
cue->setFontSize(m_fontSize, m_videoDisplaySize.size(), m_fontSizeIsImportant);
}
} }
// 11. Return output. // 11. Return output.
...@@ -1304,6 +1308,32 @@ void MediaControlTextTrackContainerElement::updateDisplay() ...@@ -1304,6 +1308,32 @@ void MediaControlTextTrackContainerElement::updateDisplay()
} }
} }
void MediaControlTextTrackContainerElement::updateTimerFired(Timer<MediaControlTextTrackContainerElement>*)
{
if (!document()->page())
return;
if (m_textTrackRepresentation) {
setInlineStyleProperty(CSSPropertyWidth, String::number(m_videoDisplaySize.size().width()) + "px");
setInlineStyleProperty(CSSPropertyHeight, String::number(m_videoDisplaySize.size().height()) + "px");
}
HTMLMediaElement* mediaElement = toParentMediaElement(this);
if (!mediaElement)
return;
float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width());
float fontScale = document()->page()->group().captionPreferences()->captionFontSizeScaleAndImportance(m_fontSizeIsImportant);
m_fontSize = lrintf(smallestDimension * fontScale);
CueList activeCues = mediaElement->currentlyActiveCues();
for (size_t i = 0; i < activeCues.size(); ++i) {
TextTrackCue* cue = activeCues[i].data();
cue->setFontSize(m_fontSize, m_videoDisplaySize.size(), m_fontSizeIsImportant);
}
}
void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate) void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate)
{ {
HTMLMediaElement* mediaElement = toParentMediaElement(this); HTMLMediaElement* mediaElement = toParentMediaElement(this);
...@@ -1333,25 +1363,7 @@ void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate) ...@@ -1333,25 +1363,7 @@ void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate)
return; return;
m_videoDisplaySize = videoBox; m_videoDisplaySize = videoBox;
if (m_textTrackRepresentation) { m_updateTimer.startOneShot(0);
setInlineStyleProperty(CSSPropertyWidth, String::number(m_videoDisplaySize.size().width()) + "px");
setInlineStyleProperty(CSSPropertyHeight, String::number(m_videoDisplaySize.size().height()) + "px");
}
float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width());
bool important;
float fontSize = smallestDimension * (document()->page()->group().captionPreferences()->captionFontSizeScale(important));
if (fontSize != m_fontSize) {
m_fontSize = fontSize;
setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px", important);
}
CueList activeCues = mediaElement->currentlyActiveCues();
for (size_t i = 0; i < activeCues.size(); ++i) {
TextTrackCue* cue = activeCues[i].data();
cue->videoSizeDidChange(m_videoDisplaySize.size());
}
} }
void MediaControlTextTrackContainerElement::paintTextTrackRepresentation(GraphicsContext* context, const IntRect& contextRect) void MediaControlTextTrackContainerElement::paintTextTrackRepresentation(GraphicsContext* context, const IntRect& contextRect)
......
...@@ -448,6 +448,8 @@ public: ...@@ -448,6 +448,8 @@ public:
static const AtomicString& textTrackContainerElementShadowPseudoId(); static const AtomicString& textTrackContainerElementShadowPseudoId();
private: private:
void updateTimerFired(Timer<MediaControlTextTrackContainerElement>*);
explicit MediaControlTextTrackContainerElement(Document*); explicit MediaControlTextTrackContainerElement(Document*);
virtual const AtomicString& shadowPseudoId() const OVERRIDE; virtual const AtomicString& shadowPseudoId() const OVERRIDE;
...@@ -457,8 +459,10 @@ private: ...@@ -457,8 +459,10 @@ private:
virtual void textTrackRepresentationBoundsChanged(const IntRect&) OVERRIDE; virtual void textTrackRepresentationBoundsChanged(const IntRect&) OVERRIDE;
OwnPtr<TextTrackRepresentation> m_textTrackRepresentation; OwnPtr<TextTrackRepresentation> m_textTrackRepresentation;
Timer<MediaControlTextTrackContainerElement> m_updateTimer;
IntRect m_videoDisplaySize; IntRect m_videoDisplaySize;
float m_fontSize; int m_fontSize;
bool m_fontSizeIsImportant;
}; };
#endif #endif
......
...@@ -409,9 +409,9 @@ void MediaControls::updateTextTrackDisplay() ...@@ -409,9 +409,9 @@ void MediaControls::updateTextTrackDisplay()
void MediaControls::textTrackPreferencesChanged() void MediaControls::textTrackPreferencesChanged()
{ {
closedCaptionTracksChanged();
if (m_textDisplayContainer) if (m_textDisplayContainer)
m_textDisplayContainer->updateSizes(true); m_textDisplayContainer->updateSizes(true);
closedCaptionTracksChanged();
} }
#endif #endif
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "HTMLDivElement.h" #include "HTMLDivElement.h"
#include "HTMLMediaElement.h" #include "HTMLMediaElement.h"
#include "HTMLSpanElement.h" #include "HTMLSpanElement.h"
#include "Logging.h"
#include "NodeTraversal.h" #include "NodeTraversal.h"
#include "RenderTextTrackCue.h" #include "RenderTextTrackCue.h"
#include "Text.h" #include "Text.h"
...@@ -1179,6 +1180,16 @@ bool TextTrackCue::operator==(const TextTrackCue& cue) const ...@@ -1179,6 +1180,16 @@ bool TextTrackCue::operator==(const TextTrackCue& cue) const
return true; return true;
} }
void TextTrackCue::setFontSize(int fontSize, const IntSize&, bool important)
{
if (!hasDisplayTree() || !fontSize)
return;
LOG(Media, "TextTrackCue::setFontSize - setting cue font size to %i", fontSize);
element()->setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px", important);
}
} // namespace WebCore } // namespace WebCore
#endif #endif
...@@ -177,7 +177,7 @@ public: ...@@ -177,7 +177,7 @@ public:
}; };
CueAlignment getAlignment() const { return m_cueAlignment; } CueAlignment getAlignment() const { return m_cueAlignment; }
virtual void videoSizeDidChange(const IntSize&) { } virtual void setFontSize(int, const IntSize&, bool important);
virtual bool operator==(const TextTrackCue&) const; virtual bool operator==(const TextTrackCue&) const;
virtual bool operator!=(const TextTrackCue& cue) const virtual bool operator!=(const TextTrackCue& cue) const
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "HTMLDivElement.h" #include "HTMLDivElement.h"
#include "HTMLNames.h" #include "HTMLNames.h"
#include "InbandTextTrackPrivateClient.h" #include "InbandTextTrackPrivateClient.h"
#include "Logging.h"
#include "RenderObject.h" #include "RenderObject.h"
#include "RenderTextTrackCue.h" #include "RenderTextTrackCue.h"
#include "ScriptExecutionContext.h" #include "ScriptExecutionContext.h"
...@@ -65,6 +66,7 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize) ...@@ -65,6 +66,7 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext); setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext);
TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(getCue()); TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(getCue());
RefPtr<HTMLDivElement> cueElement = cue->element();