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/text/StringBuilder.h"
33 #include "wtf/text/WTFString.h"
37 // DateTimeNumericFieldElement represents numeric field of date time format,
44 class DateTimeNumericFieldElement : public DateTimeFieldElement {
45 WTF_MAKE_NONCOPYABLE(DateTimeNumericFieldElement);
49 Step(int step = 1, int stepBase = 0) : step(step), stepBase(stepBase) { }
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; }
65 DateTimeNumericFieldElement(Document&, FieldOwner&, const Range&, const Range& hardLimits, const String& placeholder, const Step& = Step());
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; }
72 // DateTimeFieldElement functions.
73 virtual bool hasValue() const override final;
74 void initialize(const AtomicString& pseudo, const String& axHelpText);
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;
82 // DateTimeFieldElement functions.
83 virtual void handleKeyboardEvent(KeyboardEvent*) override final;
84 virtual float maximumWidth(const Font&) override;
85 virtual void stepDown() override final;
86 virtual void stepUp() override final;
87 virtual String value() const override final;
90 virtual void setFocus(bool) override final;
92 String formatValue(int) const;
93 int roundUp(int) const;
94 int roundDown(int) const;
95 int typeAheadValue() const;
97 const String m_placeholder;
99 const Range m_hardLimits;
103 mutable StringBuilder m_typeAheadBuffer;