Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / shadow / DateTimeNumericFieldElement.h
blobfa5c0324ffa6fd17cb052fda7f489cc4920aca28
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
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.
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.
26 #ifndef DateTimeNumericFieldElement_h
27 #define DateTimeNumericFieldElement_h
29 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
30 #include "core/html/shadow/DateTimeFieldElement.h"
32 #include "wtf/Allocator.h"
33 #include "wtf/text/StringBuilder.h"
34 #include "wtf/text/WTFString.h"
36 namespace blink {
38 // DateTimeNumericFieldElement represents numeric field of date time format,
39 // such as:
40 // - hour
41 // - minute
42 // - millisecond
43 // - second
44 // - year
45 class DateTimeNumericFieldElement : public DateTimeFieldElement {
46 WTF_MAKE_NONCOPYABLE(DateTimeNumericFieldElement);
48 public:
49 struct Step {
50 DISALLOW_ALLOCATION();
51 Step(int step = 1, int stepBase = 0) : step(step), stepBase(stepBase) { }
52 int step;
53 int stepBase;
56 struct Range {
57 DISALLOW_ALLOCATION();
58 Range(int minimum, int maximum) : minimum(minimum), maximum(maximum) { }
59 int clampValue(int) const;
60 bool isInRange(int) const;
61 bool isSingleton() const { return minimum == maximum; }
63 int minimum;
64 int maximum;
67 protected:
68 DateTimeNumericFieldElement(Document&, FieldOwner&, const Range&, const Range& hardLimits, const String& placeholder, const Step& = Step());
70 int clampValue(int value) const { return m_range.clampValue(value); }
71 virtual int defaultValueForStepDown() const;
72 virtual int defaultValueForStepUp() const;
73 const Range& range() const { return m_range; }
75 // DateTimeFieldElement functions.
76 bool hasValue() const final;
77 void initialize(const AtomicString& pseudo, const String& axHelpText);
78 int maximum() const;
79 void setEmptyValue(EventBehavior = DispatchNoEvent) final;
80 void setValueAsInteger(int, EventBehavior = DispatchNoEvent) override;
81 int valueAsInteger() const final;
82 String visibleValue() const final;
84 private:
85 // DateTimeFieldElement functions.
86 void handleKeyboardEvent(KeyboardEvent*) final;
87 float maximumWidth(const Font&) override;
88 void stepDown() final;
89 void stepUp() final;
90 String value() const final;
92 // Node functions.
93 void setFocus(bool) final;
95 String formatValue(int) const;
96 int roundUp(int) const;
97 int roundDown(int) const;
98 int typeAheadValue() const;
100 const String m_placeholder;
101 const Range m_range;
102 const Range m_hardLimits;
103 const Step m_step;
104 int m_value;
105 bool m_hasValue;
106 mutable StringBuilder m_typeAheadBuffer;
109 } // namespace blink
111 #endif
112 #endif