This source file includes following definitions.
- serialize
- expressionCompare
- createNotAll
- m_expressions
- m_serializationCache
- cssText
- trace
#include "config.h"
#include "core/css/MediaQuery.h"
#include "MediaTypeNames.h"
#include "core/css/MediaQueryExp.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "wtf/NonCopyingSort.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
String MediaQuery::serialize() const
{
StringBuilder result;
switch (m_restrictor) {
case MediaQuery::Only:
result.append("only ");
break;
case MediaQuery::Not:
result.append("not ");
break;
case MediaQuery::None:
break;
}
if (m_expressions->isEmpty()) {
result.append(m_mediaType);
return result.toString();
}
if (m_mediaType != MediaTypeNames::all || m_restrictor != None) {
result.append(m_mediaType);
result.append(" and ");
}
result.append(m_expressions->at(0)->serialize());
for (size_t i = 1; i < m_expressions->size(); ++i) {
result.append(" and ");
result.append(m_expressions->at(i)->serialize());
}
return result.toString();
}
static bool expressionCompare(const OwnPtrWillBeMember<MediaQueryExp>& a, const OwnPtrWillBeMember<MediaQueryExp>& b)
{
return codePointCompare(a->serialize(), b->serialize()) < 0;
}
PassOwnPtrWillBeRawPtr<MediaQuery> MediaQuery::createNotAll()
{
return adoptPtrWillBeNoop(new MediaQuery(MediaQuery::Not, "all", nullptr));
}
MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtrWillBeRawPtr<ExpressionHeapVector> expressions)
: m_restrictor(r)
, m_mediaType(attemptStaticStringCreation(mediaType.lower()))
, m_expressions(expressions)
{
if (!m_expressions) {
m_expressions = adoptPtrWillBeNoop(new ExpressionHeapVector);
return;
}
nonCopyingSort(m_expressions->begin(), m_expressions->end(), expressionCompare);
MediaQueryExp* key = 0;
for (int i = m_expressions->size() - 1; i >= 0; --i) {
MediaQueryExp* exp = m_expressions->at(i).get();
if (key && *exp == *key)
m_expressions->remove(i);
else
key = exp;
}
}
MediaQuery::MediaQuery(const MediaQuery& o)
: m_restrictor(o.m_restrictor)
, m_mediaType(o.m_mediaType)
, m_expressions(adoptPtrWillBeNoop(new ExpressionHeapVector(o.m_expressions->size())))
, m_serializationCache(o.m_serializationCache)
{
for (unsigned i = 0; i < m_expressions->size(); ++i)
(*m_expressions)[i] = o.m_expressions->at(i)->copy();
}
MediaQuery::~MediaQuery()
{
}
bool MediaQuery::operator==(const MediaQuery& other) const
{
return cssText() == other.cssText();
}
String MediaQuery::cssText() const
{
if (m_serializationCache.isNull())
const_cast<MediaQuery*>(this)->m_serializationCache = serialize();
return m_serializationCache;
}
void MediaQuery::trace(Visitor* visitor)
{
#if ENABLE(OILPAN)
visitor->trace(m_expressions);
#endif
}
}