Commit 776c2773 authored by vcarbune@chromium.org's avatar vcarbune@chromium.org
Browse files

TextTrackCue Extension for WebVTT Regions

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

Reviewed by Eric Carlson.

Source/WebCore:

The TextTrackCue gets a new attribute and setting, regionId, which specifies
to which region the cue belongs to. The attribute is guarded by WEBVTT_REGIONS
and is by default disabled in ports.

Test: media/track/regions-webvtt/text-track-cue-region-attribute.html

* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::TextTrackCue): Added member variable for the regionId attribute.
(WebCore):
(WebCore::TextTrackCue::setRegionId): Setter for the regionId attribute.
(WebCore::TextTrackCue::settingName): Added RegionId setting name.
(WebCore::TextTrackCue::setCueSettings): Parsed the "region:" cue setting.
* html/track/TextTrackCue.h:
(TextTrackCue):
(WebCore::TextTrackCue::regionId): Getter for the regionId attribute.
* html/track/TextTrackCue.idl: Updated to match the WebVTT Regions Extension.

LayoutTests:

* media/track/captions-webvtt/header-regions.vtt: Updated to include cues with
settings for which the "region:" setting should be ignored (for backwards compatibility
regarding WebVTT rendering rules).
* media/track/regions-webvtt/text-track-cue-region-attribute-expected.txt: Added.
* media/track/regions-webvtt/text-track-cue-region-attribute.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147355 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c4232f57
2013-04-01 Victor Carbune <vcarbune@chromium.org>
TextTrackCue Extension for WebVTT Regions
https://bugs.webkit.org/show_bug.cgi?id=109821
Reviewed by Eric Carlson.
* media/track/captions-webvtt/header-regions.vtt: Updated to include cues with
settings for which the "region:" setting should be ignored (for backwards compatibility
regarding WebVTT rendering rules).
* media/track/regions-webvtt/text-track-cue-region-attribute-expected.txt: Added.
* media/track/regions-webvtt/text-track-cue-region-attribute.html: Added.
2013-04-01 Nate Chapin <japhet@chromium.org>
 
Unreviewed, chromium gardening.
......@@ -8,5 +8,17 @@ Region: invalid_settings values but region still created
: Invalid Header
1
00:00:00.000 --> 00:00:02.500
00:00:00.000 --> 00:00:02.500 region:someregionattributeid
We are in New York City
2
00:00:00.000 --> 00:00:02.500 line:5 region:ignored_attribute_value
Line is specified, Region should be ignored.
3
00:00:00.000 --> 00:00:02.500 size:10% region:ignored_attribute_value
Size is specified, Region should be ignored.
4
00:00:00.000 --> 00:00:02.500 vertical:lr region:ignored_attribute_value
Vertical is specified, Region should be ignored.
Tests the regionId attribute of a cue.
** Test the setter and getter through the JS API **
EXPECTED (cue.regionId == '') OK
EXPECTED (cue.regionId == 'someId') OK
** Test parsing a region attribute of a cue **
EXPECTED (cue.regionId == 'someregionattributeid') OK
** Test that region attribute is ignored if either line position or cue size are specified or writing direction is not horizontal **
EXPECTED (cue.regionId == '') OK
EXPECTED (cue.regionId == '') OK
EXPECTED (cue.regionId == '') 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>
var cue;
function startTest()
{
if (!window.TextTrackRegion) {
failTest();
return;
}
consoleWrite("<br>** Test the setter and getter through the JS API **");
cue = new TextTrackCue(0.0, 1.0, "sample");
testExpected("cue.regionId", "");
cue.regionId = "someId";
testExpected("cue.regionId", "someId");
consoleWrite("<br>** Test parsing a region attribute of a cue **");
findMediaElement();
cue = video.textTracks[0].cues[0];
testExpected("cue.regionId", "someregionattributeid");
consoleWrite("<br>** Test that region attribute is ignored if either line position or cue size are specified or writing direction is not horizontal **");
for (i = 1; i < 4; ++i) {
cue = video.textTracks[0].cues[i];
testExpected("cue.regionId", "");
}
consoleWrite("");
endTest();
}
</script>
</head>
<body>
<p>Tests the regionId attribute of a cue.</p>
<video controls>
<track src="../captions-webvtt/header-regions.vtt" kind="captions" default onload="startTest()">
</video>
</body>
</html>
2013-04-01 Victor Carbune <vcarbune@chromium.org>
TextTrackCue Extension for WebVTT Regions
https://bugs.webkit.org/show_bug.cgi?id=109821
Reviewed by Eric Carlson.
The TextTrackCue gets a new attribute and setting, regionId, which specifies
to which region the cue belongs to. The attribute is guarded by WEBVTT_REGIONS
and is by default disabled in ports.
Test: media/track/regions-webvtt/text-track-cue-region-attribute.html
* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::TextTrackCue): Added member variable for the regionId attribute.
(WebCore):
(WebCore::TextTrackCue::setRegionId): Setter for the regionId attribute.
(WebCore::TextTrackCue::settingName): Added RegionId setting name.
(WebCore::TextTrackCue::setCueSettings): Parsed the "region:" cue setting.
* html/track/TextTrackCue.h:
(TextTrackCue):
(WebCore::TextTrackCue::regionId): Getter for the regionId attribute.
* html/track/TextTrackCue.idl: Updated to match the WebVTT Regions Extension.
2013-03-05 Anders Carlsson <andersca@apple.com>
 
