Back to index

lightning-sunbird  0.9+nobinonly
nsGenericHTMLElement.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
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 #ifndef nsGenericHTMLElement_h___
00039 #define nsGenericHTMLElement_h___
00040 
00041 #include "nsGenericElement.h"
00042 #include "nsIDOMHTMLElement.h"
00043 #include "nsINameSpaceManager.h"  // for kNameSpaceID_None
00044 #include "nsIFormControl.h"
00045 #include "nsIDOMNSHTMLFrameElement.h"
00046 #include "nsIChromeEventHandler.h"
00047 #include "nsFrameLoader.h"
00048 
00049 class nsIDOMAttr;
00050 class nsIDOMEventListener;
00051 class nsIDOMNodeList;
00052 class nsIFrame;
00053 class nsMappedAttributes;
00054 class nsIStyleRule;
00055 class nsISupportsArray;
00056 class nsChildContentList;
00057 class nsDOMCSSDeclaration;
00058 class nsIDOMCSSStyleDeclaration;
00059 class nsIURI;
00060 class nsIFormControlFrame;
00061 class nsIForm;
00062 class nsPresState;
00063 class nsIScrollableView;
00064 class nsILayoutHistoryState;
00065 class nsIEditor;
00066 struct nsRect;
00067 struct nsSize;
00068 struct nsRuleData;
00069 
00070 typedef void (*nsMapRuleToAttributesFunc)(const nsMappedAttributes* aAttributes, 
00071                                           nsRuleData* aData);
00072 
00073 
00077 class nsGenericHTMLElement : public nsGenericElement
00078 {
00079 public:
00080   nsGenericHTMLElement(nsINodeInfo *aNodeInfo)
00081     : nsGenericElement(aNodeInfo)
00082   {
00083   }
00084 
00086   static nsGenericHTMLElement* FromContent(nsIContent *aContent)
00087   {
00088     if (aContent->IsContentOfType(eHTML))
00089       return NS_STATIC_CAST(nsGenericHTMLElement*, aContent);
00090     return nsnull;
00091   }
00092 
00094   static void Shutdown();
00095 
00104   nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement, REFNSIID aIID,
00105                              void **aInstancePtr);
00106 
00107   // From nsGenericElement
00108   nsresult CopyInnerTo(nsGenericElement* aDest, PRBool aDeep);
00109 
00110   // Implementation for nsIDOMNode
00111   NS_METHOD GetNodeName(nsAString& aNodeName);
00112   NS_METHOD GetLocalName(nsAString& aLocalName);
00113 
00114   // Implementation for nsIDOMElement
00115   NS_METHOD SetAttribute(const nsAString& aName,
00116                          const nsAString& aValue);
00117   NS_METHOD GetTagName(nsAString& aTagName);
00118   NS_METHOD GetElementsByTagName(const nsAString& aTagname,
00119                                  nsIDOMNodeList** aReturn);
00120   NS_METHOD GetElementsByTagNameNS(const nsAString& aNamespaceURI,
00121                                    const nsAString& aLocalName,
00122                                    nsIDOMNodeList** aReturn);
00123 
00124   // nsIDOMHTMLElement methods. Note that these are non-virtual
00125   // methods, implementations are expected to forward calls to these
00126   // methods.
00127   nsresult GetId(nsAString& aId);
00128   nsresult SetId(const nsAString& aId);
00129   nsresult GetTitle(nsAString& aTitle);
00130   nsresult SetTitle(const nsAString& aTitle);
00131   nsresult GetLang(nsAString& aLang);
00132   nsresult SetLang(const nsAString& aLang);
00133   nsresult GetDir(nsAString& aDir);
00134   nsresult SetDir(const nsAString& aDir);
00135   nsresult GetClassName(nsAString& aClassName);
00136   nsresult SetClassName(const nsAString& aClassName);
00137 
00138   // nsIDOMNSHTMLElement methods. Note that these are non-virtual
00139   // methods, implementations are expected to forward calls to these
00140   // methods.
00141   nsresult GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
00142   nsresult GetOffsetTop(PRInt32* aOffsetTop);
00143   nsresult GetOffsetLeft(PRInt32* aOffsetLeft);
00144   nsresult GetOffsetWidth(PRInt32* aOffsetWidth);
00145   nsresult GetOffsetHeight(PRInt32* aOffsetHeight);
00146   nsresult GetOffsetParent(nsIDOMElement** aOffsetParent);
00147   virtual nsresult GetInnerHTML(nsAString& aInnerHTML);
00148   virtual nsresult SetInnerHTML(const nsAString& aInnerHTML);
00149   nsresult GetScrollTop(PRInt32* aScrollTop);
00150   nsresult SetScrollTop(PRInt32 aScrollTop);
00151   nsresult GetScrollLeft(PRInt32* aScrollLeft);
00152   nsresult SetScrollLeft(PRInt32 aScrollLeft);
00153   nsresult GetScrollHeight(PRInt32* aScrollHeight);
00154   nsresult GetScrollWidth(PRInt32* aScrollWidth);
00155   nsresult GetClientHeight(PRInt32* aClientHeight);
00156   nsresult GetClientWidth(PRInt32* aClientWidth);
00157   nsresult ScrollIntoView(PRBool aTop);
00158   // Declare Focus(), Blur(), GetTabIndex(), SetTabIndex(), GetSpellcheck() and
00159   // SetSpellcheck() such that classes that inherit interfaces with those 
00160   // methods properly override them
00161   NS_IMETHOD Focus();
00162   NS_IMETHOD Blur();
00163   NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
00164   NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
00165   NS_IMETHOD GetSpellcheck(PRBool* aSpellcheck);
00166   NS_IMETHOD SetSpellcheck(PRBool aSpellcheck);
00167 
00174   void GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent);
00175   void GetScrollInfo(nsIScrollableView **aScrollableView, float *aP2T,
00176                      float *aT2P, nsIFrame **aFrame = nsnull);
00177 
00184   static const nsSize GetClientAreaSize(nsIFrame *aFrame);
00185 
00186   // Implementation for nsIContent
00187   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
00188                               nsIContent* aBindingParent,
00189                               PRBool aCompileEventHandlers);
00190   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00191                    const nsAString& aValue, PRBool aNotify)
00192   {
00193     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
00194   }
00195   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix,
00196                            const nsAString& aValue,
00197                            PRBool aNotify);
00198   virtual nsresult GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00199                            nsAString& aResult) const;
00200   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00201                              PRBool aNotify);
00202 #ifdef DEBUG
00203   virtual void List(FILE* out, PRInt32 aIndent) const;
00204   virtual void DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const;
00205 #endif
00206   virtual PRBool IsContentOfType(PRUint32 aFlags) const;
00207   virtual void RemoveFocus(nsPresContext *aPresContext);
00208   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull);
00209 
00215   static nsresult DispatchClickEvent(nsPresContext* aPresContext,
00216                                      nsInputEvent* aSourceEvent,
00217                                      nsIContent* aTarget,
00218                                      PRBool aFullDispatch,
00219                                      nsEventStatus* aStatus);
00220   
00224   static nsresult DispatchEvent(nsPresContext* aPresContext,
00225                                 nsEvent* aEvent,
00226                                 nsIContent* aTarget,
00227                                 PRBool aFullDispatch,
00228                                 nsEventStatus* aStatus);
00229 
00234   nsresult HandleDOMEventForAnchors(nsPresContext* aPresContext,
00235                                     nsEvent* aEvent,
00236                                     nsIDOMEvent** aDOMEvent,
00237                                     PRUint32 aFlags,
00238                                     nsEventStatus* aEventStatus);
00239 
00240   // Used by A, AREA, LINK, and STYLE.
00241   // Callers must hold a reference to nsHTMLUtils's global reference count.
00242   nsresult GetHrefURIForAnchors(nsIURI** aURI);
00243 
00244   // HTML element methods
00245   void Compact() { mAttrsAndChildren.Compact(); }
00246   const nsAttrValue* GetParsedAttr(nsIAtom* aAttr) const
00247   {
00248     return mAttrsAndChildren.GetAttr(aAttr);
00249   }
00250   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
00251 
00252   // Implementation for nsIStyledContent
00253   virtual const nsAttrValue* GetClasses() const;
00254   virtual nsIAtom *GetIDAttributeName() const;
00255   virtual nsIAtom *GetClassAttributeName() const;
00256   NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
00257   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
00258   virtual nsICSSStyleRule* GetInlineStyleRule();
00259   NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
00260   already_AddRefed<nsIURI> GetBaseURI() const;
00261 
00262   //----------------------------------------
00273   virtual PRBool ParseAttribute(nsIAtom* aAttribute,
00274                                 const nsAString& aValue,
00275                                 nsAttrValue& aResult);
00276 
00277   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00278 
00287   void GetBaseTarget(nsAString& aBaseTarget) const;
00288 
00289 #ifdef DEBUG
00290   void ListAttributes(FILE* out) const;
00291 #endif
00292 
00300   nsIFormControlFrame* GetFormControlFrame(PRBool aFlushContent)
00301   {
00302     nsIDocument* doc = GetCurrentDoc();
00303     if (!doc) {
00304       return nsnull;
00305     }
00306 
00307     return GetFormControlFrameFor(this, doc, aFlushContent);
00308   }
00309 
00316   nsIFrame* GetPrimaryFrame(PRBool aFlushContent)
00317   {
00318     nsIDocument* doc = GetCurrentDoc();
00319     if (!doc) {
00320       return nsnull;
00321     }
00322 
00323     return GetPrimaryFrameFor(this, doc, aFlushContent);
00324   }
00325 
00326   //----------------------------------------
00327 
00335   static PRBool ParseAlignValue(const nsAString& aString,
00336                                 nsAttrValue& aResult);
00337 
00345   PRBool ParseDivAlignValue(const nsAString& aString,
00346                             nsAttrValue& aResult) const;
00347 
00355   PRBool ParseTableHAlignValue(const nsAString& aString,
00356                                nsAttrValue& aResult) const;
00357 
00365   PRBool ParseTableCellHAlignValue(const nsAString& aString,
00366                                    nsAttrValue& aResult) const;
00367 
00376   static PRBool ParseTableVAlignValue(const nsAString& aString,
00377                                       nsAttrValue& aResult);
00378 
00387   static PRBool ParseImageAttribute(nsIAtom* aAttribute,
00388                                     const nsAString& aString,
00389                                     nsAttrValue& aResult);
00397   static PRBool ParseFrameborderValue(const nsAString& aString,
00398                                       nsAttrValue& aResult);
00399 
00407   static PRBool ParseScrollingValue(const nsAString& aString,
00408                                     nsAttrValue& aResult);
00409 
00414   nsresult  ReparseStyleAttribute(void);
00423   static void ParseStyleAttribute(nsIContent* aContent,
00424                                   PRBool aCaseSensitive,
00425                                   const nsAString& aValue,
00426                                   nsAttrValue& aResult);
00427 
00428   /*
00429    * Attribute Mapping Helpers
00430    */
00431 
00441   static void MapCommonAttributesInto(const nsMappedAttributes* aAttributes, 
00442                                       nsRuleData* aRuleData);
00443   static const MappedAttributeEntry sCommonAttributeMap[];
00444   static const MappedAttributeEntry sImageMarginSizeAttributeMap[];
00445   static const MappedAttributeEntry sImageBorderAttributeMap[];
00446   static const MappedAttributeEntry sImageAlignAttributeMap[];
00447   static const MappedAttributeEntry sDivAlignAttributeMap[];
00448   static const MappedAttributeEntry sBackgroundAttributeMap[];
00449   static const MappedAttributeEntry sScrollingAttributeMap[];
00450   
00458   static void MapImageAlignAttributeInto(const nsMappedAttributes* aAttributes,
00459                                          nsRuleData* aData);
00460 
00469   static void MapDivAlignAttributeInto(const nsMappedAttributes* aAttributes,
00470                                        nsRuleData* aData);
00471 
00479   static void MapImageBorderAttributeInto(const nsMappedAttributes* aAttributes,
00480                                           nsRuleData* aData);
00488   static void MapImageMarginAttributeInto(const nsMappedAttributes* aAttributes,
00489                                           nsRuleData* aData);
00497   static void MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes,
00498                                          nsRuleData* aData);
00507   static void MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes,
00508                                           nsRuleData* aData);
00517   static void MapScrollingAttributeInto(const nsMappedAttributes* aAttributes,
00518                                         nsRuleData* aData);
00528   static nsIFrame* GetPrimaryFrameFor(nsIContent* aContent,
00529                                       nsIDocument* aDocument,
00530                                       PRBool aFlushContent);
00531 
00542   static nsIFormControlFrame* GetFormControlFrameFor(nsIContent* aContent,
00543                                                      nsIDocument* aDocument,
00544                                                      PRBool aFlushContent);
00552   static nsresult GetPrimaryPresState(nsGenericHTMLElement* aContent,
00553                                       nsPresState** aPresState);
00562   static nsresult GetLayoutHistoryAndKey(nsGenericHTMLElement* aContent,
00563                                          nsILayoutHistoryState** aState,
00564                                          nsACString& aKey);
00574   static PRBool RestoreFormControlState(nsGenericHTMLElement* aContent,
00575                                         nsIFormControl* aControl);
00576 
00581   NS_HIDDEN_(nsPresContext*) GetPresContext();
00582 
00583   // Form Helper Routines
00592   already_AddRefed<nsIDOMHTMLFormElement> FindForm(nsIForm* aCurrentForm = nsnull);
00593 
00598   static PRBool InNavQuirksMode(nsIDocument* aDoc);
00599 
00615   nsresult SetAttrAndNotify(PRInt32 aNamespaceID,
00616                             nsIAtom* aAttribute,
00617                             nsIAtom* aPrefix,
00618                             const nsAString& aOldValue,
00619                             nsAttrValue& aParsedValue,
00620                             PRBool aModification,
00621                             PRBool aFireMutation,
00622                             PRBool aNotify);
00623  
00624   // Helper functions for <a> and <area>
00625   static nsresult SetProtocolInHrefString(const nsAString &aHref,
00626                                           const nsAString &aProtocol,
00627                                           nsAString &aResult);
00628 
00629   static nsresult SetHostInHrefString(const nsAString &aHref,
00630                                       const nsAString &aHost,
00631                                       nsAString &aResult);
00632 
00633   static nsresult SetHostnameInHrefString(const nsAString &aHref,
00634                                           const nsAString &aHostname,
00635                                           nsAString &aResult);
00636 
00637   static nsresult SetPathnameInHrefString(const nsAString &aHref,
00638                                           const nsAString &aHostname,
00639                                           nsAString &aResult);
00640 
00641   static nsresult SetSearchInHrefString(const nsAString &aHref,
00642                                         const nsAString &aSearch,
00643                                         nsAString &aResult);
00644   
00645   static nsresult SetHashInHrefString(const nsAString &aHref,
00646                                       const nsAString &aHash,
00647                                       nsAString &aResult);
00648 
00649   static nsresult SetPortInHrefString(const nsAString &aHref,
00650                                       const nsAString &aPort,
00651                                       nsAString &aResult);
00652 
00653   static nsresult GetProtocolFromHrefString(const nsAString &aHref,
00654                                             nsAString& aProtocol,
00655                                             nsIDocument *aDocument);
00656 
00657   static nsresult GetHostFromHrefString(const nsAString &aHref,
00658                                         nsAString& aHost);
00659 
00660   static nsresult GetHostnameFromHrefString(const nsAString &aHref,
00661                                             nsAString& aHostname);
00662 
00663   static nsresult GetPathnameFromHrefString(const nsAString &aHref,
00664                                             nsAString& aPathname);
00665 
00666   static nsresult GetSearchFromHrefString(const nsAString &aHref,
00667                                           nsAString& aSearch);
00668 
00669   static nsresult GetPortFromHrefString(const nsAString &aHref,
00670                                         nsAString& aPort);
00671 
00672   static nsresult GetHashFromHrefString(const nsAString &aHref,
00673                                         nsAString& aHash);
00674 protected:
00681   void SetElementFocus(PRBool aDoFocus);
00687   void RegUnRegAccessKey(PRBool aDoReg);
00688 
00694   PRBool IsEventName(nsIAtom* aName);
00695 
00696   virtual const nsAttrName* InternalGetExistingAttrNameFromQName(const nsAString& aStr) const;
00697 
00706   nsresult ReplaceContentsWithText(const nsAString& aText, PRBool aNotify);
00707 
00718   NS_HIDDEN_(nsresult) GetAttrHelper(nsIAtom* aAttr, nsAString& aValue);
00719 
00729   NS_HIDDEN_(nsresult) SetAttrHelper(nsIAtom* aAttr, const nsAString& aValue);
00730 
00740   NS_HIDDEN_(nsresult) GetStringAttrWithDefault(nsIAtom* aAttr,
00741                                                 const char* aDefault,
00742                                                 nsAString& aResult);
00743 
00752   NS_HIDDEN_(nsresult) GetBoolAttr(nsIAtom* aAttr, PRBool* aValue) const;
00753 
00762   NS_HIDDEN_(nsresult) SetBoolAttr(nsIAtom* aAttr, PRBool aValue);
00763 
00774   NS_HIDDEN_(nsresult) GetIntAttr(nsIAtom* aAttr, PRInt32 aDefault, PRInt32* aValue);
00775 
00784   NS_HIDDEN_(nsresult) SetIntAttr(nsIAtom* aAttr, PRInt32 aValue);
00785 
00796   NS_HIDDEN_(nsresult) GetURIAttr(nsIAtom* aAttr, nsAString& aResult);
00797 
00802   void RecreateFrames();
00803 
00807   NS_HIDDEN_(nsresult) GetEditor(nsIEditor** aEditor);
00808   NS_HIDDEN_(nsresult) GetEditorInternal(nsIEditor** aEditor);
00809 
00818   virtual already_AddRefed<nsIEditor> GetAssociatedEditor();
00819 
00823   PRBool IsCurrentBodyElement();
00824 
00829   static void SyncEditorsOnSubtree(nsIContent* content);
00830 };
00831 
00832 
00833 //----------------------------------------------------------------------
00834 
00838 class nsGenericHTMLFormElement : public nsGenericHTMLElement,
00839                                  public nsIFormControl
00840 {
00841 public:
00842   nsGenericHTMLFormElement(nsINodeInfo *aNodeInfo);
00843   virtual ~nsGenericHTMLFormElement();
00844 
00845   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00846 
00847   virtual PRBool IsContentOfType(PRUint32 aFlags) const;
00848 
00849   // nsIFormControl
00850   NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm);
00851   NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm,
00852                      PRBool aRemoveFromForm = PR_TRUE);
00853   NS_IMETHOD SaveState()
00854   {
00855     return NS_OK;
00856   }
00857   virtual PRBool RestoreState(nsPresState* aState)
00858   {
00859     return PR_FALSE;
00860   }
00861   virtual PRBool AllowDrop()
00862   {
00863     return PR_TRUE;
00864   }
00865 
00866   // nsIContent
00867   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
00868                               nsIContent* aBindingParent,
00869                               PRBool aCompileEventHandlers);
00870   virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
00871                               PRBool aNullParent = PR_TRUE);
00872   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00873                    const nsAString& aValue, PRBool aNotify)
00874   {
00875     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
00876   }
00877   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00878                            nsIAtom* aPrefix, const nsAString& aValue,
00879                            PRBool aNotify);
00880 
00881   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00882                              PRBool aNotify);
00883 
00884 protected:
00891   void FindAndSetForm();
00892 
00903   virtual void AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00904                             const nsAString* aValue, PRBool aNotify);
00905 
00909   PRBool CanBeDisabled() const;
00910 
00911   virtual PRInt32 IntrinsicState() const;
00912 
00914   nsIForm* mForm;
00915 };
00916 
00917 //----------------------------------------------------------------------
00918 
00923 class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
00924                                   public nsIDOMNSHTMLFrameElement,
00925                                   public nsIFrameLoaderOwner,
00926                                   public nsIChromeEventHandler
00927 {
00928 public:
00929   nsGenericHTMLFrameElement(nsINodeInfo *aNodeInfo)
00930     : nsGenericHTMLElement(aNodeInfo)
00931   {
00932   }
00933   virtual ~nsGenericHTMLFrameElement();
00934 
00935   // nsISupports
00936   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00937 
00938   // nsIDOMNSHTMLFrameElement
00939   NS_DECL_NSIDOMNSHTMLFRAMEELEMENT
00940 
00941   // nsIChromeEventHandler
00942   NS_DECL_NSICHROMEEVENTHANDLER
00943 
00944   // nsIFrameLoaderOwner
00945   NS_DECL_NSIFRAMELOADEROWNER
00946 
00947   // nsIContent
00948   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull);
00949   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
00950                               nsIContent* aBindingParent,
00951                               PRBool aCompileEventHandlers);
00952   virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
00953                               PRBool aNullParent = PR_TRUE);
00954   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00955                    const nsAString& aValue, PRBool aNotify)
00956   {
00957     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
00958   }
00959   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00960                            nsIAtom* aPrefix, const nsAString& aValue,
00961                            PRBool aNotify);
00962 
00963   // nsIDOMNSHTMLElement 
00964   NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
00965   NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
00966 
00967 protected:
00968   // This doesn't really ensure a frame loade in all cases, only when
00969   // it makes sense.
00970   nsresult EnsureFrameLoader();
00971   nsresult LoadSrc();
00972   nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
00973 
00974   nsCOMPtr<nsIFrameLoader> mFrameLoader;
00975 };
00976 
00977 //----------------------------------------------------------------------
00978 
00982 #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName)                            \
00983 nsGenericHTMLElement*                                                        \
00984 NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
00985 {                                                                            \
00986   return new nsHTML##_elementName##Element(aNodeInfo);                       \
00987 }
00988 
00989 #define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName)               \
00990 nsGenericHTMLElement*                                                        \
00991 NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
00992 {                                                                            \
00993   return new nsHTML##_elementName##Element(aNodeInfo, aFromParser);          \
00994 }
00995 
00996 
01002 #define NS_IMPL_STRING_ATTR(_class, _method, _atom)                  \
01003   NS_IMETHODIMP                                                      \
01004   _class::Get##_method(nsAString& aValue)                            \
01005   {                                                                  \
01006     return GetAttrHelper(nsHTMLAtoms::_atom, aValue);                \
01007   }                                                                  \
01008   NS_IMETHODIMP                                                      \
01009   _class::Set##_method(const nsAString& aValue)                      \
01010   {                                                                  \
01011     return SetAttrHelper(nsHTMLAtoms::_atom, aValue);                \
01012   }
01013 
01019 #define NS_IMPL_STRING_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
01020   NS_IMETHODIMP                                                      \
01021   _class::Get##_method(nsAString& aValue)                            \
01022   {                                                                  \
01023     return GetStringAttrWithDefault(nsHTMLAtoms::_atom, _default, aValue);\
01024   }                                                                  \
01025   NS_IMETHODIMP                                                      \
01026   _class::Set##_method(const nsAString& aValue)                      \
01027   {                                                                  \
01028     return SetAttrHelper(nsHTMLAtoms::_atom, aValue);                \
01029   }
01030 
01036 #define NS_IMPL_BOOL_ATTR(_class, _method, _atom)                     \
01037   NS_IMETHODIMP                                                       \
01038   _class::Get##_method(PRBool* aValue)                                \
01039   {                                                                   \
01040     return GetBoolAttr(nsHTMLAtoms::_atom, aValue);                   \
01041   }                                                                   \
01042   NS_IMETHODIMP                                                       \
01043   _class::Set##_method(PRBool aValue)                                 \
01044   {                                                                   \
01045     return SetBoolAttr(nsHTMLAtoms::_atom, aValue);                   \
01046   }
01047 
01053 #define NS_IMPL_INT_ATTR(_class, _method, _atom)                    \
01054   NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, -1)
01055 
01056 #define NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default)  \
01057   NS_IMETHODIMP                                                           \
01058   _class::Get##_method(PRInt32* aValue)                                   \
01059   {                                                                       \
01060     return GetIntAttr(nsHTMLAtoms::_atom, _default, aValue);              \
01061   }                                                                       \
01062   NS_IMETHODIMP                                                           \
01063   _class::Set##_method(PRInt32 aValue)                                    \
01064   {                                                                       \
01065     return SetIntAttr(nsHTMLAtoms::_atom, aValue);                        \
01066   }
01067 
01075 #define NS_IMPL_URI_ATTR(_class, _method, _atom)                    \
01076   NS_IMETHODIMP                                                     \
01077   _class::Get##_method(nsAString& aValue)                           \
01078   {                                                                 \
01079     return GetURIAttr(nsHTMLAtoms::_atom, aValue);                  \
01080   }                                                                 \
01081   NS_IMETHODIMP                                                     \
01082   _class::Set##_method(const nsAString& aValue)                     \
01083   {                                                                 \
01084     return SetAttrHelper(nsHTMLAtoms::_atom, aValue);               \
01085   }
01086 
01091 #define NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(_class, _base, _base_if) \
01092   NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr)    \
01093   {                                                                           \
01094     NS_ENSURE_ARG_POINTER(aInstancePtr);                                      \
01095                                                                               \
01096     *aInstancePtr = nsnull;                                                   \
01097                                                                               \
01098     nsresult rv;                                                              \
01099                                                                               \
01100     rv = _base::QueryInterface(aIID, aInstancePtr);                           \
01101                                                                               \
01102     if (NS_SUCCEEDED(rv))                                                     \
01103       return rv;                                                              \
01104                                                                               \
01105     rv = DOMQueryInterface(NS_STATIC_CAST(_base_if *, this), aIID,            \
01106                            aInstancePtr);                                     \
01107                                                                               \
01108     if (NS_SUCCEEDED(rv))                                                     \
01109       return rv;                                                              \
01110                                                                               \
01111     nsISupports *foundInterface = nsnull;
01112 
01113 
01114 #define NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(_class, _base)                    \
01115   NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(_class, _base,                 \
01116                                                nsIDOMHTMLElement)
01117 
01118 
01119 #define NS_HTML_CONTENT_INTERFACE_MAP_END                                     \
01120     {                                                                         \
01121       return PostQueryInterface(aIID, aInstancePtr);                          \
01122     }                                                                         \
01123                                                                               \
01124     NS_ADDREF(foundInterface);                                                \
01125                                                                               \
01126     *aInstancePtr = foundInterface;                                           \
01127                                                                               \
01128     return NS_OK;                                                             \
01129   }
01130 
01131 
01132 #define NS_INTERFACE_MAP_ENTRY_IF_TAG(_interface, _tag)                       \
01133   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface,                              \
01134                                      mNodeInfo->Equals(nsHTMLAtoms::_tag))
01135 
01136 
01137 #define NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(_class, _tag)         \
01138   if (mNodeInfo->Equals(nsHTMLAtoms::_tag) &&                                 \
01139       aIID.Equals(NS_GET_IID(nsIClassInfo))) {                                \
01140     foundInterface =                                                          \
01141       nsContentUtils::GetClassInfoInstance(eDOMClassInfo_##_class##_id);      \
01142     if (!foundInterface) {                                                    \
01143       *aInstancePtr = nsnull;                                                 \
01144       return NS_ERROR_OUT_OF_MEMORY;                                          \
01145     }                                                                         \
01146   } else
01147 
01148 
01149 
01150 // Element class factory methods
01151 
01152 #define NS_DECLARE_NS_NEW_HTML_ELEMENT(_elementName)              \
01153 nsGenericHTMLElement*                                             \
01154 NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo,         \
01155                                   PRBool aFromParser = PR_FALSE);
01156 
01157 NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared)
01158 NS_DECLARE_NS_NEW_HTML_ELEMENT(Anchor)
01159 NS_DECLARE_NS_NEW_HTML_ELEMENT(Applet)
01160 NS_DECLARE_NS_NEW_HTML_ELEMENT(Area)
01161 NS_DECLARE_NS_NEW_HTML_ELEMENT(BR)
01162 NS_DECLARE_NS_NEW_HTML_ELEMENT(Body)
01163 NS_DECLARE_NS_NEW_HTML_ELEMENT(Button)
01164 NS_DECLARE_NS_NEW_HTML_ELEMENT(Canvas)
01165 NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod)
01166 NS_DECLARE_NS_NEW_HTML_ELEMENT(Div)
01167 NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet)
01168 NS_DECLARE_NS_NEW_HTML_ELEMENT(Font)
01169 NS_DECLARE_NS_NEW_HTML_ELEMENT(Form)
01170 NS_DECLARE_NS_NEW_HTML_ELEMENT(Frame)
01171 NS_DECLARE_NS_NEW_HTML_ELEMENT(FrameSet)
01172 NS_DECLARE_NS_NEW_HTML_ELEMENT(HR)
01173 NS_DECLARE_NS_NEW_HTML_ELEMENT(Head)
01174 NS_DECLARE_NS_NEW_HTML_ELEMENT(Heading)
01175 NS_DECLARE_NS_NEW_HTML_ELEMENT(Html)
01176 NS_DECLARE_NS_NEW_HTML_ELEMENT(IFrame)
01177 NS_DECLARE_NS_NEW_HTML_ELEMENT(Image)
01178 NS_DECLARE_NS_NEW_HTML_ELEMENT(Input)
01179 NS_DECLARE_NS_NEW_HTML_ELEMENT(LI)
01180 NS_DECLARE_NS_NEW_HTML_ELEMENT(Label)
01181 NS_DECLARE_NS_NEW_HTML_ELEMENT(Legend)
01182 NS_DECLARE_NS_NEW_HTML_ELEMENT(Link)
01183 NS_DECLARE_NS_NEW_HTML_ELEMENT(Map)
01184 NS_DECLARE_NS_NEW_HTML_ELEMENT(Meta)
01185 NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList)
01186 NS_DECLARE_NS_NEW_HTML_ELEMENT(Object)
01187 NS_DECLARE_NS_NEW_HTML_ELEMENT(OptGroup)
01188 NS_DECLARE_NS_NEW_HTML_ELEMENT(Option)
01189 NS_DECLARE_NS_NEW_HTML_ELEMENT(Paragraph)
01190 NS_DECLARE_NS_NEW_HTML_ELEMENT(Pre)
01191 NS_DECLARE_NS_NEW_HTML_ELEMENT(Script)
01192 NS_DECLARE_NS_NEW_HTML_ELEMENT(Select)
01193 NS_DECLARE_NS_NEW_HTML_ELEMENT(Span)
01194 NS_DECLARE_NS_NEW_HTML_ELEMENT(Style)
01195 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCaption)
01196 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCell)
01197 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCol)
01198 NS_DECLARE_NS_NEW_HTML_ELEMENT(Table)
01199 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableRow)
01200 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableSection)
01201 NS_DECLARE_NS_NEW_HTML_ELEMENT(Tbody)
01202 NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea)
01203 NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot)
01204 NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead)
01205 NS_DECLARE_NS_NEW_HTML_ELEMENT(Title)
01206 NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown)
01207 
01208 #endif /* nsGenericHTMLElement_h___ */