/src/mozilla-central/dom/html/ImageDocument.h
Line | Count | Source (jump to first uncovered line) |
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 |
8 | | |
9 | | #include "mozilla/Attributes.h" |
10 | | #include "imgINotificationObserver.h" |
11 | | #include "MediaDocument.h" |
12 | | #include "nsIDOMEventListener.h" |
13 | | #include "nsIImageDocument.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | class ImageDocument final : public MediaDocument, |
19 | | public nsIImageDocument, |
20 | | public imgINotificationObserver, |
21 | | public nsIDOMEventListener |
22 | | { |
23 | | public: |
24 | | ImageDocument(); |
25 | | |
26 | | NS_DECL_ISUPPORTS_INHERITED |
27 | | |
28 | | enum MediaDocumentKind MediaDocumentKind() const override |
29 | 0 | { |
30 | 0 | return MediaDocumentKind::Image; |
31 | 0 | } |
32 | | |
33 | | virtual nsresult Init() override; |
34 | | |
35 | | virtual nsresult StartDocumentLoad(const char* aCommand, |
36 | | nsIChannel* aChannel, |
37 | | nsILoadGroup* aLoadGroup, |
38 | | nsISupports* aContainer, |
39 | | nsIStreamListener** aDocListener, |
40 | | bool aReset = true, |
41 | | nsIContentSink* aSink = nullptr) override; |
42 | | |
43 | | virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) override; |
44 | | virtual void Destroy() override; |
45 | | virtual void OnPageShow(bool aPersisted, |
46 | | EventTarget* aDispatchStartTarget, |
47 | | bool aOnlySystemGroup = false) override; |
48 | | |
49 | | NS_DECL_NSIIMAGEDOCUMENT |
50 | | NS_DECL_IMGINOTIFICATIONOBSERVER |
51 | | |
52 | | // nsIDOMEventListener |
53 | | NS_DECL_NSIDOMEVENTLISTENER |
54 | | |
55 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument) |
56 | | |
57 | | friend class ImageListener; |
58 | | |
59 | 0 | void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); } |
60 | | |
61 | | // WebIDL API |
62 | | virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
63 | | override; |
64 | | |
65 | | bool ImageIsOverflowing() const |
66 | | { |
67 | | return mImageIsOverflowingHorizontally || mImageIsOverflowingVertically; |
68 | | } |
69 | | bool ImageIsResized() const |
70 | | { |
71 | | return mImageIsResized; |
72 | | } |
73 | | already_AddRefed<imgIRequest> GetImageRequest(ErrorResult& aRv); |
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(); |
78 | | void RestoreImageTo(int32_t aX, int32_t aY) |
79 | | { |
80 | | ScrollImageTo(aX, aY, true); |
81 | | } |
82 | | void ToggleImageSize(); |
83 | | |
84 | | protected: |
85 | | virtual ~ImageDocument(); |
86 | | |
87 | | virtual nsresult CreateSyntheticDocument() override; |
88 | | |
89 | | nsresult CheckOverflowing(bool changeState); |
90 | | |
91 | | void UpdateTitleAndCharset(); |
92 | | |
93 | | void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage); |
94 | | |
95 | 0 | float GetRatio() { |
96 | 0 | return std::min(mVisibleWidth / mImageWidth, |
97 | 0 | mVisibleHeight / mImageHeight); |
98 | 0 | } |
99 | | |
100 | | void ResetZoomLevel(); |
101 | | float GetZoomLevel(); |
102 | | #if defined(MOZ_WIDGET_ANDROID) |
103 | | float GetResolution(); |
104 | | #endif |
105 | | |
106 | | void UpdateSizeFromLayout(); |
107 | | |
108 | | enum eModeClasses { |
109 | | eNone, |
110 | | eShrinkToFit, |
111 | | eOverflowingVertical, // And maybe horizontal too. |
112 | | eOverflowingHorizontalOnly |
113 | | }; |
114 | | void SetModeClass(eModeClasses mode); |
115 | | |
116 | | nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage); |
117 | | nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus); |
118 | | void OnHasTransparency(); |
119 | | |
120 | | nsCOMPtr<Element> mImageContent; |
121 | | |
122 | | float mVisibleWidth; |
123 | | float mVisibleHeight; |
124 | | int32_t mImageWidth; |
125 | | int32_t mImageHeight; |
126 | | |
127 | | bool mResizeImageByDefault; |
128 | | bool mClickResizingEnabled; |
129 | | bool mImageIsOverflowingHorizontally; |
130 | | bool mImageIsOverflowingVertically; |
131 | | // mImageIsResized is true if the image is currently resized |
132 | | bool mImageIsResized; |
133 | | // mShouldResize is true if the image should be resized when it doesn't fit |
134 | | // mImageIsResized cannot be true when this is false, but mImageIsResized |
135 | | // can be false when this is true |
136 | | bool mShouldResize; |
137 | | bool mFirstResize; |
138 | | // mObservingImageLoader is true while the observer is set. |
139 | | bool mObservingImageLoader; |
140 | | |
141 | | float mOriginalZoomLevel; |
142 | | #if defined(MOZ_WIDGET_ANDROID) |
143 | | float mOriginalResolution; |
144 | | #endif |
145 | | }; |
146 | | |
147 | | } // namespace dom |
148 | | } // namespace mozilla |
149 | | |
150 | | #endif /* mozilla_dom_ImageDocument_h */ |