Skip to content

Commit dd4b4af

Browse files
committed
Parametrize HtmlCollection class with the type of the element
1 parent 1b07261 commit dd4b4af

15 files changed

+1031
-1039
lines changed

api-reports/2_12.txt

Lines changed: 503 additions & 503 deletions
Large diffs are not rendered by default.

api-reports/2_13.txt

Lines changed: 503 additions & 503 deletions
Large diffs are not rendered by default.

src/main/scala/org/scalajs/dom/Document.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ abstract class Document extends Node with NodeSelector with DocumentEvent with P
5151
* root node. The returned HTMLCollection is live, meaning that it updates itself automatically to stay in sync with
5252
* the DOM tree without having to call document.getElementsByTagName again.
5353
*/
54-
def getElementsByTagName(name: String): HTMLCollection = js.native
54+
def getElementsByTagName(name: String): HTMLCollection[Element] = js.native
5555

5656
/** Returns a list of elements with the given tag name belonging to the given namespace. The complete document is
5757
* searched, including the root node.
5858
*/
59-
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection = js.native
59+
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection[Element] = js.native
6060

6161
/** Returns a set of elements which have all the given class names. When called on the document object, the complete
6262
* document is searched, including the root node. You may also call getElementsByClassName on any element; it will
6363
* return only elements which are descendants of the specified root element with the given class names.
6464
*/
65-
def getElementsByClassName(classNames: String): HTMLCollection = js.native
65+
def getElementsByClassName(classNames: String): HTMLCollection[Element] = js.native
6666

6767
/** Returns the element from the document whose elementFromPoint method is being called which is the topmost element
6868
* which lies under the given point.  To get an element, specify the point via coordinates, in CSS pixels, relative

src/main/scala/org/scalajs/dom/Element.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ abstract class Element extends Node with NodeSelector with ParentNode with NonDo
167167
* automatically. Consequently, there is no need to call several times element.getElementsByTagName with the same
168168
* element and arguments.
169169
*/
170-
def getElementsByTagName(name: String): HTMLCollection = js.native
170+
def getElementsByTagName(name: String): HTMLCollection[Element] = js.native
171171

172172
/** Returns a list of elements with the given tag name belonging to the given namespace. */
173-
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection = js.native
173+
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection[Element] = js.native
174174

175175
/** Returns an array-like object of all child elements which have all of the given class names. When called on the
176176
* document object, the complete document is searched, including the root node. You may also call
177177
* getElementsByClassName() on any element; it will return only elements which are descendants of the specified root
178178
* element with the given class names.
179179
*/
180-
def getElementsByClassName(classNames: String): HTMLCollection = js.native
180+
def getElementsByClassName(classNames: String): HTMLCollection[Element] = js.native
181181

182182
/** hasAttributeNS returns a boolean value indicating whether the current element has the specified attribute. */
183183
def hasAttributeNS(namespaceURI: String, localName: String): Boolean = js.native

