content/html/document/src/ImageDocument.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:6cd80d62e20e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_ImageDocument_h
6 #define mozilla_dom_ImageDocument_h
7
8 #include "mozilla/Attributes.h"
9 #include "imgINotificationObserver.h"
10 #include "MediaDocument.h"
11 #include "nsIDOMEventListener.h"
12 #include "nsIImageDocument.h"
13
14 namespace mozilla {
15 namespace dom {
16
17 class ImageDocument MOZ_FINAL : public MediaDocument,
18 public nsIImageDocument,
19 public imgINotificationObserver,
20 public nsIDOMEventListener
21 {
22 public:
23 ImageDocument();
24 virtual ~ImageDocument();
25
26 NS_DECL_ISUPPORTS_INHERITED
27
28 virtual nsresult Init() MOZ_OVERRIDE;
29
30 virtual nsresult StartDocumentLoad(const char* aCommand,
31 nsIChannel* aChannel,
32 nsILoadGroup* aLoadGroup,
33 nsISupports* aContainer,
34 nsIStreamListener** aDocListener,
35 bool aReset = true,
36 nsIContentSink* aSink = nullptr) MOZ_OVERRIDE;
37
38 virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) MOZ_OVERRIDE;
39 virtual void Destroy() MOZ_OVERRIDE;
40 virtual void OnPageShow(bool aPersisted,
41 EventTarget* aDispatchStartTarget) MOZ_OVERRIDE;
42
43 NS_DECL_NSIIMAGEDOCUMENT
44 NS_DECL_IMGINOTIFICATIONOBSERVER
45
46 // nsIDOMEventListener
47 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE;
48
49 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument)
50
51 friend class ImageListener;
52
53 void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
54
55 // WebIDL API
56 virtual JSObject* WrapNode(JSContext* aCx)
57 MOZ_OVERRIDE;
58
59 bool ImageResizingEnabled() const
60 {
61 return true;
62 }
63 bool ImageIsOverflowing() const
64 {
65 return mImageIsOverflowing;
66 }
67 bool ImageIsResized() const
68 {
69 return mImageIsResized;
70 }
71 already_AddRefed<imgIRequest> GetImageRequest(ErrorResult& aRv);
72 void ShrinkToFit();
73 void RestoreImage();
74 void RestoreImageTo(int32_t aX, int32_t aY)
75 {
76 ScrollImageTo(aX, aY, true);
77 }
78 void ToggleImageSize();
79
80 protected:
81 virtual nsresult CreateSyntheticDocument();
82
83 nsresult CheckOverflowing(bool changeState);
84
85 void UpdateTitleAndCharset();
86
87 void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
88
89 float GetRatio() {
90 return std::min(mVisibleWidth / mImageWidth,
91 mVisibleHeight / mImageHeight);
92 }
93
94 void ResetZoomLevel();
95 float GetZoomLevel();
96
97 void UpdateSizeFromLayout();
98
99 enum eModeClasses {
100 eNone,
101 eShrinkToFit,
102 eOverflowing
103 };
104 void SetModeClass(eModeClasses mode);
105
106 nsresult OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage);
107 nsresult OnStopRequest(imgIRequest *aRequest, nsresult aStatus);
108
109 nsCOMPtr<nsIContent> mImageContent;
110
111 float mVisibleWidth;
112 float mVisibleHeight;
113 int32_t mImageWidth;
114 int32_t mImageHeight;
115
116 bool mResizeImageByDefault;
117 bool mClickResizingEnabled;
118 bool mImageIsOverflowing;
119 // mImageIsResized is true if the image is currently resized
120 bool mImageIsResized;
121 // mShouldResize is true if the image should be resized when it doesn't fit
122 // mImageIsResized cannot be true when this is false, but mImageIsResized
123 // can be false when this is true
124 bool mShouldResize;
125 bool mFirstResize;
126 // mObservingImageLoader is true while the observer is set.
127 bool mObservingImageLoader;
128
129 float mOriginalZoomLevel;
130 };
131
132 } // namespace dom
133 } // namespace mozilla
134
135 #endif /* mozilla_dom_ImageDocument_h */

mercurial