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/HTMLTableElement.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2011-08-20 14:18:50 +04:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2013-02-14 19:33:16 +04:00
|
|
|
#include "nsMappedAttributes.h"
|
2012-12-29 12:08:15 +04:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLTableElementBinding.h"
|
2013-02-01 03:11:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-04-16 06:58:44 +04:00
|
|
|
#include "jsfriendapi.h"
|
1998-11-17 02:31:24 +03:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Table)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-10-11 09:50:08 +04:00
|
|
|
|
1998-11-17 02:31:24 +03: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 21:35:18 +03:00
|
|
|
class TableRowsCollection final : public nsIHTMLCollection,
|
|
|
|
public nsWrapperCache
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit TableRowsCollection(HTMLTableElement* aParent);
|
1998-11-17 02:31:24 +03:00
|
|
|
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
1998-11-17 02:31:24 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual Element* GetElementAt(uint32_t aIndex) override;
|
|
|
|
virtual nsINode* GetParentObject() override
|
2011-06-01 01:47:59 +04:00
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-11-11 11:55:41 +04:00
|
|
|
virtual Element*
|
2015-03-21 19:28:04 +03:00
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override;
|
2016-05-10 05:25:40 +03:00
|
|
|
virtual void GetSupportedNames(nsTArray<nsString>& aNames) override;
|
2012-09-06 00:49:53 +04:00
|
|
|
|
1998-11-17 02:31:24 +03:00
|
|
|
NS_IMETHOD ParentDestroyed();
|
|
|
|
|
2011-06-01 01:47:17 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TableRowsCollection)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
2013-11-12 19:22:22 +04:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-12 19:22:22 +04:00
|
|
|
protected:
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~TableRowsCollection();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
2011-06-01 01:47:17 +04:00
|
|
|
{
|
2013-11-12 19:22:22 +04:00
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
2011-06-01 01:47:17 +04:00
|
|
|
}
|
2007-03-08 14:17:16 +03:00
|
|
|
|
2006-04-21 05:44:58 +04:00
|
|
|
// Those rows that are not in table sections
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement* mParent;
|
1998-11-17 02:31:24 +03:00
|
|
|
};
|
|
|
|
|
1999-10-07 04:35:04 +04:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
TableRowsCollection::TableRowsCollection(HTMLTableElement *aParent)
|
2007-03-08 14:17:16 +03:00
|
|
|
: mParent(aParent)
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TableRowsCollection::~TableRowsCollection()
|
|
|
|
{
|
2000-12-23 13:56:31 +03: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-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
2013-11-12 19:22:22 +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
|
|
|
TableRowsCollection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-11-12 19:22:22 +04: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 17:13:33 +03:00
|
|
|
return HTMLCollectionBinding::Wrap(aCx, this, aGivenProto);
|
2013-11-12 19:22:22 +04:00
|
|
|
}
|
|
|
|
|
2016-05-17 10:08:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(TableRowsCollection)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TableRowsCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TableRowsCollection)
|
|
|
|
|
2007-08-21 02:55:06 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD(TableRowsCollection)
|
2014-08-26 03:21:35 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE(TableRowsCollection, nsIHTMLCollection,
|
|
|
|
nsIDOMHTMLCollection)
|
2007-08-21 02:55:06 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(TableRowsCollection)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2005-08-15 06:34:21 +04: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 10:08:00 +03: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 05:44:58 +04:00
|
|
|
// |rv| is in scope.
|
2016-05-17 10:08:00 +03: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 06:34:21 +04:00
|
|
|
} \
|
|
|
|
} \
|
2016-05-17 10:08:00 +03:00
|
|
|
} while (0)
|
2005-08-15 06:34:21 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t
|
2006-04-21 05:44:58 +04:00
|
|
|
CountRowsInRowGroup(nsIDOMHTMLCollection* rows)
|
2004-04-14 08:26:00 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = 0;
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2006-04-21 05:44:58 +04:00
|
|
|
if (rows) {
|
|
|
|
rows->GetLength(&length);
|
2004-04-14 08:26:00 +04:00
|
|
|
}
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2004-04-14 08:26:00 +04:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2000-12-23 13:56:31 +03: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 09:54:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
TableRowsCollection::GetLength(uint32_t* aLength)
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
|
|
|
*aLength=0;
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2016-05-17 10:08:00 +03:00
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2006-04-21 05:44:58 +04:00
|
|
|
*aLength += CountRowsInRowGroup(rows);
|
2016-05-17 10:08:00 +03:00
|
|
|
}, {
|
|
|
|
(*aLength)++;
|
|
|
|
});
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2011-04-25 21:46:51 +04:00
|
|
|
return NS_OK;
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
2008-10-22 18:31:14 +04: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-15 02:10:08 +04:00
|
|
|
static Element*
|
2006-04-21 05:44:58 +04:00
|
|
|
GetItemOrCountInRowGroup(nsIDOMHTMLCollection* rows,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aIndex, uint32_t* aCount)
|
2004-04-14 08:26:00 +04:00
|
|
|
{
|
2008-10-22 18:31:14 +04:00
|
|
|
*aCount = 0;
|
2004-04-14 08:26:00 +04:00
|
|
|
|
2006-04-21 05:44:58 +04:00
|
|
|
if (rows) {
|
2008-10-22 18:31:14 +04:00
|
|
|
rows->GetLength(aCount);
|
|
|
|
if (aIndex < *aCount) {
|
2012-09-05 19:42:58 +04:00
|
|
|
nsIHTMLCollection* list = static_cast<nsIHTMLCollection*>(rows);
|
|
|
|
return list->GetElementAt(aIndex);
|
2004-04-14 08:26:00 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-04-14 08:26:00 +04:00
|
|
|
}
|
2005-08-15 06:34:21 +04:00
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
Element*
|
2012-09-05 19:42:58 +04:00
|
|
|
TableRowsCollection::GetElementAt(uint32_t aIndex)
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
2016-05-17 10:08:00 +03:00
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count;
|
2012-11-15 02:10:08 +04:00
|
|
|
Element* node = GetItemOrCountInRowGroup(rows, aIndex, &count);
|
2008-10-22 18:31:14 +04:00
|
|
|
if (node) {
|
2016-05-17 09:54:00 +03:00
|
|
|
return node;
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
1999-01-08 21:57:40 +03:00
|
|
|
|
2004-04-14 08:26:00 +04:00
|
|
|
NS_ASSERTION(count <= aIndex, "GetItemOrCountInRowGroup screwed up");
|
|
|
|
aIndex -= count;
|
2016-05-17 10:08:00 +03:00
|
|
|
},{
|
|
|
|
if (aIndex == 0) {
|
|
|
|
return _node->AsElement();
|
|
|
|
}
|
|
|
|
aIndex--;
|
|
|
|
});
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2016-05-17 09:54:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
TableRowsCollection::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2012-09-05 19:42:58 +04:00
|
|
|
nsISupports* node = GetElementAt(aIndex);
|
2008-10-22 18:31:14 +04:00
|
|
|
if (!node) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2011-04-25 21:46:57 +04:00
|
|
|
return NS_OK;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
2005-08-15 06:34:21 +04:00
|
|
|
}
|
2004-04-14 08:26:00 +04:00
|
|
|
|
2013-11-11 11:55:41 +04:00
|
|
|
Element*
|
|
|
|
TableRowsCollection::GetFirstNamedElement(const nsAString& aName, bool& aFound)
|
2012-09-06 00:49:53 +04:00
|
|
|
{
|
2013-11-11 11:55:41 +04:00
|
|
|
aFound = false;
|
2016-05-17 10:08:00 +03:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
|
|
|
NS_ENSURE_TRUE(nameAtom, nullptr);
|
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2013-11-11 11:55:41 +04:00
|
|
|
Element* item = rows->NamedGetter(aName, aFound);
|
|
|
|
if (aFound) {
|
|
|
|
return item;
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
2016-05-17 10:08:00 +03: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-06 00:49:53 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-05 20:58:03 +04:00
|
|
|
void
|
2016-05-10 05:25:40 +03:00
|
|
|
TableRowsCollection::GetSupportedNames(nsTArray<nsString>& aNames)
|
2012-11-05 20:58:03 +04:00
|
|
|
{
|
2016-05-17 10:08:00 +03:00
|
|
|
DO_FOR_EACH_BY_ORDER({
|
2012-11-05 20:58:03 +04:00
|
|
|
nsTArray<nsString> names;
|
|
|
|
nsCOMPtr<nsIHTMLCollection> coll = do_QueryInterface(rows);
|
|
|
|
if (coll) {
|
2016-05-10 05:25:40 +03:00
|
|
|
coll->GetSupportedNames(names);
|
2012-11-05 20:58:03 +04:00
|
|
|
for (uint32_t i = 0; i < names.Length(); ++i) {
|
|
|
|
if (!aNames.Contains(names[i])) {
|
|
|
|
aNames.AppendElement(names[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-17 10:08:00 +03: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 20:58:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 09:54:00 +03:00
|
|
|
NS_IMETHODIMP
|
2008-11-01 00:40:35 +03:00
|
|
|
TableRowsCollection::NamedItem(const nsAString& aName,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
2016-05-17 10:08:00 +03:00
|
|
|
bool found;
|
|
|
|
nsISupports* node = GetFirstNamedElement(aName, found);
|
|
|
|
if (!node) {
|
|
|
|
*aReturn = nullptr;
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2016-05-17 10:08:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TableRowsCollection::ParentDestroyed()
|
|
|
|
{
|
|
|
|
// see comment in destructor, do NOT release mParent!
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-11-17 02:31:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
/* --------------------------- HTMLTableElement ---------------------------- */
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLTableElement::HTMLTableElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2011-08-20 14:18:50 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
|
|
|
mTableInheritedAttributes(TABLE_ATTRS_DIRTY)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2013-12-17 17:58:32 +04:00
|
|
|
SetHasWeirdParserInsertionMode();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::~HTMLTableElement()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
if (mRows) {
|
1998-11-17 02:31:24 +03:00
|
|
|
mRows->ParentDestroyed();
|
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
ReleaseInheritedAttributes();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +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
|
|
|
HTMLTableElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-29 12:08:15 +04: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 17:13:33 +03:00
|
|
|
return HTMLTableElementBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-29 12:08:15 +04:00
|
|
|
}
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableElement)
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTableElement, nsGenericHTMLElement)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTBodies)
|
2012-01-08 03:37:43 +04:00
|
|
|
if (tmp->mRows) {
|
|
|
|
tmp->mRows->ParentDestroyed();
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRows)
|
2012-01-08 03:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableElement,
|
2007-03-08 14:17:16 +03:00
|
|
|
nsGenericHTMLElement)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTBodies)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTableElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTableElement, Element)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
// QueryInterface implementation for HTMLTableElement
|
2015-04-25 17:23:54 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTableElement)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
// the DOM spec says border, cellpadding, cellSpacing are all "wstring"
|
2000-12-23 13:56:31 +03:00
|
|
|
// in fact, they are integers or they are meaningless. so we store them
|
|
|
|
// here as ints.
|
1998-09-15 21:58:24 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection*
|
|
|
|
HTMLTableElement::Rows()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
if (!mRows) {
|
1998-11-17 02:31:24 +03:00
|
|
|
mRows = new TableRowsCollection(this);
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
return mRows;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection*
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::TBodies()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
if (!mTBodies) {
|
2004-04-14 08:26:00 +04:00
|
|
|
// Not using NS_GetContentList because this should not be cached
|
2006-07-02 11:23:10 +04:00
|
|
|
mTBodies = new nsContentList(this,
|
2011-11-16 11:50:19 +04:00
|
|
|
kNameSpaceID_XHTML,
|
2010-09-01 06:47:00 +04:00
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tbody,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2011-04-25 21:46:51 +04:00
|
|
|
return mTBodies;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTHead()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> head = GetTHead();
|
2012-12-29 12:08:15 +04:00
|
|
|
if (!head) {
|
|
|
|
// Create a new head rowgroup.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 12:08:15 +04:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::thead,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
head = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!head) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
ErrorResult rv;
|
2016-10-14 15:33:42 +03:00
|
|
|
nsCOMPtr<nsINode> refNode = nsINode::GetFirstChild();
|
|
|
|
nsINode::InsertBefore(*head, refNode, rv);
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
2012-12-29 12:08:15 +04:00
|
|
|
return head.forget();
|
|
|
|
}
|
2002-12-17 16:29:39 +03:00
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::DeleteTHead()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* tHead = GetTHead();
|
|
|
|
if (tHead) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tHead, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTFoot()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> foot = GetTFoot();
|
2012-12-29 12:08:15 +04:00
|
|
|
if (!foot) {
|
|
|
|
// create a new foot rowgroup
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 12:08:15 +04:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tfoot,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
foot = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!foot) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
AppendChildTo(foot, true);
|
1998-11-18 02:09:59 +03:00
|
|
|
}
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
return foot.forget();
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::DeleteTFoot()
|
1998-11-18 09:06:37 +03:00
|
|
|
{
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* tFoot = GetTFoot();
|
|
|
|
if (tFoot) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tFoot, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateCaption()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> caption = GetCaption();
|
2012-12-29 12:08:15 +04:00
|
|
|
if (!caption) {
|
|
|
|
// Create a new caption.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 12:08:15 +04:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::caption,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
caption = NS_NewHTMLTableCaptionElement(nodeInfo.forget());
|
|
|
|
if (!caption) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
AppendChildTo(caption, true);
|
1998-11-18 02:09:59 +03:00
|
|
|
}
|
2012-12-29 12:08:15 +04:00
|
|
|
return caption.forget();
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::DeleteCaption()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableCaptionElement* caption = GetCaption();
|
|
|
|
if (caption) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*caption, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-04 09:04:30 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTBody()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo =
|
2012-12-04 09:04:30 +04:00
|
|
|
OwnerDoc()->NodeInfoManager()->GetNodeInfo(nsGkAtoms::tbody, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
MOZ_ASSERT(nodeInfo);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> newBody =
|
2012-12-04 09:04:30 +04:00
|
|
|
NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
MOZ_ASSERT(newBody);
|
|
|
|
|
2016-10-14 15:33:42 +03:00
|
|
|
nsCOMPtr<nsIContent> referenceNode = nullptr;
|
2012-12-04 09:04:30 +04:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
|
|
|
child;
|
|
|
|
child = child->GetPreviousSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::tbody)) {
|
2012-12-04 09:04:30 +04:00
|
|
|
referenceNode = child->GetNextSibling();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
nsINode::InsertBefore(*newBody, referenceNode, rv);
|
|
|
|
|
|
|
|
return newBody.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::InsertRow(int32_t aIndex, ErrorResult& aError)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
1998-12-10 02:30:06 +03:00
|
|
|
/* get the ref row at aIndex
|
2013-08-02 02:24:21 +04:00
|
|
|
if there is one,
|
2009-01-23 12:02:09 +03:00
|
|
|
get its parent
|
1998-12-10 02:30:06 +03:00
|
|
|
insert the new row just before the ref row
|
1998-11-18 09:06:37 +03:00
|
|
|
else
|
|
|
|
get the first row group
|
|
|
|
insert the new row as its first child
|
|
|
|
*/
|
2002-12-17 16:29:39 +03:00
|
|
|
if (aIndex < -1) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-01-03 09:49:10 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
|
|
|
uint32_t rowCount = rows->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
if ((uint32_t)aIndex > rowCount && aIndex != -1) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-01-03 09:49:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// use local variable refIndex so we can remember original aIndex
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t refIndex = (uint32_t)aIndex;
|
2002-01-03 09:49:10 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> newRow;
|
2002-01-03 09:49:10 +03:00
|
|
|
if (rowCount > 0) {
|
2002-12-17 16:29:39 +03:00
|
|
|
if (refIndex == rowCount || aIndex == -1) {
|
2000-12-23 13:56:31 +03: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 09:49:10 +03:00
|
|
|
refIndex = rowCount - 1;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 03:23:43 +03:00
|
|
|
RefPtr<Element> refRow = rows->Item(refIndex);
|
|
|
|
nsCOMPtr<nsINode> parent = refRow->GetParentNode();
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-11-18 09:06:37 +03:00
|
|
|
// create the row
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2006-12-26 20:47:52 +03:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
2004-06-25 16:26:02 +04:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2004-06-06 06:38:32 +04:00
|
|
|
if (newRow) {
|
2012-12-29 12:08:15 +04:00
|
|
|
// If aIndex is -1 or equal to the number of rows, the new row
|
2003-01-12 00:33:00 +03:00
|
|
|
// is appended.
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex == -1 || uint32_t(aIndex) == rowCount) {
|
2012-12-29 12:08:15 +04:00
|
|
|
parent->AppendChild(*newRow, aError);
|
|
|
|
} else {
|
2000-12-23 13:56:31 +03:00
|
|
|
// insert the new row before the reference row we found above
|
2012-12-29 12:08:15 +04:00
|
|
|
parent->InsertBefore(*newRow, refRow, aError);
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
} else {
|
2016-05-17 09:54:00 +03:00
|
|
|
// the row count was 0, so
|
2014-05-02 05:29:23 +04:00
|
|
|
// find the last row group and insert there as first child
|
2012-12-29 12:08:15 +04:00
|
|
|
nsCOMPtr<nsIContent> rowGroup;
|
2014-05-02 05:29:23 +04:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
2011-09-27 11:54:58 +04:00
|
|
|
child;
|
2014-05-02 05:29:23 +04:00
|
|
|
child = child->GetPreviousSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::tbody)) {
|
2012-12-29 12:08:15 +04:00
|
|
|
rowGroup = child;
|
2004-04-14 08:26:00 +04:00
|
|
|
break;
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
|
|
|
if (!rowGroup) { // need to create a TBODY
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2006-12-26 20:47:52 +03:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tbody,
|
2004-06-25 16:26:02 +04:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
rowGroup = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (rowGroup) {
|
|
|
|
aError = AppendChildTo(rowGroup, true);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
|
|
|
if (rowGroup) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2006-12-26 20:47:52 +03:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
2004-06-25 16:26:02 +04:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2004-04-14 08:26:00 +04:00
|
|
|
if (newRow) {
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* section =
|
|
|
|
static_cast<HTMLTableSectionElement*>(rowGroup.get());
|
2012-12-29 18:07:48 +04:00
|
|
|
nsIHTMLCollection* rows = section->Rows();
|
2016-10-14 15:33:42 +03:00
|
|
|
nsCOMPtr<nsINode> refNode = rows->Item(0);
|
|
|
|
rowGroup->InsertBefore(*newRow, refNode, aError);
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
return newRow.forget();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
void
|
|
|
|
HTMLTableElement::DeleteRow(int32_t aIndex, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
if (aIndex < -1) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t refIndex;
|
2012-12-29 12:08:15 +04:00
|
|
|
if (aIndex == -1) {
|
|
|
|
refIndex = rows->Length();
|
2002-12-17 16:29:39 +03:00
|
|
|
if (refIndex == 0) {
|
2012-12-29 12:08:15 +04:00
|
|
|
return;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
2012-12-29 12:08:15 +04:00
|
|
|
} else {
|
|
|
|
refIndex = (uint32_t)aIndex;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsCOMPtr<nsIContent> row = rows->Item(refIndex);
|
2001-12-11 13:20:57 +03:00
|
|
|
if (!row) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2001-12-11 13:20:57 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
row->RemoveFromParent();
|
|
|
|
}
|
2001-12-11 13:20:57 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
1998-09-15 21:58:24 +04:00
|
|
|
/* ignore summary, just a string */
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::cellspacing ||
|
2013-02-07 12:08:57 +04:00
|
|
|
aAttribute == nsGkAtoms::cellpadding ||
|
|
|
|
aAttribute == nsGkAtoms::border) {
|
2012-02-21 13:34:01 +04:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
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
|
|
|
if (aResult.ParseSpecialIntValue(aValue)) {
|
2005-11-29 19:37:15 +03:00
|
|
|
// treat 0 width as auto
|
|
|
|
nsAttrValue::ValueType type = aResult.Type();
|
2011-07-11 14:56:00 +04:00
|
|
|
return !((type == nsAttrValue::eInteger &&
|
|
|
|
aResult.GetIntegerValue() == 0) ||
|
|
|
|
(type == nsAttrValue::ePercent &&
|
|
|
|
aResult.GetPercentValue() == 0.0f));
|
2001-08-22 08:21:05 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return ParseTableHAlignValue(aValue, aResult);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor ||
|
|
|
|
aAttribute == nsGkAtoms::bordercolor) {
|
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::hspace ||
|
|
|
|
aAttribute == nsGkAtoms::vspace) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
1999-07-24 23:55:35 +04:00
|
|
|
}
|
2000-06-14 04:59:29 +04:00
|
|
|
}
|
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,
|
2005-11-29 19:37:15 +03:00
|
|
|
aResult);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2005-09-23 09:02:42 +04:00
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void
|
|
|
|
HTMLTableElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2003-07-12 01:16:12 +04: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).
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
nsPresContext* presContext = aData->PresContext();
|
2007-11-16 06:46:42 +03:00
|
|
|
nsCompatibility mode = presContext->CompatibilityMode();
|
2001-10-25 04:24:08 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(TableBorder))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
// cellspacing
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellspacing);
|
2012-02-21 13:34:01 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger &&
|
2017-01-27 03:51:01 +03:00
|
|
|
!aData->PropertyIsSet(eCSSProperty_border_spacing)) {
|
|
|
|
aData->SetPixelValue(eCSSProperty_border_spacing, float(value->GetIntegerValue()));
|
1998-09-15 21:58:24 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Margin))) {
|
2011-08-20 14:18:50 +04: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) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_left);
|
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_right);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
1999-05-27 03:48:19 +04:00
|
|
|
|
2011-08-20 14:18:50 +04: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 13:56:31 +03:00
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_left, (float)value->GetIntegerValue());
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_right, (float)value->GetIntegerValue());
|
1999-05-27 03:48:19 +04:00
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vspace);
|
|
|
|
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_top, (float)value->GetIntegerValue());
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_bottom, (float)value->GetIntegerValue());
|
2000-02-12 03:58:38 +03:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Border))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
// bordercolor
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bordercolor);
|
|
|
|
nscolor color;
|
|
|
|
if (value && presContext->UseDocumentColors() &&
|
|
|
|
value->GetColorValue(color)) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_top_color, color);
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_left_color, color);
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_bottom_color, color);
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_right_color, color);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
2000-06-14 04:59:29 +04:00
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
// border
|
|
|
|
const nsAttrValue* borderValue = aAttributes->GetAttr(nsGkAtoms::border);
|
|
|
|
if (borderValue) {
|
|
|
|
// border = 1 pixel default
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t borderThickness = 1;
|
2011-08-20 14:18:50 +04:00
|
|
|
|
|
|
|
if (borderValue->Type() == nsAttrValue::eInteger)
|
|
|
|
borderThickness = borderValue->GetIntegerValue();
|
|
|
|
|
|
|
|
// by default, set all border sides to the specified width
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_top_width, (float)borderThickness);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_left_width, (float)borderThickness);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_bottom_width, (float)borderThickness);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_right_width, (float)borderThickness);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
1998-11-11 22:56:02 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::cellpadding },
|
|
|
|
{ &nsGkAtoms::cellspacing },
|
|
|
|
{ &nsGkAtoms::border },
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
|
|
|
{ &nsGkAtoms::hspace },
|
|
|
|
{ &nsGkAtoms::vspace },
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::bordercolor },
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::align },
|
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);
|
1998-09-05 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::GetAttributeMappingFunction() const
|
1998-09-05 08:00:06 +04:00
|
|
|
{
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
MapInheritedTableAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Padding))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellpadding);
|
2012-02-21 13:34:01 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
// We have cellpadding. This will override our padding values if we
|
|
|
|
// don't have any set.
|
2017-01-27 03:51:01 +03:00
|
|
|
float pad = float(value->GetIntegerValue());
|
2012-02-21 13:34:01 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_top, pad);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_right, pad);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_bottom, pad);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_left, pad);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMappedAttributes*
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::GetAttributesMappedForCell()
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
|
|
|
if (mTableInheritedAttributes) {
|
|
|
|
if (mTableInheritedAttributes == TABLE_ATTRS_DIRTY)
|
|
|
|
BuildInheritedAttributes();
|
|
|
|
if (mTableInheritedAttributes != TABLE_ATTRS_DIRTY)
|
|
|
|
return mTableInheritedAttributes;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::BuildInheritedAttributes()
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mTableInheritedAttributes == TABLE_ATTRS_DIRTY,
|
|
|
|
"potential leak, plus waste of work");
|
2014-10-02 23:07:24 +04:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2011-08-20 14:18:50 +04:00
|
|
|
nsHTMLStyleSheet* sheet = document ?
|
2012-07-30 18:20:58 +04:00
|
|
|
document->GetAttributeStyleSheet() : nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMappedAttributes> newAttrs;
|
2011-08-20 14:18:50 +04:00
|
|
|
if (sheet) {
|
|
|
|
const nsAttrValue* value = mAttrsAndChildren.GetAttr(nsGkAtoms::cellpadding);
|
|
|
|
if (value) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMappedAttributes> modifiableMapped = new
|
2011-08-20 14:18:50 +04: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 19:33:16 +04:00
|
|
|
void
|
|
|
|
HTMLTableElement::ReleaseInheritedAttributes()
|
|
|
|
{
|
|
|
|
if (mTableInheritedAttributes &&
|
|
|
|
mTableInheritedAttributes != TABLE_ATTRS_DIRTY)
|
|
|
|
NS_RELEASE(mTableInheritedAttributes);
|
|
|
|
mTableInheritedAttributes = TABLE_ATTRS_DIRTY;
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
nsresult
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
return nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2015-08-01 08:14:06 +03:00
|
|
|
nsAttrValueOrString* aValue,
|
2012-12-28 06:45:57 +04:00
|
|
|
bool aNotify)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2011-08-28 14:59:34 +04:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
2011-08-20 14:18:50 +04:00
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
}
|
2011-08-28 14:59:34 +04:00
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
bool aNotify)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2011-08-28 14:59:34 +04:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
BuildInheritedAttributes();
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
2011-08-28 14:59:34 +04:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
2012-12-28 06:45:57 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|