Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLIFrameElement.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 "nsIDOMHTMLIFrameElement.h"
00038 #include "nsGenericHTMLElement.h"
00039 #include "nsHTMLAtoms.h"
00040 #include "nsPresContext.h"
00041 #include "nsIPresShell.h"
00042 #include "nsIDocument.h"
00043 #include "nsMappedAttributes.h"
00044 #include "nsDOMError.h"
00045 #include "nsRuleData.h"
00046 
00047 class nsHTMLIFrameElement : public nsGenericHTMLFrameElement,
00048                             public nsIDOMHTMLIFrameElement
00049 {
00050 public:
00051   nsHTMLIFrameElement(nsINodeInfo *aNodeInfo);
00052   virtual ~nsHTMLIFrameElement();
00053 
00054   // nsISupports
00055   NS_DECL_ISUPPORTS_INHERITED
00056 
00057   // nsIDOMNode
00058   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFrameElement::)
00059 
00060   // nsIDOMElement
00061   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
00062 
00063   // nsIDOMHTMLElement
00064   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
00065 
00066   // nsIDOMHTMLIFrameElement
00067   NS_DECL_NSIDOMHTMLIFRAMEELEMENT
00068 
00069   // nsIContent
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(IFrame)
00079 
00080 
00081 nsHTMLIFrameElement::nsHTMLIFrameElement(nsINodeInfo *aNodeInfo)
00082   : nsGenericHTMLFrameElement(aNodeInfo)
00083 {
00084 }
00085 
00086 nsHTMLIFrameElement::~nsHTMLIFrameElement()
00087 {
00088 }
00089 
00090 
00091 NS_IMPL_ADDREF(nsHTMLIFrameElement)
00092 NS_IMPL_RELEASE(nsHTMLIFrameElement)
00093 
00094 // QueryInterface implementation for nsHTMLIFrameElement
00095 NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLIFrameElement, nsGenericHTMLFrameElement)
00096   NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLIFrameElement)
00097   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLIFrameElement)
00098 NS_HTML_CONTENT_INTERFACE_MAP_END
00099 
00100 
00101 NS_IMPL_DOM_CLONENODE(nsHTMLIFrameElement)
00102 
00103 
00104 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Align, align)
00105 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, FrameBorder, frameborder)
00106 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Height, height)
00107 NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
00108 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
00109 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
00110 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
00111 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
00112 NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
00113 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
00114 
00115 NS_IMETHODIMP
00116 nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
00117 {
00118   return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
00119 }
00120 
00121 PRBool
00122 nsHTMLIFrameElement::ParseAttribute(nsIAtom* aAttribute,
00123                                     const nsAString& aValue,
00124                                     nsAttrValue& aResult)
00125 {
00126   if (aAttribute == nsHTMLAtoms::marginwidth) {
00127     return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
00128   }
00129   if (aAttribute == nsHTMLAtoms::marginheight) {
00130     return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
00131   }
00132   if (aAttribute == nsHTMLAtoms::width) {
00133     return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
00134   }
00135   if (aAttribute == nsHTMLAtoms::height) {
00136     return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
00137   }
00138   if (aAttribute == nsHTMLAtoms::frameborder) {
00139     return ParseFrameborderValue(aValue, aResult);
00140   }
00141   if (aAttribute == nsHTMLAtoms::scrolling) {
00142     return ParseScrollingValue(aValue, aResult);
00143   }
00144   if (aAttribute == nsHTMLAtoms::align) {
00145     return ParseAlignValue(aValue, aResult);
00146   }
00147 
00148   return nsGenericHTMLFrameElement::ParseAttribute(aAttribute, aValue, aResult);
00149 }
00150 
00151 static void
00152 MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
00153                       nsRuleData* aData)
00154 {
00155   if (aData->mSID == eStyleStruct_Border) {
00156     // frameborder: 0 | 1 (| NO | YES in quirks mode)
00157     // If frameborder is 0 or No, set border to 0
00158     // else leave it as the value set in html.css
00159     const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::frameborder);
00160     if (value && value->Type() == nsAttrValue::eEnum) {
00161       PRInt32 frameborder = value->GetEnumValue();
00162       if (NS_STYLE_FRAME_0 == frameborder ||
00163           NS_STYLE_FRAME_NO == frameborder ||
00164           NS_STYLE_FRAME_OFF == frameborder) {
00165         if (aData->mMarginData->mBorderWidth.mLeft.GetUnit() == eCSSUnit_Null)
00166           aData->mMarginData->mBorderWidth.mLeft.SetFloatValue(0.0f, eCSSUnit_Pixel);
00167         if (aData->mMarginData->mBorderWidth.mRight.GetUnit() == eCSSUnit_Null)
00168           aData->mMarginData->mBorderWidth.mRight.SetFloatValue(0.0f, eCSSUnit_Pixel);
00169         if (aData->mMarginData->mBorderWidth.mTop.GetUnit() == eCSSUnit_Null)
00170           aData->mMarginData->mBorderWidth.mTop.SetFloatValue(0.0f, eCSSUnit_Pixel);
00171         if (aData->mMarginData->mBorderWidth.mBottom.GetUnit() == eCSSUnit_Null)
00172           aData->mMarginData->mBorderWidth.mBottom.SetFloatValue(0.0f, eCSSUnit_Pixel);
00173       }
00174     }
00175   }
00176   else if (aData->mSID == eStyleStruct_Position) {
00177     // width: value
00178     if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
00179       const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::width);
00180       if (value && value->Type() == nsAttrValue::eInteger)
00181         aData->mPositionData->mWidth.SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
00182       else if (value && value->Type() == nsAttrValue::ePercent)
00183         aData->mPositionData->mWidth.SetPercentValue(value->GetPercentValue());
00184     }
00185 
00186     // height: value
00187     if (aData->mPositionData->mHeight.GetUnit() == eCSSUnit_Null) {
00188       const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::height);
00189       if (value && value->Type() == nsAttrValue::eInteger)
00190         aData->mPositionData->mHeight.SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
00191       else if (value && value->Type() == nsAttrValue::ePercent)
00192         aData->mPositionData->mHeight.SetPercentValue(value->GetPercentValue());
00193     }
00194   }
00195 
00196   nsGenericHTMLElement::MapScrollingAttributeInto(aAttributes, aData);
00197   nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
00198   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
00199 }
00200 
00201 NS_IMETHODIMP_(PRBool)
00202 nsHTMLIFrameElement::IsAttributeMapped(const nsIAtom* aAttribute) const
00203 {
00204   static const MappedAttributeEntry attributes[] = {
00205     { &nsHTMLAtoms::width },
00206     { &nsHTMLAtoms::height },
00207     { &nsHTMLAtoms::frameborder },
00208     { nsnull },
00209   };
00210 
00211   static const MappedAttributeEntry* const map[] = {
00212     attributes,
00213     sScrollingAttributeMap,
00214     sImageAlignAttributeMap,
00215     sCommonAttributeMap,
00216   };
00217   
00218   return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
00219 }
00220 
00221 
00222 
00223 nsMapRuleToAttributesFunc
00224 nsHTMLIFrameElement::GetAttributeMappingFunction() const
00225 {
00226   return &MapAttributesIntoRule;
00227 }
00228