Skip to content
Permalink
Browse files
Incorrect behavior of "cursor: auto" over links
https://bugs.webkit.org/show_bug.cgi?id=173909
rdar://33054544

Reviewed by Simon Fraser.

* LayoutTests/imported/w3c/web-platform-tests/html/rendering/the-css-user-agent-style-sheet-and-presentational-hints/mouse-cursor-imagemap-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/the-css-user-agent-style-sheet-and-presentational-hints/no-help-cursor-on-links.historical-expected.txt:
* Source/WebCore/css/html.css:
hand cursor (pointer) should not be rendered through 'auto' behavior of agent.
(a:any-link):
(a:any-link:read-write):
(area:any-link):
* Source/WebCore/page/EventHandler.cpp:
Removing hand cursor calculation from 'auto' case. Auto should just result in default or text cursors.
We are now using computedStyle instead of renderer->style() because we still need to access style
for elements without a renderer, like <area>.
(WebCore::EventHandler::updateCursor):
(WebCore::EventHandler::selectCursor):
(WebCore::EventHandler::handleMouseMoveEvent):
* Source/WebCore/page/EventHandler.h:
Since we don't handle hand cursor anymore on selectCursor, selectCursor and updateCursor
no longer need to receive shiftKey.

Canonical link: https://commits.webkit.org/253685@main
  • Loading branch information
vitorroriz authored and nt1m committed Aug 23, 2022
1 parent a98a145 commit 3a4722baf0484b65517d8045fbdfe82d03052149
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
@@ -2,5 +2,5 @@
An unclickable (non-link) area should not show the link cursor when hovered.


FAIL Only clickable areas should show the link cursor. assert_equals: expected "pointer" but got "auto"
PASS Only clickable areas should show the link cursor.

@@ -1,4 +1,4 @@

FAIL Unvisited help links must have pointer cursor, not help cursor assert_equals: expected "pointer" but got "auto"
FAIL Visited help links must have pointer cursor, not help cursor assert_equals: expected "pointer" but got "auto"
PASS Unvisited help links must have pointer cursor, not help cursor
PASS Visited help links must have pointer cursor, not help cursor
unvisited will be visited
@@ -1290,13 +1290,21 @@ input[type="file"]:focus::file-selector-button {
a:any-link {
color: -webkit-link;
text-decoration: underline;
cursor: auto;
cursor: pointer;
}

a:any-link:active {
color: -webkit-activelink;
}

a:any-link:read-write {
cursor: text;
}

area:any-link {
cursor: pointer;
}

/* HTML5 ruby elements */

ruby, rt {
@@ -1420,18 +1420,18 @@ void EventHandler::updateCursor()
HitTestResult result(view->windowToContents(*m_lastKnownMousePosition));
document->hitTest(hitType, result);

updateCursor(*view, result, shiftKey);
updateCursor(*view, result);
}

void EventHandler::updateCursor(FrameView& view, const HitTestResult& result, bool shiftKey)
void EventHandler::updateCursor(FrameView& view, const HitTestResult& result)
{
if (auto optionalCursor = selectCursor(result, shiftKey)) {
if (auto optionalCursor = selectCursor(result)) {
m_currentMouseCursor = WTFMove(optionalCursor.value());
view.setCursor(m_currentMouseCursor);
}
}

std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bool shiftKey)
std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result)
{
if (m_resizeLayer && m_resizeLayer->inResizeMode())
return std::nullopt;
@@ -1458,8 +1458,8 @@ std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bo
if (!node)
return std::nullopt;

auto renderer = node->renderer();
auto* style = renderer ? &renderer->style() : nullptr;
// We are using the node's computed style instead of renderer()->style because we need style info for nodes without a renderer, e.g.: <area>
auto* style = node->computedStyle();
bool horizontalText = !style || style->isHorizontalWritingMode();
const Cursor& iBeam = horizontalText ? iBeamCursor() : verticalTextCursor();

@@ -1470,6 +1470,7 @@ std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bo
cancelAutoHideCursorTimer();
#endif

auto* renderer = node->renderer();
if (renderer) {
Cursor overrideCursor;
switch (renderer->getCursor(roundedIntPoint(result.localPoint()), overrideCursor)) {
@@ -1537,9 +1538,6 @@ std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bo

bool editable = node->hasEditableStyle();

if (useHandCursor(node.get(), result.isOverLink(), shiftKey))
return handCursor();

bool inResizer = false;
if (renderer && renderer->hasLayer()) {
// FIXME: With right-aligned text in a box, the renderer here is usually a RenderText, which prevents showing the resize cursor: webkit.org/b/210935.
@@ -2044,7 +2042,7 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& platformMouseE

if (!newSubframe || mouseEvent.scrollbar()) {
if (RefPtr view = m_frame.view())
updateCursor(*view, mouseEvent.hitTestResult(), platformMouseEvent.shiftKey());
updateCursor(*view, mouseEvent.hitTestResult());
}

m_lastMouseMoveEventSubframe = newSubframe;
@@ -343,7 +343,7 @@ class EventHandler {
WEBCORE_EXPORT void cancelSelectionAutoscroll();
#endif

WEBCORE_EXPORT std::optional<Cursor> selectCursor(const HitTestResult&, bool shiftKey);
WEBCORE_EXPORT std::optional<Cursor> selectCursor(const HitTestResult&);

#if ENABLE(KINETIC_SCROLLING)
std::optional<WheelScrollGestureState> wheelScrollGestureState() const { return m_wheelScrollGestureState; }
@@ -403,7 +403,7 @@ class EventHandler {

bool internalKeyEvent(const PlatformKeyboardEvent&);

void updateCursor(FrameView&, const HitTestResult&, bool shiftKey);
void updateCursor(FrameView&, const HitTestResult&);

void hoverTimerFired();

@@ -3245,7 +3245,7 @@ static void populateCaretContext(const HitTestResult& hitTestResult, const Inter

auto hitTestResult = eventHandler.hitTestResultAtPoint(request.point, hitTestRequestTypes);
if (auto* hitFrame = hitTestResult.innerNodeFrame()) {
info.cursor = hitFrame->eventHandler().selectCursor(hitTestResult, false);
info.cursor = hitFrame->eventHandler().selectCursor(hitTestResult);
if (request.includeCaretContext)
populateCaretContext(hitTestResult, request, info);
}

0 comments on commit 3a4722b

Please sign in to comment.