From 05464fedb3ad6f9ce8b71c0a5732118e45fd5618 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sat, 29 Dec 2012 15:07:56 +0100 Subject: [PATCH] Fix for bug 824907 (Convert HTML table elements to WebIDL) - convert HTMLTableCellElement to WebIDL. r=bz. --HG-- rename : content/html/content/src/nsHTMLTableCellElement.cpp => content/html/content/src/HTMLTableCellElement.cpp rename : content/html/content/src/nsHTMLTableCellElement.cpp => content/html/content/src/HTMLTableCellElement.h rename : content/html/content/src/nsHTMLTableElement.cpp => content/html/content/src/HTMLTableElement.cpp rename : content/html/content/src/nsHTMLTableElement.h => content/html/content/src/HTMLTableElement.h rename : content/html/content/src/nsHTMLTableRowElement.cpp => content/html/content/src/HTMLTableRowElement.h extra : rebase_source : fcf088e7ac91a216ae7ad1cb16d509a17cd7a2a7 --- .../html/content/src/HTMLTableCellElement.cpp | 304 +++++++++++++++--- .../html/content/src/HTMLTableCellElement.h | 119 ++++++- .../html/content/src/HTMLTableRowElement.h | 2 + content/html/content/test/reflect.js | 2 - dom/bindings/Bindings.conf | 4 + dom/webidl/HTMLTableCellElement.webidl | 53 +++ dom/webidl/WebIDL.mk | 1 + js/xpconnect/src/dom_quickstubs.qsconf | 8 - 8 files changed, 436 insertions(+), 57 deletions(-) create mode 100644 dom/webidl/HTMLTableCellElement.webidl diff --git a/content/html/content/src/HTMLTableCellElement.cpp b/content/html/content/src/HTMLTableCellElement.cpp index 739f5abe5524..185e78ccc6d0 100644 --- a/content/html/content/src/HTMLTableCellElement.cpp +++ b/content/html/content/src/HTMLTableCellElement.cpp @@ -7,17 +7,13 @@ #include "mozilla/dom/HTMLTableCellElement.h" #include "mozilla/dom/HTMLTableElement.h" -#include "nsIDOMHTMLTableCellElement.h" -#include "nsIDOMHTMLTableRowElement.h" -#include "nsIDOMHTMLCollection.h" +#include "mozilla/dom/HTMLTableRowElement.h" #include "nsMappedAttributes.h" #include "nsAttrValueInlines.h" -#include "nsGkAtoms.h" -#include "nsStyleConsts.h" -#include "nsPresContext.h" #include "nsRuleData.h" #include "nsRuleWalker.h" #include "celldata.h" +#include "mozilla/dom/HTMLTableCellElementBinding.h" NS_IMPL_NS_NEW_HTML_ELEMENT(TableCell) DOMCI_NODE_DATA(HTMLTableCellElement, mozilla::dom::HTMLTableCellElement) @@ -29,6 +25,13 @@ HTMLTableCellElement::~HTMLTableCellElement() { } +JSObject* +HTMLTableCellElement::WrapNode(JSContext *aCx, JSObject *aScope, + bool *aTriedToWrap) +{ + return HTMLTableCellElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + NS_IMPL_ADDREF_INHERITED(HTMLTableCellElement, Element) NS_IMPL_RELEASE_INHERITED(HTMLTableCellElement, Element) @@ -45,11 +48,10 @@ NS_IMPL_ELEMENT_CLONE(HTMLTableCellElement) // protected method -already_AddRefed +HTMLTableRowElement* HTMLTableCellElement::GetRow() const { - nsCOMPtr row = do_QueryInterface(GetParent()); - return row.forget(); + return HTMLTableRowElement::FromContentOrNull(GetParent()); } // protected method @@ -81,14 +83,12 @@ HTMLTableCellElement::GetTable() const return nullptr; } -NS_IMETHODIMP -HTMLTableCellElement::GetCellIndex(int32_t* aCellIndex) +int32_t +HTMLTableCellElement::CellIndex() const { - *aCellIndex = -1; - - nsCOMPtr row = GetRow(); + HTMLTableRowElement* row = GetRow(); if (!row) { - return NS_OK; + return -1; } nsCOMPtr cells; @@ -96,7 +96,7 @@ HTMLTableCellElement::GetCellIndex(int32_t* aCellIndex) row->GetCells(getter_AddRefs(cells)); if (!cells) { - return NS_OK; + return -1; } uint32_t numCells; @@ -106,15 +106,20 @@ HTMLTableCellElement::GetCellIndex(int32_t* aCellIndex) nsCOMPtr node; cells->Item(i, getter_AddRefs(node)); - if (node.get() == static_cast(this)) { - *aCellIndex = i; - break; + if (node.get() == static_cast(this)) { + return i; } } - return NS_OK; + return -1; } +NS_IMETHODIMP +HTMLTableCellElement::GetCellIndex(int32_t* aCellIndex) +{ + *aCellIndex = CellIndex(); + return NS_OK; +} NS_IMETHODIMP HTMLTableCellElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) @@ -132,42 +137,249 @@ HTMLTableCellElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) return NS_OK; } - -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Abbr, abbr) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Axis, axis) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, BgColor, bgcolor) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Ch, _char) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, ChOff, charoff) -NS_IMPL_INT_ATTR_DEFAULT_VALUE(HTMLTableCellElement, ColSpan, colspan, 1) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Headers, headers) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Height, height) -NS_IMPL_BOOL_ATTR(HTMLTableCellElement, NoWrap, nowrap) -NS_IMPL_INT_ATTR_DEFAULT_VALUE(HTMLTableCellElement, RowSpan, rowspan, 1) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Scope, scope) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, VAlign, valign) -NS_IMPL_STRING_ATTR(HTMLTableCellElement, Width, width) - +NS_IMETHODIMP +HTMLTableCellElement::SetAbbr(const nsAString& aAbbr) +{ + ErrorResult rv; + SetAbbr(aAbbr, rv); + return rv.ErrorCode(); +} NS_IMETHODIMP -HTMLTableCellElement::GetAlign(nsAString& aValue) +HTMLTableCellElement::GetAbbr(nsAString& aAbbr) { - if (!GetAttr(kNameSpaceID_None, nsGkAtoms::align, aValue)) { - // There's no align attribute, ask the row for the alignment. - nsCOMPtr row = GetRow(); - if (row) { - return row->GetAlign(aValue); - } - } - + nsString abbr; + GetAbbr(abbr); + aAbbr = abbr; return NS_OK; } NS_IMETHODIMP -HTMLTableCellElement::SetAlign(const nsAString& aValue) +HTMLTableCellElement::SetAxis(const nsAString& aAxis) { - return SetAttr(kNameSpaceID_None, nsGkAtoms::align, aValue, true); + ErrorResult rv; + SetAxis(aAxis, rv); + return rv.ErrorCode(); } +NS_IMETHODIMP +HTMLTableCellElement::GetAxis(nsAString& aAxis) +{ + nsString axis; + GetAxis(axis); + aAxis = axis; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetAlign(const nsAString& aAlign) +{ + ErrorResult rv; + SetAlign(aAlign, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetAlign(nsAString& aAlign) +{ + nsString align; + GetAlign(align); + aAlign = align; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetVAlign(const nsAString& aVAlign) +{ + ErrorResult rv; + SetVAlign(aVAlign, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetVAlign(nsAString& aVAlign) +{ + nsString vAlign; + GetVAlign(vAlign); + aVAlign = vAlign; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetCh(const nsAString& aCh) +{ + ErrorResult rv; + SetCh(aCh, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetCh(nsAString& aCh) +{ + nsString ch; + GetCh(ch); + aCh = ch; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetChOff(const nsAString& aChOff) +{ + ErrorResult rv; + SetChOff(aChOff, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetChOff(nsAString& aChOff) +{ + nsString chOff; + GetChOff(chOff); + aChOff = chOff; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetBgColor(const nsAString& aBgColor) +{ + ErrorResult rv; + SetBgColor(aBgColor, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetBgColor(nsAString& aBgColor) +{ + nsString bgColor; + GetBgColor(bgColor); + aBgColor = bgColor; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetHeight(const nsAString& aHeight) +{ + ErrorResult rv; + SetHeight(aHeight, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetHeight(nsAString& aHeight) +{ + nsString height; + GetHeight(height); + aHeight = height; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetWidth(const nsAString& aWidth) +{ + ErrorResult rv; + SetWidth(aWidth, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetWidth(nsAString& aWidth) +{ + nsString width; + GetWidth(width); + aWidth = width; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetNoWrap(bool aNoWrap) +{ + ErrorResult rv; + SetNoWrap(aNoWrap, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetNoWrap(bool* aNoWrap) +{ + *aNoWrap = NoWrap(); + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetScope(const nsAString& aScope) +{ + ErrorResult rv; + SetScope(aScope, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetScope(nsAString& aScope) +{ + nsString scope; + GetScope(scope); + aScope = scope; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetHeaders(const nsAString& aHeaders) +{ + ErrorResult rv; + SetHeaders(aHeaders, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetHeaders(nsAString& aHeaders) +{ + nsString headers; + GetHeaders(headers); + aHeaders = headers; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetColSpan(int32_t aColSpan) +{ + ErrorResult rv; + SetColSpan(aColSpan, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetColSpan(int32_t* aColSpan) +{ + *aColSpan = ColSpan(); + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableCellElement::SetRowSpan(int32_t aRowSpan) +{ + ErrorResult rv; + SetRowSpan(aRowSpan, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableCellElement::GetRowSpan(int32_t* aRowSpan) +{ + *aRowSpan = RowSpan(); + return NS_OK; +} + +void +HTMLTableCellElement::GetAlign(nsString& aValue) +{ + if (!GetAttr(kNameSpaceID_None, nsGkAtoms::align, aValue)) { + // There's no align attribute, ask the row for the alignment. + HTMLTableRowElement* row = GetRow(); + if (row) { + row->GetAlign(aValue); + } + } +} static const nsAttrValue::EnumTable kCellScopeTable[] = { { "row", NS_STYLE_CELL_SCOPE_ROW }, diff --git a/content/html/content/src/HTMLTableCellElement.h b/content/html/content/src/HTMLTableCellElement.h index 1e1a555b0bd6..a8c4a25442e0 100644 --- a/content/html/content/src/HTMLTableCellElement.h +++ b/content/html/content/src/HTMLTableCellElement.h @@ -22,6 +22,7 @@ public: HTMLTableCellElement(already_AddRefed aNodeInfo) : nsGenericHTMLElement(aNodeInfo) { + SetIsDOMBinding(); } virtual ~HTMLTableCellElement(); @@ -40,6 +41,119 @@ public: // nsIDOMHTMLTableCellElement NS_DECL_NSIDOMHTMLTABLECELLELEMENT + uint32_t ColSpan() const + { + return GetIntAttr(nsGkAtoms::colspan, 1); + } + void SetColSpan(uint32_t aColSpan, ErrorResult& aError) + { + SetHTMLIntAttr(nsGkAtoms::colspan, aColSpan, aError); + } + uint32_t RowSpan() const + { + return GetIntAttr(nsGkAtoms::rowspan, 1); + } + void SetRowSpan(uint32_t aRowSpan, ErrorResult& aError) + { + SetHTMLIntAttr(nsGkAtoms::rowspan, aRowSpan, aError); + } + //already_AddRefed Headers() const; + void GetHeaders(nsString& aHeaders) + { + GetHTMLAttr(nsGkAtoms::headers, aHeaders); + } + void SetHeaders(const nsAString& aHeaders, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::headers, aHeaders, aError); + } + int32_t CellIndex() const; + + void GetAbbr(nsString& aAbbr) + { + GetHTMLAttr(nsGkAtoms::abbr, aAbbr); + } + void SetAbbr(const nsAString& aAbbr, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::abbr, aAbbr, aError); + } + void GetScope(nsString& aScope) + { + GetHTMLAttr(nsGkAtoms::scope, aScope); + } + void SetScope(const nsAString& aScope, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::scope, aScope, aError); + } + void GetAlign(nsString& aAlign); + void SetAlign(const nsAString& aAlign, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::align, aAlign, aError); + } + void GetAxis(nsString& aAxis) + { + GetHTMLAttr(nsGkAtoms::axis, aAxis); + } + void SetAxis(const nsAString& aAxis, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::axis, aAxis, aError); + } + void GetHeight(nsString& aHeight) + { + GetHTMLAttr(nsGkAtoms::height, aHeight); + } + void SetHeight(const nsAString& aHeight, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::height, aHeight, aError); + } + void GetWidth(nsString& aWidth) + { + GetHTMLAttr(nsGkAtoms::width, aWidth); + } + void SetWidth(const nsAString& aWidth, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::width, aWidth, aError); + } + void GetCh(nsString& aCh) + { + GetHTMLAttr(nsGkAtoms::_char, aCh); + } + void SetCh(const nsAString& aCh, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::_char, aCh, aError); + } + void GetChOff(nsString& aChOff) + { + GetHTMLAttr(nsGkAtoms::charoff, aChOff); + } + void SetChOff(const nsAString& aChOff, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::charoff, aChOff, aError); + } + bool NoWrap() + { + return GetBoolAttr(nsGkAtoms::nowrap); + } + void SetNoWrap(bool aNoWrap, ErrorResult& aError) + { + SetHTMLBoolAttr(nsGkAtoms::nowrap, aNoWrap, aError); + } + void GetVAlign(nsString& aVAlign) + { + GetHTMLAttr(nsGkAtoms::valign, aVAlign); + } + void SetVAlign(const nsAString& aVAlign, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::valign, aVAlign, aError); + } + void GetBgColor(nsString& aBgColor) + { + GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor); + } + void SetBgColor(const nsAString& aBgColor, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError); + } + virtual bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, const nsAString& aValue, @@ -54,9 +168,12 @@ public: virtual nsIDOMNode* AsDOMNode() { return this; } protected: + virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope, + bool *aTriedToWrap) MOZ_OVERRIDE; + HTMLTableElement* GetTable() const; - already_AddRefed GetRow() const; + HTMLTableRowElement* GetRow() const; }; } // namespace dom diff --git a/content/html/content/src/HTMLTableRowElement.h b/content/html/content/src/HTMLTableRowElement.h index 74ba6b306cd6..cd22097e13c8 100644 --- a/content/html/content/src/HTMLTableRowElement.h +++ b/content/html/content/src/HTMLTableRowElement.h @@ -20,6 +20,8 @@ class HTMLTableRowElement : public nsGenericHTMLElement, public: HTMLTableRowElement(already_AddRefed aNodeInfo); + NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableRowElement, nsGkAtoms::tr) + // nsISupports NS_DECL_ISUPPORTS_INHERITED diff --git a/content/html/content/test/reflect.js b/content/html/content/test/reflect.js index 02c667aa0324..b3dc6267fe89 100644 --- a/content/html/content/test/reflect.js +++ b/content/html/content/test/reflect.js @@ -64,9 +64,7 @@ function reflectString(aParameters) input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ], link: [ "crossOrigin" ], source: [ "media" ], - td: [ "align", "vAlign", "ch" ], textarea: [ "name", "placeholder" ], - th: [ "align", "vAlign", "ch" ], tr: [ "align", "vAlign", "ch" ], }; if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) { diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 1baaafe302c7..439f5d2bfc51 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -422,6 +422,10 @@ DOMInterfaces = { 'hasInstanceInterface': 'nsIDOMHTMLScriptElement', }, +'HTMLTableCellElement': { + 'hasInstanceInterface': 'nsIDOMHTMLTableCellElement' +}, + 'HTMLTableElement': { 'hasInstanceInterface': 'nsIDOMHTMLTableElement', 'resultNotAddRefed': [ diff --git a/dom/webidl/HTMLTableCellElement.webidl b/dom/webidl/HTMLTableCellElement.webidl new file mode 100644 index 000000000000..968f6ec289cf --- /dev/null +++ b/dom/webidl/HTMLTableCellElement.webidl @@ -0,0 +1,53 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. + * + * The origin of this IDL file is + * http://www.whatwg.org/specs/web-apps/current-work/ + * + * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and + * Opera Software ASA. You are granted a license to use, reproduce + * and create derivative works of this document. + */ + +interface HTMLTableCellElement : HTMLElement { + [SetterThrows] + attribute unsigned long colSpan; + [SetterThrows] + attribute unsigned long rowSpan; + //[PutForwards=value] readonly attribute DOMSettableTokenList headers; + [SetterThrows] + attribute DOMString headers; + readonly attribute long cellIndex; + + // Mozilla-specific extensions + [SetterThrows] + attribute DOMString abbr; + [SetterThrows] + attribute DOMString scope; +/* +}; + +partial interface HTMLTableCellElement { +*/ + [SetterThrows] + attribute DOMString align; + [SetterThrows] + attribute DOMString axis; + [SetterThrows] + attribute DOMString height; + [SetterThrows] + attribute DOMString width; + + [SetterThrows] + attribute DOMString ch; + [SetterThrows] + attribute DOMString chOff; + [SetterThrows] + attribute boolean noWrap; + [SetterThrows] + attribute DOMString vAlign; + + [TreatNullAs=EmptyString, SetterThrows] attribute DOMString bgColor; +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 518c75e18228..67629bcc45bf 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -74,6 +74,7 @@ webidl_files = \ HTMLScriptElement.webidl \ HTMLSpanElement.webidl \ HTMLTableCaptionElement.webidl \ + HTMLTableCellElement.webidl \ HTMLTableElement.webidl \ HTMLTableSectionElement.webidl \ HTMLTitleElement.webidl \ diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index 95dd348a7f93..abbcae27a651 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -180,14 +180,6 @@ members = [ 'nsIDOMHTMLSelectElement.options', 'nsIDOMHTMLSelectElement.size', 'nsIDOMHTMLStyleElement.disabled', - 'nsIDOMHTMLTableCellElement.colSpan', - 'nsIDOMHTMLTableCellElement.headers', - 'nsIDOMHTMLTableCellElement.cellIndex', - 'nsIDOMHTMLTableCellElement.rowSpan', - 'nsIDOMHTMLTableCellElement.abbr', - 'nsIDOMHTMLTableCellElement.scope', - 'nsIDOMHTMLTableCellElement.noWrap', - 'nsIDOMHTMLTableCellElement.width', 'nsIDOMHTMLTableColElement.span', 'nsIDOMHTMLTableColElement.width', 'nsIDOMHTMLTableRowElement.sectionRowIndex',