diff options
author | Steve Block <steveblock@google.com> | 2011-06-10 16:52:27 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-14 01:14:02 +0100 |
commit | 54cdeeebc7adcbcd900e8b6a141a8cae27d9a631 (patch) | |
tree | 845b0d338b204a48560eca3b51b34cf92ed96840 /Source/WebCore/html/HTMLFormControlElement.cpp | |
parent | d2c5226a647dc21d0c15267e09a3d19cf3e0d593 (diff) | |
download | external_webkit-54cdeeebc7adcbcd900e8b6a141a8cae27d9a631.zip external_webkit-54cdeeebc7adcbcd900e8b6a141a8cae27d9a631.tar.gz external_webkit-54cdeeebc7adcbcd900e8b6a141a8cae27d9a631.tar.bz2 |
Merge WebKit at branches/chromium/742 r88085: Initial merge by git.
Change-Id: I0501b484b9528e31b0026e5ad64416dd6541cdde
Diffstat (limited to 'Source/WebCore/html/HTMLFormControlElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLFormControlElement.cpp | 52 |
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() |