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 : #ifndef mozilla_dom_HTMLSourceElement_h
8 : #define mozilla_dom_HTMLSourceElement_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "nsIDOMHTMLSourceElement.h"
12 : #include "nsGenericHTMLElement.h"
13 : #include "mozilla/dom/HTMLMediaElement.h"
14 :
15 : class nsAttrValue;
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : class MediaList;
21 :
22 : class HTMLSourceElement final : public nsGenericHTMLElement,
23 : public nsIDOMHTMLSourceElement
24 : {
25 : public:
26 : explicit HTMLSourceElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
27 :
28 : // nsISupports
29 : NS_DECL_ISUPPORTS_INHERITED
30 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSourceElement,
31 : nsGenericHTMLElement)
32 :
33 0 : NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLSourceElement, source)
34 :
35 : // nsIDOMHTMLSourceElement
36 : NS_DECL_NSIDOMHTMLSOURCEELEMENT
37 :
38 : virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult,
39 : bool aPreallocateChildren) const override;
40 :
41 : // Override BindToTree() so that we can trigger a load when we add a
42 : // child source element.
43 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
44 : nsIContent* aBindingParent,
45 : bool aCompileEventHandlers) override;
46 :
47 : // If this element's media attr matches for its owner document. Returns true
48 : // if no media attr was set.
49 : bool MatchesCurrentMedia();
50 :
51 : // True if a source tag would match the given media attribute for the
52 : // specified document. Used by the preloader to determine valid <source> tags
53 : // prior to DOM creation.
54 : static bool WouldMatchMediaForDocument(const nsAString& aMediaStr,
55 : const nsIDocument *aDocument);
56 :
57 : // Return the MediaSource object if any associated with the src attribute
58 : // when it was set.
59 0 : MediaSource* GetSrcMediaSource() { return mSrcMediaSource; };
60 :
61 : // WebIDL
62 0 : void GetSrc(nsString& aSrc)
63 : {
64 0 : GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
65 0 : }
66 0 : void SetSrc(const nsAString& aSrc, mozilla::ErrorResult& rv)
67 : {
68 0 : SetHTMLAttr(nsGkAtoms::src, aSrc, rv);
69 0 : }
70 :
71 0 : void GetType(DOMString& aType)
72 : {
73 0 : GetHTMLAttr(nsGkAtoms::type, aType);
74 0 : }
75 0 : void SetType(const nsAString& aType, ErrorResult& rv)
76 : {
77 0 : SetHTMLAttr(nsGkAtoms::type, aType, rv);
78 0 : }
79 :
80 0 : void GetSrcset(DOMString& aSrcset)
81 : {
82 0 : GetHTMLAttr(nsGkAtoms::srcset, aSrcset);
83 0 : }
84 0 : void SetSrcset(const nsAString& aSrcset, mozilla::ErrorResult& rv)
85 : {
86 0 : SetHTMLAttr(nsGkAtoms::srcset, aSrcset, rv);
87 0 : }
88 :
89 0 : void GetSizes(DOMString& aSizes)
90 : {
91 0 : GetHTMLAttr(nsGkAtoms::sizes, aSizes);
92 0 : }
93 0 : void SetSizes(const nsAString& aSizes, mozilla::ErrorResult& rv)
94 : {
95 0 : SetHTMLAttr(nsGkAtoms::sizes, aSizes, rv);
96 0 : }
97 :
98 0 : void GetMedia(DOMString& aMedia)
99 : {
100 0 : GetHTMLAttr(nsGkAtoms::media, aMedia);
101 0 : }
102 0 : void SetMedia(const nsAString& aMedia, mozilla::ErrorResult& rv)
103 : {
104 0 : SetHTMLAttr(nsGkAtoms::media, aMedia, rv);
105 0 : }
106 :
107 : protected:
108 : virtual ~HTMLSourceElement();
109 :
110 : virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
111 :
112 : protected:
113 : virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
114 : const nsAttrValue* aValue,
115 : const nsAttrValue* aOldValue,
116 : bool aNotify) override;
117 :
118 : private:
119 : RefPtr<MediaList> mMediaList;
120 : RefPtr<MediaSource> mSrcMediaSource;
121 :
122 : // Generates a new MediaList using the given input
123 : void UpdateMediaList(const nsAttrValue* aValue);
124 : };
125 :
126 : } // namespace dom
127 : } // namespace mozilla
128 :
129 : #endif // mozilla_dom_HTMLSourceElement_h
|