summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLInputElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/HTMLInputElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLInputElement.cpp115
1 files changed, 67 insertions, 48 deletions
diff --git a/Source/WebCore/html/HTMLInputElement.cpp b/Source/WebCore/html/HTMLInputElement.cpp
index 9248f0bc2..4a8107ee5 100644
--- a/Source/WebCore/html/HTMLInputElement.cpp
+++ b/Source/WebCore/html/HTMLInputElement.cpp
@@ -37,6 +37,7 @@
#include "EventNames.h"
#include "ExceptionCode.h"
#include "FileList.h"
+#include "FormController.h"
#include "Frame.h"
#include "HTMLCollection.h"
#include "HTMLDataListElement.h"
@@ -127,10 +128,10 @@ HTMLInputElement::~HTMLInputElement()
// setForm(0) may register this to a document-level radio button group.
// We should unregister it to avoid accessing a deleted object.
if (isRadioButton())
- document()->checkedRadioButtons().removeButton(this);
+ document()->formController()->checkedRadioButtons().removeButton(this);
}
-const AtomicString& HTMLInputElement::formControlName() const
+const AtomicString& HTMLInputElement::name() const
{
return m_name.isNull() ? emptyAtom : m_name;
}
@@ -273,7 +274,7 @@ bool HTMLInputElement::stepMismatch() const
return willValidate() && m_inputType->stepMismatch(value());
}
-bool HTMLInputElement::getAllowedValueStep(double* step) const
+bool HTMLInputElement::getAllowedValueStep(Decimal* step) const
{
return m_inputType->getAllowedValueStep(step);
}
@@ -295,15 +296,26 @@ void HTMLInputElement::stepDown(int n, ExceptionCode& ec)
bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const
{
- if (isTextField())
- return HTMLTextFormControlElement::isFocusable();
- return HTMLTextFormControlElement::isKeyboardFocusable(event) && m_inputType->isKeyboardFocusable();
+ return m_inputType->isKeyboardFocusable(event);
}
bool HTMLInputElement::isMouseFocusable() const
{
- if (isTextField())
- return HTMLTextFormControlElement::isFocusable();
+ return m_inputType->isMouseFocusable();
+}
+
+bool HTMLInputElement::isTextFormControlFocusable() const
+{
+ return HTMLTextFormControlElement::isFocusable();
+}
+
+bool HTMLInputElement::isTextFormControlKeyboardFocusable(KeyboardEvent* event) const
+{
+ return HTMLTextFormControlElement::isKeyboardFocusable(event);
+}
+
+bool HTMLInputElement::isTextFormControlMouseFocusable() const
+{
return HTMLTextFormControlElement::isMouseFocusable();
}
@@ -456,7 +468,6 @@ void HTMLInputElement::subtreeHasChanged()
{
ASSERT(isTextField());
ASSERT(renderer());
- RenderTextControlSingleLine* renderTextControl = toRenderTextControlSingleLine(renderer());
bool wasChanged = wasChangedSinceLastFormControlChangeEvent();
setChangedSinceLastFormControlChangeEvent(true);
@@ -472,12 +483,7 @@ void HTMLInputElement::subtreeHasChanged()
// Recalc for :invalid and hasUnacceptableValue() change.
setNeedsStyleRecalc();
- if (cancelButtonElement())
- renderTextControl->updateCancelButtonVisibility();
-
- // If the incremental attribute is set, then dispatch the search event
- if (searchEventsShouldBeDispatched() && isSearchField() && m_inputType)
- static_cast<SearchInputType*>(m_inputType.get())->startSearchEventTimer();
+ m_inputType->subtreeHasChanged();
if (!wasChanged && focused()) {
if (Frame* frame = document()->frame())
@@ -498,12 +504,12 @@ const AtomicString& HTMLInputElement::formControlType() const
return m_inputType->formControlType();
}
-bool HTMLInputElement::saveFormControlState(String& result) const
+FormControlState HTMLInputElement::saveFormControlState() const
{
- return m_inputType->saveFormControlState(result);
+ return m_inputType->saveFormControlState();
}
-void HTMLInputElement::restoreFormControlState(const String& state)
+void HTMLInputElement::restoreFormControlState(const FormControlState& state)
{
m_inputType->restoreFormControlState(state);
m_stateRestored = true;
@@ -553,7 +559,7 @@ void HTMLInputElement::collectStyleForAttribute(const Attribute& attribute, Styl
} else if (attribute.name() == borderAttr && isImageButton())
applyBorderAttributeToStyle(attribute, style);
else
- return HTMLTextFormControlElement::collectStyleForAttribute(attribute, style);
+ HTMLTextFormControlElement::collectStyleForAttribute(attribute, style);
}
void HTMLInputElement::parseAttribute(const Attribute& attribute)
@@ -949,7 +955,7 @@ void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
double HTMLInputElement::valueAsNumber() const
{
- return m_inputType->valueAsNumber();
+ return m_inputType->valueAsDouble();
}
void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec, TextFieldEventBehavior eventBehavior)
@@ -958,7 +964,7 @@ void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec, Text
ec = NOT_SUPPORTED_ERR;
return;
}
- m_inputType->setValueAsNumber(newValue, eventBehavior, ec);
+ m_inputType->setValueAsDouble(newValue, eventBehavior, ec);
}
String HTMLInputElement::placeholder() const
@@ -971,11 +977,6 @@ void HTMLInputElement::setPlaceholder(const String& value)
setAttribute(placeholderAttr, value);
}
-bool HTMLInputElement::searchEventsShouldBeDispatched() const
-{
- return hasAttribute(incrementalAttr);
-}
-
void HTMLInputElement::setValueFromRenderer(const String& value)
{
// File upload controls will never use this.
@@ -1134,7 +1135,7 @@ static inline bool isRFC2616TokenCharacter(UChar ch)
return isASCII(ch) && ch > ' ' && ch != '"' && ch != '(' && ch != ')' && ch != ',' && ch != '/' && (ch < ':' || ch > '@') && (ch < '[' || ch > ']') && ch != '{' && ch != '}' && ch != 0x7f;
}
-static inline bool isValidMIMEType(const String& type)
+static bool isValidMIMEType(const String& type)
{
size_t slashPosition = type.find('/');
if (slashPosition == notFound || !slashPosition || slashPosition == type.length() - 1)
@@ -1146,26 +1147,41 @@ static inline bool isValidMIMEType(const String& type)
return true;
}
-Vector<String> HTMLInputElement::acceptMIMETypes()
+static bool isValidFileExtension(const String& type)
{
- Vector<String> mimeTypes;
+ if (type.length() < 2)
+ return false;
+ return type[0] == '.';
+}
- String acceptString = accept();
+static Vector<String> parseAcceptAttribute(const String& acceptString, bool (*predicate)(const String&))
+{
+ Vector<String> types;
if (acceptString.isEmpty())
- return mimeTypes;
+ return types;
Vector<String> splitTypes;
acceptString.split(',', false, splitTypes);
for (size_t i = 0; i < splitTypes.size(); ++i) {
- String trimmedMimeType = stripLeadingAndTrailingHTMLSpaces(splitTypes[i]);
- if (trimmedMimeType.isEmpty())
+ String trimmedType = stripLeadingAndTrailingHTMLSpaces(splitTypes[i]);
+ if (trimmedType.isEmpty())
continue;
- if (!isValidMIMEType(trimmedMimeType))
+ if (!predicate(trimmedType))
continue;
- mimeTypes.append(trimmedMimeType.lower());
+ types.append(trimmedType.lower());
}
- return mimeTypes;
+ return types;
+}
+
+Vector<String> HTMLInputElement::acceptMIMETypes()
+{
+ return parseAcceptAttribute(fastGetAttribute(acceptAttr), isValidMIMEType);
+}
+
+Vector<String> HTMLInputElement::acceptFileExtensions()
+{
+ return parseAcceptAttribute(fastGetAttribute(acceptAttr), isValidFileExtension);
}
String HTMLInputElement::accept() const
@@ -1225,11 +1241,18 @@ void HTMLInputElement::setFiles(PassRefPtr<FileList> files)
m_inputType->setFiles(files);
}
-void HTMLInputElement::receiveDroppedFiles(const Vector<String>& filenames)
+bool HTMLInputElement::receiveDroppedFiles(const DragData* dragData)
{
- m_inputType->receiveDroppedFiles(filenames);
+ return m_inputType->receiveDroppedFiles(dragData);
}
+#if ENABLE(FILE_SYSTEM)
+String HTMLInputElement::droppedFileSystemId()
+{
+ return m_inputType->droppedFileSystemId();
+}
+#endif
+
Icon* HTMLInputElement::icon() const
{
return m_inputType->icon();
@@ -1317,9 +1340,7 @@ bool HTMLInputElement::isRequiredFormControl() const
void HTMLInputElement::addSearchResult()
{
- ASSERT(isSearchField());
- if (renderer())
- toRenderTextControlSingleLine(renderer())->addSearchResult();
+ m_inputType->addSearchResult();
}
void HTMLInputElement::onSearch()
@@ -1351,16 +1372,14 @@ void HTMLInputElement::didChangeForm()
Node::InsertionNotificationRequest HTMLInputElement::insertedInto(ContainerNode* insertionPoint)
{
HTMLTextFormControlElement::insertedInto(insertionPoint);
- if (!insertionPoint->inDocument())
- return InsertionDone;
- ASSERT(inDocument());
- addToRadioButtonGroup();
+ if (insertionPoint->inDocument() && !form())
+ addToRadioButtonGroup();
return InsertionDone;
}
void HTMLInputElement::removedFrom(ContainerNode* insertionPoint)
{
- if (insertionPoint->inDocument())
+ if (insertionPoint->inDocument() && !form())
removeFromRadioButtonGroup();
HTMLTextFormControlElement::removedFrom(insertionPoint);
}
@@ -1374,7 +1393,7 @@ void HTMLInputElement::didMoveToNewDocument(Document* oldDocument)
if (needsSuspensionCallback)
oldDocument->unregisterForPageCacheSuspensionCallbacks(this);
if (isRadioButton())
- oldDocument->checkedRadioButtons().removeButton(this);
+ oldDocument->formController()->checkedRadioButtons().removeButton(this);
}
if (needsSuspensionCallback)
@@ -1672,7 +1691,7 @@ CheckedRadioButtons* HTMLInputElement::checkedRadioButtons() const
if (HTMLFormElement* formElement = form())
return &formElement->checkedRadioButtons();
if (inDocument())
- return &document()->checkedRadioButtons();
+ return &document()->formController()->checkedRadioButtons();
return 0;
}