LadybirdBrowser / ladybird

Truly independent web browser
https://ladybird.org
BSD 2-Clause "Simplified" License
19.66k stars 802 forks source link

Read-only input/textarea element does not allow text selection #579

Open simonkrauter opened 2 months ago

simonkrauter commented 2 months ago

Ladybird currently does not support to select (and copy) text in the elements <input readonly> and <textarea readonly>.

In Chrome/Firefox this is possible.

Test page:

<!DOCTYPE html>
<html>
<body>
<input type="text" value="Select and copy this!" readonly style="width: 350px;"></input><br>
<textarea readonly style="width: 350px; height: 150px;">
This text is read-only.

But the user should still be able

to select and copy parts of it.
</textarea><br>
Regular text<br>
<button>Button</button>
tcl3 commented 2 months ago

I believe the code responsible for this behavior is here:

https://github.com/LadybirdBrowser/ladybird/blob/da8633b2d0ab3b9d8f1cdad39a8ad85ca2accf03/Userland/Libraries/LibWeb/Page/EventHandler.cpp#L433-L435

Replacing this with if (true) makes selection on readonly inputs work.

To be honest, I'm not sure what the exact intention of this line is or what the behavior is supposed to be.

simonkrauter commented 2 months ago

@tcl3 I've already started to work on this place. The read-only case is simple, just allow selection in any case (like what you wrote with if (true). Note: Buttons and placeholders should continue to not allow selection, which needs some extra code. Then in future we could forbid the selection according to the CSS property user-select (which I don't like).

trflynn89 commented 3 weeks ago

Re-opening as we reverted the fix in #1195. It broke web features (e.g. typing into the search field on google.com, and comment boxes on github.com).