Cannot select multiple non-adjacent items in a multiple select control with the keybo...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jan 2014 17:23:48 +0000 (17:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jan 2014 17:23:48 +0000 (17:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=15816

Patch by Pascal Jacquemart <p.jacquemart@samsung.com> on 2014-01-09
Reviewed by Chris Fleizach.

Source/WebCore:

Test: fast/forms/listbox-non-contiguous-keyboard-selection.html

* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::HTMLSelectElement):
New member m_allowsNonContiguousSelection defaults to false
(WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
Tracking CTRL modifier to start multiple non contiguous selection
* html/HTMLSelectElement.h: New member m_allowsNonContiguousSelection
(WebCore::HTMLSelectElement::allowsNonContiguousSelection): New getter
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::addFocusRingRects):
Following implementation made for spatial navigation

LayoutTests:

* fast/forms/listbox-non-contiguous-keyboard-selection-expected.txt: Added.
* fast/forms/listbox-non-contiguous-keyboard-selection.html: Added.
* platform/mac/TestExpectations:
Multiple non contiguous selection with keyboard not enabled on Mac

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/listbox-non-contiguous-keyboard-selection-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/listbox-non-contiguous-keyboard-selection.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElement.h
Source/WebCore/rendering/RenderListBox.cpp

index 0668d52..30d7452 100644 (file)
@@ -1,3 +1,15 @@
+2014-01-09  Pascal Jacquemart  <p.jacquemart@samsung.com>
+
+        Cannot select multiple non-adjacent items in a multiple select control with the keyboard only
+        https://bugs.webkit.org/show_bug.cgi?id=15816
+
+        Reviewed by Chris Fleizach.
+
+        * fast/forms/listbox-non-contiguous-keyboard-selection-expected.txt: Added.
+        * fast/forms/listbox-non-contiguous-keyboard-selection.html: Added.
+        * platform/mac/TestExpectations:
+        Multiple non contiguous selection with keyboard not enabled on Mac
+
 2014-01-09  Seokju Kwon  <seokju@webkit.org>
 
         Web Inspector: Remove unused overriding protocols.
diff --git a/LayoutTests/fast/forms/listbox-non-contiguous-keyboard-selection-expected.txt b/LayoutTests/fast/forms/listbox-non-contiguous-keyboard-selection-expected.txt
new file mode 100644 (file)
index 0000000..e7964a8
--- /dev/null
@@ -0,0 +1,11 @@
+<select> selection test for multiple but non contiguous selection with keyboard.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+1) Select multiple non-adjacent items with the keyboard
+PASS selectionPattern("sl1") is "01010"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/listbox-non-contiguous-keyboard-selection.html b/LayoutTests/fast/forms/listbox-non-contiguous-keyboard-selection.html
new file mode 100644 (file)
index 0000000..66a80e2
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description('&lt;select&gt; selection test for multiple but non contiguous selection with keyboard.');
+
+function keyDownOnSelect(selId, identifier, modifier) {
+    document.getElementById(selId).focus();
+    if (window.eventSender)
+        eventSender.keyDown(identifier, [modifier]);
+}
+
+function createSelect(idName, sz, mlt, selIndex) {
+    var sl = document.createElement("select");
+    var i = 0;
+    sl.size = sz;
+    while (i < sz) {
+        var opt = document.createElement("option");
+        if (i == selIndex)
+            opt.selected = true;
+        opt.textContent = "item " + i;
+        sl.appendChild(opt);
+        i++;
+    }
+    sl.multiple = mlt;
+    sl.id = idName;
+    var parent = document.getElementById("parent");
+    parent.appendChild(sl);
+}
+
+function selectionPattern(selId) {
+    var sl = document.getElementById(selId);
+    var result = '';
+    for (var i = 0; i < sl.options.length; i++)
+        result += sl.options[i].selected ? '1' : '0';
+    return result;
+}
+
+var parent = document.createElement('div');
+parent.id = "parent";
+document.body.appendChild(parent);
+
+createSelect("sl1", 5, true, -1);
+
+debug("1) Select multiple non-adjacent items with the keyboard");
+// Move to second item.
+keyDownOnSelect("sl1", "downArrow", "addSelectionKey");
+keyDownOnSelect("sl1", "downArrow", "addSelectionKey");
+// Select it.
+keyDownOnSelect("sl1", " ");
+// Move to fourth item.
+keyDownOnSelect("sl1", "downArrow", "addSelectionKey");
+keyDownOnSelect("sl1", "downArrow", "addSelectionKey");
+// Select it.
+keyDownOnSelect("sl1", " ");
+shouldBe('selectionPattern("sl1")', '"01010"');
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 00961ec..e2c156b 100644 (file)
@@ -565,6 +565,9 @@ webkit.org/b/92352 css3/flexbox/flex-rounding.html
 fast/events/show-modal-dialog-onblur-onfocus.html
 platform/mac/fast/forms/listbox-scrollbar-hit-test.html
 
