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

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

Issue 14578010: Fixing inconsistency with the media query spec and other browsers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 7 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2006, 2010, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2006, 2010, 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 unsigned length = string.length(); 113 unsigned length = string.length();
114 unsigned i = 0; 114 unsigned i = 0;
115 for (; i < length; ++i) { 115 for (; i < length; ++i) {
116 unsigned short c = string[i]; 116 unsigned short c = string[i];
117 if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '1' && c <= '9') || (c == '-'))) 117 if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '1' && c <= '9') || (c == '-')))
118 break; 118 break;
119 } 119 }
120 return string.left(i); 120 return string.left(i);
121 } 121 }
122 122
123 PassOwnPtr<MediaQuery> MediaQuerySet::parseMediaQuery(const String& queryString)
124 {
125 ASSERT(!queryString.isEmpty());
apavlov 2013/05/15 12:28:36 I cannot see any code that might guarantee the que
126
127 CSSParser parser(CSSStrictMode);
128 OwnPtr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString);
129
130 if (parsedQuery)
131 return parsedQuery.release();
132
133 if (m_fallbackToDescriptor) {
134 String medium = parseMediaDescriptor(queryString);
135 if (!medium.isNull())
136 return adoptPtr(new MediaQuery(MediaQuery::None, medium, nullptr));
137 }
138
139 return adoptPtr(new MediaQuery(MediaQuery::None, "not all", nullptr));
140 }
141
123 bool MediaQuerySet::parse(const String& mediaString) 142 bool MediaQuerySet::parse(const String& mediaString)
124 { 143 {
125 CSSParser parser(CSSStrictMode); 144 if (mediaString.isEmpty()) {
145 m_queries.clear();
146 return true;
147 }
148
149 Vector<String> list;
150 // FIXME: This is too simple as it shouldn't split when the ',' is inside
151 // other allowed matching pairs such as (), [], {}, "", and ''.
rune 2013/05/15 11:28:56 Yes, ideally CSSParser should have a parseMediaQue
152 mediaString.split(',', /* allowEmptyEntries */ true, list);
126 153
127 Vector<OwnPtr<MediaQuery> > result; 154 Vector<OwnPtr<MediaQuery> > result;
128 Vector<String> list; 155 result.reserveInitialCapacity(list.size());
129 mediaString.split(',', list); 156
130 for (unsigned i = 0; i < list.size(); ++i) { 157 for (unsigned i = 0; i < list.size(); ++i) {
131 String medium = list[i].stripWhiteSpace(); 158 String queryString = list[i].stripWhiteSpace();
132 if (medium.isEmpty()) { 159 if (OwnPtr<MediaQuery> parsedQuery = parseMediaQuery(queryString))
apavlov 2013/05/15 12:28:36 Shouldn't the code check that queryString is not e
133 if (!m_fallbackToDescriptor) 160 result.uncheckedAppend(parsedQuery.release());
134 return false;
135 continue;
136 }
137 OwnPtr<MediaQuery> mediaQuery = parser.parseMediaQuery(medium);
138 if (!mediaQuery) {
139 if (!m_fallbackToDescriptor)
140 return false;
141 String mediaDescriptor = parseMediaDescriptor(medium);
142 if (mediaDescriptor.isNull())
143 continue;
144 mediaQuery = adoptPtr(new MediaQuery(MediaQuery::None, mediaDescript or, nullptr));
145 }
146 result.append(mediaQuery.release());
147 } 161 }
148 // ",,,," falls straight through, but is not valid unless fallback 162
149 if (!m_fallbackToDescriptor && list.isEmpty()) {
150 String strippedMediaString = mediaString.stripWhiteSpace();
151 if (!strippedMediaString.isEmpty())
152 return false;
153 }
154 m_queries.swap(result); 163 m_queries.swap(result);
155 return true; 164 return true;
156 } 165 }
157 166
158 bool MediaQuerySet::add(const String& queryString) 167 bool MediaQuerySet::add(const String& queryString)
159 { 168 {
160 CSSParser parser(CSSStrictMode); 169 if (OwnPtr<MediaQuery> parsedQuery = parseMediaQuery(queryString)) {
161 170 m_queries.append(parsedQuery.release());
162 OwnPtr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString); 171 return true;
163 if (!parsedQuery && m_fallbackToDescriptor) {
164 String medium = parseMediaDescriptor(queryString);
165 if (!medium.isNull())
166 parsedQuery = adoptPtr(new MediaQuery(MediaQuery::None, medium, null ptr));
167 } 172 }
168 if (!parsedQuery) 173 return false;
169 return false;
170
171 m_queries.append(parsedQuery.release());
172 return true;
173 } 174 }
174 175
175 bool MediaQuerySet::remove(const String& queryStringToRemove) 176 bool MediaQuerySet::remove(const String& queryStringToRemove)
176 { 177 {
177 CSSParser parser(CSSStrictMode); 178 OwnPtr<MediaQuery> parsedQuery = parseMediaQuery(queryStringToRemove);
178
179 OwnPtr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryStringToRemove) ;
180 if (!parsedQuery && m_fallbackToDescriptor) {
181 String medium = parseMediaDescriptor(queryStringToRemove);
182 if (!medium.isNull())
183 parsedQuery = adoptPtr(new MediaQuery(MediaQuery::None, medium, null ptr));
184 }
185 if (!parsedQuery) 179 if (!parsedQuery)
186 return false; 180 return false;
187 181
188 for (size_t i = 0; i < m_queries.size(); ++i) { 182 for (size_t i = 0; i < m_queries.size(); ++i) {
189 MediaQuery* query = m_queries[i].get(); 183 MediaQuery* query = m_queries[i].get();
190 if (*query == *parsedQuery) { 184 if (*query == *parsedQuery) {
191 m_queries.remove(i); 185 m_queries.remove(i);
192 return true; 186 return true;
193 } 187 }
194 } 188 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV alue); 351 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV alue);
358 if (primitiveValue->isDotsPerInch() || primitiveValue->isDot sPerCentimeter()) 352 if (primitiveValue->isDotsPerInch() || primitiveValue->isDot sPerCentimeter())
359 addResolutionWarningMessageToConsole(document, mediaQuer ySet->mediaText(), primitiveValue); 353 addResolutionWarningMessageToConsole(document, mediaQuer ySet->mediaText(), primitiveValue);
360 } 354 }
361 } 355 }
362 } 356 }
363 } 357 }
364 } 358 }
365 359
366 } 360 }
OLDNEW
« LayoutTests/fast/media/mq-parsing-expected.txt ('K') | « Source/core/css/MediaList.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698