LayoutTests:
authorantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Feb 2007 19:57:49 +0000 (19:57 +0000)
committerantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Feb 2007 19:57:49 +0000 (19:57 +0000)
        Reviewed by Darin.

        - tests for http://bugs.webkit.org/show_bug.cgi?id=11447
        REGRESSION(NativeListBox): List not scrolled to preselected option
        <rdar://problem/4957463>

        * fast/forms/select-initial-position-expected.checksum: Added.
        * fast/forms/select-initial-position-expected.png: Added.
        * fast/forms/select-initial-position-expected.txt: Added.
        * fast/forms/select-initial-position.html: Added.

WebCore:

        Reviewed by Darin.

        - fix http://bugs.webkit.org/show_bug.cgi?id=11447
        REGRESSION(NativeListBox): List not scrolled to preselected option
        <rdar://problem/4957463>

        Initiate scroll when selected <option> is added to <select>.

        * html/HTMLOptionElement.cpp:
        (WebCore::HTMLOptionElement::insertedIntoDocument):
        * html/HTMLOptionElement.h:
        * html/HTMLSelectElement.cpp:
        (WebCore::HTMLSelectElement::notifyOptionSelected):
        (WebCore::HTMLSelectElement::updateListBoxSelection):
        (WebCore::HTMLSelectElement::scrollToSelection):
        * html/HTMLSelectElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19797 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/select-initial-position-expected.checksum [new file with mode: 0644]
LayoutTests/fast/forms/select-initial-position-expected.png [new file with mode: 0644]
LayoutTests/fast/forms/select-initial-position-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/select-initial-position.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLOptionElement.cpp
WebCore/html/HTMLOptionElement.h
WebCore/html/HTMLSelectElement.cpp
WebCore/html/HTMLSelectElement.h

index 0b84324c0006b59b2eab4a1ba0062fe05ebe777b..4180de3738c28ea4350c210edb746883fb4ebe6e 100644 (file)
@@ -1,3 +1,16 @@
+2007-02-21  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+        
+        - tests for http://bugs.webkit.org/show_bug.cgi?id=11447
+        REGRESSION(NativeListBox): List not scrolled to preselected option
+        <rdar://problem/4957463>
+
+        * fast/forms/select-initial-position-expected.checksum: Added.
+        * fast/forms/select-initial-position-expected.png: Added.
+        * fast/forms/select-initial-position-expected.txt: Added.
+        * fast/forms/select-initial-position.html: Added.
+
 2007-02-21  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Adam Roben.
