2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
#include "mozilla/dom/HTMLTableSectionElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsMappedAttributes.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRuleData.h"
|
2012-12-29 06:07:48 -08:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "mozilla/dom/HTMLTableSectionElementBinding.h"
|
2013-01-31 15:11:49 -08:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(TableSection)
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
// you will see the phrases "rowgroup" and "section" used interchangably
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
JSObject*
|
2013-04-25 09:29:54 -07:00
|
|
|
HTMLTableSectionElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLTableSectionElementBinding::Wrap(aCx, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableSectionElement)
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableSectionElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericHTMLElement)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTableSectionElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTableSectionElement, Element)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
// QueryInterface implementation for HTMLTableSectionElement
|
2013-08-01 15:24:22 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTableSectionElement)
|
2013-08-07 13:23:08 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableSectionElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
nsIHTMLCollection*
|
|
|
|
HTMLTableSectionElement::Rows()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mRows) {
|
|
|
|
mRows = new nsContentList(this,
|
|
|
|
mNodeInfo->NamespaceID(),
|
2010-08-31 19:47:00 -07:00
|
|
|
nsGkAtoms::tr,
|
|
|
|
nsGkAtoms::tr,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
return mRows;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableSectionElement::InsertRow(int32_t aIndex, ErrorResult& aError)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIndex < -1) {
|
2012-12-29 06:07:48 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
uint32_t rowCount = rows->Length();
|
2012-08-22 08:56:38 -07:00
|
|
|
if (aIndex > (int32_t)rowCount) {
|
2012-12-29 06:07:48 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool doInsert = (aIndex < int32_t(rowCount)) && (aIndex != -1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// create the row
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
nsRefPtr<nsGenericHTMLElement> rowContent =
|
|
|
|
NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2010-07-23 02:49:57 -07:00
|
|
|
if (!rowContent) {
|
2012-12-29 06:07:48 -08:00
|
|
|
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doInsert) {
|
2012-12-29 06:07:48 -08:00
|
|
|
nsINode::InsertBefore(*rowContent, rows->Item(aIndex), aError);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-12-29 06:07:48 -08:00
|
|
|
nsINode::AppendChild(*rowContent, aError);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-12-29 06:07:48 -08:00
|
|
|
return rowContent.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
void
|
|
|
|
HTMLTableSectionElement::DeleteRow(int32_t aValue, ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aValue < -1) {
|
2012-12-29 06:07:48 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t refIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aValue == -1) {
|
2012-12-29 06:07:48 -08:00
|
|
|
refIndex = rows->Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (refIndex == 0) {
|
2012-12-29 06:07:48 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
|
|
|
}
|
|
|
|
else {
|
2012-08-22 08:56:38 -07:00
|
|
|
refIndex = (uint32_t)aValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
nsINode* row = rows->Item(refIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!row) {
|
2012-12-29 06:07:48 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 06:07:48 -08:00
|
|
|
nsINode::RemoveChild(*row, aError);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableSectionElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
/* ignore these attributes, stored simply as strings
|
|
|
|
ch
|
|
|
|
*/
|
|
|
|
if (aAttribute == nsGkAtoms::charoff) {
|
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::height) {
|
2011-02-04 11:46:16 -08:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
|
|
|
return ParseTableCellHAlignValue(aValue, aResult);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::bgcolor) {
|
2010-07-17 01:09:14 -07:00
|
|
|
return aResult.ParseColor(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::valign) {
|
|
|
|
return ParseTableVAlignValue(aValue, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 10:50:49 -07:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(aNamespaceID,
|
|
|
|
aAttribute, aValue,
|
|
|
|
aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2013-11-19 11:21:29 -08:00
|
|
|
void
|
|
|
|
HTMLTableSectionElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// height: value
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* height = aData->ValueForHeight();
|
|
|
|
if (height->GetUnit() == eCSSUnit_Null) {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger)
|
2011-03-17 20:14:31 -07:00
|
|
|
height->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* textAlign = aData->ValueForTextAlign();
|
|
|
|
if (textAlign->GetUnit() == eCSSUnit_Null) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// align: enum
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum)
|
2011-03-17 20:14:31 -07:00
|
|
|
textAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TextReset)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* verticalAlign = aData->ValueForVerticalAlign();
|
|
|
|
if (verticalAlign->GetUnit() == eCSSUnit_Null) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// valign: enum
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::valign);
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum)
|
2011-03-17 20:14:31 -07:00
|
|
|
verticalAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableSectionElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2013-08-01 15:24:22 -07:00
|
|
|
{ &nsGkAtoms::align },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ &nsGkAtoms::valign },
|
|
|
|
{ &nsGkAtoms::height },
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nullptr }
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableSectionElement::GetAttributeMappingFunction() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
2012-12-27 18:45:57 -08:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|