1/* 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 2004, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21#ifndef MediaList_h 22#define MediaList_h 23 24#include "ExceptionCode.h" 25#include <wtf/Forward.h> 26#include <wtf/PassRefPtr.h> 27#include <wtf/RefCounted.h> 28#include <wtf/Vector.h> 29#include <wtf/text/WTFString.h> 30 31namespace WebCore { 32 33class CSSRule; 34class CSSStyleSheet; 35class Document; 36class MediaList; 37class MediaQuery; 38 39class MediaQuerySet : public RefCounted<MediaQuerySet> { 40public: 41 static PassRefPtr<MediaQuerySet> create() 42 { 43 return adoptRef(new MediaQuerySet()); 44 } 45 static PassRefPtr<MediaQuerySet> create(const String& mediaString) 46 { 47 return adoptRef(new MediaQuerySet(mediaString, false)); 48 } 49 static PassRefPtr<MediaQuerySet> createAllowingDescriptionSyntax(const String& mediaString) 50 { 51 return adoptRef(new MediaQuerySet(mediaString, true)); 52 } 53 ~MediaQuerySet(); 54 55 bool parse(const String&); 56 bool add(const String&); 57 bool remove(const String&); 58 59 void addMediaQuery(PassOwnPtr<MediaQuery>); 60 61 const Vector<OwnPtr<MediaQuery> >& queryVector() const { return m_queries; } 62 63 int lastLine() const { return m_lastLine; } 64 void setLastLine(int lastLine) { m_lastLine = lastLine; } 65 66 String mediaText() const; 67 68 PassRefPtr<MediaQuerySet> copy() const { return adoptRef(new MediaQuerySet(*this)); } 69 70private: 71 MediaQuerySet(); 72 MediaQuerySet(const String& mediaQuery, bool fallbackToDescription); 73 MediaQuerySet(const MediaQuerySet&); 74 75 unsigned m_fallbackToDescriptor : 1; // true if failed media query parsing should fallback to media description parsing. 76 signed m_lastLine : 31; 77 Vector<OwnPtr<MediaQuery> > m_queries; 78}; 79 80class MediaList : public RefCounted<MediaList> { 81public: 82 static PassRefPtr<MediaList> create(MediaQuerySet* mediaQueries, CSSStyleSheet* parentSheet) 83 { 84 return adoptRef(new MediaList(mediaQueries, parentSheet)); 85 } 86 static PassRefPtr<MediaList> create(MediaQuerySet* mediaQueries, CSSRule* parentRule) 87 { 88 return adoptRef(new MediaList(mediaQueries, parentRule)); 89 } 90 91 ~MediaList(); 92 93 unsigned length() const { return m_mediaQueries->queryVector().size(); } 94 String item(unsigned index) const; 95 void deleteMedium(const String& oldMedium, ExceptionCode&); 96 void appendMedium(const String& newMedium, ExceptionCode&); 97 98 String mediaText() const { return m_mediaQueries->mediaText(); } 99 void setMediaText(const String&, ExceptionCode&); 100 101 // Not part of CSSOM. 102 CSSRule* parentRule() const { return m_parentRule; } 103 CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } 104 void clearParentStyleSheet() { ASSERT(m_parentStyleSheet); m_parentStyleSheet = 0; } 105 void clearParentRule() { ASSERT(m_parentRule); m_parentRule = 0; } 106 const MediaQuerySet* queries() const { return m_mediaQueries.get(); } 107 108 void reattach(MediaQuerySet*); 109 110private: 111 MediaList(); 112 MediaList(MediaQuerySet*, CSSStyleSheet* parentSheet); 113 MediaList(MediaQuerySet*, CSSRule* parentRule); 114 115 RefPtr<MediaQuerySet> m_mediaQueries; 116 CSSStyleSheet* m_parentStyleSheet; 117 CSSRule* m_parentRule; 118}; 119 120#if ENABLE(RESOLUTION_MEDIA_QUERY) 121// Adds message to inspector console whenever dpi or dpcm values are used for "screen" media. 122void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*); 123#endif 124 125} // namespace 126 127#endif 128