From 7e1f58e993f362d5d16bd1230a4417ebb2aa07b3 Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Thu, 13 Apr 2023 11:45:57 +0000 Subject: [PATCH] Bug 13093 - Don't change cursor when mouseover links during selection r=emilio Differential Revision: https://phabricator.services.mozilla.com/D175055 --- dom/base/nsContentAreaDragDrop.cpp | 12 +----------- dom/base/nsContentUtils.cpp | 10 ++++++++++ dom/base/nsContentUtils.h | 6 ++++++ dom/events/EventStateManager.cpp | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/dom/base/nsContentAreaDragDrop.cpp b/dom/base/nsContentAreaDragDrop.cpp index 00d8e47b4ca4..f99fd447f37c 100644 --- a/dom/base/nsContentAreaDragDrop.cpp +++ b/dom/base/nsContentAreaDragDrop.cpp @@ -332,16 +332,6 @@ static nsIContent* FindDragTarget(nsIContent* aContent) { return nullptr; } -static nsIContent* FindParentLinkNode(nsIContent* aContent) { - for (nsIContent* content = aContent; content; - content = content->GetFlattenedTreeParent()) { - if (nsContentUtils::IsDraggableLink(content)) { - return content; - } - } - return nullptr; -} - // // GetAnchorURL // @@ -548,7 +538,7 @@ nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag, // // if the alt key is down, don't start a drag if we're in an // anchor because we want to do selection. - parentLink = FindParentLinkNode(draggedNode); + parentLink = nsContentUtils::GetClosestLinkInFlatTree(draggedNode); if (parentLink && mIsAltKeyPressed) { *aCanDrag = false; return NS_OK; diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index e6d15e6fd55e..6ce3947e0999 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -10997,6 +10997,16 @@ void nsContentUtils::RequestGeckoTaskBurst() { } } +nsIContent* nsContentUtils::GetClosestLinkInFlatTree(nsIContent* aContent) { + for (nsIContent* content = aContent; content; + content = content->GetFlattenedTreeParent()) { + if (nsContentUtils::IsDraggableLink(content)) { + return content; + } + } + return nullptr; +} + namespace mozilla { std::ostream& operator<<(std::ostream& aOut, const PreventDefaultResult aPreventDefaultResult) { diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 6b517e2fb1a1..5e7cf91cf77f 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -3389,6 +3389,12 @@ class nsContentUtils { return sMayHaveFormRadioStateChangeListeners; } + /** + * Returns the closest link element in the flat tree of aContent if there's + * one, otherwise returns nullptr. + */ + static nsIContent* GetClosestLinkInFlatTree(nsIContent* aContent); + private: static bool InitializeEventTable(); diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index c43058a51370..1f6454f7dac5 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -150,6 +150,21 @@ static inline int32_t RoundDown(double aDouble) { : static_cast(ceil(aDouble)); } +static bool IsSelectingLink(nsIFrame* aTargetFrame) { + if (!aTargetFrame) { + return false; + } + const nsFrameSelection* frameSel = aTargetFrame->GetConstFrameSelection(); + if (!frameSel || !frameSel->GetDragState()) { + return false; + } + + if (!nsContentUtils::GetClosestLinkInFlatTree(aTargetFrame->GetContent())) { + return false; + } + return true; +} + static UniquePtr CreateMouseOrPointerWidgetEvent( WidgetMouseEvent* aMouseEvent, EventMessage aMessage, EventTarget* aRelatedTarget); @@ -4224,6 +4239,11 @@ void EventStateManager::UpdateCursor(nsPresContext* aPresContext, } if (aTargetFrame) { + if (cursor == StyleCursorKind::Pointer && IsSelectingLink(aTargetFrame)) { + cursor = aTargetFrame->GetWritingMode().IsVertical() + ? StyleCursorKind::VerticalText + : StyleCursorKind::Text; + } SetCursor(cursor, container, resolution, hotspot, aTargetFrame->GetNearestWidget(), false); gLastCursorSourceFrame = aTargetFrame;