Commit 2cd48f46 authored by eric.carlson@apple.com's avatar eric.carlson@apple.com
Browse files

[Mac] respect in-band caption color

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

Reviewed by Dean Jackson.

Source/WebCore: 

Test: media/track/track-in-band-style.html

* WebCore.xcodeproj/project.pbxproj: Add HTMLDivElement.h to private headers because it is 
    included by HTMLTextElement, which is included by HTMLMediaElement.h, which is included 
    by files in WebKit/WebKit2.
* html/track/InbandTextTrack.cpp:
(WebCore::InbandTextTrack::addGenericCue): Set cue colors if necessary.

* html/track/TextTrackCue.h:
(WebCore::TextTrackCue::element): New, accessor for the cue element so it can be styled.

* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties): Set container and cue background 
    color if necessary.
(WebCore::TextTrackCueGeneric::operator==): Compare cue colors.
* html/track/TextTrackCueGeneric.h:
(WebCore::TextTrackCueGeneric::foregroundColor): Add color accessors.
(WebCore::TextTrackCueGeneric::setForegroundColor):
(WebCore::TextTrackCueGeneric::backgroundColor):
(WebCore::TextTrackCueGeneric::setBackgroundColor):

* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks): Always
    regenerate override CSS when an element registers for callbacks.
(WebCore::CaptionUserPreferencesMac::captionsWindowCSS): Drive by fix of "window color" padding.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Log the stylesheet generated
    for easier debugging.

* platform/graphics/InbandTextTrackPrivateClient.h:
(WebCore::GenericCueData::foregroundColor): Add color getters/setters.
(WebCore::GenericCueData::setForegroundColor):
(WebCore::GenericCueData::backgroundColor):
(WebCore::GenericCueData::setBackgroundColor):

* platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
(WebCore::makeRGBA32FromARGBCFArray): Initialize a RGBA32 from a CFArray of color values.
(WebCore::InbandTextTrackPrivateAVF::processCueAttributes): Process cue colors.

LayoutTests: 

* media/track/track-in-band-style-expected.txt: Added.
* media/track/track-in-band-style.html: Added.

* platform/chromium/TestExpectations: Skip new test.
* platform/efl/TestExpectations: Ditto.
* platform/gtk/TestExpectations: Ditto.
* platform/mac/TestExpectations: Ditto.
* platform/qt/TestExpectations: Ditto.
* platform/win/TestExpectations: Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@142349 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b9181b30
2013-02-08 Benjamin Poulain <bpoulain@apple.com>
2013-02-08 Eric Carlson <eric.carlson@apple.com>
 
Move workerThreadCount from TestRunner to WebCore Internals
https://bugs.webkit.org/show_bug.cgi?id=109239
[Mac] respect in-band caption color
https://bugs.webkit.org/show_bug.cgi?id=109203
 
Reviewed by Darin Adler.
Reviewed by Dean Jackson.
 
Update the tests testRunner->internals.
* media/track/track-in-band-style-expected.txt: Added.
* media/track/track-in-band-style.html: Added.
 
* fast/workers/resources/dedicated-worker-lifecycle.js:
(runTests.worker.onmessage):
(runTests):
(orphanedWorkerExited.worker.onmessage):
(orphanedWorkerExited):
* fast/workers/resources/worker-lifecycle.js:
(runTests.worker.onmessage):
(runTests):
* fast/workers/resources/worker-util.js:
(.return):
(waitUntilThreadCountMatches):
* fast/workers/worker-close-more.html:
* http/tests/workers/resources/worker-util.js:
(.return):
(waitUntilThreadCountMatches):
* platform/chromium/TestExpectations: Skip new test.
* platform/efl/TestExpectations: Ditto.
* platform/gtk/TestExpectations: Ditto.
* platform/mac/TestExpectations: Ditto.
* platform/qt/TestExpectations: Ditto.
* platform/win/TestExpectations: Ditto.
 
2013-02-08 Gregg Tavares <gman@chromium.org>
 
