2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-05-06 17:42:00 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef mozilla_dom_ImageDocument_h
|
|
|
|
#define mozilla_dom_ImageDocument_h
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-05-06 17:42:00 +04:00
|
|
|
#include "imgINotificationObserver.h"
|
|
|
|
#include "MediaDocument.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-04-21 19:45:36 +03:00
|
|
|
class HTMLImageElement;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ImageDocument final : public MediaDocument,
|
2015-03-27 21:52:19 +03:00
|
|
|
public imgINotificationObserver,
|
|
|
|
public nsIDOMEventListener {
|
2013-05-06 17:42:00 +04:00
|
|
|
public:
|
|
|
|
ImageDocument();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2018-07-19 14:36:20 +03:00
|
|
|
enum MediaDocumentKind MediaDocumentKind() const override {
|
|
|
|
return MediaDocumentKind::Image;
|
|
|
|
}
|
|
|
|
|
2020-04-20 22:31:26 +03:00
|
|
|
nsresult Init() override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
2020-04-20 22:31:26 +03:00
|
|
|
nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup, nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset = true,
|
|
|
|
nsIContentSink* aSink = nullptr) override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
2020-04-20 22:31:26 +03:00
|
|
|
void SetScriptGlobalObject(nsIScriptGlobalObject*) override;
|
|
|
|
void Destroy() override;
|
|
|
|
void OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget,
|
|
|
|
bool aOnlySystemGroup = false) override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
|
|
|
|
|
|
|
// nsIDOMEventListener
|
2018-04-20 07:49:29 +03:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument)
|
|
|
|
|
|
|
|
friend class ImageListener;
|
|
|
|
|
2020-04-21 18:40:55 +03:00
|
|
|
void DefaultCheckOverflowing();
|
2013-05-06 17:42:00 +04:00
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
// WebIDL API
|
2020-04-20 22:31:26 +03:00
|
|
|
JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
bool ImageIsOverflowing() const {
|
2020-04-21 19:45:23 +03:00
|
|
|
return ImageIsOverflowingHorizontally() || ImageIsOverflowingVertically();
|
2013-05-06 17:42:00 +04:00
|
|
|
}
|
2020-04-21 19:45:23 +03:00
|
|
|
|
|
|
|
bool ImageIsOverflowingVertically() const {
|
|
|
|
return mImageHeight > mVisibleHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageIsOverflowingHorizontally() const {
|
|
|
|
return mImageWidth > mVisibleWidth;
|
|
|
|
}
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
bool ImageIsResized() const { return mImageIsResized; }
|
2017-12-05 19:18:16 +03:00
|
|
|
// ShrinkToFit is called from xpidl methods and we don't have a good
|
|
|
|
// way to mark those MOZ_CAN_RUN_SCRIPT yet.
|
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void ShrinkToFit();
|
2013-05-06 17:42:00 +04:00
|
|
|
void RestoreImage();
|
|
|
|
|
2020-04-20 22:31:26 +03:00
|
|
|
void NotifyPossibleTitleChange(bool aBoundTitleElement) override;
|
2018-11-07 15:58:18 +03:00
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~ImageDocument();
|
|
|
|
|
2020-04-20 22:31:26 +03:00
|
|
|
nsresult CreateSyntheticDocument() override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
nsresult CheckOverflowing(bool changeState);
|
|
|
|
|
|
|
|
void UpdateTitleAndCharset();
|
|
|
|
|
2020-04-21 19:51:51 +03:00
|
|
|
void ScrollImageTo(int32_t aX, int32_t aY);
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
float GetRatio() {
|
|
|
|
return std::min(mVisibleWidth / mImageWidth, mVisibleHeight / mImageHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetZoomLevel();
|
|
|
|
float GetZoomLevel();
|
2018-02-21 01:07:21 +03:00
|
|
|
float GetResolution();
|
2013-05-06 17:42:00 +04:00
|
|
|
|
2013-11-20 02:24:59 +04:00
|
|
|
void UpdateSizeFromLayout();
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
enum eModeClasses {
|
|
|
|
eNone,
|
|
|
|
eShrinkToFit,
|
2016-02-06 07:31:19 +03:00
|
|
|
eOverflowingVertical, // And maybe horizontal too.
|
|
|
|
eOverflowingHorizontalOnly
|
2013-05-06 17:42:00 +04:00
|
|
|
};
|
|
|
|
void SetModeClass(eModeClasses mode);
|
|
|
|
|
2020-03-12 07:25:34 +03:00
|
|
|
void OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
|
|
|
|
void OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
|
2014-11-17 22:16:45 +03:00
|
|
|
void OnHasTransparency();
|
2013-05-06 17:42:00 +04:00
|
|
|
|
2020-04-21 19:45:36 +03:00
|
|
|
RefPtr<HTMLImageElement> mImageContent;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
float mVisibleWidth;
|
|
|
|
float mVisibleHeight;
|
|
|
|
int32_t mImageWidth;
|
|
|
|
int32_t mImageHeight;
|
|
|
|
|
|
|
|
// mImageIsResized is true if the image is currently resized
|
|
|
|
bool mImageIsResized;
|
|
|
|
// mShouldResize is true if the image should be resized when it doesn't fit
|
|
|
|
// mImageIsResized cannot be true when this is false, but mImageIsResized
|
|
|
|
// can be false when this is true
|
|
|
|
bool mShouldResize;
|
|
|
|
bool mFirstResize;
|
|
|
|
// mObservingImageLoader is true while the observer is set.
|
|
|
|
bool mObservingImageLoader;
|
2018-11-07 15:58:18 +03:00
|
|
|
bool mTitleUpdateInProgress;
|
|
|
|
bool mHasCustomTitle;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
float mOriginalZoomLevel;
|
2018-02-21 01:07:21 +03:00
|
|
|
float mOriginalResolution;
|
2013-05-06 17:42:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_ImageDocument_h */
|