[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>
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)
EXPECTED (cueDisplayElement.offsetTop > (video.videoHeight * .75) == 'true') OK
EXPECTED (cueDisplayElement.offsetTop > (video.videoHeight * .70) == 'true') OK
END OF TEST
......@@ -20,13 +20,14 @@
consoleWrite("");
cueDisplayElement = textTrackDisplayElement(video, 'display', 0);
testExpected("cueDisplayElement.offsetTop > (video.videoHeight * .75)", true);
document.body.offsetTop;
testExpected("cueDisplayElement.offsetTop > (video.videoHeight * .70)", true);
endTest();
}
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();
video.src = findMediaFile('video', '../content/test');
......
......@@ -34,22 +34,23 @@ EXPECTED (2 * testCueDisplayBox.offsetLeft == video.videoWidth - testCueDisplayB
Test the cue display colors and font.
RUN(video.width = 320)
RUN(video.height = 240)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '12px') OK
EXPECTED (getComputedStyle(currentCue).fontSize == '12px') OK
RUN(video.width = 640)
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.height = 960)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '48px') OK
EXPECTED (getComputedStyle(currentCue).fontSize == '48px') OK
RUN(video.width = 2560)
RUN(video.height = 1440)
EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontSize == '72px') OK
EXPECTED (getComputedStyle(currentCue).fontFamily == 'sans-serif') OK
EXPECTED (getComputedStyle(currentCue).color == 'rgb(255, 255, 255)') 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
......@@ -12,29 +12,33 @@
var testTrack;
var testCueDisplayBox;
var seekedCount = 0;
var resizeCount = 1;
var info = [ "Lorem", "ipsum", "dolor", "sit" ];
function testFontSize(width, height)
function setVideoSize(width, height)
{
run("video.width = " + width);
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.");
testFontSize(320, 240);
testFontSize(640, 480);
testFontSize(1280, 960);
testFontSize(2560, 1440);
document.body.offsetTop;
currentCue = textTrackDisplayElement(video, 'cue');
testExpected("getComputedStyle(currentCue).fontSize", parseInt(240 * resizeCount * 0.05) + "px");
consoleWrite("");
if (++resizeCount < 5) {
setVideoSize(320 * resizeCount, 240 * resizeCount);
setTimeout(resizeTest, 10);
return
}
testExpected("getComputedStyle(textTrackDisplayElement(video)).fontFamily", "sans-serif");
testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgb(255, 255, 255)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.796875)");
testExpected("getComputedStyle(currentCue).fontFamily", "sans-serif");
testExpected("getComputedStyle(currentCue).color", "rgb(255, 255, 255)");
testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.8)");
consoleWrite("");
endTest();
// Resize the video so it is easier to interact with it manually, if necessary.
......@@ -42,6 +46,13 @@
video.height = 240;
}
function testCueStyle()
{
consoleWrite("<br>Test the cue display colors and font.");
setVideoSize(320, 240);
setTimeout(resizeTest, 10);
}
function seeked()
{
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>
Repaint rect too small on elements with shadows
......@@ -1081,8 +1081,6 @@ static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a,
void HTMLMediaElement::updateActiveTextTrackCues(float movieTime)
{
LOG(Media, "HTMLMediaElement::updateActiveTextTracks");
// 4.8.10.8 Playing the media resource
// If the current playback position changes while the steps are running,
......@@ -1091,6 +1089,8 @@ void HTMLMediaElement::updateActiveTextTrackCues(float movieTime)
if (ignoreTrackDisplayUpdateRequests())
return;
LOG(Media, "HTMLMediaElement::updateActiveTextTracks");
// 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
// media element (not the disabled ones) whose start times are less than or
......
......@@ -1188,7 +1188,9 @@ const AtomicString& MediaControlCurrentTimeDisplayElement::shadowPseudoId() cons
MediaControlTextTrackContainerElement::MediaControlTextTrackContainerElement(Document* document)
: MediaControlDivElement(document, MediaTextTrackDisplayContainer)
, m_updateTimer(this, &MediaControlTextTrackContainerElement::updateTimerFired)
, m_fontSize(0)
, m_fontSizeIsImportant(false)
{
}
......@@ -1275,9 +1277,11 @@ void MediaControlTextTrackContainerElement::updateDisplay()
continue;
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.
appendChild(displayBox, ASSERT_NO_EXCEPTION, AttachNow);
cue->setFontSize(m_fontSize, m_videoDisplaySize.size(), m_fontSizeIsImportant);
}
}
// 11. Return output.
......@@ -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)
{
HTMLMediaElement* mediaElement = toParentMediaElement(this);
......@@ -1333,25 +1363,7 @@ void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate)
return;
m_videoDisplaySize = videoBox;
if (m_textTrackRepresentation) {
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());
}
m_updateTimer.startOneShot(0);
}
void MediaControlTextTrackContainerElement::paintTextTrackRepresentation(GraphicsContext* context, const IntRect& contextRect)
......
......@@ -448,6 +448,8 @@ public:
static const AtomicString& textTrackContainerElementShadowPseudoId();
private:
void updateTimerFired(Timer<MediaControlTextTrackContainerElement>*);
explicit MediaControlTextTrackContainerElement(Document*);
virtual const AtomicString& shadowPseudoId() const OVERRIDE;
......@@ -457,8 +459,10 @@ private:
virtual void textTrackRepresentationBoundsChanged(const IntRect&) OVERRIDE;
OwnPtr<TextTrackRepresentation> m_textTrackRepresentation;
Timer<MediaControlTextTrackContainerElement> m_updateTimer;
IntRect m_videoDisplaySize;
float m_fontSize;
int m_fontSize;
bool m_fontSizeIsImportant;
};
#endif
......
......@@ -409,9 +409,9 @@ void MediaControls::updateTextTrackDisplay()
void MediaControls::textTrackPreferencesChanged()
{
closedCaptionTracksChanged();
if (m_textDisplayContainer)
m_textDisplayContainer->updateSizes(true);
closedCaptionTracksChanged();
}
#endif
......
......@@ -42,6 +42,7 @@
#include "HTMLDivElement.h"
#include "HTMLMediaElement.h"
#include "HTMLSpanElement.h"
#include "Logging.h"
#include "NodeTraversal.h"
#include "RenderTextTrackCue.h"
#include "Text.h"
......@@ -1179,6 +1180,16 @@ bool TextTrackCue::operator==(const TextTrackCue& cue) const
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
#endif
......@@ -177,7 +177,7 @@ public:
};
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& cue) const
......
......@@ -34,6 +34,7 @@
#include "HTMLDivElement.h"
#include "HTMLNames.h"
#include "InbandTextTrackPrivateClient.h"
#include "Logging.h"
#include "RenderObject.h"
#include "RenderTextTrackCue.h"
#include "ScriptExecutionContext.h"
......@@ -65,6 +66,7 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext);
TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(getCue());
RefPtr<HTMLDivElement> cueElement = cue->element();
float size = static_cast<float>(cue->getCSSSize());
if (cue->useDefaultPosition()) {
......@@ -81,22 +83,18 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
}
if (cue->foregroundColor().isValid())
setInlineStyleProperty(CSSPropertyColor, cue->foregroundColor().serialized());
cueElement->setInlineStyleProperty(CSSPropertyColor, cue->foregroundColor().serialized());
if (cue->backgroundColor().isValid())
cue->element()->setInlineStyleProperty(CSSPropertyBackgroundColor, cue->backgroundColor().serialized());
cueElement->setInlineStyleProperty(CSSPropertyBackgroundColor, cue->backgroundColor().serialized());
if (cue->getWritingDirection() == TextTrackCue::Horizontal)
setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
else
setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto);
if (cue->baseFontSizeRelativeToVideoHeight()) {
double fontSize = videoSize.height() * cue->baseFontSizeRelativeToVideoHeight() / 100;
if (cue->fontSizeMultiplier())
fontSize *= cue->fontSizeMultiplier() / 100;
setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
}
if (cue->baseFontSizeRelativeToVideoHeight())
cue->setFontSize(cue->baseFontSizeRelativeToVideoHeight(), videoSize, false);
if (cue->getAlignment() == TextTrackCue::Middle)
setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter);
......@@ -135,20 +133,24 @@ void TextTrackCueGeneric::setPosition(int position, ExceptionCode& ec)
TextTrackCue::setPosition(position, ec);
}
void TextTrackCueGeneric::videoSizeDidChange(const IntSize& videoSize)
void TextTrackCueGeneric::setFontSize(int fontSize, const IntSize& videoSize, bool important)
{
if (!hasDisplayTree())
if (!hasDisplayTree() || !fontSize)
return;
if (important || !baseFontSizeRelativeToVideoHeight()) {
TextTrackCue::setFontSize(fontSize, videoSize, important);
return;
if (baseFontSizeRelativeToVideoHeight()) {
double fontSize = videoSize.height() * baseFontSizeRelativeToVideoHeight() / 100;
if (fontSizeMultiplier())
fontSize *= fontSizeMultiplier() / 100;
displayTreeInternal()->setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
}
}
double size = videoSize.height() * baseFontSizeRelativeToVideoHeight() / 100;
if (fontSizeMultiplier())
size *= fontSizeMultiplier() / 100;
element()->setInlineStyleProperty(CSSPropertyFontSize, String::number(lrintf(size)) + "px");
LOG(Media, "TextTrackCueGeneric::setFontSize - setting cue font size to %li", lrintf(size));
}
bool TextTrackCueGeneric::operator==(const TextTrackCue& cue) const
{
if (cue.cueType() != TextTrackCue::Generic)
......
......@@ -68,7 +68,7 @@ public:
Color backgroundColor() const { return m_backgroundColor; }
void setBackgroundColor(RGBA32 color) { m_backgroundColor.setRGB(color); }
virtual void videoSizeDidChange(const IntSize&);
virtual void setFontSize(int, const IntSize&, bool important) OVERRIDE;
virtual bool operator==(const TextTrackCue&) const OVERRIDE;
virtual bool operator!=(const TextTrackCue& cue) const OVERRIDE
......
......@@ -205,7 +205,7 @@ void TextTrackList::remove(TextTrack* track)
invalidateTrackIndexesAfterTrack(track);
ASSERT(track->mediaElement() == m_owner);
ASSERT(!track->mediaElement() || track->mediaElement() == m_owner);
track->setMediaElement(0);
tracks->remove(index);
......
......@@ -28,10 +28,12 @@
#if ENABLE(VIDEO_TRACK)
#include "CaptionUserPreferences.h"
#include "DOMWrapperWorld.h"
#include "Page.h"
#include "PageGroup.h"
#include "Settings.h"
#include "TextTrackList.h"
#include "UserStyleSheetTypes.h"
#include <wtf/NonCopyingSort.h>
namespace WebCore {
......@@ -221,6 +223,28 @@ int CaptionUserPreferences::textTrackLanguageSelectionScore(TextTrack* track, co
return (preferredLanguages.size() - languageMatchIndex) * 10;
}
void CaptionUserPreferences::setCaptionsStyleSheetOverride(const String& override)
{
m_captionsStyleSheetOverride = override;
updateCaptionStyleSheetOveride();
}
void CaptionUserPreferences::updateCaptionStyleSheetOveride()
{
// Identify our override style sheet with a unique URL - a new scheme and a UUID.
DEFINE_STATIC_LOCAL(KURL, captionsStyleSheetURL, (ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23"));
pageGroup()->removeUserStyleSheetFromWorld(mainThreadNormalWorld(), captionsStyleSheetURL);
String captionsOverrideStyleSheet = captionsStyleSheetOverride();
if (captionsOverrideStyleSheet.isEmpty())
return;
pageGroup()->addUserStyleSheetToWorld(mainThreadNormalWorld(), captionsOverrideStyleSheet, captionsStyleSheetURL, Vector<String>(),
Vector<String>(), InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocuments);
}
}
#endif // ENABLE(VIDEO_TRACK)
......@@ -66,8 +66,10 @@ public:
virtual bool userPrefersTextDescriptions() const;
virtual void setUserPrefersTextDescriptions(bool preference);
virtual float captionFontSizeScale(bool& important) const { important = false; return 0.05f; }
virtual String captionsStyleSheetOverride() const { return emptyString(); }
virtual float captionFontSizeScaleAndImportance(bool& important) const { important = false; return 0.05f; }
virtual String captionsStyleSheetOverride() const { return m_captionsStyleSheetOverride; }
virtual void setCaptionsStyleSheetOverride(const String&);
virtual void setInterestedInCaptionPreferenceChanges() { }
......@@ -86,6 +88,7 @@ public:
protected:
CaptionUserPreferences(PageGroup*);
void updateCaptionStyleSheetOveride();
private:
void timerFired(Timer<CaptionUserPreferences>*);
......@@ -95,6 +98,7 @@ private:
CaptionDisplayMode m_displayMode;
Timer<CaptionUserPreferences> m_timer;
String m_userPreferredLanguage;
String m_captionsStyleSheetOverride;