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

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: Rebased 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
« no previous file with comments | « Source/core/html/track/TextTrackRegionList.idl ('k') | Source/core/html/track/WebVTTParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
68 #endif
69 Id, 65 Id,
70 TimingsAndSettings, 66 TimingsAndSettings,
71 CueText, 67 CueText,
72 BadCue 68 BadCue
73 }; 69 };
74 70
75 static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, Execution Context* context) 71 static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, Execution Context* context)
76 { 72 {
77 return adoptPtr(new WebVTTParser(client, context)); 73 return adoptPtr(new WebVTTParser(client, context));
78 } 74 }
(...skipping 14 matching lines...) Expand all
93 } 89 }
94 static inline bool isValidSettingDelimiter(char c) 90 static inline bool isValidSettingDelimiter(char c)
95 { 91 {
96 // ... a WebVTT cue consists of zero or more of the following components , in any order, separated from each other by one or more 92 // ... 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. 93 // U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characte rs.
98 return c == ' ' || c == '\t'; 94 return c == ' ' || c == '\t';
99 } 95 }
100 static String collectDigits(const String&, unsigned*); 96 static String collectDigits(const String&, unsigned*);
101 static String collectWord(const String&, unsigned*); 97 static String collectWord(const String&, unsigned*);
102 98
103 #if ENABLE(WEBVTT_REGIONS)
104 // Useful functions for parsing percentage settings. 99 // Useful functions for parsing percentage settings.
105 static float parseFloatPercentageValue(const String&, bool&); 100 static float parseFloatPercentageValue(const String&, bool&);
106 static FloatPoint parseFloatPercentageValuePair(const String&, char, bool&); 101 static FloatPoint parseFloatPercentageValuePair(const String&, char, bool&);
107 #endif
108 102
109 // Input data to the parser to parse. 103 // Input data to the parser to parse.
110 void parseBytes(const char* data, unsigned length); 104 void parseBytes(const char* data, unsigned length);
111 105
112 // Transfers ownership of last parsed cues to caller. 106 // Transfers ownership of last parsed cues to caller.
113 void getNewCues(Vector<RefPtr<TextTrackCue> >&); 107 void getNewCues(Vector<RefPtr<TextTrackCue> >&);
114 #if ENABLE(WEBVTT_REGIONS)
115 void getNewRegions(Vector<RefPtr<TextTrackRegion> >&); 108 void getNewRegions(Vector<RefPtr<TextTrackRegion> >&);
116 #endif
117 109
118 PassRefPtr<DocumentFragment> createDocumentFragmentFromCueText(const String& ); 110 PassRefPtr<DocumentFragment> createDocumentFragmentFromCueText(const String& );
119 double collectTimeStamp(const String&, unsigned*); 111 double collectTimeStamp(const String&, unsigned*);
120 112
121 protected: 113 protected:
122 WebVTTParser(WebVTTParserClient*, ExecutionContext*); 114 WebVTTParser(WebVTTParserClient*, ExecutionContext*);
123 115
124 ExecutionContext* m_executionContext; 116 ExecutionContext* m_executionContext;
125 ParseState m_state; 117 ParseState m_state;
126 118
127 private: 119 private:
128 bool hasRequiredFileIdentifier(); 120 bool hasRequiredFileIdentifier();
129 ParseState collectCueId(const String&); 121 ParseState collectCueId(const String&);
130 ParseState collectTimingsAndSettings(const String&); 122 ParseState collectTimingsAndSettings(const String&);
131 ParseState collectCueText(const String&, unsigned length, unsigned); 123 ParseState collectCueText(const String&, unsigned length, unsigned);
132 ParseState ignoreBadCue(const String&); 124 ParseState ignoreBadCue(const String&);
133 125
134 void createNewCue(); 126 void createNewCue();
135 void resetCueValues(); 127 void resetCueValues();
136 128
137 #if ENABLE(WEBVTT_REGIONS) 129 void collectMetadataHeader(const String&);
138 void collectHeader(const String&);
139 void createNewRegion(); 130 void createNewRegion();
140 #endif
141 131
142 void skipWhiteSpace(const String&, unsigned*); 132 void skipWhiteSpace(const String&, unsigned*);
143 static void skipLineTerminator(const char* data, unsigned length, unsigned*) ; 133 static void skipLineTerminator(const char* data, unsigned length, unsigned*) ;
144 static String collectNextLine(const char* data, unsigned length, unsigned*); 134 static String collectNextLine(const char* data, unsigned length, unsigned*);
145 135
146 void constructTreeFromToken(Document&); 136 void constructTreeFromToken(Document&);
147 137
148 String m_currentHeaderName; 138 String m_currentHeaderName;
149 String m_currentHeaderValue; 139 String m_currentHeaderValue;
150 140
151 Vector<char> m_identifierData; 141 Vector<char> m_identifierData;
152 String m_currentId; 142 String m_currentId;
153 double m_currentStartTime; 143 double m_currentStartTime;
154 double m_currentEndTime; 144 double m_currentEndTime;
155 StringBuilder m_currentContent; 145 StringBuilder m_currentContent;
156 String m_currentSettings; 146 String m_currentSettings;
157 147
158 WebVTTToken m_token; 148 WebVTTToken m_token;
159 OwnPtr<WebVTTTokenizer> m_tokenizer; 149 OwnPtr<WebVTTTokenizer> m_tokenizer;
160 150
161 RefPtr<ContainerNode> m_currentNode; 151 RefPtr<ContainerNode> m_currentNode;
162 152
163 WebVTTParserClient* m_client; 153 WebVTTParserClient* m_client;
164 154
165 Vector<AtomicString> m_languageStack; 155 Vector<AtomicString> m_languageStack;
166 Vector<RefPtr<TextTrackCue> > m_cuelist; 156 Vector<RefPtr<TextTrackCue> > m_cuelist;
167 157
168 #if ENABLE(WEBVTT_REGIONS)
169 Vector<RefPtr<TextTrackRegion> > m_regionList; 158 Vector<RefPtr<TextTrackRegion> > m_regionList;
170 #endif
171 }; 159 };
172 160
173 } // namespace WebCore 161 } // namespace WebCore
174 162
175 #endif 163 #endif
OLDNEW
« no previous file with comments | « Source/core/html/track/TextTrackRegionList.idl ('k') | Source/core/html/track/WebVTTParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698