mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 846929 - Instead of directly overwriting the style attribute to give a zoom in/zoom out cursor on very large images (when they overflow), add/remove classes that will change the cursor. r=roc
This commit is contained in:
parent
a8bbf2e6a4
commit
81dfd14df2
@ -10,6 +10,7 @@
|
||||
#include "nsIImageLoadingContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsIDocumentInlines.h"
|
||||
#include "nsDOMTokenList.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMKeyEvent.h"
|
||||
@ -119,6 +120,13 @@ protected:
|
||||
void ResetZoomLevel();
|
||||
float GetZoomLevel();
|
||||
|
||||
enum eModeClasses {
|
||||
eNone,
|
||||
eShrinkToFit,
|
||||
eOverflowing
|
||||
};
|
||||
void SetModeClass(eModeClasses mode);
|
||||
|
||||
nsresult OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage);
|
||||
nsresult OnStopRequest(imgIRequest *aRequest, nsresult aStatus);
|
||||
|
||||
@ -421,8 +429,7 @@ ImageDocument::ShrinkToFit()
|
||||
// origin now that we're showing a shrunk-to-window version.
|
||||
(void) ScrollImageTo(0, 0, false);
|
||||
|
||||
imageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
|
||||
NS_LITERAL_STRING("cursor: -moz-zoom-in"), true);
|
||||
SetModeClass(eShrinkToFit);
|
||||
|
||||
mImageIsResized = true;
|
||||
|
||||
@ -474,11 +481,10 @@ ImageDocument::RestoreImage()
|
||||
imageContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::height, true);
|
||||
|
||||
if (mImageIsOverflowing) {
|
||||
imageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
|
||||
NS_LITERAL_STRING("cursor: -moz-zoom-out"), true);
|
||||
SetModeClass(eOverflowing);
|
||||
}
|
||||
else {
|
||||
imageContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
|
||||
SetModeClass(eNone);
|
||||
}
|
||||
|
||||
mImageIsResized = false;
|
||||
@ -514,13 +520,15 @@ ImageDocument::Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aDa
|
||||
return OnStartContainer(aRequest, image);
|
||||
}
|
||||
|
||||
nsDOMTokenList* classList = mImageContent->AsElement()->GetClassList();
|
||||
mozilla::ErrorResult rv;
|
||||
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
|
||||
if (mImageContent) {
|
||||
// Update the background-color of the image only after the
|
||||
// image has been decoded to prevent flashes of just the
|
||||
// background-color.
|
||||
mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
||||
NS_LITERAL_STRING("decoded"), true);
|
||||
classList->Add(NS_LITERAL_STRING("decoded"), rv);
|
||||
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -528,8 +536,8 @@ ImageDocument::Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aDa
|
||||
// mImageContent can be null if the document is already destroyed
|
||||
if (mImageContent) {
|
||||
// Remove any decoded-related styling when the image is unloaded.
|
||||
mImageContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
||||
true);
|
||||
classList->Remove(NS_LITERAL_STRING("decoded"), rv);
|
||||
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,6 +552,25 @@ ImageDocument::Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aDa
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ImageDocument::SetModeClass(eModeClasses mode)
|
||||
{
|
||||
nsDOMTokenList* classList = mImageContent->AsElement()->GetClassList();
|
||||
mozilla::ErrorResult rv;
|
||||
|
||||
if (mode == eShrinkToFit) {
|
||||
classList->Add(NS_LITERAL_STRING("shrinkToFit"), rv);
|
||||
} else {
|
||||
classList->Remove(NS_LITERAL_STRING("shrinkToFit"), rv);
|
||||
}
|
||||
|
||||
if (mode == eOverflowing) {
|
||||
classList->Add(NS_LITERAL_STRING("overflowing"), rv);
|
||||
} else {
|
||||
classList->Remove(NS_LITERAL_STRING("overflowing"), rv);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
ImageDocument::OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage)
|
||||
{
|
||||
|
@ -15,6 +15,14 @@
|
||||
color: #222;
|
||||
}
|
||||
|
||||
.overflowing {
|
||||
cursor: -moz-zoom-out;
|
||||
}
|
||||
|
||||
.shrinkToFit {
|
||||
cursor: -moz-zoom-in;
|
||||
}
|
||||
|
||||
.completeRotation {
|
||||
transition: transform 0.3s ease 0s;
|
||||
}
|
||||
|
@ -15,6 +15,14 @@
|
||||
color: #222;
|
||||
}
|
||||
|
||||
.overflowing {
|
||||
cursor: -moz-zoom-out;
|
||||
}
|
||||
|
||||
.shrinkToFit {
|
||||
cursor: -moz-zoom-in;
|
||||
}
|
||||
|
||||
.completeRotation {
|
||||
transition: transform 0.3s ease 0s;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user