~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is Mozilla Communicator client code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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 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.
 
36
 *
 
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"
 
44
 
 
45
#include "nsIDocument.h"
 
46
#include "nsIPresShell.h"
 
47
#include "nsIDOMDocument.h"
 
48
#include "nsIWebNavigation.h"
 
49
#include "nsIFormControl.h"
 
50
 
 
51
class nsHTMLObjectElement : public nsGenericHTMLFormElement,
 
52
                            public nsImageLoadingContent,
 
53
                            public nsIDOMHTMLObjectElement
 
54
{
 
55
public:
 
56
  nsHTMLObjectElement();
 
57
  virtual ~nsHTMLObjectElement();
 
58
 
 
59
  // nsISupports
 
60
  NS_DECL_ISUPPORTS_INHERITED
 
61
 
 
62
  // nsIDOMNode
 
63
  NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFormElement::)
 
64
 
 
65
  // nsIDOMElement
 
66
  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
 
67
 
 
68
  // nsIDOMHTMLElement
 
69
  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
 
70
 
 
71
  // nsIDOMHTMLObjectElement
 
72
  NS_DECL_NSIDOMHTMLOBJECTELEMENT
 
73
 
 
74
  // Overriden nsIFormControl methods
 
75
  NS_IMETHOD_(PRInt32) GetType() { return NS_FORM_OBJECT; }
 
76
  NS_IMETHOD Reset();
 
77
  NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
 
78
                               nsIContent* aSubmitElement);
 
79
  NS_IMETHOD SaveState();
 
80
  NS_IMETHOD RestoreState(nsIPresState* aState);
 
81
 
 
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;
 
90
};
 
91
 
 
92
nsresult
 
93
NS_NewHTMLObjectElement(nsIHTMLContent** aInstancePtrResult,
 
94
                        nsINodeInfo *aNodeInfo, PRBool aFromParser)
 
95
{
 
96
  NS_ENSURE_ARG_POINTER(aInstancePtrResult);
 
97
 
 
98
  nsHTMLObjectElement* it = new nsHTMLObjectElement();
 
99
 
 
100
  if (!it) {
 
101
    return NS_ERROR_OUT_OF_MEMORY;
 
102
  }
 
103
 
 
104
  nsresult rv = it->Init(aNodeInfo);
 
105
 
 
106
  if (NS_FAILED(rv)) {
 
107
    delete it;
 
108
 
 
109
    return rv;
 
110
  }
 
111
 
 
112
  *aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
 
113
  NS_ADDREF(*aInstancePtrResult);
 
114
 
 
115
  return NS_OK;
 
116
}
 
117
 
 
118
 
 
119
nsHTMLObjectElement::nsHTMLObjectElement()
 
120
{
 
121
}
 
122
 
 
123
nsHTMLObjectElement::~nsHTMLObjectElement()
 
124
{
 
125
}
 
126
 
 
127
 
 
128
NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement) 
 
129
NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement) 
 
130
 
 
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
 
139
 
 
140
// nsIDOMHTMLObjectElement
 
141
nsresult
 
142
nsHTMLObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
 
143
{
 
144
  NS_ENSURE_ARG_POINTER(aReturn);
 
145
  *aReturn = nsnull;
 
146
 
 
147
  nsRefPtr<nsHTMLObjectElement> it = new nsHTMLObjectElement();
 
148
 
 
149
  if (!it) {
 
150
    return NS_ERROR_OUT_OF_MEMORY;
 
151
  }
 
152
 
 
153
  nsresult rv = it->Init(mNodeInfo);
 
154
 
 
155
  if (NS_FAILED(rv))
 
156
    return rv;
 
157
 
 
158
  CopyInnerTo(it, aDeep);
 
159
 
 
160
  *aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
 
161
 
 
162
  NS_ADDREF(*aReturn);
 
163
 
 
164
  return NS_OK;
 
165
}
 
166
 
 
167
NS_IMETHODIMP
 
