Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Select with multiple enabled does not consistently fire OnChange
https://bugs.webkit.org/show_bug.cgi?id=257565

Reviewed by Ryosuke Niwa.

This patch aligns WebKit with Blink / Chromium and Gecko / Firefox.

Partial Merge: https://src.chromium.org/viewvc/blink?view=revision&revision=164563

This patch adds logic for the case, when the listbox is scrollable to
fire 'onChange' event when the selection is dropped outside of 'listbox'.

* Source/WebCore/page/AutoscrollController.cpp:
(AutoscrollController::startAutoscrollForSelection): As above
* LayoutTests/fast/forms/select/multiselect-in-listbox-mouse-release-outside.html: Add Test Case
* LayoutTests/fast/forms/select/multiselect-in-listbox-mouse-release-outside-expected.txt: Add Test Case Expectation
* LayoutTests/platform/ios/TestExpectations: 'iOS' exception due to lack of 'listbox' appearance

Canonical link: https://commits.webkit.org/264873@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Jun 5, 2023
1 parent e25dc49 commit 066cf30
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
@@ -0,0 +1,9 @@
should dispatch change event when mouse is released outside.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<body>
<script src="../../../resources/js-test.js"></script>
<select id="listBoxSelect" size="5" multiple="multiple">
<option value="option 1">Option 1</option>
<option value="option 2">Option 2</option>
<option value="option 3">Option 3</option>
<option value="option 4">Option 4</option>
<option value="option 5">Option 5</option>
</select>
<script>
description('should dispatch change event when mouse is released outside.');
jsTestIsAsync = true;
var select = document.getElementById('listBoxSelect');
select.onchange = function() {
testPassed('A change event was dispatched.');
}

window.onload = function()
{
if (!window.eventSender)
debug('Select listbox using mouse and release the mouse pointer outside the listbox. The test passes if "A change event was dispatched." is printed.');
else {
var x = select.offsetLeft + 7;
var y = select.offsetTop + 7;
eventSender.dragMode = false;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseMoveTo(x, y + 20);
eventSender.mouseMoveTo(x, y + 600);
eventSender.mouseUp();
setTimeout(HorizontalTest, 100);
}
}
function HorizontalTest()
{
var x = select.offsetLeft + 7;
var y = select.offsetTop + 7;
eventSender.dragMode = false;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseMoveTo(x + 20, y);
eventSender.mouseMoveTo(x + 600, y);
eventSender.mouseUp();
finishJSTest();
}
</script>
</body>
</html>
1 change: 1 addition & 0 deletions LayoutTests/platform/ios/TestExpectations
Expand Up @@ -3937,6 +3937,7 @@ imported/w3c/web-platform-tests/css/css-writing-modes/forms/color-input-appearan
# <select> are always menulists on iOS, regardless of multiple/size attributes, these tests assume the listbox appearance that desktop platforms have.
imported/w3c/web-platform-tests/css/css-writing-modes/forms/select-multiple-scrolling.optional.html [ Failure ]
imported/w3c/web-platform-tests/css/css-writing-modes/forms/select-size-scrolling-and-sizing.optional.html [ Failure ]
fast/forms/select/multiselect-in-listbox-mouse-release-outside.html [ Skip ]

# To investigate: might need to relax the tests, or adapt native thumb appearance.
imported/w3c/web-platform-tests/css/css-writing-modes/forms/range-input-vertical-ltr-painting.html [ ImageOnlyFailure ]
Expand Down
6 changes: 5 additions & 1 deletion Source/WebCore/page/AutoscrollController.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2006-2023 Apple Inc. All rights reserved.
* Copyright (C) 2014 Google Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
* Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
*
Expand Down Expand Up @@ -34,6 +35,7 @@
#include "LocalFrameView.h"
#include "Page.h"
#include "RenderBox.h"
#include "RenderListBox.h"
#include "RenderView.h"
#include "ScrollView.h"
#include "Settings.h"
Expand Down Expand Up @@ -75,6 +77,8 @@ void AutoscrollController::startAutoscrollForSelection(RenderObject* renderer)
if (m_autoscrollTimer.isActive())
return;
auto* scrollable = RenderBox::findAutoscrollable(renderer);
if (!scrollable)
scrollable = renderer->isListBox() ? downcast<RenderListBox>(renderer) : nullptr;
if (!scrollable)
return;
m_autoscrollType = AutoscrollForSelection;
Expand Down

0 comments on commit 066cf30

Please sign in to comment.