Bug 1461610. In image documents change the cursor to zoom in/out based on full zoom. r=emilio

Clicking on the image toggles between "shrink to fit" and full size mode. However it also
resets the full zoom. So if the full zoom has been changed then a click can zoom in/out.

The full situation is complicated because you could be in "shrink to fit" mode (so the cursor
should be the zoom in cursor) and then increase the full zoom so that image is bigger than it
would be in fullsize mode so clicking would actually result in zooming out. I don't try to
resolve this. Instead I just let cursor be decided by the "shrink to fit"/full size state if
that's relevant, otherwise the fullzoom will determine the cursor.

Differential Revision: https://phabricator.services.mozilla.com/D161980
This commit is contained in:
Timothy Nikkel 2022-11-17 00:39:33 +00:00
parent eee0f3c4ff
commit f1b674d43c
3 changed files with 28 additions and 0 deletions

View File

@ -177,6 +177,7 @@ nsresult ImageDocument::StartDocumentLoad(
}
mOriginalZoomLevel = IsSiteSpecific() ? 1.0 : GetZoomLevel();
CheckFullZoom();
mOriginalResolution = GetResolution();
if (BrowsingContext* context = GetBrowsingContext()) {
@ -255,6 +256,7 @@ void ImageDocument::OnPageShow(bool aPersisted,
bool aOnlySystemGroup) {
if (aPersisted) {
mOriginalZoomLevel = IsSiteSpecific() ? 1.0 : GetZoomLevel();
CheckFullZoom();
mOriginalResolution = GetResolution();
}
RefPtr<ImageDocument> kungFuDeathGrip(this);
@ -486,6 +488,7 @@ ImageDocument::HandleEvent(Event* aEvent) {
aEvent->GetType(eventType);
if (eventType.EqualsLiteral("resize")) {
CheckOverflowing(false);
CheckFullZoom();
} else if (eventType.EqualsLiteral("click") &&
StaticPrefs::browser_enable_click_image_resizing() &&
!mIsInObjectOrEmbed) {
@ -738,6 +741,22 @@ float ImageDocument::GetZoomLevel() {
return mOriginalZoomLevel;
}
void ImageDocument::CheckFullZoom() {
nsDOMTokenList* classList =
mImageContent ? mImageContent->ClassList() : nullptr;
if (!classList) {
return;
}
classList->Toggle(u"fullZoomOut"_ns,
dom::Optional<bool>(GetZoomLevel() > mOriginalZoomLevel),
IgnoreErrors());
classList->Toggle(u"fullZoomIn"_ns,
dom::Optional<bool>(GetZoomLevel() < mOriginalZoomLevel),
IgnoreErrors());
}
float ImageDocument::GetResolution() {
if (PresShell* presShell = GetPresShell()) {
return presShell->GetResolution();

View File

@ -96,6 +96,7 @@ class ImageDocument final : public MediaDocument,
void ResetZoomLevel();
float GetZoomLevel();
void CheckFullZoom();
float GetResolution();
void UpdateSizeFromLayout();

View File

@ -16,6 +16,14 @@ body {
}
@media not print {
.fullZoomOut {
cursor: zoom-out;
}
.fullZoomIn {
cursor: zoom-in;
}
.shrinkToFit {
cursor: zoom-in;
}