Bug 13093 - Don't change cursor when mouseover links during selection r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D175055
This commit is contained in:
Sean Feng 2023-04-13 11:45:57 +00:00
Родитель e7b8ab5258
Коммит 7e1f58e993
4 изменённых файлов: 37 добавлений и 11 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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();

Просмотреть файл

@ -150,6 +150,21 @@ static inline int32_t RoundDown(double aDouble) {
: static_cast<int32_t>(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<WidgetMouseEvent> 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;