Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/DateTimeEditElement.h

Issue 2815263002: Move form-related files in core/html/shadow to core/html/forms. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26 #ifndef DateTimeEditElement_h
27 #define DateTimeEditElement_h
28
29 #include "core/html/forms/StepRange.h"
30 #include "core/html/shadow/DateTimeFieldElement.h"
31 #include "platform/DateComponents.h"
32 #include "platform/wtf/Allocator.h"
33 #include "public/platform/WebFocusType.h"
34
35 namespace blink {
36
37 class DateTimeFieldsState;
38 class Locale;
39 class StepRange;
40
41 // DateTimeEditElement class contains numberic field and symbolc field for
42 // representing date and time, such as
43 // - Year, Month, Day Of Month
44 // - Hour, Minute, Second, Millisecond, AM/PM
45 class DateTimeEditElement final : public HTMLDivElement,
46 public DateTimeFieldElement::FieldOwner {
47 WTF_MAKE_NONCOPYABLE(DateTimeEditElement);
48 USING_GARBAGE_COLLECTED_MIXIN(DateTimeEditElement);
49
50 public:
51 // EditControlOwner implementer must call removeEditControlOwner when
52 // it doesn't handle event, e.g. at destruction.
53 class EditControlOwner : public GarbageCollectedMixin {
54 public:
55 virtual ~EditControlOwner();
56 virtual void DidBlurFromControl(WebFocusType) = 0;
57 virtual void DidFocusOnControl(WebFocusType) = 0;
58 virtual void EditControlValueChanged() = 0;
59 virtual String FormatDateTimeFieldsState(
60 const DateTimeFieldsState&) const = 0;
61 virtual bool IsEditControlOwnerDisabled() const = 0;
62 virtual bool IsEditControlOwnerReadOnly() const = 0;
63 virtual AtomicString LocaleIdentifier() const = 0;
64 virtual void EditControlDidChangeValueByKeyboard() = 0;
65 };
66
67 struct LayoutParameters {
68 STACK_ALLOCATED();
69 String date_time_format;
70 String fallback_date_time_format;
71 Locale& locale;
72 const StepRange step_range;
73 DateComponents minimum;
74 DateComponents maximum;
75 String placeholder_for_day;
76 String placeholder_for_month;
77 String placeholder_for_year;
78
79 LayoutParameters(Locale& locale, const StepRange& step_range)
80 : locale(locale), step_range(step_range) {}
81 };
82
83 static DateTimeEditElement* Create(Document&, EditControlOwner&);
84
85 ~DateTimeEditElement() override;
86 DECLARE_VIRTUAL_TRACE();
87
88 void AddField(DateTimeFieldElement*);
89 bool AnyEditableFieldsHaveValues() const;
90 void BlurByOwner();
91 void DefaultEventHandler(Event*) override;
92 void DisabledStateChanged();
93 Element* FieldsWrapperElement() const;
94 void FocusIfNoFocus();
95 // If oldFocusedNode is one of sub-fields, focus on it. Otherwise focus on
96 // the first sub-field.
97 void FocusByOwner(Element* old_focused_element = 0);
98 bool HasFocusedField();
99 void ReadOnlyStateChanged();
100 void RemoveEditControlOwner() { edit_control_owner_ = nullptr; }
101 void ResetFields();
102 void SetEmptyValue(const LayoutParameters&,
103 const DateComponents& date_for_read_only_field);
104 void SetValueAsDate(const LayoutParameters&, const DateComponents&);
105 void SetValueAsDateTimeFieldsState(const DateTimeFieldsState&);
106 void SetOnlyYearMonthDay(const DateComponents&);
107 void StepDown();
108 void StepUp();
109 String Value() const;
110 DateTimeFieldsState ValueAsDateTimeFieldsState() const;
111
112 private:
113 static const size_t kInvalidFieldIndex = static_cast<size_t>(-1);
114
115 // Datetime can be represent at most five fields, such as
116 // 1. year
117 // 2. month
118 // 3. day-of-month
119 // 4. hour
120 // 5. minute
121 // 6. second
122 // 7. millisecond
123 // 8. AM/PM
124 static const int kMaximumNumberOfFields = 8;
125
126 DateTimeEditElement(Document&, EditControlOwner&);
127
128 DateTimeFieldElement* FieldAt(size_t) const;
129 size_t FieldIndexOf(const DateTimeFieldElement&) const;
130 DateTimeFieldElement* FocusedField() const;
131 size_t FocusedFieldIndex() const;
132 bool FocusOnNextFocusableField(size_t start_index);
133 bool IsDisabled() const;
134 bool IsReadOnly() const;
135 void GetLayout(const LayoutParameters&, const DateComponents&);
136 void UpdateUIState();
137
138 // Element function.
139 PassRefPtr<ComputedStyle> CustomStyleForLayoutObject() override;
140 bool IsDateTimeEditElement() const override;
141
142 // DateTimeFieldElement::FieldOwner functions.
143 void DidBlurFromField(WebFocusType) override;
144 void DidFocusOnField(WebFocusType) override;
145 void FieldValueChanged() override;
146 bool FocusOnNextField(const DateTimeFieldElement&) override;
147 bool FocusOnPreviousField(const DateTimeFieldElement&) override;
148 bool IsFieldOwnerDisabled() const override;
149 bool IsFieldOwnerReadOnly() const override;
150 AtomicString LocaleIdentifier() const override;
151 void FieldDidChangeValueByKeyboard() override;
152
153 HeapVector<Member<DateTimeFieldElement>, kMaximumNumberOfFields> fields_;
154 Member<EditControlOwner> edit_control_owner_;
155 };
156
157 DEFINE_TYPE_CASTS(DateTimeEditElement,
158 Element,
159 element,
160 element->IsDateTimeEditElement(),
161 element.IsDateTimeEditElement());
162
163 } // namespace blink
164
165 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698