Skip to content

Commit

Permalink
Cherry-pick 2ef8bf0. rdar://problem/99937243
Browse files Browse the repository at this point in the history
    Revert [253685@main] Incorrect behavior of "cursor: auto" over links
    https://bugs.webkit.org/show_bug.cgi?id=173909
    rdar://33054544

    Reviewed by Tim Nguyen.

    * 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:
    (a:any-link):
    (a:any-link:read-write): Deleted.
    (area:any-link): Deleted.
    * Source/WebCore/page/EventHandler.cpp:
    (WebCore::EventHandler::updateCursor):
    (WebCore::EventHandler::selectCursor):
    (WebCore::EventHandler::handleMouseMoveEvent):
    * Source/WebCore/page/EventHandler.h:
    * Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
    (WebKit::WebPage::positionInformation):

    Canonical link: https://commits.webkit.org/254480@main

Canonical link: https://commits.webkit.org/254351.3@safari-7615.1.6-branch
  • Loading branch information
vitorroriz authored and rjepstein committed Sep 14, 2022
1 parent 387758d commit 9585e39
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
Expand Up @@ -2,5 +2,5 @@
An unclickable (non-link) area should not show the link cursor when hovered.


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

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

PASS Unvisited help links must have pointer cursor, not help cursor
PASS Visited help links must have pointer cursor, not help cursor
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"
unvisited will be visited
10 changes: 1 addition & 9 deletions Source/WebCore/css/html.css
Expand Up @@ -1290,21 +1290,13 @@ input[type="file"]:focus::file-selector-button {
a:any-link {
color: -webkit-link;
text-decoration: underline;
cursor: pointer;
cursor: auto;
}

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

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

area:any-link {
cursor: pointer;
}

/* HTML5 ruby elements */

ruby, rt {
Expand Down
18 changes: 10 additions & 8 deletions Source/WebCore/page/EventHandler.cpp
Expand Up @@ -1420,18 +1420,18 @@ void EventHandler::updateCursor()
HitTestResult result(view->windowToContents(*m_lastKnownMousePosition));
document->hitTest(hitType, result);

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

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

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

// 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();
auto renderer = node->renderer();
auto* style = renderer ? &renderer->style() : nullptr;
bool horizontalText = !style || style->isHorizontalWritingMode();
const Cursor& iBeam = horizontalText ? iBeamCursor() : verticalTextCursor();

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

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

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.
Expand Down Expand Up @@ -2042,7 +2044,7 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& platformMouseE

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

m_lastMouseMoveEventSubframe = newSubframe;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/EventHandler.h
Expand Up @@ -343,7 +343,7 @@ class EventHandler {
WEBCORE_EXPORT void cancelSelectionAutoscroll();
#endif

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

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

bool internalKeyEvent(const PlatformKeyboardEvent&);

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

void hoverTimerFired();

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Expand Up @@ -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);
info.cursor = hitFrame->eventHandler().selectCursor(hitTestResult, false);
if (request.includeCaretContext)
populateCaretContext(hitTestResult, request, info);
}
Expand Down

0 comments on commit 9585e39

Please sign in to comment.