LCOV - code coverage report
Current view: directory - content/html/content/src - nsHTMLTableSectionElement.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 118 3 2.5 %
Date: 2012-06-02 Functions: 127 3 2.4 %

       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 "nsIDOMHTMLTableSectionElem.h"
      41                 : #include "nsIDOMEventTarget.h"
      42                 : #include "nsMappedAttributes.h"
      43                 : #include "nsGenericHTMLElement.h"
      44                 : #include "nsGkAtoms.h"
      45                 : #include "nsHTMLParts.h"
      46                 : #include "nsStyleConsts.h"
      47                 : #include "nsContentList.h"
      48                 : #include "nsRuleData.h"
      49                 : #include "nsDOMError.h"
      50                 : #include "nsIDocument.h"
      51                 : #include "nsContentUtils.h"
      52                 : 
      53                 : using namespace mozilla;
      54                 : 
      55                 : // you will see the phrases "rowgroup" and "section" used interchangably
      56                 : 
      57                 : class nsHTMLTableSectionElement : public nsGenericHTMLElement,
      58                 :                                   public nsIDOMHTMLTableSectionElement
      59               0 : {
      60                 : public:
      61                 :   nsHTMLTableSectionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      62                 : 
      63                 :   // nsISupports
      64                 :   NS_DECL_ISUPPORTS_INHERITED
      65                 : 
      66                 :   // nsIDOMNode
      67               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
      68                 : 
      69                 :   // nsIDOMElement
      70               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
      71                 : 
      72                 :   // nsIDOMHTMLElement
      73               0 :   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
      74                 : 
      75                 :   // nsIDOMHTMLTableSectionElement
      76                 :   NS_DECL_NSIDOMHTMLTABLESECTIONELEMENT
      77                 : 
      78                 :   virtual bool ParseAttribute(PRInt32 aNamespaceID,
      79                 :                                 nsIAtom* aAttribute,
      80                 :                                 const nsAString& aValue,
      81                 :                                 nsAttrValue& aResult);
      82                 :   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
      83                 :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
      84                 : 
      85                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
      86                 : 
      87            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLTableSectionElement,
      88                 :                                                      nsGenericHTMLElement)
      89                 : 
      90                 :   virtual nsXPCClassInfo* GetClassInfo();
      91                 : protected:
      92                 :   nsRefPtr<nsContentList> mRows;
      93                 : };
      94                 : 
      95                 : 
      96               0 : NS_IMPL_NS_NEW_HTML_ELEMENT(TableSection)
      97                 : 
      98                 : 
      99               0 : nsHTMLTableSectionElement::nsHTMLTableSectionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
     100               0 :   : nsGenericHTMLElement(aNodeInfo)
     101                 : {
     102               0 : }
     103                 : 
     104            1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableSectionElement)
     105               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableSectionElement,
     106                 :                                                   nsGenericHTMLElement)
     107               0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRows,
     108                 :                                                        nsIDOMNodeList)
     109               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     110                 : 
     111               0 : NS_IMPL_ADDREF_INHERITED(nsHTMLTableSectionElement, nsGenericElement) 
     112               0 : NS_IMPL_RELEASE_INHERITED(nsHTMLTableSectionElement, nsGenericElement) 
     113                 : 
     114                 : 
     115               0 : DOMCI_NODE_DATA(HTMLTableSectionElement, nsHTMLTableSectionElement)
     116                 : 
     117                 : // QueryInterface implementation for nsHTMLTableSectionElement
     118               0 : NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLTableSectionElement)
     119               0 :   NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLTableSectionElement,
     120                 :                                    nsIDOMHTMLTableSectionElement)
     121               0 :   NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLTableSectionElement,
     122                 :                                                nsGenericHTMLElement)
     123               0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLTableSectionElement)
     124                 : 
     125                 : 
     126               0 : NS_IMPL_ELEMENT_CLONE(nsHTMLTableSectionElement)
     127                 : 
     128                 : 
     129               0 : NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, Align, align)
     130               0 : NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, VAlign, valign)
     131               0 : NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, Ch, _char)
     132               0 : NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, ChOff, charoff)
     133                 : 
     134                 : 
     135                 : NS_IMETHODIMP
     136               0 : nsHTMLTableSectionElement::GetRows(nsIDOMHTMLCollection** aValue)
     137                 : {
     138               0 :   if (!mRows) {
     139                 :     mRows = new nsContentList(this,
     140               0 :                               mNodeInfo->NamespaceID(),
     141                 :                               nsGkAtoms::tr,
     142                 :                               nsGkAtoms::tr,
     143               0 :                               false);
     144                 :   }
     145                 : 
     146               0 :   NS_ADDREF(*aValue = mRows);
     147               0 :   return NS_OK;
     148                 : }
     149                 : 
     150                 : 
     151                 : NS_IMETHODIMP
     152               0 : nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex,
     153                 :                                      nsIDOMHTMLElement** aValue)
     154                 : {
     155               0 :   *aValue = nsnull;
     156                 : 
     157               0 :   if (aIndex < -1) {
     158               0 :     return NS_ERROR_DOM_INDEX_SIZE_ERR;
     159                 :   }
     160                 : 
     161               0 :   nsCOMPtr<nsIDOMHTMLCollection> rows;
     162               0 :   GetRows(getter_AddRefs(rows));
     163                 : 
     164                 :   PRUint32 rowCount;
     165               0 :   rows->GetLength(&rowCount);
     166                 : 
     167               0 :   if (aIndex > (PRInt32)rowCount) {
     168               0 :     return NS_ERROR_DOM_INDEX_SIZE_ERR;
     169                 :   }
     170                 : 
     171               0 :   bool doInsert = (aIndex < PRInt32(rowCount)) && (aIndex != -1);
     172                 : 
     173                 :   // create the row
     174               0 :   nsCOMPtr<nsINodeInfo> nodeInfo;
     175                 :   nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
     176               0 :                               getter_AddRefs(nodeInfo));
     177                 : 
     178               0 :   nsCOMPtr<nsIContent> rowContent = NS_NewHTMLTableRowElement(nodeInfo.forget());
     179               0 :   if (!rowContent) {
     180               0 :     return NS_ERROR_OUT_OF_MEMORY;
     181                 :   }
     182                 : 
     183               0 :   nsCOMPtr<nsIDOMNode> rowNode(do_QueryInterface(rowContent));
     184               0 :   NS_ASSERTION(rowNode, "Should implement nsIDOMNode!");
     185                 : 
     186               0 :   nsCOMPtr<nsIDOMNode> retChild;
     187                 : 
     188                 :   nsresult rv;
     189               0 :   if (doInsert) {
     190               0 :     nsCOMPtr<nsIDOMNode> refRow;
     191               0 :     rows->Item(aIndex, getter_AddRefs(refRow));
     192                 : 
     193               0 :     rv = InsertBefore(rowNode, refRow, getter_AddRefs(retChild));
     194               0 :     NS_ENSURE_SUCCESS(rv, rv);
     195                 :   } else {
     196               0 :     rv = AppendChild(rowNode, getter_AddRefs(retChild));
     197               0 :     NS_ENSURE_SUCCESS(rv, rv);
     198                 :   }
     199                 : 
     200               0 :   if (retChild) {
     201               0 :     CallQueryInterface(retChild, aValue);
     202                 :   }
     203                 : 
     204               0 :   return NS_OK;
     205                 : }
     206                 : 
     207                 : NS_IMETHODIMP
     208               0 : nsHTMLTableSectionElement::DeleteRow(PRInt32 aValue)
     209                 : {
     210               0 :   if (aValue < -1) {
     211               0 :     return NS_ERROR_DOM_INDEX_SIZE_ERR;
     212                 :   }
     213                 : 
     214               0 :   nsCOMPtr<nsIDOMHTMLCollection> rows;
     215               0 :   GetRows(getter_AddRefs(rows));
     216                 : 
     217                 :   nsresult rv;
     218                 :   PRUint32 refIndex;
     219               0 :   if (aValue == -1) {
     220               0 :     rv = rows->GetLength(&refIndex);
     221               0 :     NS_ENSURE_SUCCESS(rv, rv);
     222                 : 
     223               0 :     if (refIndex == 0) {
     224               0 :       return NS_OK;
     225                 :     }
     226                 : 
     227               0 :     --refIndex;
     228                 :   }
     229                 :   else {
     230               0 :     refIndex = (PRUint32)aValue;
     231                 :   }
     232                 : 
     233               0 :   nsCOMPtr<nsIDOMNode> row;
     234               0 :   rv = rows->Item(refIndex, getter_AddRefs(row));
     235               0 :   NS_ENSURE_SUCCESS(rv, rv);
     236                 : 
     237               0 :   if (!row) {
     238               0 :     return NS_ERROR_DOM_INDEX_SIZE_ERR;
     239                 :   }
     240                 : 
     241               0 :   nsCOMPtr<nsIDOMNode> retChild;
     242               0 :   return RemoveChild(row, getter_AddRefs(retChild));
     243                 : }
     244                 : 
     245                 : bool
     246               0 : nsHTMLTableSectionElement::ParseAttribute(PRInt32 aNamespaceID,
     247                 :                                           nsIAtom* aAttribute,
     248                 :                                           const nsAString& aValue,
     249                 :                                           nsAttrValue& aResult)
     250                 : {
     251               0 :   if (aNamespaceID == kNameSpaceID_None) {
     252                 :     /* ignore these attributes, stored simply as strings
     253                 :        ch
     254                 :     */
     255               0 :     if (aAttribute == nsGkAtoms::charoff) {
     256               0 :       return aResult.ParseIntWithBounds(aValue, 0);
     257                 :     }
     258               0 :     if (aAttribute == nsGkAtoms::height) {
     259               0 :       return aResult.ParseSpecialIntValue(aValue);
     260                 :     }
     261               0 :     if (aAttribute == nsGkAtoms::align) {
     262               0 :       return ParseTableCellHAlignValue(aValue, aResult);
     263                 :     }
     264               0 :     if (aAttribute == nsGkAtoms::bgcolor) {
     265               0 :       return aResult.ParseColor(aValue);
     266                 :     }
     267               0 :     if (aAttribute == nsGkAtoms::valign) {
     268               0 :       return ParseTableVAlignValue(aValue, aResult);
     269                 :     }
     270                 :   }
     271                 : 
     272                 :   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
     273               0 :                                               aResult);
     274                 : }
     275                 : 
     276                 : static 
     277               0 : void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
     278                 : {
     279               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
     280                 :     // height: value
     281               0 :     nsCSSValue* height = aData->ValueForHeight();
     282               0 :     if (height->GetUnit() == eCSSUnit_Null) {
     283               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
     284               0 :       if (value && value->Type() == nsAttrValue::eInteger)
     285               0 :         height->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
     286                 :     }
     287                 :   }
     288               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
     289               0 :     nsCSSValue* textAlign = aData->ValueForTextAlign();
     290               0 :     if (textAlign->GetUnit() == eCSSUnit_Null) {
     291                 :       // align: enum
     292               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
     293               0 :       if (value && value->Type() == nsAttrValue::eEnum)
     294               0 :         textAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
     295                 :     }
     296                 :   }
     297               0 :   if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TextReset)) {
     298               0 :     nsCSSValue* verticalAlign = aData->ValueForVerticalAlign();
     299               0 :     if (verticalAlign->GetUnit() == eCSSUnit_Null) {
     300                 :       // valign: enum
     301               0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::valign);
     302               0 :       if (value && value->Type() == nsAttrValue::eEnum)
     303               0 :         verticalAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
     304                 :     }
     305                 :   }
     306                 : 
     307               0 :   nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
     308               0 :   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
     309               0 : }
     310                 : 
     311                 : NS_IMETHODIMP_(bool)
     312               0 : nsHTMLTableSectionElement::IsAttributeMapped(const nsIAtom* aAttribute) const
     313                 : {
     314                 :   static const MappedAttributeEntry attributes[] = {
     315                 :     { &nsGkAtoms::align }, 
     316                 :     { &nsGkAtoms::valign },
     317                 :     { &nsGkAtoms::height },
     318                 :     { nsnull }
     319                 :   };
     320                 : 
     321                 :   static const MappedAttributeEntry* const map[] = {
     322                 :     attributes,
     323                 :     sCommonAttributeMap,
     324                 :     sBackgroundAttributeMap,
     325                 :   };
     326                 : 
     327               0 :   return FindAttributeDependence(aAttribute, map);
     328                 : }
     329                 : 
     330                 : 
     331                 : nsMapRuleToAttributesFunc
     332               0 : nsHTMLTableSectionElement::GetAttributeMappingFunction() const
     333                 : {
     334               0 :   return &MapAttributesIntoRule;
     335            4392 : }

Generated by: LCOV version 1.7