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

Side by Side Diff: Source/core/html/track/vtt/VTTToken.h

Issue 81113003: Turn VTTToken into an immutable object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « Source/core/html/track/vtt/VTTParser.cpp ('k') | Source/core/html/track/vtt/VTTTokenizer.h » ('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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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 VTTToken_h 31 #ifndef VTTToken_h
32 #define VTTToken_h 32 #define VTTToken_h
33 33
34 #include "wtf/text/StringBuilder.h"
35
36 namespace WebCore { 34 namespace WebCore {
37 35
38 class VTTTokenTypes { 36 class VTTTokenTypes {
39 public: 37 public:
40 enum Type { 38 enum Type {
41 Uninitialized, 39 Uninitialized,
42 Character, 40 Character,
43 StartTag, 41 StartTag,
44 EndTag, 42 EndTag,
45 TimestampTag, 43 TimestampTag,
46 }; 44 };
47 }; 45 };
48 46
49 class VTTToken { 47 class VTTToken {
50 WTF_MAKE_NONCOPYABLE(VTTToken);
51 WTF_MAKE_FAST_ALLOCATED;
52 public: 48 public:
53 typedef VTTTokenTypes Type; 49 typedef VTTTokenTypes Type;
54 50
55 VTTToken() { clear(); } 51 VTTToken() : m_type(Type::Uninitialized) { }
52
53 static VTTToken StringToken(const String& characterData)
54 {
55 return VTTToken(Type::Character, characterData);
56 }
57 static VTTToken StartTag(const String& tagName, const AtomicString& classes = emptyAtom, const AtomicString& annotation = emptyAtom)
58 {
59 VTTToken token(Type::StartTag, tagName);
60 token.m_classes = classes;
61 token.m_annotation = annotation;
62 return token;
63 }
64 static VTTToken EndTag(const String& tagName)
65 {
66 return VTTToken(Type::EndTag, tagName);
67 }
68 static VTTToken TimestampTag(const String& timestampData)
69 {
70 return VTTToken(Type::TimestampTag, timestampData);
71 }
56 72
57 Type::Type type() const { return m_type; } 73 Type::Type type() const { return m_type; }
58 void setType(Type::Type type) { m_type = type; } 74 const String& name() const { return m_data; }
59 75 const String& characters() const { return m_data; }
60 StringBuilder& name() 76 const AtomicString& classes() const { return m_classes; }
61 { 77 const AtomicString& annotation() const { return m_annotation; }
62 return m_data;
63 }
64
65 StringBuilder& characters()
66 {
67 return m_data;
68 }
69
70 void appendToData(char character)
71 {
72 m_data.append(character);
73 }
74
75 void appendToData(UChar character)
76 {
77 m_data.append(character);
78 }
79
80 void appendToData(const StringBuilder& characters)
81 {
82 m_data.append(characters);
83 }
84
85 void addNewClass(const StringBuilder& s)
86 {
87 if (!m_classes.isEmpty())
88 m_classes.append(' ');
89 m_classes.append(s);
90 }
91
92 StringBuilder& classes()
93 {
94 return m_classes;
95 }
96
97 void addNewAnnotation(const StringBuilder& s)
98 {
99 m_annotation.clear();
100 m_annotation.append(s);
101 }
102
103 StringBuilder& annotation()
104 {
105 return m_annotation;
106 }
107
108 void clear()
109 {
110 m_type = Type::Uninitialized;
111 m_data.clear();
112 m_annotation.clear();
113 m_classes.clear();
114 }
115 78
116 private: 79 private:
80 VTTToken(Type::Type type, const String& data)
81 : m_type(type)
82 , m_data(data) { }
83
117 Type::Type m_type; 84 Type::Type m_type;
118 StringBuilder m_data; 85 String m_data;
119 StringBuilder m_annotation; 86 AtomicString m_annotation;
120 StringBuilder m_classes; 87 AtomicString m_classes;
121 }; 88 };
122 89
123 } 90 }
124 91
125 #endif 92 #endif
OLDNEW
« no previous file with comments | « Source/core/html/track/vtt/VTTParser.cpp ('k') | Source/core/html/track/vtt/VTTTokenizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698