Drag a selection box across a page so it covers an
<input type="range">, release, then drag the slider. The
thumb does not follow the mouse and the cursor turns into
not-allowed. Firefox is fine.
The press sits inside the document selection, so
DragController::DraggableNode() reports
kDragSourceActionSelection and Blink arms a selection drag
(immediate on non-Mac, kTextDragDelay is 0). That drag eats the
slider drag. The reporter's own workaround -- calling
removeAllRanges() on mousedown -- confirms the mechanism.
The fix clears the selection in
SliderThumbElement::StartDragging(), but only when the
selection actually covers the input. Both entry points go through
StartDragging(): the thumb press
(SliderThumbElement::DefaultEventHandler) and the track press
(RangeInputType::HandleMouseDownEvent ->
DragFrom()).
// third_party/blink/renderer/core/html/forms/slider_thumb_element.cc
bool SelectionOverlapsNode(const FrameSelection& selection, const Node& node) {
const SelectionInDomTree& dom_selection = selection.GetSelectionInDomTree();
if (!dom_selection.IsRange()) {
return false;
}
return dom_selection.ComputeStartPosition() <= Position::AfterNode(node) &&
Position::BeforeNode(node) <= dom_selection.ComputeEndPosition();
}
void SliderThumbElement::StartDragging() {
if (LocalFrame* frame = GetDocument().GetFrame()) {
// A press inside the selection arms a selection drag, which would
// swallow the slider drag.
const HTMLInputElement* input = HostInput();
if (input && SelectionOverlapsNode(frame->Selection(), *input)) {
frame->Selection().Clear();
}
...
2 files: the fix plus one WPT,
html/semantics/forms/the-input-element/range-drag-after-selection.html,
with a thumb-drag and a track-drag case. It uses the testdriver Actions API
(same pattern as the existing selection-pointer.html), so it
runs in other engines too -- Firefox passes it today, Chrome and Edge do
not.
| case | before | after |
|---|---|---|
| box selection over the slider, drag the thumb | value stuck at 71, selection drag fires | value 98, no selection drag |
| box selection over the slider, drag from the track | value stuck at 71 | value 98 |
| no selection, drag the thumb | value 98 | value 98 |
| selection elsewhere, press the thumb | selection kept | selection kept |
The first version of this fix cleared the selection unconditionally on mousedown. That also wiped selections that have nothing to do with the slider -- visible as a 3447 px diff in case 4 -- so the condition was narrowed to selections that overlap the input.
Rendered runs live in your browser: drag a box across the
slider, release, then drag the slider -- stock Chrome reproduces cases 1 and
2. Expected and Diff are
content_shell captures (patched build) and the pixel mask
between the unpatched and patched binaries.
fast/forms/range/ tests pass.fast/forms/ + editing/selection/: 3170 tests,
all as expected (the one crash,
fast/forms/label/labelable-elements.html, is an unrelated
frame-name DCHECK that passes when run alone).There is no runtime flag here, so "before" is an unpatched
content_shell (out/dist) and "after" is the patched
one; mouse drags are synthesized over the DevTools protocol.
xvfb-run -a python3 capture_screenshots.py
The clear sits in SliderThumbElement::StartDragging() so both
the thumb and the track press are covered. The alternative is to teach
DragController::DraggableNode() that a press on a slider control
never starts a selection drag, which would also cover other UA controls that
take drags. Happy to move it if that is the preferred layer.