bool MediaQuerySet::parse(const String& mediaString) { CSSParser parser(CSSStrictMode); Vector<std::unique_ptr<MediaQuery>> result; Vector<String> list; mediaString.split(',', list); for (unsigned i = 0; i < list.size(); ++i) { String medium = list[i].stripWhiteSpace(); if (medium.isEmpty()) { if (!m_fallbackToDescriptor) return false; continue; } std::unique_ptr<MediaQuery> mediaQuery = parser.parseMediaQuery(medium); if (!mediaQuery) { if (!m_fallbackToDescriptor) return false; String mediaDescriptor = parseMediaDescriptor(medium); if (mediaDescriptor.isNull()) continue; mediaQuery = std::make_unique<MediaQuery>(MediaQuery::None, mediaDescriptor, nullptr); } result.append(std::move(mediaQuery)); } // ",,,," falls straight through, but is not valid unless fallback if (!m_fallbackToDescriptor && list.isEmpty()) { String strippedMediaString = mediaString.stripWhiteSpace(); if (!strippedMediaString.isEmpty()) return false; } m_queries = std::move(result); return true; }
bool MediaQuerySet::add(const String& queryString) { CSSParser parser(CSSStrictMode); std::unique_ptr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString); if (!parsedQuery && m_fallbackToDescriptor) { String medium = parseMediaDescriptor(queryString); if (!medium.isNull()) parsedQuery = std::make_unique<MediaQuery>(MediaQuery::None, medium, nullptr); } if (!parsedQuery) return false; m_queries.append(std::move(parsedQuery)); return true; }
bool MediaQuerySet::add(const String& queryString) { CSSParser parser(CSSStrictMode); OwnPtr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString); if (!parsedQuery && m_fallbackToDescriptor) { String medium = parseMediaDescriptor(queryString); if (!medium.isNull()) parsedQuery = adoptPtr(new MediaQuery(MediaQuery::None, medium, nullptr)); } if (!parsedQuery) return false; m_queries.append(parsedQuery.release()); return true; }
void MediaList::appendMedium(const String& newMedium, ExceptionCode& ec) { ec = INVALID_CHARACTER_ERR; CSSParser p(true); if (p.parseMediaQuery(this, newMedium)) { ec = 0; } else if (m_fallback) { String medium = parseMediaDescriptor(newMedium); if (!medium.isNull()) { m_queries.append(new MediaQuery(MediaQuery::None, medium, 0)); ec = 0; } } if (!ec) notifyChanged(); }
void MediaList::setMediaText(const String& value, ExceptionCode& ec) { RefPtr<MediaList> tempMediaList = MediaList::create(); CSSParser p(true); Vector<String> list; value.split(',', list); Vector<String>::const_iterator end = list.end(); for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) { String medium = (*it).stripWhiteSpace(); if (!medium.isEmpty()) { if (!p.parseMediaQuery(tempMediaList.get(), medium)) { if (m_fallback) { String mediaDescriptor = parseMediaDescriptor(medium); if (!mediaDescriptor.isNull()) tempMediaList->m_queries.append(new MediaQuery(MediaQuery::None, mediaDescriptor, 0)); } else { ec = SYNTAX_ERR; return; } } } else if (!m_fallback) { ec = SYNTAX_ERR; return; } } // ",,,," falls straight through, but is not valid unless fallback if (!m_fallback && list.begin() == list.end()) { String s = value.stripWhiteSpace(); if (!s.isEmpty()) { ec = SYNTAX_ERR; return; } } ec = 0; deleteAllValues(m_queries); m_queries = tempMediaList->m_queries; tempMediaList->m_queries.clear(); notifyChanged(); }
void MediaList::deleteMedium(const String& oldMedium, ExceptionCode& ec) { RefPtr<MediaList> tempMediaList = MediaList::create(); CSSParser p(true); MediaQuery* oldQuery = 0; bool deleteOldQuery = false; if (p.parseMediaQuery(tempMediaList.get(), oldMedium)) { if (tempMediaList->m_queries.size() > 0) oldQuery = tempMediaList->m_queries[0]; } else if (m_fallback) { String medium = parseMediaDescriptor(oldMedium); if (!medium.isNull()) { oldQuery = new MediaQuery(MediaQuery::None, medium, 0); deleteOldQuery = true; } } // DOM Style Sheets spec doesn't allow SYNTAX_ERR to be thrown in deleteMedium ec = NOT_FOUND_ERR; if (oldQuery) { for(size_t i = 0; i < m_queries.size(); ++i) { MediaQuery* a = m_queries[i]; if (*a == *oldQuery) { m_queries.remove(i); delete a; ec = 0; break; } } if (deleteOldQuery) delete oldQuery; } if (!ec) notifyChanged(); }
bool MediaQuerySet::remove(const String& queryStringToRemove) { CSSParser parser(CSSStrictMode); std::unique_ptr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryStringToRemove); if (!parsedQuery && m_fallbackToDescriptor) { String medium = parseMediaDescriptor(queryStringToRemove); if (!medium.isNull()) parsedQuery = std::make_unique<MediaQuery>(MediaQuery::None, medium, nullptr); } if (!parsedQuery) return false; for (size_t i = 0; i < m_queries.size(); ++i) { MediaQuery* query = m_queries[i].get(); if (*query == *parsedQuery) { m_queries.remove(i); return true; } } return false; }