#ifndef HTMLSelectElement_h
#define HTMLSelectElement_h
#include "core/events/Event.h"
#include "core/html/HTMLFormControlElementWithState.h"
#include "core/html/HTMLOptionsCollection.h"
#include "core/html/forms/TypeAhead.h"
#include "wtf/Vector.h"
namespace WebCore {
class ExceptionState;
class HTMLOptionElement;
class HTMLSelectElement FINAL : public HTMLFormControlElementWithState, public TypeAheadDataSource {
public:
static PassRefPtr<HTMLSelectElement> create(Document&);
static PassRefPtr<HTMLSelectElement> create(Document&, HTMLFormElement*);
int selectedIndex() const;
void setSelectedIndex(int);
int suggestedIndex() const;
void setSuggestedIndex(int);
void optionSelectedByUser(int index, bool dispatchChangeEvent, bool allowMultipleSelection = false);
virtual String validationMessage() const OVERRIDE;
virtual bool valueMissing() const OVERRIDE;
virtual void resetImpl() OVERRIDE;
unsigned length() const;
int size() const { return m_size; }
bool multiple() const { return m_multiple; }
bool usesMenuList() const;
void add(HTMLElement*, HTMLElement* beforeElement, ExceptionState&);
void addBeforeOptionAtIndex(HTMLElement*, int beforeIndex, ExceptionState&);
using Node::remove;
void remove(int index);
String value() const;
void setValue(const String&, bool sendEvents = false);
String suggestedValue() const;
void setSuggestedValue(const String&);
PassRefPtr<HTMLOptionsCollection> options();
PassRefPtr<HTMLCollection> selectedOptions();
void optionElementChildrenChanged();
void setRecalcListItems();
void invalidateSelectedItems();
void updateListItemSelectedStates();
const Vector<HTMLElement*>& listItems() const;
virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;
void accessKeySetSelectedIndex(int);
void setMultiple(bool);
void setSize(int);
void setOption(unsigned index, HTMLOptionElement*, ExceptionState&);
void setLength(unsigned, ExceptionState&);
Element* namedItem(const AtomicString& name);
Element* item(unsigned index);
void scrollToSelection();
void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true);
bool canSelectAll() const;
void selectAll();
int listToOptionIndex(int listIndex) const;
void listBoxOnChange();
int optionToListIndex(int optionIndex) const;
int activeSelectionStartListIndex() const;
int activeSelectionEndListIndex() const;
void setActiveSelectionAnchorIndex(int);
void setActiveSelectionEndIndex(int);
void updateListBoxSelection(bool deselectOtherOptions);
void optionSelectionStateChanged(HTMLOptionElement*, bool optionIsSelected);
bool anonymousIndexedSetter(unsigned, PassRefPtr<HTMLOptionElement>, ExceptionState&);
protected:
HTMLSelectElement(Document&, HTMLFormElement*);
private:
virtual const AtomicString& formControlType() const OVERRIDE;
virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE;
virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusType) OVERRIDE;
virtual void dispatchBlurEvent(Element* newFocusedElemnet) OVERRIDE;
virtual bool canStartSelection() const OVERRIDE { return false; }
virtual bool isEnumeratable() const OVERRIDE { return true; }
virtual bool isInteractiveContent() const OVERRIDE;
virtual bool supportsAutofocus() const OVERRIDE;
virtual bool supportLabels() const OVERRIDE { return true; }
virtual FormControlState saveFormControlState() const OVERRIDE;
virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
virtual bool appendFormData(FormDataList&, bool) OVERRIDE;
virtual void defaultEventHandler(Event*) OVERRIDE;
void dispatchInputAndChangeEventForMenuList(bool requiresUserGesture = true);
void recalcListItems(bool updateSelectedStates = true) const;
void typeAheadFind(KeyboardEvent*);
void saveLastSelection();
virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
virtual bool isOptionalFormControl() const OVERRIDE { return !isRequiredFormControl(); }
virtual bool isRequiredFormControl() const OVERRIDE;
bool hasPlaceholderLabelOption() const;
enum SelectOptionFlag {
DeselectOtherOptions = 1 << 0,
DispatchInputAndChangeEvent = 1 << 1,
UserDriven = 1 << 2,
};
typedef unsigned SelectOptionFlags;
void selectOption(int optionIndex, SelectOptionFlags = 0);
void deselectItemsWithoutValidation(HTMLElement* elementToExclude = 0);
void parseMultipleAttribute(const AtomicString&);
int lastSelectedListIndex() const;
void updateSelectedState(int listIndex, bool multi, bool shift);
void menuListDefaultEventHandler(Event*);
bool platformHandleKeydownEvent(KeyboardEvent*);
void listBoxDefaultEventHandler(Event*);
void setOptionsChangedOnRenderer();
size_t searchOptionsForValue(const String&, size_t listIndexStart, size_t listIndexEnd) const;
enum SkipDirection {
SkipBackwards = -1,
SkipForwards = 1
};
int nextValidIndex(int listIndex, SkipDirection, int skip) const;
int nextSelectableListIndex(int startIndex) const;
int previousSelectableListIndex(int startIndex) const;
int firstSelectableListIndex() const;
int lastSelectableListIndex() const;
int nextSelectableListIndexPageAway(int startIndex, SkipDirection) const;
virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
virtual void finishParsingChildren() OVERRIDE;
virtual int indexOfSelectedOption() const OVERRIDE;
virtual int optionCount() const OVERRIDE;
virtual String optionAtIndex(int index) const OVERRIDE;
mutable Vector<HTMLElement*> m_listItems;
Vector<bool> m_lastOnChangeSelection;
Vector<bool> m_cachedStateForActiveSelection;
TypeAhead m_typeAhead;
int m_size;
int m_lastOnChangeIndex;
int m_activeSelectionAnchorIndex;
int m_activeSelectionEndIndex;
bool m_isProcessingUserDrivenChange;
bool m_multiple;
bool m_activeSelectionState;
mutable bool m_shouldRecalcListItems;
int m_suggestedIndex;
};
}
#endif