Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 * However, the parsing rules for media queries are incompatible with those of H TML4 | 45 * However, the parsing rules for media queries are incompatible with those of H TML4 |
| 46 * and are consistent with those of media queries used in CSS. | 46 * and are consistent with those of media queries used in CSS. |
| 47 * | 47 * |
| 48 * HTML5 (at the moment of writing still work in progress) references the Media Queries | 48 * HTML5 (at the moment of writing still work in progress) references the Media Queries |
| 49 * specification directly and thus updates the rules for HTML. | 49 * specification directly and thus updates the rules for HTML. |
| 50 * | 50 * |
| 51 * CSS 2.1 Spec (http://www.w3.org/TR/CSS21/media.html) | 51 * CSS 2.1 Spec (http://www.w3.org/TR/CSS21/media.html) |
| 52 * CSS 3 Media Queries Spec (http://www.w3.org/TR/css3-mediaqueries/) | 52 * CSS 3 Media Queries Spec (http://www.w3.org/TR/css3-mediaqueries/) |
| 53 */ | 53 */ |
| 54 | 54 |
| 55 DEFINE_GC_INFO(MediaQuerySet); | |
| 56 DEFINE_GC_INFO(MediaList); | |
| 57 | |
| 55 MediaQuerySet::MediaQuerySet() | 58 MediaQuerySet::MediaQuerySet() |
| 56 { | 59 { |
| 57 } | 60 } |
| 58 | 61 |
| 59 MediaQuerySet::MediaQuerySet(const MediaQuerySet& o) | 62 MediaQuerySet::MediaQuerySet(const MediaQuerySet& o) |
| 60 : RefCounted<MediaQuerySet>() | 63 : m_queries(o.m_queries.size()) |
| 61 , m_queries(o.m_queries.size()) | |
| 62 { | 64 { |
| 63 for (unsigned i = 0; i < m_queries.size(); ++i) | 65 for (unsigned i = 0; i < m_queries.size(); ++i) |
| 64 m_queries[i] = o.m_queries[i]->copy(); | 66 m_queries[i] = o.m_queries[i]->copy(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 MediaQuerySet::~MediaQuerySet() | 69 MediaQuerySet::~MediaQuerySet() |
| 68 { | 70 { |
| 69 } | 71 } |
| 70 | 72 |
| 71 PassRefPtr<MediaQuerySet> MediaQuerySet::create(const String& mediaString) | 73 PassRefPtrWillBeRawPtr<MediaQuerySet> MediaQuerySet::create(const String& mediaS tring) |
| 72 { | 74 { |
| 73 if (mediaString.isEmpty()) | 75 if (mediaString.isEmpty()) |
| 74 return MediaQuerySet::create(); | 76 return MediaQuerySet::create(); |
| 75 | 77 |
| 76 BisonCSSParser parser(strictCSSParserContext()); | 78 BisonCSSParser parser(strictCSSParserContext()); |
| 77 return parser.parseMediaQueryList(mediaString); | 79 return parser.parseMediaQueryList(mediaString); |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool MediaQuerySet::set(const String& mediaString) | 82 bool MediaQuerySet::set(const String& mediaString) |
| 81 { | 83 { |
| 82 RefPtr<MediaQuerySet> result = create(mediaString); | 84 RefPtrWillBeRawPtr<MediaQuerySet> result = create(mediaString); |
| 83 m_queries.swap(result->m_queries); | 85 m_queries.swap(result->m_queries); |
| 84 return true; | 86 return true; |
| 85 } | 87 } |
| 86 | 88 |
| 87 bool MediaQuerySet::add(const String& queryString) | 89 bool MediaQuerySet::add(const String& queryString) |
| 88 { | 90 { |
| 89 // To "parse a media query" for a given string means to follow "the parse | 91 // To "parse a media query" for a given string means to follow "the parse |
| 90 // a media query list" steps and return "null" if more than one media query | 92 // a media query list" steps and return "null" if more than one media query |
| 91 // is returned, or else the returned media query. | 93 // is returned, or else the returned media query. |
| 92 RefPtr<MediaQuerySet> result = create(queryString); | 94 RefPtrWillBeRawPtr<MediaQuerySet> result = create(queryString); |
| 93 | 95 |
| 94 // Only continue if exactly one media query is found, as described above. | 96 // Only continue if exactly one media query is found, as described above. |
| 95 if (result->m_queries.size() != 1) | 97 if (result->m_queries.size() != 1) |
| 96 return true; | 98 return true; |
| 97 | 99 |
| 98 OwnPtr<MediaQuery> newQuery = result->m_queries[0].release(); | 100 OwnPtrWillBeRawPtr<MediaQuery> newQuery = result->m_queries[0].release(); |
| 99 ASSERT(newQuery); | 101 ASSERT(newQuery); |
| 100 | 102 |
| 101 // If comparing with any of the media queries in the collection of media | 103 // If comparing with any of the media queries in the collection of media |
| 102 // queries returns true terminate these steps. | 104 // queries returns true terminate these steps. |
| 103 for (size_t i = 0; i < m_queries.size(); ++i) { | 105 for (size_t i = 0; i < m_queries.size(); ++i) { |
| 104 MediaQuery* query = m_queries[i].get(); | 106 MediaQuery* query = m_queries[i].get(); |
| 105 if (*query == *newQuery) | 107 if (*query == *newQuery) |
| 106 return true; | 108 return true; |
| 107 } | 109 } |
| 108 | 110 |
| 109 m_queries.append(newQuery.release()); | 111 m_queries.append(newQuery.release()); |
| 110 return true; | 112 return true; |
| 111 } | 113 } |
| 112 | 114 |
| 113 bool MediaQuerySet::remove(const String& queryStringToRemove) | 115 bool MediaQuerySet::remove(const String& queryStringToRemove) |
| 114 { | 116 { |
| 115 // To "parse a media query" for a given string means to follow "the parse | 117 // To "parse a media query" for a given string means to follow "the parse |
| 116 // a media query list" steps and return "null" if more than one media query | 118 // a media query list" steps and return "null" if more than one media query |
| 117 // is returned, or else the returned media query. | 119 // is returned, or else the returned media query. |
| 118 RefPtr<MediaQuerySet> result = create(queryStringToRemove); | 120 RefPtrWillBeRawPtr<MediaQuerySet> result = create(queryStringToRemove); |
| 119 | 121 |
| 120 // Only continue if exactly one media query is found, as described above. | 122 // Only continue if exactly one media query is found, as described above. |
| 121 if (result->m_queries.size() != 1) | 123 if (result->m_queries.size() != 1) |
| 122 return true; | 124 return true; |
| 123 | 125 |
| 124 OwnPtr<MediaQuery> newQuery = result->m_queries[0].release(); | 126 OwnPtrWillBeRawPtr<MediaQuery> newQuery = result->m_queries[0].release(); |
| 125 ASSERT(newQuery); | 127 ASSERT(newQuery); |
| 126 | 128 |
| 127 // Remove any media query from the collection of media queries for which | 129 // Remove any media query from the collection of media queries for which |
| 128 // comparing with the media query returns true. | 130 // comparing with the media query returns true. |
| 129 bool found = false; | 131 bool found = false; |
| 130 for (size_t i = 0; i < m_queries.size(); ++i) { | 132 for (size_t i = 0; i < m_queries.size(); ++i) { |
| 131 MediaQuery* query = m_queries[i].get(); | 133 MediaQuery* query = m_queries[i].get(); |
| 132 if (*query == *newQuery) { | 134 if (*query == *newQuery) { |
| 133 m_queries.remove(i); | 135 m_queries.remove(i); |
| 134 --i; | 136 --i; |
| 135 found = true; | 137 found = true; |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 return found; | 141 return found; |
| 140 } | 142 } |
| 141 | 143 |
| 142 void MediaQuerySet::addMediaQuery(PassOwnPtr<MediaQuery> mediaQuery) | 144 void MediaQuerySet::addMediaQuery(PassOwnPtrWillBeRawPtr<MediaQuery> mediaQuery) |
| 143 { | 145 { |
| 144 m_queries.append(mediaQuery); | 146 m_queries.append(mediaQuery); |
| 145 } | 147 } |
| 146 | 148 |
| 147 String MediaQuerySet::mediaText() const | 149 String MediaQuerySet::mediaText() const |
| 148 { | 150 { |
| 149 StringBuilder text; | 151 StringBuilder text; |
| 150 | 152 |
| 151 bool first = true; | 153 bool first = true; |
| 152 for (size_t i = 0; i < m_queries.size(); ++i) { | 154 for (size_t i = 0; i < m_queries.size(); ++i) { |
| 153 if (!first) | 155 if (!first) |
| 154 text.appendLiteral(", "); | 156 text.appendLiteral(", "); |
| 155 else | 157 else |
| 156 first = false; | 158 first = false; |
| 157 text.append(m_queries[i]->cssText()); | 159 text.append(m_queries[i]->cssText()); |
| 158 } | 160 } |
| 159 return text.toString(); | 161 return text.toString(); |
| 160 } | 162 } |
| 161 | 163 |
| 164 void MediaQuerySet::trace(Visitor* visitor) | |
| 165 { | |
| 166 // We don't support tracing of vectors of OwnPtrs (ie. OwnPtr<Vector<OwnPtr< MediaQuery> > >). | |
|
haraken
2014/02/21 01:02:36
OwnPtr<Vector<OwnPtr<MediaQuery> > > => Vector<Own
wibling-chromium
2014/02/21 08:43:08
We talked a bit about this locally. We could fix t
wibling-chromium
2014/02/25 12:07:28
I tried this above and both when calling visitor->
haraken
2014/02/25 12:09:57
Makes sense. Having #if in a couple of places in a
| |
| 167 // Since this is a transitional object we are just ifdef'ing it out when oil pan is not enabled. | |
| 168 #if ENABLE(OILPAN) | |
| 169 visitor->trace(m_queries); | |
| 170 #endif | |
| 171 } | |
| 172 | |
| 162 MediaList::MediaList(MediaQuerySet* mediaQueries, CSSStyleSheet* parentSheet) | 173 MediaList::MediaList(MediaQuerySet* mediaQueries, CSSStyleSheet* parentSheet) |
| 163 : m_mediaQueries(mediaQueries) | 174 : m_mediaQueries(mediaQueries) |
| 164 , m_parentStyleSheet(parentSheet) | 175 , m_parentStyleSheet(parentSheet) |
| 165 , m_parentRule(0) | 176 , m_parentRule(0) |
| 166 { | 177 { |
| 167 } | 178 } |
| 168 | 179 |
| 169 MediaList::MediaList(MediaQuerySet* mediaQueries, CSSRule* parentRule) | 180 MediaList::MediaList(MediaQuerySet* mediaQueries, CSSRule* parentRule) |
| 170 : m_mediaQueries(mediaQueries) | 181 : m_mediaQueries(mediaQueries) |
| 171 , m_parentStyleSheet(0) | 182 , m_parentStyleSheet(0) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 182 CSSStyleSheet::RuleMutationScope mutationScope(m_parentRule); | 193 CSSStyleSheet::RuleMutationScope mutationScope(m_parentRule); |
| 183 | 194 |
| 184 m_mediaQueries->set(value); | 195 m_mediaQueries->set(value); |
| 185 | 196 |
| 186 if (m_parentStyleSheet) | 197 if (m_parentStyleSheet) |
| 187 m_parentStyleSheet->didMutate(); | 198 m_parentStyleSheet->didMutate(); |
| 188 } | 199 } |
| 189 | 200 |
| 190 String MediaList::item(unsigned index) const | 201 String MediaList::item(unsigned index) const |
| 191 { | 202 { |
| 192 const Vector<OwnPtr<MediaQuery> >& queries = m_mediaQueries->queryVector(); | 203 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& queries = m_mediaQu eries->queryVector(); |
| 193 if (index < queries.size()) | 204 if (index < queries.size()) |
| 194 return queries[index]->cssText(); | 205 return queries[index]->cssText(); |
| 195 return String(); | 206 return String(); |
| 196 } | 207 } |
| 197 | 208 |
| 198 void MediaList::deleteMedium(const String& medium, ExceptionState& exceptionStat e) | 209 void MediaList::deleteMedium(const String& medium, ExceptionState& exceptionStat e) |
| 199 { | 210 { |
| 200 CSSStyleSheet::RuleMutationScope mutationScope(m_parentRule); | 211 CSSStyleSheet::RuleMutationScope mutationScope(m_parentRule); |
| 201 | 212 |
| 202 bool success = m_mediaQueries->remove(medium); | 213 bool success = m_mediaQueries->remove(medium); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 221 if (m_parentStyleSheet) | 232 if (m_parentStyleSheet) |
| 222 m_parentStyleSheet->didMutate(); | 233 m_parentStyleSheet->didMutate(); |
| 223 } | 234 } |
| 224 | 235 |
| 225 void MediaList::reattach(MediaQuerySet* mediaQueries) | 236 void MediaList::reattach(MediaQuerySet* mediaQueries) |
| 226 { | 237 { |
| 227 ASSERT(mediaQueries); | 238 ASSERT(mediaQueries); |
| 228 m_mediaQueries = mediaQueries; | 239 m_mediaQueries = mediaQueries; |
| 229 } | 240 } |
| 230 | 241 |
| 242 void MediaList::trace(Visitor* visitor) | |
| 243 { | |
| 244 visitor->trace(m_mediaQueries); | |
| 245 } | |
| 246 | |
| 231 static void addResolutionWarningMessageToConsole(Document* document, const Strin g& serializedExpression, const CSSPrimitiveValue* value) | 247 static void addResolutionWarningMessageToConsole(Document* document, const Strin g& serializedExpression, const CSSPrimitiveValue* value) |
| 232 { | 248 { |
| 233 ASSERT(document); | 249 ASSERT(document); |
| 234 ASSERT(value); | 250 ASSERT(value); |
| 235 | 251 |
| 236 DEFINE_STATIC_LOCAL(String, mediaQueryMessage, ("Consider using 'dppx' units instead of '%replacementUnits%', as in CSS '%replacementUnits%' means dots-per- CSS-%lengthUnit%, not dots-per-physical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%' of a screen. In media query expression: ")); | 252 DEFINE_STATIC_LOCAL(String, mediaQueryMessage, ("Consider using 'dppx' units instead of '%replacementUnits%', as in CSS '%replacementUnits%' means dots-per- CSS-%lengthUnit%, not dots-per-physical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%' of a screen. In media query expression: ")); |
| 237 DEFINE_STATIC_LOCAL(String, mediaValueDPI, ("dpi")); | 253 DEFINE_STATIC_LOCAL(String, mediaValueDPI, ("dpi")); |
| 238 DEFINE_STATIC_LOCAL(String, mediaValueDPCM, ("dpcm")); | 254 DEFINE_STATIC_LOCAL(String, mediaValueDPCM, ("dpcm")); |
| 239 DEFINE_STATIC_LOCAL(String, lengthUnitInch, ("inch")); | 255 DEFINE_STATIC_LOCAL(String, lengthUnitInch, ("inch")); |
| 240 DEFINE_STATIC_LOCAL(String, lengthUnitCentimeter, ("centimeter")); | 256 DEFINE_STATIC_LOCAL(String, lengthUnitCentimeter, ("centimeter")); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 257 return mediaFeature == MediaFeatureNames::resolutionMediaFeature | 273 return mediaFeature == MediaFeatureNames::resolutionMediaFeature |
| 258 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature | 274 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature |
| 259 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; | 275 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; |
| 260 } | 276 } |
| 261 | 277 |
| 262 void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* me diaQuerySet) | 278 void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* me diaQuerySet) |
| 263 { | 279 { |
| 264 if (!mediaQuerySet || !document) | 280 if (!mediaQuerySet || !document) |
| 265 return; | 281 return; |
| 266 | 282 |
| 267 const Vector<OwnPtr<MediaQuery> >& mediaQueries = mediaQuerySet->queryVector (); | 283 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& mediaQueries = medi aQuerySet->queryVector(); |
| 268 const size_t queryCount = mediaQueries.size(); | 284 const size_t queryCount = mediaQueries.size(); |
| 269 | 285 |
| 270 if (!queryCount) | 286 if (!queryCount) |
| 271 return; | 287 return; |
| 272 | 288 |
| 273 for (size_t i = 0; i < queryCount; ++i) { | 289 for (size_t i = 0; i < queryCount; ++i) { |
| 274 const MediaQuery* query = mediaQueries[i].get(); | 290 const MediaQuery* query = mediaQueries[i].get(); |
| 275 if (equalIgnoringCase(query->mediaType(), "print")) | 291 if (equalIgnoringCase(query->mediaType(), "print")) |
| 276 continue; | 292 continue; |
| 277 | 293 |
| 278 const ExpressionVector& expressions = query->expressions(); | 294 const ExpressionVector& expressions = query->expressions(); |
| 279 for (size_t j = 0; j < expressions.size(); ++j) { | 295 for (size_t j = 0; j < expressions.size(); ++j) { |
| 280 const MediaQueryExp* expression = expressions.at(j).get(); | 296 const MediaQueryExp* expression = expressions.at(j).get(); |
| 281 if (isResolutionMediaFeature(expression->mediaFeature())) { | 297 if (isResolutionMediaFeature(expression->mediaFeature())) { |
| 282 CSSValue* cssValue = expression->value(); | 298 CSSValue* cssValue = expression->value(); |
| 283 if (cssValue && cssValue->isPrimitiveValue()) { | 299 if (cssValue && cssValue->isPrimitiveValue()) { |
| 284 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV alue); | 300 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV alue); |
| 285 if (primitiveValue->isDotsPerInch() || primitiveValue->isDot sPerCentimeter()) | 301 if (primitiveValue->isDotsPerInch() || primitiveValue->isDot sPerCentimeter()) |
| 286 addResolutionWarningMessageToConsole(document, mediaQuer ySet->mediaText(), primitiveValue); | 302 addResolutionWarningMessageToConsole(document, mediaQuer ySet->mediaText(), primitiveValue); |
| 287 } | 303 } |
| 288 } | 304 } |
| 289 } | 305 } |
| 290 } | 306 } |
| 291 } | 307 } |
| 292 | 308 |
| 293 } | 309 } |
| OLD | NEW |