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/HTMLTableCellElement.h"
|
|
|
|
#include "mozilla/dom/HTMLTableElement.h"
|
2012-12-29 18:07:56 +04:00
|
|
|
#include "mozilla/dom/HTMLTableRowElement.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"
|
2008-07-16 19:02:18 +04:00
|
|
|
#include "celldata.h"
|
2012-12-29 18:07:56 +04:00
|
|
|
#include "mozilla/dom/HTMLTableCellElementBinding.h"
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2004-05-19 00:58:12 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(TableCell)
|
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
|
|
|
HTMLTableCellElement::~HTMLTableCellElement()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:56 +04:00
|
|
|
JSObject*
|
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
|
|
|
HTMLTableCellElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-29 18:07:56 +04:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLTableCellElement_Binding::Wrap(aCx, this, aGivenProto);
|
2012-12-29 18:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableCellElement)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-09-02 04:56:01 +04:00
|
|
|
|
1998-12-18 20:05:17 +03:00
|
|
|
// protected method
|
2012-12-29 18:07:56 +04:00
|
|
|
HTMLTableRowElement*
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableCellElement::GetRow() const
|
1998-12-18 20:05:17 +03:00
|
|
|
{
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLTableRowElement::FromNodeOrNull(GetParent());
|
1998-12-18 20:05:17 +03:00
|
|
|
}
|
|
|
|
|
2003-07-13 02:12:59 +04:00
|
|
|
// protected method
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement*
|
|
|
|
HTMLTableCellElement::GetTable() const
|
2003-07-13 02:12:59 +04:00
|
|
|
{
|
2004-08-10 14:22:36 +04:00
|
|
|
nsIContent *parent = GetParent();
|
2011-11-16 11:50:19 +04:00
|
|
|
if (!parent) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// parent should be a row.
|
|
|
|
nsIContent* section = parent->GetParent();
|
|
|
|
if (!section) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (section->IsHTMLElement(nsGkAtoms::table)) {
|
2011-11-16 11:50:19 +04:00
|
|
|
// XHTML, without a row group.
|
2012-12-28 06:45:57 +04:00
|
|
|
return static_cast<HTMLTableElement*>(section);
|
2003-07-13 02:12:59 +04:00
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
|
|
|
|
// We have a row group.
|
|
|
|
nsIContent* result = section->GetParent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (result && result->IsHTMLElement(nsGkAtoms::table)) {
|
2012-12-28 06:45:57 +04:00
|
|
|
return static_cast<HTMLTableElement*>(result);
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-07-13 02:12:59 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:56 +04:00
|
|
|
int32_t
|
|
|
|
HTMLTableCellElement::CellIndex() const
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2012-12-29 18:07:56 +04:00
|
|
|
HTMLTableRowElement* row = GetRow();
|
2001-02-06 05:11:30 +03:00
|
|
|
if (!row) {
|
2012-12-29 18:07:56 +04:00
|
|
|
return -1;
|
2001-02-06 05:11:30 +03:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:57 +04:00
|
|
|
nsIHTMLCollection* cells = row->Cells();
|
2001-02-06 05:11:30 +03:00
|
|
|
if (!cells) {
|
2012-12-29 18:07:56 +04:00
|
|
|
return -1;
|
2001-02-06 05:11:30 +03:00
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:57 +04:00
|
|
|
uint32_t numCells = cells->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < numCells; i++) {
|
2012-12-29 18:07:57 +04:00
|
|
|
if (cells->Item(i) == this) {
|
2012-12-29 18:07:56 +04:00
|
|
|
return i;
|
1998-12-18 20:05:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:56 +04:00
|
|
|
return -1;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
1999-05-27 03:47:19 +04:00
|
|
|
|
2017-03-26 23:53:34 +03:00
|
|
|
nsMappedAttributes*
|
|
|
|
HTMLTableCellElement::GetMappedAttributesInheritedFromTable() const
|
|
|
|
{
|
|
|
|
if (HTMLTableElement* table = GetTable()) {
|
|
|
|
return table->GetAttributesMappedForCell();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-12-29 18:07:56 +04:00
|
|
|
void
|
2015-02-13 04:27:39 +03:00
|
|
|
HTMLTableCellElement::GetAlign(DOMString& aValue)
|
2012-12-29 18:07:56 +04:00
|
|
|
{
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::align, aValue)) {
|
|
|
|
// There's no align attribute, ask the row for the alignment.
|
|
|
|
HTMLTableRowElement* row = GetRow();
|
|
|
|
if (row) {
|
|
|
|
row->GetAlign(aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-11 05:57:40 +04:00
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kCellScopeTable[] = {
|
1998-09-15 21:58:24 +04:00
|
|
|
{ "row", NS_STYLE_CELL_SCOPE_ROW },
|
|
|
|
{ "col", NS_STYLE_CELL_SCOPE_COL },
|
|
|
|
{ "rowgroup", NS_STYLE_CELL_SCOPE_ROWGROUP },
|
|
|
|
{ "colgroup", NS_STYLE_CELL_SCOPE_COLGROUP },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1998-09-15 21:58:24 +04:00
|
|
|
};
|
|
|
|
|
2016-05-05 21:29:54 +03:00
|
|
|
void
|
|
|
|
HTMLTableCellElement::GetScope(DOMString& aScope)
|
|
|
|
{
|
|
|
|
GetEnumAttr(nsGkAtoms::scope, nullptr, aScope);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableCellElement::ParseAttribute(int32_t aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2012-12-28 06:45:57 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2012-12-28 06:45:57 +04:00
|
|
|
nsAttrValue& aResult)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
/* ignore these attributes, stored simply as strings
|
|
|
|
abbr, axis, ch, headers
|
|
|
|
*/
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::charoff) {
|
2005-11-29 19:37:15 +03:00
|
|
|
/* attributes that resolve to integers with a min of 0 */
|
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::colspan) {
|
2017-05-18 00:24:34 +03:00
|
|
|
aResult.ParseClampedNonNegativeInt(aValue, 1, 1, MAX_COLSPAN);
|
|
|
|
return true;
|
2004-11-16 18:46:55 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::rowspan) {
|
2017-05-18 00:24:34 +03:00
|
|
|
aResult.ParseClampedNonNegativeInt(aValue, 1, 0, MAX_ROWSPAN);
|
|
|
|
// quirks mode does not honor the special html 4 value of 0
|
|
|
|
if (aResult.GetIntegerValue() == 0 && InNavQuirksMode(OwnerDoc())) {
|
|
|
|
aResult.SetTo(1, &aValue);
|
1999-09-14 00:18:33 +04:00
|
|
|
}
|
2017-05-18 00:24:34 +03:00
|
|
|
return true;
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::height) {
|
2011-02-04 22:46:16 +03:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::width) {
|
2011-02-04 22:46:16 +03:00
|
|
|
return aResult.ParseSpecialIntValue(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::scope) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kCellScopeTable, false);
|
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);
|
1999-07-24 23:55:35 +04:00
|
|
|
}
|
1998-09-15 21:58:24 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03: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
|
|
|
|
HTMLTableCellElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2018-06-22 19:48:42 +03:00
|
|
|
MappedDeclarations& aDecls)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2018-03-29 04:39:07 +03:00
|
|
|
// width: value
|
2018-06-22 19:48:42 +03:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_width)) {
|
2018-03-29 04:39:07 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
if (value->GetIntegerValue() > 0)
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValue(eCSSProperty_width, (float)value->GetIntegerValue());
|
2018-03-29 04:39:07 +03:00
|
|
|
// else 0 implies auto for compatibility.
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
else if (value && value->Type() == nsAttrValue::ePercent) {
|
|
|
|
if (value->GetPercentValue() > 0.0f)
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPercentValue(eCSSProperty_width, value->GetPercentValue());
|
2018-03-29 04:39:07 +03:00
|
|
|
// else 0 implies auto for compatibility
|
1999-08-26 01:49:18 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
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) {
|
|
|
|
if (value->GetIntegerValue() > 0)
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValue(eCSSProperty_height, (float)value->GetIntegerValue());
|
2018-03-29 04:39:07 +03:00
|
|
|
// else 0 implies auto for compatibility.
|
|
|
|
}
|
|
|
|
else if (value && value->Type() == nsAttrValue::ePercent) {
|
|
|
|
if (value->GetPercentValue() > 0.0f)
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPercentValue(eCSSProperty_height, value->GetPercentValue());
|
2018-03-29 04:39:07 +03:00
|
|
|
// else 0 implies auto for compatibility
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_white_space)) {
|
2018-03-29 04:39:07 +03:00
|
|
|
// nowrap: enum
|
|
|
|
if (aAttributes->GetAttr(nsGkAtoms::nowrap)) {
|
|
|
|
// See if our width is not a nonzero integer width.
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
|
2018-06-22 19:48:42 +03:00
|
|
|
nsCompatibility mode = aDecls.Document()->GetCompatibilityMode();
|
2018-03-29 04:39:07 +03:00
|
|
|
if (!value || value->Type() != nsAttrValue::eInteger ||
|
|
|
|
value->GetIntegerValue() == 0 ||
|
|
|
|
eCompatibility_NavQuirks != mode) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_white_space, StyleWhiteSpace::Nowrap);
|
2001-05-03 17:20:48 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2003-09-11 05:34:29 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03: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
|
|
|
HTMLTableCellElement::IsAttributeMapped(const nsAtom* aAttribute) const
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2018-04-11 11:22:05 +03:00
|
|
|
{ &nsGkAtoms::align },
|
|
|
|
{ &nsGkAtoms::valign },
|
|
|
|
{ &nsGkAtoms::nowrap },
|
2003-07-12 01:16:12 +04:00
|
|
|
#if 0
|
|
|
|
// XXXldb If these are implemented, they might need to move to
|
|
|
|
// GetAttributeChangeHint (depending on how, and preferably not).
|
2018-04-11 11:22:05 +03:00
|
|
|
{ &nsGkAtoms::abbr },
|
|
|
|
{ &nsGkAtoms::axis },
|
|
|
|
{ &nsGkAtoms::headers },
|
|
|
|
{ &nsGkAtoms::scope },
|
2003-07-12 01:16:12 +04:00
|
|
|
#endif
|
2018-04-11 11:22:05 +03:00
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ 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
|
|
|
}
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableCellElement::GetAttributeMappingFunction() const
|
1998-09-05 08:00:06 +04:00
|
|
|
{
|
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
|