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

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

Issue 178803006: Turn MQ classes into thread safe (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased after MediaFeature generation landed Created 6 years, 9 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 11 matching lines...) Expand all
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
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 "config.h" 29 #include "config.h"
30 #include "core/css/MediaQuery.h" 30 #include "core/css/MediaQuery.h"
31 31
32 #include "MediaTypeNames.h"
32 #include "core/css/MediaQueryExp.h" 33 #include "core/css/MediaQueryExp.h"
34 #include "core/html/parser/HTMLParserIdioms.h"
33 #include "wtf/NonCopyingSort.h" 35 #include "wtf/NonCopyingSort.h"
34 #include "wtf/text/StringBuilder.h" 36 #include "wtf/text/StringBuilder.h"
35 37
36 namespace WebCore { 38 namespace WebCore {
37 39
38 // http://dev.w3.org/csswg/cssom/#serialize-a-media-query 40 // http://dev.w3.org/csswg/cssom/#serialize-a-media-query
39 String MediaQuery::serialize() const 41 String MediaQuery::serialize() const
40 { 42 {
41 StringBuilder result; 43 StringBuilder result;
42 switch (m_restrictor) { 44 switch (m_restrictor) {
43 case MediaQuery::Only: 45 case MediaQuery::Only:
44 result.append("only "); 46 result.append("only ");
45 break; 47 break;
46 case MediaQuery::Not: 48 case MediaQuery::Not:
47 result.append("not "); 49 result.append("not ");
48 break; 50 break;
49 case MediaQuery::None: 51 case MediaQuery::None:
50 break; 52 break;
51 } 53 }
52 54
53 if (m_expressions->isEmpty()) { 55 if (m_expressions->isEmpty()) {
54 result.append(m_mediaType); 56 result.append(m_mediaType);
55 return result.toString(); 57 return result.toString();
56 } 58 }
57 59
58 if (m_mediaType != "all" || m_restrictor != None) { 60 if (m_mediaType != MediaTypeNames::all || m_restrictor != None) {
59 result.append(m_mediaType); 61 result.append(m_mediaType);
60 result.append(" and "); 62 result.append(" and ");
61 } 63 }
62 64
63 result.append(m_expressions->at(0)->serialize()); 65 result.append(m_expressions->at(0)->serialize());
64 for (size_t i = 1; i < m_expressions->size(); ++i) { 66 for (size_t i = 1; i < m_expressions->size(); ++i) {
65 result.append(" and "); 67 result.append(" and ");
66 result.append(m_expressions->at(i)->serialize()); 68 result.append(m_expressions->at(i)->serialize());
67 } 69 }
68 return result.toString(); 70 return result.toString();
69 } 71 }
70 72
71 static bool expressionCompare(const OwnPtrWillBeMember<MediaQueryExp>& a, const OwnPtrWillBeMember<MediaQueryExp>& b) 73 static bool expressionCompare(const OwnPtrWillBeMember<MediaQueryExp>& a, const OwnPtrWillBeMember<MediaQueryExp>& b)
72 { 74 {
73 return codePointCompare(a->serialize(), b->serialize()) < 0; 75 return codePointCompare(a->serialize(), b->serialize()) < 0;
74 } 76 }
75 77
76 MediaQuery::MediaQuery(Restrictor r, const AtomicString& mediaType, PassOwnPtrWi llBeRawPtr<ExpressionHeapVector> expressions) 78 MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtrWillBeRa wPtr<ExpressionHeapVector> expressions)
77 : m_restrictor(r) 79 : m_restrictor(r)
78 , m_mediaType(mediaType.lower()) 80 , m_mediaType(attemptStaticStringCreation(mediaType.lower()))
79 , m_expressions(expressions) 81 , m_expressions(expressions)
80 { 82 {
81 if (!m_expressions) { 83 if (!m_expressions) {
82 m_expressions = adoptPtrWillBeNoop(new ExpressionHeapVector); 84 m_expressions = adoptPtrWillBeNoop(new ExpressionHeapVector);
83 return; 85 return;
84 } 86 }
85 87
86 nonCopyingSort(m_expressions->begin(), m_expressions->end(), expressionCompa re); 88 nonCopyingSort(m_expressions->begin(), m_expressions->end(), expressionCompa re);
87 89
88 // Remove all duplicated expressions. 90 // Remove all duplicated expressions.
89 MediaQueryExp* key = 0; 91 MediaQueryExp* key = 0;
90 for (int i = m_expressions->size() - 1; i >= 0; --i) { 92 for (int i = m_expressions->size() - 1; i >= 0; --i) {
91 MediaQueryExp* exp = m_expressions->at(i).get(); 93 MediaQueryExp* exp = m_expressions->at(i).get();
92 94
93 if (key && *exp == *key) 95 if (key && *exp == *key)
94 m_expressions->remove(i); 96 m_expressions->remove(i);
95 else 97 else
96 key = exp; 98 key = exp;
97 } 99 }
98 } 100 }
99 101
100 MediaQuery::MediaQuery(const MediaQuery& o) 102 MediaQuery::MediaQuery(const MediaQuery& o)
101 : m_restrictor(o.m_restrictor) 103 : m_restrictor(o.m_restrictor)
102 , m_mediaType(o.m_mediaType) 104 , m_mediaType(o.m_mediaType.impl())
abarth-chromium 2014/03/06 08:03:57 Why is this needed? Normally you can assign one s
103 , m_expressions(adoptPtrWillBeNoop(new ExpressionHeapVector(o.m_expressions- >size()))) 105 , m_expressions(adoptPtrWillBeNoop(new ExpressionHeapVector(o.m_expressions- >size())))
104 , m_serializationCache(o.m_serializationCache) 106 , m_serializationCache(o.m_serializationCache)
105 { 107 {
106 for (unsigned i = 0; i < m_expressions->size(); ++i) 108 for (unsigned i = 0; i < m_expressions->size(); ++i)
107 (*m_expressions)[i] = o.m_expressions->at(i)->copy(); 109 (*m_expressions)[i] = o.m_expressions->at(i)->copy();
108 } 110 }
109 111
110 MediaQuery::~MediaQuery() 112 MediaQuery::~MediaQuery()
111 { 113 {
112 } 114 }
(...skipping 16 matching lines...) Expand all
129 void MediaQuery::trace(Visitor* visitor) 131 void MediaQuery::trace(Visitor* visitor)
130 { 132 {
131 // We don't support tracing of vectors of OwnPtrs (ie. OwnPtr<Vector<OwnPtr< MediaQuery> > >). 133 // We don't support tracing of vectors of OwnPtrs (ie. OwnPtr<Vector<OwnPtr< MediaQuery> > >).
132 // Since this is a transitional object we are just ifdef'ing it out when oil pan is not enabled. 134 // Since this is a transitional object we are just ifdef'ing it out when oil pan is not enabled.
133 #if ENABLE(OILPAN) 135 #if ENABLE(OILPAN)
134 visitor->trace(m_expressions); 136 visitor->trace(m_expressions);
135 #endif 137 #endif
136 } 138 }
137 139
138 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698