Bug 1560081 - Convert CSS pixels to device pixels in CursorForImage. r=jmathies

Differential Revision: https://phabricator.services.mozilla.com/D35325

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masatoshi Kimura 2019-06-20 20:00:24 +00:00
Родитель d91cc5fa28
Коммит f9e0ad7f00
6 изменённых файлов: 24 добавлений и 20 удалений

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

@ -100,7 +100,7 @@ TaskbarPreviewButton::SetImage(imgIContainer* img) {
if (img) {
nsresult rv;
rv = nsWindowGfx::CreateIcon(
img, false, 0, 0,
img, false, LayoutDeviceIntPoint(),
nsWindowGfx::GetIconMetrics(nsWindowGfx::kRegularIcon),
&Button().hIcon);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -88,8 +88,8 @@ TaskbarTabPreview::SetIcon(imgIContainer* icon) {
if (icon) {
nsresult rv;
rv = nsWindowGfx::CreateIcon(
icon, false, 0, 0, nsWindowGfx::GetIconMetrics(nsWindowGfx::kSmallIcon),
&hIcon);
icon, false, LayoutDeviceIntPoint(),
nsWindowGfx::GetIconMetrics(nsWindowGfx::kSmallIcon), &hIcon);
NS_ENSURE_SUCCESS(rv, rv);
}

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

@ -181,7 +181,7 @@ TaskbarWindowPreview::SetOverlayIcon(imgIContainer* aStatusIcon,
HICON hIcon = nullptr;
if (aStatusIcon) {
rv = nsWindowGfx::CreateIcon(
aStatusIcon, false, 0, 0,
aStatusIcon, false, LayoutDeviceIntPoint(),
nsWindowGfx::GetIconMetrics(nsWindowGfx::kSmallIcon), &hIcon);
NS_ENSURE_SUCCESS(rv, rv);
}

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

@ -2817,8 +2817,8 @@ static HCURSOR CursorFor(nsCursor aCursor) {
}
static HCURSOR CursorForImage(imgIContainer* aImageContainer,
uint32_t aHotspotX, uint32_t aHotspotY,
double aScale) {
CSSIntPoint aHotspot,
CSSToLayoutDeviceScale aScale) {
if (!aImageContainer) {
return nullptr;
}
@ -2839,10 +2839,11 @@ static HCURSOR CursorForImage(imgIContainer* aImageContainer,
return nullptr;
}
IntSize size = RoundedToInt(Size(width * aScale, height * aScale));
LayoutDeviceIntSize size = RoundedToInt(CSSIntSize(width, height) * aScale);
LayoutDeviceIntPoint hotspot = RoundedToInt(aHotspot * aScale);
HCURSOR cursor;
nsresult rv = nsWindowGfx::CreateIcon(aImageContainer, true, aHotspotX,
aHotspotY, size, &cursor);
nsresult rv =
nsWindowGfx::CreateIcon(aImageContainer, true, hotspot, size, &cursor);
if (NS_FAILED(rv)) {
return nullptr;
}
@ -2858,8 +2859,8 @@ void nsWindow::SetCursor(nsCursor aDefaultCursor, imgIContainer* aImageCursor,
return;
}
double scale = GetDefaultScale().scale;
HCURSOR cursor = CursorForImage(aImageCursor, aHotspotX, aHotspotY, scale);
HCURSOR cursor = CursorForImage(
aImageCursor, CSSIntPoint(aHotspotX, aHotspotY), GetDefaultScale());
if (cursor) {
mCursor = eCursorInvalid;
::SetCursor(cursor);

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

@ -418,7 +418,7 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) {
return result;
}
IntSize nsWindowGfx::GetIconMetrics(IconSizeType aSizeType) {
LayoutDeviceIntSize nsWindowGfx::GetIconMetrics(IconSizeType aSizeType) {
int32_t width = ::GetSystemMetrics(sIconMetrics[aSizeType].xMetric);
int32_t height = ::GetSystemMetrics(sIconMetrics[aSizeType].yMetric);
@ -426,12 +426,14 @@ IntSize nsWindowGfx::GetIconMetrics(IconSizeType aSizeType) {
width = height = sIconMetrics[aSizeType].defaultSize;
}
return IntSize(width, height);
return LayoutDeviceIntSize(width, height);
}
nsresult nsWindowGfx::CreateIcon(imgIContainer* aContainer, bool aIsCursor,
uint32_t aHotspotX, uint32_t aHotspotY,
IntSize aScaledSize, HICON* aIcon) {
LayoutDeviceIntPoint aHotspot,
LayoutDeviceIntSize aScaledSize,
HICON* aIcon) {
MOZ_ASSERT(aHotspot.x >= 0 && aHotspot.y >= 0);
MOZ_ASSERT((aScaledSize.width > 0 && aScaledSize.height > 0) ||
(aScaledSize.width == 0 && aScaledSize.height == 0));
@ -521,8 +523,8 @@ nsresult nsWindowGfx::CreateIcon(imgIContainer* aContainer, bool aIsCursor,
ICONINFO info = {0};
info.fIcon = !aIsCursor;
info.xHotspot = aHotspotX;
info.yHotspot = aHotspotY;
info.xHotspot = aHotspot.x;
info.yHotspot = aHotspot.y;
info.hbmMask = mbmp;
info.hbmColor = bmp;

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

@ -16,10 +16,11 @@
class nsWindowGfx {
public:
enum IconSizeType { kSmallIcon, kRegularIcon };
static mozilla::gfx::IntSize GetIconMetrics(IconSizeType aSizeType);
static mozilla::LayoutDeviceIntSize GetIconMetrics(IconSizeType aSizeType);
static nsresult CreateIcon(imgIContainer* aContainer, bool aIsCursor,
uint32_t aHotspotX, uint32_t aHotspotY,
mozilla::gfx::IntSize aScaledSize, HICON* aIcon);
mozilla::LayoutDeviceIntPoint aHotspot,
mozilla::LayoutDeviceIntSize aScaledSize,
HICON* aIcon);
private:
/**