Home | History | Annotate | Download | only in html
      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/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 
     42 namespace WebCore {
     43 
     44 struct DateTimeChooserParameters;
     45 
     46 class BaseMultipleFieldsDateAndTimeInputType
     47     : public BaseDateAndTimeInputType
     48     , protected DateTimeEditElement::EditControlOwner
     49     , protected PickerIndicatorElement::PickerIndicatorOwner
     50     , protected SpinButtonElement::SpinButtonOwner
     51     , protected ClearButtonElement::ClearButtonOwner {
     52 public:
     53     virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const = 0;
     54 
     55 protected:
     56     BaseMultipleFieldsDateAndTimeInputType(HTMLInputElement*);
     57     virtual ~BaseMultipleFieldsDateAndTimeInputType();
     58 
     59     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const = 0;
     60     bool shouldHaveSecondField(const DateComponents&) const;
     61 
     62 private:
     63     // DateTimeEditElement::EditControlOwner functions
     64     virtual void didBlurFromControl() OVERRIDE FINAL;
     65     virtual void didFocusOnControl() OVERRIDE FINAL;
     66     virtual void editControlValueChanged() OVERRIDE FINAL;
     67     virtual bool isEditControlOwnerDisabled() const OVERRIDE FINAL;
     68     virtual bool isEditControlOwnerReadOnly() const OVERRIDE FINAL;
     69     virtual AtomicString localeIdentifier() const OVERRIDE FINAL;
     70 
     71     // SpinButtonElement::SpinButtonOwner functions.
     72     virtual void focusAndSelectSpinButtonOwner() OVERRIDE;
     73     virtual bool shouldSpinButtonRespondToMouseEvents() OVERRIDE;
     74     virtual bool shouldSpinButtonRespondToWheelEvents() OVERRIDE;
     75     virtual void spinButtonStepDown() OVERRIDE;
     76     virtual void spinButtonStepUp() OVERRIDE;
     77 
     78     // PickerIndicatorElement::PickerIndicatorOwner functions
     79     virtual bool isPickerIndicatorOwnerDisabledOrReadOnly() const OVERRIDE FINAL;
     80     virtual void pickerIndicatorChooseValue(const String&) OVERRIDE FINAL;
     81     virtual bool setupDateTimeChooserParameters(DateTimeChooserParameters&) OVERRIDE FINAL;
     82 
     83     // ClearButtonElement::ClearButtonOwner functions.
     84     virtual void focusAndSelectClearButtonOwner() OVERRIDE;
     85     virtual bool shouldClearButtonRespondToMouseEvents() OVERRIDE;
     86     virtual void clearValue() OVERRIDE;
     87 
     88     // InputType functions
     89     virtual String badInputText() const OVERRIDE;
     90     virtual void blur() OVERRIDE FINAL;
     91     virtual PassRefPtr<RenderStyle> customStyleForRenderer(PassRefPtr<RenderStyle>) OVERRIDE;
     92     virtual void createShadowSubtree() OVERRIDE FINAL;
     93     virtual void destroyShadowSubtree() OVERRIDE FINAL;
     94     virtual void disabledAttributeChanged() OVERRIDE FINAL;
     95     virtual void forwardEvent(Event*) OVERRIDE FINAL;
     96     virtual void handleFocusEvent(Element* oldFocusedElement, FocusDirection) OVERRIDE;
     97     virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE FINAL;
     98     virtual bool hasBadInput() const OVERRIDE;
     99     virtual bool hasCustomFocusLogic() const OVERRIDE FINAL;
    100     virtual void minOrMaxAttributeChanged() OVERRIDE FINAL;
    101     virtual void readonlyAttributeChanged() OVERRIDE FINAL;
    102     virtual void requiredAttributeChanged() OVERRIDE FINAL;
    103     virtual void restoreFormControlState(const FormControlState&) OVERRIDE FINAL;
    104     virtual FormControlState saveFormControlState() const OVERRIDE FINAL;
    105     virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE FINAL;
    106     virtual bool shouldUseInputMethod() const OVERRIDE FINAL;
    107     virtual void stepAttributeChanged() OVERRIDE FINAL;
    108     virtual void updateInnerTextValue() OVERRIDE FINAL;
    109     virtual void valueAttributeChanged() OVERRIDE;
    110     virtual void listAttributeTargetChanged() OVERRIDE FINAL;
    111     virtual void updateClearButtonVisibility() OVERRIDE FINAL;
    112 
    113     DateTimeEditElement* dateTimeEditElement() const;
    114     SpinButtonElement* spinButtonElement() const;
    115     ClearButtonElement* clearButtonElement() const;
    116     PickerIndicatorElement* pickerIndicatorElement() const;
    117     bool containsFocusedShadowElement() const;
    118     void showPickerIndicator();
    119     void hidePickerIndicator();
    120     void updatePickerIndicatorVisibility();
    121 
    122     bool m_isDestroyingShadowSubtree;
    123     bool m_pickerIndicatorIsVisible;
    124     bool m_pickerIndicatorIsAlwaysVisible;
    125     bool m_didCreateShadowElements;
    126 };
    127 
    128 } // namespace WebCore
    129 
    130 #endif
    131 #endif // BaseMultipleFieldsDateAndTimeInputType_h
    132