2013-11-03 Andreas Kling <akling@apple.com>
+ HTMLOptionsCollection is always rooted at a HTMLSelectElement.
+ <https://webkit.org/b/123719>
+
+ Tighten up HTMLOptionsCollection by making the constructor take
+ a HTMLSelectElement& and adding a HTMLSelectElement& getter instead
+ of casting all over the place. Removed now-pointless assertions.
+
+ Reviewed by Sam Weinig.
+
+2013-11-03 Andreas Kling <akling@apple.com>
+
RenderTextFragment: Tighten first-letter logic.
<https://webkit.org/b/123714>
void JSHTMLOptionsCollection::indexSetter(ExecState* exec, unsigned index, JSValue value)
{
- HTMLSelectElement& base = toHTMLSelectElement(impl().ownerNode());
- selectIndexSetter(&base, exec, index, value);
+ selectIndexSetter(&impl().selectElement(), exec, index, value);
}
JSValue JSHTMLOptionsCollection::add(ExecState* exec)
#include "HTMLNames.h"
#include "HTMLOptionsCollection.h"
#include "HTMLParserIdioms.h"
+#include "HTMLSelectElement.h"
#include "HTMLTableRowsCollection.h"
#include "InsertionPoint.h"
#include "InspectorInstrumentation.h"
ASSERT(hasTagName(tableTag));
return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTableRowsCollection>(*this, type);
} else if (type == SelectOptions) {
- ASSERT(hasTagName(selectTag));
- return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLOptionsCollection>(*this, type);
+ return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLOptionsCollection>(toHTMLSelectElement(*this), type);
} else if (type == FormControls) {
ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag));
return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLFormControlsCollection>(*this, type);
}
// FIXME: This function should be renamed since it doesn't have an atomic name.
- template<typename T>
- PassRefPtr<T> addCacheWithAtomicName(ContainerNode& node, CollectionType collectionType)
+ template<typename T, typename ContainerType>
+ PassRefPtr<T> addCacheWithAtomicName(ContainerType& container, CollectionType collectionType)
{
NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, starAtom), nullptr);
if (!result.isNewEntry)
return static_cast<T*>(result.iterator->value);
- RefPtr<T> list = T::create(node, collectionType);
+ RefPtr<T> list = T::create(container, collectionType);
result.iterator->value = list.get();
return list.release();
}
namespace WebCore {
-HTMLOptionsCollection::HTMLOptionsCollection(ContainerNode& select)
+HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement& select)
: HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter)
{
- ASSERT(isHTMLSelectElement(select));
}
-PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(ContainerNode& select, CollectionType)
+PassRef<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement& select, CollectionType)
{
- return adoptRef(new HTMLOptionsCollection(select));
+ return adoptRef(*new HTMLOptionsCollection(select));
}
void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, ExceptionCode& ec)
}
ec = 0;
- HTMLSelectElement& select = toHTMLSelectElement(ownerNode());
if (index == -1 || unsigned(index) >= length())
- select.add(newOption, 0, ec);
+ selectElement().add(newOption, 0, ec);
else
- select.add(newOption, toHTMLOptionElement(item(index)), ec);
+ selectElement().add(newOption, toHTMLOptionElement(item(index)), ec);
ASSERT(!ec);
}
void HTMLOptionsCollection::remove(int index)
{
- toHTMLSelectElement(ownerNode()).removeByIndex(index);
+ selectElement().removeByIndex(index);
}
void HTMLOptionsCollection::remove(HTMLOptionElement* option)
{
- toHTMLSelectElement(ownerNode()).remove(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
#define HTMLOptionsCollection_h
#include "HTMLCollection.h"
+#include "HTMLSelectElement.h"
namespace WebCore {
class HTMLOptionElement;
-class HTMLSelectElement;
typedef int ExceptionCode;
-class HTMLOptionsCollection : public HTMLCollection {
+class HTMLOptionsCollection FINAL : public HTMLCollection {
public:
- static PassRefPtr<HTMLOptionsCollection> create(ContainerNode&, CollectionType);
+ static PassRef<HTMLOptionsCollection> create(HTMLSelectElement&, CollectionType);
+
+ HTMLSelectElement& selectElement() { return toHTMLSelectElement(ownerNode()); }
+ const HTMLSelectElement& selectElement() const { return toHTMLSelectElement(ownerNode()); }
void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
void setLength(unsigned, ExceptionCode&);
private:
- explicit HTMLOptionsCollection(ContainerNode&);
+ explicit HTMLOptionsCollection(HTMLSelectElement&);
};
} //namespace
#include "Event.h"
#include "HTMLFormControlElementWithState.h"
-#include "HTMLOptionsCollection.h"
#include "TypeAhead.h"
#include <wtf/Vector.h>
namespace WebCore {
class HTMLOptionElement;
+class HTMLOptionsCollection;
class HTMLSelectElement : public HTMLFormControlElementWithState, public TypeAheadDataSource {
public: