- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / shadow / DateTimeNumericFieldElement.h
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 DateTimeNumericFieldElement_h
27 #define DateTimeNumericFieldElement_h
28
29 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
30 #include "core/html/shadow/DateTimeFieldElement.h"
31
32 #include "wtf/text/StringBuilder.h"
33 #include "wtf/text/WTFString.h"
34
35 namespace WebCore {
36
37 // DateTimeNumericFieldElement represents numeric field of date time format,
38 // such as:
39 //  - hour
40 //  - minute
41 //  - millisecond
42 //  - second
43 //  - year
44 class DateTimeNumericFieldElement : public DateTimeFieldElement {
45     WTF_MAKE_NONCOPYABLE(DateTimeNumericFieldElement);
46
47 public:
48     struct Step {
49         Step(int step = 1, int stepBase = 0) : step(step), stepBase(stepBase) { }
50         int step;
51         int stepBase;
52     };
53
54     struct Range {
55         Range(int minimum, int maximum) : minimum(minimum), maximum(maximum) { }
56         int clampValue(int) const;
57         bool isInRange(int) const;
58         bool isSingleton() const { return minimum == maximum; }
59
60         int minimum;
61         int maximum;
62     };
63
64 protected:
65     DateTimeNumericFieldElement(Document&, FieldOwner&, const Range&, const Range& hardLimits, const String& placeholder, const Step& = Step());
66
67     int clampValue(int value) const { return m_range.clampValue(value); }
68     virtual int defaultValueForStepDown() const;
69     virtual int defaultValueForStepUp() const;
70     const Range& range() const { return m_range; }
71
72     // DateTimeFieldElement functions.
73     virtual bool hasValue() const OVERRIDE FINAL;
74     void initialize(const AtomicString& pseudo, const String& axHelpText);
75     int maximum() const;
76     virtual void setEmptyValue(EventBehavior = DispatchNoEvent) OVERRIDE FINAL;
77     virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) OVERRIDE;
78     virtual int valueAsInteger() const OVERRIDE FINAL;
79     virtual String visibleValue() const OVERRIDE FINAL;
80
81 private:
82     // DateTimeFieldElement functions.
83     virtual void didBlur() OVERRIDE FINAL;
84     virtual void handleKeyboardEvent(KeyboardEvent*) OVERRIDE FINAL;
85     virtual float maximumWidth(const Font&) OVERRIDE;
86     virtual void stepDown() OVERRIDE FINAL;
87     virtual void stepUp() OVERRIDE FINAL;
88     virtual String value() const OVERRIDE FINAL;
89
90     String formatValue(int) const;
91     int roundUp(int) const;
92     int roundDown(int) const;
93     int typeAheadValue() const;
94
95     DOMTimeStamp m_lastDigitCharTime;
96     const String m_placeholder;
97     const Range m_range;
98     const Range m_hardLimits;
99     const Step m_step;
100     int m_value;
101     bool m_hasValue;
102     mutable StringBuilder m_typeAheadBuffer;
103 };
104
105 } // namespace WebCore
106
107 #endif
108 #endif