LCOV - app.info - content/html/content/src/nsHTMLTableColElement.cpp

LCOV - code coverage report
| Current view: | directory - content/html/content/src - nsHTMLTableColElement.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 74 | 0 | 0.0 %
| Date: | 2012-04-21 | Functions: | 122 | 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 "nsIDOMHTMLTableColElement.h"
          41                 : #include "nsIDOMEventTarget.h"
          42                 : #include "nsMappedAttributes.h"
          43                 : #include "nsGenericHTMLElement.h"
          44                 : #include "nsGkAtoms.h"
          45                 : #include "nsStyleConsts.h"
          46                 : #include "nsRuleData.h"
          47                 :
          48                 : using namespace mozilla;
          49                 :
          50                 : // use the same protection as ancient code did
          51                 : // http://lxr.mozilla.org/classic/source/lib/layout/laytable.c#46
          52                 : #define MAX_COLSPAN 1000
          53                 :
          54                 : class nsHTMLTableColElement : public nsGenericHTMLElement,
          55                 :                               public nsIDOMHTMLTableColElement
          56                 : {
          57                 : public:
          58                 :   nsHTMLTableColElement(already_AddRefed<nsINodeInfo> aNodeInfo);
          59                 :   virtual ~nsHTMLTableColElement();
          60                 :
          61                 :   // nsISupports
          62                 :   NS_DECL_ISUPPORTS_INHERITED
          63                 :
          64                 :   // nsIDOMNode
          65               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
          66                 :
          67                 :   // nsIDOMElement
          68               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
          69                 :
          70                 :   // nsIDOMHTMLElement
          71               0 :   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
          72                 :
          73                 :   // nsIDOMHTMLTableColElement
          74                 :   NS_DECL_NSIDOMHTMLTABLECOLELEMENT
          75                 :
          76                 :   virtual bool ParseAttribute(PRInt32 aNamespaceID,
          77                 :                                 nsIAtom* aAttribute,
          78                 :                                 const nsAString& aValue,
          79                 :                                 nsAttrValue& aResult);
          80                 :   nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
          81                 :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
          82                 :
          83                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
          84                 :
          85                 :   virtual nsXPCClassInfo* GetClassInfo();
          86                 : };
          87                 :
          88                 :
          89               0 : NS_IMPL_NS_NEW_HTML_ELEMENT(TableCol)
          90                 :
          91                 :
          92               0 : nsHTMLTableColElement::nsHTMLTableColElement(already_AddRefed<nsINodeInfo> aNodeInfo)
          93               0 :   : nsGenericHTMLElement(aNodeInfo)
          94                 : {
          95               0 : }
          96                 :
          97               0 : nsHTMLTableColElement::~nsHTMLTableColElement()
          98                 : {
          99               0 : }
         100                 :
         101                 :
         102               0 : NS_IMPL_ADDREF_INHERITED(nsHTMLTableColElement, nsGenericElement)
         103               0 : NS_IMPL_RELEASE_INHERITED(nsHTMLTableColElement, nsGenericElement)
         104                 :
         105                 :
         106               0 : DOMCI_NODE_DATA(HTMLTableColElement, nsHTMLTableColElement)
         107                 :
         108                 : // QueryInterface implementation for nsHTMLTableColElement
         109               0 : NS_INTERFACE_TABLE_HEAD(nsHTMLTableColElement)
         110               0 :   NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLTableColElement,
         111                 :                                    nsIDOMHTMLTableColElement)
         112               0 :   NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLTableColElement,
         113                 :                                                nsGenericHTMLElement)
         114               0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLTableColElement)
         115                 :
         116               0 : NS_IMPL_ELEMENT_CLONE(nsHTMLTableColElement)
         117                 :
         118                 :
         119               0 : NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Align, align)
         120               0 : NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Ch, _char)
         121               0 : NS_IMPL_STRING_ATTR(nsHTMLTableColElement, ChOff, charoff)
         122               0 : NS_IMPL_INT_ATTR_DEFAULT_VALUE(nsHTMLTableColElement, Span, span, 1)
         123               0 : NS_IMPL_STRING_ATTR(nsHTMLTableColElement, VAlign, valign)
         124               0 : NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Width, width)
         125                 :
         126                 :
         127                 : bool
         128               0 : nsHTMLTableColElement::ParseAttribute(PRInt32 aNamespaceID,
         129                 :                                       nsIAtom* aAttribute,
         130                 :                                       const nsAString& aValue,
         131                 :                                       nsAttrValue& aResult)
         132                 : {
         133               0 :   if (aNamespaceID == kNameSpaceID_None) {
         134                 :     /* ignore these attributes, stored simply as strings ch */
         135               0 :     if (aAttribute == nsGkAtoms::charoff) {
         136               0 :       return aResult.ParseSpecialIntValue(aValue);
         137                 :     }
         138               0 :     if (aAttribute == nsGkAtoms::span) {
         139                 :       /* protection from unrealistic large colspan values */
         140               0 :       return aResult.ParseIntWithBounds(aValue, 1, MAX_COLSPAN);
         141                 :     }
         142               0 :     if (aAttribute == nsGkAtoms::width) {
         143               0 :       return aResult.ParseSpecialIntValue(aValue);
         144                 :     }
         145               0 :     if (aAttribute == nsGkAtoms::align) {
         146               0 :       return ParseTableCellHAlignValue(aValue, aResult);
         147                 :     }
         148               0 :     if (aAttribute == nsGkAtoms::valign) {
         149               0 :       return ParseTableVAlignValue(aValue, aResult);
         150                 :     }
         151                 :   }
         152                 :
         153                 :   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
         154               0 :                                               aResult);
         155                 : }
         156                 :
         157                 : static
         158               0 : void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
         159                 : {
         160               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Table)) {
         161               0 :     nsCSSValue *span = aData->ValueForSpan();
         162               0 :     if (span->GetUnit() == eCSSUnit_Null) {
         163                 :       // span: int
         164               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::span);
         165               0 :       if (value && value->Type() == nsAttrValue::eInteger) {
         166               0 :         PRInt32 val = value->GetIntegerValue();
         167                 :         // Note: Do NOT use this code for table cells!  The value "0"
         168                 :         // means something special for colspan and rowspan, but for <col
         169                 :         // span> and <colgroup span> it's just disallowed.
         170               0 :         if (val > 0) {
         171               0 :           span->SetIntValue(value->GetIntegerValue(), eCSSUnit_Integer);
         172                 :         }
         173                 :       }
         174                 :     }
         175                 :   }
         176               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
         177               0 :     nsCSSValue* width = aData->ValueForWidth();
         178               0 :     if (width->GetUnit() == eCSSUnit_Null) {
         179                 :       // width
         180               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
         181               0 :       if (value) {
         182               0 :         switch (value->Type()) {
         183                 :         case nsAttrValue::ePercent: {
         184               0 :           width->SetPercentValue(value->GetPercentValue());
         185               0 :           break;
         186                 :         }
         187                 :         case nsAttrValue::eInteger: {
         188               0 :           width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
         189               0 :           break;
         190                 :         }
         191                 :         default:
         192               0 :           break;
         193                 :         }
         194                 :       }
         195                 :     }
         196                 :   }
         197               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
         198               0 :     nsCSSValue* textAlign = aData->ValueForTextAlign();
         199               0 :     if (textAlign->GetUnit() == eCSSUnit_Null) {
         200                 :       // align: enum
         201               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
         202               0 :       if (value && value->Type() == nsAttrValue::eEnum)
         203               0 :         textAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
         204                 :     }
         205                 :   }
         206               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TextReset)) {
         207               0 :     nsCSSValue* verticalAlign = aData->ValueForVerticalAlign();
         208               0 :     if (verticalAlign->GetUnit() == eCSSUnit_Null) {
         209                 :       // valign: enum
         210               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::valign);
         211               0 :       if (value && value->Type() == nsAttrValue::eEnum)
         212               0 :         verticalAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
         213                 :     }
         214                 :   }
         215                 :
         216               0 :   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
         217               0 : }
         218                 :
         219                 : NS_IMETHODIMP_(bool)
         220               0 : nsHTMLTableColElement::IsAttributeMapped(const nsIAtom* aAttribute) const
         221                 : {
         222                 :   static const MappedAttributeEntry attributes[] = {
         223                 :     { &nsGkAtoms::width },
         224                 :     { &nsGkAtoms::align },
         225                 :     { &nsGkAtoms::valign },
         226                 :     { &nsGkAtoms::span },
         227                 :     { nsnull }
         228                 :   };
         229                 :
         230                 :   static const MappedAttributeEntry* const map[] = {
         231                 :     attributes,
         232                 :     sCommonAttributeMap,
         233                 :   };
         234                 :
         235               0 :   return FindAttributeDependence(aAttribute, map);
         236                 : }
         237                 :
         238                 :
         239                 : nsMapRuleToAttributesFunc
         240               0 : nsHTMLTableColElement::GetAttributeMappingFunction() const
         241                 : {
         242               0 :   return &MapAttributesIntoRule;
         243                 : }

Generated by: LCOV version 1.7