summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/track/WebVTTParser.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/track/WebVTTParser.h')
-rw-r--r--Source/WebCore/html/track/WebVTTParser.h128
1 files changed, 50 insertions, 78 deletions
diff --git a/Source/WebCore/html/track/WebVTTParser.h b/Source/WebCore/html/track/WebVTTParser.h
index eb27d7930..69ac0552a 100644
--- a/Source/WebCore/html/track/WebVTTParser.h
+++ b/Source/WebCore/html/track/WebVTTParser.h
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2013 Google Inc. All rights reserved.
* Copyright (C) 2013 Cable Television Labs, Inc.
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,16 +30,18 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef WebVTTParser_h
-#define WebVTTParser_h
+#pragma once
#if ENABLE(VIDEO_TRACK)
+#include "BufferedLineReader.h"
#include "DocumentFragment.h"
#include "HTMLNames.h"
-#include "TextTrackRegion.h"
+#include "TextResourceDecoder.h"
+#include "VTTRegion.h"
#include "WebVTTTokenizer.h"
-#include <wtf/PassOwnPtr.h>
+#include <memory>
+#include <wtf/MediaTime.h>
#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -46,29 +49,29 @@ namespace WebCore {
using namespace HTMLNames;
class Document;
+class ISOWebVTTCue;
+class VTTScanner;
class WebVTTParserClient {
public:
virtual ~WebVTTParserClient() { }
virtual void newCuesParsed() = 0;
-#if ENABLE(WEBVTT_REGIONS)
virtual void newRegionsParsed() = 0;
-#endif
virtual void fileFailedToParse() = 0;
};
-class WebVTTCueData : public RefCounted<WebVTTCueData> {
+class WebVTTCueData final : public RefCounted<WebVTTCueData> {
public:
- static PassRefPtr<WebVTTCueData> create() { return adoptRef(new WebVTTCueData()); }
- virtual ~WebVTTCueData() { }
+ static Ref<WebVTTCueData> create() { return adoptRef(*new WebVTTCueData()); }
+ ~WebVTTCueData() { }
- double startTime() const { return m_startTime; }
- void setStartTime(double startTime) { m_startTime = startTime; }
+ MediaTime startTime() const { return m_startTime; }
+ void setStartTime(const MediaTime& startTime) { m_startTime = startTime; }
- double endTime() const { return m_endTime; }
- void setEndTime(double endTime) { m_endTime = endTime; }
+ MediaTime endTime() const { return m_endTime; }
+ void setEndTime(const MediaTime& endTime) { m_endTime = endTime; }
String id() const { return m_id; }
void setId(String id) { m_id = id; }
@@ -79,30 +82,25 @@ public:
String settings() const { return m_settings; }
void setSettings(String settings) { m_settings = settings; }
+ MediaTime originalStartTime() const { return m_originalStartTime; }
+ void setOriginalStartTime(const MediaTime& time) { m_originalStartTime = time; }
+
private:
- WebVTTCueData()
- : m_startTime(0)
- , m_endTime(0)
- {
- }
+ WebVTTCueData() { }
- double m_startTime;
- double m_endTime;
+ MediaTime m_startTime;
+ MediaTime m_endTime;
+ MediaTime m_originalStartTime;
String m_id;
String m_content;
String m_settings;
};
-class WebVTTParser {
+class WebVTTParser final {
public:
- virtual ~WebVTTParser() { }
-
enum ParseState {
Initial,
Header,
-#if ENABLE(WEBVTT_REGIONS)
- Metadata,
-#endif
Id,
TimingsAndSettings,
CueText,
@@ -110,11 +108,8 @@ public:
Finished
};
- static OwnPtr<WebVTTParser> create(WebVTTParserClient* client, ScriptExecutionContext* context)
- {
- return adoptPtr(new WebVTTParser(client, context));
- }
-
+ WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*);
+
static inline bool isRecognizedTag(const AtomicString& tagName)
{
return tagName == iTag
@@ -124,91 +119,68 @@ public:
|| tagName == rtTag;
}
- static inline bool isASpace(char c)
- {
- // WebVTT space characters are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and U+000D CARRIAGE RETURN (CR).
- return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r';
- }
- static inline bool isValidSettingDelimiter(char c)
+ static inline bool isValidSettingDelimiter(UChar c)
{
// ... a WebVTT cue consists of zero or more of the following components, in any order, separated from each other by one or more
// U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters.
return c == ' ' || c == '\t';
}
- static String collectDigits(const String&, unsigned*);
- static String collectWord(const String&, unsigned*);
+ static bool collectTimeStamp(const String&, MediaTime&);
-#if ENABLE(WEBVTT_REGIONS)
// Useful functions for parsing percentage settings.
- static float parseFloatPercentageValue(const String&, bool&);
- static FloatPoint parseFloatPercentageValuePair(const String&, char, bool&);
-#endif
+ static bool parseFloatPercentageValue(VTTScanner& valueScanner, float&);
+ static bool parseFloatPercentageValuePair(VTTScanner& valueScanner, char, FloatPoint&);
// Input data to the parser to parse.
- void parseBytes(const char* data, unsigned length);
+ void parseBytes(const char*, unsigned);
+ void parseFileHeader(String&&);
+ void parseCueData(const ISOWebVTTCue&);
+ void flush();
void fileFinished();
// Transfers ownership of last parsed cues to caller.
void getNewCues(Vector<RefPtr<WebVTTCueData>>&);
-#if ENABLE(WEBVTT_REGIONS)
- void getNewRegions(Vector<RefPtr<TextTrackRegion>>&);
-#endif
+ void getNewRegions(Vector<RefPtr<VTTRegion>>&);
- PassRefPtr<DocumentFragment> createDocumentFragmentFromCueText(const String&);
- double collectTimeStamp(const String&, unsigned*);
+ // Create the DocumentFragment representation of the WebVTT cue text.
+ static Ref<DocumentFragment> createDocumentFragmentFromCueText(Document&, const String&);
protected:
- WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*);
-
ScriptExecutionContext* m_scriptExecutionContext;
ParseState m_state;
private:
+ void parse();
+ void flushPendingCue();
bool hasRequiredFileIdentifier(const String&);
ParseState collectCueId(const String&);
ParseState collectTimingsAndSettings(const String&);
ParseState collectCueText(const String&);
+ ParseState recoverCue(const String&);
ParseState ignoreBadCue(const String&);
void createNewCue();
void resetCueValues();
-#if ENABLE(WEBVTT_REGIONS)
- void collectHeader(const String&);
- void createNewRegion();
-#endif
+ void collectMetadataHeader(const String&);
+ void createNewRegion(const String& headerValue);
- void skipWhiteSpace(const String&, unsigned*);
- String collectNextLine(const char* data, unsigned length, unsigned*);
+ static bool collectTimeStamp(VTTScanner& input, MediaTime& timeStamp);
- void constructTreeFromToken(Document*);
-
- String m_currentHeaderName;
- String m_currentHeaderValue;
-
- Vector<char> m_buffer;
+ BufferedLineReader m_lineReader;
+ RefPtr<TextResourceDecoder> m_decoder;
String m_currentId;
- double m_currentStartTime;
- double m_currentEndTime;
+ MediaTime m_currentStartTime;
+ MediaTime m_currentEndTime;
StringBuilder m_currentContent;
String m_currentSettings;
-
- WebVTTToken m_token;
- OwnPtr<WebVTTTokenizer> m_tokenizer;
-
- RefPtr<ContainerNode> m_currentNode;
WebVTTParserClient* m_client;
- Vector<AtomicString> m_languageStack;
Vector<RefPtr<WebVTTCueData>> m_cuelist;
-
-#if ENABLE(WEBVTT_REGIONS)
- Vector<RefPtr<TextTrackRegion>> m_regionList;
-#endif
+ Vector<RefPtr<VTTRegion>> m_regionList;
};
} // namespace WebCore
-#endif
-#endif
+#endif // ENABLE(VIDEO_TRACK)