no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / html / ImageDocument.h
blob891658264c837a1670d2c5001ee356d55bb1025f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_ImageDocument_h
7 #define mozilla_dom_ImageDocument_h
9 #include "mozilla/Attributes.h"
10 #include "imgINotificationObserver.h"
11 #include "mozilla/dom/MediaDocument.h"
12 #include "nsIDOMEventListener.h"
14 namespace mozilla {
15 enum class StyleImageRendering : uint8_t;
16 struct IntrinsicSize;
17 } // namespace mozilla
19 namespace mozilla::dom {
20 class HTMLImageElement;
22 class ImageDocument final : public MediaDocument,
23 public imgINotificationObserver,
24 public nsIDOMEventListener {
25 public:
26 ImageDocument();
28 NS_DECL_ISUPPORTS_INHERITED
30 enum MediaDocumentKind MediaDocumentKind() const override {
31 return MediaDocumentKind::Image;
34 nsresult Init(nsIPrincipal* aPrincipal,
35 nsIPrincipal* aPartitionedPrincipal) override;
37 nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
38 nsILoadGroup* aLoadGroup, nsISupports* aContainer,
39 nsIStreamListener** aDocListener,
40 bool aReset = true) override;
42 void SetScriptGlobalObject(nsIScriptGlobalObject*) override;
43 void Destroy() override;
44 void OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget,
45 bool aOnlySystemGroup = false) override;
47 NS_DECL_IMGINOTIFICATIONOBSERVER
49 // nsIDOMEventListener
50 NS_DECL_NSIDOMEVENTLISTENER
52 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument)
54 friend class ImageListener;
56 void DefaultCheckOverflowing();
58 // WebIDL API
59 JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
61 bool ImageIsOverflowing() const {
62 return ImageIsOverflowingHorizontally() || ImageIsOverflowingVertically();
65 bool ImageIsOverflowingVertically() const {
66 return mImageHeight > mVisibleHeight;
69 bool ImageIsOverflowingHorizontally() const {
70 return mImageWidth > mVisibleWidth;
73 bool ImageIsResized() const { return mImageIsResized; }
74 // ShrinkToFit is called from xpidl methods and we don't have a good
75 // way to mark those MOZ_CAN_RUN_SCRIPT yet.
76 MOZ_CAN_RUN_SCRIPT_BOUNDARY void ShrinkToFit();
77 void RestoreImage();
79 void NotifyPossibleTitleChange(bool aBoundTitleElement) override;
81 void UpdateRemoteStyle(StyleImageRendering aImageRendering);
83 protected:
84 virtual ~ImageDocument();
86 nsresult CreateSyntheticDocument() override;
88 nsresult CheckOverflowing(bool changeState);
90 void UpdateTitleAndCharset();
92 void ScrollImageTo(int32_t aX, int32_t aY);
94 float GetRatio() const {
95 return std::min(mVisibleWidth / mImageWidth, mVisibleHeight / mImageHeight);
98 bool IsSiteSpecific();
100 void ResetZoomLevel();
101 float GetZoomLevel();
102 void CheckFullZoom();
103 float GetResolution();
105 void UpdateSizeFromLayout();
107 enum eModeClasses {
108 eNone,
109 eShrinkToFit,
110 eOverflowingVertical, // And maybe horizontal too.
111 eOverflowingHorizontalOnly,
112 eIsInObjectOrEmbed
114 void SetModeClass(eModeClasses mode);
116 void OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
117 void OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
118 void OnHasTransparency();
120 void MaybeSendResultToEmbedder(nsresult aResult);
122 RefPtr<HTMLImageElement> mImageContent;
124 float mVisibleWidth;
125 float mVisibleHeight;
126 int32_t mImageWidth;
127 int32_t mImageHeight;
129 // mImageIsResized is true if the image is currently resized
130 bool mImageIsResized;
131 // mShouldResize is true if the image should be resized when it doesn't fit
132 // mImageIsResized cannot be true when this is false, but mImageIsResized
133 // can be false when this is true
134 bool mShouldResize;
135 bool mFirstResize;
136 // mObservingImageLoader is true while the observer is set.
137 bool mObservingImageLoader;
138 bool mTitleUpdateInProgress;
139 bool mHasCustomTitle;
141 // True iff embedder is either <object> or <embed>.
142 bool mIsInObjectOrEmbed;
144 float mOriginalZoomLevel;
145 float mOriginalResolution;
148 inline ImageDocument* Document::AsImageDocument() {
149 MOZ_ASSERT(IsImageDocument());
150 return static_cast<ImageDocument*>(this);
153 inline const ImageDocument* Document::AsImageDocument() const {
154 MOZ_ASSERT(IsImageDocument());
155 return static_cast<const ImageDocument*>(this);
158 } // namespace mozilla::dom
160 #endif /* mozilla_dom_ImageDocument_h */