1 /* 2 * (C) 1999-2003 Lars Knoll (knoll (at) 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 "core/dom/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 31 namespace WebCore { 32 33 class CSSRule; 34 class CSSStyleSheet; 35 class Document; 36 class ExceptionState; 37 class MediaList; 38 class MediaQuery; 39 40 class MediaQuerySet : public RefCounted<MediaQuerySet> { 41 public: 42 static PassRefPtr<MediaQuerySet> create() 43 { 44 return adoptRef(new MediaQuerySet()); 45 } 46 static PassRefPtr<MediaQuerySet> create(const String& mediaString); 47 ~MediaQuerySet(); 48 49 bool set(const String&); 50 bool add(const String&); 51 bool remove(const String&); 52 53 void addMediaQuery(PassOwnPtr<MediaQuery>); 54 55 const Vector<OwnPtr<MediaQuery> >& queryVector() const { return m_queries; } 56 57 String mediaText() const; 58 59 PassRefPtr<MediaQuerySet> copy() const { return adoptRef(new MediaQuerySet(*this)); } 60 61 private: 62 MediaQuerySet(); 63 MediaQuerySet(const MediaQuerySet&); 64 65 Vector<OwnPtr<MediaQuery> > m_queries; 66 }; 67 68 class MediaList : public RefCounted<MediaList> { 69 public: 70 static PassRefPtr<MediaList> create(MediaQuerySet* mediaQueries, CSSStyleSheet* parentSheet) 71 { 72 return adoptRef(new MediaList(mediaQueries, parentSheet)); 73 } 74 static PassRefPtr<MediaList> create(MediaQuerySet* mediaQueries, CSSRule* parentRule) 75 { 76 return adoptRef(new MediaList(mediaQueries, parentRule)); 77 } 78 79 ~MediaList(); 80 81 unsigned length() const { return m_mediaQueries->queryVector().size(); } 82 String item(unsigned index) const; 83 void deleteMedium(const String& oldMedium, ExceptionState&); 84 void appendMedium(const String& newMedium, ExceptionState&); 85 86 String mediaText() const { return m_mediaQueries->mediaText(); } 87 void setMediaText(const String&); 88 89 // Not part of CSSOM. 90 CSSRule* parentRule() const { return m_parentRule; } 91 CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } 92 void clearParentStyleSheet() { ASSERT(m_parentStyleSheet); m_parentStyleSheet = 0; } 93 void clearParentRule() { ASSERT(m_parentRule); m_parentRule = 0; } 94 const MediaQuerySet* queries() const { return m_mediaQueries.get(); } 95 96 void reattach(MediaQuerySet*); 97 98 private: 99 MediaList(); 100 MediaList(MediaQuerySet*, CSSStyleSheet* parentSheet); 101 MediaList(MediaQuerySet*, CSSRule* parentRule); 102 103 RefPtr<MediaQuerySet> m_mediaQueries; 104 CSSStyleSheet* m_parentStyleSheet; 105 CSSRule* m_parentRule; 106 }; 107 108 // Adds message to inspector console whenever dpi or dpcm values are used for "screen" media. 109 void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*); 110 111 } // namespace 112 113 #endif 114