2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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-11 09:50:08 +04:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
#include "mozilla/dom/HTMLTableSectionElement.h"
|
2018-06-22 19:48:42 +03:00
|
|
|
#include "mozilla/MappedDeclarations.h"
|
2004-01-26 22:22:05 +03:00
|
|
|
#include "nsMappedAttributes.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2012-12-29 18:07:48 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "mozilla/dom/HTMLTableSectionElementBinding.h"
|
2013-02-01 03:11:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2004-05-19 00:58:12 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(TableSection)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
// you will see the phrases "rowgroup" and "section" used interchangably
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
HTMLTableSectionElement::~HTMLTableSectionElement() {}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* HTMLTableSectionElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLTableSectionElement_Binding::Wrap(aCx, this, aGivenProto);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableSectionElement)
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableSectionElement,
|
2007-03-08 14:17:16 +03:00
|
|
|
nsGenericHTMLElement)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2017-10-03 02:42:09 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLTableSectionElement,
|
|
|
|
nsGenericHTMLElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableSectionElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
nsIHTMLCollection* HTMLTableSectionElement::Rows() {
|
2000-12-23 13:56:31 +03:00
|
|
|
if (!mRows) {
|
2006-07-02 11:23:10 +04:00
|
|
|
mRows = new nsContentList(this, mNodeInfo->NamespaceID(), nsGkAtoms::tr,
|
2010-09-01 06:47:00 +04:00
|
|
|
nsGkAtoms::tr, false);
|
1998-12-18 20:05:17 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
return mRows;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement> HTMLTableSectionElement::InsertRow(
|
|
|
|
int32_t aIndex, ErrorResult& aError) {
|
2002-12-17 16:29:39 +03:00
|
|
|
if (aIndex < -1) {
|
2012-12-29 18:07:48 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
uint32_t rowCount = rows->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex > (int32_t)rowCount) {
|
2012-12-29 18:07:48 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool doInsert = (aIndex < int32_t(rowCount)) && (aIndex != -1);
|
2000-05-03 18:57:00 +04:00
|
|
|
|
1998-12-18 20:05:17 +03:00
|
|
|
// create the row
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> rowContent =
|
2012-12-29 18:07:48 +04:00
|
|
|
NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2010-07-23 13:49:57 +04:00
|
|
|
if (!rowContent) {
|
2012-12-29 18:07:48 +04:00
|
|
|
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
2004-06-06 06:38:32 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2002-12-17 16:29:39 +03:00
|
|
|
if (doInsert) {
|
2016-10-14 15:33:42 +03:00
|
|
|
nsCOMPtr<nsINode> refNode = rows->Item(aIndex);
|
|
|
|
nsINode::InsertBefore(*rowContent, refNode, aError);
|
2002-12-17 16:29:39 +03:00
|
|
|
} else {
|
2012-12-29 18:07:48 +04:00
|
|
|
nsINode::AppendChild(*rowContent, aError);
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
2012-12-29 18:07:48 +04:00
|
|
|
return rowContent.forget();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
void HTMLTableSectionElement::DeleteRow(int32_t aValue, ErrorResult& aError) {
|
2002-12-17 16:29:39 +03:00
|
|
|
if (aValue < -1) {
|
2012-12-29 18:07:48 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t refIndex;
|
2002-12-17 16:29:39 +03:00
|
|
|
if (aValue == -1) {
|
2012-12-29 18:07:48 +04:00
|
|
|
refIndex = rows->Length();
|
2002-12-17 16:29:39 +03:00
|
|
|
if (refIndex == 0) {
|
2012-12-29 18:07:48 +04:00
|
|
|
return;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
refIndex = (uint32_t)aValue;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2019-02-13 23:51:10 +03:00
|
|
|
nsCOMPtr<nsINode> row = rows->Item(refIndex);
|
2002-12-17 16:29:39 +03:00
|
|
|
if (!row) {
|
2012-12-29 18:07:48 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
1998-12-18 20:05:17 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 18:07:48 +04:00
|
|
|
nsINode::RemoveChild(*row, aError);
|
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
bool HTMLTableSectionElement::ParseAttribute(
|
|
|
|
int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal, nsAttrValue& aResult) {
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
/* ignore these attributes, stored simply as strings
|
|
|
|
ch
|
|
|
|
*/
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::height) {
|
2019-06-28 23:56:55 +03:00
|
|
|
// Per HTML spec there should be nothing special here, but all browsers
|
|
|
|
// implement height mapping to style. See
|
|
|
|
// <https://github.com/whatwg/html/issues/4718>. All browsers allow 0, so
|
|
|
|
// keep doing that.
|
|
|
|
return aResult.ParseHTMLDimension(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return ParseTableCellHAlignValue(aValue, aResult);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor) {
|
2010-07-17 12:09:14 +04:00
|
|
|
return aResult.ParseColor(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::valign) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return ParseTableVAlignValue(aValue, aResult);
|
|
|
|
}
|
1998-09-15 21:58:24 +04:00
|
|
|
}
|
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(
|
|
|
|
aNamespaceID, aAttribute, aValue, aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void HTMLTableSectionElement::MapAttributesIntoRule(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2018-03-29 04:39:07 +03:00
|
|
|
// height: value
|
2018-06-22 19:48:42 +03:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_height)) {
|
2018-03-29 04:39:07 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger)
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValue(eCSSProperty_height,
|
|
|
|
(float)value->GetIntegerValue());
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
nsGenericHTMLElement::MapDivAlignAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapVAlignAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-03 01:05:19 +03:00
|
|
|
HTMLTableSectionElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2018-04-03 06:21:06 +03:00
|
|
|
{nsGkAtoms::align}, {nsGkAtoms::valign}, {nsGkAtoms::height}, {nullptr}};
|
2003-04-17 00:54:20 +04:00
|
|
|
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-17 00:54:20 +04:00
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
nsMapRuleToAttributesFunc HTMLTableSectionElement::GetAttributeMappingFunction()
|
|
|
|
const {
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-05 08:00:06 +04:00
|
|
|
}
|
2012-12-28 06:45:57 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|