Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Selection should not set the cursor type to text over the explicitly …
…set cursor type

https://bugs.webkit.org/show_bug.cgi?id=258622

Reviewed by Ryosuke Niwa.

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

Merge: https://chromium.googlesource.com/chromium/blink/+/a5c471c481544403615780bce2845de58e37e341

When tried to select some text in an area that has style
cursor:default set, cursor type changes to text cursor ignoring
the cursor style that is explicitly set.

When the cursor style is explicitly set as default(or something else),
we should not change it to text cursor no matter what we are over
or what operation we are performing (be it hovering over the text
or selecting the text).

We change the cursor type to text during selection. But if there is
an explicit cursor style set then this explicitly set cursor style
should be given priority over the text style cursor during selection.

Currently if the area on which cursor:default is set is contenteditable,
in this particular case we do not change the cursor style to text on
selection. This should be the behavior irrespective of editability.

* Source/WebCore/page/EventHandler.cpp:
(EventHandler::selectCursor): As per commit message
* LayoutTests/editing/caret/caret-type-for-user-select-none.html: Add Test Case
* LayoutTests/editing/caret/caret-type-for-user-select-none-expected.txt: Add Test Case Expectation
* LayoutTests/platform/ios/TestExpectations: Add Platform Specific Expectation to Skip on iOS due to test leveraging 'eventSender' mousedown and mouseMoveTo.

Canonical link: https://commits.webkit.org/265597@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Jun 28, 2023
1 parent 687a6e6 commit 1504201
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
@@ -0,0 +1,11 @@
Tests whether explicitly set caret style is retained on performing text selection

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


Try selecting this text by dragging the cursor. Progress cursor should be displayed while doing so.
PASS currentCursorType is "Progress"
PASS successfullyParsed is true

TEST COMPLETE

29 changes: 29 additions & 0 deletions LayoutTests/editing/caret/caret-type-for-user-select-none.html
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<body>
<p id="description"></p>
<div style="cursor:progress; border: 2px solid red;" id="test">Try selecting this text by dragging the cursor. Progress cursor should be displayed while doing so.</div>
<div id="console"></div>
<script src="../../resources/js-test.js"></script>
<script>
if (window.eventSender && window.internals) {
description('Tests whether explicitly set caret style is retained on performing text selection');
var div = document.getElementById("test");
div.focus();
var y = div.offsetTop + div.offsetHeight / 2;
function leapForwardAndMove(x) {
eventSender.leapForward(200);
eventSender.mouseMoveTo(div.offsetLeft + x, y);
}
eventSender.dragMode = false;
leapForwardAndMove(div.offsetLeft + 5, y);
eventSender.mouseDown();
leapForwardAndMove(10);
leapForwardAndMove(div.offsetWidth - 10);
var cursorInfo = window.internals.getCurrentCursorInfo(document);
var currentCursorType = cursorInfo.substring(cursorInfo.indexOf('=') + 1, cursorInfo.lastIndexOf(' '));
shouldBeEqualToString('currentCursorType', 'Progress');
}
</script>
</body>
</html>
1 change: 1 addition & 0 deletions LayoutTests/platform/ios/TestExpectations
Expand Up @@ -1081,6 +1081,7 @@ imported/w3c/web-platform-tests/shadow-dom/accesskey.tentative.html [ Skip ]

# Tests that use EventSender's mouseMoveTo, mouseUp and mouseDown
css3/viewport-percentage-lengths/vh-resize.html [ Skip ]
editing/caret/caret-type-for-user-select-none.html [ Skip ]
editing/pasteboard/can-read-in-dragstart-event.html [ Skip ]
editing/pasteboard/cleanup-on-move.html [ Skip ]
editing/pasteboard/copy-crash.html [ Skip ]
Expand Down
22 changes: 11 additions & 11 deletions Source/WebCore/page/EventHandler.cpp
Expand Up @@ -1552,17 +1552,6 @@ std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bo
}
}

// During selection, use an I-beam regardless of the content beneath the cursor.
// If a drag may be starting or we're capturing mouse events for a particular node, don't treat this as a selection.
if (m_mousePressed
&& mouseDownMayStartSelect()
#if ENABLE(DRAG_SUPPORT)
&& !m_mouseDownMayStartDrag
#endif
&& m_frame.selection().isCaretOrRange()
&& !m_capturingMouseEventsElement)
return iBeam;

switch (style ? style->cursor() : CursorType::Auto) {
case CursorType::Auto: {
if (ImageOverlay::isOverlayText(node.get())) {
Expand All @@ -1585,6 +1574,17 @@ std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bo
return layerRenderer.shouldPlaceVerticalScrollbarOnLeft() ? southWestResizeCursor() : southEastResizeCursor();
}

// During selection, use an I-beam regardless of the content beneath the cursor.
// If a drag may be starting or we're capturing mouse events for a particular node, don't treat this as a selection.
if (m_mousePressed
&& mouseDownMayStartSelect()
#if ENABLE(DRAG_SUPPORT)
&& !m_mouseDownMayStartDrag
#endif
&& m_frame.selection().isCaretOrRange()
&& !m_capturingMouseEventsElement)
return iBeam;

if ((editable || (renderer && renderer->isText() && node->canStartSelection())) && !inResizer && !result.scrollbar())
return iBeam;
return pointerCursor();
Expand Down

0 comments on commit 1504201

Please sign in to comment.