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 BaseMultipleFieldsDateAndTimeInputType_h
32#define BaseMultipleFieldsDateAndTimeInputType_h
33
34#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
35#include "core/html/forms/BaseDateAndTimeInputType.h"
36
37#include "core/html/shadow/ClearButtonElement.h"
38#include "core/html/shadow/DateTimeEditElement.h"
39#include "core/html/shadow/PickerIndicatorElement.h"
40#include "core/html/shadow/SpinButtonElement.h"
41
42namespace blink {
43
44struct DateTimeChooserParameters;
45
46class BaseMultipleFieldsDateAndTimeInputType
47    : public BaseDateAndTimeInputType
48    , protected DateTimeEditElement::EditControlOwner
49    , protected PickerIndicatorElement::PickerIndicatorOwner
50    , protected SpinButtonElement::SpinButtonOwner
51    , protected ClearButtonElement::ClearButtonOwner {
52    WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BaseMultipleFieldsDateAndTimeInputType);
53
54public:
55    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const = 0;
56
57    virtual void trace(Visitor* visitor) OVERRIDE { BaseDateAndTimeInputType::trace(visitor); }
58
59protected:
60    BaseMultipleFieldsDateAndTimeInputType(HTMLInputElement&);
61    virtual ~BaseMultipleFieldsDateAndTimeInputType();
62
63    virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const = 0;
64    bool shouldHaveSecondField(const DateComponents&) const;
65
66private:
67    // DateTimeEditElement::EditControlOwner functions
68    virtual void didBlurFromControl() OVERRIDE FINAL;
69    virtual void didFocusOnControl() OVERRIDE FINAL;
70    virtual void editControlValueChanged() OVERRIDE FINAL;
71    virtual bool isEditControlOwnerDisabled() const OVERRIDE FINAL;
72    virtual bool isEditControlOwnerReadOnly() const OVERRIDE FINAL;
73    virtual AtomicString localeIdentifier() const OVERRIDE FINAL;
74    virtual void editControlDidChangeValueByKeyboard() OVERRIDE FINAL;
75
76    // SpinButtonElement::SpinButtonOwner functions.
77    virtual void focusAndSelectSpinButtonOwner() OVERRIDE;
78    virtual bool shouldSpinButtonRespondToMouseEvents() OVERRIDE;
79    virtual bool shouldSpinButtonRespondToWheelEvents() OVERRIDE;
80    virtual void spinButtonStepDown() OVERRIDE;
81    virtual void spinButtonStepUp() OVERRIDE;
82    virtual void spinButtonDidReleaseMouseCapture(SpinButtonElement::EventDispatch) OVERRIDE;
83
84    // PickerIndicatorElement::PickerIndicatorOwner functions
85    virtual bool isPickerIndicatorOwnerDisabledOrReadOnly() const OVERRIDE FINAL;
86    virtual void pickerIndicatorChooseValue(const String&) OVERRIDE FINAL;
87    virtual void pickerIndicatorChooseValue(double) OVERRIDE FINAL;
88    virtual Element& pickerOwnerElement() const OVERRIDE FINAL;
89    virtual bool setupDateTimeChooserParameters(DateTimeChooserParameters&) OVERRIDE FINAL;
90
91    // ClearButtonElement::ClearButtonOwner functions.
92    virtual void focusAndSelectClearButtonOwner() OVERRIDE;
93    virtual bool shouldClearButtonRespondToMouseEvents() OVERRIDE;
94    virtual void clearValue() OVERRIDE;
95
96    // InputType functions
97    virtual String badInputText() const OVERRIDE;
98    virtual void blur() OVERRIDE FINAL;
99    virtual PassRefPtr<RenderStyle> customStyleForRenderer(PassRefPtr<RenderStyle>) OVERRIDE;
100    virtual void createShadowSubtree() OVERRIDE FINAL;
101    virtual void destroyShadowSubtree() OVERRIDE FINAL;
102    virtual void disabledAttributeChanged() OVERRIDE FINAL;
103    virtual void forwardEvent(Event*) OVERRIDE FINAL;
104    virtual void handleFocusInEvent(Element* oldFocusedElement, FocusType) OVERRIDE FINAL;
105    virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE FINAL;
106    virtual bool hasBadInput() const OVERRIDE;
107    virtual bool hasCustomFocusLogic() const OVERRIDE FINAL;
108    virtual void minOrMaxAttributeChanged() OVERRIDE FINAL;
109    virtual void readonlyAttributeChanged() OVERRIDE FINAL;
110    virtual void requiredAttributeChanged() OVERRIDE FINAL;
111    virtual void restoreFormControlState(const FormControlState&) OVERRIDE FINAL;
112    virtual FormControlState saveFormControlState() const OVERRIDE FINAL;
113    virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE FINAL;
114    virtual void stepAttributeChanged() OVERRIDE FINAL;
115    virtual void updateView() OVERRIDE FINAL;
116    virtual void valueAttributeChanged() OVERRIDE;
117    virtual void listAttributeTargetChanged() OVERRIDE FINAL;
118    virtual void updateClearButtonVisibility() OVERRIDE FINAL;
119    virtual TextDirection computedTextDirection() OVERRIDE FINAL;
120    virtual AXObject* popupRootAXObject() OVERRIDE FINAL;
121
122    DateTimeEditElement* dateTimeEditElement() const;
123    SpinButtonElement* spinButtonElement() const;
124    ClearButtonElement* clearButtonElement() const;
125    PickerIndicatorElement* pickerIndicatorElement() const;
126    bool containsFocusedShadowElement() const;
127    void showPickerIndicator();
128    void hidePickerIndicator();
129    void updatePickerIndicatorVisibility();
130
131    bool m_isDestroyingShadowSubtree;
132    bool m_pickerIndicatorIsVisible;
133    bool m_pickerIndicatorIsAlwaysVisible;
134};
135
136} // namespace blink
137
138#endif
139#endif // BaseMultipleFieldsDateAndTimeInputType_h
140