Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2000 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
      6  * Copyright (C) 2010 Google Inc. All rights reserved.
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  *
     23  */
     24 
     25 #ifndef HTMLSelectElement_h
     26 #define HTMLSelectElement_h
     27 
     28 #include "CollectionCache.h"
     29 #include "HTMLFormControlElement.h"
     30 #include "SelectElement.h"
     31 
     32 namespace WebCore {
     33 
     34 class HTMLOptionElement;
     35 class HTMLOptionsCollection;
     36 class KeyboardEvent;
     37 
     38 class HTMLSelectElement : public HTMLFormControlElementWithState, public SelectElement {
     39 public:
     40     HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
     41 
     42     virtual int selectedIndex() const;
     43     virtual void setSelectedIndex(int index, bool deselect = true);
     44     virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false);
     45 
     46     unsigned length() const;
     47 
     48     virtual int size() const { return m_data.size(); }
     49     virtual bool multiple() const { return m_data.multiple(); }
     50 
     51     void add(HTMLElement* element, HTMLElement* before, ExceptionCode&);
     52     void remove(int index);
     53 
     54     String value();
     55     void setValue(const String&);
     56 
     57     PassRefPtr<HTMLOptionsCollection> options();
     58 
     59     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
     60 
     61     void setRecalcListItems();
     62     void recalcListItemsIfNeeded();
     63 
     64     virtual const Vector<Element*>& listItems() const { return m_data.listItems(this); }
     65 
     66     virtual void accessKeyAction(bool sendToAnyElement);
     67     void accessKeySetSelectedIndex(int);
     68 
     69     void setMultiple(bool);
     70 
     71     void setSize(int);
     72 
     73     void setOption(unsigned index, HTMLOptionElement*, ExceptionCode&);
     74     void setLength(unsigned, ExceptionCode&);
     75 
     76     Node* namedItem(const AtomicString& name);
     77     Node* item(unsigned index);
     78 
     79     CollectionCache* collectionInfo() { m_collectionInfo.checkConsistency(); return &m_collectionInfo; }
     80 
     81     void scrollToSelection();
     82 
     83 private:
     84     virtual int tagPriority() const { return 6; }
     85     virtual bool checkDTD(const Node* newChild);
     86 
     87     virtual const AtomicString& formControlType() const;
     88 
     89     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
     90     virtual bool isMouseFocusable() const;
     91     virtual bool canSelectAll() const;
     92     virtual void selectAll();
     93 
     94     virtual void recalcStyle(StyleChange);
     95 
     96     virtual void dispatchFocusEvent();
     97     virtual void dispatchBlurEvent();
     98 
     99     virtual bool canStartSelection() const { return false; }
    100 
    101     virtual bool isEnumeratable() const { return true; }
    102 
    103     virtual bool saveFormControlState(String& value) const;
    104     virtual void restoreFormControlState(const String&);
    105 
    106     virtual void parseMappedAttribute(MappedAttribute*);
    107 
    108     virtual RenderObject* createRenderer(RenderArena*, RenderStyle *);
    109     virtual bool appendFormData(FormDataList&, bool);
    110 
    111     virtual int optionToListIndex(int optionIndex) const;
    112     virtual int listToOptionIndex(int listIndex) const;
    113 
    114     virtual void reset();
    115 
    116     virtual void defaultEventHandler(Event*);
    117 
    118     virtual void setActiveSelectionAnchorIndex(int index);
    119     virtual void setActiveSelectionEndIndex(int index);
    120     virtual void updateListBoxSelection(bool deselectOtherOptions);
    121     virtual void listBoxOnChange();
    122     virtual void menuListOnChange();
    123 
    124     virtual int activeSelectionStartListIndex() const;
    125     virtual int activeSelectionEndListIndex() const;
    126 
    127     void recalcListItems(bool updateSelectedStates = true) const;
    128 
    129     void deselectItems(HTMLOptionElement* excludeElement = 0);
    130     void typeAheadFind(KeyboardEvent*);
    131     void saveLastSelection();
    132 
    133     virtual void insertedIntoTree(bool);
    134 
    135     virtual bool isOptionalFormControl() const { return true; }
    136 
    137     SelectElementData m_data;
    138     CollectionCache m_collectionInfo;
    139 };
    140 
    141 } // namespace
    142 
    143 #endif
    144