Title: [86976] trunk
Revision
86976
Author
infe...@chromium.org
Date
2011-05-20 12:36:02 -0700 (Fri, 20 May 2011)

Log Message

2011-05-20  Abhishek Arya  <infe...@chromium.org>

        Reviewed by Kent Tamura.

        Tests that we do not crash when auto-focus triggers a attach.
        https://bugs.webkit.org/show_bug.cgi?id=32882

        * fast/forms/input-element-attach-crash-expected.txt: Added.
        * fast/forms/input-element-attach-crash.html: Added.
2011-05-20  Abhishek Arya  <infe...@chromium.org>

        Reviewed by Kent Tamura.

        Make auto-focus a post attach callback in
        HTMLFormControlElement::attach().
        https://bugs.webkit.org/show_bug.cgi?id=32882

        Original patch by Darin Adler. This one uses a part of it.
        
        Test: fast/forms/input-element-attach-crash.html

        * dom/Document.cpp:
        (WebCore::Document::recalcStyle): Make sure that m_inStyleRecalc is
        already false by the time post-attach callbacks are done so that
        layout triggered inside those callbacks can work properly.
        * html/HTMLFormControlElement.cpp:
        (WebCore::shouldAutofocus): Helper function that expresses
        the rule for which form control elements should auto-focus.
        (WebCore::focusPostAttach): Called post-attach to focus an
        element if we discover it should be focused during attach.
        (WebCore::HTMLFormControlElement::attach): Refactored code for
        which elements need auto-focus into a separate function. Instead
        of focusing right away, use the focusPostAttach function to focus
        after attach is done. Also added calls to suspendPostAttachCallbacks
        and resumePostAttachCallbacks so post-attach callbacks happen late
        enough. Before, they could run inside the base attach function.
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::attach): Added calls to
        suspendPostAttachCallbacks and resumePostAttachCallbacks so
        post-attach callbacks happen late enough

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (86975 => 86976)


--- trunk/LayoutTests/ChangeLog	2011-05-20 19:28:10 UTC (rev 86975)
+++ trunk/LayoutTests/ChangeLog	2011-05-20 19:36:02 UTC (rev 86976)
@@ -1,3 +1,13 @@
+2011-05-20  Abhishek Arya  <infe...@chromium.org>
+
+        Reviewed by Kent Tamura.
+
+        Tests that we do not crash when auto-focus triggers a attach.
+        https://bugs.webkit.org/show_bug.cgi?id=32882
+
+        * fast/forms/input-element-attach-crash-expected.txt: Added.
+        * fast/forms/input-element-attach-crash.html: Added.
+
 2011-05-20  Mark Pilgrim  <pilg...@chromium.org>
 
         Reviewed by Tony Chang.

Added: trunk/LayoutTests/fast/forms/input-element-attach-crash-expected.txt (0 => 86976)


--- trunk/LayoutTests/fast/forms/input-element-attach-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-element-attach-crash-expected.txt	2011-05-20 19:36:02 UTC (rev 86976)
@@ -0,0 +1,2 @@
+ 
+PASS  

Added: trunk/LayoutTests/fast/forms/input-element-attach-crash.html (0 => 86976)


--- trunk/LayoutTests/fast/forms/input-element-attach-crash.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-element-attach-crash.html	2011-05-20 19:36:02 UTC (rev 86976)
@@ -0,0 +1,20 @@
+<html>
+    <head>
+        <script>
+            if (window.layoutTestController)
+                layoutTestController.dumpAsText();
+        </script>
+    </head>
+    <body>
+        <button autofocus>
+            <object>
+                <select autofocus>
+                <input>
+                <span>
+                <div></div>
+                PASS
+            </object>
+            <object></object>
+        </button>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (86975 => 86976)


--- trunk/Source/WebCore/ChangeLog	2011-05-20 19:28:10 UTC (rev 86975)
+++ trunk/Source/WebCore/ChangeLog	2011-05-20 19:36:02 UTC (rev 86976)
@@ -1,3 +1,35 @@
+2011-05-20  Abhishek Arya  <infe...@chromium.org>
+
+        Reviewed by Kent Tamura.
+
+        Make auto-focus a post attach callback in
+        HTMLFormControlElement::attach().
+        https://bugs.webkit.org/show_bug.cgi?id=32882
+
+        Original patch by Darin Adler. This one uses a part of it.
+        
+        Test: fast/forms/input-element-attach-crash.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::recalcStyle): Make sure that m_inStyleRecalc is
+        already false by the time post-attach callbacks are done so that
+        layout triggered inside those callbacks can work properly.
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::shouldAutofocus): Helper function that expresses
+        the rule for which form control elements should auto-focus.
+        (WebCore::focusPostAttach): Called post-attach to focus an
+        element if we discover it should be focused during attach.
+        (WebCore::HTMLFormControlElement::attach): Refactored code for
+        which elements need auto-focus into a separate function. Instead
+        of focusing right away, use the focusPostAttach function to focus
+        after attach is done. Also added calls to suspendPostAttachCallbacks
+        and resumePostAttachCallbacks so post-attach callbacks happen late
+        enough. Before, they could run inside the base attach function.
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::attach): Added calls to
+        suspendPostAttachCallbacks and resumePostAttachCallbacks so
+        post-attach callbacks happen late enough
+
 2011-05-20  Alok Priyadarshi  <al...@chromium.org>
 
         Reviewed by James Robinson.

Modified: trunk/Source/WebCore/dom/Document.cpp (86975 => 86976)


--- trunk/Source/WebCore/dom/Document.cpp	2011-05-20 19:28:10 UTC (rev 86975)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-05-20 19:36:02 UTC (rev 86976)
@@ -1543,6 +1543,8 @@
     clearNeedsStyleRecalc();
     clearChildNeedsStyleRecalc();
     unscheduleStyleRecalc();
+
+    m_inStyleRecalc = false;
     
     // Pseudo element removal and similar may only work with these flags still set. Reset them after the style recalc.
     if (m_styleSelector) {
@@ -1558,7 +1560,6 @@
     }
     RenderWidget::resumeWidgetHierarchyUpdates();
     resumePostAttachCallbacks();
-    m_inStyleRecalc = false;
 
     // If we wanted to call implicitClose() during recalcStyle, do so now that we're finished.
     if (m_closeAfterStyleRecalc) {

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (86975 => 86976)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2011-05-20 19:28:10 UTC (rev 86975)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2011-05-20 19:36:02 UTC (rev 86976)
@@ -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()

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (86975 => 86976)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-05-20 19:28:10 UTC (rev 86975)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-05-20 19:36:02 UTC (rev 86976)
@@ -735,6 +735,8 @@
 
 void HTMLInputElement::attach()
 {
+    suspendPostAttachCallbacks();
+
     if (!m_hasType)
         updateType();
 
@@ -744,6 +746,8 @@
 
     if (document()->focusedNode() == this)
         document()->updateFocusAppearanceSoon(true /* restore selection */);
+
+    resumePostAttachCallbacks();
 }
 
 void HTMLInputElement::detach()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to