15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *           (C) 1999 Antti Koivisto (koivisto@kde.org)
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *           (C) 2001 Dirk Mueller (mueller@kde.org)
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2009, 2010, 2011, 2012 Google Inc. All rights reserved.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2012 Samsung Electronics. All rights reserved.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version.
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful,
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details.
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA.
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
2906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/InputType.h"
3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
31197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ExceptionMessages.h"
32197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ExceptionState.h"
335d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/InputTypeNames.h"
3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/accessibility/AXObjectCache.h"
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/NodeRenderStyle.h"
361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/events/KeyboardEvent.h"
371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/events/ScopedEventQueue.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/fileapi/FileList.h"
3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/frame/FrameHost.h"
40bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "core/html/FormDataList.h"
4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLInputElement.h"
42d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/html/HTMLShadowElement.h"
4306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/ButtonInputType.h"
4406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/CheckboxInputType.h"
457242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/html/forms/ColorChooser.h"
4606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/ColorInputType.h"
4706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/DateInputType.h"
4806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/DateTimeLocalInputType.h"
4906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/EmailInputType.h"
5006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/FileInputType.h"
5106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/FormController.h"
5206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/HiddenInputType.h"
5306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/ImageInputType.h"
5406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/MonthInputType.h"
5506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/NumberInputType.h"
5606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/PasswordInputType.h"
5706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/RadioInputType.h"
5806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/RangeInputType.h"
5906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/ResetInputType.h"
6006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/SearchInputType.h"
6106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/SubmitInputType.h"
6206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/TelephoneInputType.h"
6306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/TextInputType.h"
6406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/TimeInputType.h"
6506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/URLInputType.h"
6606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/WeekInputType.h"
6753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/parser/HTMLParserIdioms.h"
6853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderTheme.h"
695d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "platform/RuntimeEnabledFeatures.h"
701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/text/PlatformLocale.h"
711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/text/TextBreakIterator.h"
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
73c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)using blink::WebLocalizedString;
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)using namespace HTMLNames;
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
78323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)typedef PassRefPtrWillBeRawPtr<InputType> (*InputTypeFactoryFunction)(HTMLInputElement&);
79926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)typedef HashMap<AtomicString, InputTypeFactoryFunction, CaseFoldingHash> InputTypeFactoryMap;
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static PassOwnPtr<InputTypeFactoryMap> createInputTypeFactoryMap()
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    OwnPtr<InputTypeFactoryMap> map = adoptPtr(new InputTypeFactoryMap);
8451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::button, ButtonInputType::create);
8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::checkbox, CheckboxInputType::create);
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    map->add(InputTypeNames::color, ColorInputType::create);
8751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::date, DateInputType::create);
8851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::datetime_local, DateTimeLocalInputType::create);
8951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::email, EmailInputType::create);
9051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::file, FileInputType::create);
9151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::hidden, HiddenInputType::create);
9251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::image, ImageInputType::create);
9351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::month, MonthInputType::create);
9451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::number, NumberInputType::create);
9551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::password, PasswordInputType::create);
9651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::radio, RadioInputType::create);
9751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::range, RangeInputType::create);
9851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::reset, ResetInputType::create);
9951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::search, SearchInputType::create);
10051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::submit, SubmitInputType::create);
10151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::tel, TelephoneInputType::create);
10251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::time, TimeInputType::create);
10351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    map->add(InputTypeNames::url, URLInputType::create);
10409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    map->add(InputTypeNames::week, WeekInputType::create);
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // No need to register "text" because it is the default type.
1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return map.release();
1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1098abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)static const InputTypeFactoryMap* factoryMap()
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    static const InputTypeFactoryMap* factoryMap = createInputTypeFactoryMap().leakPtr();
1128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    return factoryMap;
1138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
1148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
115323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)PassRefPtrWillBeRawPtr<InputType> InputType::create(HTMLInputElement& element, const AtomicString& typeName)
1168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
1178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    InputTypeFactoryFunction factory = typeName.isEmpty() ? 0 : factoryMap()->get(typeName);
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!factory)
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        factory = TextInputType::create;
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return factory(element);
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
123323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)PassRefPtrWillBeRawPtr<InputType> InputType::createText(HTMLInputElement& element)
1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return TextInputType::create(element);
1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)const AtomicString& InputType::normalizeTypeName(const AtomicString& typeName)
1298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
1308abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    if (typeName.isEmpty())
13151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        return InputTypeNames::text;
1328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    InputTypeFactoryMap::const_iterator it = factoryMap()->find(typeName);
13351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    return it == factoryMap()->end() ? InputTypeNames::text : it->key;
1348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
1358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)InputType::~InputType()
1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isTextField() const
1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::shouldSaveAndRestoreFormControlState() const
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)FormControlState InputType::saveFormControlState() const
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
152bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    String currentValue = element().value();
153bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (currentValue == element().defaultValue())
1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return FormControlState();
1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return FormControlState(currentValue);
1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void InputType::restoreFormControlState(const FormControlState& state)
1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
160bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    element().setValue(state[0]);
1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isFormDataAppendable() const
1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // There is no form data unless there's a name for non-image types.
166bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return !element().name().isEmpty();
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::appendFormData(FormDataList& encoding, bool) const
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Always successful.
172bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    encoding.appendData(element().name(), element().value());
1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
176bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)String InputType::resultForDialogSubmit() const
177bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
178bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return element().fastGetAttribute(valueAttr);
179bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
180bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)double InputType::valueAsDate() const
1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return DateComponents::invalidMilliseconds();
1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void InputType::setValueAsDate(double, ExceptionState& exceptionState) const
1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    exceptionState.throwDOMException(InvalidStateError, "This input element does not support Date values.");
1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)double InputType::valueAsDouble() const
1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1935d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    return std::numeric_limits<double>::quiet_NaN();
1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void InputType::setValueAsDouble(double doubleValue, TextFieldEventBehavior eventBehavior, ExceptionState& exceptionState) const
1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
19809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    exceptionState.throwDOMException(InvalidStateError, "This input element does not support Number values.");
1995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void InputType::setValueAsDecimal(const Decimal& newValue, TextFieldEventBehavior eventBehavior, ExceptionState&) const
2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
20309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    element().setValue(serialize(newValue), eventBehavior);
2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::supportsValidation() const
2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::typeMismatchFor(const String&) const
2125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
2145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::typeMismatch() const
2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::supportsRequired() const
2225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Almost all validatable types support @required.
2245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return supportsValidation();
2255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::valueMissing(const String&) const
2285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
2305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
232926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool InputType::hasBadInput() const
233926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
234926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return false;
235926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
236926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
2377242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccibool InputType::tooLong(const String&, HTMLTextFormControlElement::NeedsToCheckDirtyFlag) const
2387242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{
2397242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return false;
2407242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci}
2417242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
2425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::patternMismatch(const String&) const
2435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::rangeUnderflow(const String& value) const
2485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal numericValue = parseToNumberOrNaN(value);
2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!numericValue.isFinite())
2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return numericValue < createStepRange(RejectAny).minimum();
2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::rangeOverflow(const String& value) const
2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
2635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal numericValue = parseToNumberOrNaN(value);
2655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!numericValue.isFinite())
2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
2675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return numericValue > createStepRange(RejectAny).maximum();
2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Decimal InputType::defaultValueForStepUp() const
2725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
2745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)double InputType::minimum() const
2775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return createStepRange(RejectAny).minimum().toDouble();
2795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)double InputType::maximum() const
2825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return createStepRange(RejectAny).maximum().toDouble();
2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isInRange(const String& value) const
2875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
2905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal numericValue = parseToNumberOrNaN(value);
2925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!numericValue.isFinite())
2935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return true;
2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    StepRange stepRange(createStepRange(RejectAny));
2965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return numericValue >= stepRange.minimum() && numericValue <= stepRange.maximum();
2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isOutOfRange(const String& value) const
3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
3025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
3035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal numericValue = parseToNumberOrNaN(value);
3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!numericValue.isFinite())
3065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return true;
3075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    StepRange stepRange(createStepRange(RejectAny));
3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return numericValue < stepRange.minimum() || numericValue > stepRange.maximum();
3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::stepMismatch(const String& value) const
3135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
3155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
3165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal numericValue = parseToNumberOrNaN(value);
3185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!numericValue.isFinite())
3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return createStepRange(RejectAny).stepMismatch(numericValue);
3225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
324926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)String InputType::badInputText() const
325926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
326926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    ASSERT_NOT_REACHED();
32706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    return locale().queryString(WebLocalizedString::ValidationTypeMismatch);
32806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)}
32906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
33006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)String InputType::rangeOverflowText(const Decimal&) const
33106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles){
33206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    ASSERT_NOT_REACHED();
33306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    return String();
33406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)}
33506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
33606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)String InputType::rangeUnderflowText(const Decimal&) const
33706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles){
33806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    ASSERT_NOT_REACHED();
33906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    return String();
340926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
341926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
3425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::typeMismatchText() const
3435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
34406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    return locale().queryString(WebLocalizedString::ValidationTypeMismatch);
3455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::valueMissingText() const
3485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
34906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    return locale().queryString(WebLocalizedString::ValidationValueMissing);
3505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::validationMessage() const
3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
354bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    const String value = element().value();
3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The order of the following checks is meaningful. e.g. We'd like to show the
357926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // badInput message even if the control has other validation errors.
358926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (hasBadInput())
359926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return badInputText();
360926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
3615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (valueMissing(value))
3625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return valueMissingText();
3635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (typeMismatch())
3655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return typeMismatchText();
3665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (patternMismatch(value))
36806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)        return locale().queryString(WebLocalizedString::ValidationPatternMismatch);
3695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
370bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (element().tooLong())
371bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        return locale().validationMessageTooLongText(value.length(), element().maxLength());
3725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
3745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return emptyString();
3755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal numericValue = parseToNumberOrNaN(value);
3775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!numericValue.isFinite())
3785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return emptyString();
3795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    StepRange stepRange(createStepRange(RejectAny));
3815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (numericValue < stepRange.minimum())
38306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)        return rangeUnderflowText(stepRange.minimum());
3845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (numericValue > stepRange.maximum())
38606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)        return rangeOverflowText(stepRange.maximum());
3875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (stepRange.stepMismatch(numericValue)) {
3899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        ASSERT(stepRange.hasStep());
3909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        Decimal candidate1 = stepRange.clampValue(numericValue);
3919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        String localizedCandidate1 = localizeValue(serialize(candidate1));
3929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        Decimal candidate2 = candidate1 < numericValue ? candidate1 + stepRange.step() : candidate1 - stepRange.step();
3939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        if (!candidate2.isFinite() || candidate2 < stepRange.minimum() || candidate2 > stepRange.maximum())
3949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)            return locale().queryString(WebLocalizedString::ValidationStepMismatchCloseToLimit, localizedCandidate1);
3959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        String localizedCandidate2 = localizeValue(serialize(candidate2));
3969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        if (candidate1 < candidate2)
3979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)            return locale().queryString(WebLocalizedString::ValidationStepMismatch, localizedCandidate1, localizedCandidate2);
3989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)        return locale().queryString(WebLocalizedString::ValidationStepMismatch, localizedCandidate2, localizedCandidate1);
3995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
4005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return emptyString();
4025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::shouldSubmitImplicitly(Event* event)
4055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return event->isKeyboardEvent() && event->type() == EventTypeNames::keypress && toKeyboardEvent(event)->charCode() == '\r';
4075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Decimal InputType::parseToNumber(const String&, const Decimal& defaultValue) const
4105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
4125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return defaultValue;
4135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Decimal InputType::parseToNumberOrNaN(const String& string) const
4165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return parseToNumber(string, Decimal::nan());
4185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::serialize(const Decimal&) const
4215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
4235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return String();
4245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void InputType::dispatchSimulatedClickIfActive(KeyboardEvent* event) const
4275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
428bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (element().active())
429bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        element().dispatchSimulatedClick(event);
4305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    event->setDefaultHandled();
4315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Chrome* InputType::chrome() const
4345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
43509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (FrameHost* host = element().document().frameHost())
43609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return &host->chrome();
4375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
4385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)Locale& InputType::locale() const
4419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){
442bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return element().locale();
4439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)}
4449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)
4455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::canSetStringValue() const
4465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
4485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::hasCustomFocusLogic() const
4515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
4535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
455f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)bool InputType::isKeyboardFocusable() const
4565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
457bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return element().isFocusable();
4585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
460591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochbool InputType::shouldShowFocusRingOnMouseFocus() const
4615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
462591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    return false;
4635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
465e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void InputType::enableSecureTextInput()
466e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
467e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
468e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
469e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void InputType::disableSecureTextInput()
470e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
471e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
472e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
4735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void InputType::accessKeyAction(bool)
4745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
475bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    element().focus(false);
4765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
478e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void InputType::countUsage()
479e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
480e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
481e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
4825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::shouldRespectAlignAttribute()
4835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
4855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
487e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void InputType::sanitizeValueInResponseToMinOrMaxAttributeChange()
488e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
489e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
490e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
4915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::canBeSuccessfulSubmitButton()
4925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
4945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::rendererIsNeeded()
4975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
4995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)FileList* InputType::files()
5025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
5045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
506d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void InputType::setFiles(PassRefPtrWillBeRawPtr<FileList>)
5075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::getTypeSpecificValue(String&)
5115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
5135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::fallbackValue() const
5165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return String();
5185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::defaultValue() const
5215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return String();
5235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::canSetSuggestedValue()
5265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
5285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::shouldSendChangeEventAfterCheckedChanged()
5315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
5335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::storesValueSeparateFromAttribute()
5365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
5385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
540323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)bool InputType::shouldDispatchFormControlChangeEvent(String& oldValue, String& newValue)
541323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles){
542323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    return !equalIgnoringNullity(oldValue, newValue);
543323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)}
544323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
5455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void InputType::setValue(const String& sanitizedValue, bool valueChanged, TextFieldEventBehavior eventBehavior)
5465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
547bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    element().setValueInternal(sanitizedValue, eventBehavior);
54809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    element().setNeedsStyleRecalc(SubtreeStyleChange);
549926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!valueChanged)
550926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return;
551926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    switch (eventBehavior) {
552926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case DispatchChangeEvent:
553bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        element().dispatchFormControlChangeEvent();
554926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        break;
555926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case DispatchInputAndChangeEvent:
556bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        element().dispatchFormControlInputEvent();
557bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        element().dispatchFormControlChangeEvent();
558926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        break;
559926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    case DispatchNoEvent:
560926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        break;
561926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
5625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::canSetValue(const String&)
5655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
5675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::localizeValue(const String& proposedValue) const
5705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return proposedValue;
5725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::visibleValue() const
5755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
576bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return element().value();
5775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::sanitizeValue(const String& proposedValue) const
5805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return proposedValue;
5825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5847242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccivoid InputType::warnIfValueIsInvalidAndElementIsVisible(const String& value) const
5857242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{
5867242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // Don't warn if the value is set in Modernizr.
5877242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    RenderStyle* style = element().renderStyle();
5887242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (style && style->visibility() != HIDDEN)
5897242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        warnIfValueIsInvalid(value);
5907242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci}
5917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
592e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)void InputType::warnIfValueIsInvalid(const String&) const
593e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles){
594e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)}
595e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
5965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::receiveDroppedFiles(const DragData*)
5975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
5995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::droppedFileSystemId()
6035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
6055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return String();
6065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::shouldRespectListAttribute()
6095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::shouldRespectSpeechAttribute()
6145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isTextButton() const
6195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
623bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)bool InputType::isInteractiveContent() const
6245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
6265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isEnumeratable()
6295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
6315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isCheckable()
6345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::isSteppable() const
6395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6437242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccibool InputType::shouldRespectHeightAndWidthAttributes()
6445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6487242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucciint InputType::maxLength() const
6495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6507242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return HTMLInputElement::maximumLength;
6515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::supportsPlaceholder() const
6545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
658926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool InputType::supportsReadOnly() const
659926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
660926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return false;
661926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
662926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
6635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String InputType::defaultToolTip() const
6645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return String();
6665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Decimal InputType::findClosestTickMarkValue(const Decimal&)
6695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
6715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return Decimal::nan();
6725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void InputType::handleDOMActivateEvent(Event*)
6759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){
6769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)}
6779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)
67843e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)bool InputType::hasLegalLinkAttribute(const QualifiedName&) const
67943e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles){
68043e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    return false;
68143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)}
68243e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)
68343e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)const QualifiedName& InputType::subResourceAttributeName() const
68443e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles){
6855d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    return QualifiedName::null();
68643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)}
68743e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)
6887242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccibool InputType::shouldAppearIndeterminate() const
6895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
6915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
693e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochbool InputType::supportsInputModeAttribute() const
694e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch{
695e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    return false;
696e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
697e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
6985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::supportsSelectionAPI() const
6995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
7015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)unsigned InputType::height() const
7045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
7065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)unsigned InputType::width() const
7095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
7115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
713c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)TextDirection InputType::computedTextDirection()
714c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){
715c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    return element().computedStyle()->direction();
716c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
717c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
7187242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano TucciColorChooserClient* InputType::colorChooserClient()
7197242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{
7207242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return 0;
7217242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci}
7227242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
72309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void InputType::applyStep(const Decimal& current, int count, AnyStepHandling anyStepHandling, TextFieldEventBehavior eventBehavior, ExceptionState& exceptionState)
7245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    StepRange stepRange(createStepRange(anyStepHandling));
7265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!stepRange.hasStep()) {
72709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        exceptionState.throwDOMException(InvalidStateError, "This form element does not have an allowed value step.");
7285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
7295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
7305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
73109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    EventQueueScope scope;
73209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    const Decimal step = stepRange.step();
7335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
734bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    const AtomicString& stepString = element().fastGetAttribute(stepAttr);
73509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!equalIgnoringCase(stepString, "any") && stepRange.stepMismatch(current)) {
73609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // Snap-to-step / clamping steps
73709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // If the current value is not matched to step value:
73809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // - The value should be the larger matched value nearest to 0 if count > 0
73909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        //   e.g. <input type=number value=3 min=-100 step=3> -> 5
74009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // - The value should be the smaller matched value nearest to 0 if count < 0
74109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        //   e.g. <input type=number value=3 min=-100 step=3> -> 2
74209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        //
74309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
74409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        ASSERT(!step.isZero());
74509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        Decimal newValue;
74609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        const Decimal base = stepRange.stepBase();
74709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (count < 0)
74809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = base + ((current - base) / step).floor() * step;
74909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        else if (count > 0)
75009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = base + ((current - base) / step).ceiling() * step;
75109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        else
75209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = current;
75309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
75409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (newValue < stepRange.minimum())
75509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = stepRange.minimum();
75609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (newValue > stepRange.maximum())
75709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = stepRange.maximum();
75809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
75909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        setValueAsDecimal(newValue, count == 1 || count == -1 ? DispatchChangeEvent : DispatchNoEvent, IGNORE_EXCEPTION);
76009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (count > 1) {
76109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            applyStep(newValue, count - 1, AnyIsDefaultStep, DispatchChangeEvent, IGNORE_EXCEPTION);
76209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return;
76309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
76409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (count < -1) {
76509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            applyStep(newValue, count + 1, AnyIsDefaultStep, DispatchChangeEvent, IGNORE_EXCEPTION);
76609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return;
76709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
76809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    } else {
76909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        Decimal newValue = current + stepRange.step() * count;
7705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
77109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (!equalIgnoringCase(stepString, "any"))
77209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = stepRange.alignValueForStep(current, newValue);
7735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
77409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (newValue > stepRange.maximum())
77509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = newValue - stepRange.step();
77609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        else if (newValue < stepRange.minimum())
77709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            newValue = newValue + stepRange.step();
7785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
77909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        setValueAsDecimal(newValue, eventBehavior, exceptionState);
78009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
781bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (AXObjectCache* cache = element().document().existingAXObjectCache())
782bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        cache->postNotification(&element(), AXObjectCache::AXValueChanged, true);
7835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool InputType::getAllowedValueStep(Decimal* step) const
7865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    StepRange stepRange(createStepRange(RejectAny));
7885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    *step = stepRange.step();
7895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return stepRange.hasStep();
7905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)StepRange InputType::createStepRange(AnyStepHandling) const
7935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
7955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return StepRange();
7965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
79851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void InputType::stepUp(int n, ExceptionState& exceptionState)
7995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable()) {
80109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        exceptionState.throwDOMException(InvalidStateError, "This form element is not steppable.");
8025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
8035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
80409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    const Decimal current = parseToNumber(element().value(), 0);
80509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    applyStep(current, n, RejectAny, DispatchNoEvent, exceptionState);
8065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void InputType::stepUpFromRenderer(int n)
8095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
81009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // The only difference from stepUp()/stepDown() is the extra treatment
81109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // of the current value before applying the step:
8125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //
8135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If the current value is not a number, including empty, the current value is assumed as 0.
8145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //   * If 0 is in-range, and matches to step value
8155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     - The value should be the +step if n > 0
8165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     - The value should be the -step if n < 0
8175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     If -step or +step is out of range, new value should be 0.
8185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //   * If 0 is smaller than the minimum value
8195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     - The value should be the minimum value for any n
8205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //   * If 0 is larger than the maximum value
8215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     - The value should be the maximum value for any n
8225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //   * If 0 is in-range, but not matched to step value
8235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     - The value should be the larger matched value nearest to 0 if n > 0
8245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //       e.g. <input type=number min=-100 step=3> -> 2
8255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //     - The value should be the smaler matched value nearest to 0 if n < 0
8265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //       e.g. <input type=number min=-100 step=3> -> -1
8275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //   As for date/datetime-local/month/time/week types, the current value is assumed as "the current local date/time".
8285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //   As for datetime type, the current value is assumed as "the current date/time in UTC".
8295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If the current value is smaller than the minimum value:
8305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //  - The value should be the minimum value if n > 0
8315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //  - Nothing should happen if n < 0
8325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If the current value is larger than the maximum value:
8335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //  - The value should be the maximum value if n < 0
8345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //  - Nothing should happen if n > 0
8355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    //
8365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // n is assumed as -n if step < 0.
8375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(isSteppable());
8395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isSteppable())
8405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
8415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(n);
8425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!n)
8435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
8445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    StepRange stepRange(createStepRange(AnyIsDefaultStep));
8465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // FIXME: Not any changes after stepping, even if it is an invalid value, may be better.
8485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // (e.g. Stepping-up for <input type="number" value="foo" step="any" /> => "foo")
8495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!stepRange.hasStep())
850e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return;
8515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
85293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    EventQueueScope scope;
8535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const Decimal step = stepRange.step();
8545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int sign;
8565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (step > 0)
8575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        sign = n;
8585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else if (step < 0)
8595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        sign = -n;
8605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
8615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        sign = 0;
8625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
86309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    Decimal current = parseToNumberOrNaN(element().value());
8645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!current.isFinite()) {
8655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        current = defaultValueForStepUp();
8665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        const Decimal nextDiff = step * n;
8675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (current < stepRange.minimum() - nextDiff)
8685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            current = stepRange.minimum() - nextDiff;
8695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (current > stepRange.maximum() - nextDiff)
8705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            current = stepRange.maximum() - nextDiff;
8711fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch        setValueAsDecimal(current, DispatchNoEvent, IGNORE_EXCEPTION);
8725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
873e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if ((sign > 0 && current < stepRange.minimum()) || (sign < 0 && current > stepRange.maximum())) {
874a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch        setValueAsDecimal(sign > 0 ? stepRange.minimum() : stepRange.maximum(), DispatchChangeEvent, IGNORE_EXCEPTION);
87509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
876926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
877a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    applyStep(current, n, AnyIsDefaultStep, DispatchChangeEvent, IGNORE_EXCEPTION);
878926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
879926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
880f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void InputType::countUsageIfVisible(UseCounter::Feature feature) const
881926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
882bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (RenderStyle* style = element().renderStyle()) {
883926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (style->visibility() != HIDDEN)
884bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)            UseCounter::count(element().document(), feature);
8855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
8865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
888a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)Decimal InputType::findStepBase(const Decimal& defaultValue) const
889a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){
890a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), Decimal::nan());
891a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (!stepBase.isFinite())
892a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        stepBase = parseToNumber(element().fastGetAttribute(valueAttr), defaultValue);
893a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    return stepBase;
894a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
895a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
89609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)StepRange InputType::createStepRange(AnyStepHandling anyStepHandling, const Decimal& stepBaseDefault, const Decimal& minimumDefault, const Decimal& maximumDefault, const StepRange::StepDescription& stepDescription) const
89709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
89809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    const Decimal stepBase = findStepBase(stepBaseDefault);
89909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), minimumDefault);
90009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), maximumDefault);
90109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr));
90209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return StepRange(stepBase, minimum, maximum, step, stepDescription);
90309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
90409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
905c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
906