Back to index

lightning-sunbird  0.9+nobinonly
nsIContent.h
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 #ifndef nsIContent_h___
00038 #define nsIContent_h___
00039 
00040 #include <stdio.h>
00041 #include "nsCOMPtr.h"
00042 #include "nsISupports.h"
00043 #include "nsEvent.h"
00044 #include "nsAString.h"
00045 #include "nsContentErrors.h"
00046 #include "nsPropertyTable.h"
00047 #include "nsIDOMGCParticipant.h"
00048 
00049 // Forward declarations
00050 class nsIAtom;
00051 class nsIDocument;
00052 class nsPresContext;
00053 class nsVoidArray;
00054 class nsIDOMEvent;
00055 class nsIContent;
00056 class nsISupportsArray;
00057 class nsIDOMRange;
00058 class nsINodeInfo;
00059 class nsIEventListenerManager;
00060 class nsIURI;
00061 
00062 // IID for the nsIContent interface
00063 // 9d059608-ddb0-4e6a-9969-d2f363a1b557
00064 #define NS_ICONTENT_IID \
00065 { 0x9d059608, 0xddb0, 0x4e6a, \
00066   { 0x99, 0x69, 0xd2, 0xf3, 0x63, 0xa1, 0xb5, 0x57 } }
00067 
00072 class nsIContent : public nsIDOMGCParticipant {
00073 public:
00074   NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
00075 
00076   nsIContent()
00077     : mParentPtrBits(0) { }
00078 
00084   virtual nsIDocument* GetDocument() const = 0;
00085 
00111   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
00112                               nsIContent* aBindingParent,
00113                               PRBool aCompileEventHandlers) = 0;
00114 
00129   virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
00130                               PRBool aNullParent = PR_TRUE) = 0;
00131   
00137   virtual PRBool IsInDoc() const = 0;
00138 
00145   nsIDocument *GetCurrentDoc() const
00146   {
00147     // XXX This should become:
00148     // return IsInDoc() ? GetOwnerDoc() : nsnull;
00149     return GetDocument();
00150   }
00151 
00157   virtual nsIDocument *GetOwnerDoc() const = 0;
00158 
00163   nsIContent* GetParent() const
00164   {
00165     return NS_REINTERPRET_CAST(nsIContent *, mParentPtrBits & ~kParentBitMask);
00166   }
00167 
00173   virtual PRBool IsNativeAnonymous() const = 0;
00174 
00180   virtual void SetNativeAnonymous(PRBool aAnonymous) = 0;
00181 
00186   virtual PRInt32 GetNameSpaceID() const = 0;
00187 
00192   virtual nsIAtom *Tag() const = 0;
00193 
00198   virtual nsINodeInfo * GetNodeInfo() const = 0;
00199 
00204   virtual PRUint32 GetChildCount() const = 0;
00205 
00212   virtual nsIContent *GetChildAt(PRUint32 aIndex) const = 0;
00213 
00219   virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const = 0;
00220 
00230   virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
00231                                  PRBool aNotify) = 0;
00232 
00240   virtual nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify) = 0;
00241 
00249   virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify) = 0;
00250 
00256   virtual nsIAtom *GetIDAttributeName() const = 0;
00257 
00268   virtual already_AddRefed<nsINodeInfo> GetExistingAttrNameFromQName(const nsAString& aStr) const = 0;
00269 
00284   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00285                    const nsAString& aValue, PRBool aNotify)
00286   {
00287     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
00288   }
00289 
00305   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00306                            nsIAtom* aPrefix, const nsAString& aValue,
00307                            PRBool aNotify) = 0;
00308 
00322   virtual nsresult GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, 
00323                            nsAString& aResult) const = 0;
00324 
00332   virtual PRBool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const = 0;
00333 
00343   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr, 
00344                              PRBool aNotify) = 0;
00345 
00346 
00356   virtual nsresult GetAttrNameAt(PRUint32 aIndex, PRInt32* aNameSpaceID,
00357                                  nsIAtom** aName, nsIAtom** aPrefix) const = 0;
00358 
00364   virtual PRUint32 GetAttrCount() const = 0;
00365 
00378   virtual nsresult RangeAdd(nsIDOMRange* aRange) = 0;
00379 
00384   virtual void RangeRemove(nsIDOMRange* aRange) = 0;
00385 
00393   virtual const nsVoidArray *GetRangeList() const = 0;
00394 
00427   virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
00428                                   nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
00429                                   PRUint32 aFlags,
00430                                   nsEventStatus* aEventStatus) = 0;
00431 
00444   virtual PRUint32 ContentID() const = 0;
00449   virtual void SetContentID(PRUint32 aID)
00450   {
00451   }
00452 
00464   virtual void SetFocus(nsPresContext* aPresContext)
00465   {
00466   }
00467 
00479   virtual void RemoveFocus(nsPresContext* aPresContext)
00480   {
00481   }
00482 
00505   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull)
00506   {
00507     if (aTabIndex) 
00508       *aTabIndex = -1; // Default, not tabbable
00509     return PR_FALSE;
00510   }
00511 
00519   virtual nsIContent *GetBindingParent() const = 0;
00520 
00524   enum {
00526     eTEXT                = 0x00000001,
00528     eELEMENT             = 0x00000002,
00530     eHTML                = 0x00000004,
00532     eHTML_FORM_CONTROL   = 0x00000008,
00534     eXUL                 = 0x00000010,
00536     ePROCESSING_INSTRUCTION = 0x00000020,
00538     eSVG                 = 0x00000040,
00540     eCOMMENT             = 0x00000080
00541   };
00542 
00552   virtual PRBool IsContentOfType(PRUint32 aFlags) const = 0;
00553 
00559   virtual nsresult GetListenerManager(nsIEventListenerManager** aResult) = 0;
00560 
00569   virtual already_AddRefed<nsIURI> GetBaseURI() const = 0;
00570 
00598   virtual void DoneCreatingElement()
00599   {
00600   }
00601 
00607   virtual void SetMayHaveFrame(PRBool aMayHaveFrame)
00608   {
00609   }
00610 
00615   virtual PRBool MayHaveFrame() const
00616   {
00617     return PR_TRUE;
00618   }
00619     
00626   virtual void BeginAddingChildren()
00627   {
00628   }
00629 
00645   virtual void DoneAddingChildren()
00646   {
00647   }
00648 
00654   virtual PRBool IsDoneAddingChildren()
00655   {
00656     return PR_TRUE;
00657   }
00658 
00665   // XXXbz this is PRInt32 because all the ESM content state APIs use
00666   // PRInt32.  We should really use PRUint32 instead.
00667   virtual PRInt32 IntrinsicState() const
00668   {
00669     return 0;
00670   }
00671     
00672 
00673   /* Methods for manipulating content node properties.  For documentation on
00674    * properties, see nsPropertyTable.h.
00675    */
00676 
00677   virtual void* GetProperty(nsIAtom  *aPropertyName,
00678                             nsresult *aStatus = nsnull) const
00679   { if (aStatus) *aStatus = NS_ERROR_NOT_IMPLEMENTED; return nsnull; }
00680 
00681   virtual nsresult SetProperty(nsIAtom                   *aPropertyName,
00682                                void                      *aValue,
00683                                NSPropertyDtorFunc         aDtor = nsnull)
00684   { return NS_ERROR_NOT_IMPLEMENTED; }
00685 
00686   virtual nsresult DeleteProperty(nsIAtom *aPropertyName)
00687   { return NS_ERROR_NOT_IMPLEMENTED; }
00688 
00689   virtual void* UnsetProperty(nsIAtom  *aPropertyName,
00690                               nsresult *aStatus = nsnull)
00691   { if (aStatus) *aStatus = NS_ERROR_NOT_IMPLEMENTED; return nsnull; }
00692 
00693 
00694 #ifdef DEBUG
00695 
00700   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
00701 
00707   virtual void DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,
00708                            PRBool aDumpAll = PR_TRUE) const = 0;
00709 #endif
00710 
00711   enum ETabFocusType {
00712   //eTabFocus_textControlsMask = (1<<0),  // unused - textboxes always tabbable
00713     eTabFocus_formElementsMask = (1<<1),  // non-text form elements
00714     eTabFocus_linksMask = (1<<2),         // links
00715     eTabFocus_any = 1 + (1<<1) + (1<<2)   // everything that can be focused
00716   };
00717 
00718   // Tab focus model bit field:
00719   static PRInt32 sTabFocusModel;
00720 
00721   // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
00722   // the tabfocus bit field applies to xul elements.
00723   static PRBool sTabFocusModelAppliesToXUL;
00724 
00725 protected:
00726   typedef PRWord PtrBits;
00727 
00728   // Subclasses may use the low two bits of mParentPtrBits to store other data
00729   enum { kParentBitMask = 0x3 };
00730 
00731   PtrBits      mParentPtrBits;
00732 };
00733 
00734 #endif /* nsIContent_h___ */