Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLDivElement.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 "nsIDOMHTMLDivElement.h"
00038 #include "nsIDOMEventReceiver.h"
00039 #include "nsGenericHTMLElement.h"
00040 #include "nsHTMLAtoms.h"
00041 #include "nsStyleConsts.h"
00042 #include "nsPresContext.h"
00043 #include "nsMappedAttributes.h"
00044 
00045 // XXX support missing nav attributes? gutter, cols, width
00046 
00047 
00048 class nsHTMLDivElement : public nsGenericHTMLElement,
00049                          public nsIDOMHTMLDivElement
00050 {
00051 public:
00052   nsHTMLDivElement(nsINodeInfo *aNodeInfo);
00053   virtual ~nsHTMLDivElement();
00054 
00055   // nsISupports
00056   NS_DECL_ISUPPORTS_INHERITED
00057 
00058   // nsIDOMNode
00059   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
00060 
00061   // nsIDOMElement
00062   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
00063 
00064   // nsIDOMHTMLElement
00065   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
00066 
00067   // nsIDOMHTMLDivElement
00068   NS_DECL_NSIDOMHTMLDIVELEMENT
00069 
00070   virtual PRBool ParseAttribute(nsIAtom* aAttribute,
00071                                 const nsAString& aValue,
00072                                 nsAttrValue& aResult);
00073   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00074   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
00075 };
00076 
00077 
00078 NS_IMPL_NS_NEW_HTML_ELEMENT(Div)
00079 
00080 
00081 nsHTMLDivElement::nsHTMLDivElement(nsINodeInfo *aNodeInfo)
00082   : nsGenericHTMLElement(aNodeInfo)
00083 {
00084 }
00085 
00086 nsHTMLDivElement::~nsHTMLDivElement()
00087 {
00088 }
00089 
00090 
00091 NS_IMPL_ADDREF_INHERITED(nsHTMLDivElement, nsGenericElement) 
00092 NS_IMPL_RELEASE_INHERITED(nsHTMLDivElement, nsGenericElement) 
00093 
00094 
00095 
00096 // QueryInterface implementation for nsHTMLDivElement
00097 NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLDivElement, nsGenericHTMLElement)
00098   NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDivElement)
00099   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDivElement)
00100 NS_HTML_CONTENT_INTERFACE_MAP_END
00101 
00102 
00103 NS_IMPL_DOM_CLONENODE(nsHTMLDivElement)
00104 
00105 
00106 NS_IMPL_STRING_ATTR(nsHTMLDivElement, Align, align)
00107 
00108 
00109 PRBool
00110 nsHTMLDivElement::ParseAttribute(nsIAtom* aAttribute,
00111                                  const nsAString& aValue,
00112                                  nsAttrValue& aResult)
00113 {
00114   if (aAttribute == nsHTMLAtoms::align) {
00115     return ParseDivAlignValue(aValue, aResult);
00116   }
00117   if (aAttribute == nsHTMLAtoms::cols) {
00118     return aResult.ParseIntWithBounds(aValue, 0);
00119   }
00120   if (aAttribute == nsHTMLAtoms::gutter) {
00121     return aResult.ParseIntWithBounds(aValue, 1);
00122   }
00123   if (aAttribute == nsHTMLAtoms::width) {
00124     return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
00125   }
00126 
00127   return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
00128 }
00129 
00130 static void
00131 MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
00132 {
00133   nsGenericHTMLElement::MapDivAlignAttributeInto(aAttributes, aData);
00134   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
00135 }
00136 
00137 NS_IMETHODIMP_(PRBool)
00138 nsHTMLDivElement::IsAttributeMapped(const nsIAtom* aAttribute) const
00139 {
00140   static const MappedAttributeEntry* const map[] = {
00141     sDivAlignAttributeMap,
00142     sCommonAttributeMap
00143   };
00144   
00145   return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
00146 }
00147 
00148 nsMapRuleToAttributesFunc
00149 nsHTMLDivElement::GetAttributeMappingFunction() const
00150 {
00151   return &MapAttributesIntoRule;
00152 }