2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-12-28 06:45:57 +04:00
|
|
|
#ifndef mozilla_dom_HTMLTableElement_h
|
|
|
|
#define mozilla_dom_HTMLTableElement_h
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-08-28 14:59:34 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-12-29 12:08:15 +04:00
|
|
|
#include "mozilla/dom/HTMLTableCaptionElement.h"
|
|
|
|
#include "mozilla/dom/HTMLTableSectionElement.h"
|
2011-08-28 14:59:34 +04:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-08-28 14:59:34 +04:00
|
|
|
|
|
|
|
class TableRowsCollection;
|
|
|
|
|
2015-04-25 17:23:54 +03:00
|
|
|
class HTMLTableElement final : public nsGenericHTMLElement {
|
2011-08-28 14:59:34 +04:00
|
|
|
public:
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit HTMLTableElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2011-08-28 14:59:34 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLTableElement, table)
|
2012-12-29 18:07:57 +04:00
|
|
|
|
2011-08-28 14:59:34 +04:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableCaptionElement* GetCaption() const {
|
|
|
|
return static_cast<HTMLTableCaptionElement*>(GetChild(nsGkAtoms::caption));
|
|
|
|
}
|
2016-07-21 23:40:00 +03:00
|
|
|
void SetCaption(HTMLTableCaptionElement* aCaption, ErrorResult& aError) {
|
2012-12-29 12:08:15 +04:00
|
|
|
DeleteCaption();
|
|
|
|
if (aCaption) {
|
2017-02-21 06:43:00 +03:00
|
|
|
nsCOMPtr<nsINode> firstChild = nsINode::GetFirstChild();
|
|
|
|
nsINode::InsertBefore(*aCaption, firstChild, aError);
|
2012-12-29 12:08:15 +04:00
|
|
|
}
|
|
|
|
}
|
2013-08-02 02:24:21 +04:00
|
|
|
|
|
|
|
void DeleteTFoot();
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateCaption();
|
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void DeleteCaption();
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* GetTHead() const {
|
|
|
|
return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::thead));
|
|
|
|
}
|
2012-12-29 18:07:48 +04:00
|
|
|
void SetTHead(HTMLTableSectionElement* aTHead, ErrorResult& aError) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aTHead && !aTHead->IsHTMLElement(nsGkAtoms::thead)) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteTHead();
|
2012-12-29 18:07:48 +04:00
|
|
|
if (aTHead) {
|
2017-02-21 06:43:00 +03:00
|
|
|
nsCOMPtr<nsIContent> refNode = nullptr;
|
|
|
|
for (refNode = nsINode::GetFirstChild(); refNode;
|
|
|
|
refNode = refNode->GetNextSibling()) {
|
|
|
|
if (refNode->IsHTMLElement() &&
|
|
|
|
!refNode->IsHTMLElement(nsGkAtoms::caption) &&
|
|
|
|
!refNode->IsHTMLElement(nsGkAtoms::colgroup)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:33:42 +03:00
|
|
|
nsINode::InsertBefore(*aTHead, refNode, aError);
|
2012-12-29 12:08:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateTHead();
|
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void DeleteTHead();
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* GetTFoot() const {
|
|
|
|
return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::tfoot));
|
|
|
|
}
|
2012-12-29 18:07:48 +04:00
|
|
|
void SetTFoot(HTMLTableSectionElement* aTFoot, ErrorResult& aError) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aTFoot && !aTFoot->IsHTMLElement(nsGkAtoms::tfoot)) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteTFoot();
|
2012-12-29 18:07:48 +04:00
|
|
|
if (aTFoot) {
|
|
|
|
nsINode::AppendChild(*aTFoot, aError);
|
2012-12-29 12:08:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateTFoot();
|
|
|
|
|
|
|
|
nsIHTMLCollection* TBodies();
|
2012-12-04 09:04:30 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsGenericHTMLElement> CreateTBody();
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection* Rows();
|
|
|
|
|
|
|
|
already_AddRefed<nsGenericHTMLElement> InsertRow(int32_t aIndex,
|
|
|
|
ErrorResult& aError);
|
|
|
|
void DeleteRow(int32_t aIndex, ErrorResult& aError);
|
|
|
|
|
|
|
|
void GetAlign(DOMString& aAlign) { GetHTMLAttr(nsGkAtoms::align, aAlign); }
|
|
|
|
void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
|
|
|
|
}
|
2015-02-13 04:27:39 +03:00
|
|
|
void GetBorder(DOMString& aBorder) {
|
2012-12-29 12:08:15 +04:00
|
|
|
GetHTMLAttr(nsGkAtoms::border, aBorder);
|
|
|
|
}
|
|
|
|
void SetBorder(const nsAString& aBorder, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
|
|
|
|
}
|
|
|
|
void GetFrame(DOMString& aFrame) { GetHTMLAttr(nsGkAtoms::frame, aFrame); }
|
|
|
|
void SetFrame(const nsAString& aFrame, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::frame, aFrame, aError);
|
|
|
|
}
|
|
|
|
void GetRules(DOMString& 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);
|
|
|
|
}
|
2015-02-13 04:27:39 +03:00
|
|
|
void GetSummary(DOMString& aSummary) {
|
|
|
|
GetHTMLAttr(nsGkAtoms::summary, aSummary);
|
|
|
|
}
|
2012-12-29 12:08:15 +04:00
|
|
|
void SetSummary(const nsAString& aSummary, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::summary, aSummary, aError);
|
|
|
|
}
|
|
|
|
void GetWidth(DOMString& aWidth) { GetHTMLAttr(nsGkAtoms::width, aWidth); }
|
|
|
|
void SetWidth(const nsAString& aWidth, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
|
|
|
|
}
|
2015-02-13 04:27:39 +03:00
|
|
|
void GetBgColor(DOMString& aBgColor) {
|
2012-12-29 12:08:15 +04:00
|
|
|
GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
|
|
|
|
}
|
|
|
|
void SetBgColor(const nsAString& aBgColor, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
|
|
|
|
}
|
2015-02-13 04:27:39 +03:00
|
|
|
void GetCellPadding(DOMString& aCellPadding) {
|
2012-12-29 12:08:15 +04:00
|
|
|
GetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding);
|
|
|
|
}
|
|
|
|
void SetCellPadding(const nsAString& aCellPadding, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding, aError);
|
|
|
|
}
|
2015-02-13 04:27:39 +03:00
|
|
|
void GetCellSpacing(DOMString& aCellSpacing) {
|
2012-12-29 12:08:15 +04:00
|
|
|
GetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing);
|
|
|
|
}
|
|
|
|
void SetCellSpacing(const nsAString& aCellSpacing, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing, aError);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2011-08-28 14:59:34 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
|
|
|
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction()
|
|
|
|
const override;
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2011-08-28 14:59:34 +04:00
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2011-08-28 14:59:34 +04:00
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
2019-05-29 01:47:08 +03:00
|
|
|
virtual void UnbindFromTree(bool aNullParent = true) override;
|
2011-08-28 14:59:34 +04:00
|
|
|
/**
|
|
|
|
* Called when an attribute is about to be changed
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2011-08-28 14:59:34 +04:00
|
|
|
/**
|
|
|
|
* Called when an attribute has just been changed
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2017-05-19 00:09:01 +03:00
|
|
|
bool aNotify) override;
|
2011-08-28 14:59:34 +04:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTableElement,
|
2012-01-08 03:37:43 +04:00
|
|
|
nsGenericHTMLElement)
|
2011-08-28 14:59:34 +04:00
|
|
|
nsMappedAttributes* GetAttributesMappedForCell();
|
2012-12-29 12:08:15 +04:00
|
|
|
|
2011-08-28 14:59:34 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLTableElement();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2012-12-29 12:08:15 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsIContent* GetChild(nsAtom* aTag) const {
|
2012-12-29 12:08:15 +04:00
|
|
|
for (nsIContent* cur = nsINode::GetFirstChild(); cur;
|
|
|
|
cur = cur->GetNextSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (cur->IsHTMLElement(aTag)) {
|
2012-12-29 12:08:15 +04:00
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-08-28 14:59:34 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsContentList> mTBodies;
|
|
|
|
RefPtr<TableRowsCollection> mRows;
|
2011-08-28 14:59:34 +04:00
|
|
|
nsMappedAttributes* mTableInheritedAttributes;
|
|
|
|
void BuildInheritedAttributes();
|
2013-02-14 19:33:16 +04:00
|
|
|
void ReleaseInheritedAttributes();
|
2013-11-19 23:21:29 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2018-06-22 19:48:42 +03:00
|
|
|
MappedDeclarations&);
|
2011-08-28 14:59:34 +04:00
|
|
|
};
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_HTMLTableElement_h */
|