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 THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_MULTIPLE_FIELDS_TEMPORAL_INPUT_TYPE_VIEW_H_
32 #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_MULTIPLE_FIELDS_TEMPORAL_INPUT_TYPE_VIEW_H_
33 
34 #include "third_party/blink/public/mojom/input/focus_type.mojom-blink-forward.h"
35 #include "third_party/blink/renderer/core/html/forms/clear_button_element.h"
36 #include "third_party/blink/renderer/core/html/forms/date_time_edit_element.h"
37 #include "third_party/blink/renderer/core/html/forms/input_type_view.h"
38 #include "third_party/blink/renderer/core/html/forms/picker_indicator_element.h"
39 #include "third_party/blink/renderer/core/html/forms/spin_button_element.h"
40 
41 namespace blink {
42 
43 class BaseTemporalInputType;
44 struct DateTimeChooserParameters;
45 
46 class MultipleFieldsTemporalInputTypeView final
47     : public GarbageCollected<MultipleFieldsTemporalInputTypeView>,
48       public InputTypeView,
49       protected DateTimeEditElement::EditControlOwner,
50       protected PickerIndicatorElement::PickerIndicatorOwner,
51       protected SpinButtonElement::SpinButtonOwner,
52       protected ClearButtonElement::ClearButtonOwner {
53  public:
54   MultipleFieldsTemporalInputTypeView(HTMLInputElement&,
55                                       BaseTemporalInputType&);
56   ~MultipleFieldsTemporalInputTypeView() override;
57   void Trace(Visitor*) const override;
58 
59   wtf_size_t FocusedFieldIndex() const override;
60 
61  private:
62   // DateTimeEditElement::EditControlOwner functions
63   void DidBlurFromControl(mojom::blink::FocusType) final;
64   void DidFocusOnControl(mojom::blink::FocusType) final;
65   void EditControlValueChanged() final;
66   String FormatDateTimeFieldsState(const DateTimeFieldsState&) const override;
67   bool IsEditControlOwnerDisabled() const final;
68   bool IsEditControlOwnerReadOnly() const final;
69   AtomicString LocaleIdentifier() const final;
70   void EditControlDidChangeValueByKeyboard() final;
71 
72   // SpinButtonElement::SpinButtonOwner functions.
73   void FocusAndSelectSpinButtonOwner() override;
74   bool ShouldSpinButtonRespondToMouseEvents() override;
75   bool ShouldSpinButtonRespondToWheelEvents() override;
76   void SpinButtonStepDown() override;
77   void SpinButtonStepUp() override;
78   void SpinButtonDidReleaseMouseCapture(
79       SpinButtonElement::EventDispatch) override;
80 
81   // PickerIndicatorElement::PickerIndicatorOwner functions
82   bool IsPickerIndicatorOwnerDisabledOrReadOnly() const final;
83   void PickerIndicatorChooseValue(const String&) final;
84   void PickerIndicatorChooseValue(double) final;
85   Element& PickerOwnerElement() const final;
86   bool SetupDateTimeChooserParameters(DateTimeChooserParameters&) final;
87   void DidEndChooser() final;
88   String AriaRoleForPickerIndicator() const final;
89 
90   // ClearButtonElement::ClearButtonOwner functions.
91   void FocusAndSelectClearButtonOwner() override;
92   bool ShouldClearButtonRespondToMouseEvents() override;
93   void ClearValue() override;
94 
95   // InputTypeView functions
96   void Blur() final;
97   void ClosePopupView() override;
98   bool HasOpenedPopup() const override;
99   void CustomStyleForLayoutObject(ComputedStyle& style) override;
100   void CreateShadowSubtree() final;
101   void DestroyShadowSubtree() final;
102   void DisabledAttributeChanged() final;
103   void ForwardEvent(Event&) final;
104   void HandleClickEvent(MouseEvent&) final;
105   void HandleFocusInEvent(Element* old_focused_element,
106                           mojom::blink::FocusType) final;
107   void HandleKeydownEvent(KeyboardEvent&) final;
108   bool HasBadInput() const override;
109   bool HasCustomFocusLogic() const final;
110   void MinOrMaxAttributeChanged() final;
111   void ReadonlyAttributeChanged() final;
112   void RequiredAttributeChanged() final;
113   void RestoreFormControlState(const FormControlState&) final;
114   FormControlState SaveFormControlState() const final;
115   void DidSetValue(const String&, bool value_changed) final;
116   void StepAttributeChanged() final;
117   void UpdateView() final;
118   void ValueAttributeChanged() override;
119   void ListAttributeTargetChanged() final;
120   void UpdateClearButtonVisibility() final;
121   TextDirection ComputedTextDirection() final;
122   AXObject* PopupRootAXObject() final;
123 
124   DateTimeEditElement* GetDateTimeEditElement() const;
125   SpinButtonElement* GetSpinButtonElement() const;
126   ClearButtonElement* GetClearButtonElement() const;
127   PickerIndicatorElement* GetPickerIndicatorElement() const;
128   bool ContainsFocusedShadowElement() const;
129   void ShowPickerIndicator();
130   void HidePickerIndicator();
131   void UpdatePickerIndicatorVisibility();
132 
133   Member<BaseTemporalInputType> input_type_;
134   bool is_destroying_shadow_subtree_;
135   bool picker_indicator_is_visible_;
136   bool picker_indicator_is_always_visible_;
137 };
138 
139 }  // namespace blink
140 
141 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_MULTIPLE_FIELDS_TEMPORAL_INPUT_TYPE_VIEW_H_
142