Apply changes from storage events locally
......@@ -534,6 +534,18 @@ bool TextTrackCue::dispatchEvent(PassRefPtr<Event> event)
return EventTarget::dispatchEvent(event);
}
#if ENABLE(WEBVTT_REGIONS)
void TextTrackCue::setRegionId(const String& regionId)
{
if (m_regionId == regionId)
return;
cueWillChange();
m_regionId = regionId;
cueDidChange();
}
#endif
bool TextTrackCue::isActive()
{
return m_isActive && track() && track()->mode() != TextTrack::disabledKeyword();
......@@ -862,6 +874,9 @@ TextTrackCue::CueSetting TextTrackCue::settingName(const String& name)
DEFINE_STATIC_LOCAL(const String, positionKeyword, (ASCIILiteral("position")));
DEFINE_STATIC_LOCAL(const String, sizeKeyword, (ASCIILiteral("size")));
DEFINE_STATIC_LOCAL(const String, alignKeyword, (ASCIILiteral("align")));
#if ENABLE(WEBVTT_REGIONS)
DEFINE_STATIC_LOCAL(const String, regionIdKeyword, (ASCIILiteral("region")));
#endif
if (name == verticalKeyword)
return Vertical;
......@@ -873,6 +888,10 @@ TextTrackCue::CueSetting TextTrackCue::settingName(const String& name)
return Size;
else if (name == alignKeyword)
return Align;
#if ENABLE(WEBVTT_REGIONS)
else if (name == regionIdKeyword)
return RegionId;
#endif
return None;
}
......@@ -1066,6 +1085,11 @@ void TextTrackCue::setCueSettings(const String& input)
m_cueAlignment = End;
}
break;
#if ENABLE(WEBVTT_REGIONS)
case RegionId:
m_regionId = WebVTTParser::collectWord(input, &position);
break;
#endif
case None:
break;
}
......@@ -1073,6 +1097,16 @@ void TextTrackCue::setCueSettings(const String& input)
NextSetting:
position = endOfSetting;
}
#if ENABLE(WEBVTT_REGIONS)
// If cue's line position is not auto or cue's size is not 100 or cue's
// writing direction is not horizontal, but cue's region identifier is not
// the empty string, let cue's region identifier be the empty string.
if (m_regionId.isEmpty())
return;
if (m_linePosition != undefinedPosition || m_cueSize != 100 || m_writingDirection != Horizontal)
m_regionId = emptyString();
#endif
}
int TextTrackCue::getCSSWritingDirection() const
......
......@@ -135,6 +135,11 @@ public:
using EventTarget::dispatchEvent;
virtual bool dispatchEvent(PassRefPtr<Event>) OVERRIDE;
#if ENABLE(WEBVTT_REGIONS)
const String& regionId() const { return m_regionId; }
void setRegionId(const String&);
#endif
bool isActive();
void setIsActive(bool);
......@@ -204,6 +209,9 @@ protected:
PassRefPtr<TextTrackCueBox> displayTreeInternal();
private:
void createWebVTTNodeTree();
void copyWebVTTNodeToDOMTree(ContainerNode* WebVTTNode, ContainerNode* root);
std::pair<double, double> getPositionCoordinates() const;
void parseSettings(const String&);
......@@ -216,7 +224,17 @@ private:
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
enum CueSetting { None, Vertical, Line, Position, Size, Align };
enum CueSetting {
None,
Vertical,
Line,
Position,
Size,
Align,
#if ENABLE(WEBVTT_REGIONS)
RegionId
#endif
};
CueSetting settingName(const String&);
String m_id;
......@@ -257,9 +275,9 @@ private:
int m_displaySize;
std::pair<float, float> m_displayPosition;
void createWebVTTNodeTree();
void copyWebVTTNodeToDOMTree(ContainerNode* WebVTTNode, ContainerNode* root);
#if ENABLE(WEBVTT_REGIONS)
String m_regionId;
#endif
};
} // namespace WebCore
......
......@@ -57,10 +57,10 @@
attribute DOMString text;
DocumentFragment getCueAsHTML();
attribute EventListener onenter;
attribute EventListener onexit;
// EventTarget interface
void addEventListener(in DOMString type,
in EventListener listener,
......@@ -70,5 +70,9 @@
in [Optional] boolean useCapture);
boolean dispatchEvent(in Event evt)
raises(EventException);
#if defined(ENABLE_WEBVTT_REGIONS) && ENABLE_WEBVTT_REGIONS
attribute DOMString regionId;
#endif
};
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