Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLAppletElement.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  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #include "nsIDOMHTMLAppletElement.h"
00039 #include "nsIDOMEventReceiver.h"
00040 #include "nsGenericHTMLElement.h"
00041 #include "nsHTMLAtoms.h"
00042 #include "nsStyleConsts.h"
00043 #include "nsPresContext.h"
00044 #include "nsIDocument.h"
00045 #include "nsLayoutAtoms.h"
00046 
00047 // XXX this is to get around conflicts with windows.h defines
00048 // introduced through jni.h
00049 #if defined (XP_WIN) && ! defined (WINCE)
00050 #undef GetClassName
00051 #undef GetObject
00052 #endif
00053 
00054 
00055 class nsHTMLAppletElement : public nsGenericHTMLElement,
00056                             public nsIDOMHTMLAppletElement
00057 {
00058 public:
00059   nsHTMLAppletElement(nsINodeInfo *aNodeInfo, PRBool aFromParser = PR_FALSE);
00060   virtual ~nsHTMLAppletElement();
00061 
00062   // nsISupports
00063   NS_DECL_ISUPPORTS_INHERITED
00064 
00065   // nsIDOMNode
00066   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
00067 
00068   // nsIDOMElement
00069   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
00070 
00071   // nsIDOMHTMLElement
00072   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
00073 
00074   // nsIDOMHTMLAppletElement
00075   NS_DECL_NSIDOMHTMLAPPLETELEMENT
00076 
00077   virtual void DoneAddingChildren();
00078   virtual PRBool IsDoneAddingChildren();
00079 
00080   // nsIContent
00081   // Have to override tabindex for <embed> to act right
00082   NS_IMETHOD GetTabIndex(PRInt32* aTabIndex);
00083   NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
00084   virtual void SetFocus(nsPresContext* aPresContext);
00085   // Let applet decide whether it wants focus from mouse clicks
00086   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull)
00087     { if (aTabIndex) GetTabIndex(aTabIndex); return PR_TRUE; }
00088 
00089   virtual PRBool ParseAttribute(nsIAtom* aAttribute,
00090                                 const nsAString& aValue,
00091                                 nsAttrValue& aResult);
00092   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
00093   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00094 
00095 protected:
00096   PRPackedBool mReflectedApplet;
00097   PRPackedBool mIsDoneAddingChildren;
00098   PRPackedBool mInSetFocus; // Used in SetFocus(nsPresContext*)
00099 };
00100 
00101 
00102 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Applet)
00103 
00104 
00105 nsHTMLAppletElement::nsHTMLAppletElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
00106   : nsGenericHTMLElement(aNodeInfo), mReflectedApplet(PR_FALSE),
00107     mIsDoneAddingChildren(!aFromParser),
00108     mInSetFocus(PR_FALSE)
00109 {
00110 }
00111 
00112 nsHTMLAppletElement::~nsHTMLAppletElement()
00113 {
00114 }
00115 
00116 PRBool
00117 nsHTMLAppletElement::IsDoneAddingChildren()
00118 {
00119   return mIsDoneAddingChildren;
00120 }
00121 
00122 void
00123 nsHTMLAppletElement::DoneAddingChildren()
00124 {
00125   mIsDoneAddingChildren = PR_TRUE;
00126   RecreateFrames();  
00127 }
00128 
00129 NS_IMPL_ADDREF_INHERITED(nsHTMLAppletElement, nsGenericElement) 
00130 NS_IMPL_RELEASE_INHERITED(nsHTMLAppletElement, nsGenericElement) 
00131 
00132 
00133 // QueryInterface implementation for nsHTMLAppletElement
00134 NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLAppletElement, nsGenericHTMLElement)
00135   NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLAppletElement)
00136   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLAppletElement)
00137 NS_HTML_CONTENT_INTERFACE_MAP_END
00138 
00139 
00140 NS_IMPL_DOM_CLONENODE(nsHTMLAppletElement)
00141 
00142 
00143 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Align, align)
00144 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Alt, alt)
00145 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Archive, archive)
00146 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Code, code)
00147 NS_IMPL_URI_ATTR(nsHTMLAppletElement, CodeBase, codebase)
00148 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Height, height)
00149 NS_IMPL_INT_ATTR(nsHTMLAppletElement, Hspace, hspace)
00150 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Name, name)
00151 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Object, object)
00152 NS_IMPL_INT_ATTR(nsHTMLAppletElement, Vspace, vspace)
00153 NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Width, width)
00154 NS_IMPL_INT_ATTR(nsHTMLAppletElement, TabIndex, tabindex)
00155 
00156 void
00157 nsHTMLAppletElement::SetFocus(nsPresContext* aPresContext)
00158 {
00159   if (mInSetFocus) {
00160     NS_WARNING("nsHTMLAppletElement::SetFocus() called recursively on same element");
00161     return;
00162   }
00163   mInSetFocus = PR_TRUE;
00164   nsGenericHTMLElement::SetFocus(aPresContext);
00165   mInSetFocus = PR_FALSE;
00166 }
00167 
00168 PRBool
00169 nsHTMLAppletElement::ParseAttribute(nsIAtom* aAttribute,
00170                                     const nsAString& aValue,
00171                                     nsAttrValue& aResult)
00172 {
00173   if (aAttribute == nsHTMLAtoms::align) {
00174     return nsGenericHTMLElement::ParseAlignValue(aValue, aResult);
00175   }
00176   if (nsGenericHTMLElement::ParseImageAttribute(aAttribute,
00177                                                 aValue, aResult)) {
00178     return PR_TRUE;
00179   }
00180 
00181   return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
00182 }
00183 
00184 static void
00185 MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
00186                       nsRuleData* aData)
00187 {
00188   nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData);
00189   nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
00190   nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
00191   nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
00192   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
00193 }
00194 
00195 NS_IMETHODIMP_(PRBool)
00196 nsHTMLAppletElement::IsAttributeMapped(const nsIAtom* aAttribute) const
00197 {
00198   static const MappedAttributeEntry* const map[] = {
00199     sCommonAttributeMap,
00200     sImageMarginSizeAttributeMap,
00201     sImageAlignAttributeMap,
00202     sImageBorderAttributeMap
00203   };
00204   
00205   return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
00206 }
00207 
00208 nsMapRuleToAttributesFunc
00209 nsHTMLAppletElement::GetAttributeMappingFunction() const
00210 {
00211   return &MapAttributesIntoRule;
00212 }