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

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
« no previous file with comments | « Source/core/css/MediaList.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CSSParser parser(CSSStrictMode);
126 OwnPtr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString);
127
128 if (parsedQuery)
129 return parsedQuery.release();
130
131 if (m_fallbackToDescriptor) {
132 String medium = parseMediaDescriptor(queryString);
133 if (!medium.isNull())
134 return adoptPtr(new MediaQuery(MediaQuery::None, medium, nullptr));
135 }
136
137 return adoptPtr(new MediaQuery(MediaQuery::None, "not all", nullptr));
138 }
139
123 bool MediaQuerySet::parse(const String& mediaString) 140 bool MediaQuerySet::parse(const String& mediaString)
124 { 141 {
125 CSSParser parser(CSSStrictMode); 142 if (mediaString.isEmpty()) {
143 m_queries.clear();
144 return true;
145 }
146
147 Vector<String> list;
148 // FIXME: This is too simple as it shouldn't split when the ',' is inside
149 // other allowed matching pairs such as (), [], {}, "", and ''.
150 mediaString.split(',', /* allowEmptyEntries */ true, list);
126 151
127 Vector<OwnPtr<MediaQuery> > result; 152 Vector<OwnPtr<MediaQuery> > result;
128 Vector<String> list; 153 result.reserveInitialCapacity(list.size());
129 mediaString.split(',', list); 154
130 for (unsigned i = 0; i < list.size(); ++i) { 155 for (unsigned i = 0; i < list.size(); ++i) {
131 String medium = list[i].stripWhiteSpace(); 156 String queryString = list[i].stripWhiteSpace();
132 if (medium.isEmpty()) { 157 if (OwnPtr<MediaQuery> parsedQuery = parseMediaQuery(queryString))
133 if (!m_fallbackToDescriptor) 158 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 } 159 }
148 // ",,,," falls straight through, but is not valid unless fallback 160
149 if (!m_fallbackToDescriptor && list.isEmpty()) {
150 String strippedMediaString = mediaString.stripWhiteSpace();
151 if (!strippedMediaString.isEmpty())
152 return false;
153 }
154 m_queries.swap(result); 161 m_queries.swap(result);
155 return true; 162 return true;
156 } 163 }
157 164
158 bool MediaQuerySet::add(const String& queryString) 165 bool MediaQuerySet::add(const String& queryString)
159 { 166 {
160 CSSParser parser(CSSStrictMode); 167 if (OwnPtr<MediaQuery> parsedQuery = parseMediaQuery(queryString)) {
161 168 m_queries.append(parsedQuery.release());
162 OwnPtr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString); 169 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 } 170 }
168 if (!parsedQuery) 171 return false;
169 return false;
170
171 m_queries.append(parsedQuery.release());
172 return true;
173 } 172 }
174 173
175 bool MediaQuerySet::remove(const String& queryStringToRemove) 174 bool MediaQuerySet::remove(const String& queryStringToRemove)
176 { 175 {
177 CSSParser parser(CSSStrictMode); 176 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) 177 if (!parsedQuery)
186 return false; 178 return false;
187 179
188 for (size_t i = 0; i < m_queries.size(); ++i) { 180 for (size_t i = 0; i < m_queries.size(); ++i) {
189 MediaQuery* query = m_queries[i].get(); 181 MediaQuery* query = m_queries[i].get();
190 if (*query == *parsedQuery) { 182 if (*query == *parsedQuery) {
191 m_queries.remove(i); 183 m_queries.remove(i);
192 return true; 184 return true;
193 } 185 }
194 } 186 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV alue); 349 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV alue);
358 if (primitiveValue->isDotsPerInch() || primitiveValue->isDot sPerCentimeter()) 350 if (primitiveValue->isDotsPerInch() || primitiveValue->isDot sPerCentimeter())
359 addResolutionWarningMessageToConsole(document, mediaQuer ySet->mediaText(), primitiveValue); 351 addResolutionWarningMessageToConsole(document, mediaQuer ySet->mediaText(), primitiveValue);
360 } 352 }
361 } 353 }
362 } 354 }
363 } 355 }
364 } 356 }
365 357
366 } 358 }
OLDNEW
« no previous file with comments | « Source/core/css/MediaList.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698