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

Side by Side Diff: third_party/WebKit/Source/core/css/MediaQuery.cpp

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
1 /* 1 /*
2 * CSS Media Query 2 * CSS Media Query
3 * 3 *
4 * Copyright (C) 2005, 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. 4 * Copyright (C) 2005, 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>.
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 12 matching lines...) Expand all
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "core/css/MediaQuery.h" 29 #include "core/css/MediaQuery.h"
30 30
31 #include "core/MediaTypeNames.h" 31 #include "core/MediaTypeNames.h"
32 #include "core/css/MediaQueryExp.h" 32 #include "core/css/MediaQueryExp.h"
33 #include "core/css/serializer/CSSDeserializeStream.h"
34 #include "core/css/serializer/CSSSerializeStream.h"
33 #include "core/html/parser/HTMLParserIdioms.h" 35 #include "core/html/parser/HTMLParserIdioms.h"
34 #include "wtf/NonCopyingSort.h" 36 #include "wtf/NonCopyingSort.h"
35 #include "wtf/text/StringBuilder.h" 37 #include "wtf/text/StringBuilder.h"
36 38
37 namespace blink { 39 namespace blink {
38 40
39 // http://dev.w3.org/csswg/cssom/#serialize-a-media-query 41 // http://dev.w3.org/csswg/cssom/#serialize-a-media-query
40 String MediaQuery::serialize() const 42 String MediaQuery::serialize() const
41 { 43 {
42 StringBuilder result; 44 StringBuilder result;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 127
126 // http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries 128 // http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries
127 String MediaQuery::cssText() const 129 String MediaQuery::cssText() const
128 { 130 {
129 if (m_serializationCache.isNull()) 131 if (m_serializationCache.isNull())
130 const_cast<MediaQuery*>(this)->m_serializationCache = serialize(); 132 const_cast<MediaQuery*>(this)->m_serializationCache = serialize();
131 133
132 return m_serializationCache; 134 return m_serializationCache;
133 } 135 }
134 136
137 void MediaQuery::serialize(CSSSerializeStream* stream) const
138 {
139 stream->writeEnumAsInt<Restrictor>(m_restrictor);
140 stream->writeString(m_mediaType);
141
142 stream->writeUnsigned(m_expressions->size());
143 for (const OwnPtrWillBeMember<MediaQueryExp>& exp : *m_expressions)
144 exp->serialize(stream);
145 }
146
147 PassOwnPtrWillBeRawPtr<MediaQuery> MediaQuery::deserialize(CSSDeserializeStream* stream)
148 {
149 Restrictor restrictor = stream->readIntAsEnum<Restrictor>();
150 String mediaType = stream->readString();
151
152 OwnPtrWillBeMember<ExpressionHeapVector> expressions = adoptPtrWillBeNoop(ne w ExpressionHeapVector);
153 unsigned size = stream->readUnsigned();
154 expressions->reserveCapacity(size);
155 for (unsigned i = 0; i < size; ++ i)
156 expressions->append(MediaQueryExp::deserialize(stream));
157
158 return adoptPtrWillBeNoop(new MediaQuery(restrictor, mediaType, expressions. release()));
159 }
160
135 DEFINE_TRACE(MediaQuery) 161 DEFINE_TRACE(MediaQuery)
136 { 162 {
137 // We don't support tracing of vectors of OwnPtrs (ie. OwnPtr<Vector<OwnPtr< MediaQuery>>>). 163 // We don't support tracing of vectors of OwnPtrs (ie. OwnPtr<Vector<OwnPtr< MediaQuery>>>).
138 // Since this is a transitional object we are just ifdef'ing it out when oil pan is not enabled. 164 // Since this is a transitional object we are just ifdef'ing it out when oil pan is not enabled.
139 #if ENABLE(OILPAN) 165 #if ENABLE(OILPAN)
140 visitor->trace(m_expressions); 166 visitor->trace(m_expressions);
141 #endif 167 #endif
142 } 168 }
143 169
144 } 170 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/MediaQuery.h ('k') | third_party/WebKit/Source/core/css/MediaQueryExp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698