Changeset 94011 in webkit
- Timestamp:
- Aug 29, 2011, 1:47:06 PM (15 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 12 edited
- 1 copied
-
CMakeLists.txt (modified) (1 diff)
-
ChangeLog (modified) (1 diff)
-
GNUmakefile.list.am (modified) (1 diff)
-
WebCore.gypi (modified) (1 diff)
-
WebCore.pro (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (5 diffs)
-
html/TextTrackCue.cpp (modified) (5 diffs)
-
html/TextTrackCue.h (modified) (4 diffs)
-
platform/track/CueParser.cpp (modified) (2 diffs)
-
platform/track/CueParser.h (modified) (1 diff)
-
platform/track/WebVTTParser.cpp (modified) (4 diffs)
-
platform/track/WebVTTParser.h (modified) (5 diffs)
-
platform/track/WebVTTToken.h (added)
-
platform/track/WebVTTTokenizer.cpp (added)
-
platform/track/WebVTTTokenizer.h (copied) (copied from trunk/Source/WebCore/platform/track/CueParser.h ) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r93744 r94011 2040 2040 platform/track/CueParser.cpp 2041 2041 platform/track/WebVTTParser.cpp 2042 platform/track/WebVTTTokenizer.cpp 2042 2043 ) 2043 2044 ENDIF() -
trunk/Source/WebCore/ChangeLog
r94010 r94011 1 2011-08-29 Anna Cavender <annacc@chromium.org> 2 3 Implement WebVTT Cue Text Parsing rules and DOM construction 4 https://bugs.webkit.org/show_bug.cgi?id=64132 5 6 Reviewed by Adam Barth. 7 8 Tests in media/track, particularly track-webvtt-tc[022 - 028]*. 9 10 * CMakeLists.txt: 11 * GNUmakefile.list.am: 12 * WebCore.gypi: 13 * WebCore.pro: 14 * WebCore.xcodeproj/project.pbxproj: 15 * html/TextTrackCue.cpp: 16 * html/TextTrackCue.h: 17 * platform/track/CueParser.cpp: 18 * platform/track/CueParser.h: 19 * platform/track/WebVTTParser.cpp: 20 * platform/track/WebVTTParser.h: 21 * platform/track/WebVTTToken.h: Added. 22 * platform/track/WebVTTTokenizer.cpp: Added. 23 * platform/track/WebVTTTokenizer.h: Added. 24 1 25 2011-08-29 Patrick Gansterer <paroga@webkit.org> 2 26 -
trunk/Source/WebCore/GNUmakefile.list.am
r93951 r94011 2876 2876 Source/WebCore/platform/track/WebVTTParser.cpp \ 2877 2877 Source/WebCore/platform/track/WebVTTParser.h \ 2878 Source/WebCore/platform/track/WebVTTToken.h \ 2879 Source/WebCore/platform/track/WebVTTTokenizer.h \ 2880 Source/WebCore/platform/track/WebVTTTokenizer.cpp \ 2878 2881 Source/WebCore/platform/TreeShared.h \ 2879 2882 Source/WebCore/platform/URLString.h \ -
trunk/Source/WebCore/WebCore.gypi
r93951 r94011 4395 4395 'platform/track/WebVTTParser.cpp', 4396 4396 'platform/track/WebVTTParser.h', 4397 'platform/track/WebVTTToken.h', 4398 'platform/track/WebVTTTokenizer.cpp', 4399 'platform/track/WebVTTTokenizer.h', 4397 4400 'platform/win/BString.cpp', 4398 4401 'platform/win/BString.h', -
trunk/Source/WebCore/WebCore.pro
r93951 r94011 2122 2122 platform/track/CueParserPrivate.h \ 2123 2123 platform/track/WebVTTParser.h \ 2124 platform/track/WebVTTToken.h \ 2125 platform/track/WebVTTTokenizer.h \ 2124 2126 platform/Widget.h \ 2125 2127 platform/PlatformStrategies.h \ -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r93980 r94011 4091 4091 ABDDFE7A0A5C6E7000A3E11D /* RenderMenuList.h in Headers */ = {isa = PBXBuildFile; fileRef = ABDDFE740A5C6E7000A3E11D /* RenderMenuList.h */; }; 4092 4092 ADDF1AD71257CD9A0003A759 /* RenderSVGPath.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */; }; 4093 B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */ = {isa = PBXBuildFile; fileRef = B10B697D140C174000BC1C26 /* WebVTTToken.h */; }; 4094 B10B6981140C174000BC1C26 /* WebVTTTokenizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */; }; 4095 B10B6982140C174000BC1C26 /* WebVTTTokenizer.h in Headers */ = {isa = PBXBuildFile; fileRef = B10B697F140C174000BC1C26 /* WebVTTTokenizer.h */; }; 4093 4096 B14353D5138EA8ED00D53276 /* MediaStreamList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B14353D1138EA8ED00D53276 /* MediaStreamList.cpp */; }; 4094 4097 B14353D6138EA8ED00D53276 /* MediaStreamList.h in Headers */ = {isa = PBXBuildFile; fileRef = B14353D2138EA8ED00D53276 /* MediaStreamList.h */; }; … … 10633 10636 ADDF1AD41257CD9A0003A759 /* RenderSVGPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGPath.cpp; sourceTree = "<group>"; }; 10634 10637 ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGPath.h; sourceTree = "<group>"; }; 10638 B10B697D140C174000BC1C26 /* WebVTTToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebVTTToken.h; path = platform/track/WebVTTToken.h; sourceTree = "<group>"; }; 10639 B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebVTTTokenizer.cpp; path = platform/track/WebVTTTokenizer.cpp; sourceTree = "<group>"; }; 10640 B10B697F140C174000BC1C26 /* WebVTTTokenizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebVTTTokenizer.h; path = platform/track/WebVTTTokenizer.h; sourceTree = "<group>"; }; 10635 10641 B14353D1138EA8ED00D53276 /* MediaStreamList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaStreamList.cpp; sourceTree = "<group>"; }; 10636 10642 B14353D2138EA8ED00D53276 /* MediaStreamList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaStreamList.h; sourceTree = "<group>"; }; … … 12976 12982 65C97AF208EA908800ACD273 /* config.h */, 12977 12983 EDEC98020AED7E170059137F /* WebCorePrefix.h */, 12984 B10B697D140C174000BC1C26 /* WebVTTToken.h */, 12985 B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */, 12986 B10B697F140C174000BC1C26 /* WebVTTTokenizer.h */, 12978 12987 9307061309E0CA8200B17FE4 /* DerivedSources.make */, 12979 12988 93F19B1908245E59001E9ABC /* Info.plist */, … … 23440 23449 D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */, 23441 23450 BCE43897140B0051005E437E /* EventConstructors.h in Headers */, 23451 B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */, 23452 B10B6982140C174000BC1C26 /* WebVTTTokenizer.h in Headers */, 23442 23453 ); 23443 23454 runOnlyForDeploymentPostprocessing = 0; … … 26249 26260 DF9AFD7313FC31D80015FEB7 /* MediaPlayerPrivateAVFoundationObjC.mm in Sources */, 26250 26261 BCE4389A140B0073005E437E /* JSEventConstructors.cpp in Sources */, 26262 B10B6981140C174000BC1C26 /* WebVTTTokenizer.cpp in Sources */, 26251 26263 ); 26252 26264 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/WebCore/html/TextTrackCue.cpp
r92538 r94011 42 42 namespace WebCore { 43 43 44 TextTrackCue::TextTrackCue(const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit) 45 : m_id(id) 44 TextTrackCue::TextTrackCue(ScriptExecutionContext* context, const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit) 45 : ActiveDOMObject(context, this) 46 , m_id(id) 46 47 , m_startTime(start) 47 48 , m_endTime(end) … … 128 129 PassRefPtr<DocumentFragment> TextTrackCue::getCueAsHTML() 129 130 { 130 // FIXME(62883): Implement. 131 return DocumentFragment::create(0); 131 return m_documentFragment; 132 } 133 134 void TextTrackCue::setCueHTML(PassRefPtr<DocumentFragment> fragment) 135 { 136 m_documentFragment = fragment; 132 137 } 133 138 … … 141 146 { 142 147 m_isActive = active; 148 } 149 150 ScriptExecutionContext* TextTrackCue::scriptExecutionContext() const 151 { 152 return ActiveDOMObject::scriptExecutionContext(); 143 153 } 144 154 … … 149 159 unsigned position = 0; 150 160 while (position < input.length()) { 161 // Discard any space characters between or after settings (not in the spec, but we think it should be). 162 while (position < input.length() && WebVTTParser::isASpace(input[position])) 163 position++; 164 151 165 // 2-4 Settings - get the next character representing a settings. 152 166 char setting = input[position++]; … … 286 300 } 287 301 288 // Discard any remaining space characters between or after settings (not in the spec, but we think it should be).289 while (position < input.length() && WebVTTParser::isASpace(input[position]))290 position++;291 302 continue; 292 303 -
trunk/Source/WebCore/html/TextTrackCue.h
r92538 r94011 34 34 #if ENABLE(VIDEO_TRACK) 35 35 36 #include "ActiveDOMObject.h" 36 37 #include "TextTrack.h" 37 38 #include <wtf/PassOwnPtr.h> … … 41 42 42 43 class DocumentFragment; 44 class ScriptExecutionContext; 43 45 class TextTrack; 44 46 45 class TextTrackCue : public RefCounted<TextTrackCue> {47 class TextTrackCue : public RefCounted<TextTrackCue>, public ActiveDOMObject { 46 48 public: 47 static PassRefPtr<TextTrackCue> create( const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit)49 static PassRefPtr<TextTrackCue> create(ScriptExecutionContext* context, const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit) 48 50 { 49 return adoptRef(new TextTrackCue( id, start, end, content, settings, pauseOnExit));51 return adoptRef(new TextTrackCue(context, id, start, end, content, settings, pauseOnExit)); 50 52 } 51 53 … … 72 74 String getCueAsSource(); 73 75 PassRefPtr<DocumentFragment> getCueAsHTML(); 76 void setCueHTML(PassRefPtr<DocumentFragment>); 74 77 75 78 bool isActive(); 76 79 void setIsActive(bool); 80 81 virtual ScriptExecutionContext* scriptExecutionContext() const; 77 82 78 83 private: 79 TextTrackCue( const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit);84 TextTrackCue(ScriptExecutionContext*, const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit); 80 85 81 86 void parseSettings(const String&); … … 94 99 int m_cueSize; 95 100 Alignment m_cueAlignment; 101 RefPtr<DocumentFragment> m_documentFragment; 96 102 97 103 bool m_isActive; -
trunk/Source/WebCore/platform/track/CueParser.cpp
r93899 r94011 62 62 63 63 m_client = client; 64 m_scriptExecutionContext = context; 64 65 65 66 m_loader = ThreadableLoader::create(context, this, request, options); … … 111 112 { 112 113 if (!m_private) { 113 m_private = WebVTTParser::create(this );114 m_private = WebVTTParser::create(this, m_scriptExecutionContext); 114 115 m_client->trackLoadStarted(); 115 116 } -
trunk/Source/WebCore/platform/track/CueParser.h
r92538 r94011 70 70 void newCuesParsed(); 71 71 72 protected: 73 ScriptExecutionContext* m_scriptExecutionContext; 74 72 75 private: 73 76 void createWebVTTParser(); -
trunk/Source/WebCore/platform/track/WebVTTParser.cpp
r92538 r94011 35 35 #include "WebVTTParser.h" 36 36 37 #include "HTMLElement.h" 38 #include "ProcessingInstruction.h" 39 #include "SegmentedString.h" 40 #include "Text.h" 37 41 #include <wtf/text/WTFString.h> 38 42 … … 79 83 } 80 84 81 WebVTTParser::WebVTTParser(CueParserPrivateClient* client) 82 : m_state(Initial) 85 WebVTTParser::WebVTTParser(CueParserPrivateClient* client, ScriptExecutionContext* context) 86 : m_scriptExecutionContext(context) 87 , m_state(Initial) 88 , m_tokenizer(WebVTTTokenizer::create()) 83 89 { 84 90 m_client = client; … … 205 211 void WebVTTParser::processCueText() 206 212 { 207 // 51 - Cue text processing based on WebVTT cue text parsing rules and WebVTT cue text DOM construction rules. 208 // FIXME(64132): Process the cue text as per the cue text parsing rules. 209 // Source: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#webvtt-cue-text-parsing-rules 210 RefPtr<TextTrackCue> cue = TextTrackCue::create(m_currentId, m_currentStartTime, m_currentEndTime, m_currentContent.toString(), m_currentSettings, false); 213 // 51 - Cue text processing based on 214 // 4.8.10.13.4 WebVTT cue text parsing rules and 215 // 4.8.10.13.5 WebVTT cue text DOM construction rules. 216 if (m_currentContent.length() <= 0) 217 return; 218 219 ASSERT(m_scriptExecutionContext->isDocument()); 220 Document* document = static_cast<Document*>(m_scriptExecutionContext); 221 222 m_attachmentRoot = DocumentFragment::create(document); 223 m_currentNode = m_attachmentRoot; 224 m_tokenizer->reset(); 225 m_token.clear(); 226 227 SegmentedString content(m_currentContent.toString()); 228 while (m_tokenizer->nextToken(content, m_token)) 229 constructTreeFromToken(document); 230 231 RefPtr<TextTrackCue> cue = TextTrackCue::create(m_scriptExecutionContext, m_currentId, m_currentStartTime, m_currentEndTime, m_currentContent.toString(), m_currentSettings, false); 232 cue->setCueHTML(m_attachmentRoot); 211 233 m_cuelist.append(cue); 212 234 m_client->newCuesParsed(); … … 282 304 } 283 305 306 void WebVTTParser::constructTreeFromToken(Document* document) 307 { 308 AtomicString tokenTagName(m_token.name().data(), m_token.name().size()); 309 QualifiedName tagName(nullAtom, tokenTagName, xhtmlNamespaceURI); 310 311 switch (m_token.type()) { 312 case WebVTTTokenTypes::Character: { 313 String content(m_token.characters().data(), m_token.characters().size()); 314 RefPtr<Text> child = Text::create(document, content); 315 m_currentNode->parserAddChild(child); 316 break; 317 } 318 case WebVTTTokenTypes::StartTag: { 319 RefPtr<HTMLElement> child; 320 if (isRecognizedTag(tokenTagName)) 321 child = HTMLElement::create(tagName, document); 322 else if (m_token.name().size() == 1 && m_token.name()[0] == 'c') 323 child = HTMLElement::create(spanTag, document); 324 else if (m_token.name().size() == 1 && m_token.name()[0] == 'v') 325 child = HTMLElement::create(qTag, document); 326 327 if (child) { 328 if (m_token.classes().size() > 0) { 329 RefPtr<NamedNodeMap> attributeMap = NamedNodeMap::create(); 330 attributeMap->addAttribute(Attribute::createMapped(classAttr, AtomicString(m_token.classes().data(), m_token.classes().size()))); 331 child->setAttributeMap(attributeMap.release()); 332 } 333 if (child->hasTagName(qTag)) 334 child->setAttribute(titleAttr, String(m_token.annotation().data(), m_token.annotation().size())); 335 m_currentNode->parserAddChild(child); 336 m_currentNode = child; 337 } 338 break; 339 } 340 case WebVTTTokenTypes::EndTag: 341 if (isRecognizedTag(tokenTagName) 342 || m_token.name().size() == 1 && m_token.name()[0] == 'c' 343 || m_token.name().size() == 1 && m_token.name()[0] == 'v') 344 if (m_currentNode->parentNode()) 345 m_currentNode = m_currentNode->parentNode(); 346 break; 347 case WebVTTTokenTypes::TimestampTag: { 348 unsigned position = 0; 349 double time = collectTimeStamp(m_token.characters().data(), &position); 350 if (time != malformedTime) 351 m_currentNode->parserAddChild(ProcessingInstruction::create(document, "timestamp", String(m_token.characters().data(), m_token.characters().size()))); 352 break; 353 } 354 default: 355 break; 356 } 357 m_token.clear(); 358 } 359 284 360 void WebVTTParser::skipWhiteSpace(const String& line, unsigned* position) 285 361 { -
trunk/Source/WebCore/platform/track/WebVTTParser.h
r92538 r94011 35 35 36 36 #include "CueParserPrivate.h" 37 #include "Document.h" 38 #include "DocumentFragment.h" 39 #include "HTMLNames.h" 40 #include "WebVTTTokenizer.h" 37 41 #include <wtf/PassOwnPtr.h> 38 42 #include <wtf/text/StringBuilder.h> 39 43 40 44 namespace WebCore { 45 46 using namespace HTMLNames; 41 47 42 48 static const int secondsPerHour = 3600; … … 50 56 enum ParseState { Initial, Header, Id, TimingsAndSettings, CueText, BadCue }; 51 57 52 static PassOwnPtr<WebVTTParser> create(CueParserPrivateClient* client )58 static PassOwnPtr<WebVTTParser> create(CueParserPrivateClient* client, ScriptExecutionContext* context) 53 59 { 54 return adoptPtr(new WebVTTParser(client ));60 return adoptPtr(new WebVTTParser(client, context)); 55 61 } 56 62 57 63 static bool hasRequiredFileIdentifier(const char* data, unsigned length); 64 65 static inline bool isRecognizedTag(const AtomicString& tagName) 66 { 67 return tagName == iTag 68 || tagName == bTag 69 || tagName == uTag 70 || tagName == rubyTag 71 || tagName == rtTag; 72 } 58 73 59 74 static inline bool isASpace(char c) … … 70 85 71 86 protected: 72 WebVTTParser(CueParserPrivateClient* );87 WebVTTParser(CueParserPrivateClient*, ScriptExecutionContext*); 73 88 89 ScriptExecutionContext* m_scriptExecutionContext; 74 90 ParseState m_state; 75 91 … … 86 102 static void skipLineTerminator(const char* data, unsigned length, unsigned*); 87 103 static String collectNextLine(const char* data, unsigned length, unsigned*); 104 105 void constructTreeFromToken(Document*); 88 106 89 107 String m_currentId; … … 92 110 StringBuilder m_currentContent; 93 111 String m_currentSettings; 112 113 WebVTTToken m_token; 114 OwnPtr<WebVTTTokenizer> m_tokenizer; 115 116 RefPtr<DocumentFragment> m_attachmentRoot; 117 RefPtr<ContainerNode> m_currentNode; 94 118 95 119 CueParserPrivateClient* m_client; -
trunk/Source/WebCore/platform/track/WebVTTTokenizer.h
r94010 r94011 29 29 */ 30 30 31 #ifndef CueParser_h32 #define CueParser_h31 #ifndef WebVTTTokenizer_h 32 #define WebVTTTokenizer_h 33 33 34 34 #if ENABLE(VIDEO_TRACK) 35 35 36 #include "ThreadableLoader.h" 37 #include "ThreadableLoaderClient.h" 38 #include "WebVTTParser.h" 39 #include <wtf/RefCounted.h> 40 #include <wtf/Vector.h> 41 #include <wtf/text/WTFString.h> 36 #include "MarkupTokenizerBase.h" 37 #include "SegmentedString.h" 38 #include "WebVTTToken.h" 42 39 43 40 namespace WebCore { 44 41 45 class ScriptExecutionContext; 46 class TextTrackCue; 47 48 class CueParserClient { 42 class WebVTTTokenizerState { 49 43 public: 50 virtual void newCuesParsed() = 0; 51 virtual void trackLoadStarted() = 0; 52 virtual void trackLoadError() = 0; 53 virtual void trackLoadCompleted() = 0; 44 enum State { 45 DataState, 46 EscapeState, 47 TagState, 48 StartTagState, 49 StartTagClassState, 50 StartTagAnnotationState, 51 EndTagState, 52 EndTagOpenState, 53 TimestampTagState, 54 }; 54 55 }; 55 56 56 class CueParser : public ThreadableLoaderClient, CueParserPrivateClient { 57 class WebVTTTokenizer : MarkupTokenizerBase<WebVTTToken, WebVTTTokenizerState> { 58 WTF_MAKE_NONCOPYABLE(WebVTTTokenizer); 59 WTF_MAKE_FAST_ALLOCATED; 57 60 public: 58 CueParser(); 59 virtual ~CueParser(); 61 static PassOwnPtr<WebVTTTokenizer> create() { return adoptPtr(new WebVTTTokenizer); } 60 62 61 void didReceiveResponse(unsigned long, const ResourceResponse&); 62 void didReceiveData(const char*, int); 63 void didFinishLoading(unsigned long); 64 void didFail(const ResourceError&); 65 66 void load(const String&, ScriptExecutionContext*, CueParserClient*); 67 bool supportsType(const String&); 68 69 void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&); 70 void newCuesParsed(); 63 void reset(); 64 65 bool nextToken(SegmentedString&, WebVTTToken&); 71 66 72 67 private: 73 void createWebVTTParser(); 74 75 RefPtr<ThreadableLoader> m_loader; 76 OwnPtr<CueParserPrivateInterface> m_private; 77 CueParserClient* m_client; 68 WebVTTTokenizer(); 69 70 Vector<UChar, 32> m_buffer; 78 71 }; 79 72 80 } // namespace WebCore73 } 81 74 82 75 #endif
Note:
See TracChangeset
for help on using the changeset viewer.