1 /* 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 2004, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights 4 * reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_MEDIA_LIST_H_ 23 #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_MEDIA_LIST_H_ 24 25 #include "third_party/blink/renderer/core/core_export.h" 26 #include "third_party/blink/renderer/core/css/media_query.h" 27 #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" 28 #include "third_party/blink/renderer/platform/heap/handle.h" 29 #include "third_party/blink/renderer/platform/wtf/forward.h" 30 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 31 #include "third_party/blink/renderer/platform/wtf/vector.h" 32 33 namespace blink { 34 35 class CSSRule; 36 class CSSStyleSheet; 37 class ExceptionState; 38 class ExecutionContext; 39 class MediaList; 40 class MediaQuery; 41 42 class CORE_EXPORT MediaQuerySet : public RefCounted<MediaQuerySet> { 43 public: Create()44 static scoped_refptr<MediaQuerySet> Create() { 45 return base::AdoptRef(new MediaQuerySet()); 46 } 47 static scoped_refptr<MediaQuerySet> Create(const String& media_string, 48 const ExecutionContext*); 49 50 bool Set(const String&, const ExecutionContext*); 51 bool Add(const String&, const ExecutionContext*); 52 bool Remove(const String&, const ExecutionContext*); 53 54 void AddMediaQuery(std::unique_ptr<MediaQuery>); 55 QueryVector()56 const Vector<std::unique_ptr<MediaQuery>>& QueryVector() const { 57 return queries_; 58 } 59 60 String MediaText() const; 61 Copy()62 scoped_refptr<MediaQuerySet> Copy() const { 63 return base::AdoptRef(new MediaQuerySet(*this)); 64 } 65 66 private: 67 MediaQuerySet(); 68 MediaQuerySet(const MediaQuerySet&); 69 70 Vector<std::unique_ptr<MediaQuery>> queries_; 71 }; 72 73 class MediaList final : public ScriptWrappable { 74 DEFINE_WRAPPERTYPEINFO(); 75 76 public: 77 MediaList(scoped_refptr<MediaQuerySet>, CSSStyleSheet* parent_sheet); 78 MediaList(scoped_refptr<MediaQuerySet>, CSSRule* parent_rule); 79 length()80 unsigned length() const { return media_queries_->QueryVector().size(); } 81 String item(unsigned index) const; 82 void deleteMedium(const ExecutionContext*, 83 const String& old_medium, 84 ExceptionState&); 85 void appendMedium(const ExecutionContext*, const String& new_medium); 86 87 // Note that this getter doesn't require the ExecutionContext, but the 88 // attribute is marked as [CallWith=ExecutionContext] so that the setter can 89 // have access to the ExecutionContext. mediaText(const ExecutionContext *)90 String mediaText(const ExecutionContext*) const { 91 return media_queries_->MediaText(); 92 } 93 void setMediaText(const ExecutionContext*, const String&); 94 95 // Not part of CSSOM. ParentRule()96 CSSRule* ParentRule() const { return parent_rule_; } ParentStyleSheet()97 CSSStyleSheet* ParentStyleSheet() const { return parent_style_sheet_; } 98 Queries()99 const MediaQuerySet* Queries() const { return media_queries_.get(); } 100 101 void Reattach(scoped_refptr<MediaQuerySet>); 102 103 void Trace(Visitor*) const override; 104 105 private: 106 scoped_refptr<MediaQuerySet> media_queries_; 107 Member<CSSStyleSheet> parent_style_sheet_; 108 Member<CSSRule> parent_rule_; 109 }; 110 111 } // namespace blink 112 113 #endif 114