Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: Source/WebCore/html/HTMLFormControlElement.cpp

Issue 7065003: Merge 86976 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/742/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/dom/Document.cpp ('k') | Source/WebCore/html/HTMLInputElement.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/html/HTMLFormControlElement.cpp
===================================================================
--- Source/WebCore/html/HTMLFormControlElement.cpp (revision 87084)
+++ Source/WebCore/html/HTMLFormControlElement.cpp (working copy)
@@ -120,10 +120,45 @@
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 @@
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 (shouldAutofocus(this)) {
+ ref();
+ queuePostAttachCallback(focusPostAttach, this);
+ }
- if (autofocus() && renderer() && !document()->ignoreAutofocus() && !isReadOnlyFormControl() &&
- ((hasTagName(inputTag) && !isInputTypeHidden) || hasTagName(selectTag) ||
- hasTagName(keygenTag) || hasTagName(buttonTag) || hasTagName(textareaTag)))
- focus();
+ resumePostAttachCallbacks();
}
void HTMLFormControlElement::willMoveToNewOwnerDocument()
« no previous file with comments | « Source/WebCore/dom/Document.cpp ('k') | Source/WebCore/html/HTMLInputElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698