Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLOListElement.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 "nsIDOMHTMLOListElement.h"
00038 #include "nsIDOMHTMLDListElement.h"
00039 #include "nsIDOMHTMLUListElement.h"
00040 #include "nsIDOMEventReceiver.h"
00041 #include "nsGenericHTMLElement.h"
00042 #include "nsHTMLAtoms.h"
00043 #include "nsStyleConsts.h"
00044 #include "nsPresContext.h"
00045 #include "nsMappedAttributes.h"
00046 #include "nsRuleData.h"
00047 
00048 class nsHTMLSharedListElement : public nsGenericHTMLElement,
00049                                 public nsIDOMHTMLOListElement,
00050                                 public nsIDOMHTMLDListElement,
00051                                 public nsIDOMHTMLUListElement
00052 {
00053 public:
00054   nsHTMLSharedListElement(nsINodeInfo *aNodeInfo);
00055   virtual ~nsHTMLSharedListElement();
00056 
00057   // nsISupports
00058   NS_DECL_ISUPPORTS_INHERITED
00059 
00060   // nsIDOMNode
00061   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
00062 
00063   // nsIDOMElement
00064   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
00065 
00066   // nsIDOMHTMLElement
00067   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
00068 
00069   // nsIDOMHTMLOListElement
00070   NS_DECL_NSIDOMHTMLOLISTELEMENT
00071 
00072   // nsIDOMHTMLDListElement
00073   // fully declared by NS_DECL_NSIDOMHTMLOLISTELEMENT
00074 
00075   // nsIDOMHTMLUListElement
00076   // fully declared by NS_DECL_NSIDOMHTMLOLISTELEMENT
00077 
00078   virtual PRBool ParseAttribute(nsIAtom* aAttribute,
00079                                 const nsAString& aValue,
00080                                 nsAttrValue& aResult);
00081   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
00082   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00083 };
00084 
00085 
00086 NS_IMPL_NS_NEW_HTML_ELEMENT(SharedList)
00087 
00088 
00089 nsHTMLSharedListElement::nsHTMLSharedListElement(nsINodeInfo *aNodeInfo)
00090   : nsGenericHTMLElement(aNodeInfo)
00091 {
00092 }
00093 
00094 nsHTMLSharedListElement::~nsHTMLSharedListElement()
00095 {
00096 }
00097 
00098 
00099 NS_IMPL_ADDREF_INHERITED(nsHTMLSharedListElement, nsGenericElement) 
00100 NS_IMPL_RELEASE_INHERITED(nsHTMLSharedListElement, nsGenericElement) 
00101 
00102 
00103 // QueryInterface implementation for nsHTMLSharedListElement
00104 NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(nsHTMLSharedListElement,
00105                                              nsGenericHTMLElement,
00106                                              nsIDOMHTMLOListElement)
00107   NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLOListElement, ol)
00108   NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLDListElement, dl)
00109   NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLUListElement, ul)
00110 
00111   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLOListElement, ol)
00112   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLDListElement, dl)
00113   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLUListElement, ul)
00114 NS_HTML_CONTENT_INTERFACE_MAP_END
00115 
00116 
00117 NS_IMPL_DOM_CLONENODE_AMBIGUOUS(nsHTMLSharedListElement,
00118                                 nsIDOMHTMLOListElement)
00119 
00120 
00121 NS_IMPL_BOOL_ATTR(nsHTMLSharedListElement, Compact, compact)
00122 NS_IMPL_INT_ATTR(nsHTMLSharedListElement, Start, start)
00123 NS_IMPL_STRING_ATTR(nsHTMLSharedListElement, Type, type)
00124 
00125 
00126 nsAttrValue::EnumTable kListTypeTable[] = {
00127   { "none", NS_STYLE_LIST_STYLE_NONE },
00128   { "disc", NS_STYLE_LIST_STYLE_DISC },
00129   { "circle", NS_STYLE_LIST_STYLE_CIRCLE },
00130   { "round", NS_STYLE_LIST_STYLE_CIRCLE },
00131   { "square", NS_STYLE_LIST_STYLE_SQUARE },
00132   { "decimal", NS_STYLE_LIST_STYLE_DECIMAL },
00133   { "lower-roman", NS_STYLE_LIST_STYLE_LOWER_ROMAN },
00134   { "upper-roman", NS_STYLE_LIST_STYLE_UPPER_ROMAN },
00135   { "lower-alpha", NS_STYLE_LIST_STYLE_LOWER_ALPHA },
00136   { "upper-alpha", NS_STYLE_LIST_STYLE_UPPER_ALPHA },
00137   { 0 }
00138 };
00139 
00140 nsAttrValue::EnumTable kOldListTypeTable[] = {
00141   { "1", NS_STYLE_LIST_STYLE_OLD_DECIMAL },
00142   { "A", NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA },
00143   { "a", NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA },
00144   { "I", NS_STYLE_LIST_STYLE_OLD_UPPER_ROMAN },
00145   { "i", NS_STYLE_LIST_STYLE_OLD_LOWER_ROMAN },
00146   { 0 }
00147 };
00148 
00149 PRBool
00150 nsHTMLSharedListElement::ParseAttribute(nsIAtom* aAttribute,
00151                                         const nsAString& aValue,
00152                                         nsAttrValue& aResult)
00153 {
00154   if (mNodeInfo->Equals(nsHTMLAtoms::ol) ||
00155       mNodeInfo->Equals(nsHTMLAtoms::ul)) {
00156     if (aAttribute == nsHTMLAtoms::type) {
00157       return aResult.ParseEnumValue(aValue, kListTypeTable) ||
00158              aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE);
00159     }
00160     if (aAttribute == nsHTMLAtoms::start) {
00161       return aResult.ParseIntValue(aValue);
00162     }
00163   }
00164 
00165   return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
00166 }
00167 
00168 static void
00169 MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
00170 {
00171   if (aData->mSID == eStyleStruct_List) {
00172     if (aData->mListData->mType.GetUnit() == eCSSUnit_Null) {
00173       // type: enum
00174       const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::type);
00175       if (value) {
00176         if (value->Type() == nsAttrValue::eEnum)
00177           aData->mListData->mType.SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
00178         else
00179           aData->mListData->mType.SetIntValue(NS_STYLE_LIST_STYLE_DECIMAL, eCSSUnit_Enumerated);
00180       }
00181     }
00182   }
00183 
00184   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
00185 }
00186 
00187 NS_IMETHODIMP_(PRBool)
00188 nsHTMLSharedListElement::IsAttributeMapped(const nsIAtom* aAttribute) const
00189 {
00190   if (mNodeInfo->Equals(nsHTMLAtoms::ol) ||
00191       mNodeInfo->Equals(nsHTMLAtoms::ul)) {
00192     static const MappedAttributeEntry attributes[] = {
00193       { &nsHTMLAtoms::type },
00194       { nsnull }
00195     };
00196 
00197     static const MappedAttributeEntry* const map[] = {
00198       attributes,
00199       sCommonAttributeMap,
00200     };
00201 
00202     return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
00203   }
00204 
00205   return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
00206 }
00207 
00208 nsMapRuleToAttributesFunc
00209 nsHTMLSharedListElement::GetAttributeMappingFunction() const
00210 {
00211   if (mNodeInfo->Equals(nsHTMLAtoms::ol) ||
00212       mNodeInfo->Equals(nsHTMLAtoms::ul)) {
00213     return &MapAttributesIntoRule;
00214   }
00215 
00216   return nsGenericHTMLElement::GetAttributeMappingFunction();
00217 }