1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla code.
17 : *
18 : * The Initial Developer of the Original Code is the Mozilla Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2007
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Chris Double <chris.double@double.co.nz>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 : #include "nsIDOMHTMLSourceElement.h"
39 : #include "nsIDOMEventTarget.h"
40 : #include "nsGenericHTMLElement.h"
41 : #include "nsGkAtoms.h"
42 : #include "nsStyleConsts.h"
43 : #include "nsMappedAttributes.h"
44 : #include "nsRuleData.h"
45 : #include "nsHTMLMediaElement.h"
46 : #include "nsCOMPtr.h"
47 : #include "nsThreadUtils.h"
48 :
49 : class nsHTMLSourceElement : public nsGenericHTMLElement,
50 : public nsIDOMHTMLSourceElement
51 : {
52 : public:
53 : nsHTMLSourceElement(already_AddRefed<nsINodeInfo> aNodeInfo);
54 : virtual ~nsHTMLSourceElement();
55 :
56 : // nsISupports
57 : NS_DECL_ISUPPORTS_INHERITED
58 :
59 : // nsIDOMNode
60 0 : NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
61 :
62 : // nsIDOMElement
63 0 : NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
64 :
65 : // nsIDOMHTMLElement
66 0 : NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
67 :
68 : // nsIDOMHTMLSourceElement
69 : NS_DECL_NSIDOMHTMLSOURCEELEMENT
70 :
71 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
72 :
73 : // Override BindToTree() so that we can trigger a load when we add a
74 : // child source element.
75 : virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
76 : nsIContent *aBindingParent,
77 : bool aCompileEventHandlers);
78 :
79 : virtual nsXPCClassInfo* GetClassInfo();
80 : };
81 :
82 :
83 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
84 :
85 :
86 0 : nsHTMLSourceElement::nsHTMLSourceElement(already_AddRefed<nsINodeInfo> aNodeInfo)
87 0 : : nsGenericHTMLElement(aNodeInfo)
88 : {
89 0 : }
90 :
91 0 : nsHTMLSourceElement::~nsHTMLSourceElement()
92 : {
93 0 : }
94 :
95 :
96 0 : NS_IMPL_ADDREF_INHERITED(nsHTMLSourceElement, nsGenericElement)
97 0 : NS_IMPL_RELEASE_INHERITED(nsHTMLSourceElement, nsGenericElement)
98 :
99 :
100 0 : DOMCI_NODE_DATA(HTMLSourceElement, nsHTMLSourceElement)
101 :
102 : // QueryInterface implementation for nsHTMLSourceElement
103 0 : NS_INTERFACE_TABLE_HEAD(nsHTMLSourceElement)
104 0 : NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLSourceElement, nsIDOMHTMLSourceElement)
105 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLSourceElement,
106 : nsGenericHTMLElement)
107 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLSourceElement)
108 :
109 :
110 0 : NS_IMPL_ELEMENT_CLONE(nsHTMLSourceElement)
111 :
112 :
113 0 : NS_IMPL_URI_ATTR(nsHTMLSourceElement, Src, src)
114 0 : NS_IMPL_STRING_ATTR(nsHTMLSourceElement, Type, type)
115 :
116 : nsresult
117 0 : nsHTMLSourceElement::BindToTree(nsIDocument *aDocument,
118 : nsIContent *aParent,
119 : nsIContent *aBindingParent,
120 : bool aCompileEventHandlers)
121 : {
122 : nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
123 : aParent,
124 : aBindingParent,
125 0 : aCompileEventHandlers);
126 0 : NS_ENSURE_SUCCESS(rv, rv);
127 :
128 0 : if (!aParent || !aParent->IsNodeOfType(nsINode::eMEDIA))
129 0 : return NS_OK;
130 :
131 0 : nsHTMLMediaElement* media = static_cast<nsHTMLMediaElement*>(aParent);
132 0 : media->NotifyAddedSource();
133 :
134 0 : return NS_OK;
135 : }
136 :
|