168
nsHTMLObjectElement::GetForm(nsIDOMHTMLFormElement** aForm)
 
169
{
 
170
  return nsGenericHTMLFormElement::GetForm(aForm);
 
171
}
 
172
 
 
173
// nsIFormControl
 
174
 
 
175
NS_IMETHODIMP
 
176
nsHTMLObjectElement::Reset()
 
177
{
 
178
  return NS_OK;
 
179
}
 
180
 
 
181
NS_IMETHODIMP
 
182
nsHTMLObjectElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
 
183
                                       nsIContent* aSubmitElement)
 
184
{
 
185
  return NS_OK;
 
186
}
 
187
 
 
188
NS_IMETHODIMP
 
189
nsHTMLObjectElement::SaveState()
 
190
{
 
191
  return NS_OK;
 
192
}
 
193
 
 
194
NS_IMETHODIMP
 
195
nsHTMLObjectElement::RestoreState(nsIPresState* aState)
 
196
{
 
197
  return NS_OK;
 
198
}
 
199
 
 
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)
 
217
 
 
218
 
 
219
NS_IMETHODIMP
 
220
nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument)
 
221
{
 
222
  NS_ENSURE_ARG_POINTER(aContentDocument);
 
223
 
 
224
  *aContentDocument = nsnull;
 
225
 
 
226
  if (!mDocument) {
 
227
    return NS_OK;
 
228
  }
 
229
 
 
230
  nsIDocument *sub_doc = mDocument->GetSubDocumentFor(this);
 
231
 
 
232
  if (!sub_doc) {
 
233
    return NS_OK;
 
234
  }
 
235
 
 
236
  return CallQueryInterface(sub_doc, aContentDocument);
 
237
}
 
238
 
 
239
PRBool
 
240
nsHTMLObjectElement::ParseAttribute(nsIAtom* aAttribute,
 
241
                                    const nsAString& aValue,
 
242
                                    nsAttrValue& aResult)
 
243
{
 
244
  if (aAttribute == nsHTMLAtoms::align) {
 
245
    return ParseAlignValue(aValue, aResult);
 
246
  }
 
247
  if (aAttribute == nsHTMLAtoms::tabindex) {
 
248
    return aResult.ParseIntWithBounds(aValue, 0, 32767);
 
249
  }
 
250
  if (ParseImageAttribute(aAttribute, aValue, aResult)) {
 
251
    return PR_TRUE;
 
252
  }
 
253
 
 
254
  return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
 
255
}
 
256
 
 
257
NS_IMETHODIMP
 
258
nsHTMLObjectElement::AttributeToString(nsIAtom* aAttribute,
 
259
                                       const nsHTMLValue& aValue,
 
260
                                       nsAString& aResult) const
 
261
{
 
262
  if (aAttribute == nsHTMLAtoms::align) {
 
263
    if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
 
264
      VAlignValueToString(aValue, aResult);
 
265
      return NS_CONTENT_ATTR_HAS_VALUE;
 
266
    }
 
267
  }
 
268
 
 
269
  return nsGenericHTMLFormElement::AttributeToString(aAttribute, aValue,
 
270
                                                     aResult);
 
271
}
 
272
 
 
273
static void
 
274
MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
 
275
                      nsRuleData* aData)
 
276
{
 
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);
 
282
}
 
283
 
 
284
NS_IMETHODIMP_(PRBool)
 
285
nsHTMLObjectElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 
286
{
 
287
  static const MappedAttributeEntry* const map[] = {
 
288
    sCommonAttributeMap,
 
289
    sImageMarginSizeAttributeMap,
 
290
    sImageBorderAttributeMap,
 
291
    sImageAlignAttributeMap,
 
292
  };
 
293
 
 
294
  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
 
295
}
 
296
 
 
297
 
 
298
NS_IMETHODIMP
 
299
nsHTMLObjectElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const
 
300
{
 
301
  aMapRuleFunc = &MapAttributesIntoRule;
 
302
  return NS_OK;
 
303
}