2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
#include "mozilla/dom/HTMLTableElement.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRuleData.h"
|
2011-08-20 03:18:50 -07:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2013-02-14 07:33:16 -08:00
|
|
|
#include "nsMappedAttributes.h"
|
2012-12-29 00:08:15 -08:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLTableElementBinding.h"
|
2013-01-31 15:11:49 -08:00
|
|
|
#include "nsContentUtils.h"
|
2014-04-15 19:58:44 -07:00
|
|
|
#include "jsfriendapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Table)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* ------------------------------ TableRowsCollection -------------------------------- */
|
|
|
|
/**
|
|
|
|
* This class provides a late-bound collection of rows in a table.
|
|
|
|
* mParent is NOT ref-counted to avoid circular references
|
|
|
|
*/
|
2011-05-31 14:47:17 -07:00
|
|
|
class TableRowsCollection : public nsIHTMLCollection,
|
|
|
|
public nsWrapperCache
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit TableRowsCollection(HTMLTableElement* aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
|
|
|
|
2012-11-14 14:10:08 -08:00
|
|
|
virtual Element* GetElementAt(uint32_t aIndex);
|
2011-05-31 14:47:59 -07:00
|
|
|
virtual nsINode* GetParentObject()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-11-10 23:55:41 -08:00
|
|
|
virtual Element*
|
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) MOZ_OVERRIDE;
|
2014-04-15 19:58:44 -07:00
|
|
|
virtual void GetSupportedNames(unsigned aFlags,
|
|
|
|
nsTArray<nsString>& aNames) MOZ_OVERRIDE;
|
2012-09-05 13:49:53 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD ParentDestroyed();
|
|
|
|
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TableRowsCollection)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
2013-11-12 07:22:22 -08:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-12 07:22:22 -08:00
|
|
|
protected:
|
2014-06-24 19:09:15 -07:00
|
|
|
virtual ~TableRowsCollection();
|
|
|
|
|
2013-11-12 07:22:22 -08:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() MOZ_OVERRIDE
|
2011-05-31 14:47:17 -07:00
|
|
|
{
|
2013-11-12 07:22:22 -08:00
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
2011-05-31 14:47:17 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Those rows that are not in table sections
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement* mParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<nsContentList> mOrphanRows;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
TableRowsCollection::TableRowsCollection(HTMLTableElement *aParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mParent(aParent)
|
2011-10-01 09:14:39 -07:00
|
|
|
, mOrphanRows(new nsContentList(mParent,
|
2011-11-15 23:50:19 -08:00
|
|
|
kNameSpaceID_XHTML,
|
2011-10-01 09:14:39 -07:00
|
|
|
nsGkAtoms::tr,
|
|
|
|
nsGkAtoms::tr,
|
2011-10-17 07:59:28 -07:00
|
|
|
false))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TableRowsCollection::~TableRowsCollection()
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
}
|
|
|
|
|
2013-11-12 07:22:22 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
TableRowsCollection::WrapObject(JSContext* aCx)
|
2013-11-12 07:22:22 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLCollectionBinding::Wrap(aCx, this);
|
2013-11-12 07:22:22 -08:00
|
|
|
}
|
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TableRowsCollection, mOrphanRows)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TableRowsCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TableRowsCollection)
|
|
|
|
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_INTERFACE_TABLE_HEAD(TableRowsCollection)
|
2014-08-25 16:21:35 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE(TableRowsCollection, nsIHTMLCollection,
|
|
|
|
nsIDOMHTMLCollection)
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(TableRowsCollection)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// rowgroup's rows will be in the nsIDOMHTMLCollection* named "rows". Note
|
|
|
|
// that this may be null at any time. This macro assumes an nsresult named
|
|
|
|
// |rv| is in scope.
|
|
|
|
#define DO_FOR_EACH_ROWGROUP(_code) \
|
2008-10-22 07:31:14 -07:00
|
|
|
do { \
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mParent) { \
|
|
|
|
/* THead */ \
|
2012-12-29 00:08:15 -08:00
|
|
|
HTMLTableSectionElement* rowGroup = mParent->GetTHead(); \
|
2012-12-29 06:07:48 -08:00
|
|
|
nsIHTMLCollection* rows; \
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rowGroup) { \
|
2012-12-29 06:07:48 -08:00
|
|
|
rows = rowGroup->Rows(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
} \
|
|
|
|
/* TBodies */ \
|
2012-12-29 00:08:15 -08:00
|
|
|
for (nsIContent* _node = mParent->nsINode::GetFirstChild(); \
|
|
|
|
_node; _node = _node->GetNextSibling()) { \
|
|
|
|
if (_node->IsHTML(nsGkAtoms::tbody)) { \
|
|
|
|
rowGroup = static_cast<HTMLTableSectionElement*>(_node); \
|
2012-12-29 06:07:48 -08:00
|
|
|
rows = rowGroup->Rows(); \
|
2011-04-25 10:46:51 -07:00
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
2007-03-22 10:30:00 -07:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
/* orphan rows */ \
|
|
|
|
rows = mOrphanRows; \
|
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
/* TFoot */ \
|
2011-04-25 10:46:51 -07:00
|
|
|
rowGroup = mParent->GetTFoot(); \
|
2012-12-29 06:07:48 -08:00
|
|
|
rows = nullptr; \
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rowGroup) { \
|
2012-12-29 06:07:48 -08:00
|
|
|
rows = rowGroup->Rows(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
} \
|
|
|
|
} \
|
2008-11-28 02:10:24 -08:00
|
|
|
} while (0)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
CountRowsInRowGroup(nsIDOMHTMLCollection* rows)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (rows) {
|
|
|
|
rows->GetLength(&length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we re-count every call. A better implementation would be to set
|
|
|
|
// ourselves up as an observer of contentAppended, contentInserted,
|
|
|
|
// and contentDeleted
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
TableRowsCollection::GetLength(uint32_t* aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aLength=0;
|
|
|
|
|
|
|
|
DO_FOR_EACH_ROWGROUP(
|
|
|
|
*aLength += CountRowsInRowGroup(rows);
|
|
|
|
);
|
|
|
|
|
2011-04-25 10:46:51 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-22 07:31:14 -07: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 14:10:08 -08:00
|
|
|
static Element*
|
2007-03-22 10:30:00 -07:00
|
|
|
GetItemOrCountInRowGroup(nsIDOMHTMLCollection* rows,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex, uint32_t* aCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-22 07:31:14 -07:00
|
|
|
*aCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (rows) {
|
2008-10-22 07:31:14 -07:00
|
|
|
rows->GetLength(aCount);
|
|
|
|
if (aIndex < *aCount) {
|
2012-09-05 08:42:58 -07:00
|
|
|
nsIHTMLCollection* list = static_cast<nsIHTMLCollection*>(rows);
|
|
|
|
return list->GetElementAt(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-14 14:10:08 -08:00
|
|
|
Element*
|
2012-09-05 08:42:58 -07:00
|
|
|
TableRowsCollection::GetElementAt(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
DO_FOR_EACH_ROWGROUP(
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
2012-11-14 14:10:08 -08:00
|
|
|
Element* node = GetItemOrCountInRowGroup(rows, aIndex, &count);
|
2008-10-22 07:31:14 -07:00
|
|
|
if (node) {
|
|
|
|
return node;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(count <= aIndex, "GetItemOrCountInRowGroup screwed up");
|
|
|
|
aIndex -= count;
|
|
|
|
);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
TableRowsCollection::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
2012-09-05 08:42:58 -07:00
|
|
|
nsISupports* node = GetElementAt(aIndex);
|
2008-10-22 07:31:14 -07:00
|
|
|
if (!node) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aReturn = nullptr;
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2011-04-25 10:46:57 -07:00
|
|
|
return NS_OK;
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-10 23:55:41 -08:00
|
|
|
Element*
|
|
|
|
TableRowsCollection::GetFirstNamedElement(const nsAString& aName, bool& aFound)
|
2012-09-05 13:49:53 -07:00
|
|
|
{
|
2013-11-10 23:55:41 -08:00
|
|
|
aFound = false;
|
2012-09-05 13:49:53 -07:00
|
|
|
DO_FOR_EACH_ROWGROUP(
|
2013-11-10 23:55:41 -08:00
|
|
|
Element* item = rows->NamedGetter(aName, aFound);
|
|
|
|
if (aFound) {
|
|
|
|
return item;
|
2012-09-05 13:49:53 -07:00
|
|
|
}
|
|
|
|
);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-05 08:58:03 -08:00
|
|
|
void
|
2014-04-15 19:58:44 -07:00
|
|
|
TableRowsCollection::GetSupportedNames(unsigned aFlags,
|
|
|
|
nsTArray<nsString>& aNames)
|
2012-11-05 08:58:03 -08:00
|
|
|
{
|
2014-04-15 19:58:44 -07:00
|
|
|
if (!(aFlags & JSITER_HIDDEN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-05 08:58:03 -08:00
|
|
|
DO_FOR_EACH_ROWGROUP(
|
|
|
|
nsTArray<nsString> names;
|
|
|
|
nsCOMPtr<nsIHTMLCollection> coll = do_QueryInterface(rows);
|
|
|
|
if (coll) {
|
2014-04-15 19:58:44 -07:00
|
|
|
coll->GetSupportedNames(aFlags, names);
|
2012-11-05 08:58:03 -08:00
|
|
|
for (uint32_t i = 0; i < names.Length(); ++i) {
|
|
|
|
if (!aNames.Contains(names[i])) {
|
|
|
|
aNames.AppendElement(names[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-31 14:40:35 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TableRowsCollection::NamedItem(const nsAString& aName,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
2012-10-13 05:50:24 -07:00
|
|
|
DO_FOR_EACH_ROWGROUP(
|
|
|
|
nsCOMPtr<nsIHTMLCollection> collection = do_QueryInterface(rows);
|
|
|
|
if (collection) {
|
|
|
|
nsresult rv = collection->NamedItem(aName, aReturn);
|
|
|
|
if (NS_FAILED(rv) || *aReturn) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2012-10-13 05:50:24 -07:00
|
|
|
*aReturn = nullptr;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TableRowsCollection::ParentDestroyed()
|
|
|
|
{
|
|
|
|
// see comment in destructor, do NOT release mParent!
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
/* --------------------------- HTMLTableElement ---------------------------- */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLTableElement::HTMLTableElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2011-08-20 03:18:50 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
|
|
|
mTableInheritedAttributes(TABLE_ATTRS_DIRTY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-12-17 05:58:32 -08:00
|
|
|
SetHasWeirdParserInsertionMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::~HTMLTableElement()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mRows) {
|
|
|
|
mRows->ParentDestroyed();
|
|
|
|
}
|
2011-08-20 03:18:50 -07:00
|
|
|
ReleaseInheritedAttributes();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
HTMLTableElement::WrapNode(JSContext *aCx)
|
2012-12-29 00:08:15 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLTableElementBinding::Wrap(aCx, this);
|
2012-12-29 00:08:15 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableElement)
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTableElement, nsGenericHTMLElement)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTBodies)
|
2012-01-07 15:37:43 -08:00
|
|
|
if (tmp->mRows) {
|
|
|
|
tmp->mRows->ParentDestroyed();
|
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRows)
|
2012-01-07 15:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericHTMLElement)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTBodies)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTableElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTableElement, Element)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
// QueryInterface implementation for HTMLTableElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLTableElement)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLTableElement, nsIDOMHTMLTableElement)
|
2013-08-07 13:23:08 -07:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2012-12-27 18:45:57 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
// the DOM spec says border, cellpadding, cellSpacing are all "wstring"
|
|
|
|
// in fact, they are integers or they are meaningless. so we store them
|
|
|
|
// here as ints.
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
nsIHTMLCollection*
|
|
|
|
HTMLTableElement::Rows()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mRows) {
|
|
|
|
mRows = new TableRowsCollection(this);
|
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
return mRows;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
nsIHTMLCollection*
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::TBodies()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mTBodies) {
|
|
|
|
// Not using NS_GetContentList because this should not be cached
|
|
|
|
mTBodies = new nsContentList(this,
|
2011-11-15 23:50:19 -08:00
|
|
|
kNameSpaceID_XHTML,
|
2010-08-31 19:47:00 -07:00
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tbody,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-25 10:46:51 -07:00
|
|
|
return mTBodies;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTHead()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-29 00:08:15 -08:00
|
|
|
nsRefPtr<nsGenericHTMLElement> head = GetTHead();
|
|
|
|
if (!head) {
|
|
|
|
// Create a new head rowgroup.
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 00:08:15 -08:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::thead,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
head = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!head) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
nsINode::InsertBefore(*head, nsINode::GetFirstChild(), rv);
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2012-12-29 00:08:15 -08:00
|
|
|
return head.forget();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-01 15:24:21 -07:00
|
|
|
void
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::DeleteTHead()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-29 00:08:15 -08:00
|
|
|
HTMLTableSectionElement* tHead = GetTHead();
|
|
|
|
if (tHead) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tHead, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTFoot()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-29 00:08:15 -08:00
|
|
|
nsRefPtr<nsGenericHTMLElement> foot = GetTFoot();
|
|
|
|
if (!foot) {
|
|
|
|
// create a new foot rowgroup
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 00:08:15 -08:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tfoot,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
foot = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!foot) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
AppendChildTo(foot, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
return foot.forget();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-01 15:24:21 -07:00
|
|
|
void
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::DeleteTFoot()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-29 00:08:15 -08:00
|
|
|
HTMLTableSectionElement* tFoot = GetTFoot();
|
|
|
|
if (tFoot) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tFoot, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateCaption()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-29 00:08:15 -08:00
|
|
|
nsRefPtr<nsGenericHTMLElement> caption = GetCaption();
|
|
|
|
if (!caption) {
|
|
|
|
// Create a new caption.
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-12-29 00:08:15 -08:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::caption,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
caption = NS_NewHTMLTableCaptionElement(nodeInfo.forget());
|
|
|
|
if (!caption) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
AppendChildTo(caption, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-12-29 00:08:15 -08:00
|
|
|
return caption.forget();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-01 15:24:21 -07:00
|
|
|
void
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::DeleteCaption()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-29 00:08:15 -08:00
|
|
|
HTMLTableCaptionElement* caption = GetCaption();
|
|
|
|
if (caption) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*caption, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-03 21:04:30 -08:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTBody()
|
|
|
|
{
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo =
|
2012-12-03 21:04:30 -08:00
|
|
|
OwnerDoc()->NodeInfoManager()->GetNodeInfo(nsGkAtoms::tbody, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
MOZ_ASSERT(nodeInfo);
|
|
|
|
|
2013-08-07 13:23:08 -07:00
|
|
|
nsRefPtr<nsGenericHTMLElement> newBody =
|
2012-12-03 21:04:30 -08:00
|
|
|
NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
MOZ_ASSERT(newBody);
|
|
|
|
|
|
|
|
nsIContent* referenceNode = nullptr;
|
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
|
|
|
child;
|
|
|
|
child = child->GetPreviousSibling()) {
|
|
|
|
if (child->IsHTML(nsGkAtoms::tbody)) {
|
|
|
|
referenceNode = child->GetNextSibling();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
nsINode::InsertBefore(*newBody, referenceNode, rv);
|
|
|
|
|
|
|
|
return newBody.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::InsertRow(int32_t aIndex, ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
/* get the ref row at aIndex
|
2013-08-01 15:24:21 -07:00
|
|
|
if there is one,
|
2009-01-23 01:02:09 -08:00
|
|
|
get its parent
|
2007-03-22 10:30:00 -07:00
|
|
|
insert the new row just before the ref row
|
|
|
|
else
|
|
|
|
get the first row group
|
|
|
|
insert the new row as its first child
|
|
|
|
*/
|
|
|
|
if (aIndex < -1) {
|
2012-12-29 00:08:15 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
|
|
|
uint32_t rowCount = rows->Length();
|
2012-08-22 08:56:38 -07:00
|
|
|
if ((uint32_t)aIndex > rowCount && aIndex != -1) {
|
2012-12-29 00:08:15 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// use local variable refIndex so we can remember original aIndex
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t refIndex = (uint32_t)aIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
nsRefPtr<nsGenericHTMLElement> newRow;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rowCount > 0) {
|
|
|
|
if (refIndex == rowCount || aIndex == -1) {
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
refIndex = rowCount - 1;
|
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
Element* refRow = rows->Item(refIndex);
|
|
|
|
nsINode* parent = refRow->GetParentNode();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// create the row
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (newRow) {
|
2012-12-29 00:08:15 -08:00
|
|
|
// If aIndex is -1 or equal to the number of rows, the new row
|
2007-03-22 10:30:00 -07:00
|
|
|
// is appended.
|
2012-08-22 08:56:38 -07:00
|
|
|
if (aIndex == -1 || uint32_t(aIndex) == rowCount) {
|
2012-12-29 00:08:15 -08:00
|
|
|
parent->AppendChild(*newRow, aError);
|
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// insert the new row before the reference row we found above
|
2012-12-29 00:08:15 -08:00
|
|
|
parent->InsertBefore(*newRow, refRow, aError);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
} else {
|
|
|
|
// the row count was 0, so
|
2014-05-01 18:29:23 -07:00
|
|
|
// find the last row group and insert there as first child
|
2012-12-29 00:08:15 -08:00
|
|
|
nsCOMPtr<nsIContent> rowGroup;
|
2014-05-01 18:29:23 -07:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
2011-09-27 00:54:58 -07:00
|
|
|
child;
|
2014-05-01 18:29:23 -07:00
|
|
|
child = child->GetPreviousSibling()) {
|
|
|
|
if (child->IsHTML(nsGkAtoms::tbody)) {
|
2012-12-29 00:08:15 -08:00
|
|
|
rowGroup = child;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rowGroup) { // need to create a TBODY
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tbody,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
rowGroup = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (rowGroup) {
|
|
|
|
aError = AppendChildTo(rowGroup, true);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rowGroup) {
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (newRow) {
|
2012-12-29 00:08:15 -08:00
|
|
|
HTMLTableSectionElement* section =
|
|
|
|
static_cast<HTMLTableSectionElement*>(rowGroup.get());
|
2012-12-29 06:07:48 -08:00
|
|
|
nsIHTMLCollection* rows = section->Rows();
|
|
|
|
rowGroup->InsertBefore(*newRow, rows->Item(0), aError);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
return newRow.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
void
|
|
|
|
HTMLTableElement::DeleteRow(int32_t aIndex, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
if (aIndex < -1) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t refIndex;
|
2012-12-29 00:08:15 -08:00
|
|
|
if (aIndex == -1) {
|
|
|
|
refIndex = rows->Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (refIndex == 0) {
|
2012-12-29 00:08:15 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
2012-12-29 00:08:15 -08:00
|
|
|
} else {
|
|
|
|
refIndex = (uint32_t)aIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
nsCOMPtr<nsIContent> row = rows->Item(refIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!row) {
|
2012-12-29 00:08:15 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 00:08:15 -08:00
|
|
|
row->RemoveFromParent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
/* ignore summary, just a string */
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::cellspacing ||
|
2013-02-07 00:08:57 -08:00
|
|
|
aAttribute == nsGkAtoms::cellpadding ||
|
|
|
|
aAttribute == nsGkAtoms::border) {
|
2012-02-21 01:34:01 -08:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::height) {
|
2011-02-04 11:46:16 -08:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::width) {
|
2011-02-04 11:46:16 -08:00
|
|
|
if (aResult.ParseSpecialIntValue(aValue)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// treat 0 width as auto
|
|
|
|
nsAttrValue::ValueType type = aResult.Type();
|
2011-07-11 03:56:00 -07:00
|
|
|
return !((type == nsAttrValue::eInteger &&
|
|
|
|
aResult.GetIntegerValue() == 0) ||
|
|
|
|
(type == nsAttrValue::ePercent &&
|
|
|
|
aResult.GetPercentValue() == 0.0f));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
|
|
|
return ParseTableHAlignValue(aValue, aResult);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::bgcolor ||
|
|
|
|
aAttribute == nsGkAtoms::bordercolor) {
|
2010-07-17 01:09:14 -07:00
|
|
|
return aResult.ParseColor(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::hspace ||
|
|
|
|
aAttribute == nsGkAtoms::vspace) {
|
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 10:50:49 -07:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(aNamespaceID,
|
|
|
|
aAttribute, aValue,
|
|
|
|
aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-19 11:21:29 -08:00
|
|
|
void
|
|
|
|
HTMLTableElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
2007-03-22 10:30:00 -07: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-15 19:46:42 -08:00
|
|
|
nsPresContext* presContext = aData->mPresContext;
|
|
|
|
nsCompatibility mode = presContext->CompatibilityMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TableBorder)) {
|
2011-08-20 03:18:50 -07:00
|
|
|
// cellspacing
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellspacing);
|
|
|
|
nsCSSValue* borderSpacing = aData->ValueForBorderSpacing();
|
2012-02-21 01:34:01 -08:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger &&
|
|
|
|
borderSpacing->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderSpacing->
|
|
|
|
SetFloatValue(float(value->GetIntegerValue()), eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Margin)) {
|
2011-08-20 03:18:50 -07: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) {
|
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeftValue();
|
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetAutoValue();
|
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRightValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetAutoValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-20 03:18:50 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-20 03:18:50 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-20 03:18:50 -07:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeftValue();
|
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRightValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-20 03:18:50 -07:00
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vspace);
|
|
|
|
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
nsCSSValue* marginTop = aData->ValueForMarginTop();
|
|
|
|
if (marginTop->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginTop->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* marginBottom = aData->ValueForMarginBottom();
|
|
|
|
if (marginBottom->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginBottom->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
|
2011-08-20 03:18:50 -07: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());
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-20 03:18:50 -07: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());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) {
|
2011-08-20 03:18:50 -07:00
|
|
|
// bordercolor
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bordercolor);
|
|
|
|
nscolor color;
|
|
|
|
if (value && presContext->UseDocumentColors() &&
|
|
|
|
value->GetColorValue(color)) {
|
|
|
|
nsCSSValue* borderLeftColor = aData->ValueForBorderLeftColorValue();
|
|
|
|
if (borderLeftColor->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderLeftColor->SetColorValue(color);
|
|
|
|
nsCSSValue* borderRightColor = aData->ValueForBorderRightColorValue();
|
|
|
|
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);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-20 03:18:50 -07:00
|
|
|
// border
|
|
|
|
const nsAttrValue* borderValue = aAttributes->GetAttr(nsGkAtoms::border);
|
|
|
|
if (borderValue) {
|
|
|
|
// border = 1 pixel default
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t borderThickness = 1;
|
2011-08-20 03:18:50 -07:00
|
|
|
|
|
|
|
if (borderValue->Type() == nsAttrValue::eInteger)
|
|
|
|
borderThickness = borderValue->GetIntegerValue();
|
|
|
|
|
|
|
|
// by default, set all border sides to the specified width
|
|
|
|
nsCSSValue* borderLeftWidth = aData->ValueForBorderLeftWidthValue();
|
|
|
|
if (borderLeftWidth->GetUnit() == eCSSUnit_Null)
|
|
|
|
borderLeftWidth->SetFloatValue((float)borderThickness, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* borderRightWidth = aData->ValueForBorderRightWidthValue();
|
|
|
|
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);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-08-20 03:18:50 -07:00
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry attributes[] = {
|
|
|
|
{ &nsGkAtoms::cellpadding },
|
|
|
|
{ &nsGkAtoms::cellspacing },
|
|
|
|
{ &nsGkAtoms::border },
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
|
|
|
{ &nsGkAtoms::hspace },
|
|
|
|
{ &nsGkAtoms::vspace },
|
|
|
|
|
|
|
|
{ &nsGkAtoms::bordercolor },
|
|
|
|
|
|
|
|
{ &nsGkAtoms::align },
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nullptr }
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::GetAttributeMappingFunction() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
2011-08-20 03:18:50 -07: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 01:34:01 -08: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);
|
|
|
|
|
|
|
|
nsCSSValue* paddingLeft = aData->ValueForPaddingLeftValue();
|
|
|
|
if (paddingLeft->GetUnit() == eCSSUnit_Null) {
|
|
|
|
*paddingLeft = padVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue* paddingRight = aData->ValueForPaddingRightValue();
|
|
|
|
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 03:18:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMappedAttributes*
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::GetAttributesMappedForCell()
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
|
|
|
if (mTableInheritedAttributes) {
|
|
|
|
if (mTableInheritedAttributes == TABLE_ATTRS_DIRTY)
|
|
|
|
BuildInheritedAttributes();
|
|
|
|
if (mTableInheritedAttributes != TABLE_ATTRS_DIRTY)
|
|
|
|
return mTableInheritedAttributes;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-08-20 03:18:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::BuildInheritedAttributes()
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mTableInheritedAttributes == TABLE_ATTRS_DIRTY,
|
|
|
|
"potential leak, plus waste of work");
|
2014-10-02 12:07:24 -07:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2011-08-20 03:18:50 -07:00
|
|
|
nsHTMLStyleSheet* sheet = document ?
|
2012-07-30 07:20:58 -07:00
|
|
|
document->GetAttributeStyleSheet() : nullptr;
|
2011-08-20 03:18:50 -07:00
|
|
|
nsRefPtr<nsMappedAttributes> newAttrs;
|
|
|
|
if (sheet) {
|
|
|
|
const nsAttrValue* value = mAttrsAndChildren.GetAttr(nsGkAtoms::cellpadding);
|
|
|
|
if (value) {
|
|
|
|
nsRefPtr<nsMappedAttributes> modifiableMapped = new
|
|
|
|
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 07:33:16 -08:00
|
|
|
void
|
|
|
|
HTMLTableElement::ReleaseInheritedAttributes()
|
|
|
|
{
|
|
|
|
if (mTableInheritedAttributes &&
|
|
|
|
mTableInheritedAttributes != TABLE_ATTRS_DIRTY)
|
|
|
|
NS_RELEASE(mTableInheritedAttributes);
|
|
|
|
mTableInheritedAttributes = TABLE_ATTRS_DIRTY;
|
|
|
|
}
|
|
|
|
|
2011-08-20 03:18:50 -07:00
|
|
|
nsresult
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
return nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify)
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
2011-08-28 03:59:34 -07:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
2011-08-20 03:18:50 -07:00
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
}
|
2011-08-28 03:59:34 -07:00
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 03:18:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-27 18:45:57 -08:00
|
|
|
HTMLTableElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
bool aNotify)
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
2011-08-28 03:59:34 -07:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
BuildInheritedAttributes();
|
2011-08-20 03:18:50 -07:00
|
|
|
}
|
2011-08-28 03:59:34 -07:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 03:18:50 -07:00
|
|
|
}
|
2012-12-27 18:45:57 -08:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|