michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef mozilla_dom_ImageDocument_h michael@0: #define mozilla_dom_ImageDocument_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "imgINotificationObserver.h" michael@0: #include "MediaDocument.h" michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsIImageDocument.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class ImageDocument MOZ_FINAL : public MediaDocument, michael@0: public nsIImageDocument, michael@0: public imgINotificationObserver, michael@0: public nsIDOMEventListener michael@0: { michael@0: public: michael@0: ImageDocument(); michael@0: virtual ~ImageDocument(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: virtual nsresult Init() MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult StartDocumentLoad(const char* aCommand, michael@0: nsIChannel* aChannel, michael@0: nsILoadGroup* aLoadGroup, michael@0: nsISupports* aContainer, michael@0: nsIStreamListener** aDocListener, michael@0: bool aReset = true, michael@0: nsIContentSink* aSink = nullptr) MOZ_OVERRIDE; michael@0: michael@0: virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) MOZ_OVERRIDE; michael@0: virtual void Destroy() MOZ_OVERRIDE; michael@0: virtual void OnPageShow(bool aPersisted, michael@0: EventTarget* aDispatchStartTarget) MOZ_OVERRIDE; michael@0: michael@0: NS_DECL_NSIIMAGEDOCUMENT michael@0: NS_DECL_IMGINOTIFICATIONOBSERVER michael@0: michael@0: // nsIDOMEventListener michael@0: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE; michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument) michael@0: michael@0: friend class ImageListener; michael@0: michael@0: void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); } michael@0: michael@0: // WebIDL API michael@0: virtual JSObject* WrapNode(JSContext* aCx) michael@0: MOZ_OVERRIDE; michael@0: michael@0: bool ImageResizingEnabled() const michael@0: { michael@0: return true; michael@0: } michael@0: bool ImageIsOverflowing() const michael@0: { michael@0: return mImageIsOverflowing; michael@0: } michael@0: bool ImageIsResized() const michael@0: { michael@0: return mImageIsResized; michael@0: } michael@0: already_AddRefed GetImageRequest(ErrorResult& aRv); michael@0: void ShrinkToFit(); michael@0: void RestoreImage(); michael@0: void RestoreImageTo(int32_t aX, int32_t aY) michael@0: { michael@0: ScrollImageTo(aX, aY, true); michael@0: } michael@0: void ToggleImageSize(); michael@0: michael@0: protected: michael@0: virtual nsresult CreateSyntheticDocument(); michael@0: michael@0: nsresult CheckOverflowing(bool changeState); michael@0: michael@0: void UpdateTitleAndCharset(); michael@0: michael@0: void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage); michael@0: michael@0: float GetRatio() { michael@0: return std::min(mVisibleWidth / mImageWidth, michael@0: mVisibleHeight / mImageHeight); michael@0: } michael@0: michael@0: void ResetZoomLevel(); michael@0: float GetZoomLevel(); michael@0: michael@0: void UpdateSizeFromLayout(); michael@0: michael@0: enum eModeClasses { michael@0: eNone, michael@0: eShrinkToFit, michael@0: eOverflowing michael@0: }; michael@0: void SetModeClass(eModeClasses mode); michael@0: michael@0: nsresult OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage); michael@0: nsresult OnStopRequest(imgIRequest *aRequest, nsresult aStatus); michael@0: michael@0: nsCOMPtr mImageContent; michael@0: michael@0: float mVisibleWidth; michael@0: float mVisibleHeight; michael@0: int32_t mImageWidth; michael@0: int32_t mImageHeight; michael@0: michael@0: bool mResizeImageByDefault; michael@0: bool mClickResizingEnabled; michael@0: bool mImageIsOverflowing; michael@0: // mImageIsResized is true if the image is currently resized michael@0: bool mImageIsResized; michael@0: // mShouldResize is true if the image should be resized when it doesn't fit michael@0: // mImageIsResized cannot be true when this is false, but mImageIsResized michael@0: // can be false when this is true michael@0: bool mShouldResize; michael@0: bool mFirstResize; michael@0: // mObservingImageLoader is true while the observer is set. michael@0: bool mObservingImageLoader; michael@0: michael@0: float mOriginalZoomLevel; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_dom_ImageDocument_h */