1/**
2 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef WMLSelectElement_h
22#define WMLSelectElement_h
23
24#if ENABLE(WML)
25#include "WMLFormControlElement.h"
26#include "SelectElement.h"
27
28namespace WebCore {
29
30class WMLSelectElement : public WMLFormControlElement, public SelectElement {
31public:
32    static PassRefPtr<WMLSelectElement> create(const QualifiedName&, Document*);
33
34    WMLSelectElement(const QualifiedName&, Document*);
35    virtual ~WMLSelectElement();
36
37    virtual const AtomicString& formControlName() const;
38    virtual const AtomicString& formControlType() const;
39
40    virtual bool isKeyboardFocusable(KeyboardEvent*) const;
41    virtual bool isMouseFocusable() const;
42    virtual bool canSelectAll() const { return !m_data.usesMenuList(); }
43    virtual void selectAll();
44
45    virtual void recalcStyle(StyleChange);
46
47    virtual void dispatchFocusEvent();
48    virtual void dispatchBlurEvent();
49
50    virtual bool canStartSelection() const { return false; }
51
52    virtual int selectedIndex() const;
53    virtual void setSelectedIndex(int index, bool deselect = true);
54    virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false, bool allowMultipleSelection = false);
55
56    virtual int size() const { return m_data.size(); }
57    virtual bool multiple() const { return m_data.multiple(); }
58
59    virtual bool saveFormControlState(String& value) const;
60    virtual void restoreFormControlState(const String&);
61
62    virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
63
64    virtual void parseMappedAttribute(Attribute*);
65
66    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
67    virtual bool appendFormData(FormDataList&, bool);
68    virtual int optionToListIndex(int optionIndex) const;
69    virtual int listToOptionIndex(int listIndex) const;
70
71    virtual const Vector<Element*>& listItems() const { return m_data.listItems(this); }
72    virtual void reset();
73
74    virtual void defaultEventHandler(Event*);
75    virtual void accessKeyAction(bool sendToAnyElement);
76    virtual void setActiveSelectionAnchorIndex(int index);
77    virtual void setActiveSelectionEndIndex(int index);
78    virtual void updateListBoxSelection(bool deselectOtherOptions);
79    virtual void listBoxOnChange();
80    virtual void menuListOnChange();
81
82    virtual int activeSelectionStartListIndex() const;
83    virtual int activeSelectionEndListIndex() const;
84
85    void accessKeySetSelectedIndex(int);
86    void setRecalcListItems();
87    void scrollToSelection();
88    void selectInitialOptions();
89
90    bool initialized() const { return m_initialized; }
91
92    virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true);
93private:
94    virtual void insertedIntoTree(bool);
95
96    void calculateDefaultOptionIndices();
97    void selectDefaultOptions();
98    void initializeVariables();
99    void updateVariables();
100
101    Vector<unsigned> parseIndexValueString(const String&) const;
102    Vector<unsigned> valueStringToOptionIndices(const String&) const;
103    String optionIndicesToValueString() const;
104    String optionIndicesToString() const;
105
106    virtual void updateValidity() {}
107
108    String name() const;
109    String value() const;
110    String iname() const;
111    String ivalue() const;
112
113    SelectElementData m_data;
114    bool m_initialized;
115    Vector<unsigned> m_defaultOptionIndices;
116};
117
118}
119
120#endif
121#endif
122