OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #ifndef VTTParser_h | 31 #ifndef VTTParser_h |
32 #define VTTParser_h | 32 #define VTTParser_h |
33 | 33 |
34 #include "core/HTMLNames.h" | 34 #include "core/HTMLNames.h" |
35 #include "core/dom/DocumentFragment.h" | 35 #include "core/dom/DocumentFragment.h" |
36 #include "core/html/parser/TextResourceDecoder.h" | 36 #include "core/html/parser/TextResourceDecoder.h" |
37 #include "core/html/track/vtt/BufferedLineReader.h" | 37 #include "core/html/track/vtt/BufferedLineReader.h" |
38 #include "core/html/track/vtt/VTTCue.h" | 38 #include "core/html/track/vtt/VTTCue.h" |
39 #include "core/html/track/vtt/VTTRegion.h" | |
40 #include "core/html/track/vtt/VTTTokenizer.h" | 39 #include "core/html/track/vtt/VTTTokenizer.h" |
41 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
42 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
43 #include <memory> | 42 #include <memory> |
44 | 43 |
45 namespace blink { | 44 namespace blink { |
46 | 45 |
47 class Document; | 46 class Document; |
48 class VTTScanner; | 47 class VTTScanner; |
49 | 48 |
50 class VTTParserClient : public GarbageCollectedMixin { | 49 class VTTParserClient : public GarbageCollectedMixin { |
51 public: | 50 public: |
52 virtual ~VTTParserClient() {} | 51 virtual ~VTTParserClient() {} |
53 | 52 |
54 virtual void newCuesParsed() = 0; | 53 virtual void newCuesParsed() = 0; |
55 virtual void newRegionsParsed() = 0; | |
56 virtual void fileFailedToParse() = 0; | 54 virtual void fileFailedToParse() = 0; |
57 | 55 |
58 DEFINE_INLINE_VIRTUAL_TRACE() {} | 56 DEFINE_INLINE_VIRTUAL_TRACE() {} |
59 }; | 57 }; |
60 | 58 |
61 // Implementation of the WebVTT parser algorithm. | 59 // Implementation of the WebVTT parser algorithm. |
62 // https://w3c.github.io/webvtt/#webvtt-parser-algorithm | 60 // https://w3c.github.io/webvtt/#webvtt-parser-algorithm |
63 class VTTParser final : public GarbageCollectedFinalized<VTTParser> { | 61 class VTTParser final : public GarbageCollectedFinalized<VTTParser> { |
64 public: | 62 public: |
65 enum ParseState { Initial, Header, Id, TimingsAndSettings, CueText, BadCue }; | 63 enum ParseState { Initial, Header, Id, TimingsAndSettings, CueText, BadCue }; |
(...skipping 30 matching lines...) Expand all Loading... |
96 // Create the DocumentFragment representation of the WebVTT cue text. | 94 // Create the DocumentFragment representation of the WebVTT cue text. |
97 static DocumentFragment* createDocumentFragmentFromCueText(Document&, | 95 static DocumentFragment* createDocumentFragmentFromCueText(Document&, |
98 const String&); | 96 const String&); |
99 | 97 |
100 // Input data to the parser to parse. | 98 // Input data to the parser to parse. |
101 void parseBytes(const char* data, size_t length); | 99 void parseBytes(const char* data, size_t length); |
102 void flush(); | 100 void flush(); |
103 | 101 |
104 // Transfers ownership of last parsed cues to caller. | 102 // Transfers ownership of last parsed cues to caller. |
105 void getNewCues(HeapVector<Member<TextTrackCue>>&); | 103 void getNewCues(HeapVector<Member<TextTrackCue>>&); |
106 void getNewRegions(HeapVector<Member<VTTRegion>>&); | |
107 | 104 |
108 DECLARE_TRACE(); | 105 DECLARE_TRACE(); |
109 | 106 |
110 private: | 107 private: |
111 VTTParser(VTTParserClient*, Document&); | 108 VTTParser(VTTParserClient*, Document&); |
112 | 109 |
113 Member<Document> m_document; | 110 Member<Document> m_document; |
114 ParseState m_state; | 111 ParseState m_state; |
115 | 112 |
116 void parse(); | 113 void parse(); |
(...skipping 19 matching lines...) Expand all Loading... |
136 double m_currentStartTime; | 133 double m_currentStartTime; |
137 double m_currentEndTime; | 134 double m_currentEndTime; |
138 StringBuilder m_currentContent; | 135 StringBuilder m_currentContent; |
139 String m_currentSettings; | 136 String m_currentSettings; |
140 | 137 |
141 Member<VTTParserClient> m_client; | 138 Member<VTTParserClient> m_client; |
142 | 139 |
143 HeapVector<Member<TextTrackCue>> m_cueList; | 140 HeapVector<Member<TextTrackCue>> m_cueList; |
144 | 141 |
145 VTTRegionMap m_regionMap; | 142 VTTRegionMap m_regionMap; |
146 HeapVector<Member<VTTRegion>> m_regionList; | |
147 }; | 143 }; |
148 | 144 |
149 } // namespace blink | 145 } // namespace blink |
150 | 146 |
151 #endif | 147 #endif |
OLD | NEW |