LCOV - code coverage report
Current view: directory - content/html/content/src - nsHTMLPreElement.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 50 0 0.0 %
Date: 2012-06-02 Functions: 112 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "mozilla/Util.h"
      39                 : 
      40                 : #include "nsIDOMHTMLPreElement.h"
      41                 : #include "nsIDOMEventTarget.h"
      42                 : #include "nsGenericHTMLElement.h"
      43                 : #include "nsGkAtoms.h"
      44                 : #include "nsStyleConsts.h"
      45                 : #include "nsMappedAttributes.h"
      46                 : #include "nsRuleData.h"
      47                 : 
      48                 : using namespace mozilla;
      49                 : 
      50                 : class nsHTMLPreElement : public nsGenericHTMLElement,
      51                 :                          public nsIDOMHTMLPreElement
      52                 : {
      53                 : public:
      54                 :   nsHTMLPreElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      55                 :   virtual ~nsHTMLPreElement();
      56                 : 
      57                 :   // nsISupports
      58                 :   NS_DECL_ISUPPORTS_INHERITED
      59                 : 
      60                 :   // nsIDOMNode
      61               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
      62                 : 
      63                 :   // nsIDOMElement
      64               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
      65                 : 
      66                 :   // nsIDOMHTMLElement
      67               0 :   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
      68                 : 
      69                 :   // nsIDOMHTMLPreElement
      70                 :   NS_IMETHOD GetWidth(PRInt32* aWidth);
      71                 :   NS_IMETHOD SetWidth(PRInt32 aWidth);
      72                 : 
      73                 :   virtual bool ParseAttribute(PRInt32 aNamespaceID,
      74                 :                                 nsIAtom* aAttribute,
      75                 :                                 const nsAString& aValue,
      76                 :                                 nsAttrValue& aResult);
      77                 :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
      78                 :   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
      79                 : 
      80                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
      81                 : 
      82                 :   virtual nsXPCClassInfo* GetClassInfo();
      83                 : };
      84                 : 
      85                 : 
      86               0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Pre)
      87                 : 
      88                 : 
      89               0 : nsHTMLPreElement::nsHTMLPreElement(already_AddRefed<nsINodeInfo> aNodeInfo)
      90               0 :   : nsGenericHTMLElement(aNodeInfo)
      91                 : {
      92               0 : }
      93                 : 
      94               0 : nsHTMLPreElement::~nsHTMLPreElement()
      95                 : {
      96               0 : }
      97                 : 
      98                 : 
      99               0 : NS_IMPL_ADDREF_INHERITED(nsHTMLPreElement, nsGenericElement)
     100               0 : NS_IMPL_RELEASE_INHERITED(nsHTMLPreElement, nsGenericElement)
     101                 : 
     102                 : 
     103               0 : DOMCI_NODE_DATA(HTMLPreElement, nsHTMLPreElement)
     104                 : 
     105                 : // QueryInterface implementation for nsHTMLPreElement
     106               0 : NS_INTERFACE_TABLE_HEAD(nsHTMLPreElement)
     107               0 :   NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLPreElement, nsIDOMHTMLPreElement)
     108               0 :   NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLPreElement,
     109                 :                                                nsGenericHTMLElement)
     110               0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLPreElement)
     111                 : 
     112                 : 
     113               0 : NS_IMPL_ELEMENT_CLONE(nsHTMLPreElement)
     114                 : 
     115                 : 
     116               0 : NS_IMPL_INT_ATTR(nsHTMLPreElement, Width, width)
     117                 : 
     118                 : 
     119                 : bool
     120               0 : nsHTMLPreElement::ParseAttribute(PRInt32 aNamespaceID,
     121                 :                                  nsIAtom* aAttribute,
     122                 :                                  const nsAString& aValue,
     123                 :                                  nsAttrValue& aResult)
     124                 : {
     125               0 :   if (aNamespaceID == kNameSpaceID_None) {
     126               0 :     if (aAttribute == nsGkAtoms::cols) {
     127               0 :       return aResult.ParseIntWithBounds(aValue, 0);
     128                 :     }
     129               0 :     if (aAttribute == nsGkAtoms::width) {
     130               0 :       return aResult.ParseIntWithBounds(aValue, 0);
     131                 :     }
     132                 :   }
     133                 : 
     134                 :   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
     135               0 :                                               aResult);
     136                 : }
     137                 : 
     138                 : static void
     139               0 : MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
     140                 :                       nsRuleData* aData)
     141                 : {
     142               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
     143               0 :     nsCSSValue* width = aData->ValueForWidth();
     144               0 :     if (width->GetUnit() == eCSSUnit_Null) {
     145                 :       // width: int (html4 attribute == nav4 cols)
     146               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
     147               0 :       if (!value || value->Type() != nsAttrValue::eInteger) {
     148                 :         // cols: int (nav4 attribute)
     149               0 :         value = aAttributes->GetAttr(nsGkAtoms::cols);
     150                 :       }
     151                 : 
     152               0 :       if (value && value->Type() == nsAttrValue::eInteger)
     153               0 :         width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Char);
     154                 :     }
     155                 :   }
     156               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
     157               0 :     nsCSSValue* whiteSpace = aData->ValueForWhiteSpace();
     158               0 :     if (whiteSpace->GetUnit() == eCSSUnit_Null) {
     159                 :       // wrap: empty
     160               0 :       if (aAttributes->GetAttr(nsGkAtoms::wrap))
     161               0 :         whiteSpace->SetIntValue(NS_STYLE_WHITESPACE_PRE_WRAP, eCSSUnit_Enumerated);
     162                 : 
     163                 :       // width: int (html4 attribute == nav4 cols)
     164               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
     165               0 :       if (!value || value->Type() != nsAttrValue::eInteger) {
     166                 :         // cols: int (nav4 attribute)
     167               0 :         value = aAttributes->GetAttr(nsGkAtoms::cols);
     168                 :       }
     169                 : 
     170               0 :       if (value && value->Type() == nsAttrValue::eInteger) {
     171                 :         // Force wrap property on since we want to wrap at a width
     172                 :         // boundary not just a newline.
     173               0 :         whiteSpace->SetIntValue(NS_STYLE_WHITESPACE_PRE_WRAP, eCSSUnit_Enumerated);
     174                 :       }
     175                 :     }
     176                 :   }
     177                 : 
     178               0 :   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
     179               0 : }
     180                 : 
     181                 : NS_IMETHODIMP_(bool)
     182               0 : nsHTMLPreElement::IsAttributeMapped(const nsIAtom* aAttribute) const
     183                 : {
     184                 :   static const MappedAttributeEntry attributes[] = {
     185                 :     { &nsGkAtoms::wrap },
     186                 :     { &nsGkAtoms::cols },
     187                 :     { &nsGkAtoms::width },
     188                 :     { nsnull },
     189                 :   };
     190                 :   
     191                 :   static const MappedAttributeEntry* const map[] = {
     192                 :     attributes,
     193                 :     sCommonAttributeMap,
     194                 :   };
     195                 : 
     196               0 :   return FindAttributeDependence(aAttribute, map);
     197                 : }
     198                 : 
     199                 : nsMapRuleToAttributesFunc
     200               0 : nsHTMLPreElement::GetAttributeMappingFunction() const
     201                 : {
     202               0 :   return &MapAttributesIntoRule;
     203                 : }

Generated by: LCOV version 1.7