2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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-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;
|
|
|
|
|
2015-04-25 14:23:54 +00:00
|
|
|
class HTMLTableElement final : public nsGenericHTMLElement
|
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));
|
|
|
|
}
|
2016-07-21 20:40:00 +00:00
|
|
|
void SetCaption(HTMLTableCaptionElement* aCaption, ErrorResult& aError)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
DeleteCaption();
|
|
|
|
if (aCaption) {
|
2016-07-21 20:40:00 +00:00
|
|
|
nsINode::AppendChild(*aCaption, aError);
|
2012-12-29 08:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
if (aTHead && !aTHead->IsHTMLElement(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
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
if (aTFoot && !aTFoot->IsHTMLElement(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);
|
|
|
|
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetAlign(DOMString& aAlign)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::align, aAlign);
|
|
|
|
}
|
|
|
|
void SetAlign(const nsAString& aAlign, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetBorder(DOMString& aBorder)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::border, aBorder);
|
|
|
|
}
|
|
|
|
void SetBorder(const nsAString& aBorder, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetFrame(DOMString& aFrame)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::frame, aFrame);
|
|
|
|
}
|
|
|
|
void SetFrame(const nsAString& aFrame, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::frame, aFrame, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetRules(DOMString& aRules)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::rules, aRules);
|
|
|
|
}
|
|
|
|
void SetRules(const nsAString& aRules, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::rules, aRules, aError);
|
|
|
|
}
|
|
|
|
void GetSummary(nsString& aSummary)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::summary, aSummary);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetSummary(DOMString& aSummary)
|
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::summary, aSummary);
|
|
|
|
}
|
2012-12-29 08:08:15 +00:00
|
|
|
void SetSummary(const nsAString& aSummary, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::summary, aSummary, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetWidth(DOMString& aWidth)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::width, aWidth);
|
|
|
|
}
|
|
|
|
void SetWidth(const nsAString& aWidth, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetBgColor(DOMString& aBgColor)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
|
|
|
|
}
|
|
|
|
void SetBgColor(const nsAString& aBgColor, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetCellPadding(DOMString& aCellPadding)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
GetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding);
|
|
|
|
}
|
|
|
|
void SetCellPadding(const nsAString& aCellPadding, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding, aError);
|
|
|
|
}
|
2015-02-13 01:27:39 +00:00
|
|
|
void GetCellSpacing(DOMString& aCellSpacing)
|
2012-12-29 08:08:15 +00:00
|
|
|
{
|
|
|
|
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,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsAttrValue& aResult) override;
|
|
|
|
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
|
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
|
2011-08-28 10:59:34 +00:00
|
|
|
|
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aCompileEventHandlers) override;
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aNullParent = true) 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,
|
2015-08-01 05:14:06 +00:00
|
|
|
nsAttrValueOrString* aValue,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aNotify) 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,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsAttrValue* aValue, bool aNotify) 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();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-12-29 08:08:15 +00:00
|
|
|
|
|
|
|
nsIContent* GetChild(nsIAtom *aTag) const
|
|
|
|
{
|
|
|
|
for (nsIContent* cur = nsINode::GetFirstChild(); cur;
|
|
|
|
cur = cur->GetNextSibling()) {
|
2015-03-03 11:08:59 +00:00
|
|
|
if (cur->IsHTMLElement(aTag)) {
|
2012-12-29 08:08:15 +00:00
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-08-28 10:59:34 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsContentList> mTBodies;
|
|
|
|
RefPtr<TableRowsCollection> mRows;
|
2011-08-28 10:59:34 +00:00
|
|
|
// 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 */
|