diff --git a/content/html/document/src/ImageDocument.cpp b/content/html/document/src/ImageDocument.cpp index 2bacbe9efc78..70e250a9a956 100644 --- a/content/html/document/src/ImageDocument.cpp +++ b/content/html/document/src/ImageDocument.cpp @@ -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) { diff --git a/toolkit/themes/osx/global/media/TopLevelImageDocument.css b/toolkit/themes/osx/global/media/TopLevelImageDocument.css index 8166b03c5175..8b77873efdd4 100644 --- a/toolkit/themes/osx/global/media/TopLevelImageDocument.css +++ b/toolkit/themes/osx/global/media/TopLevelImageDocument.css @@ -15,6 +15,14 @@ color: #222; } + .overflowing { + cursor: -moz-zoom-out; + } + + .shrinkToFit { + cursor: -moz-zoom-in; + } + .completeRotation { transition: transform 0.3s ease 0s; } diff --git a/toolkit/themes/windows/global/media/TopLevelImageDocument.css b/toolkit/themes/windows/global/media/TopLevelImageDocument.css index 8166b03c5175..8b77873efdd4 100644 --- a/toolkit/themes/windows/global/media/TopLevelImageDocument.css +++ b/toolkit/themes/windows/global/media/TopLevelImageDocument.css @@ -15,6 +15,14 @@ color: #222; } + .overflowing { + cursor: -moz-zoom-out; + } + + .shrinkToFit { + cursor: -moz-zoom-in; + } + .completeRotation { transition: transform 0.3s ease 0s; }