| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 public: | 51 public: |
| 52 virtual ~VTTParserClient() { } | 52 virtual ~VTTParserClient() { } |
| 53 | 53 |
| 54 virtual void newCuesParsed() = 0; | 54 virtual void newCuesParsed() = 0; |
| 55 virtual void newRegionsParsed() = 0; | 55 virtual void newRegionsParsed() = 0; |
| 56 virtual void fileFailedToParse() = 0; | 56 virtual void fileFailedToParse() = 0; |
| 57 | 57 |
| 58 DEFINE_INLINE_VIRTUAL_TRACE() { } | 58 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Implementation of the WebVTT parser algorithm. |
| 62 // https://w3c.github.io/webvtt/#webvtt-parser-algorithm |
| 61 class VTTParser final : public GarbageCollectedFinalized<VTTParser> { | 63 class VTTParser final : public GarbageCollectedFinalized<VTTParser> { |
| 62 public: | 64 public: |
| 63 enum ParseState { | 65 enum ParseState { |
| 64 Initial, | 66 Initial, |
| 65 Header, | 67 Header, |
| 66 Id, | 68 Id, |
| 67 TimingsAndSettings, | 69 TimingsAndSettings, |
| 68 CueText, | 70 CueText, |
| 69 BadCue | 71 BadCue |
| 70 }; | 72 }; |
| 71 | 73 |
| 72 static VTTParser* create(VTTParserClient* client, Document& document) | 74 static VTTParser* create(VTTParserClient* client, Document& document) |
| 73 { | 75 { |
| 74 return new VTTParser(client, document); | 76 return new VTTParser(client, document); |
| 75 } | 77 } |
| 76 ~VTTParser() | 78 ~VTTParser() |
| 77 { | 79 { |
| 78 } | 80 } |
| 79 | 81 |
| 80 static inline bool isRecognizedTag(const AtomicString& tagName) | 82 static inline bool isRecognizedTag(const AtomicString& tagName) |
| 81 { | 83 { |
| 82 return tagName == HTMLNames::iTag | 84 return tagName == HTMLNames::iTag |
| 83 || tagName == HTMLNames::bTag | 85 || tagName == HTMLNames::bTag |
| 84 || tagName == HTMLNames::uTag | 86 || tagName == HTMLNames::uTag |
| 85 || tagName == HTMLNames::rubyTag | 87 || tagName == HTMLNames::rubyTag |
| 86 || tagName == HTMLNames::rtTag; | 88 || tagName == HTMLNames::rtTag; |
| 87 } | 89 } |
| 88 static inline bool isASpace(UChar c) | 90 static inline bool isASpace(UChar c) |
| 89 { | 91 { |
| 90 // 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). | 92 // WebVTT space characters are U+0020 SPACE, U+0009 CHARACTER |
| 93 // TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and |
| 94 // U+000D CARRIAGE RETURN (CR). |
| 91 return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'; | 95 return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'; |
| 92 } | 96 } |
| 93 static inline bool isValidSettingDelimiter(UChar c) | 97 static inline bool isValidSettingDelimiter(UChar c) |
| 94 { | 98 { |
| 95 // ... a WebVTT cue consists of zero or more of the following components
, in any order, separated from each other by one or more | 99 // ... a WebVTT cue consists of zero or more of the following components
, in any order, separated from each other by one or more |
| 96 // U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characte
rs. | 100 // U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characte
rs. |
| 97 return c == ' ' || c == '\t'; | 101 return c == ' ' || c == '\t'; |
| 98 } | 102 } |
| 99 static bool collectTimeStamp(const String&, double& timeStamp); | 103 static bool collectTimeStamp(const String&, double& timeStamp); |
| 100 | 104 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 Member<VTTParserClient> m_client; | 153 Member<VTTParserClient> m_client; |
| 150 | 154 |
| 151 HeapVector<Member<TextTrackCue>> m_cueList; | 155 HeapVector<Member<TextTrackCue>> m_cueList; |
| 152 | 156 |
| 153 HeapVector<Member<VTTRegion>> m_regionList; | 157 HeapVector<Member<VTTRegion>> m_regionList; |
| 154 }; | 158 }; |
| 155 | 159 |
| 156 } // namespace blink | 160 } // namespace blink |
| 157 | 161 |
| 158 #endif | 162 #endif |
| OLD | NEW |