Skip to content

Commit

Permalink
Bug 1761408 - Ensure Windows cursor is up-to-date from nsWindow::SetC…
Browse files Browse the repository at this point in the history
…ursor(). r=mhowell

Also add better docs as to why we're doing what we're doing.

Also, avoid calling LoadCursor for built-in cursors over and over in chrome
pages.

Differential Revision: https://phabricator.services.mozilla.com/D142067
  • Loading branch information
emilio committed Mar 25, 2022
1 parent 283bdce commit 7fc2a16
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3245,26 +3245,34 @@ static HCURSOR CursorForImage(const nsIWidget::Cursor& aCursor,
return cursor;
}

// Setting the actual cursor
void nsWindow::SetCursor(const Cursor& aCursor) {
static HCURSOR sCustomHCursor = nullptr;
static HCURSOR sCurrentHCursor = nullptr;
static bool sCurrentHCursorIsCustom = false;

mCursor = aCursor;

if (!mUpdateCursor && sCurrentCursor == aCursor) {
if (sCurrentCursor == aCursor && sCurrentHCursor && !mUpdateCursor) {
// Cursors in windows are global, so even if our mUpdateCursor flag is
// false we always need to make sure the Windows cursor is up-to-date,
// since stuff like native drag and drop / resizers code can mutate it
// outside of this method.
::SetCursor(sCurrentHCursor);
return;
}

mUpdateCursor = false;
if (sCustomHCursor) {
::DestroyIcon(sCustomHCursor);
sCustomHCursor = nullptr;
}

if (sCurrentHCursorIsCustom) {
::DestroyIcon(sCurrentHCursor);
}
sCurrentHCursor = nullptr;
sCurrentHCursorIsCustom = false;
sCurrentCursor = aCursor;

HCURSOR cursor = CursorForImage(aCursor, GetDefaultScale());
bool custom = false;
if (cursor) {
sCustomHCursor = cursor;
custom = true;
} else {
cursor = CursorFor(aCursor.mDefaultCursor);
}
Expand All @@ -3273,6 +3281,8 @@ void nsWindow::SetCursor(const Cursor& aCursor) {
return;
}

sCurrentHCursor = cursor;
sCurrentHCursorIsCustom = custom;
::SetCursor(cursor);
}

Expand Down

0 comments on commit 7fc2a16

Please sign in to comment.