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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.h
diff --git a/third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.h b/third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.h
new file mode 100644
index 0000000000000000000000000000000000000000..7a97d823861f96b66eaac1a54e23a7d8e5d1dfe9
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.h
@@ -0,0 +1,95 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CSSSerializeStream_h
+#define CSSSerializeStream_h
+
+#include "core/css/CSSValue.h"
+#include "core/dom/QualifiedName.h"
+#include "platform/graphics/Color.h"
+#include "wtf/RefPtr.h"
+#include "wtf/Vector.h"
+
+namespace blink {
+
+#ifdef NDEBUG
+#define CSDEBUG(...)
+#define CSSHOW(s)
+#else
+#define CSDEBUG(...) fprintf(stderr, __VA_ARGS__)
+#define CSSHOW(s) s.show()
+#endif
+
+struct StylePropertyMetadata;
+struct Referrer;
+class CSSValue;
+
+template<typename T> class CSSSerializeTrait;
+
+class CSSSerializeStream {
+ WTF_MAKE_NONCOPYABLE(CSSSerializeStream);
+
+public:
+ CSSSerializeStream() {}
+
+ void writeClassType(CSSValue::ClassType);
+ void writeColor(Color);
+ void writeBool(bool);
+ void writeInt(int);
+ void writeUnsigned(unsigned);
+ void writeDouble(double);
+ void writeUChar32(UChar32);
+ void writeString(const String&);
+ void writeAtomicString(const AtomicString&);
+ void writeQualifiedName(const QualifiedName&);
+ void writeStylePropertyMetadata(StylePropertyMetadata);
+ void writeReferrer(const Referrer&);
+
+ template<typename T> void writeEnumAsInt(T v)
+ {
+ writeInt(static_cast<int>(v));
+ }
+
+ template<typename T> void serializeNullable(T* p);
+ template<typename T> void serializeNullable(const RefPtr<T>& p)
+ {
+ serializeNullable(p.get());
+ }
+
+ Vector<char>& data() { return m_buffer; }
+
+private:
+ void padIfNeeded();
+
+ Vector<char> m_buffer;
+};
+
+template<typename T> class CSSSerializeTrait {
+public:
+ static void serializeNull(CSSSerializeStream* stream)
+ {
+ stream->writeBool(false);
+ }
+
+ static void serializeNonNullHeader(CSSSerializeStream* stream)
+ {
+ stream->writeBool(true);
+ }
+};
+
+template<typename T>
+inline void CSSSerializeStream::serializeNullable(T* p)
+{
+ if (!p) {
+ CSSSerializeTrait<T>::serializeNull(this);
+ return;
+ }
+
+ CSSSerializeTrait<T>::serializeNonNullHeader(this);
+ p->serialize(this);
+}
+
+} // namespace blink
+
+#endif // CSSSerializeStream_h

Powered by Google App Engine
This is Rietveld 408576698