2015-05-03 19:32:37 +00: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 11:12:37 +00: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 05:50:08 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
#include "mozilla/dom/HTMLTableElement.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValueInlines.h"
|
2004-07-20 06:11:27 +00:00
|
|
|
#include "nsRuleData.h"
|
2011-08-20 10:18:50 +00:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2013-02-14 15:33:16 +00:00
|
|
|
#include "nsMappedAttributes.h"
|
2012-12-29 08:08:15 +00:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLTableElementBinding.h"
|
2013-01-31 23:11:49 +00:00
|
|
|
#include "nsContentUtils.h"
|
2014-04-16 02:58:44 +00:00
|
|
|
#include "jsfriendapi.h"
|
1998-11-16 23:31:24 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Table)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-10-11 05:50:08 +00:00
|
|
|
|
1998-11-16 23:31:24 +00:00
|
|
|
/* ------------------------------ TableRowsCollection -------------------------------- */
|
|
|
|
/**
|
|
|
|
* This class provides a late-bound collection of rows in a table.
|
|
|
|
* mParent is NOT ref-counted to avoid circular references
|
|
|
|
*/
|
2015-03-21 18:35:18 +00:00
|
|
|
class TableRowsCollection final : public nsIHTMLCollection,
|
|
|
|
public nsWrapperCache
|
1998-11-16 23:31:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit TableRowsCollection(HTMLTableElement* aParent);
|
1998-11-16 23:31:24 +00:00
|
|
|
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
1998-11-16 23:31:24 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual Element* GetElementAt(uint32_t aIndex) override;
|
|
|
|
virtual nsINode* GetParentObject() override
|
2011-05-31 21:47:59 +00:00
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2008-10-22 14:31:14 +00:00
|
|
|
|
2013-11-11 07:55:41 +00:00
|
|
|
virtual Element*
|
2015-03-21 16:28:04 +00:00
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override;
|
2016-05-10 02:25:40 +00:00
|
|
|
virtual void GetSupportedNames(nsTArray<nsString>& aNames) override;
|
2012-09-05 20:49:53 +00:00
|
|
|
|
1998-11-16 23:31:24 +00:00
|
|
|
NS_IMETHOD ParentDestroyed();
|
|
|
|
|
2011-05-31 21:47:17 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TableRowsCollection)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
2013-11-12 15:22:22 +00:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-12 15:22:22 +00:00
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~TableRowsCollection();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
2011-05-31 21:47:17 +00:00
|
|
|
{
|
2013-11-12 15:22:22 +00:00
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
2011-05-31 21:47:17 +00:00
|
|
|
}
|
2007-03-08 11:17:16 +00:00
|
|
|
|
2006-04-21 01:44:58 +00:00
|
|
|
// Those rows that are not in table sections
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement* mParent;
|
1998-11-16 23:31:24 +00:00
|
|
|
};
|
|
|
|
|
1999-10-07 00:35:04 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
TableRowsCollection::TableRowsCollection(HTMLTableElement *aParent)
|
2007-03-08 11:17:16 +00:00
|
|
|
: mParent(aParent)
|
1998-11-16 23:31:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TableRowsCollection::~TableRowsCollection()
|
|
|
|
{
|
2000-12-23 10:56:31 +00:00
|
|
|
// we do NOT have a ref-counted reference to mParent, so do NOT
|
|
|
|
// release it! this is to avoid circular references. The
|
|
|
|
// instantiator who provided mParent is responsible for managing our
|
|
|
|
// reference for us.
|
1998-11-16 23:31:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 15:22:22 +00: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 14:13:33 +00:00
|
|
|
TableRowsCollection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-11-12 15:22:22 +00:00
|
|
|
{
|
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 14:13:33 +00:00
|
|
|
return HTMLCollectionBinding::Wrap(aCx, this, aGivenProto);
|
2013-11-12 15:22:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 07:08:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(TableRowsCollection)
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TableRowsCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TableRowsCollection)
|
|
|
|
|
2007-08-20 22:55:06 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD(TableRowsCollection)
|
2014-08-25 23:21:35 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE(TableRowsCollection, nsIHTMLCollection,
|
|
|
|
nsIDOMHTMLCollection)
|
2007-08-20 22:55:06 +00:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(TableRowsCollection)
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2005-08-15 02:34:21 +00:00
|
|
|
// Macro that can be used to avoid copy/pasting code to iterate over the
|
|
|
|
// rowgroups. _code should be the code to execute for each rowgroup. The
|
2016-05-17 07:08:00 +00:00
|
|
|
// rowgroup's rows will be in the nsIDOMHTMLCollection* named "rows".
|
|
|
|
// _trCode should be the code to execute for each tr row. Note that
|
|
|
|
// this may be null at any time. This macro assumes an nsresult named
|
2006-04-21 01:44:58 +00:00
|
|
|
// |rv| is in scope.
|
2016-05-17 07:08:00 +00:00
|
|
|
#define DO_FOR_EACH_BY_ORDER(_code, _trCode) \
|
|
|
|
do { \
|
|
|
|
if (mParent) { \
|
|
|
|
HTMLTableSectionElement* rowGroup; \
|
|
|
|
nsIHTMLCollection* rows; \
|
|
|
|
/* THead */ \
|
|
|
|
for (nsIContent* _node = mParent->nsINode::GetFirstChild(); \
|
|
|
|
_node; _node = _node->GetNextSibling()) { \
|
|
|
|
if (_node->IsHTMLElement(nsGkAtoms::thead)) { \
|
|
|
|
rowGroup = static_cast<HTMLTableSectionElement*>(_node);\
|
|
|
|
rows = rowGroup->Rows(); \
|
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
/* TBodies */ \
|
|
|
|
for (nsIContent* _node = mParent->nsINode::GetFirstChild(); \
|
|
|
|
_node; _node = _node->GetNextSibling()) { \
|
|
|
|
if (_node->IsHTMLElement(nsGkAtoms::tr)) { \
|
|
|
|
do { \
|
|
|
|
_trCode \
|
|
|
|
} while (0); \
|
|
|
|
} else if (_node->IsHTMLElement(nsGkAtoms::tbody)) { \
|
|
|
|
rowGroup = static_cast<HTMLTableSectionElement*>(_node); \
|
|
|
|
rows = rowGroup->Rows(); \
|
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
/* TFoot */ \
|
|
|
|
for (nsIContent* _node = mParent->nsINode::GetFirstChild(); \
|
|
|
|
_node; _node = _node->GetNextSibling()) { \
|
|
|
|
if (_node->IsHTMLElement(nsGkAtoms::tfoot)) { \
|
|
|
|
rowGroup = static_cast<HTMLTableSectionElement*>(_node);\
|
|
|
|
rows = rowGroup->Rows(); \
|
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
} \
|
2005-08-15 02:34:21 +00:00
|
|
|
} \
|
|
|
|
} \
|
2016-05-17 07:08:00 +00:00
|
|
|
} while (0)
|
2005-08-15 02:34:21 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t
|
2006-04-21 01:44:58 +00:00
|
|
|
CountRowsInRowGroup(nsIDOMHTMLCollection* rows)
|
2004-04-14 04:26:00 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = 0;
|
2016-05-17 06:54:00 +00:00
|
|
|
|
2006-04-21 01:44:58 +00:00
|
|
|
if (rows) {
|
|
|
|
rows->GetLength(&length);
|
2004-04-14 04:26:00 +00:00
|
|
|
}
|
2016-05-17 06:54:00 +00:00
|
|
|
|
2004-04-14 04:26:00 +00:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
// we re-count every call. A better implementation would be to set
|
|
|
|
// ourselves up as an observer of contentAppended, contentInserted,
|
|
|
|
// and contentDeleted
|
2016-05-17 06:54:00 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
TableRowsCollection::GetLength(uint32_t* aLength)
|
1998-11-16 23:31:24 +00:00
|
|
|
{
|
|
|
|
*aLength=0;
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2016-05-17 07:08:00 +00:00
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2006-04-21 01:44:58 +00:00
|
|
|
*aLength += CountRowsInRowGroup(rows);
|
2016-05-17 07:08:00 +00:00
|
|
|
}, {
|
|
|
|
(*aLength)++;
|
|
|
|
});
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2011-04-25 17:46:51 +00:00
|
|
|
return NS_OK;
|
1998-11-16 23:31:24 +00:00
|
|
|
}
|
|
|
|
|
2008-10-22 14:31:14 +00:00
|
|
|
// Returns the item at index aIndex if available. If null is returned,
|
|
|
|
// then aCount will be set to the number of rows in this row collection.
|
|
|
|
// Otherwise, the value of aCount is undefined.
|
2012-11-14 22:10:08 +00:00
|
|
|
static Element*
|
2006-04-21 01:44:58 +00:00
|
|
|
GetItemOrCountInRowGroup(nsIDOMHTMLCollection* rows,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aIndex, uint32_t* aCount)
|
2004-04-14 04:26:00 +00:00
|
|
|
{
|
2008-10-22 14:31:14 +00:00
|
|
|
*aCount = 0;
|
2004-04-14 04:26:00 +00:00
|
|
|
|
2006-04-21 01:44:58 +00:00
|
|
|
if (rows) {
|
2008-10-22 14:31:14 +00:00
|
|
|
rows->GetLength(aCount);
|
|
|
|
if (aIndex < *aCount) {
|
2012-09-05 15:42:58 +00:00
|
|
|
nsIHTMLCollection* list = static_cast<nsIHTMLCollection*>(rows);
|
|
|
|
return list->GetElementAt(aIndex);
|
2004-04-14 04:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-17 06:54:00 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2004-04-14 04:26:00 +00:00
|
|
|
}
|
2005-08-15 02:34:21 +00:00
|
|
|
|
2012-11-14 22:10:08 +00:00
|
|
|
Element*
|
2012-09-05 15:42:58 +00:00
|
|
|
TableRowsCollection::GetElementAt(uint32_t aIndex)
|
1998-11-16 23:31:24 +00:00
|
|
|
{
|
2016-05-17 07:08:00 +00:00
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count;
|
2012-11-14 22:10:08 +00:00
|
|
|
Element* node = GetItemOrCountInRowGroup(rows, aIndex, &count);
|
2008-10-22 14:31:14 +00:00
|
|
|
if (node) {
|
2016-05-17 06:54:00 +00:00
|
|
|
return node;
|
1998-11-16 23:31:24 +00:00
|
|
|
}
|
1999-01-08 18:57:40 +00:00
|
|
|
|
2004-04-14 04:26:00 +00:00
|
|
|
NS_ASSERTION(count <= aIndex, "GetItemOrCountInRowGroup screwed up");
|
|
|
|
aIndex -= count;
|
2016-05-17 07:08:00 +00:00
|
|
|
},{
|
|
|
|
if (aIndex == 0) {
|
|
|
|
return _node->AsElement();
|
|
|
|
}
|
|
|
|
aIndex--;
|
|
|
|
});
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-10-22 14:31:14 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 06:54:00 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
TableRowsCollection::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2008-10-22 14:31:14 +00:00
|
|
|
{
|
2012-09-05 15:42:58 +00:00
|
|
|
nsISupports* node = GetElementAt(aIndex);
|
2008-10-22 14:31:14 +00:00
|
|
|
if (!node) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aReturn = nullptr;
|
2008-10-22 14:31:14 +00:00
|
|
|
|
2011-04-25 17:46:57 +00:00
|
|
|
return NS_OK;
|
2008-10-22 14:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
2005-08-15 02:34:21 +00:00
|
|
|
}
|
2004-04-14 04:26:00 +00:00
|
|
|
|
2013-11-11 07:55:41 +00:00
|
|
|
Element*
|
|
|
|
TableRowsCollection::GetFirstNamedElement(const nsAString& aName, bool& aFound)
|
2012-09-05 20:49:53 +00:00
|
|
|
{
|
2013-11-11 07:55:41 +00:00
|
|
|
aFound = false;
|
2016-05-17 07:08:00 +00:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
|
|
|
NS_ENSURE_TRUE(nameAtom, nullptr);
|
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2013-11-11 07:55:41 +00:00
|
|
|
Element* item = rows->NamedGetter(aName, aFound);
|
|
|
|
if (aFound) {
|
|
|
|
return item;
|
2012-09-05 20:49:53 +00:00
|
|
|
}
|
2016-05-17 07:08:00 +00:00
|
|
|
}, {
|
|
|
|
if (_node->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
nameAtom, eCaseMatters) ||
|
|
|
|
_node->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id,
|
|
|
|
nameAtom, eCaseMatters)) {
|
|
|
|
aFound = true;
|
|
|
|
return _node->AsElement();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-09-05 20:49:53 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:58:03 +00:00
|
|
|
void
|
2016-05-10 02:25:40 +00:00
|
|
|
TableRowsCollection::GetSupportedNames(nsTArray<nsString>& aNames)
|
2012-11-05 16:58:03 +00:00
|
|
|
{
|
2016-05-17 07:08:00 +00:00
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2012-11-05 16:58:03 +00:00
|
|
|
nsTArray<nsString> names;
|
|
|
|
nsCOMPtr<nsIHTMLCollection> coll = do_QueryInterface(rows);
|
|
|
|
if (coll) {
|
2016-05-10 02:25:40 +00:00
|
|
|
coll->GetSupportedNames(names);
|
2012-11-05 16:58:03 +00:00
|
|
|
for (uint32_t i = 0; i < names.Length(); ++i) {
|
|
|
|
if (!aNames.Contains(names[i])) {
|
|
|
|
aNames.AppendElement(names[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-17 07:08:00 +00:00
|
|
|
}, {
|
|
|
|
if (_node->HasID()) {
|
|
|
|
nsIAtom* idAtom = _node->GetID();
|
|
|
|
MOZ_ASSERT(idAtom != nsGkAtoms::_empty,
|
|
|
|
"Empty ids don't get atomized");
|
|
|
|
nsDependentAtomString idStr(idAtom);
|
|
|
|
if (!aNames.Contains(idStr)) {
|
|
|
|
aNames.AppendElement(idStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement* el = nsGenericHTMLElement::FromContent(_node);
|
|
|
|
if (el) {
|
|
|
|
const nsAttrValue* val = el->GetParsedAttr(nsGkAtoms::name);
|
|
|
|
if (val && val->Type() == nsAttrValue::eAtom) {
|
|
|
|
nsIAtom* nameAtom = val->GetAtomValue();
|
|
|
|
MOZ_ASSERT(nameAtom != nsGkAtoms::_empty,
|
|
|
|
"Empty names don't get atomized");
|
|
|
|
nsDependentAtomString nameStr(nameAtom);
|
|
|
|
if (!aNames.Contains(nameStr)) {
|
|
|
|
aNames.AppendElement(nameStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-11-05 16:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 06:54:00 +00:00
|
|
|
NS_IMETHODIMP
|
2008-10-31 21:40:35 +00:00
|
|
|
TableRowsCollection::NamedItem(const nsAString& aName,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
2016-05-17 07:08:00 +00:00
|
|
|
bool found;
|
|
|
|
nsISupports* node = GetFirstNamedElement(aName, found);
|
|
|
|
if (!node) {
|
|
|
|
*aReturn = nullptr;
|
2008-10-31 21:40:35 +00:00
|
|
|
|
2016-05-17 07:08:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
1998-11-16 23:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TableRowsCollection::ParentDestroyed()
|
|
|
|
{
|
|
|
|
// see comment in destructor, do NOT release mParent!
|
2012-07-30 14:20:58 +00:00
|
|
|
mParent = nullptr;
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1998-11-16 23:31:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
/* --------------------------- HTMLTableElement ---------------------------- */
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
HTMLTableElement::HTMLTableElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2011-08-20 10:18:50 +00:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
|
|
|
mTableInheritedAttributes(TABLE_ATTRS_DIRTY)
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2013-12-17 13:58:32 +00:00
|
|
|
SetHasWeirdParserInsertionMode();
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::~HTMLTableElement()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2000-12-23 10:56:31 +00:00
|
|
|
if (mRows) {
|
1998-11-16 23:31:24 +00:00
|
|
|
mRows->ParentDestroyed();
|
|
|
|
}
|
2011-08-20 10:18:50 +00:00
|
|
|
ReleaseInheritedAttributes();
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00: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 14:13:33 +00:00
|
|
|
HTMLTableElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
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 14:13:33 +00:00
|
|
|
return HTMLTableElementBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-29 08:08:15 +00:00
|
|
|
}
|
1998-09-02 00:56:01 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableElement)
|
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTableElement, nsGenericHTMLElement)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTBodies)
|
2012-01-07 23:37:43 +00:00
|
|
|
if (tmp->mRows) {
|
|
|
|
tmp->mRows->ParentDestroyed();
|
|
|
|
}
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRows)
|
2012-01-07 23:37:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-12-28 02:45:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableElement,
|
2007-03-08 11:17:16 +00:00
|
|
|
nsGenericHTMLElement)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTBodies)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTableElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTableElement, Element)
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
// QueryInterface implementation for HTMLTableElement
|
2015-04-25 14:23:54 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTableElement)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
1998-09-02 00:56:01 +00:00
|
|
|
|
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableElement)
|
1998-09-02 00:56:01 +00:00
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1998-09-15 17:58:24 +00:00
|
|
|
// the DOM spec says border, cellpadding, cellSpacing are all "wstring"
|
2000-12-23 10:56:31 +00:00
|
|
|
// in fact, they are integers or they are meaningless. so we store them
|
|
|
|
// here as ints.
|
1998-09-15 17:58:24 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
nsIHTMLCollection*
|
|
|
|
HTMLTableElement::Rows()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2000-12-23 10:56:31 +00:00
|
|
|
if (!mRows) {
|
1998-11-16 23:31:24 +00:00
|
|
|
mRows = new TableRowsCollection(this);
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
return mRows;
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
nsIHTMLCollection*
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::TBodies()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2000-12-23 10:56:31 +00:00
|
|
|
if (!mTBodies) {
|
2004-04-14 04:26:00 +00:00
|
|
|
// Not using NS_GetContentList because this should not be cached
|
2006-07-02 07:23:10 +00:00
|
|
|
mTBodies = new nsContentList(this,
|
2011-11-16 07:50:19 +00:00
|
|
|
kNameSpaceID_XHTML,
|
2010-09-01 02:47:00 +00:00
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tbody,
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
1998-11-16 23:31:24 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2011-04-25 17:46:51 +00:00
|
|
|
return mTBodies;
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTHead()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> head = GetTHead();
|
2012-12-29 08:08:15 +00:00
|
|
|
if (!head) {
|
|
|
|
// Create a new head rowgroup.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 08:08:15 +00:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::thead,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
head = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!head) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
ErrorResult rv;
|
2016-10-14 12:33:42 +00:00
|
|
|
nsCOMPtr<nsINode> refNode = nsINode::GetFirstChild();
|
|
|
|
nsINode::InsertBefore(*head, refNode, rv);
|
2011-11-16 07:50:19 +00:00
|
|
|
}
|
2012-12-29 08:08:15 +00:00
|
|
|
return head.forget();
|
|
|
|
}
|
2002-12-17 13:29:39 +00:00
|
|
|
|
2013-08-01 22:24:21 +00:00
|
|
|
void
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::DeleteTHead()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableSectionElement* tHead = GetTHead();
|
|
|
|
if (tHead) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tHead, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-18 06:06:37 +00:00
|
|
|
}
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTFoot()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> foot = GetTFoot();
|
2012-12-29 08:08:15 +00:00
|
|
|
if (!foot) {
|
|
|
|
// create a new foot rowgroup
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 08:08:15 +00:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tfoot,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
foot = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!foot) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
AppendChildTo(foot, true);
|
1998-11-17 23:09:59 +00:00
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
return foot.forget();
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-08-01 22:24:21 +00:00
|
|
|
void
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::DeleteTFoot()
|
1998-11-18 06:06:37 +00:00
|
|
|
{
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableSectionElement* tFoot = GetTFoot();
|
|
|
|
if (tFoot) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tFoot, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-18 06:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateCaption()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> caption = GetCaption();
|
2012-12-29 08:08:15 +00:00
|
|
|
if (!caption) {
|
|
|
|
// Create a new caption.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 08:08:15 +00:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::caption,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
caption = NS_NewHTMLTableCaptionElement(nodeInfo.forget());
|
|
|
|
if (!caption) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-16 07:50:19 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
AppendChildTo(caption, true);
|
1998-11-17 23:09:59 +00:00
|
|
|
}
|
2012-12-29 08:08:15 +00:00
|
|
|
return caption.forget();
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-08-01 22:24:21 +00:00
|
|
|
void
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::DeleteCaption()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableCaptionElement* caption = GetCaption();
|
|
|
|
if (caption) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*caption, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-16 23:31:24 +00:00
|
|
|
}
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 05:04:30 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTBody()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo =
|
2012-12-04 05:04:30 +00:00
|
|
|
OwnerDoc()->NodeInfoManager()->GetNodeInfo(nsGkAtoms::tbody, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
MOZ_ASSERT(nodeInfo);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> newBody =
|
2012-12-04 05:04:30 +00:00
|
|
|
NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
MOZ_ASSERT(newBody);
|
|
|
|
|
2016-10-14 12:33:42 +00:00
|
|
|
nsCOMPtr<nsIContent> referenceNode = nullptr;
|
2012-12-04 05:04:30 +00:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
|
|
|
child;
|
|
|
|
child = child->GetPreviousSibling()) {
|
2015-03-03 11:08:59 +00:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::tbody)) {
|
2012-12-04 05:04:30 +00:00
|
|
|
referenceNode = child->GetNextSibling();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
nsINode::InsertBefore(*newBody, referenceNode, rv);
|
|
|
|
|
|
|
|
return newBody.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::InsertRow(int32_t aIndex, ErrorResult& aError)
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
1998-12-09 23:30:06 +00:00
|
|
|
/* get the ref row at aIndex
|
2013-08-01 22:24:21 +00:00
|
|
|
if there is one,
|
2009-01-23 09:02:09 +00:00
|
|
|
get its parent
|
1998-12-09 23:30:06 +00:00
|
|
|
insert the new row just before the ref row
|
1998-11-18 06:06:37 +00:00
|
|
|
else
|
|
|
|
get the first row group
|
|
|
|
insert the new row as its first child
|
|
|
|
*/
|
2002-12-17 13:29:39 +00:00
|
|
|
if (aIndex < -1) {
|
2012-12-29 08:08:15 +00:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-01-03 06:49:10 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
|
|
|
uint32_t rowCount = rows->Length();
|
2012-08-22 15:56:38 +00:00
|
|
|
if ((uint32_t)aIndex > rowCount && aIndex != -1) {
|
2012-12-29 08:08:15 +00:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-01-03 06:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// use local variable refIndex so we can remember original aIndex
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t refIndex = (uint32_t)aIndex;
|
2002-01-03 06:49:10 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> newRow;
|
2002-01-03 06:49:10 +00:00
|
|
|
if (rowCount > 0) {
|
2002-12-17 13:29:39 +00:00
|
|
|
if (refIndex == rowCount || aIndex == -1) {
|
2000-12-23 10:56:31 +00:00
|
|
|
// we set refIndex to the last row so we can get the last row's
|
|
|
|
// parent we then do an AppendChild below if (rowCount<aIndex)
|
|
|
|
|
2002-01-03 06:49:10 +00:00
|
|
|
refIndex = rowCount - 1;
|
2000-12-23 10:56:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 00:23:43 +00:00
|
|
|
RefPtr<Element> refRow = rows->Item(refIndex);
|
|
|
|
nsCOMPtr<nsINode> parent = refRow->GetParentNode();
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1998-11-18 06:06:37 +00:00
|
|
|
// create the row
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2006-12-26 17:47:52 +00:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
2004-06-25 12:26:02 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2004-06-06 02:38:32 +00:00
|
|
|
if (newRow) {
|
2012-12-29 08:08:15 +00:00
|
|
|
// If aIndex is -1 or equal to the number of rows, the new row
|
2003-01-11 21:33:00 +00:00
|
|
|
// is appended.
|
2012-08-22 15:56:38 +00:00
|
|
|
if (aIndex == -1 || uint32_t(aIndex) == rowCount) {
|
2012-12-29 08:08:15 +00:00
|
|
|
parent->AppendChild(*newRow, aError);
|
|
|
|
} else {
|
2000-12-23 10:56:31 +00:00
|
|
|
// insert the new row before the reference row we found above
|
2012-12-29 08:08:15 +00:00
|
|
|
parent->InsertBefore(*newRow, refRow, aError);
|
2000-12-23 10:56:31 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
2000-12-23 10:56:31 +00:00
|
|
|
}
|
1998-11-18 06:06:37 +00:00
|
|
|
}
|
2011-11-16 07:50:19 +00:00
|
|
|
} else {
|
2016-05-17 06:54:00 +00:00
|
|
|
// the row count was 0, so
|
2014-05-02 01:29:23 +00:00
|
|
|
// find the last row group and insert there as first child
|
2012-12-29 08:08:15 +00:00
|
|
|
nsCOMPtr<nsIContent> rowGroup;
|
2014-05-02 01:29:23 +00:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
2011-09-27 07:54:58 +00:00
|
|
|
child;
|
2014-05-02 01:29:23 +00:00
|
|
|
child = child->GetPreviousSibling()) {
|
2015-03-03 11:08:59 +00:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::tbody)) {
|
2012-12-29 08:08:15 +00:00
|
|
|
rowGroup = child;
|
2004-04-14 04:26:00 +00:00
|
|
|
break;
|
1998-11-18 06:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
|
|
|
if (!rowGroup) { // need to create a TBODY
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2006-12-26 17:47:52 +00:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tbody,
|
2004-06-25 12:26:02 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
rowGroup = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (rowGroup) {
|
|
|
|
aError = AppendChildTo(rowGroup, true);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
1998-11-18 06:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
|
|
|
if (rowGroup) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2006-12-26 17:47:52 +00:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
2004-06-25 12:26:02 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2004-04-14 04:26:00 +00:00
|
|
|
if (newRow) {
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableSectionElement* section =
|
|
|
|
static_cast<HTMLTableSectionElement*>(rowGroup.get());
|
2012-12-29 14:07:48 +00:00
|
|
|
nsIHTMLCollection* rows = section->Rows();
|
2016-10-14 12:33:42 +00:00
|
|
|
nsCOMPtr<nsINode> refNode = rows->Item(0);
|
|
|
|
rowGroup->InsertBefore(*newRow, refNode, aError);
|
1998-11-18 06:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
return newRow.forget();
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
void
|
|
|
|
HTMLTableElement::DeleteRow(int32_t aIndex, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
if (aIndex < -1) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t refIndex;
|
2012-12-29 08:08:15 +00:00
|
|
|
if (aIndex == -1) {
|
|
|
|
refIndex = rows->Length();
|
2002-12-17 13:29:39 +00:00
|
|
|
if (refIndex == 0) {
|
2012-12-29 08:08:15 +00:00
|
|
|
return;
|
2002-12-17 13:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
2012-12-29 08:08:15 +00:00
|
|
|
} else {
|
|
|
|
refIndex = (uint32_t)aIndex;
|
2002-12-17 13:29:39 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
nsCOMPtr<nsIContent> row = rows->Item(refIndex);
|
2001-12-11 10:20:57 +00:00
|
|
|
if (!row) {
|
2012-12-29 08:08:15 +00:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2001-12-11 10:20:57 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
row->RemoveFromParent();
|
|
|
|
}
|
2001-12-11 10:20:57 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
1998-09-15 17:58:24 +00:00
|
|
|
/* ignore summary, just a string */
|
2005-11-29 16:37:15 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::cellspacing ||
|
2013-02-07 08:08:57 +00:00
|
|
|
aAttribute == nsGkAtoms::cellpadding ||
|
|
|
|
aAttribute == nsGkAtoms::border) {
|
2012-02-21 09:34:01 +00:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::height) {
|
2011-02-04 19:46:16 +00:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::width) {
|
2011-02-04 19:46:16 +00:00
|
|
|
if (aResult.ParseSpecialIntValue(aValue)) {
|
2005-11-29 16:37:15 +00:00
|
|
|
// treat 0 width as auto
|
|
|
|
nsAttrValue::ValueType type = aResult.Type();
|
2011-07-11 10:56:00 +00:00
|
|
|
return !((type == nsAttrValue::eInteger &&
|
|
|
|
aResult.GetIntegerValue() == 0) ||
|
|
|
|
(type == nsAttrValue::ePercent &&
|
|
|
|
aResult.GetPercentValue() == 0.0f));
|
2001-08-22 04:21:05 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
2016-05-17 06:54:00 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2005-11-29 16:37:15 +00:00
|
|
|
return ParseTableHAlignValue(aValue, aResult);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor ||
|
|
|
|
aAttribute == nsGkAtoms::bordercolor) {
|
2010-07-17 08:09:14 +00:00
|
|
|
return aResult.ParseColor(aValue);
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::hspace ||
|
|
|
|
aAttribute == nsGkAtoms::vspace) {
|
2005-11-29 16:37:15 +00:00
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
1999-07-24 19:55:35 +00:00
|
|
|
}
|
2000-06-14 00:59:29 +00:00
|
|
|
}
|
1998-09-15 17:58:24 +00:00
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(aNamespaceID,
|
|
|
|
aAttribute, aValue,
|
|
|
|
aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2005-11-29 16:37:15 +00:00
|
|
|
aResult);
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2005-09-23 05:02:42 +00:00
|
|
|
|
1998-09-15 17:58:24 +00:00
|
|
|
|
2013-11-19 19:21:29 +00:00
|
|
|
void
|
|
|
|
HTMLTableElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2003-07-11 21:16:12 +00:00
|
|
|
// XXX Bug 211636: This function is used by a single style rule
|
|
|
|
// that's used to match two different type of elements -- tables, and
|
|
|
|
// table cells. (nsHTMLTableCellElement overrides
|
|
|
|
// WalkContentStyleRules so that this happens.) This violates the
|
|
|
|
// nsIStyleRule contract, since it's the same style rule object doing
|
|
|
|
// the mapping in two different ways. It's also incorrect since it's
|
|
|
|
// testing the display type of the style context rather than checking
|
|
|
|
// which *element* it's matching (style rules should not stop matching
|
|
|
|
// when the display type is changed).
|
|
|
|
|
2007-11-16 03:46:42 +00:00
|
|
|
nsPresContext* presContext = aData->mPresContext;
|
|
|
|
nsCompatibility mode = presContext->CompatibilityMode();
|
2001-10-25 00:24:08 +00:00
|
|
|
|
2007-10-08 21:58:22 +00:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TableBorder)) {
|
2011-08-20 10:18:50 +00:00
|
|
|
// cellspacing
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellspacing);
|
|
|
|
nsCSSValue* borderSpacing = aData->ValueForBorderSpacing();
|
2012-02-21 09:34:01 +00:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger &&
|
|
|
|
borderSpacing->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderSpacing->
|
|
|
|
SetFloatValue(float(value->GetIntegerValue()), eCSSUnit_Pixel);
|
1998-09-15 17:58:24 +00:00
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
}
|
2007-10-08 21:58:22 +00:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Margin)) {
|
2011-08-20 10:18:50 +00:00
|
|
|
// align; Check for enumerated type (it may be another type if
|
|
|
|
// illegal)
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
|
|
|
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum) {
|
|
|
|
if (value->GetEnumValue() == NS_STYLE_TEXT_ALIGN_CENTER ||
|
|
|
|
value->GetEnumValue() == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) {
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeft();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetAutoValue();
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRight();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetAutoValue();
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
2011-08-20 10:18:50 +00:00
|
|
|
}
|
1999-05-26 23:48:19 +00:00
|
|
|
|
2011-08-20 10:18:50 +00:00
|
|
|
// hspace is mapped into left and right margin,
|
|
|
|
// vspace is mapped into top and bottom margins
|
|
|
|
// - *** Quirks Mode only ***
|
|
|
|
if (eCompatibility_NavQuirks == mode) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::hspace);
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2011-08-20 10:18:50 +00:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeft();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
2016-05-17 06:54:00 +00:00
|
|
|
marginLeft->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRight();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
1999-05-26 23:48:19 +00:00
|
|
|
}
|
2011-08-20 10:18:50 +00:00
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vspace);
|
|
|
|
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
nsCSSValue* marginTop = aData->ValueForMarginTop();
|
|
|
|
if (marginTop->GetUnit() == eCSSUnit_Null)
|
2016-05-17 06:54:00 +00:00
|
|
|
marginTop->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2011-08-20 10:18:50 +00:00
|
|
|
nsCSSValue* marginBottom = aData->ValueForMarginBottom();
|
|
|
|
if (marginBottom->GetUnit() == eCSSUnit_Null)
|
2016-05-17 06:54:00 +00:00
|
|
|
marginBottom->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2000-02-12 00:58:38 +00:00
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-08 21:58:22 +00:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
|
2011-08-20 10:18:50 +00:00
|
|
|
// width: value
|
|
|
|
nsCSSValue* width = aData->ValueForWidth();
|
|
|
|
if (width->GetUnit() == eCSSUnit_Null) {
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger)
|
|
|
|
width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
|
|
|
else if (value && value->Type() == nsAttrValue::ePercent)
|
|
|
|
width->SetPercentValue(value->GetPercentValue());
|
|
|
|
}
|
1998-09-15 17:58:24 +00:00
|
|
|
|
2011-08-20 10:18:50 +00:00
|
|
|
// height: value
|
|
|
|
nsCSSValue* height = aData->ValueForHeight();
|
|
|
|
if (height->GetUnit() == eCSSUnit_Null) {
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger)
|
|
|
|
height->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
|
|
|
else if (value && value->Type() == nsAttrValue::ePercent)
|
|
|
|
height->SetPercentValue(value->GetPercentValue());
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-08 21:58:22 +00:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
|
2011-08-20 10:18:50 +00:00
|
|
|
// bordercolor
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bordercolor);
|
|
|
|
nscolor color;
|
|
|
|
if (value && presContext->UseDocumentColors() &&
|
|
|
|
value->GetColorValue(color)) {
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* borderLeftColor = aData->ValueForBorderLeftColor();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (borderLeftColor->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderLeftColor->SetColorValue(color);
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* borderRightColor = aData->ValueForBorderRightColor();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (borderRightColor->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderRightColor->SetColorValue(color);
|
|
|
|
nsCSSValue* borderTopColor = aData->ValueForBorderTopColor();
|
|
|
|
if (borderTopColor->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderTopColor->SetColorValue(color);
|
|
|
|
nsCSSValue* borderBottomColor = aData->ValueForBorderBottomColor();
|
|
|
|
if (borderBottomColor->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderBottomColor->SetColorValue(color);
|
|
|
|
}
|
2000-06-14 00:59:29 +00:00
|
|
|
|
2011-08-20 10:18:50 +00:00
|
|
|
// border
|
|
|
|
const nsAttrValue* borderValue = aAttributes->GetAttr(nsGkAtoms::border);
|
|
|
|
if (borderValue) {
|
|
|
|
// border = 1 pixel default
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t borderThickness = 1;
|
2011-08-20 10:18:50 +00:00
|
|
|
|
|
|
|
if (borderValue->Type() == nsAttrValue::eInteger)
|
|
|
|
borderThickness = borderValue->GetIntegerValue();
|
|
|
|
|
|
|
|
// by default, set all border sides to the specified width
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* borderLeftWidth = aData->ValueForBorderLeftWidth();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (borderLeftWidth->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderLeftWidth->SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* borderRightWidth = aData->ValueForBorderRightWidth();
|
2011-08-20 10:18:50 +00:00
|
|
|
if (borderRightWidth->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderRightWidth->SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* borderTopWidth = aData->ValueForBorderTopWidth();
|
|
|
|
if (borderTopWidth->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderTopWidth->SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* borderBottomWidth = aData->ValueForBorderBottomWidth();
|
|
|
|
if (borderBottomWidth->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderBottomWidth->SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
|
1999-07-07 01:24:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-20 10:18:50 +00:00
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
1999-07-07 01:24:40 +00:00
|
|
|
}
|
1998-11-11 19:56:02 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
1999-07-07 01:24:40 +00:00
|
|
|
{
|
2004-02-25 21:04:50 +00:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2006-12-26 17:47:52 +00:00
|
|
|
{ &nsGkAtoms::cellpadding },
|
|
|
|
{ &nsGkAtoms::cellspacing },
|
|
|
|
{ &nsGkAtoms::border },
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
|
|
|
{ &nsGkAtoms::hspace },
|
|
|
|
{ &nsGkAtoms::vspace },
|
2016-05-17 06:54:00 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
{ &nsGkAtoms::bordercolor },
|
2016-05-17 06:54:00 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
{ &nsGkAtoms::align },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2003-04-16 20:54:20 +00:00
|
|
|
};
|
|
|
|
|
2004-02-25 21:04:50 +00:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-16 20:54:20 +00:00
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1998-09-05 04:00:06 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::GetAttributeMappingFunction() const
|
1998-09-05 04:00:06 +00:00
|
|
|
{
|
2005-01-12 19:45:38 +00:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
2011-08-20 10:18:50 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
MapInheritedTableAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
|
|
|
{
|
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Padding)) {
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellpadding);
|
2012-02-21 09:34:01 +00:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
// We have cellpadding. This will override our padding values if we
|
|
|
|
// don't have any set.
|
|
|
|
nsCSSValue padVal(float(value->GetIntegerValue()), eCSSUnit_Pixel);
|
|
|
|
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* paddingLeft = aData->ValueForPaddingLeft();
|
2012-02-21 09:34:01 +00:00
|
|
|
if (paddingLeft->GetUnit() == eCSSUnit_Null) {
|
|
|
|
*paddingLeft = padVal;
|
|
|
|
}
|
|
|
|
|
2015-01-17 04:16:02 +00:00
|
|
|
nsCSSValue* paddingRight = aData->ValueForPaddingRight();
|
2012-02-21 09:34:01 +00:00
|
|
|
if (paddingRight->GetUnit() == eCSSUnit_Null) {
|
|
|
|
*paddingRight = padVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue* paddingTop = aData->ValueForPaddingTop();
|
|
|
|
if (paddingTop->GetUnit() == eCSSUnit_Null) {
|
|
|
|
*paddingTop = padVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue* paddingBottom = aData->ValueForPaddingBottom();
|
|
|
|
if (paddingBottom->GetUnit() == eCSSUnit_Null) {
|
|
|
|
*paddingBottom = padVal;
|
2011-08-20 10:18:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMappedAttributes*
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::GetAttributesMappedForCell()
|
2011-08-20 10:18:50 +00:00
|
|
|
{
|
|
|
|
if (mTableInheritedAttributes) {
|
|
|
|
if (mTableInheritedAttributes == TABLE_ATTRS_DIRTY)
|
|
|
|
BuildInheritedAttributes();
|
|
|
|
if (mTableInheritedAttributes != TABLE_ATTRS_DIRTY)
|
|
|
|
return mTableInheritedAttributes;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-08-20 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::BuildInheritedAttributes()
|
2011-08-20 10:18:50 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mTableInheritedAttributes == TABLE_ATTRS_DIRTY,
|
|
|
|
"potential leak, plus waste of work");
|
2014-10-02 19:07:24 +00:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2011-08-20 10:18:50 +00:00
|
|
|
nsHTMLStyleSheet* sheet = document ?
|
2012-07-30 14:20:58 +00:00
|
|
|
document->GetAttributeStyleSheet() : nullptr;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsMappedAttributes> newAttrs;
|
2011-08-20 10:18:50 +00:00
|
|
|
if (sheet) {
|
|
|
|
const nsAttrValue* value = mAttrsAndChildren.GetAttr(nsGkAtoms::cellpadding);
|
|
|
|
if (value) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsMappedAttributes> modifiableMapped = new
|
2011-08-20 10:18:50 +00:00
|
|
|
nsMappedAttributes(sheet, MapInheritedTableAttributesIntoRule);
|
|
|
|
|
|
|
|
if (modifiableMapped) {
|
|
|
|
nsAttrValue val(*value);
|
|
|
|
modifiableMapped->SetAndTakeAttr(nsGkAtoms::cellpadding, val);
|
|
|
|
}
|
|
|
|
newAttrs = sheet->UniqueMappedAttributes(modifiableMapped);
|
|
|
|
NS_ASSERTION(newAttrs, "out of memory, but handling gracefully");
|
|
|
|
|
|
|
|
if (newAttrs != modifiableMapped) {
|
|
|
|
// Reset the stylesheet of modifiableMapped so that it doesn't
|
|
|
|
// spend time trying to remove itself from the hash. There is no
|
|
|
|
// risk that modifiableMapped is in the hash since we created
|
|
|
|
// it ourselves and it didn't come from the stylesheet (in which
|
|
|
|
// case it would not have been modifiable).
|
|
|
|
modifiableMapped->DropStyleSheetReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mTableInheritedAttributes = newAttrs;
|
|
|
|
NS_IF_ADDREF(mTableInheritedAttributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:33:16 +00:00
|
|
|
void
|
|
|
|
HTMLTableElement::ReleaseInheritedAttributes()
|
|
|
|
{
|
|
|
|
if (mTableInheritedAttributes &&
|
|
|
|
mTableInheritedAttributes != TABLE_ATTRS_DIRTY)
|
|
|
|
NS_RELEASE(mTableInheritedAttributes);
|
|
|
|
mTableInheritedAttributes = TABLE_ATTRS_DIRTY;
|
|
|
|
}
|
|
|
|
|
2011-08-20 10:18:50 +00:00
|
|
|
nsresult
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2011-08-20 10:18:50 +00:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
return nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2011-08-20 10:18:50 +00:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2015-08-01 05:14:06 +00:00
|
|
|
nsAttrValueOrString* aValue,
|
2012-12-28 02:45:57 +00:00
|
|
|
bool aNotify)
|
2011-08-20 10:18:50 +00:00
|
|
|
{
|
2011-08-28 10:59:34 +00:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
2011-08-20 10:18:50 +00:00
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
}
|
2011-08-28 10:59:34 +00:00
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-28 02:45:57 +00:00
|
|
|
HTMLTableElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
bool aNotify)
|
2011-08-20 10:18:50 +00:00
|
|
|
{
|
2011-08-28 10:59:34 +00:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
BuildInheritedAttributes();
|
2011-08-20 10:18:50 +00:00
|
|
|
}
|
2011-08-28 10:59:34 +00:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 10:18:50 +00:00
|
|
|
}
|
2012-12-28 02:45:57 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|