1 /*
2 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef TextControlInnerElements_h
28 #define TextControlInnerElements_h
29
30 #include "HTMLDivElement.h"
31 #include "SpeechInputListener.h"
32 #include "Timer.h"
33 #include <wtf/Forward.h>
34
35 namespace WebCore {
36
37 class SpeechInput;
38
39 class TextControlInnerElement : public HTMLDivElement {
40 public:
41 static PassRefPtr<TextControlInnerElement> create(HTMLElement* shadowParent);
42 virtual void detach();
43
44 void attachInnerElement(Node*, PassRefPtr<RenderStyle>, RenderArena*);
45
46 protected:
47 TextControlInnerElement(Document*, HTMLElement* shadowParent = 0);
48
49 private:
isMouseFocusable()50 virtual bool isMouseFocusable() const { return false; }
51 };
52
53 class TextControlInnerTextElement : public TextControlInnerElement {
54 public:
55 static PassRefPtr<TextControlInnerTextElement> create(Document*, HTMLElement* shadowParent);
56
57 virtual void defaultEventHandler(Event*);
58
59 private:
60 TextControlInnerTextElement(Document*, HTMLElement* shadowParent);
61 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
62 };
63
64 class SearchFieldResultsButtonElement : public TextControlInnerElement {
65 public:
66 static PassRefPtr<SearchFieldResultsButtonElement> create(Document*);
67
68 virtual void defaultEventHandler(Event*);
69
70 private:
71 SearchFieldResultsButtonElement(Document*);
72 };
73
74 class SearchFieldCancelButtonElement : public TextControlInnerElement {
75 public:
76 static PassRefPtr<SearchFieldCancelButtonElement> create(Document*);
77
78 virtual void defaultEventHandler(Event*);
79
80 private:
81 SearchFieldCancelButtonElement(Document*);
82
83 virtual void detach();
84
85 bool m_capturing;
86 };
87
88 class SpinButtonElement : public TextControlInnerElement {
89 public:
90 enum UpDownState {
91 Indeterminate, // Hovered, but the event is not handled.
92 Down,
93 Up,
94 };
95
96 static PassRefPtr<SpinButtonElement> create(HTMLElement*);
upDownState()97 UpDownState upDownState() const { return m_upDownState; }
98
99 private:
100 SpinButtonElement(HTMLElement*);
101
102 virtual void detach();
isSpinButtonElement()103 virtual bool isSpinButtonElement() const { return true; }
isEnabledFormControl()104 virtual bool isEnabledFormControl() const { return static_cast<Element*>(shadowAncestorNode())->isEnabledFormControl(); }
isReadOnlyFormControl()105 virtual bool isReadOnlyFormControl() const { return static_cast<Element*>(shadowAncestorNode())->isReadOnlyFormControl(); }
106 virtual void defaultEventHandler(Event*);
107 void startRepeatingTimer();
108 void stopRepeatingTimer();
109 void repeatingTimerFired(Timer<SpinButtonElement>*);
110 virtual void setHovered(bool = true);
111
112 bool m_capturing;
113 UpDownState m_upDownState;
114 UpDownState m_pressStartingState;
115 Timer<SpinButtonElement> m_repeatingTimer;
116 };
117
118 #if ENABLE(INPUT_SPEECH)
119
120 class InputFieldSpeechButtonElement
121 : public TextControlInnerElement,
122 public SpeechInputListener {
123 public:
124 enum SpeechInputState {
125 Idle,
126 Recording,
127 Recognizing,
128 };
129
130 static PassRefPtr<InputFieldSpeechButtonElement> create(HTMLElement*);
131 virtual ~InputFieldSpeechButtonElement();
132
133 virtual void detach();
134 virtual void defaultEventHandler(Event*);
isInputFieldSpeechButtonElement()135 virtual bool isInputFieldSpeechButtonElement() const { return true; }
state()136 SpeechInputState state() const { return m_state; }
137
138 // SpeechInputListener methods.
139 void didCompleteRecording(int);
140 void didCompleteRecognition(int);
141 void setRecognitionResult(int, const SpeechInputResultArray&);
142
143 private:
144 InputFieldSpeechButtonElement(HTMLElement*);
145 SpeechInput* speechInput();
146 void setState(SpeechInputState state);
147
148 bool m_capturing;
149 SpeechInputState m_state;
150 int m_listenerId;
151 SpeechInputResultArray m_results;
152 };
153
toInputFieldSpeechButtonElement(Element * element)154 inline InputFieldSpeechButtonElement* toInputFieldSpeechButtonElement(Element* element)
155 {
156 ASSERT(!element || element->isInputFieldSpeechButtonElement());
157 return static_cast<InputFieldSpeechButtonElement*>(element);
158 }
159
160 #endif // ENABLE(INPUT_SPEECH)
161
162 } // namespace
163
164 #endif
165