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