diff options
Diffstat (limited to 'Source/WebCore/html/HTMLOptionsCollection.h')
-rw-r--r-- | Source/WebCore/html/HTMLOptionsCollection.h | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/Source/WebCore/html/HTMLOptionsCollection.h b/Source/WebCore/html/HTMLOptionsCollection.h index 1c5e6889b..3f7dd5a7a 100644 --- a/Source/WebCore/html/HTMLOptionsCollection.h +++ b/Source/WebCore/html/HTMLOptionsCollection.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004-2016 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,39 +21,64 @@ * */ -#ifndef HTMLOptionsCollection_h -#define HTMLOptionsCollection_h +#pragma once -#include "HTMLCollection.h" +#include "CachedHTMLCollection.h" +#include "HTMLOptionElement.h" #include "HTMLSelectElement.h" namespace WebCore { -class HTMLOptionElement; +class HTMLOptionsCollection final : public CachedHTMLCollection<HTMLOptionsCollection, CollectionTypeTraits<SelectOptions>::traversalType> { +public: + static Ref<HTMLOptionsCollection> create(HTMLSelectElement&, CollectionType); -typedef int ExceptionCode; + HTMLSelectElement& selectElement() { return downcast<HTMLSelectElement>(ownerNode()); } + const HTMLSelectElement& selectElement() const { return downcast<HTMLSelectElement>(ownerNode()); } -class HTMLOptionsCollection final : public HTMLCollection { -public: - static PassRef<HTMLOptionsCollection> create(HTMLSelectElement&, CollectionType); + HTMLOptionElement* item(unsigned offset) const final; + HTMLOptionElement* namedItem(const AtomicString& name) const final; - HTMLSelectElement& selectElement() { return toHTMLSelectElement(ownerNode()); } - const HTMLSelectElement& selectElement() const { return toHTMLSelectElement(ownerNode()); } + using OptionOrOptGroupElement = Variant<RefPtr<HTMLOptionElement>, RefPtr<HTMLOptGroupElement>>; + using HTMLElementOrInt = Variant<RefPtr<HTMLElement>, int>; + WEBCORE_EXPORT ExceptionOr<void> add(const OptionOrOptGroupElement&, const std::optional<HTMLElementOrInt>& before); + WEBCORE_EXPORT void remove(int index); + void remove(HTMLOptionElement&); - void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&); - void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&); - void remove(int index); - void remove(HTMLOptionElement*); + WEBCORE_EXPORT int selectedIndex() const; + WEBCORE_EXPORT void setSelectedIndex(int); - int selectedIndex() const; - void setSelectedIndex(int); + WEBCORE_EXPORT ExceptionOr<void> setLength(unsigned); - void setLength(unsigned, ExceptionCode&); + // For CachedHTMLCollection. + bool elementMatches(Element&) const; private: explicit HTMLOptionsCollection(HTMLSelectElement&); }; -} //namespace +inline HTMLOptionElement* HTMLOptionsCollection::item(unsigned offset) const +{ + return downcast<HTMLOptionElement>(CachedHTMLCollection<HTMLOptionsCollection, CollectionTypeTraits<SelectOptions>::traversalType>::item(offset)); +} + +inline HTMLOptionElement* HTMLOptionsCollection::namedItem(const AtomicString& name) const +{ + return downcast<HTMLOptionElement>(CachedHTMLCollection<HTMLOptionsCollection, CollectionTypeTraits<SelectOptions>::traversalType>::namedItem(name)); +} + +inline bool HTMLOptionsCollection::elementMatches(Element& element) const +{ + if (!element.hasTagName(HTMLNames::optionTag)) + return false; + + if (element.parentNode() == &selectElement()) + return true; + + ASSERT(element.parentNode()); + return element.parentNode()->hasTagName(HTMLNames::optgroupTag) && element.parentNode()->parentNode() == &selectElement(); +} + +} // namespace WebCore -#endif +SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLOptionsCollection, SelectOptions) |