Home | History | Annotate | Download | only in shadow
      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:
     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*);
     97     UpDownState upDownState() const { return m_upDownState; }
     98 
     99 private:
    100     SpinButtonElement(HTMLElement*);
    101 
    102     virtual void detach();
    103     virtual bool isSpinButtonElement() const { return true; }
    104     // FIXME: shadowAncestorNode() should be const.
    105     virtual bool isEnabledFormControl() const { return static_cast<Element*>(const_cast<SpinButtonElement*>(this)->shadowAncestorNode())->isEnabledFormControl(); }
    106     virtual bool isReadOnlyFormControl() const { return static_cast<Element*>(const_cast<SpinButtonElement*>(this)->shadowAncestorNode())->isReadOnlyFormControl(); }
    107     virtual void defaultEventHandler(Event*);
    108     void startRepeatingTimer();
    109     void stopRepeatingTimer();
    110     void repeatingTimerFired(Timer<SpinButtonElement>*);
    111     virtual void setHovered(bool = true);
    112 
    113     bool m_capturing;
    114     UpDownState m_upDownState;
    115     UpDownState m_pressStartingState;
    116     Timer<SpinButtonElement> m_repeatingTimer;
    117 };
    118 
    119 #if ENABLE(INPUT_SPEECH)
    120 
    121 class InputFieldSpeechButtonElement
    122     : public TextControlInnerElement,
    123       public SpeechInputListener {
    124 public:
    125     enum SpeechInputState {
    126         Idle,
    127         Recording,
    128         Recognizing,
    129     };
    130 
    131     static PassRefPtr<InputFieldSpeechButtonElement> create(HTMLElement*);
    132     virtual ~InputFieldSpeechButtonElement();
    133 
    134     virtual void detach();
    135     virtual void defaultEventHandler(Event*);
    136     virtual bool isInputFieldSpeechButtonElement() const { return true; }
    137     SpeechInputState state() const { return m_state; }
    138 
    139     // SpeechInputListener methods.
    140     void didCompleteRecording(int);
    141     void didCompleteRecognition(int);
    142     void setRecognitionResult(int, const SpeechInputResultArray&);
    143 
    144 private:
    145     InputFieldSpeechButtonElement(HTMLElement*);
    146     SpeechInput* speechInput();
    147     void setState(SpeechInputState state);
    148 
    149     bool m_capturing;
    150     SpeechInputState m_state;
    151     int m_listenerId;
    152     SpeechInputResultArray m_results;
    153 };
    154 
    155 inline InputFieldSpeechButtonElement* toInputFieldSpeechButtonElement(Element* element)
    156 {
    157     ASSERT(!element || element->isInputFieldSpeechButtonElement());
    158     return static_cast<InputFieldSpeechButtonElement*>(element);
    159 }
    160 
    161 #endif // ENABLE(INPUT_SPEECH)
    162 
    163 } // namespace
    164 
    165 #endif
    166