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