1/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef TextFieldInputType_h
32#define TextFieldInputType_h
33
34#include "InputType.h"
35#include "SpinButtonElement.h"
36
37namespace WebCore {
38
39class FormDataList;
40class TextControlInnerTextElement;
41
42// The class represents types of which UI contain text fields.
43// It supports not only the types for BaseTextInputType but also type=number.
44class TextFieldInputType : public InputType, protected SpinButtonElement::SpinButtonOwner {
45protected:
46    explicit TextFieldInputType(HTMLInputElement&);
47    virtual ~TextFieldInputType();
48    virtual bool canSetSuggestedValue() override;
49    virtual void handleKeydownEvent(KeyboardEvent*) override;
50    void handleKeydownEventForSpinButton(KeyboardEvent*);
51
52    virtual HTMLElement* containerElement() const override;
53    virtual HTMLElement* innerBlockElement() const override;
54    virtual TextControlInnerTextElement* innerTextElement() const override;
55    virtual HTMLElement* innerSpinButtonElement() const override;
56#if ENABLE(INPUT_SPEECH)
57    virtual HTMLElement* speechButtonElement() const override;
58#endif
59
60protected:
61    virtual bool needsContainer() const;
62    virtual bool shouldHaveSpinButton() const;
63    virtual void createShadowSubtree() override;
64    virtual void destroyShadowSubtree() override;
65    virtual void attributeChanged() override;
66    virtual void disabledAttributeChanged() override;
67    virtual void readonlyAttributeChanged() override;
68    virtual bool supportsReadOnly() const override;
69    virtual void handleBlurEvent() override;
70    virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override;
71    virtual void updateInnerTextValue() override;
72#if PLATFORM(IOS)
73    virtual String sanitizeValue(const String&) const override;
74#endif
75
76    virtual String convertFromVisibleValue(const String&) const;
77    enum ValueChangeState {
78        ValueChangeStateNone,
79        ValueChangeStateChanged
80    };
81    virtual void didSetValueByUserEdit(ValueChangeState);
82
83private:
84    virtual bool isKeyboardFocusable(KeyboardEvent*) const override;
85    virtual bool isMouseFocusable() const override;
86    virtual bool isTextField() const override;
87    virtual bool valueMissing(const String&) const override;
88    virtual void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) override;
89    virtual void forwardEvent(Event*) override;
90    virtual bool shouldSubmitImplicitly(Event*) override;
91    virtual RenderPtr<RenderElement> createInputRenderer(PassRef<RenderStyle>) override;
92    virtual bool shouldUseInputMethod() const override;
93#if !PLATFORM(IOS)
94    virtual String sanitizeValue(const String&) const override;
95#endif
96    virtual bool shouldRespectListAttribute() override;
97    virtual HTMLElement* placeholderElement() const override;
98    virtual void updatePlaceholderText() override;
99    virtual bool appendFormData(FormDataList&, bool multipart) const override;
100    virtual void subtreeHasChanged() override;
101
102    // SpinButtonElement::SpinButtonOwner functions.
103    virtual void focusAndSelectSpinButtonOwner() override;
104    virtual bool shouldSpinButtonRespondToMouseEvents() override;
105    virtual bool shouldSpinButtonRespondToWheelEvents() override;
106    virtual void spinButtonStepDown() override;
107    virtual void spinButtonStepUp() override;
108
109    RefPtr<HTMLElement> m_container;
110    RefPtr<HTMLElement> m_innerBlock;
111    RefPtr<TextControlInnerTextElement> m_innerText;
112    RefPtr<HTMLElement> m_placeholder;
113    RefPtr<SpinButtonElement> m_innerSpinButton;
114#if ENABLE(INPUT_SPEECH)
115    RefPtr<HTMLElement> m_speechButton;
116#endif
117};
118
119} // namespace WebCore
120
121#endif // TextFieldInputType_h
122