Line data Source code
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/ErrorResult.h"
13 : #include "mozilla/ServoUtils.h"
14 : #include "mozilla/StyleBackendType.h"
15 :
16 : #include "nsIDOMMediaList.h"
17 : #include "nsWrapperCache.h"
18 :
19 : class nsIDocument;
20 : class nsPresContext;
21 : class nsMediaQueryResultCacheKey;
22 :
23 : namespace mozilla {
24 : class StyleSheet;
25 :
26 : namespace dom {
27 :
28 : // XXX This class doesn't use the branch dispatch approach that we use
29 : // elsewhere for stylo, but instead just relies on virtual call.
30 : // That's because this class should not be critical to performance,
31 : // and using branch dispatch would make it much more complicated.
32 : // Performance critical path should hold a subclass of this class
33 : // directly. We may want to determine in the future whether the
34 : // above is correct.
35 :
36 54 : class MediaList : public nsIDOMMediaList
37 : , public nsWrapperCache
38 : {
39 : public:
40 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
41 225 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaList)
42 :
43 : /**
44 : * Creates a MediaList backed by the given StyleBackendType.
45 : */
46 : static already_AddRefed<MediaList> Create(StyleBackendType,
47 : const nsAString& aMedia);
48 :
49 : virtual already_AddRefed<MediaList> Clone() = 0;
50 :
51 : JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
52 0 : nsISupports* GetParentObject() const { return nullptr; }
53 :
54 : virtual void GetText(nsAString& aMediaText) = 0;
55 : virtual void SetText(const nsAString& aMediaText) = 0;
56 : virtual bool Matches(nsPresContext* aPresContext) const = 0;
57 :
58 : #ifdef DEBUG
59 : virtual bool IsServo() const = 0;
60 : #endif
61 :
62 : void SetStyleSheet(StyleSheet* aSheet);
63 :
64 : NS_DECL_NSIDOMMEDIALIST
65 :
66 : // WebIDL
67 : // XPCOM GetMediaText and SetMediaText are fine.
68 : virtual uint32_t Length() = 0;
69 : virtual void IndexedGetter(uint32_t aIndex, bool& aFound,
70 : nsAString& aReturn) = 0;
71 : // XPCOM Item is fine.
72 0 : void DeleteMedium(const nsAString& aMedium, ErrorResult& aRv)
73 : {
74 0 : aRv = DeleteMedium(aMedium);
75 0 : }
76 0 : void AppendMedium(const nsAString& aMedium, ErrorResult& aRv)
77 : {
78 0 : aRv = AppendMedium(aMedium);
79 0 : }
80 :
81 : protected:
82 : virtual nsresult Delete(const nsAString& aOldMedium) = 0;
83 : virtual nsresult Append(const nsAString& aNewMedium) = 0;
84 :
85 0 : virtual ~MediaList() {}
86 :
87 : // not refcounted; sheet will let us know when it goes away
88 : // mStyleSheet is the sheet that needs to be dirtied when this
89 : // medialist changes
90 : StyleSheet* mStyleSheet = nullptr;
91 :
92 : private:
93 : template<typename Func>
94 : inline nsresult DoMediaChange(Func aCallback);
95 : };
96 :
97 : } // namespace dom
98 : } // namespace mozilla
99 :
100 : #endif // mozilla_dom_MediaList_h
|