range slider drag fails after box-selecting across the slider

#40796813 Area: Blink>Forms / drag + selection P3 CL 8625727 In Review

TL;DR

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()).

The change

// 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.

What changes, what does not

casebeforeafter
box selection over the slider, drag the thumbvalue stuck at 71, selection drag firesvalue 98, no selection drag
box selection over the slider, drag from the trackvalue stuck at 71value 98
no selection, drag the thumbvalue 98value 98
selection elsewhere, press the thumbselection keptselection kept

Why the last row matters

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.

Samples

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.

1. box selection, then drag the thumb -- the bug

Drag a selection box over the slider, release, then drag the thumb.
Expected: Patched build: the thumb follows the mouse, value 98.
Patched build: the thumb follows the mouse, value 98.
Diff mask
3194 px differ -- the thumb position and the readout.
content_shell: before / after
Before
beforeunpatched: value stuck at 71, selection drag fired
After
afterpatched: value 98, no selection drag

2. box selection, then press the track -- same bug

Same selection, but the press lands on the track left of the thumb.
Expected: Patched build: the track press drags to value 98.
Patched build: the track press drags to value 98.
Diff mask
3194 px differ -- the thumb position and the readout.
content_shell: before / after
Before
beforeunpatched: value stuck at 71
After
afterpatched: value 98

3. no selection -- unchanged

Control case: dragging the thumb always worked here.
Expected: Patched build: value 98, same as before.
Patched build: value 98, same as before.
Diff mask
0 px differ -- nothing differs.
content_shell: before / after
Before
beforeunpatched: value 98
After
afterpatched: value 98

4. selection elsewhere -- must not be cleared

The paragraph below the slider is selected, then the thumb is pressed and released without moving.
Expected: Patched build: the selection survives the press.
Patched build: the selection survives the press.
Diff mask
0 px differ -- nothing differs -- this is what the narrowed condition buys.
content_shell: before / after
Before
beforeunpatched: selection kept
After
afterpatched: selection kept

Verification

Web tests (debug build, local)

Screenshots

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

Open question for review

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.

Links

Issue 40796813 CL 8625727 standalone sampler.html capture_screenshots.py