2011-08-28 10:59:34 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-12-28 02:45:57 +00:00
|
|
|
#ifndef mozilla_dom_HTMLTableElement_h
|
|
|
|
#define mozilla_dom_HTMLTableElement_h
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-08-28 10:59:34 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-12-28 02:45:57 +00:00
|
|
|
#include "nsIDOMHTMLTableElement.h"
|
2012-12-29 08:08:15 +00:00
|
|
|
#include "mozilla/dom/HTMLTableCaptionElement.h"
|
|
|
|
#include "mozilla/dom/HTMLTableSectionElement.h"
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
#define TABLE_ATTRS_DIRTY ((nsMappedAttributes*)0x1)
|
2011-08-28 10:59:34 +00:00
|
|
|
|
|
|
|
class TableRowsCollection;
|
|
|
|
|
2013-07-11 21:26:54 +00:00
|
|
|
class HTMLTableElement MOZ_FINAL : public nsGenericHTMLElement,
|
|
|
|
public nsIDOMHTMLTableElement
|
2011-08-28 10:59:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit HTMLTableElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2013-01-05 19:45:06 +00:00
|
|
|
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableElement, table)
|
2012-12-29 14:07:57 +00:00
|
|
|
|
2011-08-28 10:59:34 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableCaptionElement* GetCaption() const
|
|
|
|
{
|
|
|
|
return static_cast<HTMLTableCaptionElement*>(GetChild(nsGkAtoms::caption));
|
|
|
|
}
|
|
|
|
void SetCaption(HTMLTableCaptionElement* aCaption)
|
|
|
|
{
|
|
|
|
DeleteCaption();
|
|
|
|
if (aCaption) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::AppendChild(*aCaption, rv);
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 22:24:21 +00:00
|
|
|
|
|
|
|
void DeleteTFoot();
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateCaption();
|
|
|
|
|
2013-08-01 22:24:21 +00:00
|
|
|
void DeleteCaption();
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableSectionElement* GetTHead() const
|
|
|
|
{
|
|
|
|
return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::thead));
|
|
|
|
}
|
2012-12-29 14:07:48 +00:00
|
|
|
void SetTHead(HTMLTableSectionElement* aTHead, ErrorResult& aError)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
2013-01-10 09:57:19 +00:00
|
|
|
if (aTHead && !aTHead->IsHTML(nsGkAtoms::thead)) {
|
2012-12-29 08:08:15 +00:00
|
|
|
aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteTHead();
|
2012-12-29 14:07:48 +00:00
|
|
|
if (aTHead) {
|
|
|
|
nsINode::InsertBefore(*aTHead, nsINode::GetFirstChild(), aError);
|
2012-12-29 08:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateTHead();
|
|
|
|
|
2013-08-01 22:24:21 +00:00
|
|
|
void DeleteTHead();
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
HTMLTableSectionElement* GetTFoot() const
|
|
|
|
{
|
|
|
|
return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::tfoot));
|
|
|
|
}
|
2012-12-29 14:07:48 +00:00
|
|
|
void SetTFoot(HTMLTableSectionElement* aTFoot, ErrorResult& aError)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
2013-01-10 09:57:19 +00:00
|
|
|
if (aTFoot && !aTFoot->IsHTML(nsGkAtoms::tfoot)) {
|
2012-12-29 08:08:15 +00:00
|
|
|
aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteTFoot();
|
2012-12-29 14:07:48 +00:00
|
|
|
if (aTFoot) {
|
|
|
|
nsINode::AppendChild(*aTFoot, aError);
|
2012-12-29 08:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateTFoot();
|
|
|
|
|
|
|
|
nsIHTMLCollection* TBodies();
|
2012-12-04 05:04:30 +00:00
|
|
|
|
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateTBody();
|
|
|
|
|
2012-12-29 08:08:15 +00:00
|
|
|
nsIHTMLCollection* Rows();
|
|
|
|
|
|
|
|
already_AddRefed<nsGenericHTMLElement> InsertRow(int32_t aIndex,
|
|
|
|
ErrorResult& aError);
|
|
|
|
void DeleteRow(int32_t aIndex, ErrorResult& aError);
|
|
|
|
|
|
|
|
void GetAlign(nsString& aAlign)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::align, aAlign);
|
|
|
|
}
|
|
|
|
void SetAlign(const nsAString& aAlign, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
|
|
|
|
}
|
|
|
|
void GetBorder(nsString& aBorder)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::border, aBorder);
|
|
|
|
}
|
|
|
|
void SetBorder(const nsAString& aBorder, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
|
|
|
|
}
|
|
|
|
void GetFrame(nsString& aFrame)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::frame, aFrame);
|
|
|
|
}
|
|
|
|
void SetFrame(const nsAString& aFrame, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::frame, aFrame, aError);
|
|
|
|
}
|
|
|
|
void GetRules(nsString& aRules)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::rules, aRules);
|
|
|
|
}
|
|
|
|
void SetRules(const nsAString& aRules, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::rules, aRules, aError);
|
|
|
|
}
|
|
|
|
void GetSummary(nsString& aSummary)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::summary, aSummary);
|
|
|
|
}
|
|
|
|
void SetSummary(const nsAString& aSummary, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::summary, aSummary, aError);
|
|
|
|
}
|
|
|
|
void GetWidth(nsString& aWidth)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::width, aWidth);
|
|
|
|
}
|
|
|
|
void SetWidth(const nsAString& aWidth, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
|
|
|
|
}
|
|
|
|
void GetBgColor(nsString& aBgColor)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
|
|
|
|
}
|
|
|
|
void SetBgColor(const nsAString& aBgColor, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
|
|
|
|
}
|
|
|
|
void GetCellPadding(nsString& aCellPadding)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding);
|
|
|
|
}
|
|
|
|
void SetCellPadding(const nsAString& aCellPadding, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding, aError);
|
|
|
|
}
|
|
|
|
void GetCellSpacing(nsString& aCellSpacing)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing);
|
|
|
|
}
|
|
|
|
void SetCellSpacing(const nsAString& aCellSpacing, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing, aError);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
2011-08-28 10:59:34 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2013-05-29 20:43:41 +00:00
|
|
|
nsAttrValue& aResult) MOZ_OVERRIDE;
|
|
|
|
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
|
2011-08-28 10:59:34 +00:00
|
|
|
|
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2013-05-29 20:43:41 +00:00
|
|
|
bool aCompileEventHandlers) MOZ_OVERRIDE;
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
2013-05-29 20:43:41 +00:00
|
|
|
bool aNullParent = true) MOZ_OVERRIDE;
|
2011-08-28 10:59:34 +00:00
|
|
|
/**
|
|
|
|
* Called when an attribute is about to be changed
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2012-02-14 02:00:56 +00:00
|
|
|
const nsAttrValueOrString* aValue,
|
2013-05-29 20:43:41 +00:00
|
|
|
bool aNotify) MOZ_OVERRIDE;
|
2011-08-28 10:59:34 +00:00
|
|
|
/**
|
|
|
|
* Called when an attribute has just been changed
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2013-05-29 20:43:41 +00:00
|
|
|
const nsAttrValue* aValue, bool aNotify) MOZ_OVERRIDE;
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTableElement,
|
2012-01-07 23:37:43 +00:00
|
|
|
nsGenericHTMLElement)
|
2011-08-28 10:59:34 +00:00
|
|
|
nsMappedAttributes* GetAttributesMappedForCell();
|
2012-12-29 08:08:15 +00:00
|
|
|
|
2011-08-28 10:59:34 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~HTMLTableElement();
|
|
|
|
|
2014-04-08 22:27:17 +00:00
|
|
|
virtual JSObject* WrapNode(JSContext *aCx) MOZ_OVERRIDE;
|
2012-12-29 08:08:15 +00:00
|
|
|
|
|
|
|
nsIContent* GetChild(nsIAtom *aTag) const
|
|
|
|
{
|
|
|
|
for (nsIContent* cur = nsINode::GetFirstChild(); cur;
|
|
|
|
cur = cur->GetNextSibling()) {
|
|
|
|
if (cur->IsHTML(aTag)) {
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-08-28 10:59:34 +00:00
|
|
|
|
|
|
|
nsRefPtr<nsContentList> mTBodies;
|
|
|
|
nsRefPtr<TableRowsCollection> mRows;
|
|
|
|
// Sentinel value of TABLE_ATTRS_DIRTY indicates that this is dirty and needs
|
|
|
|
// to be recalculated.
|
|
|
|
nsMappedAttributes *mTableInheritedAttributes;
|
|
|
|
void BuildInheritedAttributes();
|
2013-02-14 15:33:16 +00:00
|
|
|
void ReleaseInheritedAttributes();
|
2013-11-19 19:21:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData);
|
2011-08-28 10:59:34 +00:00
|
|
|
};
|
|
|
|
|
2012-12-28 02:45:57 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_HTMLTableElement_h */
|