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 "platform/heap/Handle.h" 26 #include "wtf/Forward.h" 27 #include "wtf/PassRefPtr.h" 28 #include "wtf/RefCounted.h" 29 #include "wtf/Vector.h" 30 #include "wtf/text/WTFString.h" 31 32 namespace WebCore { 33 34 class CSSRule; 35 class CSSStyleSheet; 36 class Document; 37 class ExceptionState; 38 class MediaList; 39 class MediaQuery; 40 41 class MediaQuerySet : public RefCountedWillBeGarbageCollected<MediaQuerySet> { 42 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQuerySet); 43 public: 44 static PassRefPtrWillBeRawPtr<MediaQuerySet> create() 45 { 46 return adoptRefWillBeNoop(new MediaQuerySet()); 47 } 48 static PassRefPtrWillBeRawPtr<MediaQuerySet> create(const String& mediaString); 49 static PassRefPtrWillBeRawPtr<MediaQuerySet> createOffMainThread(const String& mediaString); 50 51 bool set(const String&); 52 bool add(const String&); 53 bool remove(const String&); 54 55 void addMediaQuery(PassOwnPtrWillBeRawPtr<MediaQuery>); 56 57 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& queryVector() const { return m_queries; } 58 59 String mediaText() const; 60 61 PassRefPtrWillBeRawPtr<MediaQuerySet> copy() const { return adoptRefWillBeNoop(new MediaQuerySet(*this)); } 62 63 void trace(Visitor*); 64 65 private: 66 MediaQuerySet(); 67 MediaQuerySet(const MediaQuerySet&); 68 69 WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> > m_queries; 70 }; 71 72 class MediaList : public RefCountedWillBeGarbageCollectedFinalized<MediaList> { 73 public: 74 static PassRefPtrWillBeRawPtr<MediaList> create(MediaQuerySet* mediaQueries, CSSStyleSheet* parentSheet) 75 { 76 return adoptRefWillBeNoop(new MediaList(mediaQueries, parentSheet)); 77 } 78 static PassRefPtrWillBeRawPtr<MediaList> create(MediaQuerySet* mediaQueries, CSSRule* parentRule) 79 { 80 return adoptRefWillBeNoop(new MediaList(mediaQueries, parentRule)); 81 } 82 83 ~MediaList(); 84 85 unsigned length() const { return m_mediaQueries->queryVector().size(); } 86 String item(unsigned index) const; 87 void deleteMedium(const String& oldMedium, ExceptionState&); 88 void appendMedium(const String& newMedium, ExceptionState&); 89 90 String mediaText() const { return m_mediaQueries->mediaText(); } 91 void setMediaText(const String&); 92 93 // Not part of CSSOM. 94 CSSRule* parentRule() const { return m_parentRule; } 95 CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } 96 97 #if !ENABLE(OILPAN) 98 void clearParentStyleSheet() { ASSERT(m_parentStyleSheet); m_parentStyleSheet = nullptr; } 99 void clearParentRule() { ASSERT(m_parentRule); m_parentRule = nullptr; } 100 #endif 101 102 const MediaQuerySet* queries() const { return m_mediaQueries.get(); } 103 104 void reattach(MediaQuerySet*); 105 106 void trace(Visitor*); 107 108 private: 109 MediaList(); 110 MediaList(MediaQuerySet*, CSSStyleSheet* parentSheet); 111 MediaList(MediaQuerySet*, CSSRule* parentRule); 112 113 RefPtrWillBeMember<MediaQuerySet> m_mediaQueries; 114 // Cleared in ~CSSStyleSheet destructor when oilpan is not enabled. 115 RawPtrWillBeMember<CSSStyleSheet> m_parentStyleSheet; 116 // Cleared in the ~CSSMediaRule and ~CSSImportRule destructors when oilpan is not enabled. 117 RawPtrWillBeMember<CSSRule> m_parentRule; 118 }; 119 120 // Adds message to inspector console whenever dpi or dpcm values are used for "screen" media. 121 void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*); 122 123 } // namespace 124 125 #endif 126