src/main/scala/org/scalajs/dom/HTMLCollection.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import scala.scalajs.js.annotation._
1414
*/
1515
@js.native
1616
@JSGlobal
17-
abstract class HTMLCollection extends DOMList[Element] {
18-
def item(index: Int): Element = js.native
17+
abstract class HTMLCollection[E <: Element] extends DOMList[E] {
18+
def item(index: Int): E = js.native
1919

2020
/** Returns the specific node whose ID or, as a fallback, name matches the string specified by name. Matching by name
2121
* is only done as a last resort, only in HTML, and only if the referenced element supports the name attribute.
2222
* Returns null if no node exists by the given name.
2323
*/
24-
def namedItem(name: String): Element = js.native
24+
def namedItem(name: String): E = js.native
2525
}

src/main/scala/org/scalajs/dom/HTMLDataListElement.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ import scala.scalajs.js.annotation._
1717
abstract class HTMLDataListElement extends HTMLElement {
1818

1919
/** A collection of the contained option elements. */
20-
def options: HTMLCollection = js.native
20+
def options: HTMLCollection[Element] = js.native
2121
}

src/main/scala/org/scalajs/dom/HTMLDocument.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ abstract class HTMLDocument extends Document {
6868
def activeElement: Element = js.native
6969

7070
/** Returns a list of the embedded &lt;embed&gt; elements within the current document. */
71-
def embeds: HTMLCollection = js.native
71+
def embeds: HTMLCollection[Element] = js.native
7272

7373
/** forms returns a collection (an HTMLCollection) of the form elements within the current document. */
74-
def forms: HTMLCollection = js.native
74+
def forms: HTMLCollection[Element] = js.native
7575

7676
/** The links property returns a collection of all AREA elements and anchor elements in a document with a value for
7777
* the href attribute.
7878
*/
79-
def links: HTMLCollection = js.native
79+
def links: HTMLCollection[Element] = js.native
8080

8181
/** anchors returns a list of all of the anchors in the document. */
82-
def anchors: HTMLCollection = js.native
82+
def anchors: HTMLCollection[Element] = js.native
8383

8484
/** Returns an HTMLCollection object containing one or more HTMLEmbedElements or null which represent the
8585
* &lt;embed&gt; elements in the current document.
8686
*/
87-
def plugins: HTMLCollection = js.native
87+
def plugins: HTMLCollection[Element] = js.native
8888

8989
/** document.images returns a collection of the images in the current HTML document. */
90-
def images: HTMLCollection = js.native
90+
def images: HTMLCollection[Element] = js.native
9191

9292
/** Returns the current value of the current range for a formatting command. */
9393
def queryCommandValue(commandId: String): String = js.native

src/main/scala/org/scalajs/dom/HTMLFormElement.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class HTMLFormElement extends HTMLElement {
3333
/** elements returns an HTMLFormControlsCollection (HTML 4 HTMLCollection) of all the form controls contained in the
3434
* FORM element, with the exception of input elements which have a type attribute of image.
3535
*/
36-
def elements: HTMLCollection = js.native
36+
def elements: HTMLCollection[Element] = js.native
3737

3838
/** action gets/sets the action of the &lt;form&gt; element. */
3939
var action: String = js.native

src/main/scala/org/scalajs/dom/HTMLOptionsCollection.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,4 @@ import scala.scalajs.js.annotation._
1515
*/
1616
@js.native
1717
@JSGlobal
18-
class HTMLOptionsCollection private[this] () extends HTMLCollection {
19-
override def item(index: Int): HTMLOptionElement = js.native
20-
21-
/** Returns the specific node whose ID or, as a fallback, name matches the string specified by name. Matching by name
22-
* is only done as a last resort, only in HTML, and only if the referenced element supports the name attribute.
23-
* Returns null if no node exists by the given name.
24-
*/
25-
override def namedItem(name: String): HTMLOptionElement = js.native
26-
}
18+
class HTMLOptionsCollection private[this] () extends HTMLCollection[HTMLOptionElement]

src/main/scala/org/scalajs/dom/HTMLTableElement.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class HTMLTableElement extends HTMLElement {
3030
* a &lt;thead&gt; appear first, in tree order, and those members of a &lt;tbody&gt; last, also in tree order. The
3131
* HTMLCollection is live and is automatically updated when the HTMLTableElement changes.
3232
*/
33-
def rows: HTMLCollection = js.native
33+
def rows: HTMLCollection[Element] = js.native
3434

3535
/** Is an HTMLTableCaptionElement representing the first &lt;caption&gt; that is a child of the element, or null if
3636
* none is found. When set, if the object doesn't represent a &lt;caption&gt;, a DOMException with the
@@ -42,7 +42,7 @@ abstract class HTMLTableElement extends HTMLElement {
4242
/** Returns a live HTMLCollection containing all the &lt;tbody&gt; of the element. The HTMLCollection is live and is
4343
* automatically updated when the HTMLTableElement changes.
4444
*/
45-
def tBodies: HTMLCollection = js.native
45+
def tBodies: HTMLCollection[Element] = js.native
4646

4747
/** Is an HTMLTableSectionElement representing the first &lt;thead&gt; that is a child of the element, or null if none
4848
* is found. When set, if the object doesn't represent a &lt;thead&gt;, a DOMException with the HierarchyRequestError

src/main/scala/org/scalajs/dom/HTMLTableRowElement.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class HTMLTableRowElement extends HTMLElement with HTMLTableAlignment {
2424
/** Returns a live HTMLCollection containing the cells in the row. The HTMLCollection is live and is automatically
2525
* updated when cells are added or removed.
2626
*/
27-
def cells: HTMLCollection = js.native
27+
def cells: HTMLCollection[Element] = js.native
2828

2929
var borderColorLight: js.Any = js.native
3030

src/main/scala/org/scalajs/dom/HTMLTableSectionElement.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class HTMLTableSectionElement extends HTMLElement with HTMLTableAlignme
2020
/** Returns a live HTMLCollection containing the rows in the section. The HTMLCollection is live and is automatically
2121
* updated when rows are added or removed.
2222
*/
23-
def rows: HTMLCollection = js.native
23+
def rows: HTMLCollection[Element] = js.native
2424

2525
/** Removes the cell at the given position in the section. If the given position is greater (or equal as it starts at
2626
* zero) than the amount of rows in the section, or is smaller than 0, it raises a DOMException with the

src/main/scala/org/scalajs/dom/ParentNode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import scala.scalajs.js.|
1818
trait ParentNode extends js.Object {
1919

2020
/** Returns a live HTMLCollection containing all objects of type Element that are children of the object. */
21-
def children: HTMLCollection = js.native
21+
def children: HTMLCollection[Element] = js.native
2222

2323
/** Returns the Element that is the first child of the object, or null if there is none. */
2424
def firstElementChild: Element = js.native

src/main/scala/org/scalajs/dom/html.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object html {
1010
type Button = HTMLButtonElement
1111
type BR = HTMLBRElement
1212
type Canvas = HTMLCanvasElement
13-
type Collection = HTMLCollection
13+
type Collection[E <: Element] = HTMLCollection[E]
1414
type DataList = HTMLDataListElement
1515
type Div = HTMLDivElement
1616
type DList = HTMLDListElement

src/main/scala/org/scalajs/dom/raw.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ object raw {
321321
type HTMLCanvasElement = dom.HTMLCanvasElement
322322

323323
@deprecated("use dom.HTMLCollectionElement instead", "2.0.0")
324-
type HTMLCollectionElement = dom.HTMLCollection
324+
type HTMLCollectionElement[E <: dom.Element] = dom.HTMLCollection[E]
325325

326326
@deprecated("use dom.HTMLDataListElement instead", "2.0.0")
327327
type HTMLDataListElement = dom.HTMLDataListElement

0 commit comments

Comments
 (0)