LCOV - code coverage report
Current view: top level - dom/html - HTMLTableSectionElement.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 87 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "mozilla/dom/HTMLTableSectionElement.h"
       8             : #include "mozilla/GenericSpecifiedValuesInlines.h"
       9             : #include "nsMappedAttributes.h"
      10             : #include "nsAttrValueInlines.h"
      11             : #include "mozilla/dom/BindingUtils.h"
      12             : #include "mozilla/dom/HTMLTableSectionElementBinding.h"
      13             : #include "nsContentUtils.h"
      14             : 
      15           0 : NS_IMPL_NS_NEW_HTML_ELEMENT(TableSection)
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : // you will see the phrases "rowgroup" and "section" used interchangably
      21             : 
      22           0 : HTMLTableSectionElement::~HTMLTableSectionElement()
      23             : {
      24           0 : }
      25             : 
      26             : JSObject*
      27           0 : HTMLTableSectionElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
      28             : {
      29           0 :   return HTMLTableSectionElementBinding::Wrap(aCx, this, aGivenProto);
      30             : }
      31             : 
      32             : NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableSectionElement)
      33             : 
      34           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableSectionElement,
      35             :                                                   nsGenericHTMLElement)
      36           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
      37           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
      38             : 
      39           0 : NS_IMPL_ADDREF_INHERITED(HTMLTableSectionElement, Element)
      40           0 : NS_IMPL_RELEASE_INHERITED(HTMLTableSectionElement, Element)
      41             : 
      42             : // QueryInterface implementation for HTMLTableSectionElement
      43           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTableSectionElement)
      44           0 : NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
      45             : 
      46             : 
      47           0 : NS_IMPL_ELEMENT_CLONE(HTMLTableSectionElement)
      48             : 
      49             : nsIHTMLCollection*
      50           0 : HTMLTableSectionElement::Rows()
      51             : {
      52           0 :   if (!mRows) {
      53             :     mRows = new nsContentList(this,
      54           0 :                               mNodeInfo->NamespaceID(),
      55             :                               nsGkAtoms::tr,
      56             :                               nsGkAtoms::tr,
      57           0 :                               false);
      58             :   }
      59             : 
      60           0 :   return mRows;
      61             : }
      62             : 
      63             : already_AddRefed<nsGenericHTMLElement>
      64           0 : HTMLTableSectionElement::InsertRow(int32_t aIndex, ErrorResult& aError)
      65             : {
      66           0 :   if (aIndex < -1) {
      67           0 :     aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
      68           0 :     return nullptr;
      69             :   }
      70             : 
      71           0 :   nsIHTMLCollection* rows = Rows();
      72             : 
      73           0 :   uint32_t rowCount = rows->Length();
      74           0 :   if (aIndex > (int32_t)rowCount) {
      75           0 :     aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
      76           0 :     return nullptr;
      77             :   }
      78             : 
      79           0 :   bool doInsert = (aIndex < int32_t(rowCount)) && (aIndex != -1);
      80             : 
      81             :   // create the row
      82           0 :   RefPtr<mozilla::dom::NodeInfo> nodeInfo;
      83           0 :   nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tr,
      84           0 :                                getter_AddRefs(nodeInfo));
      85             : 
      86             :   RefPtr<nsGenericHTMLElement> rowContent =
      87           0 :     NS_NewHTMLTableRowElement(nodeInfo.forget());
      88           0 :   if (!rowContent) {
      89           0 :     aError.Throw(NS_ERROR_OUT_OF_MEMORY);
      90           0 :     return nullptr;
      91             :   }
      92             : 
      93           0 :   if (doInsert) {
      94           0 :     nsCOMPtr<nsINode> refNode = rows->Item(aIndex);
      95           0 :     nsINode::InsertBefore(*rowContent, refNode, aError);
      96             :   } else {
      97           0 :     nsINode::AppendChild(*rowContent, aError);
      98             :   }
      99           0 :   return rowContent.forget();
     100             : }
     101             : 
     102             : void
     103           0 : HTMLTableSectionElement::DeleteRow(int32_t aValue, ErrorResult& aError)
     104             : {
     105           0 :   if (aValue < -1) {
     106           0 :     aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     107           0 :     return;
     108             :   }
     109             : 
     110           0 :   nsIHTMLCollection* rows = Rows();
     111             : 
     112             :   uint32_t refIndex;
     113           0 :   if (aValue == -1) {
     114           0 :     refIndex = rows->Length();
     115           0 :     if (refIndex == 0) {
     116           0 :       return;
     117             :     }
     118             : 
     119           0 :     --refIndex;
     120             :   }
     121             :   else {
     122           0 :     refIndex = (uint32_t)aValue;
     123             :   }
     124             : 
     125           0 :   nsINode* row = rows->Item(refIndex);
     126           0 :   if (!row) {
     127           0 :     aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     128           0 :     return;
     129             :   }
     130             : 
     131           0 :   nsINode::RemoveChild(*row, aError);
     132             : }
     133             : 
     134             : bool
     135           0 : HTMLTableSectionElement::ParseAttribute(int32_t aNamespaceID,
     136             :                                         nsIAtom* aAttribute,
     137             :                                         const nsAString& aValue,
     138             :                                         nsAttrValue& aResult)
     139             : {
     140           0 :   if (aNamespaceID == kNameSpaceID_None) {
     141             :     /* ignore these attributes, stored simply as strings
     142             :        ch
     143             :     */
     144           0 :     if (aAttribute == nsGkAtoms::charoff) {
     145           0 :       return aResult.ParseIntWithBounds(aValue, 0);
     146             :     }
     147           0 :     if (aAttribute == nsGkAtoms::height) {
     148           0 :       return aResult.ParseSpecialIntValue(aValue);
     149             :     }
     150           0 :     if (aAttribute == nsGkAtoms::align) {
     151           0 :       return ParseTableCellHAlignValue(aValue, aResult);
     152             :     }
     153           0 :     if (aAttribute == nsGkAtoms::bgcolor) {
     154           0 :       return aResult.ParseColor(aValue);
     155             :     }
     156           0 :     if (aAttribute == nsGkAtoms::valign) {
     157           0 :       return ParseTableVAlignValue(aValue, aResult);
     158             :     }
     159             :   }
     160             : 
     161           0 :   return nsGenericHTMLElement::ParseBackgroundAttribute(aNamespaceID,
     162             :                                                         aAttribute, aValue,
     163           0 :                                                         aResult) ||
     164           0 :          nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
     165           0 :                                               aResult);
     166             : }
     167             : 
     168             : void
     169           0 : HTMLTableSectionElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
     170             :                                                GenericSpecifiedValues* aData)
     171             : {
     172           0 :   if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position))) {
     173             :     // height: value
     174           0 :     if (!aData->PropertyIsSet(eCSSProperty_height)) {
     175           0 :       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
     176           0 :       if (value && value->Type() == nsAttrValue::eInteger)
     177           0 :         aData->SetPixelValue(eCSSProperty_height, (float)value->GetIntegerValue());
     178             :     }
     179             :   }
     180           0 :   nsGenericHTMLElement::MapDivAlignAttributeInto(aAttributes, aData);
     181           0 :   nsGenericHTMLElement::MapVAlignAttributeInto(aAttributes, aData);
     182           0 :   nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
     183           0 :   nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
     184           0 : }
     185             : 
     186             : NS_IMETHODIMP_(bool)
     187           0 : HTMLTableSectionElement::IsAttributeMapped(const nsIAtom* aAttribute) const
     188             : {
     189             :   static const MappedAttributeEntry attributes[] = {
     190             :     { &nsGkAtoms::align },
     191             :     { &nsGkAtoms::valign },
     192             :     { &nsGkAtoms::height },
     193             :     { nullptr }
     194             :   };
     195             : 
     196             :   static const MappedAttributeEntry* const map[] = {
     197             :     attributes,
     198             :     sCommonAttributeMap,
     199             :     sBackgroundAttributeMap,
     200             :   };
     201             : 
     202           0 :   return FindAttributeDependence(aAttribute, map);
     203             : }
     204             : 
     205             : 
     206             : nsMapRuleToAttributesFunc
     207           0 : HTMLTableSectionElement::GetAttributeMappingFunction() const
     208             : {
     209           0 :   return &MapAttributesIntoRule;
     210             : }
     211             : 
     212             : } // namespace dom
     213             : } // namespace mozilla

Generated by: LCOV version 1.13