Test that style to all cues is applied correctly.
EVENT(canplaythrough)
** Check initial in-band track states
RUN(inbandTrack1 = video.textTracks[0])
EXPECTED (video.textTracks.length == '1') OK
EXPECTED (inbandTrack1.language == 'en') OK
EXPECTED (inbandTrack1.kind == 'captions') OK
RUN(video.play())
EVENT(seeked)
** Test current cue colors
EXPECTED (getComputedStyle(cueDisplayElement).color == 'rgb(255, 255, 255)') OK
EXPECTED (getComputedStyle(cueNode).backgroundColor == 'rgb(0, 0, 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>
function seeked()
{
consoleWrite("<br><i>** Test current cue colors<" + "/i>");
cueDisplayElement = textTrackDisplayElement(video, 'display', 0);
testExpected("getComputedStyle(cueDisplayElement).color", "rgb(255, 255, 255)");
cueNode = textTrackDisplayElement(video, 'all-nodes');
testExpected("getComputedStyle(cueNode).backgroundColor", "rgb(0, 0, 0)");
endTest();
}
function canplaythrough()
{
consoleWrite("<br><i>** Check initial in-band track states<" + "/i>");
run("inbandTrack1 = video.textTracks[0]");
testExpected("video.textTracks.length", 1);
testExpected("inbandTrack1.language", "en");
testExpected("inbandTrack1.kind", "captions");
inbandTrack1.mode = 'showing';
run("video.play()");
setTimeout(function() { video.pause(); video.currentTime = 0.3; }, 1500);
}
function loaded()
{
consoleWrite("Test that style to all cues is applied correctly.");
findMediaElement();
video.src = '../content/counting-captioned.mov';
waitForEvent('seeked', seeked);
waitForEvent('canplaythrough', canplaythrough);
}
</script>
</head>
<body onload="loaded()">
<video controls >
</video>
</body>
</html>
......@@ -4189,6 +4189,7 @@ webkit.org/b/94002 [ Mac Debug ] inspector/debugger/live-edit.html [ Crash Pass
# No support for exposing in-band text tracks
webkit.org/b/103767 [ Win Mac Linux ] media/track/track-in-band.html [ Skip ]
webkit.org/b/103767 [ Win Mac Linux ] media/track/track-in-band-cues-added-once.html [ Skip ]
webkit.org/b/103767 [ Win Mac Linux ] media/track/track-in-band-style.html [ Skip ]
# Flaky on Win (perhaps due to lighttpd?)
webkit.org/b/104489 [ Win ] http/tests/w3c/webperf/submission/resource-timing/html/test_resource_attribute_order.html [ Failure Pass ]
......
......@@ -1733,6 +1733,7 @@ webkit.org/b/61138 http/tests/w3c/webperf/submission/resource-timing [ Skip ]
# No support for exposing in-band text tracks
Bug(EFL) media/track/track-in-band.html [ Skip ]
Bug(EFL) media/track/track-in-band-cues-added-once.html [ Skip ]
Bug(EFL) media/track/track-in-band-style.html [ Skip ]
# All debug bots timeout (crash) on this one
webkit.org/b/56496 [ Debug ] fast/js/array-sort-modifying-tostring.html [ Crash Pass ]
......
......@@ -478,6 +478,7 @@ webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_ev
# No support for exposing in-band text tracks
webkit.org/b/103771 media/track/track-in-band.html [ Failure ]
webkit.org/b/103771 media/track/track-in-band-cues-added-once.html [ Timeout ]
webkit.org/b/103771 media/track/track-in-band-style.html [ Failure ]
#////////////////////////////////////////////////////////////////////////////////////////
# End of Expected failures
......
......@@ -1238,6 +1238,7 @@ Bug(jernoble) [ MountainLion Lion SnowLeopard ] media/video-src-blob.html
# Mountain Lion and prior do not allow access to in-band text tracks
webkit.org/b/103663 [ MountainLion Lion SnowLeopard ] media/track/track-in-band.html
webkit.org/b/103663 [ MountainLion Lion SnowLeopard ] media/track/track-in-band-cues-added-once.html
webkit.org/b/103663 [ MountainLion Lion SnowLeopard ] media/track/track-in-band-style.html
webkit.org/b/104104 fast/overflow/scrollbar-click-retains-focus.html [ Failure ]
......
......@@ -2557,6 +2557,7 @@ webkit.org/b/108257 compositing/overflow/automatically-opt-into-composited-scrol
# No support for exposing in-band text tracks
webkit.org/b/103769 media/track/track-in-band.html [ Skip ]
webkit.org/b/103769 media/track/track-in-band-cues-added-once.html [ Skip ]
webkit.org/b/103769 media/track/track-in-band-style.html [ Skip ]
webkit.org/b/104150 fast/media/implicit-media-all.html [ ImageOnlyFailure ]
......
......@@ -2500,6 +2500,7 @@ fast/js/kde/Array.html
# No support for exposing in-band text tracks
webkit.org/b/103770 media/track/track-in-band.html [ Skip ]
webkit.org/b/103770 media/track/track-in-band-cues-added-once.html [ Skip ]
webkit.org/b/103770 media/track/track-in-band-style.html [ Skip ]
# https://bugs.webkit.org/show_bug.cgi?id=97026
fast/events/keydown-leftright-keys.html
......
2013-02-08 Eric Carlson <eric.carlson@apple.com>
[Mac] respect in-band caption color
https://bugs.webkit.org/show_bug.cgi?id=109203
Reviewed by Dean Jackson.
Test: media/track/track-in-band-style.html
* WebCore.xcodeproj/project.pbxproj: Add HTMLDivElement.h to private headers because it is
included by HTMLTextElement, which is included by HTMLMediaElement.h, which is included
by files in WebKit/WebKit2.
* html/track/InbandTextTrack.cpp:
(WebCore::InbandTextTrack::addGenericCue): Set cue colors if necessary.
* html/track/TextTrackCue.h:
(WebCore::TextTrackCue::element): New, accessor for the cue element so it can be styled.
* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties): Set container and cue background
color if necessary.
(WebCore::TextTrackCueGeneric::operator==): Compare cue colors.
* html/track/TextTrackCueGeneric.h:
(WebCore::TextTrackCueGeneric::foregroundColor): Add color accessors.
(WebCore::TextTrackCueGeneric::setForegroundColor):
(WebCore::TextTrackCueGeneric::backgroundColor):
(WebCore::TextTrackCueGeneric::setBackgroundColor):
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks): Always
regenerate override CSS when an element registers for callbacks.
(WebCore::CaptionUserPreferencesMac::captionsWindowCSS): Drive by fix of "window color" padding.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Log the stylesheet generated
for easier debugging.
* platform/graphics/InbandTextTrackPrivateClient.h:
(WebCore::GenericCueData::foregroundColor): Add color getters/setters.
(WebCore::GenericCueData::setForegroundColor):
(WebCore::GenericCueData::backgroundColor):
(WebCore::GenericCueData::setBackgroundColor):
* platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
(WebCore::makeRGBA32FromARGBCFArray): Initialize a RGBA32 from a CFArray of color values.
(WebCore::InbandTextTrackPrivateAVF::processCueAttributes): Process cue colors.
2013-02-08 Benjamin Poulain <bpoulain@apple.com>
 