+# Multiple non contiguous selection with keyboard not enabled on mac
+webkit.org/b/15816 fast/forms/listbox-non-contiguous-keyboard-selection.html [ Skip ]
+
 # <rdar://problem/11224894> Several Japanese vertical text tests failing on Mountain Lion
 fast/dynamic/text-combine.html
 fast/repaint/japanese-rl-selection-clear.html
index 23b6a9e..b8b15ec 100644 (file)
@@ -1,3 +1,23 @@
+2014-01-09  Pascal Jacquemart  <p.jacquemart@samsung.com>
+
+        Cannot select multiple non-adjacent items in a multiple select control with the keyboard only
+        https://bugs.webkit.org/show_bug.cgi?id=15816
+
+        Reviewed by Chris Fleizach.
+
+        Test: fast/forms/listbox-non-contiguous-keyboard-selection.html
+
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::HTMLSelectElement):
+        New member m_allowsNonContiguousSelection defaults to false
+        (WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
+        Tracking CTRL modifier to start multiple non contiguous selection
+        * html/HTMLSelectElement.h: New member m_allowsNonContiguousSelection
+        (WebCore::HTMLSelectElement::allowsNonContiguousSelection): New getter
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::addFocusRingRects):
+        Following implementation made for spatial navigation
+
 2014-01-09  Seokju Kwon  <seokju@webkit.org>
 
         Web Inspector: Remove unused overriding protocols.
index eb6c305..db5f53e 100644 (file)
@@ -74,6 +74,7 @@ HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document& doc
     , m_isProcessingUserDrivenChange(false)
     , m_multiple(false)
     , m_activeSelectionState(false)
+    , m_allowsNonContiguousSelection(false)
     , m_shouldRecalcListItems(false)
 {
     ASSERT(hasTagName(selectTag));
@@ -1457,7 +1458,13 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
             ASSERT_UNUSED(listItems, !listItems.size() || static_cast<size_t>(endIndex) < listItems.size());
             setActiveSelectionEndIndex(endIndex);
 
-            bool selectNewItem = !m_multiple || static_cast<KeyboardEvent*>(event)->shiftKey() || !isSpatialNavigationEnabled(document().frame());
+#if PLATFORM(MAC)
+            m_allowsNonContiguousSelection = m_multiple && isSpatialNavigationEnabled(document().frame());
+#else
+            m_allowsNonContiguousSelection = m_multiple && (isSpatialNavigationEnabled(document().frame()) || static_cast<KeyboardEvent*>(event)->ctrlKey());
+#endif
+            bool selectNewItem = static_cast<KeyboardEvent*>(event)->shiftKey() || !m_allowsNonContiguousSelection;
+
             if (selectNewItem)
                 m_activeSelectionState = true;
             // If the anchor is unitialized, or if we're going to deselect all
@@ -1487,7 +1494,7 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
             if (form())
                 form()->submitImplicitly(event, false);
             event->setDefaultHandled();
-        } else if (m_multiple && keyCode == ' ' && isSpatialNavigationEnabled(document().frame())) {
+        } else if (m_multiple && keyCode == ' ' && m_allowsNonContiguousSelection) {
             // Use space to toggle selection change.
             m_activeSelectionState = !m_activeSelectionState;
             ASSERT(m_activeSelectionEndIndex >= 0
index f55de79..22149ce 100644 (file)
@@ -111,6 +111,7 @@ public:
     
     // For use in the implementation of HTMLOptionElement.
     void optionSelectionStateChanged(HTMLOptionElement*, bool optionIsSelected);
+    bool allowsNonContiguousSelection() const { return m_allowsNonContiguousSelection; };
 
 protected:
     HTMLSelectElement(const QualifiedName&, Document&, HTMLFormElement*);
@@ -208,6 +209,7 @@ private:
     bool m_isProcessingUserDrivenChange;
     bool m_multiple;
     bool m_activeSelectionState;
+    bool m_allowsNonContiguousSelection;
     mutable bool m_shouldRecalcListItems;
 };
 
index 85b0058..ae8c936 100644 (file)
@@ -319,7 +319,7 @@ void RenderListBox::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOf
 
 void RenderListBox::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer)
 {
-    if (!isSpatialNavigationEnabled(&frame()))
+    if (!selectElement().allowsNonContiguousSelection())
         return RenderBlockFlow::addFocusRingRects(rects, additionalOffset, paintContainer);
 
     // Focus the last selected item.