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

Side by Side Diff: third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.h

Issue 1481383002: [Experimental] CSSSerializer Proof-of-concept Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: snapshot: top_25 sites ser/dser now works Created 4 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CSSSerializeStream_h
6 #define CSSSerializeStream_h
7
8 #include "core/css/CSSValue.h"
9 #include "core/dom/QualifiedName.h"
10 #include "platform/graphics/Color.h"
11 #include "wtf/RefPtr.h"
12 #include "wtf/Vector.h"
13
14 namespace blink {
15
16 #ifdef NDEBUG
17 #define CSDEBUG(...)
18 #define CSSHOW(s)
19 #else
20 #define CSDEBUG(...) fprintf(stderr, __VA_ARGS__)
21 #define CSSHOW(s) s.show()
22 #endif
23
24 struct StylePropertyMetadata;
25 struct Referrer;
26 class CSSValue;
27
28 template<typename T> class CSSSerializeTrait;
29
30 class CSSSerializeStream {
31 WTF_MAKE_NONCOPYABLE(CSSSerializeStream);
32
33 public:
34 CSSSerializeStream() {}
35
36 void writeClassType(CSSValue::ClassType);
37 void writeColor(Color);
38 void writeBool(bool);
39 void writeInt(int);
40 void writeUnsigned(unsigned);
41 void writeDouble(double);
42 void writeUChar32(UChar32);
43 void writeString(const String&);
44 void writeAtomicString(const AtomicString&);
45 void writeQualifiedName(const QualifiedName&);
46 void writeStylePropertyMetadata(StylePropertyMetadata);
47 void writeReferrer(const Referrer&);
48
49 template<typename T> void writeEnumAsInt(T v)
50 {
51 writeInt(static_cast<int>(v));
52 }
53
54 template<typename T> void serializeNullable(T* p);
55 template<typename T> void serializeNullable(const RefPtr<T>& p)
56 {
57 serializeNullable(p.get());
58 }
59
60 Vector<char>& data() { return m_buffer; }
61
62 private:
63 void padIfNeeded();
64
65 Vector<char> m_buffer;
66 };
67
68 template<typename T> class CSSSerializeTrait {
69 public:
70 static void serializeNull(CSSSerializeStream* stream)
71 {
72 stream->writeBool(false);
73 }
74
75 static void serializeNonNullHeader(CSSSerializeStream* stream)
76 {
77 stream->writeBool(true);
78 }
79 };
80
81 template<typename T>
82 inline void CSSSerializeStream::serializeNullable(T* p)
83 {
84 if (!p) {
85 CSSSerializeTrait<T>::serializeNull(this);
86 return;
87 }
88
89 CSSSerializeTrait<T>::serializeNonNullHeader(this);
90 p->serialize(this);
91 }
92
93 } // namespace blink
94
95 #endif // CSSSerializeStream_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698