Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLSharedObjectElement.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "nsIDOMHTMLObjectElement.h"
00038 #include "nsGenericHTMLElement.h"
00039 #include "nsImageLoadingContent.h"
00040 #include "nsHTMLAtoms.h"
00041 #include "nsStyleConsts.h"
00042 #include "nsDOMError.h"
00043 
00044 #include "nsIDocument.h"
00045 #include "nsIPresShell.h"
00046 #include "nsIDOMDocument.h"
00047 #include "nsIWebNavigation.h"
00048 #include "nsIFormControl.h"
00049 
00050 class nsHTMLObjectElement : public nsGenericHTMLFormElement,
00051                             public nsImageLoadingContent,
00052                             public nsIDOMHTMLObjectElement
00053 {
00054 public:
00055   nsHTMLObjectElement(nsINodeInfo *aNodeInfo);
00056   virtual ~nsHTMLObjectElement();
00057 
00058   // nsISupports
00059   NS_DECL_ISUPPORTS_INHERITED
00060 
00061   // nsIDOMNode
00062   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFormElement::)
00063 
00064   // nsIDOMElement
00065   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
00066 
00067   // nsIDOMHTMLElement
00068   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
00069 
00070   // nsIDOMHTMLObjectElement
00071   NS_DECL_NSIDOMHTMLOBJECTELEMENT
00072   
00073   // nsIContent
00074   // Let plugin decide whether it wants focus from mouse clicks
00075   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull)
00076     { if (aTabIndex) GetTabIndex(aTabIndex); return PR_TRUE; }
00077 
00078   // Overriden nsIFormControl methods
00079   NS_IMETHOD_(PRInt32) GetType()
00080   {
00081     return NS_FORM_OBJECT;
00082   }
00083 
00084   NS_IMETHOD Reset();
00085   NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
00086                                nsIContent* aSubmitElement);
00087   NS_IMETHOD SaveState();
00088   virtual PRBool RestoreState(nsPresState* aState);
00089 
00090   virtual PRBool ParseAttribute(nsIAtom* aAttribute,
00091                                 const nsAString& aValue,
00092                                 nsAttrValue& aResult);
00093   nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
00094   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00095 };
00096 
00097 
00098 NS_IMPL_NS_NEW_HTML_ELEMENT(Object)
00099 
00100 
00101 nsHTMLObjectElement::nsHTMLObjectElement(nsINodeInfo *aNodeInfo)
00102   : nsGenericHTMLFormElement(aNodeInfo)
00103 {
00104 }
00105 
00106 nsHTMLObjectElement::~nsHTMLObjectElement()
00107 {
00108   DestroyImageLoadingContent();
00109 }
00110 
00111 
00112 NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement) 
00113 NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement) 
00114 
00115 // QueryInterface implementation for nsHTMLObjectElement
00116 NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement,
00117                                     nsGenericHTMLFormElement)
00118   NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLObjectElement)
00119   NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver)
00120   NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver_MOZILLA_1_8_BRANCH)
00121   NS_INTERFACE_MAP_ENTRY(nsIImageLoadingContent)
00122   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLObjectElement)
00123 NS_HTML_CONTENT_INTERFACE_MAP_END
00124 
00125 // nsIDOMHTMLObjectElement
00126 
00127 
00128 NS_IMPL_DOM_CLONENODE(nsHTMLObjectElement)
00129 
00130 
00131 NS_IMETHODIMP
00132 nsHTMLObjectElement::GetForm(nsIDOMHTMLFormElement** aForm)
00133 {
00134   return nsGenericHTMLFormElement::GetForm(aForm);
00135 }
00136 
00137 // nsIFormControl
00138 
00139 NS_IMETHODIMP
00140 nsHTMLObjectElement::Reset()
00141 {
00142   return NS_OK;
00143 }
00144 
00145 NS_IMETHODIMP
00146 nsHTMLObjectElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
00147                                        nsIContent* aSubmitElement)
00148 {
00149   return NS_OK;
00150 }
00151 
00152 NS_IMETHODIMP
00153 nsHTMLObjectElement::SaveState()
00154 {
00155   return NS_OK;
00156 }
00157 
00158 PRBool
00159 nsHTMLObjectElement::RestoreState(nsPresState* aState)
00160 {
00161   return PR_FALSE;
00162 }
00163 
00164 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Code, code)
00165 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Align, align)
00166 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Archive, archive)
00167 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Border, border)
00168 NS_IMPL_URI_ATTR(nsHTMLObjectElement, CodeBase, codebase)
00169 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, CodeType, codetype)
00170 NS_IMPL_URI_ATTR(nsHTMLObjectElement, Data, data)
00171 NS_IMPL_BOOL_ATTR(nsHTMLObjectElement, Declare, declare)
00172 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Height, height)
00173 NS_IMPL_INT_ATTR(nsHTMLObjectElement, Hspace, hspace)
00174 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Name, name)
00175 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Standby, standby)
00176 NS_IMPL_INT_ATTR(nsHTMLObjectElement, TabIndex, tabindex)
00177 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Type, type)
00178 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, UseMap, usemap)
00179 NS_IMPL_INT_ATTR(nsHTMLObjectElement, Vspace, vspace)
00180 NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Width, width)
00181 
00182 
00183 NS_IMETHODIMP
00184 nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument)
00185 {
00186   NS_ENSURE_ARG_POINTER(aContentDocument);
00187 
00188   *aContentDocument = nsnull;
00189 
00190   if (!mDocument) {
00191     return NS_OK;
00192   }
00193 
00194   nsIDocument *sub_doc = mDocument->GetSubDocumentFor(this);
00195 
00196   if (!sub_doc) {
00197     return NS_OK;
00198   }
00199 
00200   return CallQueryInterface(sub_doc, aContentDocument);
00201 }
00202 
00203 PRBool
00204 nsHTMLObjectElement::ParseAttribute(nsIAtom* aAttribute,
00205                                     const nsAString& aValue,
00206                                     nsAttrValue& aResult)
00207 {
00208   if (aAttribute == nsHTMLAtoms::align) {
00209     return ParseAlignValue(aValue, aResult);
00210   }
00211   if (ParseImageAttribute(aAttribute, aValue, aResult)) {
00212     return PR_TRUE;
00213   }
00214 
00215   return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
00216 }
00217 
00218 static void
00219 MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
00220                       nsRuleData* aData)
00221 {
00222   nsGenericHTMLFormElement::MapImageAlignAttributeInto(aAttributes, aData);
00223   nsGenericHTMLFormElement::MapImageBorderAttributeInto(aAttributes, aData);
00224   nsGenericHTMLFormElement::MapImageMarginAttributeInto(aAttributes, aData);
00225   nsGenericHTMLFormElement::MapImageSizeAttributesInto(aAttributes, aData);
00226   nsGenericHTMLFormElement::MapCommonAttributesInto(aAttributes, aData);
00227 }
00228 
00229 NS_IMETHODIMP_(PRBool)
00230 nsHTMLObjectElement::IsAttributeMapped(const nsIAtom* aAttribute) const
00231 {
00232   static const MappedAttributeEntry* const map[] = {
00233     sCommonAttributeMap,
00234     sImageMarginSizeAttributeMap,
00235     sImageBorderAttributeMap,
00236     sImageAlignAttributeMap,
00237   };
00238 
00239   return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
00240 }
00241 
00242 
00243 nsMapRuleToAttributesFunc
00244 nsHTMLObjectElement::GetAttributeMappingFunction() const
00245 {
00246   return &MapAttributesIntoRule;
00247 }