Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: Source/core/html/track/WebVTTParser.h

Issue 25798003: Enable WebVTT regions for runtime testing, updated tests and minor fixes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revert Logging Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WebVTTParser_h 31 #ifndef WebVTTParser_h
32 #define WebVTTParser_h 32 #define WebVTTParser_h
33 33
34 #include "HTMLNames.h" 34 #include "HTMLNames.h"
35 #include "RuntimeEnabledFeatures.h"
35 #include "core/dom/DocumentFragment.h" 36 #include "core/dom/DocumentFragment.h"
36 #include "core/html/track/TextTrackCue.h" 37 #include "core/html/track/TextTrackCue.h"
37 #include "core/html/track/TextTrackRegion.h" 38 #include "core/html/track/TextTrackRegion.h"
38 #include "core/html/track/WebVTTTokenizer.h" 39 #include "core/html/track/WebVTTTokenizer.h"
39 #include "wtf/PassOwnPtr.h" 40 #include "wtf/PassOwnPtr.h"
40 #include "wtf/text/StringBuilder.h" 41 #include "wtf/text/StringBuilder.h"
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
44 using namespace HTMLNames; 45 using namespace HTMLNames;
45 46
46 class Document; 47 class Document;
47 48
48 class WebVTTParserClient { 49 class WebVTTParserClient {
49 public: 50 public:
50 virtual ~WebVTTParserClient() { } 51 virtual ~WebVTTParserClient() { }
51 52
52 virtual void newCuesParsed() = 0; 53 virtual void newCuesParsed() = 0;
53 #if ENABLE(WEBVTT_REGIONS)
54 virtual void newRegionsParsed() = 0; 54 virtual void newRegionsParsed() = 0;
55 #endif
56 virtual void fileFailedToParse() = 0; 55 virtual void fileFailedToParse() = 0;
57 }; 56 };
58 57
59 class WebVTTParser { 58 class WebVTTParser {
60 public: 59 public:
61 virtual ~WebVTTParser() { } 60 virtual ~WebVTTParser() { }
62 61
63 enum ParseState { 62 enum ParseState {
64 Initial, 63 Initial,
65 Header, 64 Header,
66 #if ENABLE(WEBVTT_REGIONS)
67 Metadata, 65 Metadata,
68 #endif
69 Id, 66 Id,
70 TimingsAndSettings, 67 TimingsAndSettings,
71 CueText, 68 CueText,
72 BadCue 69 BadCue
73 }; 70 };
74 71
75 static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, ScriptExe cutionContext* context) 72 static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, ScriptExe cutionContext* context)
76 { 73 {
77 return adoptPtr(new WebVTTParser(client, context)); 74 return adoptPtr(new WebVTTParser(client, context));
78 } 75 }
(...skipping 14 matching lines...) Expand all
93 } 90 }
94 static inline bool isValidSettingDelimiter(char c) 91 static inline bool isValidSettingDelimiter(char c)
95 { 92 {
96 // ... a WebVTT cue consists of zero or more of the following components , in any order, separated from each other by one or more 93 // ... a WebVTT cue consists of zero or more of the following components , in any order, separated from each other by one or more
97 // U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characte rs. 94 // U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characte rs.
98 return c == ' ' || c == '\t'; 95 return c == ' ' || c == '\t';
99 } 96 }
100 static String collectDigits(const String&, unsigned*); 97 static String collectDigits(const String&, unsigned*);
101 static String collectWord(const String&, unsigned*); 98 static String collectWord(const String&, unsigned*);
102 99
103 #if ENABLE(WEBVTT_REGIONS)
104 // Useful functions for parsing percentage settings. 100 // Useful functions for parsing percentage settings.
105 static float parseFloatPercentageValue(const String&, bool&); 101 static float parseFloatPercentageValue(const String&, bool&);
106 static FloatPoint parseFloatPercentageValuePair(const String&, char, bool&); 102 static FloatPoint parseFloatPercentageValuePair(const String&, char, bool&);
107 #endif
108 103
109 // Input data to the parser to parse. 104 // Input data to the parser to parse.
110 void parseBytes(const char* data, unsigned length); 105 void parseBytes(const char* data, unsigned length);
111 106
112 // Transfers ownership of last parsed cues to caller. 107 // Transfers ownership of last parsed cues to caller.
113 void getNewCues(Vector<RefPtr<TextTrackCue> >&); 108 void getNewCues(Vector<RefPtr<TextTrackCue> >&);
114 #if ENABLE(WEBVTT_REGIONS)
115 void getNewRegions(Vector<RefPtr<TextTrackRegion> >&); 109 void getNewRegions(Vector<RefPtr<TextTrackRegion> >&);
116 #endif
117 110
118 PassRefPtr<DocumentFragment> createDocumentFragmentFromCueText(const String& ); 111 PassRefPtr<DocumentFragment> createDocumentFragmentFromCueText(const String& );
119 double collectTimeStamp(const String&, unsigned*); 112 double collectTimeStamp(const String&, unsigned*);
120 113
121 protected: 114 protected:
122 WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*); 115 WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*);
123 116
124 ScriptExecutionContext* m_scriptExecutionContext; 117 ScriptExecutionContext* m_scriptExecutionContext;
125 ParseState m_state; 118 ParseState m_state;
126 119
127 private: 120 private:
128 bool hasRequiredFileIdentifier(); 121 bool hasRequiredFileIdentifier();
129 ParseState collectCueId(const String&); 122 ParseState collectCueId(const String&);
130 ParseState collectTimingsAndSettings(const String&); 123 ParseState collectTimingsAndSettings(const String&);
131 ParseState collectCueText(const String&, unsigned length, unsigned); 124 ParseState collectCueText(const String&, unsigned length, unsigned);
132 ParseState ignoreBadCue(const String&); 125 ParseState ignoreBadCue(const String&);
133 126
134 void createNewCue(); 127 void createNewCue();
135 void resetCueValues(); 128 void resetCueValues();
136 129
137 #if ENABLE(WEBVTT_REGIONS)
138 void collectHeader(const String&); 130 void collectHeader(const String&);
139 void createNewRegion(); 131 void createNewRegion();
140 #endif
141 132
142 void skipWhiteSpace(const String&, unsigned*); 133 void skipWhiteSpace(const String&, unsigned*);
143 static void skipLineTerminator(const char* data, unsigned length, unsigned*) ; 134 static void skipLineTerminator(const char* data, unsigned length, unsigned*) ;
144 static String collectNextLine(const char* data, unsigned length, unsigned*); 135 static String collectNextLine(const char* data, unsigned length, unsigned*);
145 136
146 void constructTreeFromToken(Document&); 137 void constructTreeFromToken(Document&);
147 138
148 String m_currentHeaderName; 139 String m_currentHeaderName;
149 String m_currentHeaderValue; 140 String m_currentHeaderValue;
150 141
151 Vector<char> m_identifierData; 142 Vector<char> m_identifierData;
152 String m_currentId; 143 String m_currentId;
153 double m_currentStartTime; 144 double m_currentStartTime;
154 double m_currentEndTime; 145 double m_currentEndTime;
155 StringBuilder m_currentContent; 146 StringBuilder m_currentContent;
156 String m_currentSettings; 147 String m_currentSettings;
157 148
158 WebVTTToken m_token; 149 WebVTTToken m_token;
159 OwnPtr<WebVTTTokenizer> m_tokenizer; 150 OwnPtr<WebVTTTokenizer> m_tokenizer;
160 151
161 RefPtr<ContainerNode> m_currentNode; 152 RefPtr<ContainerNode> m_currentNode;
162 153
163 WebVTTParserClient* m_client; 154 WebVTTParserClient* m_client;
164 155
165 Vector<AtomicString> m_languageStack; 156 Vector<AtomicString> m_languageStack;
166 Vector<RefPtr<TextTrackCue> > m_cuelist; 157 Vector<RefPtr<TextTrackCue> > m_cuelist;
167 158
168 #if ENABLE(WEBVTT_REGIONS)
169 Vector<RefPtr<TextTrackRegion> > m_regionList; 159 Vector<RefPtr<TextTrackRegion> > m_regionList;
170 #endif
171 }; 160 };
172 161
173 } // namespace WebCore 162 } // namespace WebCore
174 163
175 #endif 164 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698