2013-05-06 17:42:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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"
|
|
|
|
#include "nsIImageDocument.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ImageDocument final : public MediaDocument,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIImageDocument,
|
|
|
|
public imgINotificationObserver,
|
|
|
|
public nsIDOMEventListener
|
2013-05-06 17:42:00 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageDocument();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult Init() override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset = true,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIContentSink* aSink = nullptr) override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) override;
|
|
|
|
virtual void Destroy() override;
|
2013-05-06 17:42:00 +04:00
|
|
|
virtual void OnPageShow(bool aPersisted,
|
2015-03-21 19:28:04 +03:00
|
|
|
EventTarget* aDispatchStartTarget) override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
NS_DECL_NSIIMAGEDOCUMENT
|
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
|
|
|
|
|
|
|
// nsIDOMEventListener
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument)
|
|
|
|
|
|
|
|
friend class ImageListener;
|
|
|
|
|
|
|
|
void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
// WebIDL API
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2015-03-21 19:28:04 +03:00
|
|
|
override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
bool ImageResizingEnabled() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool ImageIsOverflowing() const
|
|
|
|
{
|
|
|
|
return mImageIsOverflowing;
|
|
|
|
}
|
|
|
|
bool ImageIsResized() const
|
|
|
|
{
|
|
|
|
return mImageIsResized;
|
|
|
|
}
|
|
|
|
already_AddRefed<imgIRequest> GetImageRequest(ErrorResult& aRv);
|
|
|
|
void ShrinkToFit();
|
|
|
|
void RestoreImage();
|
|
|
|
void RestoreImageTo(int32_t aX, int32_t aY)
|
|
|
|
{
|
|
|
|
ScrollImageTo(aX, aY, true);
|
|
|
|
}
|
|
|
|
void ToggleImageSize();
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~ImageDocument();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult CreateSyntheticDocument() override;
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
nsresult CheckOverflowing(bool changeState);
|
|
|
|
|
|
|
|
void UpdateTitleAndCharset();
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
float GetRatio() {
|
|
|
|
return std::min(mVisibleWidth / mImageWidth,
|
|
|
|
mVisibleHeight / mImageHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetZoomLevel();
|
|
|
|
float GetZoomLevel();
|
|
|
|
|
2013-11-20 02:24:59 +04:00
|
|
|
void UpdateSizeFromLayout();
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
enum eModeClasses {
|
|
|
|
eNone,
|
|
|
|
eShrinkToFit,
|
|
|
|
eOverflowing
|
|
|
|
};
|
|
|
|
void SetModeClass(eModeClasses mode);
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
|
|
|
|
nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
|
2014-11-17 22:16:45 +03:00
|
|
|
void OnHasTransparency();
|
2013-05-06 17:42:00 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mImageContent;
|
|
|
|
|
|
|
|
float mVisibleWidth;
|
|
|
|
float mVisibleHeight;
|
|
|
|
int32_t mImageWidth;
|
|
|
|
int32_t mImageHeight;
|
|
|
|
|
|
|
|
bool mResizeImageByDefault;
|
|
|
|
bool mClickResizingEnabled;
|
|
|
|
bool mImageIsOverflowing;
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
float mOriginalZoomLevel;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_ImageDocument_h */
|