Move workerThreadCount from TestRunner to WebCore Internals
......@@ -127,6 +127,11 @@ void InbandTextTrack::addGenericCue(InbandTextTrackPrivate* trackPrivate, Generi
cue->setLine(lround(cueData->line()), IGNORE_EXCEPTION);
if (cueData->size() > 0)
cue->setSize(lround(cueData->size()), IGNORE_EXCEPTION);
if (cueData->backgroundColor().isValid())
cue->setBackgroundColor(cueData->backgroundColor().rgb());
if (cueData->foregroundColor().isValid())
cue->setForegroundColor(cueData->foregroundColor().rgb());
if (cueData->align() == GenericCueData::Start)
cue->setAlign(ASCIILiteral("start"), IGNORE_EXCEPTION);
else if (cueData->align() == GenericCueData::Middle)
......
......@@ -35,6 +35,7 @@
#if ENABLE(VIDEO_TRACK)
#include "EventTarget.h"
#include "HTMLDivElement.h"
#include "HTMLElement.h"
#include "TextTrack.h"
#include <wtf/PassOwnPtr.h>
......@@ -43,7 +44,6 @@
namespace WebCore {
class DocumentFragment;
class HTMLDivElement;
class ScriptExecutionContext;
class TextTrack;
class TextTrackCue;
......@@ -141,6 +141,8 @@ public:
void setIsActive(bool);
PassRefPtr<TextTrackCueBox> getDisplayTree(const IntSize& videoSize);
PassRefPtr<HTMLDivElement> element() const { return m_allDocumentNodes; }
void updateDisplayTree(float);
void removeDisplayTree();
void markFutureAndPastNodes(ContainerNode*, double, double);
......
......@@ -80,6 +80,12 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
setInlineStyleProperty(CSSPropertyHeight, size, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (cue->foregroundColor().isValid())
setInlineStyleProperty(CSSPropertyColor, cue->foregroundColor().serialized());
if (cue->backgroundColor().isValid())
cue->element()->setInlineStyleProperty(CSSPropertyBackgroundColor, cue->backgroundColor().serialized());
if (cue->getWritingDirection() == TextTrackCue::Horizontal)
setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
else
......@@ -142,6 +148,10 @@ bool TextTrackCueGeneric::operator==(const TextTrackCue& cue) const
return false;
if (m_fontName != other->fontName())
return false;
if (m_foregroundColor != other->foregroundColor())
return false;
if (m_backgroundColor != other->backgroundColor())
return false;
return TextTrackCue::operator==(cue);
}
......
......@@ -28,7 +28,7 @@
#if ENABLE(VIDEO_TRACK)
#include "HTMLElement.h"
#include "Color.h"
#include "TextTrackCue.h"
#include <wtf/RefCounted.h>
......@@ -62,6 +62,12 @@ public:
String fontName() const { return m_fontName; }
void setFontName(String name) { m_fontName = name; }
Color foregroundColor() const { return m_foregroundColor; }
void setForegroundColor(RGBA32 color) { m_foregroundColor.setRGB(color); }
Color backgroundColor() const { return m_backgroundColor; }
void setBackgroundColor(RGBA32 color) { m_backgroundColor.setRGB(color); }
virtual bool operator==(const TextTrackCue&) const OVERRIDE;
virtual bool operator!=(const TextTrackCue& cue) const OVERRIDE
{
......@@ -73,6 +79,8 @@ public:
private:
TextTrackCueGeneric(ScriptExecutionContext*, double start, double end, const String&);
Color m_foregroundColor;
Color m_backgroundColor;
double m_baseFontSizeRelativeToVideoHeight;
double m_fontSizeMultiplier;
String m_fontName;
......
......@@ -36,9 +36,7 @@
#import "KURL.h"
#import "Language.h"
#import "LocalizedStrings.h"
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#import "MediaAccessibility/MediaAccessibility.h"
#endif
#import "Logging.h"
#import "PageGroup.h"
#import "SoftLinking.h"
#import "TextTrackCue.h"
......@@ -46,6 +44,10 @@
#import <wtf/RetainPtr.h>
#import <wtf/text/StringBuilder.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#import "MediaAccessibility/MediaAccessibility.h"
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
SOFT_LINK_FRAMEWORK_OPTIONAL(MediaAccessibility)
......@@ -114,13 +116,13 @@ void CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks(Ca
if (!kMAXCaptionAppearanceSettingsChangedNotification)
return;
if (!m_listeningForPreferenceChanges) {
m_listeningForPreferenceChanges = true;
CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, NULL, CFNotificationSuspensionBehaviorCoalesce);
updateCaptionStyleSheetOveride();
}
updateCaptionStyleSheetOveride();
m_captionPreferenceChangeListeners.add(listener);
}
......@@ -148,10 +150,7 @@ String CaptionUserPreferencesMac::captionsWindowCSS() const
StringBuilder builder;
builder.append(windowStyle);
builder.append(getPropertyNameString(CSSPropertyPadding));
builder.append(": .2em");
if (behavior == kMACaptionAppearanceBehaviorUseValue)
builder.append(" !important");
builder.append(';');
builder.append(": .4em !important;");
return builder.toString();
}
......@@ -368,6 +367,8 @@ String CaptionUserPreferencesMac::captionsStyleSheetOverride() const
captionsOverrideStyleSheet.append('}');
}
LOG(Media, "CaptionUserPreferencesMac::captionsStyleSheetOverrideSetting sytle to:\n%s", captionsOverrideStyleSheet.toString().utf8().data());
return captionsOverrideStyleSheet.toString();
}
......
......@@ -26,6 +26,7 @@
#ifndef InbandTextTrackPrivateClient_h
#define InbandTextTrackPrivateClient_h
#include "Color.h"
#include <wtf/Noncopyable.h>
#include <wtf/text/WTFString.h>
......@@ -89,7 +90,13 @@ public:
double relativeFontSize() const { return m_relativeFontSize; }
void setRelativeFontSize(double relativeFontSize) { m_relativeFontSize = relativeFontSize; }
Color foregroundColor() const { return m_foregroundColor; }
void setForegroundColor(RGBA32 color) { m_foregroundColor.setRGB(color); }
Color backgroundColor() const { return m_backgroundColor; }
void setBackgroundColor(RGBA32 color) { m_backgroundColor.setRGB(color); }
private:
double m_startTime;
double m_endTime;
......@@ -102,6 +109,8 @@ private:
String m_fontName;
double m_baseFontSize;
double m_relativeFontSize;
Color m_foregroundColor;
Color m_backgroundColor;
};
class InbandTextTrackPrivateClient {
......
......@@ -57,6 +57,8 @@ SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextVerticalLayout_RightToLeft, CFStrin
SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextMarkupAttribute_BaseFontSizePercentageRelativeToVideoHeight, CFStringRef)
SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextMarkupAttribute_RelativeFontSize, CFStringRef)
SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextMarkupAttribute_FontFamilyName, CFStringRef)
SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextMarkupAttribute_ForegroundColorARGB, CFStringRef)
SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextMarkupAttribute_BackgroundColorARGB, CFStringRef)
#define kCMTextMarkupAttribute_Alignment getkCMTextMarkupAttribute_Alignment()
#define kCMTextMarkupAlignmentType_Start getkCMTextMarkupAlignmentType_Start()
......@@ -74,6 +76,8 @@ SOFT_LINK_POINTER_OPTIONAL(CoreMedia, kCMTextMarkupAttribute_FontFamilyName, CFS
#define kCMTextMarkupAttribute_BaseFontSizePercentageRelativeToVideoHeight getkCMTextMarkupAttribute_BaseFontSizePercentageRelativeToVideoHeight()
#define kCMTextMarkupAttribute_RelativeFontSize getkCMTextMarkupAttribute_RelativeFontSize()
#define kCMTextMarkupAttribute_FontFamilyName getkCMTextMarkupAttribute_FontFamilyName()
#define kCMTextMarkupAttribute_ForegroundColorARGB getkCMTextMarkupAttribute_ForegroundColorARGB()
#define kCMTextMarkupAttribute_BackgroundColorARGB getkCMTextMarkupAttribute_BackgroundColorARGB()
using namespace std;
......@@ -92,6 +96,26 @@ InbandTextTrackPrivateAVF::~InbandTextTrackPrivateAVF()
disconnect();
}
static bool makeRGBA32FromARGBCFArray(CFArrayRef colorArray, RGBA32& color)
{
if (CFArrayGetCount(colorArray) < 4)
return false;
float componentArray[4];
for (int i = 0; i < 4; i++) {
CFNumberRef value = static_cast<CFNumberRef>(CFArrayGetValueAtIndex(colorArray, i));
if (CFGetTypeID(value) != CFNumberGetTypeID())
return false;
float component;
CFNumberGetValue(value, kCFNumberFloatType, &component);
componentArray[i] = component;
}
color = makeRGBA32FromFloats(componentArray[1] * 255, componentArray[2] * 255, componentArray[3] * 255, componentArray[0] * 255);
return true;
}
void InbandTextTrackPrivateAVF::processCueAttributes(CFAttributedStringRef attributedString, GenericCueData* cueData)
{
// Some of the attributes we translate into per-cue WebVTT settings are are repeated on each part of an attributed string so only
......@@ -267,6 +291,28 @@ void InbandTextTrackPrivateAVF::processCueAttributes(CFAttributedStringRef attri
cueData->setFontName(valueString);
continue;
}
if (CFStringCompare(key, kCMTextMarkupAttribute_ForegroundColorARGB, 0) == kCFCompareEqualTo) {
CFArrayRef arrayValue = static_cast<CFArrayRef>(value);
if (CFGetTypeID(arrayValue) != CFArrayGetTypeID())
continue;
RGBA32 color;
if (!makeRGBA32FromARGBCFArray(arrayValue, color))
continue;
cueData->setForegroundColor(color);
}
if (CFStringCompare(key, kCMTextMarkupAttribute_BackgroundColorARGB, 0) == kCFCompareEqualTo) {
CFArrayRef arrayValue = static_cast<CFArrayRef>(value);
if (CFGetTypeID(arrayValue) != CFArrayGetTypeID())
continue;
RGBA32 color;
if (!makeRGBA32FromARGBCFArray(arrayValue, color))
continue;
cueData->setBackgroundColor(color);
}
}
content.append(tagStart);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment