tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaList.h (3031B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /* base class for representation of media lists */
      8 
      9 #ifndef mozilla_dom_MediaList_h
     10 #define mozilla_dom_MediaList_h
     11 
     12 #include "mozilla/ServoBindingTypes.h"
     13 #include "mozilla/ServoUtils.h"
     14 #include "mozilla/dom/BindingDeclarations.h"
     15 #include "nsWrapperCache.h"
     16 
     17 class nsMediaQueryResultCacheKey;
     18 
     19 namespace mozilla {
     20 class ErrorResult;
     21 class StyleSheet;
     22 
     23 namespace dom {
     24 
     25 class Document;
     26 
     27 class MediaList final : public nsISupports, public nsWrapperCache {
     28 public:
     29  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     30  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(MediaList)
     31 
     32  // Needed for CSSOM, but please don't use it outside of that :)
     33  explicit MediaList(already_AddRefed<StyleLockedMediaList> aRawList)
     34      : mRawList(aRawList) {}
     35 
     36  static already_AddRefed<MediaList> Create(
     37      const nsACString& aMedia, CallerType aCallerType = CallerType::NonSystem);
     38 
     39  already_AddRefed<MediaList> Clone();
     40 
     41  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
     42  nsISupports* GetParentObject() const;
     43 
     44  void GetText(nsACString&) const;
     45  void SetText(const nsACString&);
     46  bool Matches(const Document&) const;
     47  bool IsViewportDependent() const;
     48 
     49  void SetStyleSheet(StyleSheet* aSheet);
     50  void SetRawAfterClone(RefPtr<StyleLockedMediaList> aRaw) {
     51    mRawList = std::move(aRaw);
     52  }
     53 
     54  // WebIDL
     55  void GetMediaText(nsACString& aMediaText) const {
     56    return GetText(aMediaText);
     57  }
     58  void SetMediaText(const nsACString&);
     59  uint32_t Length() const;
     60  void IndexedGetter(uint32_t aIndex, bool& aFound, nsACString&) const;
     61  void Item(uint32_t aIndex, nsACString&);
     62  void DeleteMedium(const nsACString&, ErrorResult&);
     63  void AppendMedium(const nsACString&, ErrorResult&);
     64 
     65  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
     66 
     67  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
     68    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
     69  }
     70 
     71 protected:
     72  MediaList(const nsACString& aMedia, CallerType);
     73  MediaList();
     74 
     75  void SetTextInternal(const nsACString& aMediaText, CallerType);
     76 
     77  void Delete(const nsACString& aOldMedium, ErrorResult& aRv);
     78  void Append(const nsACString& aNewMedium, ErrorResult& aRv);
     79 
     80  ~MediaList() {
     81    MOZ_ASSERT(!mStyleSheet, "Backpointer should have been cleared");
     82  }
     83 
     84  bool IsReadOnly() const;
     85 
     86  // not refcounted; sheet will let us know when it goes away
     87  // mStyleSheet is the sheet that needs to be dirtied when this
     88  // medialist changes
     89  StyleSheet* mStyleSheet = nullptr;
     90 
     91 private:
     92  template <typename Func>
     93  inline void DoMediaChange(Func aCallback, ErrorResult& aRv);
     94  RefPtr<StyleLockedMediaList> mRawList;
     95 };
     96 
     97 }  // namespace dom
     98 }  // namespace mozilla
     99 
    100 #endif  // mozilla_dom_MediaList_h