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
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
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"
38 // DateTimeNumericFieldElement represents numeric field of date time format,
45 class DateTimeNumericFieldElement
: public DateTimeFieldElement
{
46 WTF_MAKE_NONCOPYABLE(DateTimeNumericFieldElement
);
50 DISALLOW_ALLOCATION();
51 Step(int step
= 1, int stepBase
= 0) : step(step
), stepBase(stepBase
) { }
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
; }
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
);
79 void setEmptyValue(EventBehavior
= DispatchNoEvent
) final
;
80 void setValueAsInteger(int, EventBehavior
= DispatchNoEvent
) override
;
81 int valueAsInteger() const final
;
82 String
visibleValue() const final
;
85 // DateTimeFieldElement functions.
86 void handleKeyboardEvent(KeyboardEvent
*) final
;
87 float maximumWidth(const Font
&) override
;
88 void stepDown() final
;
90 String
value() const final
;
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
;
102 const Range m_hardLimits
;
106 mutable StringBuilder m_typeAheadBuffer
;