2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
8 * Copyright (C) 2010 Google Inc. All rights reserved.
9 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
10 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
30 #include "HTMLInputElement.h"
32 #include "AXObjectCache.h"
33 #include "BeforeTextInsertedEvent.h"
34 #include "CSSPropertyNames.h"
35 #include "CSSValueKeywords.h"
37 #include "EventNames.h"
38 #include "ExceptionCode.h"
40 #include "FormController.h"
42 #include "HTMLCollection.h"
43 #include "HTMLDataListElement.h"
44 #include "HTMLFormElement.h"
45 #include "HTMLNames.h"
46 #include "HTMLOptionElement.h"
47 #include "HTMLParserIdioms.h"
48 #include "IdTargetObserver.h"
49 #include "InputType.h"
50 #include "KeyboardEvent.h"
51 #include "LocalizedStrings.h"
52 #include "MouseEvent.h"
53 #include "RenderTextControlSingleLine.h"
54 #include "RenderTheme.h"
55 #include "SearchInputType.h"
56 #include "ShadowRoot.h"
57 #include "ScriptEventListener.h"
58 #include "WheelEvent.h"
59 #include <wtf/MathExtras.h>
60 #include <wtf/StdLibExtras.h>
62 #if ENABLE(INPUT_TYPE_COLOR)
63 #include "ColorInputType.h"
66 #if ENABLE(INPUT_SPEECH)
67 #include "RuntimeEnabledFeatures.h"
70 #if ENABLE(TOUCH_EVENTS)
71 #include "TouchEvent.h"
74 #if ENABLE(TIZEN_FOCUS_UI) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)
76 #include "WindowsKeyboardCodes.h"
77 #include "htmlediting.h"
84 using namespace HTMLNames;
86 #if ENABLE(DATALIST_ELEMENT)
87 class ListAttributeTargetObserver : IdTargetObserver {
89 static PassOwnPtr<ListAttributeTargetObserver> create(const AtomicString& id, HTMLInputElement*);
90 virtual void idTargetChanged() OVERRIDE;
93 ListAttributeTargetObserver(const AtomicString& id, HTMLInputElement*);
95 HTMLInputElement* m_element;
99 // FIXME: According to HTML4, the length attribute's value can be arbitrarily
100 // large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things
101 // get rather sluggish when a text field has a larger number of characters than
102 // this, even when just clicking in the text field.
103 const int HTMLInputElement::maximumLength = 524288;
104 const int defaultSize = 20;
105 const int maxSavedResults = 256;
107 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form, bool createdByParser)
108 : HTMLTextFormControlElement(tagName, document, form)
109 , m_size(defaultSize)
110 , m_maxLength(maximumLength)
113 , m_reflectsCheckedAttribute(true)
114 , m_isIndeterminate(false)
116 , m_isActivatedSubmit(false)
117 , m_autocomplete(Uninitialized)
118 , m_isAutofilled(false)
119 , m_stateRestored(false)
120 , m_parsingInProgress(createdByParser)
121 , m_valueAttributeWasUpdatedAfterParsing(false)
122 , m_wasModifiedByUser(false)
123 , m_canReceiveDroppedFiles(false)
124 , m_hasTouchEventHandler(false)
125 , m_inputType(InputType::createText(this))
127 ASSERT(hasTagName(inputTag) || hasTagName(isindexTag));
130 PassRefPtr<HTMLInputElement> HTMLInputElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form, bool createdByParser)
132 RefPtr<HTMLInputElement> inputElement = adoptRef(new HTMLInputElement(tagName, document, form, createdByParser));
133 inputElement->createShadowSubtree();
134 return inputElement.release();
137 void HTMLInputElement::createShadowSubtree()
140 ShadowRoot::create(this, ShadowRoot::UserAgentShadowRoot, ASSERT_NO_EXCEPTION);
142 m_inputType->createShadowSubtree();
145 HTMLInputElement::~HTMLInputElement()
147 if (needsSuspensionCallback())
148 document()->unregisterForPageCacheSuspensionCallbacks(this);
150 // Need to remove form association while this is still an HTMLInputElement
151 // so that virtual functions are called correctly.
153 // setForm(0) may register this to a document-level radio button group.
154 // We should unregister it to avoid accessing a deleted object.
156 document()->formController()->checkedRadioButtons().removeButton(this);
157 #if ENABLE(TOUCH_EVENTS)
158 if (m_hasTouchEventHandler)
159 document()->didRemoveTouchEventHandler();
163 const AtomicString& HTMLInputElement::name() const
165 return m_name.isNull() ? emptyAtom : m_name;
168 HTMLElement* HTMLInputElement::containerElement() const
170 return m_inputType->containerElement();
173 HTMLElement* HTMLInputElement::innerTextElement() const
175 return m_inputType->innerTextElement();
178 HTMLElement* HTMLInputElement::innerBlockElement() const
180 return m_inputType->innerBlockElement();
183 HTMLElement* HTMLInputElement::innerSpinButtonElement() const
185 return m_inputType->innerSpinButtonElement();
188 HTMLElement* HTMLInputElement::resultsButtonElement() const
190 return m_inputType->resultsButtonElement();
193 HTMLElement* HTMLInputElement::cancelButtonElement() const
195 return m_inputType->cancelButtonElement();
198 #if ENABLE(INPUT_SPEECH)
199 HTMLElement* HTMLInputElement::speechButtonElement() const
201 return m_inputType->speechButtonElement();
205 HTMLElement* HTMLInputElement::sliderThumbElement() const
207 return m_inputType->sliderThumbElement();
210 HTMLElement* HTMLInputElement::placeholderElement() const
212 return m_inputType->placeholderElement();
215 bool HTMLInputElement::shouldAutocomplete() const
217 if (m_autocomplete != Uninitialized)
218 return m_autocomplete == On;
219 return HTMLTextFormControlElement::shouldAutocomplete();
222 bool HTMLInputElement::isValidValue(const String& value) const
224 if (!m_inputType->canSetStringValue()) {
225 ASSERT_NOT_REACHED();
228 return !m_inputType->typeMismatchFor(value)
229 && !m_inputType->stepMismatch(value)
230 && !m_inputType->rangeUnderflow(value)
231 && !m_inputType->rangeOverflow(value)
232 && !tooLong(value, IgnoreDirtyFlag)
233 && !m_inputType->patternMismatch(value)
234 && !m_inputType->valueMissing(value);
237 bool HTMLInputElement::tooLong() const
239 return willValidate() && tooLong(value(), CheckDirtyFlag);
242 bool HTMLInputElement::typeMismatch() const
244 return willValidate() && m_inputType->typeMismatch();
247 bool HTMLInputElement::valueMissing() const
249 return willValidate() && m_inputType->valueMissing(value());
252 bool HTMLInputElement::hasBadInput() const
254 return m_inputType->hasBadInput();
257 bool HTMLInputElement::patternMismatch() const
259 return willValidate() && m_inputType->patternMismatch(value());
262 bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
264 // We use isTextType() instead of supportsMaxLength() because of the
265 // 'virtual' overhead.
268 int max = maxLength();
271 if (check == CheckDirtyFlag) {
272 // Return false for the default value or a value set by a script even if
273 // it is longer than maxLength.
274 if (!hasDirtyValue() || !m_wasModifiedByUser)
277 return numGraphemeClusters(value) > static_cast<unsigned>(max);
280 bool HTMLInputElement::rangeUnderflow() const
282 return willValidate() && m_inputType->rangeUnderflow(value());
285 bool HTMLInputElement::rangeOverflow() const
287 return willValidate() && m_inputType->rangeOverflow(value());
290 String HTMLInputElement::validationMessage() const
296 return customValidationMessage();
298 return m_inputType->validationMessage();
301 double HTMLInputElement::minimum() const
303 return m_inputType->minimum();
306 double HTMLInputElement::maximum() const
308 return m_inputType->maximum();
311 bool HTMLInputElement::stepMismatch() const
313 return willValidate() && m_inputType->stepMismatch(value());
316 bool HTMLInputElement::getAllowedValueStep(Decimal* step) const
318 return m_inputType->getAllowedValueStep(step);
321 StepRange HTMLInputElement::createStepRange(AnyStepHandling anyStepHandling) const
323 return m_inputType->createStepRange(anyStepHandling);
326 void HTMLInputElement::stepUp(int n, ExceptionCode& ec)
328 m_inputType->stepUp(n, ec);
331 void HTMLInputElement::stepDown(int n, ExceptionCode& ec)
333 m_inputType->stepUp(-n, ec);
336 bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const
338 return m_inputType->isKeyboardFocusable(event);
341 bool HTMLInputElement::isMouseFocusable() const
343 return m_inputType->isMouseFocusable();
346 bool HTMLInputElement::isTextFormControlFocusable() const
348 return HTMLTextFormControlElement::isFocusable();
351 bool HTMLInputElement::isTextFormControlKeyboardFocusable(KeyboardEvent* event) const
353 return HTMLTextFormControlElement::isKeyboardFocusable(event);
356 bool HTMLInputElement::isTextFormControlMouseFocusable() const
358 return HTMLTextFormControlElement::isMouseFocusable();
361 void HTMLInputElement::updateFocusAppearance(bool restorePreviousSelection)
363 #if ENABLE(TIZEN_FOCUS_UI) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)
364 if (shouldUsePicker() && document()->settings() && document()->settings()->isSpatialNavigationEnabled())
369 if (!restorePreviousSelection || !hasCachedSelection())
372 restoreCachedSelection();
373 if (document()->frame())
374 document()->frame()->selection()->revealSelection();
376 HTMLTextFormControlElement::updateFocusAppearance(restorePreviousSelection);
379 void HTMLInputElement::aboutToUnload()
381 if (!isTextField() || !focused())
384 Frame* frame = document()->frame();
388 frame->editor()->textFieldDidEndEditing(this);
391 bool HTMLInputElement::shouldUseInputMethod()
393 return m_inputType->shouldUseInputMethod();
396 void HTMLInputElement::handleFocusEvent()
398 m_inputType->handleFocusEvent();
401 void HTMLInputElement::handleBlurEvent()
403 m_inputType->handleBlurEvent();
406 void HTMLInputElement::setType(const String& type)
408 // FIXME: This should just call setAttribute. No reason to handle the empty string specially.
409 // We should write a test case to show that setting to the empty string does not remove the
410 // attribute in other browsers and then fix this. Note that setting to null *does* remove
411 // the attribute and setAttribute implements that.
413 removeAttribute(typeAttr);
415 setAttribute(typeAttr, type);
418 void HTMLInputElement::updateType()
420 OwnPtr<InputType> newType = InputType::create(this, fastGetAttribute(typeAttr));
421 bool hadType = m_hasType;
423 if (m_inputType->formControlType() == newType->formControlType())
426 if (hadType && !newType->canChangeFromAnotherType()) {
427 // Set the attribute back to the old value.
428 // Useful in case we were called from inside parseAttribute.
429 setAttribute(typeAttr, type());
433 removeFromRadioButtonGroup();
435 bool wasAttached = attached();
439 bool didStoreValue = m_inputType->storesValueSeparateFromAttribute();
440 bool neededSuspensionCallback = needsSuspensionCallback();
441 bool didRespectHeightAndWidth = m_inputType->shouldRespectHeightAndWidthAttributes();
443 m_inputType->destroyShadowSubtree();
444 m_inputType = newType.release();
445 m_inputType->createShadowSubtree();
447 #if ENABLE(TOUCH_EVENTS)
448 bool hasTouchEventHandler = m_inputType->hasTouchEventHandler();
449 if (hasTouchEventHandler != m_hasTouchEventHandler) {
450 if (hasTouchEventHandler) {
451 document()->didAddTouchEventHandler();
452 document()->addListenerType(Document::TOUCH_LISTENER);
454 document()->didRemoveTouchEventHandler();
455 m_hasTouchEventHandler = hasTouchEventHandler;
459 setNeedsWillValidateCheck();
461 bool willStoreValue = m_inputType->storesValueSeparateFromAttribute();
463 if (didStoreValue && !willStoreValue && hasDirtyValue()) {
464 setAttribute(valueAttr, m_valueIfDirty);
465 m_valueIfDirty = String();
467 if (!didStoreValue && willStoreValue) {
468 AtomicString valueString = fastGetAttribute(valueAttr);
469 m_valueIfDirty = sanitizeValue(valueString);
471 updateValueIfNeeded();
473 setFormControlValueMatchesRenderer(false);
474 m_inputType->updateInnerTextValue();
476 m_wasModifiedByUser = false;
478 if (neededSuspensionCallback)
479 unregisterForSuspensionCallbackIfNeeded();
481 registerForSuspensionCallbackIfNeeded();
483 if (didRespectHeightAndWidth != m_inputType->shouldRespectHeightAndWidthAttributes()) {
484 ASSERT(attributeData());
485 if (Attribute* height = getAttributeItem(heightAttr))
486 attributeChanged(*height);
487 if (Attribute* width = getAttributeItem(widthAttr))
488 attributeChanged(*width);
489 if (Attribute* align = getAttributeItem(alignAttr))
490 attributeChanged(*align);
495 if (document()->focusedNode() == this)
496 updateFocusAppearance(true);
499 setChangedSinceLastFormControlChangeEvent(false);
501 addToRadioButtonGroup();
503 setNeedsValidityCheck();
504 notifyFormStateChanged();
507 void HTMLInputElement::subtreeHasChanged()
509 m_inputType->subtreeHasChanged();
510 // When typing in an input field, childrenChanged is not called, so we need to force the directionality check.
511 calculateAndAdjustDirectionality();
514 const AtomicString& HTMLInputElement::formControlType() const
516 return m_inputType->formControlType();
519 bool HTMLInputElement::shouldSaveAndRestoreFormControlState() const
521 if (!m_inputType->shouldSaveAndRestoreFormControlState())
523 return HTMLTextFormControlElement::shouldSaveAndRestoreFormControlState();
526 FormControlState HTMLInputElement::saveFormControlState() const
528 return m_inputType->saveFormControlState();
531 void HTMLInputElement::restoreFormControlState(const FormControlState& state)
533 m_inputType->restoreFormControlState(state);
534 m_stateRestored = true;
537 bool HTMLInputElement::canStartSelection() const
541 return HTMLTextFormControlElement::canStartSelection();
544 bool HTMLInputElement::canHaveSelection() const
546 return isTextField();
549 void HTMLInputElement::accessKeyAction(bool sendMouseEvents)
551 m_inputType->accessKeyAction(sendMouseEvents);
554 bool HTMLInputElement::isPresentationAttribute(const QualifiedName& name) const
556 if (name == vspaceAttr || name == hspaceAttr || name == alignAttr || name == widthAttr || name == heightAttr || (name == borderAttr && isImageButton()))
558 return HTMLTextFormControlElement::isPresentationAttribute(name);
561 void HTMLInputElement::collectStyleForAttribute(const Attribute& attribute, StylePropertySet* style)
563 if (attribute.name() == vspaceAttr) {
564 addHTMLLengthToStyle(style, CSSPropertyMarginTop, attribute.value());
565 addHTMLLengthToStyle(style, CSSPropertyMarginBottom, attribute.value());
566 } else if (attribute.name() == hspaceAttr) {
567 addHTMLLengthToStyle(style, CSSPropertyMarginLeft, attribute.value());
568 addHTMLLengthToStyle(style, CSSPropertyMarginRight, attribute.value());
569 } else if (attribute.name() == alignAttr) {
570 if (m_inputType->shouldRespectAlignAttribute())
571 applyAlignmentAttributeToStyle(attribute, style);
572 } else if (attribute.name() == widthAttr) {
573 if (m_inputType->shouldRespectHeightAndWidthAttributes())
574 addHTMLLengthToStyle(style, CSSPropertyWidth, attribute.value());
575 } else if (attribute.name() == heightAttr) {
576 if (m_inputType->shouldRespectHeightAndWidthAttributes())
577 addHTMLLengthToStyle(style, CSSPropertyHeight, attribute.value());
578 } else if (attribute.name() == borderAttr && isImageButton())
579 applyBorderAttributeToStyle(attribute, style);
581 HTMLTextFormControlElement::collectStyleForAttribute(attribute, style);
584 void HTMLInputElement::parseAttribute(const Attribute& attribute)
586 if (attribute.name() == nameAttr) {
587 removeFromRadioButtonGroup();
588 m_name = attribute.value();
589 addToRadioButtonGroup();
590 HTMLTextFormControlElement::parseAttribute(attribute);
591 } else if (attribute.name() == autocompleteAttr) {
592 if (equalIgnoringCase(attribute.value(), "off")) {
593 m_autocomplete = Off;
594 registerForSuspensionCallbackIfNeeded();
596 bool needsToUnregister = m_autocomplete == Off;
598 if (attribute.isEmpty())
599 m_autocomplete = Uninitialized;
603 if (needsToUnregister)
604 unregisterForSuspensionCallbackIfNeeded();
606 } else if (attribute.name() == typeAttr) {
608 } else if (attribute.name() == valueAttr) {
609 // We only need to setChanged if the form is looking at the default value right now.
610 if (!hasDirtyValue()) {
611 updatePlaceholderVisibility(false);
612 setNeedsStyleRecalc();
614 setFormControlValueMatchesRenderer(false);
615 setNeedsValidityCheck();
616 m_valueAttributeWasUpdatedAfterParsing = !m_parsingInProgress;
617 } else if (attribute.name() == checkedAttr) {
618 // Another radio button in the same group might be checked by state
619 // restore. We shouldn't call setChecked() even if this has the checked
620 // attribute. So, delay the setChecked() call until
621 // finishParsingChildren() is called if parsing is in progress.
622 if (!m_parsingInProgress && m_reflectsCheckedAttribute) {
623 setChecked(!attribute.isNull());
624 m_reflectsCheckedAttribute = true;
626 } else if (attribute.name() == maxlengthAttr)
627 parseMaxLengthAttribute(attribute);
628 else if (attribute.name() == sizeAttr) {
629 int oldSize = m_size;
630 int value = attribute.value().toInt();
631 m_size = value > 0 ? value : defaultSize;
632 if (m_size != oldSize && renderer())
633 renderer()->setNeedsLayoutAndPrefWidthsRecalc();
634 } else if (attribute.name() == altAttr)
635 m_inputType->altAttributeChanged();
636 else if (attribute.name() == srcAttr)
637 m_inputType->srcAttributeChanged();
638 else if (attribute.name() == usemapAttr || attribute.name() == accesskeyAttr) {
639 // FIXME: ignore for the moment
640 } else if (attribute.name() == onsearchAttr) {
641 // Search field and slider attributes all just cause updateFromElement to be called through style recalcing.
642 setAttributeEventListener(eventNames().searchEvent, createAttributeEventListener(this, attribute));
643 } else if (attribute.name() == resultsAttr) {
644 int oldResults = m_maxResults;
645 m_maxResults = !attribute.isNull() ? std::min(attribute.value().toInt(), maxSavedResults) : -1;
646 // FIXME: Detaching just for maxResults change is not ideal. We should figure out the right
647 // time to relayout for this change.
648 if (m_maxResults != oldResults && (m_maxResults <= 0 || oldResults <= 0))
649 reattachIfAttached();
650 setNeedsStyleRecalc();
651 } else if (attribute.name() == autosaveAttr || attribute.name() == incrementalAttr)
652 setNeedsStyleRecalc();
653 else if (attribute.name() == minAttr || attribute.name() == maxAttr) {
654 m_inputType->minOrMaxAttributeChanged();
655 setNeedsValidityCheck();
656 } else if (attribute.name() == multipleAttr) {
657 m_inputType->multipleAttributeChanged();
658 setNeedsValidityCheck();
659 } else if (attribute.name() == stepAttr) {
660 m_inputType->stepAttributeChanged();
661 setNeedsValidityCheck();
662 } else if (attribute.name() == patternAttr || attribute.name() == precisionAttr)
663 setNeedsValidityCheck();
664 else if (attribute.name() == disabledAttr) {
665 HTMLTextFormControlElement::parseAttribute(attribute);
666 m_inputType->disabledAttributeChanged();
667 } else if (attribute.name() == readonlyAttr) {
668 HTMLTextFormControlElement::parseAttribute(attribute);
669 m_inputType->readonlyAttributeChanged();
671 #if ENABLE(DATALIST_ELEMENT)
672 else if (attribute.name() == listAttr) {
673 m_hasNonEmptyList = !attribute.isEmpty();
674 if (m_hasNonEmptyList) {
675 resetListAttributeTargetObserver();
676 listAttributeTargetChanged();
680 #if ENABLE(INPUT_SPEECH)
681 else if (attribute.name() == webkitspeechAttr) {
683 // This renderer and its children have quite different layouts and styles depending on
684 // whether the speech button is visible or not. So we reset the whole thing and recreate
685 // to get the right styles and layout.
687 m_inputType->destroyShadowSubtree();
688 m_inputType->createShadowSubtree();
691 m_inputType->destroyShadowSubtree();
692 m_inputType->createShadowSubtree();
694 setFormControlValueMatchesRenderer(false);
695 setNeedsStyleRecalc();
696 } else if (attribute.name() == onwebkitspeechchangeAttr)
697 setAttributeEventListener(eventNames().webkitspeechchangeEvent, createAttributeEventListener(this, attribute));
700 HTMLTextFormControlElement::parseAttribute(attribute);
701 m_inputType->updateInnerTextValue();
704 void HTMLInputElement::finishParsingChildren()
706 m_parsingInProgress = false;
707 HTMLTextFormControlElement::finishParsingChildren();
708 if (!m_stateRestored) {
709 bool checked = hasAttribute(checkedAttr);
712 m_reflectsCheckedAttribute = true;
716 bool HTMLInputElement::rendererIsNeeded(const NodeRenderingContext& context)
718 return m_inputType->rendererIsNeeded() && HTMLTextFormControlElement::rendererIsNeeded(context);
721 RenderObject* HTMLInputElement::createRenderer(RenderArena* arena, RenderStyle* style)
723 return m_inputType->createRenderer(arena, style);
726 void HTMLInputElement::attach()
728 suspendPostAttachCallbacks();
733 HTMLTextFormControlElement::attach();
735 m_inputType->attach();
737 if (document()->focusedNode() == this)
738 document()->updateFocusAppearanceSoon(true /* restore selection */);
740 resumePostAttachCallbacks();
743 void HTMLInputElement::detach()
745 HTMLTextFormControlElement::detach();
746 setFormControlValueMatchesRenderer(false);
747 m_inputType->detach();
750 String HTMLInputElement::altText() const
752 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen
753 // also heavily discussed by Hixie on bugzilla
754 // note this is intentionally different to HTMLImageElement::altText()
755 String alt = fastGetAttribute(altAttr);
756 // fall back to title attribute
758 alt = getAttribute(titleAttr);
760 alt = getAttribute(valueAttr);
762 alt = inputElementAltText();
766 bool HTMLInputElement::isSuccessfulSubmitButton() const
768 // HTML spec says that buttons must have names to be considered successful.
769 // However, other browsers do not impose this constraint. So we do not.
770 return !disabled() && m_inputType->canBeSuccessfulSubmitButton();
773 bool HTMLInputElement::isActivatedSubmit() const
775 return m_isActivatedSubmit;
778 void HTMLInputElement::setActivatedSubmit(bool flag)
780 m_isActivatedSubmit = flag;
783 bool HTMLInputElement::appendFormData(FormDataList& encoding, bool multipart)
785 return m_inputType->isFormDataAppendable() && m_inputType->appendFormData(encoding, multipart);
788 void HTMLInputElement::reset()
790 if (m_inputType->storesValueSeparateFromAttribute())
793 setAutofilled(false);
794 setChecked(hasAttribute(checkedAttr));
795 m_reflectsCheckedAttribute = true;
798 bool HTMLInputElement::isTextField() const
800 return m_inputType->isTextField();
803 bool HTMLInputElement::isTextType() const
805 return m_inputType->isTextType();
808 void HTMLInputElement::setChecked(bool nowChecked, TextFieldEventBehavior eventBehavior)
810 if (checked() == nowChecked)
813 m_reflectsCheckedAttribute = false;
814 m_isChecked = nowChecked;
815 setNeedsStyleRecalc();
817 if (CheckedRadioButtons* buttons = checkedRadioButtons())
818 buttons->updateCheckedState(this);
819 if (renderer() && renderer()->style()->hasAppearance())
820 renderer()->theme()->stateChanged(renderer(), CheckedState);
821 setNeedsValidityCheck();
823 // Ideally we'd do this from the render tree (matching
824 // RenderTextView), but it's not possible to do it at the moment
825 // because of the way the code is structured.
826 if (renderer() && AXObjectCache::accessibilityEnabled())
827 renderer()->document()->axObjectCache()->checkedStateChanged(renderer());
829 // Only send a change event for items in the document (avoid firing during
830 // parsing) and don't send a change event for a radio button that's getting
831 // unchecked to match other browsers. DOM is not a useful standard for this
832 // because it says only to fire change events at "lose focus" time, which is
833 // definitely wrong in practice for these types of elements.
834 if (eventBehavior != DispatchNoEvent && inDocument() && m_inputType->shouldSendChangeEventAfterCheckedChanged()) {
835 setTextAsOfLastFormControlChangeEvent(String());
836 dispatchFormControlChangeEvent();
840 void HTMLInputElement::setIndeterminate(bool newValue)
842 if (indeterminate() == newValue)
845 m_isIndeterminate = newValue;
847 setNeedsStyleRecalc();
849 if (renderer() && renderer()->style()->hasAppearance())
850 renderer()->theme()->stateChanged(renderer(), CheckedState);
853 int HTMLInputElement::size() const
858 bool HTMLInputElement::sizeShouldIncludeDecoration(int& preferredSize) const
860 return m_inputType->sizeShouldIncludeDecoration(defaultSize, preferredSize);
863 void HTMLInputElement::copyNonAttributePropertiesFromElement(const Element& source)
865 const HTMLInputElement& sourceElement = static_cast<const HTMLInputElement&>(source);
867 m_valueIfDirty = sourceElement.m_valueIfDirty;
868 m_wasModifiedByUser = false;
869 setChecked(sourceElement.m_isChecked);
870 m_reflectsCheckedAttribute = sourceElement.m_reflectsCheckedAttribute;
871 m_isIndeterminate = sourceElement.m_isIndeterminate;
873 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source);
875 setFormControlValueMatchesRenderer(false);
876 m_inputType->updateInnerTextValue();
879 String HTMLInputElement::value() const
882 if (m_inputType->getTypeSpecificValue(value))
885 value = m_valueIfDirty;
889 AtomicString valueString = fastGetAttribute(valueAttr);
890 value = sanitizeValue(valueString);
894 return m_inputType->fallbackValue();
897 String HTMLInputElement::valueWithDefault() const
899 String value = this->value();
903 return m_inputType->defaultValue();
906 void HTMLInputElement::setValueForUser(const String& value)
908 // Call setValue and make it send a change event.
909 setValue(value, DispatchChangeEvent);
912 const String& HTMLInputElement::suggestedValue() const
914 return m_suggestedValue;
917 void HTMLInputElement::setSuggestedValue(const String& value)
919 if (!m_inputType->canSetSuggestedValue())
921 setFormControlValueMatchesRenderer(false);
922 m_suggestedValue = sanitizeValue(value);
923 setNeedsStyleRecalc();
924 m_inputType->updateInnerTextValue();
927 void HTMLInputElement::setEditingValue(const String& value)
929 if (!renderer() || !isTextField())
931 setInnerTextValue(value);
934 unsigned max = value.length();
936 setSelectionRange(max, max);
938 cacheSelectionInResponseToSetValue(max);
940 dispatchInputEvent();
943 void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior eventBehavior)
945 if (!m_inputType->canSetValue(value))
948 RefPtr<HTMLInputElement> protector(this);
949 String sanitizedValue = sanitizeValue(value);
950 bool valueChanged = sanitizedValue != this->value();
952 setLastChangeWasNotUserEdit();
953 setFormControlValueMatchesRenderer(false);
954 m_suggestedValue = String(); // Prevent TextFieldInputType::setValue from using the suggested value.
955 m_inputType->setValue(sanitizedValue, valueChanged, eventBehavior);
960 notifyFormStateChanged();
961 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
963 renderer()->updateFromElement();
967 void HTMLInputElement::setValueInternal(const String& sanitizedValue, TextFieldEventBehavior eventBehavior)
969 m_valueIfDirty = sanitizedValue;
970 m_wasModifiedByUser = eventBehavior != DispatchNoEvent;
971 setNeedsValidityCheck();
974 double HTMLInputElement::valueAsDate() const
976 return m_inputType->valueAsDate();
979 void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
981 m_inputType->setValueAsDate(value, ec);
984 double HTMLInputElement::valueAsNumber() const
986 return m_inputType->valueAsDouble();
989 void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec, TextFieldEventBehavior eventBehavior)
991 if (!isfinite(newValue)) {
992 ec = NOT_SUPPORTED_ERR;
995 m_inputType->setValueAsDouble(newValue, eventBehavior, ec);
998 String HTMLInputElement::placeholder() const
1000 return fastGetAttribute(placeholderAttr).string();
1003 void HTMLInputElement::setPlaceholder(const String& value)
1005 setAttribute(placeholderAttr, value);
1008 void HTMLInputElement::setValueFromRenderer(const String& value)
1010 // File upload controls will never use this.
1011 ASSERT(!isFileUpload());
1013 m_suggestedValue = String();
1015 // Renderer and our event handler are responsible for sanitizing values.
1016 ASSERT(value == sanitizeValue(value) || sanitizeValue(value).isEmpty());
1018 // Workaround for bug where trailing \n is included in the result of textContent.
1019 // The assert macro above may also be simplified to: value == constrainValue(value)
1020 // http://bugs.webkit.org/show_bug.cgi?id=9661
1021 m_valueIfDirty = value == "\n" ? emptyString() : value;
1023 setFormControlValueMatchesRenderer(true);
1024 m_wasModifiedByUser = true;
1026 // Input event is fired by the Node::defaultEventHandler for editable controls.
1028 dispatchInputEvent();
1029 notifyFormStateChanged();
1031 setNeedsValidityCheck();
1033 // Clear autofill flag (and yellow background) on user edit.
1034 setAutofilled(false);
1037 void* HTMLInputElement::preDispatchEventHandler(Event* event)
1039 if (event->type() == eventNames().textInputEvent && m_inputType->shouldSubmitImplicitly(event)) {
1040 event->stopPropagation();
1043 if (event->type() != eventNames().clickEvent)
1045 if (!event->isMouseEvent() || static_cast<MouseEvent*>(event)->button() != LeftButton)
1047 // FIXME: Check whether there are any cases where this actually ends up leaking.
1048 return m_inputType->willDispatchClick().leakPtr();
1051 void HTMLInputElement::postDispatchEventHandler(Event* event, void* dataFromPreDispatch)
1053 OwnPtr<ClickHandlingState> state = adoptPtr(static_cast<ClickHandlingState*>(dataFromPreDispatch));
1056 m_inputType->didDispatchClick(event, *state);
1059 void HTMLInputElement::defaultEventHandler(Event* evt)
1061 if (evt->isMouseEvent() && evt->type() == eventNames().clickEvent && static_cast<MouseEvent*>(evt)->button() == LeftButton) {
1062 m_inputType->handleClickEvent(static_cast<MouseEvent*>(evt));
1063 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1064 if(shouldUsePicker())
1065 document()->setCurrentTargetNode(document()->focusedNode());
1067 if (evt->defaultHandled())
1071 #if ENABLE(TOUCH_EVENTS)
1072 if (evt->isTouchEvent()) {
1073 m_inputType->handleTouchEvent(static_cast<TouchEvent*>(evt));
1074 if (evt->defaultHandled())
1079 if (evt->isKeyboardEvent() && evt->type() == eventNames().keydownEvent) {
1080 m_inputType->handleKeydownEvent(static_cast<KeyboardEvent*>(evt));
1081 if (evt->defaultHandled())
1084 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1085 if (static_cast<KeyboardEvent*>(evt)->keyCode() == VK_RETURN && shouldUsePicker()) {
1086 document()->setCurrentTargetNode(document()->focusedNode());
1087 #if ENABLE(TIZEN_FOCUS_UI)
1088 if (document()->settings() && document()->settings()->isSpatialNavigationEnabled()) {
1089 setSelectionRange(0, 0);
1090 evt->setDefaultHandled();
1098 // Call the base event handler before any of our own event handling for almost all events in text fields.
1099 // Makes editing keyboard handling take precedence over the keydown and keypress handling in this function.
1100 bool callBaseClassEarly = isTextField() && (evt->type() == eventNames().keydownEvent || evt->type() == eventNames().keypressEvent);
1101 if (callBaseClassEarly) {
1102 HTMLTextFormControlElement::defaultEventHandler(evt);
1103 if (evt->defaultHandled())
1107 // DOMActivate events cause the input to be "activated" - in the case of image and submit inputs, this means
1108 // actually submitting the form. For reset inputs, the form is reset. These events are sent when the user clicks
1109 // on the element, or presses enter while it is the active element. JavaScript code wishing to activate the element
1110 // must dispatch a DOMActivate event - a click event will not do the job.
1111 if (evt->type() == eventNames().DOMActivateEvent) {
1112 m_inputType->handleDOMActivateEvent(evt);
1113 if (evt->defaultHandled())
1117 // Use key press event here since sending simulated mouse events
1118 // on key down blocks the proper sending of the key press event.
1119 if (evt->isKeyboardEvent() && evt->type() == eventNames().keypressEvent) {
1120 m_inputType->handleKeypressEvent(static_cast<KeyboardEvent*>(evt));
1121 if (evt->defaultHandled())
1125 if (evt->isKeyboardEvent() && evt->type() == eventNames().keyupEvent) {
1126 m_inputType->handleKeyupEvent(static_cast<KeyboardEvent*>(evt));
1127 if (evt->defaultHandled())
1131 if (m_inputType->shouldSubmitImplicitly(evt)) {
1132 if (isSearchField()) {
1136 // Form submission finishes editing, just as loss of focus does.
1137 // If there was a change, send the event now.
1138 if (wasChangedSinceLastFormControlChangeEvent())
1139 dispatchFormControlChangeEvent();
1141 RefPtr<HTMLFormElement> formForSubmission = m_inputType->formForSubmission();
1142 // Form may never have been present, or may have been destroyed by code responding to the change event.
1143 if (formForSubmission)
1144 formForSubmission->submitImplicitly(evt, canTriggerImplicitSubmission());
1146 evt->setDefaultHandled();
1150 if (evt->isBeforeTextInsertedEvent())
1151 m_inputType->handleBeforeTextInsertedEvent(static_cast<BeforeTextInsertedEvent*>(evt));
1153 if (evt->hasInterface(eventNames().interfaceForWheelEvent)) {
1154 m_inputType->handleWheelEvent(static_cast<WheelEvent*>(evt));
1155 if (evt->defaultHandled())
1159 if (evt->isMouseEvent() && evt->type() == eventNames().mousedownEvent) {
1160 m_inputType->handleMouseDownEvent(static_cast<MouseEvent*>(evt));
1161 if (evt->defaultHandled())
1165 m_inputType->forwardEvent(evt);
1167 if (!callBaseClassEarly && !evt->defaultHandled())
1168 HTMLTextFormControlElement::defaultEventHandler(evt);
1171 bool HTMLInputElement::willRespondToMouseClickEvents()
1173 // FIXME: Consider implementing willRespondToMouseClickEvents() in InputType if more accurate results are necessary.
1177 return HTMLTextFormControlElement::willRespondToMouseClickEvents();
1180 bool HTMLInputElement::isURLAttribute(const Attribute& attribute) const
1182 return attribute.name() == srcAttr || attribute.name() == formactionAttr || HTMLTextFormControlElement::isURLAttribute(attribute);
1185 String HTMLInputElement::defaultValue() const
1187 return fastGetAttribute(valueAttr);
1190 void HTMLInputElement::setDefaultValue(const String &value)
1192 setAttribute(valueAttr, value);
1195 static inline bool isRFC2616TokenCharacter(UChar ch)
1197 return isASCII(ch) && ch > ' ' && ch != '"' && ch != '(' && ch != ')' && ch != ',' && ch != '/' && (ch < ':' || ch > '@') && (ch < '[' || ch > ']') && ch != '{' && ch != '}' && ch != 0x7f;
1200 static bool isValidMIMEType(const String& type)
1202 size_t slashPosition = type.find('/');
1203 if (slashPosition == notFound || !slashPosition || slashPosition == type.length() - 1)
1205 for (size_t i = 0; i < type.length(); ++i) {
1206 if (!isRFC2616TokenCharacter(type[i]) && i != slashPosition)
1212 static bool isValidFileExtension(const String& type)
1214 if (type.length() < 2)
1216 return type[0] == '.';
1219 static Vector<String> parseAcceptAttribute(const String& acceptString, bool (*predicate)(const String&))
1221 Vector<String> types;
1222 if (acceptString.isEmpty())
1225 Vector<String> splitTypes;
1226 acceptString.split(',', false, splitTypes);
1227 for (size_t i = 0; i < splitTypes.size(); ++i) {
1228 String trimmedType = stripLeadingAndTrailingHTMLSpaces(splitTypes[i]);
1229 if (trimmedType.isEmpty())
1231 if (!predicate(trimmedType))
1233 types.append(trimmedType.lower());
1239 Vector<String> HTMLInputElement::acceptMIMETypes()
1241 return parseAcceptAttribute(fastGetAttribute(acceptAttr), isValidMIMEType);
1244 Vector<String> HTMLInputElement::acceptFileExtensions()
1246 return parseAcceptAttribute(fastGetAttribute(acceptAttr), isValidFileExtension);
1249 String HTMLInputElement::accept() const
1251 return fastGetAttribute(acceptAttr);
1254 String HTMLInputElement::alt() const
1256 return fastGetAttribute(altAttr);
1259 int HTMLInputElement::maxLength() const
1264 void HTMLInputElement::setMaxLength(int maxLength, ExceptionCode& ec)
1267 ec = INDEX_SIZE_ERR;
1269 setAttribute(maxlengthAttr, String::number(maxLength));
1272 bool HTMLInputElement::multiple() const
1274 return fastHasAttribute(multipleAttr);
1277 void HTMLInputElement::setSize(unsigned size)
1279 setAttribute(sizeAttr, String::number(size));
1282 KURL HTMLInputElement::src() const
1284 return document()->completeURL(fastGetAttribute(srcAttr));
1287 void HTMLInputElement::setAutofilled(bool autofilled)
1289 if (autofilled == m_isAutofilled)
1292 m_isAutofilled = autofilled;
1293 setNeedsStyleRecalc();
1296 FileList* HTMLInputElement::files()
1298 return m_inputType->files();
1301 void HTMLInputElement::setFiles(PassRefPtr<FileList> files)
1303 m_inputType->setFiles(files);
1306 bool HTMLInputElement::receiveDroppedFiles(const DragData* dragData)
1308 return m_inputType->receiveDroppedFiles(dragData);
1311 #if ENABLE(FILE_SYSTEM)
1312 String HTMLInputElement::droppedFileSystemId()
1314 return m_inputType->droppedFileSystemId();
1318 Icon* HTMLInputElement::icon() const
1320 return m_inputType->icon();
1323 bool HTMLInputElement::canReceiveDroppedFiles() const
1325 return m_canReceiveDroppedFiles;
1328 void HTMLInputElement::setCanReceiveDroppedFiles(bool canReceiveDroppedFiles)
1330 if (m_canReceiveDroppedFiles == canReceiveDroppedFiles)
1332 m_canReceiveDroppedFiles = canReceiveDroppedFiles;
1334 renderer()->updateFromElement();
1337 String HTMLInputElement::visibleValue() const
1339 return m_inputType->visibleValue();
1342 String HTMLInputElement::sanitizeValue(const String& proposedValue) const
1344 if (proposedValue.isNull())
1345 return proposedValue;
1346 return m_inputType->sanitizeValue(proposedValue);
1349 String HTMLInputElement::localizeValue(const String& proposedValue) const
1351 if (proposedValue.isNull())
1352 return proposedValue;
1353 return m_inputType->localizeValue(proposedValue);
1356 bool HTMLInputElement::isInRange() const
1358 return m_inputType->isInRange(value());
1361 bool HTMLInputElement::isOutOfRange() const
1363 return m_inputType->isOutOfRange(value());
1366 bool HTMLInputElement::needsSuspensionCallback()
1368 return m_autocomplete == Off || m_inputType->shouldResetOnDocumentActivation();
1371 void HTMLInputElement::registerForSuspensionCallbackIfNeeded()
1373 if (needsSuspensionCallback())
1374 document()->registerForPageCacheSuspensionCallbacks(this);
1377 void HTMLInputElement::unregisterForSuspensionCallbackIfNeeded()
1379 if (!needsSuspensionCallback())
1380 document()->unregisterForPageCacheSuspensionCallbacks(this);
1383 bool HTMLInputElement::isRequiredFormControl() const
1385 return m_inputType->supportsRequired() && required();
1388 void HTMLInputElement::addSearchResult()
1390 m_inputType->addSearchResult();
1393 void HTMLInputElement::onSearch()
1395 ASSERT(isSearchField());
1397 static_cast<SearchInputType*>(m_inputType.get())->stopSearchEventTimer();
1398 dispatchEvent(Event::create(eventNames().searchEvent, true, false));
1401 void HTMLInputElement::documentDidResumeFromPageCache()
1403 ASSERT(needsSuspensionCallback());
1407 void HTMLInputElement::willChangeForm()
1409 removeFromRadioButtonGroup();
1410 HTMLTextFormControlElement::willChangeForm();
1413 void HTMLInputElement::didChangeForm()
1415 HTMLTextFormControlElement::didChangeForm();
1416 addToRadioButtonGroup();
1419 Node::InsertionNotificationRequest HTMLInputElement::insertedInto(ContainerNode* insertionPoint)
1421 HTMLTextFormControlElement::insertedInto(insertionPoint);
1422 if (insertionPoint->inDocument() && !form())
1423 addToRadioButtonGroup();
1424 #if ENABLE(DATALIST_ELEMENT)
1425 resetListAttributeTargetObserver();
1427 return InsertionDone;
1430 void HTMLInputElement::removedFrom(ContainerNode* insertionPoint)
1432 if (insertionPoint->inDocument() && !form())
1433 removeFromRadioButtonGroup();
1434 HTMLTextFormControlElement::removedFrom(insertionPoint);
1435 ASSERT(!inDocument());
1436 #if ENABLE(DATALIST_ELEMENT)
1437 resetListAttributeTargetObserver();
1441 void HTMLInputElement::didMoveToNewDocument(Document* oldDocument)
1443 m_inputType->willMoveToNewOwnerDocument();
1444 bool needsSuspensionCallback = this->needsSuspensionCallback();
1446 // Always unregister for cache callbacks when leaving a document, even if we would otherwise like to be registered
1447 if (needsSuspensionCallback)
1448 oldDocument->unregisterForPageCacheSuspensionCallbacks(this);
1449 if (isRadioButton())
1450 oldDocument->formController()->checkedRadioButtons().removeButton(this);
1453 if (needsSuspensionCallback)
1454 document()->registerForPageCacheSuspensionCallbacks(this);
1456 HTMLTextFormControlElement::didMoveToNewDocument(oldDocument);
1459 void HTMLInputElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
1461 HTMLTextFormControlElement::addSubresourceAttributeURLs(urls);
1463 addSubresourceURL(urls, src());
1466 bool HTMLInputElement::recalcWillValidate() const
1468 return m_inputType->supportsValidation() && HTMLTextFormControlElement::recalcWillValidate();
1471 void HTMLInputElement::requiredAttributeChanged()
1473 HTMLTextFormControlElement::requiredAttributeChanged();
1474 if (CheckedRadioButtons* buttons = checkedRadioButtons())
1475 buttons->requiredAttributeChanged(this);
1478 #if ENABLE(INPUT_TYPE_COLOR)
1479 void HTMLInputElement::selectColorInColorChooser(const Color& color)
1481 if (!m_inputType->isColorControl())
1483 static_cast<ColorInputType*>(m_inputType.get())->didChooseColor(color);
1487 #if ENABLE(DATALIST_ELEMENT)
1488 HTMLElement* HTMLInputElement::list() const
1493 HTMLDataListElement* HTMLInputElement::dataList() const
1495 if (!m_hasNonEmptyList)
1498 if (!m_inputType->shouldRespectListAttribute())
1501 Element* element = treeScope()->getElementById(fastGetAttribute(listAttr));
1504 if (!element->hasTagName(datalistTag))
1507 return static_cast<HTMLDataListElement*>(element);
1510 void HTMLInputElement::resetListAttributeTargetObserver()
1513 m_listAttributeTargetObserver = ListAttributeTargetObserver::create(fastGetAttribute(listAttr), this);
1515 m_listAttributeTargetObserver = nullptr;
1518 void HTMLInputElement::listAttributeTargetChanged()
1520 m_inputType->listAttributeTargetChanged();
1522 #endif // ENABLE(DATALIST_ELEMENT)
1524 bool HTMLInputElement::isSteppable() const
1526 return m_inputType->isSteppable();
1529 #if ENABLE(INPUT_SPEECH)
1531 bool HTMLInputElement::isSpeechEnabled() const
1533 // FIXME: Add support for RANGE, EMAIL, URL, COLOR and DATE/TIME input types.
1534 return m_inputType->shouldRespectSpeechAttribute() && RuntimeEnabledFeatures::speechInputEnabled() && hasAttribute(webkitspeechAttr);
1539 bool HTMLInputElement::isTextButton() const
1541 return m_inputType->isTextButton();
1544 bool HTMLInputElement::isRadioButton() const
1546 return m_inputType->isRadioButton();
1549 bool HTMLInputElement::isSearchField() const
1551 return m_inputType->isSearchField();
1554 bool HTMLInputElement::isInputTypeHidden() const
1556 return m_inputType->isHiddenType();
1559 bool HTMLInputElement::isPasswordField() const
1561 return m_inputType->isPasswordField();
1564 bool HTMLInputElement::isCheckbox() const
1566 return m_inputType->isCheckbox();
1569 bool HTMLInputElement::isRangeControl() const
1571 return m_inputType->isRangeControl();
1574 bool HTMLInputElement::isText() const
1576 return m_inputType->isTextType();
1579 bool HTMLInputElement::isEmailField() const
1581 return m_inputType->isEmailField();
1584 bool HTMLInputElement::isFileUpload() const
1586 return m_inputType->isFileUpload();
1589 bool HTMLInputElement::isImageButton() const
1591 return m_inputType->isImageButton();
1594 bool HTMLInputElement::isNumberField() const
1596 return m_inputType->isNumberField();
1599 bool HTMLInputElement::isSubmitButton() const
1601 return m_inputType->isSubmitButton();
1604 bool HTMLInputElement::isTelephoneField() const
1606 return m_inputType->isTelephoneField();
1609 bool HTMLInputElement::isURLField() const
1611 return m_inputType->isURLField();
1614 bool HTMLInputElement::isDateField() const
1616 return m_inputType->isDateField();
1619 bool HTMLInputElement::isDateTimeField() const
1621 return m_inputType->isDateTimeField();
1624 bool HTMLInputElement::isDateTimeLocalField() const
1626 return m_inputType->isDateTimeLocalField();
1629 bool HTMLInputElement::isMonthField() const
1631 return m_inputType->isMonthField();
1634 bool HTMLInputElement::isTimeField() const
1636 return m_inputType->isTimeField();
1639 bool HTMLInputElement::isWeekField() const
1641 return m_inputType->isWeekField();
1644 bool HTMLInputElement::isEnumeratable() const
1646 return m_inputType->isEnumeratable();
1649 bool HTMLInputElement::supportLabels() const
1651 return m_inputType->supportLabels();
1654 bool HTMLInputElement::shouldAppearChecked() const
1656 return checked() && m_inputType->isCheckable();
1659 bool HTMLInputElement::supportsPlaceholder() const
1661 return m_inputType->supportsPlaceholder();
1664 bool HTMLInputElement::isPlaceholderEmpty() const
1666 if (m_inputType->usesFixedPlaceholder())
1667 return m_inputType->fixedPlaceholder().isEmpty();
1668 return HTMLTextFormControlElement::isPlaceholderEmpty();
1671 void HTMLInputElement::updatePlaceholderText()
1673 return m_inputType->updatePlaceholderText();
1676 void HTMLInputElement::parseMaxLengthAttribute(const Attribute& attribute)
1679 if (!parseHTMLInteger(attribute.value(), maxLength))
1680 maxLength = maximumLength;
1681 if (maxLength < 0 || maxLength > maximumLength)
1682 maxLength = maximumLength;
1683 int oldMaxLength = m_maxLength;
1684 m_maxLength = maxLength;
1685 if (oldMaxLength != maxLength)
1686 updateValueIfNeeded();
1687 setNeedsStyleRecalc();
1688 setNeedsValidityCheck();
1691 void HTMLInputElement::updateValueIfNeeded()
1693 String newValue = sanitizeValue(m_valueIfDirty);
1694 ASSERT(!m_valueIfDirty.isNull() || newValue.isNull());
1695 if (newValue != m_valueIfDirty)
1699 String HTMLInputElement::defaultToolTip() const
1701 return m_inputType->defaultToolTip();
1704 bool HTMLInputElement::isIndeterminate() const
1706 return m_inputType->supportsIndeterminateAppearance() && indeterminate();
1709 #if ENABLE(MEDIA_CAPTURE)
1710 String HTMLInputElement::capture() const
1712 if (!isFileUpload())
1715 String capture = fastGetAttribute(captureAttr).lower();
1716 if (capture == "camera"
1717 || capture == "camcorder"
1718 || capture == "microphone"
1719 || capture == "filesystem")
1722 return "filesystem";
1725 void HTMLInputElement::setCapture(const String& value)
1727 setAttribute(captureAttr, value);
1732 bool HTMLInputElement::isInRequiredRadioButtonGroup() const
1734 ASSERT(isRadioButton());
1735 if (CheckedRadioButtons* buttons = checkedRadioButtons())
1736 return buttons->isRequiredGroup(name());
1740 HTMLInputElement* HTMLInputElement::checkedRadioButtonForGroup() const
1742 if (CheckedRadioButtons* buttons = checkedRadioButtons())
1743 return buttons->checkedButtonForGroup(name());
1747 CheckedRadioButtons* HTMLInputElement::checkedRadioButtons() const
1749 if (!isRadioButton())
1751 if (HTMLFormElement* formElement = form())
1752 return &formElement->checkedRadioButtons();
1754 return &document()->formController()->checkedRadioButtons();
1758 inline void HTMLInputElement::addToRadioButtonGroup()
1760 if (CheckedRadioButtons* buttons = checkedRadioButtons())
1761 buttons->addButton(this);
1764 inline void HTMLInputElement::removeFromRadioButtonGroup()
1766 if (CheckedRadioButtons* buttons = checkedRadioButtons())
1767 buttons->removeButton(this);
1770 unsigned HTMLInputElement::height() const
1772 return m_inputType->height();
1775 unsigned HTMLInputElement::width() const
1777 return m_inputType->width();
1780 void HTMLInputElement::setHeight(unsigned height)
1782 setAttribute(heightAttr, String::number(height));
1785 void HTMLInputElement::setWidth(unsigned width)
1787 setAttribute(widthAttr, String::number(width));
1790 #if ENABLE(DATALIST_ELEMENT)
1791 PassOwnPtr<ListAttributeTargetObserver> ListAttributeTargetObserver::create(const AtomicString& id, HTMLInputElement* element)
1793 return adoptPtr(new ListAttributeTargetObserver(id, element));
1796 ListAttributeTargetObserver::ListAttributeTargetObserver(const AtomicString& id, HTMLInputElement* element)
1797 : IdTargetObserver(element->treeScope()->idTargetObserverRegistry(), id)
1798 , m_element(element)
1802 void ListAttributeTargetObserver::idTargetChanged()
1804 m_element->listAttributeTargetChanged();
1808 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1809 bool HTMLInputElement::shouldUsePicker()
1811 return (isDateField() || isDateTimeField() || isDateTimeLocalField() || isMonthField() || isTimeField() || isWeekField());