From 6882a04fb36642862b11efe514251d32070c3d65 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Thu, 25 Aug 2016 19:20:41 +0300 Subject: Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443) Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev --- Source/WebCore/html/HTMLOptionsCollection.cpp | 53 +++++++++------------------ 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'Source/WebCore/html/HTMLOptionsCollection.cpp') diff --git a/Source/WebCore/html/HTMLOptionsCollection.cpp b/Source/WebCore/html/HTMLOptionsCollection.cpp index ddcfcb486..b36c3f480 100644 --- a/Source/WebCore/html/HTMLOptionsCollection.cpp +++ b/Source/WebCore/html/HTMLOptionsCollection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2011, 2012 Apple Computer, Inc. + * Copyright (C) 2006, 2011, 2012 Apple Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,69 +23,52 @@ #include "ExceptionCode.h" #include "HTMLOptionElement.h" -#include "HTMLSelectElement.h" namespace WebCore { -HTMLOptionsCollection::HTMLOptionsCollection(Node* select) - : HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter) +HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement& select) + : CachedHTMLCollection::traversalType>(select, SelectOptions) { - ASSERT(select->hasTagName(HTMLNames::selectTag)); } -PassRefPtr HTMLOptionsCollection::create(Node* select, CollectionType) +Ref HTMLOptionsCollection::create(HTMLSelectElement& select, CollectionType) { - return adoptRef(new HTMLOptionsCollection(select)); + return adoptRef(*new HTMLOptionsCollection(select)); } -void HTMLOptionsCollection::add(PassRefPtr element, ExceptionCode& ec) +void HTMLOptionsCollection::add(HTMLElement* element, HTMLElement* beforeElement, ExceptionCode& ec) { - add(element, length(), ec); + selectElement().add(element, beforeElement, ec); } -void HTMLOptionsCollection::add(PassRefPtr element, int index, ExceptionCode& ec) +void HTMLOptionsCollection::add(HTMLElement* element, int beforeIndex, ExceptionCode& ec) { - HTMLOptionElement* newOption = element.get(); - - if (!newOption) { - ec = TYPE_MISMATCH_ERR; - return; - } - - if (index < -1) { - ec = INDEX_SIZE_ERR; - return; - } - - ec = 0; - HTMLSelectElement* select = toHTMLSelectElement(ownerNode()); - - if (index == -1 || unsigned(index) >= length()) - select->add(newOption, 0, ec); - else - select->add(newOption, toHTMLOptionElement(item(index)), ec); - - ASSERT(!ec); + add(element, item(beforeIndex), ec); } void HTMLOptionsCollection::remove(int index) { - toHTMLSelectElement(ownerNode())->remove(index); + selectElement().removeByIndex(index); +} + +void HTMLOptionsCollection::remove(HTMLOptionElement* option) +{ + selectElement().remove(option); } int HTMLOptionsCollection::selectedIndex() const { - return toHTMLSelectElement(ownerNode())->selectedIndex(); + return selectElement().selectedIndex(); } void HTMLOptionsCollection::setSelectedIndex(int index) { - toHTMLSelectElement(ownerNode())->setSelectedIndex(index); + selectElement().setSelectedIndex(index); } void HTMLOptionsCollection::setLength(unsigned length, ExceptionCode& ec) { - toHTMLSelectElement(ownerNode())->setLength(length, ec); + selectElement().setLength(length, ec); } } //namespace -- cgit v1.2.1