summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/html/HTMLFormControlElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/HTMLFormControlElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLFormControlElement.cpp52
1 files changed, 41 insertions, 11 deletions
diff --git a/Source/WebCore/html/HTMLFormControlElement.cpp b/Source/WebCore/html/HTMLFormControlElement.cpp
index 87f4e4d..3d8812e 100644
--- a/Source/WebCore/html/HTMLFormControlElement.cpp
+++ b/Source/WebCore/html/HTMLFormControlElement.cpp
@@ -120,10 +120,45 @@ void HTMLFormControlElement::parseMappedAttribute(Attribute* attr)
setNeedsWillValidateCheck();
}
+static bool shouldAutofocus(HTMLFormControlElement* element)
+{
+ if (!element->autofocus())
+ return false;
+ if (!element->renderer())
+ return false;
+ if (element->document()->ignoreAutofocus())
+ return false;
+ if (element->isReadOnlyFormControl())
+ return false;
+
+ // FIXME: Should this set of hasTagName checks be replaced by a
+ // virtual member function?
+ if (element->hasTagName(inputTag))
+ return !static_cast<HTMLInputElement*>(element)->isInputTypeHidden();
+ if (element->hasTagName(selectTag))
+ return true;
+ if (element->hasTagName(keygenTag))
+ return true;
+ if (element->hasTagName(buttonTag))
+ return true;
+ if (element->hasTagName(textareaTag))
+ return true;
+
+ return false;
+}
+
+static void focusPostAttach(Node* element)
+{
+ static_cast<Element*>(element)->focus();
+ element->deref();
+}
+
void HTMLFormControlElement::attach()
{
ASSERT(!attached());
+ suspendPostAttachCallbacks();
+
HTMLElement::attach();
// The call to updateFromElement() needs to go after the call through
@@ -132,17 +167,12 @@ void HTMLFormControlElement::attach()
if (renderer())
renderer()->updateFromElement();
- // Focus the element if it should honour its autofocus attribute.
- // We have to determine if the element is a TextArea/Input/Button/Select,
- // if input type hidden ignore autofocus. So if disabled or readonly.
- bool isInputTypeHidden = false;
- if (hasTagName(inputTag))
- isInputTypeHidden = static_cast<HTMLInputElement*>(this)->isInputTypeHidden();
-
- if (autofocus() && renderer() && !document()->ignoreAutofocus() && !isReadOnlyFormControl() &&
- ((hasTagName(inputTag) && !isInputTypeHidden) || hasTagName(selectTag) ||
- hasTagName(keygenTag) || hasTagName(buttonTag) || hasTagName(textareaTag)))
- focus();
+ if (shouldAutofocus(this)) {
+ ref();
+ queuePostAttachCallback(focusPostAttach, this);
+ }
+
+ resumePostAttachCallbacks();
}
void HTMLFormControlElement::willMoveToNewOwnerDocument()