From 429830ebec892773759f99a0aa5a7a1a0fdeeded Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sat, 29 Dec 2012 15:07:57 +0100 Subject: [PATCH] Fix for bug 824907 (Convert HTML table elements to WebIDL) - convert HTMLTableRowElement to WebIDL. r=bz. --HG-- extra : rebase_source : d2febac66f508caf3c2b89816e811ed8e2c88856 --- .../html/content/src/HTMLTableCellElement.cpp | 14 +- content/html/content/src/HTMLTableElement.h | 2 + .../html/content/src/HTMLTableRowElement.cpp | 272 ++++++++++++------ .../html/content/src/HTMLTableRowElement.h | 58 +++- content/html/content/test/reflect.js | 1 - dom/bindings/Bindings.conf | 7 + dom/webidl/HTMLTableRowElement.webidl | 37 +++ dom/webidl/WebIDL.mk | 1 + js/xpconnect/src/dom_quickstubs.qsconf | 5 - 9 files changed, 284 insertions(+), 113 deletions(-) create mode 100644 dom/webidl/HTMLTableRowElement.webidl diff --git a/content/html/content/src/HTMLTableCellElement.cpp b/content/html/content/src/HTMLTableCellElement.cpp index 185e78ccc6d..01100600da7 100644 --- a/content/html/content/src/HTMLTableCellElement.cpp +++ b/content/html/content/src/HTMLTableCellElement.cpp @@ -91,22 +91,14 @@ HTMLTableCellElement::CellIndex() const return -1; } - nsCOMPtr cells; - - row->GetCells(getter_AddRefs(cells)); - + nsIHTMLCollection* cells = row->Cells(); if (!cells) { return -1; } - uint32_t numCells; - cells->GetLength(&numCells); - + uint32_t numCells = cells->Length(); for (uint32_t i = 0; i < numCells; i++) { - nsCOMPtr node; - cells->Item(i, getter_AddRefs(node)); - - if (node.get() == static_cast(this)) { + if (cells->Item(i) == this) { return i; } } diff --git a/content/html/content/src/HTMLTableElement.h b/content/html/content/src/HTMLTableElement.h index 15087a6769c..092a908e51d 100644 --- a/content/html/content/src/HTMLTableElement.h +++ b/content/html/content/src/HTMLTableElement.h @@ -25,6 +25,8 @@ public: HTMLTableElement(already_AddRefed aNodeInfo); virtual ~HTMLTableElement(); + NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableElement, nsGkAtoms::table) + // nsISupports NS_DECL_ISUPPORTS_INHERITED diff --git a/content/html/content/src/HTMLTableRowElement.cpp b/content/html/content/src/HTMLTableRowElement.cpp index d441834ba9e..86a6845d500 100644 --- a/content/html/content/src/HTMLTableRowElement.cpp +++ b/content/html/content/src/HTMLTableRowElement.cpp @@ -6,17 +6,12 @@ #include "mozilla/Util.h" #include "mozilla/dom/HTMLTableRowElement.h" -#include "nsIDOMHTMLTableElement.h" -#include "nsIDOMHTMLTableSectionElement.h" -#include "nsIDOMHTMLTableCellElement.h" +#include "mozilla/dom/HTMLTableElement.h" #include "nsMappedAttributes.h" #include "nsAttrValueInlines.h" -#include "nsContentList.h" -#include "nsGkAtoms.h" -#include "nsStyleConsts.h" -#include "nsHTMLParts.h" #include "nsRuleData.h" -#include "nsContentUtils.h" +#include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/HTMLTableRowElementBinding.h" NS_IMPL_NS_NEW_HTML_ELEMENT(TableRow) DOMCI_NODE_DATA(HTMLTableRowElement, mozilla::dom::HTMLTableRowElement) @@ -24,9 +19,11 @@ DOMCI_NODE_DATA(HTMLTableRowElement, mozilla::dom::HTMLTableRowElement) namespace mozilla { namespace dom { -HTMLTableRowElement::HTMLTableRowElement(already_AddRefed aNodeInfo) - : nsGenericHTMLElement(aNodeInfo) +JSObject* +HTMLTableRowElement::WrapNode(JSContext *aCx, JSObject *aScope, + bool *aTriedToWrap) { + return HTMLTableRowElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); } NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableRowElement) @@ -60,7 +57,7 @@ HTMLTableRowElement::GetSection() const } // protected method -already_AddRefed +HTMLTableElement* HTMLTableRowElement::GetTable() const { nsIContent* parent = GetParent(); @@ -69,50 +66,48 @@ HTMLTableRowElement::GetTable() const } // We may not be in a section - nsCOMPtr table = do_QueryInterface(parent); + HTMLTableElement* table = HTMLTableElement::FromContent(parent); if (table) { - return table.forget(); + return table; } - parent = parent->GetParent(); - if (!parent) { - return nullptr; + return HTMLTableElement::FromContentOrNull(parent->GetParent()); +} + +int32_t +HTMLTableRowElement::RowIndex() const +{ + HTMLTableElement* table = GetTable(); + if (!table) { + return -1; } - table = do_QueryInterface(parent); - return table.forget(); + + nsIHTMLCollection* rows = table->Rows(); + + uint32_t numRows = rows->Length(); + + for (uint32_t i = 0; i < numRows; i++) { + if (rows->GetElementAt(i) == this) { + return i; + } + } + + return -1; } NS_IMETHODIMP HTMLTableRowElement::GetRowIndex(int32_t* aValue) { - *aValue = -1; - nsCOMPtr table = GetTable(); - if (!table) { - return NS_OK; - } - - nsCOMPtr rows; - table->GetRows(getter_AddRefs(rows)); - - nsCOMPtr coll = do_QueryInterface(rows); - uint32_t numRows = coll->Length(); - - for (uint32_t i = 0; i < numRows; i++) { - if (coll->GetElementAt(i) == this) { - *aValue = i; - break; - } - } + *aValue = RowIndex(); return NS_OK; } -NS_IMETHODIMP -HTMLTableRowElement::GetSectionRowIndex(int32_t* aValue) +int32_t +HTMLTableRowElement::SectionRowIndex() const { - *aValue = -1; nsCOMPtr section = GetSection(); if (!section) { - return NS_OK; + return -1; } nsCOMPtr rows; @@ -122,11 +117,17 @@ HTMLTableRowElement::GetSectionRowIndex(int32_t* aValue) uint32_t numRows = coll->Length(); for (uint32_t i = 0; i < numRows; i++) { if (coll->GetElementAt(i) == this) { - *aValue = i; - break; + return i; } } + return -1; +} + +NS_IMETHODIMP +HTMLTableRowElement::GetSectionRowIndex(int32_t* aValue) +{ + *aValue = SectionRowIndex(); return NS_OK; } @@ -140,8 +141,8 @@ IsCell(nsIContent *aContent, int32_t aNamespaceID, aContent->IsHTML()); } -NS_IMETHODIMP -HTMLTableRowElement::GetCells(nsIDOMHTMLCollection** aValue) +nsIHTMLCollection* +HTMLTableRowElement::Cells() { if (!mCells) { mCells = new nsContentList(this, @@ -154,40 +155,42 @@ HTMLTableRowElement::GetCells(nsIDOMHTMLCollection** aValue) false); } - NS_ADDREF(*aValue = mCells); - return NS_OK; + return mCells; } NS_IMETHODIMP -HTMLTableRowElement::InsertCell(int32_t aIndex, nsIDOMHTMLElement** aValue) +HTMLTableRowElement::GetCells(nsIDOMHTMLCollection** aValue) { - *aValue = nullptr; + NS_ADDREF(*aValue = Cells()); + return NS_OK; +} +already_AddRefed +HTMLTableRowElement::InsertCell(int32_t aIndex, + ErrorResult& aError) +{ if (aIndex < -1) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; + aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return nullptr; } // Make sure mCells is initialized. - nsCOMPtr cells; - nsresult rv = GetCells(getter_AddRefs(cells)); - if (NS_FAILED(rv)) { - return rv; - } + nsIHTMLCollection* cells = Cells(); NS_ASSERTION(mCells, "How did that happen?"); - nsCOMPtr nextSibling; + nsCOMPtr nextSibling; // -1 means append, so should use null nextSibling if (aIndex != -1) { - cells->Item(aIndex, getter_AddRefs(nextSibling)); + nextSibling = cells->Item(aIndex); // Check whether we're inserting past end of list. We want to avoid doing // this unless we really have to, since this has to walk all our kids. If // we have a nextSibling, we're clearly not past end of list. if (!nextSibling) { - uint32_t cellCount; - cells->GetLength(&cellCount); + uint32_t cellCount = cells->Length(); if (aIndex > int32_t(cellCount)) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; + aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return nullptr; } } } @@ -197,43 +200,41 @@ HTMLTableRowElement::InsertCell(int32_t aIndex, nsIDOMHTMLElement** aValue) nsContentUtils::NameChanged(mNodeInfo, nsGkAtoms::td, getter_AddRefs(nodeInfo)); - nsCOMPtr cellContent = NS_NewHTMLTableCellElement(nodeInfo.forget()); - if (!cellContent) { - return NS_ERROR_OUT_OF_MEMORY; + nsRefPtr cell = + NS_NewHTMLTableCellElement(nodeInfo.forget()); + if (!cell) { + aError.Throw(NS_ERROR_OUT_OF_MEMORY); + return nullptr; } - nsCOMPtr cellNode(do_QueryInterface(cellContent)); - NS_ASSERTION(cellNode, "Should implement nsIDOMNode!"); + nsINode::InsertBefore(*cell, nextSibling, aError); - nsCOMPtr retChild; - InsertBefore(cellNode, nextSibling, getter_AddRefs(retChild)); - - if (retChild) { - CallQueryInterface(retChild, aValue); - } - - return NS_OK; + return cell.forget(); } - NS_IMETHODIMP -HTMLTableRowElement::DeleteCell(int32_t aValue) +HTMLTableRowElement::InsertCell(int32_t aIndex, nsIDOMHTMLElement** aValue) +{ + ErrorResult rv; + nsRefPtr cell = InsertCell(aIndex, rv); + return rv.Failed() ? rv.ErrorCode() : CallQueryInterface(cell, aValue); +} + +void +HTMLTableRowElement::DeleteCell(int32_t aValue, ErrorResult& aError) { if (aValue < -1) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; + aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return; } - nsCOMPtr cells; - GetCells(getter_AddRefs(cells)); + nsIHTMLCollection* cells = Cells(); - nsresult rv; uint32_t refIndex; if (aValue == -1) { - rv = cells->GetLength(&refIndex); - NS_ENSURE_SUCCESS(rv, rv); - + refIndex = cells->Length(); if (refIndex == 0) { - return NS_OK; + return; } --refIndex; @@ -242,24 +243,107 @@ HTMLTableRowElement::DeleteCell(int32_t aValue) refIndex = (uint32_t)aValue; } - nsCOMPtr cell; - rv = cells->Item(refIndex, getter_AddRefs(cell)); - NS_ENSURE_SUCCESS(rv, rv); - + nsCOMPtr cell = cells->Item(refIndex); if (!cell) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; + aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return; } - nsCOMPtr retChild; - return RemoveChild(cell, getter_AddRefs(retChild)); + nsINode::RemoveChild(*cell, aError); } -NS_IMPL_STRING_ATTR(HTMLTableRowElement, Align, align) -NS_IMPL_STRING_ATTR(HTMLTableRowElement, BgColor, bgcolor) -NS_IMPL_STRING_ATTR(HTMLTableRowElement, Ch, _char) -NS_IMPL_STRING_ATTR(HTMLTableRowElement, ChOff, charoff) -NS_IMPL_STRING_ATTR(HTMLTableRowElement, VAlign, valign) +NS_IMETHODIMP +HTMLTableRowElement::DeleteCell(int32_t aValue) +{ + ErrorResult rv; + DeleteCell(aValue, rv); + return rv.ErrorCode(); +} +NS_IMETHODIMP +HTMLTableRowElement::SetAlign(const nsAString& aAlign) +{ + ErrorResult rv; + SetAlign(aAlign, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableRowElement::GetAlign(nsAString& aAlign) +{ + nsString align; + GetAlign(align); + aAlign = align; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableRowElement::SetVAlign(const nsAString& aVAlign) +{ + ErrorResult rv; + SetVAlign(aVAlign, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableRowElement::GetVAlign(nsAString& aVAlign) +{ + nsString vAlign; + GetVAlign(vAlign); + aVAlign = vAlign; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableRowElement::SetCh(const nsAString& aCh) +{ + ErrorResult rv; + SetCh(aCh, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableRowElement::GetCh(nsAString& aCh) +{ + nsString ch; + GetCh(ch); + aCh = ch; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableRowElement::SetChOff(const nsAString& aChOff) +{ + ErrorResult rv; + SetChOff(aChOff, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableRowElement::GetChOff(nsAString& aChOff) +{ + nsString chOff; + GetChOff(chOff); + aChOff = chOff; + return NS_OK; +} + +NS_IMETHODIMP +HTMLTableRowElement::SetBgColor(const nsAString& aBgColor) +{ + ErrorResult rv; + SetBgColor(aBgColor, rv); + return rv.ErrorCode(); +} + +NS_IMETHODIMP +HTMLTableRowElement::GetBgColor(nsAString& aBgColor) +{ + nsString bgColor; + GetBgColor(bgColor); + aBgColor = bgColor; + return NS_OK; +} bool HTMLTableRowElement::ParseAttribute(int32_t aNamespaceID, diff --git a/content/html/content/src/HTMLTableRowElement.h b/content/html/content/src/HTMLTableRowElement.h index cd22097e13c..fd1fec1db92 100644 --- a/content/html/content/src/HTMLTableRowElement.h +++ b/content/html/content/src/HTMLTableRowElement.h @@ -18,7 +18,11 @@ class HTMLTableRowElement : public nsGenericHTMLElement, public nsIDOMHTMLTableRowElement { public: - HTMLTableRowElement(already_AddRefed aNodeInfo); + HTMLTableRowElement(already_AddRefed aNodeInfo) + : nsGenericHTMLElement(aNodeInfo) + { + SetIsDOMBinding(); + } NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableRowElement, nsGkAtoms::tr) @@ -37,6 +41,54 @@ public: // nsIDOMHTMLTableRowElement NS_DECL_NSIDOMHTMLTABLEROWELEMENT + int32_t RowIndex() const; + int32_t SectionRowIndex() const; + nsIHTMLCollection* Cells(); + already_AddRefed + InsertCell(int32_t aIndex, ErrorResult& aError); + void DeleteCell(int32_t aValue, ErrorResult& aError); + + void GetAlign(nsString& aAlign) + { + GetHTMLAttr(nsGkAtoms::align, aAlign); + } + void SetAlign(const nsAString& aAlign, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::align, aAlign, 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); + } + 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,8 +106,10 @@ public: nsGenericHTMLElement) protected: + JSObject* WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap); + already_AddRefed GetSection() const; - already_AddRefed GetTable() const; + HTMLTableElement* GetTable() const; nsRefPtr mCells; }; diff --git a/content/html/content/test/reflect.js b/content/html/content/test/reflect.js index b3dc6267fe8..b118cf9ae40 100644 --- a/content/html/content/test/reflect.js +++ b/content/html/content/test/reflect.js @@ -65,7 +65,6 @@ function reflectString(aParameters) link: [ "crossOrigin" ], source: [ "media" ], textarea: [ "name", "placeholder" ], - tr: [ "align", "vAlign", "ch" ], }; if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) { is(element.getAttribute(contentAttr), "null", diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 439f5d2bfc5..ebd5899c5e3 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -433,6 +433,13 @@ DOMInterfaces = { ] }, +'HTMLTableRowElement': { + 'hasInstanceInterface': 'nsIDOMHTMLTableRowElement', + 'resultNotAddRefed': [ + 'cells' + ] +}, + 'HTMLTableSectionElement': { 'hasInstanceInterface': 'nsIDOMHTMLTableSectionElement', 'resultNotAddRefed': [ diff --git a/dom/webidl/HTMLTableRowElement.webidl b/dom/webidl/HTMLTableRowElement.webidl new file mode 100644 index 00000000000..8791179387c --- /dev/null +++ b/dom/webidl/HTMLTableRowElement.webidl @@ -0,0 +1,37 @@ +/* -*- 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 HTMLTableRowElement : HTMLElement { + readonly attribute long rowIndex; + readonly attribute long sectionRowIndex; + readonly attribute HTMLCollection cells; + [Throws] + HTMLElement insertCell(optional long index = -1); + [Throws] + void deleteCell(long index); +/* +}; + +partial interface HTMLTableRowElement { +*/ + [SetterThrows] + attribute DOMString align; + [SetterThrows] + attribute DOMString ch; + [SetterThrows] + attribute DOMString chOff; + [SetterThrows] + attribute DOMString vAlign; + + [TreatNullAs=EmptyString, SetterThrows] attribute DOMString bgColor; +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 67629bcc45b..7cbad704990 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -76,6 +76,7 @@ webidl_files = \ HTMLTableCaptionElement.webidl \ HTMLTableCellElement.webidl \ HTMLTableElement.webidl \ + HTMLTableRowElement.webidl \ HTMLTableSectionElement.webidl \ HTMLTitleElement.webidl \ HTMLUListElement.webidl \ diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index abbcae27a65..a75857b3561 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -182,11 +182,6 @@ members = [ 'nsIDOMHTMLStyleElement.disabled', 'nsIDOMHTMLTableColElement.span', 'nsIDOMHTMLTableColElement.width', - 'nsIDOMHTMLTableRowElement.sectionRowIndex', - 'nsIDOMHTMLTableRowElement.rowIndex', - 'nsIDOMHTMLTableRowElement.cells', - 'nsIDOMHTMLTableRowElement.deleteCell', - 'nsIDOMHTMLTableRowElement.insertCell', 'nsIDOMHTMLTextAreaElement.rows', 'nsIDOMHTMLTextAreaElement.name', 'nsIDOMHTMLTextAreaElement.form',