diff --git a/LayoutTests/fast/forms/select-initial-position-expected.checksum b/LayoutTests/fast/forms/select-initial-position-expected.checksum
new file mode 100644 (file)
index 0000000..ee1da7d
--- /dev/null
@@ -0,0 +1 @@
+7099cf6855580900bbcd91ca42a80a0f
\ No newline at end of file
diff --git a/LayoutTests/fast/forms/select-initial-position-expected.png b/LayoutTests/fast/forms/select-initial-position-expected.png
new file mode 100644 (file)
index 0000000..0aed358
Binary files /dev/null and b/LayoutTests/fast/forms/select-initial-position-expected.png differ
diff --git a/LayoutTests/fast/forms/select-initial-position-expected.txt b/LayoutTests/fast/forms/select-initial-position-expected.txt
new file mode 100644 (file)
index 0000000..03708cc
--- /dev/null
@@ -0,0 +1,58 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderText {#text} at (0,0) size 93x18
+        text run at (0,0) width 93: "initial selected:"
+      RenderBR {BR} at (93,14) size 0x0
+      RenderListBox {SELECT} at (2,20) size 141x57 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
+      RenderText {#text} at (145,58) size 4x18
+        text run at (145,58) width 4: " "
+      RenderBR {BR} at (149,72) size 0x0
+      RenderText {#text} at (0,79) size 161x18
+        text run at (0,79) width 161: "dynamic selected change:"
+      RenderBR {BR} at (161,93) size 0x0
+      RenderListBox {SELECT} at (2,99) size 141x57 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
+      RenderText {#text} at (145,137) size 4x18
+        text run at (145,137) width 4: " "
+      RenderText {#text} at (0,0) size 0x0
+      RenderBR {BR} at (0,0) size 0x0
+      RenderText {#text} at (0,158) size 211x18
+        text run at (0,158) width 211: "dynamic insert of selected option:"
+      RenderBR {BR} at (211,172) size 0x0
+      RenderListBox {SELECT} at (2,178) size 141x57 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
+      RenderText {#text} at (145,216) size 4x18
+        text run at (145,216) width 4: " "
+      RenderBR {BR} at (149,230) size 0x0
+      RenderText {#text} at (0,237) size 93x18
+        text run at (0,237) width 93: "initial selected:"
+      RenderBR {BR} at (93,251) size 0x0
+      RenderMenuList {SELECT} at (2,257) size 155x18 [bgcolor=#FFFFFF]
+        RenderBlock (anonymous) at (8,2) size 124x13
+          RenderText at (0,0) size 124x13
+            text run at (0,0) width 124: "this should be selected"
+      RenderText {#text} at (159,256) size 4x18
+        text run at (159,256) width 4: " "
+      RenderBR {BR} at (163,270) size 0x0
+      RenderText {#text} at (0,277) size 161x18
+        text run at (0,277) width 161: "dynamic selected change:"
+      RenderBR {BR} at (161,291) size 0x0
+      RenderMenuList {SELECT} at (2,297) size 155x18 [bgcolor=#FFFFFF]
+        RenderBlock (anonymous) at (8,2) size 124x13
+          RenderText at (0,0) size 124x13
+            text run at (0,0) width 124: "this should be selected"
+      RenderText {#text} at (159,296) size 4x18
+        text run at (159,296) width 4: " "
+      RenderText {#text} at (0,0) size 0x0
+      RenderBR {BR} at (0,0) size 0x0
+      RenderText {#text} at (0,317) size 211x18
+        text run at (0,317) width 211: "dynamic insert of selected option:"
+      RenderBR {BR} at (211,331) size 0x0
+      RenderMenuList {SELECT} at (2,337) size 155x18 [bgcolor=#FFFFFF]
+        RenderBlock (anonymous) at (8,2) size 124x13
+          RenderText at (0,0) size 124x13
+            text run at (0,0) width 124: "this should be selected"
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/fast/forms/select-initial-position.html b/LayoutTests/fast/forms/select-initial-position.html
new file mode 100644 (file)
index 0000000..7e24851
--- /dev/null
@@ -0,0 +1,148 @@
+<html>
+
+<body>
+initial selected:<br>
+<select name="component" size="4">
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option selected=selected>this should be selected</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+</select>
+<br>
+dynamic selected change:<br>
+<select size="4">
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option id='x'>this should be selected</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+</select>
+<script>
+document.getElementById('x').selected = 'selected';
+</script>
+<br>
+dynamic insert of selected option:<br>
+<script>
+var sel = document.createElement('select');
+sel.setAttribute('size','4');
+document.body.appendChild(sel);
+var opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'this should be selected';
+opt.selected = 'selected';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+</script>
+<br>
+initial selected:<br>
+<select name="component" size="1">
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option selected=selected>this should be selected</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+</select>
+<br>
+dynamic selected change:<br>
+<select size="1">
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option id='xx'>this should be selected</option>
+    <option>opt</option>
+    <option>opt</option>
+    <option>opt</option>
+</select>
+<script>
+document.getElementById('xx').selected = 'selected';
+</script>
+<br>
+dynamic insert of selected option:<br>
+<script>
+var sel = document.createElement('select');
+sel.setAttribute('size','1');
+document.body.appendChild(sel);
+var opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'this should be selected';
+opt.selected = 'selected';
+sel.appendChild(opt);
+opt = document.createElement('option')
+opt.innerHTML = 'opt';
+sel.appendChild(opt);
+</script>
+
+</body>
+
+</html>
index 95add6eb19a16ba9b7320ff8da8c301a7c304b04..5b391f85810923d4319b57037f4457f1f06d07df 100644 (file)
@@ -1,3 +1,22 @@
+2007-02-22  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+
+        - fix http://bugs.webkit.org/show_bug.cgi?id=11447
+        REGRESSION(NativeListBox): List not scrolled to preselected option
+        <rdar://problem/4957463>
+        
+        Initiate scroll when selected <option> is added to <select>.
+
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::insertedIntoDocument):
+        * html/HTMLOptionElement.h:
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::notifyOptionSelected):
+        (WebCore::HTMLSelectElement::updateListBoxSelection):
+        (WebCore::HTMLSelectElement::scrollToSelection):
+        * html/HTMLSelectElement.h:
+
 2007-02-22  Zack Rusin  <zrusin@trolltech.com>
 
         Reviewed by Lars
index 8d8442be3bd432c2487e83ccf38627dc4e3e39e8..9565a83424c78d9b07121ace05bd064fb7301509 100644 (file)
@@ -245,4 +245,13 @@ bool HTMLOptionElement::disabled() const
     return HTMLGenericFormElement::disabled() || (parentNode() && static_cast<HTMLGenericFormElement*>(parentNode())->disabled()); 
 }
 
+void HTMLOptionElement::insertedIntoDocument()
+{
+    HTMLSelectElement* select;
+    if (selected() && (select = getSelect()))
+        select->scrollToSelection();
+    
+    HTMLGenericFormElement::insertedIntoDocument();
+}
+
 } // namespace
index d234c22dabd218bfacfc66c064605d7c6c251c3b..479eb62a9efef9035179f0b3a91b0c7fe4ed1d2d 100644 (file)
@@ -79,6 +79,8 @@ public:
     String optionText();
     
     virtual bool disabled() const;
+    
+    virtual void insertedIntoDocument();
 
 private:
     String m_value;
index 39c7602d5eca24214a142f6ec2a23a5c2cc514eb..837f18252eccc139ba3ac7ff205ba97e18eb0d3f 100644 (file)
@@ -562,8 +562,7 @@ void HTMLSelectElement::notifyOptionSelected(HTMLOptionElement* selectedOption,
     if (selected && !m_multiple)
         deselectItems(selectedOption);
 
-    if (renderer() && !usesMenuList())
-        static_cast<RenderListBox*>(renderer())->selectionChanged();
+    scrollToSelection();
 
     m_lastOnChangeIndex = selectedOption->index();
     setChanged(true);
@@ -821,7 +820,7 @@ void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions)
         }
     }
 
-    static_cast<RenderListBox*>(renderer())->selectionChanged();
+    scrollToSelection();
 }
 
 void HTMLSelectElement::listBoxOnChange()
@@ -1008,4 +1007,10 @@ void HTMLSelectElement::setLength(unsigned newLen, ExceptionCode& ec)
             remove(newLen);
 }
 
+void HTMLSelectElement::scrollToSelection()
+{
+    if (renderer() && !usesMenuList())
+        static_cast<RenderListBox*>(renderer())->selectionChanged();
+}
+
 } // namespace
index 61ba0f8eee701e3f9d31052cf2af11e24ffb038f..0d6135bb4c3bd6a32e8f7309ab2de3c9bbac922d 100644 (file)
@@ -134,6 +134,8 @@ public:
     
     int activeSelectionStartListIndex() const;
     int activeSelectionEndListIndex() const;
+    
+    void scrollToSelection();
 
 private:
     void recalcListItems() const;