From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/html/HTMLOptionsCollection.h | 65 ++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'Source/WebCore/html/HTMLOptionsCollection.h') 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::traversalType> { +public: + static Ref create(HTMLSelectElement&, CollectionType); -typedef int ExceptionCode; + HTMLSelectElement& selectElement() { return downcast(ownerNode()); } + const HTMLSelectElement& selectElement() const { return downcast(ownerNode()); } -class HTMLOptionsCollection final : public HTMLCollection { -public: - static PassRef 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>; + using HTMLElementOrInt = Variant, int>; + WEBCORE_EXPORT ExceptionOr add(const OptionOrOptGroupElement&, const std::optional& before); + WEBCORE_EXPORT void remove(int index); + void remove(HTMLOptionElement&); - void add(PassRefPtr, ExceptionCode&); - void add(PassRefPtr, 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 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(CachedHTMLCollection::traversalType>::item(offset)); +} + +inline HTMLOptionElement* HTMLOptionsCollection::namedItem(const AtomicString& name) const +{ + return downcast(CachedHTMLCollection::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) -- cgit v1.2.1