| Index: third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.cpp
|
| diff --git a/third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.cpp b/third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2db89603845cb304de4c89356cde923e8f055462
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/css/serializer/CSSSerializeStream.cpp
|
| @@ -0,0 +1,145 @@
|
| +// 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.
|
| +
|
| +#include "core/css/serializer/CSSSerializeStream.h"
|
| +
|
| +#include "core/HTMLNames.h"
|
| +#include "core/css/CSSProperty.h"
|
| +#include "platform/weborigin/Referrer.h"
|
| +
|
| +namespace blink {
|
| +
|
| +inline void CSSSerializeStream::padIfNeeded()
|
| +{
|
| + uintptr_t misalign = m_buffer.size() & 0x3;
|
| + if (misalign) {
|
| + unsigned padding = 4 - static_cast<unsigned>(misalign);
|
| + CSDEBUG("padding %d\n", padding);
|
| + m_buffer.grow(m_buffer.size() + padding);
|
| + }
|
| +}
|
| +
|
| +void CSSSerializeStream::writeClassType(CSSValue::ClassType classType)
|
| +{
|
| + CSDEBUG("write classType ");
|
| + writeUnsigned(classType);
|
| +}
|
| +
|
| +void CSSSerializeStream::writeColor(Color color)
|
| +{
|
| + CSDEBUG("write color ");
|
| + writeUnsigned(color.rgb());
|
| +}
|
| +
|
| +void CSSSerializeStream::writeBool(bool b)
|
| +{
|
| + CSDEBUG("write bool %d\n", b);
|
| + m_buffer.append(reinterpret_cast<char*>(&b), 1);
|
| +}
|
| +
|
| +void CSSSerializeStream::writeInt(int n)
|
| +{
|
| + CSDEBUG("write signed %d %x\n", n, n);
|
| + padIfNeeded();
|
| + m_buffer.append(reinterpret_cast<char*>(&n), sizeof(int));
|
| +}
|
| +
|
| +void CSSSerializeStream::writeUnsigned(unsigned u)
|
| +{
|
| + CSDEBUG("write unsigned %u %x\n", u, u);
|
| + padIfNeeded();
|
| + m_buffer.append(reinterpret_cast<char*>(&u), sizeof(unsigned));
|
| +}
|
| +
|
| +void CSSSerializeStream::writeDouble(double d)
|
| +{
|
| + CSDEBUG("write double %f\n", d);
|
| + padIfNeeded();
|
| + m_buffer.append(reinterpret_cast<char*>(&d), sizeof(double));
|
| +}
|
| +
|
| +void CSSSerializeStream::writeUChar32(UChar32 u)
|
| +{
|
| + CSDEBUG("write UChar32 %u\n", u);
|
| + padIfNeeded();
|
| + m_buffer.append(reinterpret_cast<char*>(&u), sizeof(UChar32));
|
| +}
|
| +
|
| +void CSSSerializeStream::writeString(const String& str)
|
| +{
|
| + // FIXME: emptyString vs. emptyString16???
|
| + CSDEBUG("write String ");
|
| + CSSHOW(str);
|
| + if (str.isNull()) {
|
| + writeUnsigned(0xffffffff);
|
| + return;
|
| + }
|
| +
|
| + writeUnsigned(str.length());
|
| + if (str.length()) {
|
| + writeUnsigned(str.is8Bit());
|
| + if (str.is8Bit()) {
|
| + m_buffer.append(str.characters8(), str.length());
|
| + } else {
|
| + m_buffer.append(str.characters16(), str.length() * 2);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void CSSSerializeStream::writeAtomicString(const AtomicString& str)
|
| +{
|
| + CSDEBUG("write AtomicString ");
|
| + writeString(str.string());
|
| + writeUnsigned(str.impl() ? str.impl()->hash() : 0);
|
| +}
|
| +
|
| +using QualifiedNameIntMap = HashMap<QualifiedName, int>;
|
| +static const QualifiedNameIntMap& htmlTagNameToInt()
|
| +{
|
| + DEFINE_STATIC_LOCAL(QualifiedNameIntMap, map, ());
|
| + if (map.isEmpty()) {
|
| + OwnPtr<const HTMLQualifiedName*[]> qualifiedNames = HTMLNames::getHTMLTags();
|
| + for (size_t i = 0; i < HTMLNames::HTMLTagsCount; ++i) {
|
| + map.set(*qualifiedNames[i], i);
|
| + }
|
| + }
|
| +
|
| + return map;
|
| +}
|
| +
|
| +void CSSSerializeStream::writeQualifiedName(const QualifiedName& name)
|
| +{
|
| + // FIXME
|
| + CSDEBUG("write QualifiedName ");
|
| +
|
| + const QualifiedNameIntMap& map = htmlTagNameToInt();
|
| + auto it = map.find(name);
|
| + if (it != map.end()) {
|
| + int id = it->value;
|
| + CSDEBUG("Tag %d", id);
|
| + writeInt(id);
|
| + return;
|
| + }
|
| +
|
| + writeInt(-1);
|
| + RELEASE_ASSERT(!name.hasPrefix());
|
| + // name.namespaceURI().show();
|
| + // RELEASE_ASSERT(name.namespaceURI().isEmpty());
|
| + writeAtomicString(name.localName());
|
| +}
|
| +
|
| +void CSSSerializeStream::writeStylePropertyMetadata(StylePropertyMetadata metadata)
|
| +{
|
| + CSDEBUG("write StylePropertyMetadata ");
|
| + static_assert(sizeof(StylePropertyMetadata) == sizeof(uint16_t), "uint16 hack is unapplicable");
|
| + writeUnsigned(*reinterpret_cast<uint16_t*>(&metadata));
|
| +}
|
| +
|
| +void CSSSerializeStream::writeReferrer(const Referrer& referrer)
|
| +{
|
| + writeAtomicString(referrer.referrer);
|
| + writeInt(referrer.referrerPolicy);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|