1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is Mozilla Communicator client code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
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 NPL, 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 NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
38
#include "nsIDOMHTMLObjectElement.h"
39
#include "nsGenericHTMLElement.h"
40
#include "nsImageLoadingContent.h"
41
#include "nsHTMLAtoms.h"
42
#include "nsStyleConsts.h"
43
#include "nsDOMError.h"
45
#include "nsIDocument.h"
46
#include "nsIPresShell.h"
47
#include "nsIDOMDocument.h"
48
#include "nsIWebNavigation.h"
49
#include "nsIFormControl.h"
51
class nsHTMLObjectElement : public nsGenericHTMLFormElement,
52
public nsImageLoadingContent,
53
public nsIDOMHTMLObjectElement
56
nsHTMLObjectElement();
57
virtual ~nsHTMLObjectElement();
60
NS_DECL_ISUPPORTS_INHERITED
63
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFormElement::)
66
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
69
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
71
// nsIDOMHTMLObjectElement
72
NS_DECL_NSIDOMHTMLOBJECTELEMENT
74
// Overriden nsIFormControl methods
75
NS_IMETHOD_(PRInt32) GetType() { return NS_FORM_OBJECT; }
77
NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
78
nsIContent* aSubmitElement);
79
NS_IMETHOD SaveState();
80
NS_IMETHOD RestoreState(nsIPresState* aState);
82
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
83
const nsAString& aValue,
84
nsAttrValue& aResult);
85
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
86
const nsHTMLValue& aValue,
87
nsAString& aResult) const;
88
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
89
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
93
NS_NewHTMLObjectElement(nsIHTMLContent** aInstancePtrResult,
94
nsINodeInfo *aNodeInfo, PRBool aFromParser)
96
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
98
nsHTMLObjectElement* it = new nsHTMLObjectElement();
101
return NS_ERROR_OUT_OF_MEMORY;
104
nsresult rv = it->Init(aNodeInfo);
112
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
113
NS_ADDREF(*aInstancePtrResult);
119
nsHTMLObjectElement::nsHTMLObjectElement()
123
nsHTMLObjectElement::~nsHTMLObjectElement()
128
NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement)
129
NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement)
131
// QueryInterface implementation for nsHTMLObjectElement
132
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement,
133
nsGenericHTMLFormElement)
134
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLObjectElement)
135
NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver)
136
NS_INTERFACE_MAP_ENTRY(nsIImageLoadingContent)
137
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLObjectElement)
138
NS_HTML_CONTENT_INTERFACE_MAP_END
140
// nsIDOMHTMLObjectElement
142
nsHTMLObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
144
NS_ENSURE_ARG_POINTER(aReturn);
147
nsRefPtr<nsHTMLObjectElement> it = new nsHTMLObjectElement();
150
return NS_ERROR_OUT_OF_MEMORY;
153
nsresult rv = it->Init(mNodeInfo);
158
CopyInnerTo(it, aDeep);
160
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
168
nsHTMLObjectElement::GetForm(nsIDOMHTMLFormElement** aForm)
170
return nsGenericHTMLFormElement::GetForm(aForm);
176
nsHTMLObjectElement::Reset()
182
nsHTMLObjectElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
183
nsIContent* aSubmitElement)
189
nsHTMLObjectElement::SaveState()
195
nsHTMLObjectElement::RestoreState(nsIPresState* aState)
200
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Code, code)
201
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Align, align)
202
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Archive, archive)
203
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Border, border)
204
NS_IMPL_URI_ATTR(nsHTMLObjectElement, CodeBase, codebase)
205
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, CodeType, codetype)
206
NS_IMPL_URI_ATTR(nsHTMLObjectElement, Data, data)
207
NS_IMPL_BOOL_ATTR(nsHTMLObjectElement, Declare, declare)
208
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Height, height)
209
NS_IMPL_INT_ATTR(nsHTMLObjectElement, Hspace, hspace)
210
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Name, name)
211
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Standby, standby)
212
NS_IMPL_INT_ATTR(nsHTMLObjectElement, TabIndex, tabindex)
213
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Type, type)
214
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, UseMap, usemap)
215
NS_IMPL_INT_ATTR(nsHTMLObjectElement, Vspace, vspace)
216
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Width, width)
220
nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument)
222
NS_ENSURE_ARG_POINTER(aContentDocument);
224
*aContentDocument = nsnull;
230
nsIDocument *sub_doc = mDocument->GetSubDocumentFor(this);
236
return CallQueryInterface(sub_doc, aContentDocument);
240
nsHTMLObjectElement::ParseAttribute(nsIAtom* aAttribute,
241
const nsAString& aValue,
242
nsAttrValue& aResult)
244
if (aAttribute == nsHTMLAtoms::align) {
245
return ParseAlignValue(aValue, aResult);
247
if (aAttribute == nsHTMLAtoms::tabindex) {
248
return aResult.ParseIntWithBounds(aValue, 0, 32767);
250
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
254
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
258
nsHTMLObjectElement::AttributeToString(nsIAtom* aAttribute,
259
const nsHTMLValue& aValue,
260
nsAString& aResult) const
262
if (aAttribute == nsHTMLAtoms::align) {
263
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
264
VAlignValueToString(aValue, aResult);
265
return NS_CONTENT_ATTR_HAS_VALUE;
269
return nsGenericHTMLFormElement::AttributeToString(aAttribute, aValue,
274
MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
277
nsGenericHTMLFormElement::MapImageAlignAttributeInto(aAttributes, aData);
278
nsGenericHTMLFormElement::MapImageBorderAttributeInto(aAttributes, aData);
279
nsGenericHTMLFormElement::MapImageMarginAttributeInto(aAttributes, aData);
280
nsGenericHTMLFormElement::MapImageSizeAttributesInto(aAttributes, aData);
281
nsGenericHTMLFormElement::MapCommonAttributesInto(aAttributes, aData);
284
NS_IMETHODIMP_(PRBool)
285
nsHTMLObjectElement::IsAttributeMapped(const nsIAtom* aAttribute) const
287
static const MappedAttributeEntry* const map[] = {
289
sImageMarginSizeAttributeMap,
290
sImageBorderAttributeMap,
291
sImageAlignAttributeMap,
294
return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
299
nsHTMLObjectElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const
301
aMapRuleFunc = &MapAttributesIntoRule;