1/*
2 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 * Copyright (C) 2015 Apple Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#pragma once
29
30#include "CSSParserTokenRange.h"
31#include "CSSValue.h"
32#include <memory>
33
34namespace WTF {
35class TextStream;
36}
37
38namespace WebCore {
39
40struct MediaQueryParserContext;
41
42class MediaQueryExpression {
43 WTF_MAKE_FAST_ALLOCATED;
44public:
45 explicit MediaQueryExpression(const String& mediaFeature, CSSParserTokenRange&, MediaQueryParserContext&);
46
47 const AtomicString& mediaFeature() const;
48 CSSValue* value() const;
49
50 bool isValid() const;
51
52 String serialize() const;
53
54 bool operator==(const MediaQueryExpression&) const;
55
56private:
57 AtomicString m_mediaFeature;
58 RefPtr<CSSValue> m_value;
59 bool m_isValid { false };
60 mutable String m_serializationCache;
61};
62
63inline const AtomicString& MediaQueryExpression::mediaFeature() const
64{
65 return m_mediaFeature;
66}
67
68inline CSSValue* MediaQueryExpression::value() const
69{
70 return m_value.get();
71}
72
73inline bool MediaQueryExpression::operator==(const MediaQueryExpression& other) const
74{
75 return other.m_mediaFeature == m_mediaFeature
76 && ((!m_value && !other.m_value) || (m_value && other.m_value && *m_value == *other.m_value));
77}
78
79inline bool MediaQueryExpression::isValid() const
80{
81 return m_isValid;
82}
83
84WTF::TextStream& operator<<(WTF::TextStream&, const MediaQueryExpression&);
85
86} // namespace
87