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
|
|
|
|
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2011-08-20 03:18:50 -07:00
|
|
|
#include "nsHTMLTableElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMHTMLTableCaptionElem.h"
|
|
|
|
#include "nsIDOMHTMLTableSectionElem.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2007-05-14 02:11:38 -07:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsRuleData.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
2008-10-22 07:31:14 -07:00
|
|
|
#include "nsIHTMLCollection.h"
|
2011-08-20 03:18:50 -07:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2012-06-13 08:18:30 -07:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
2011-05-31 14:47:17 -07:00
|
|
|
#include "dombindings.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
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:
|
|
|
|
TableRowsCollection(nsHTMLTableElement *aParent);
|
|
|
|
virtual ~TableRowsCollection();
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
|
|
|
|
2011-05-31 14:47:59 -07:00
|
|
|
virtual nsINode* GetParentObject()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
virtual JSObject* NamedItem(JSContext* cx, const nsAString& name,
|
|
|
|
ErrorResult& error);
|
|
|
|
|
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
|
2012-03-14 08:25:40 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
|
2011-06-29 10:17:37 -07:00
|
|
|
bool *triedToWrap)
|
2011-05-31 14:47:17 -07:00
|
|
|
{
|
2012-06-13 08:18:30 -07:00
|
|
|
JSObject* obj = mozilla::dom::HTMLCollectionBinding::Wrap(cx, scope, this,
|
|
|
|
triedToWrap);
|
|
|
|
if (obj || *triedToWrap) {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
*triedToWrap = true;
|
|
|
|
return mozilla::dom::oldproxybindings::HTMLCollection::create(cx, scope,
|
|
|
|
this);
|
2011-05-31 14:47:17 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Those rows that are not in table sections
|
2011-10-01 09:14:39 -07:00
|
|
|
nsHTMLTableElement* mParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<nsContentList> mOrphanRows;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TableRowsCollection::TableRowsCollection(nsHTMLTableElement *aParent)
|
|
|
|
: 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
|
|
|
{
|
2012-03-16 08:44:09 -07:00
|
|
|
SetIsDOMBinding();
|
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.
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(TableRowsCollection)
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(TableRowsCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2012-01-07 15:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOrphanRows)
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(TableRowsCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mOrphanRows,
|
2008-09-10 20:15:29 -07:00
|
|
|
nsIDOMNodeList)
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(TableRowsCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
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)
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-10-24 06:58:33 -07:00
|
|
|
NS_INTERFACE_TABLE2(TableRowsCollection, nsIHTMLCollection,
|
|
|
|
nsIDOMHTMLCollection)
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(TableRowsCollection)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLCollection)
|
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 */ \
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableSectionElement> rowGroup; \
|
2011-04-25 10:46:51 -07:00
|
|
|
rowGroup = mParent->GetTHead(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> rows; \
|
|
|
|
if (rowGroup) { \
|
|
|
|
rowGroup->GetRows(getter_AddRefs(rows)); \
|
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
|
|
|
} \
|
|
|
|
/* TBodies */ \
|
2011-04-25 10:46:51 -07:00
|
|
|
nsContentList *_tbodies = mParent->TBodies(); \
|
|
|
|
nsINode * _node; \
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t _tbodyIndex = 0; \
|
2011-04-25 10:46:51 -07:00
|
|
|
_node = _tbodies->GetNodeAt(_tbodyIndex); \
|
|
|
|
while (_node) { \
|
|
|
|
rowGroup = do_QueryInterface(_node); \
|
|
|
|
if (rowGroup) { \
|
|
|
|
rowGroup->GetRows(getter_AddRefs(rows)); \
|
|
|
|
do { /* gives scoping */ \
|
|
|
|
_code \
|
|
|
|
} while (0); \
|
2007-03-22 10:30:00 -07:00
|
|
|
} \
|
2011-04-25 10:46:51 -07:00
|
|
|
_node = _tbodies->GetNodeAt(++_tbodyIndex); \
|
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-07-30 07:20:58 -07:00
|
|
|
rows = nullptr; \
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rowGroup) { \
|
|
|
|
rowGroup->GetRows(getter_AddRefs(rows)); \
|
|
|
|
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-09-05 08:42:58 -07:00
|
|
|
static nsGenericElement*
|
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-09-05 08:42:58 -07:00
|
|
|
nsGenericElement*
|
|
|
|
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-09-05 08:42:58 -07:00
|
|
|
nsGenericElement* 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
|
|
|
}
|
|
|
|
|
2008-10-31 14:40:35 -07:00
|
|
|
static nsISupports*
|
2010-05-09 12:41:19 -07:00
|
|
|
GetNamedItemInRowGroup(nsIDOMHTMLCollection* aRows, const nsAString& aName,
|
2011-04-25 10:46:59 -07:00
|
|
|
nsWrapperCache** aCache)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-31 14:40:35 -07:00
|
|
|
nsCOMPtr<nsIHTMLCollection> rows = do_QueryInterface(aRows);
|
|
|
|
if (rows) {
|
2011-04-25 10:46:59 -07:00
|
|
|
return rows->GetNamedItem(aName, aCache);
|
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
|
|
|
}
|
|
|
|
|
2008-10-31 14:40:35 -07:00
|
|
|
nsISupports*
|
2010-05-09 12:41:19 -07:00
|
|
|
TableRowsCollection::GetNamedItem(const nsAString& aName,
|
2011-04-25 10:46:59 -07:00
|
|
|
nsWrapperCache** aCache)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
DO_FOR_EACH_ROWGROUP(
|
2011-04-25 10:46:59 -07:00
|
|
|
nsISupports* item = GetNamedItemInRowGroup(rows, aName, aCache);
|
|
|
|
if (item) {
|
2008-10-31 14:40:35 -07:00
|
|
|
return item;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
);
|
2012-07-30 07:20:58 -07:00
|
|
|
*aCache = nullptr;
|
|
|
|
return nullptr;
|
2008-10-31 14:40:35 -07:00
|
|
|
}
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
JSObject*
|
|
|
|
TableRowsCollection::NamedItem(JSContext* cx, const nsAString& name,
|
|
|
|
ErrorResult& error)
|
|
|
|
{
|
|
|
|
nsWrapperCache* cache;
|
|
|
|
DO_FOR_EACH_ROWGROUP(
|
|
|
|
nsISupports* item = GetNamedItemInRowGroup(rows, name, &cache);
|
|
|
|
if (item) {
|
|
|
|
JSObject* wrapper = GetWrapper();
|
|
|
|
JSAutoCompartment ac(cx, wrapper);
|
|
|
|
JS::Value v;
|
|
|
|
if (!mozilla::dom::WrapObject(cx, wrapper, item, cache, nullptr, &v)) {
|
|
|
|
error.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &v.toObject();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2008-10-31 14:40:35 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TableRowsCollection::NamedItem(const nsAString& aName,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
2010-05-09 12:41:19 -07:00
|
|
|
nsWrapperCache *cache;
|
2011-04-25 10:46:59 -07:00
|
|
|
nsISupports* item = GetNamedItem(aName, &cache);
|
2008-10-31 14:40:35 -07:00
|
|
|
if (!item) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aReturn = nullptr;
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2011-04-25 10:46:59 -07:00
|
|
|
return NS_OK;
|
2008-10-31 14:40:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(item, aReturn);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------- nsHTMLTableElement --------------------------- */
|
|
|
|
// the class declaration is at the top of this file
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Table)
|
|
|
|
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsHTMLTableElement::nsHTMLTableElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2011-08-20 03:18:50 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
|
|
|
mTableInheritedAttributes(TABLE_ATTRS_DIRTY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLTableElement::~nsHTMLTableElement()
|
|
|
|
{
|
|
|
|
if (mRows) {
|
|
|
|
mRows->ParentDestroyed();
|
|
|
|
}
|
2011-08-20 03:18:50 -07:00
|
|
|
ReleaseInheritedAttributes();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableElement)
|
2012-01-07 15:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLTableElement, nsGenericHTMLElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTBodies)
|
|
|
|
if (tmp->mRows) {
|
|
|
|
tmp->mRows->ParentDestroyed();
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRows)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableElement,
|
|
|
|
nsGenericHTMLElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTBodies,
|
2008-09-10 20:15:29 -07:00
|
|
|
nsIDOMNodeList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRows)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLTableElement, nsGenericElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLTableElement, nsGenericElement)
|
|
|
|
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
DOMCI_NODE_DATA(HTMLTableElement, nsHTMLTableElement)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsHTMLTableElement
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLTableElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLTableElement, nsIDOMHTMLTableElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLTableElement,
|
|
|
|
nsGenericHTMLElement)
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLTableElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(nsHTMLTableElement)
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, Align, align)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, BgColor, bgcolor)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, Border, border)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, CellPadding, cellpadding)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, CellSpacing, cellspacing)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, Frame, frame)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, Rules, rules)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, Summary, summary)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLTableElement, Width, width)
|
|
|
|
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
already_AddRefed<nsIDOMHTMLTableCaptionElement>
|
|
|
|
nsHTMLTableElement::GetCaption()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
for (nsIContent* cur = nsINode::GetFirstChild(); cur; cur = cur->GetNextSibling()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableCaptionElement> caption = do_QueryInterface(cur);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (caption) {
|
2011-11-15 23:50:19 -08:00
|
|
|
return caption.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::GetCaption(nsIDOMHTMLTableCaptionElement** aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableCaptionElement> caption = GetCaption();
|
|
|
|
caption.forget(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::SetCaption(nsIDOMHTMLTableCaptionElement* aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = DeleteCaption();
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aValue) {
|
|
|
|
nsCOMPtr<nsIDOMNode> resultingChild;
|
|
|
|
AppendChild(aValue, getter_AddRefs(resultingChild));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIDOMHTMLTableSectionElement>
|
|
|
|
nsHTMLTableElement::GetSection(nsIAtom *aTag)
|
|
|
|
{
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIDOMHTMLTableSectionElement> section = do_QueryInterface(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (section && child->NodeInfo()->Equals(aTag)) {
|
2011-11-15 23:50:19 -08:00
|
|
|
return section.forget();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::GetTHead(nsIDOMHTMLTableSectionElement** aValue)
|
|
|
|
{
|
2011-04-25 10:46:51 -07:00
|
|
|
*aValue = GetTHead().get();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::SetTHead(nsIDOMHTMLTableSectionElement* aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aValue));
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
|
|
|
|
if (!content->NodeInfo()->Equals(nsGkAtoms::thead)) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = DeleteTHead();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aValue) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
rv = GetFirstChild(getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> resultChild;
|
|
|
|
rv = InsertBefore(aValue, child, getter_AddRefs(resultChild));
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::GetTFoot(nsIDOMHTMLTableSectionElement** aValue)
|
|
|
|
{
|
2011-04-25 10:46:51 -07:00
|
|
|
*aValue = GetTFoot().get();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::SetTFoot(nsIDOMHTMLTableSectionElement* aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aValue));
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
|
|
|
|
if (!content->NodeInfo()->Equals(nsGkAtoms::tfoot)) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = DeleteTFoot();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aValue) {
|
|
|
|
nsCOMPtr<nsIDOMNode> resultingChild;
|
|
|
|
AppendChild(aValue, getter_AddRefs(resultingChild));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::GetRows(nsIDOMHTMLCollection** aValue)
|
|
|
|
{
|
|
|
|
if (!mRows) {
|
|
|
|
mRows = new TableRowsCollection(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = mRows;
|
|
|
|
NS_ADDREF(*aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::GetTBodies(nsIDOMHTMLCollection** aValue)
|
2011-04-25 10:46:51 -07:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aValue = TBodies());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentList*
|
|
|
|
nsHTMLTableElement::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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::CreateTHead(nsIDOMHTMLElement** aValue)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aValue = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsRefPtr<nsIDOMHTMLTableSectionElement> head = GetTHead();
|
|
|
|
if (head) {
|
|
|
|
// return the existing thead
|
|
|
|
head.forget(aValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::thead,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIContent> newHead =
|
|
|
|
NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!newHead) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
nsresult rv = GetFirstChild(getter_AddRefs(child));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> newHeadAsDOMElement = do_QueryInterface(newHead);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIDOMNode> resultChild;
|
|
|
|
InsertBefore(newHeadAsDOMElement, child, getter_AddRefs(resultChild));
|
|
|
|
newHeadAsDOMElement.forget(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::DeleteTHead()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableSectionElement> childToDelete;
|
|
|
|
nsresult rv = GetTHead(getter_AddRefs(childToDelete));
|
|
|
|
|
|
|
|
if ((NS_SUCCEEDED(rv)) && childToDelete) {
|
|
|
|
nsCOMPtr<nsIDOMNode> resultingChild;
|
|
|
|
// mInner does the notification
|
|
|
|
RemoveChild(childToDelete, getter_AddRefs(resultingChild));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::CreateTFoot(nsIDOMHTMLElement** aValue)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aValue = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsRefPtr<nsIDOMHTMLTableSectionElement> foot = GetTFoot();
|
|
|
|
if (foot) {
|
|
|
|
// return the existing tfoot
|
|
|
|
foot.forget(aValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
// create a new foot rowgroup
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tfoot,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIContent> newFoot = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!newFoot) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
AppendChildTo(newFoot, true);
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> newFootAsDOMElement = do_QueryInterface(newFoot);
|
|
|
|
newFootAsDOMElement.forget(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::DeleteTFoot()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableSectionElement> childToDelete;
|
|
|
|
nsresult rv = GetTFoot(getter_AddRefs(childToDelete));
|
|
|
|
|
|
|
|
if ((NS_SUCCEEDED(rv)) && childToDelete) {
|
|
|
|
nsCOMPtr<nsIDOMNode> resultingChild;
|
|
|
|
// mInner does the notification
|
|
|
|
RemoveChild(childToDelete, getter_AddRefs(resultingChild));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::CreateCaption(nsIDOMHTMLElement** aValue)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aValue = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
if (nsRefPtr<nsIDOMHTMLTableCaptionElement> caption = GetCaption()) {
|
|
|
|
// return the existing caption
|
|
|
|
caption.forget(aValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
// create a new head rowgroup
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::caption,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIContent> newCaption = NS_NewHTMLTableCaptionElement(nodeInfo.forget());
|
|
|
|
|
|
|
|
if (!newCaption) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
AppendChildTo(newCaption, true);
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> captionAsDOMElement =
|
|
|
|
do_QueryInterface(newCaption);
|
|
|
|
captionAsDOMElement.forget(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableElement::DeleteCaption()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableCaptionElement> childToDelete;
|
|
|
|
nsresult rv = GetCaption(getter_AddRefs(childToDelete));
|
|
|
|
|
|
|
|
if ((NS_SUCCEEDED(rv)) && childToDelete) {
|
|
|
|
nsCOMPtr<nsIDOMNode> resultingChild;
|
|
|
|
RemoveChild(childToDelete, getter_AddRefs(resultingChild));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLTableElement::InsertRow(int32_t aIndex, nsIDOMHTMLElement** aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
/* get the ref row at aIndex
|
|
|
|
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
|
|
|
|
*/
|
2012-07-30 07:20:58 -07:00
|
|
|
*aValue = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aIndex < -1) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
|
|
GetRows(getter_AddRefs(rows));
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t rowCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
rows->GetLength(&rowCount);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
if ((uint32_t)aIndex > rowCount && aIndex != -1) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsresult rv;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> refRow;
|
|
|
|
rows->Item(refIndex, getter_AddRefs(refRow));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
|
|
|
|
refRow->GetParentNode(getter_AddRefs(parent));
|
|
|
|
// create the row
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsIContent> newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (newRow) {
|
|
|
|
nsCOMPtr<nsIDOMNode> newRowNode(do_QueryInterface(newRow));
|
|
|
|
nsCOMPtr<nsIDOMNode> retChild;
|
|
|
|
|
|
|
|
// If index is -1 or equal to the number of rows, the new row
|
|
|
|
// is appended.
|
2012-08-22 08:56:38 -07:00
|
|
|
if (aIndex == -1 || uint32_t(aIndex) == rowCount) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = parent->AppendChild(newRowNode, getter_AddRefs(retChild));
|
2012-01-17 03:52:36 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// insert the new row before the reference row we found above
|
|
|
|
rv = parent->InsertBefore(newRowNode, refRow,
|
|
|
|
getter_AddRefs(retChild));
|
2012-01-17 03:52:36 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retChild) {
|
|
|
|
CallQueryInterface(retChild, aValue);
|
|
|
|
}
|
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
} else {
|
|
|
|
// the row count was 0, so
|
2007-03-22 10:30:00 -07:00
|
|
|
// find the first row group and insert there as first child
|
|
|
|
nsCOMPtr<nsIDOMNode> rowGroup;
|
|
|
|
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINodeInfo *childInfo = child->NodeInfo();
|
|
|
|
nsIAtom *localName = childInfo->NameAtom();
|
2011-11-15 23:50:19 -08:00
|
|
|
if (childInfo->NamespaceID() == kNameSpaceID_XHTML &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(localName == nsGkAtoms::thead ||
|
|
|
|
localName == nsGkAtoms::tbody ||
|
|
|
|
localName == nsGkAtoms::tfoot)) {
|
|
|
|
rowGroup = do_QueryInterface(child);
|
|
|
|
NS_ASSERTION(rowGroup, "HTML node did not QI to nsIDOMNode");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rowGroup) { // need to create a TBODY
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tbody,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> newRowGroup =
|
2010-07-23 02:49:57 -07:00
|
|
|
NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (newRowGroup) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = AppendChildTo(newRowGroup, true);
|
2012-01-17 03:52:36 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rowGroup = do_QueryInterface(newRowGroup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rowGroup) {
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsIContent> newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (newRow) {
|
|
|
|
nsCOMPtr<nsIDOMNode> firstRow;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableSectionElement> section =
|
|
|
|
do_QueryInterface(rowGroup);
|
|
|
|
|
|
|
|
if (section) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
|
|
section->GetRows(getter_AddRefs(rows));
|
|
|
|
if (rows) {
|
|
|
|
rows->Item(0, getter_AddRefs(firstRow));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> retNode, newRowNode(do_QueryInterface(newRow));
|
|
|
|
|
|
|
|
rowGroup->InsertBefore(newRowNode, firstRow, getter_AddRefs(retNode));
|
|
|
|
|
|
|
|
if (retNode) {
|
|
|
|
CallQueryInterface(retNode, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLTableElement::DeleteRow(int32_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aValue < -1) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
|
|
GetRows(getter_AddRefs(rows));
|
|
|
|
|
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t refIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aValue == -1) {
|
|
|
|
rv = rows->GetLength(&refIndex);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (refIndex == 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
|
|
|
}
|
|
|
|
else {
|
2012-08-22 08:56:38 -07:00
|
|
|
refIndex = (uint32_t)aValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> row;
|
|
|
|
rv = rows->Item(refIndex, getter_AddRefs(row));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!row) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
row->GetParentNode(getter_AddRefs(parent));
|
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> deleted_row;
|
|
|
|
return parent->RemoveChild(row, getter_AddRefs(deleted_row));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const nsAttrValue::EnumTable kFrameTable[] = {
|
|
|
|
{ "void", NS_STYLE_TABLE_FRAME_NONE },
|
|
|
|
{ "above", NS_STYLE_TABLE_FRAME_ABOVE },
|
|
|
|
{ "below", NS_STYLE_TABLE_FRAME_BELOW },
|
|
|
|
{ "hsides", NS_STYLE_TABLE_FRAME_HSIDES },
|
|
|
|
{ "lhs", NS_STYLE_TABLE_FRAME_LEFT },
|
|
|
|
{ "rhs", NS_STYLE_TABLE_FRAME_RIGHT },
|
|
|
|
{ "vsides", NS_STYLE_TABLE_FRAME_VSIDES },
|
|
|
|
{ "box", NS_STYLE_TABLE_FRAME_BOX },
|
|
|
|
{ "border", NS_STYLE_TABLE_FRAME_BORDER },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const nsAttrValue::EnumTable kRulesTable[] = {
|
|
|
|
{ "none", NS_STYLE_TABLE_RULES_NONE },
|
|
|
|
{ "groups", NS_STYLE_TABLE_RULES_GROUPS },
|
|
|
|
{ "rows", NS_STYLE_TABLE_RULES_ROWS },
|
|
|
|
{ "cols", NS_STYLE_TABLE_RULES_COLS },
|
|
|
|
{ "all", NS_STYLE_TABLE_RULES_ALL },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const nsAttrValue::EnumTable kLayoutTable[] = {
|
|
|
|
{ "auto", NS_STYLE_TABLE_LAYOUT_AUTO },
|
|
|
|
{ "fixed", NS_STYLE_TABLE_LAYOUT_FIXED },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLTableElement::ParseAttribute(int32_t aNamespaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
/* ignore summary, just a string */
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::cellspacing ||
|
|
|
|
aAttribute == nsGkAtoms::cellpadding) {
|
2012-02-21 01:34:01 -08:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-07-11 03:56:00 -07:00
|
|
|
if (aAttribute == nsGkAtoms::cols ||
|
|
|
|
aAttribute == nsGkAtoms::border) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
|
|
|
}
|
|
|
|
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::frame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return aResult.ParseEnumValue(aValue, kFrameTable, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::layout) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return aResult.ParseEnumValue(aValue, kLayoutTable, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::rules) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return aResult.ParseEnumValue(aValue, kRulesTable, false);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
|
|
|
{
|
|
|
|
// 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(Table)) {
|
2011-08-20 03:18:50 -07:00
|
|
|
const nsAttrValue* value;
|
|
|
|
// layout
|
|
|
|
nsCSSValue* tableLayout = aData->ValueForTableLayout();
|
|
|
|
if (tableLayout->GetUnit() == eCSSUnit_Null) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::layout);
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum)
|
|
|
|
tableLayout->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
// cols
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::cols);
|
|
|
|
if (value) {
|
|
|
|
nsCSSValue* cols = aData->ValueForCols();
|
|
|
|
if (value->Type() == nsAttrValue::eInteger)
|
|
|
|
cols->SetIntValue(value->GetIntegerValue(), eCSSUnit_Integer);
|
|
|
|
else // COLS had no value, so it refers to all columns
|
|
|
|
cols->SetIntValue(NS_STYLE_TABLE_COLS_ALL, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -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)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLTableElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
|
|
|
{
|
|
|
|
static const MappedAttributeEntry attributes[] = {
|
|
|
|
{ &nsGkAtoms::layout },
|
|
|
|
{ &nsGkAtoms::cellpadding },
|
|
|
|
{ &nsGkAtoms::cellspacing },
|
|
|
|
{ &nsGkAtoms::cols },
|
|
|
|
{ &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
|
|
|
|
nsHTMLTableElement::GetAttributeMappingFunction() const
|
|
|
|
{
|
|
|
|
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*
|
|
|
|
nsHTMLTableElement::GetAttributesMappedForCell()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
nsHTMLTableElement::BuildInheritedAttributes()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mTableInheritedAttributes == TABLE_ATTRS_DIRTY,
|
|
|
|
"potential leak, plus waste of work");
|
|
|
|
nsIDocument *document = GetCurrentDoc();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLTableElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers)
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
return nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLTableElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2011-08-20 03:18:50 -07:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLTableElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2012-02-13 18:00:56 -08:00
|
|
|
const nsAttrValueOrString* aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
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-08-22 08:56:38 -07:00
|
|
|
nsHTMLTableElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2012-02-13 18:00:56 -08:00
|
|
|
const nsAttrValue* aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
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
|
|
|
}
|