diff --git a/content/html/document/public/nsIImageDocument.idl b/content/html/document/public/nsIImageDocument.idl
index 5c09f6ca8210..692a1889ac8e 100644
--- a/content/html/document/public/nsIImageDocument.idl
+++ b/content/html/document/public/nsIImageDocument.idl
@@ -11,7 +11,7 @@
interface imgIRequest;
-[scriptable, uuid(7b80eebc-c98e-4461-8bdb-6e3b6e828890)]
+[scriptable, uuid(87c27f98-37dc-4b64-a8cd-92003624bcee)]
interface nsIImageDocument : nsISupports {
/* Whether the pref for image resizing has been set. */
@@ -27,14 +27,17 @@ interface nsIImageDocument : nsISupports {
readonly attribute imgIRequest imageRequest;
/* Resize the image to fit visible area. */
+ [binaryname(DOMShrinkToFit)]
void shrinkToFit();
/* Restore image original size. */
+ [binaryname(DOMRestoreImage)]
void restoreImage();
/* Restore the image, trying to keep a certain pixel in the same position.
* The coordinate system is that of the shrunken image.
*/
+ [binaryname(DOMRestoreImageTo)]
void restoreImageTo(in long x, in long y);
/* A helper method for switching between states.
@@ -42,5 +45,6 @@ interface nsIImageDocument : nsISupports {
* restore image original size, otherwise if the image is overflowing
* current visible area resize the image to fit the area.
*/
+ [binaryname(DOMToggleImageSize)]
void toggleImageSize();
};
diff --git a/content/html/document/src/ImageDocument.cpp b/content/html/document/src/ImageDocument.cpp
index 6c708845adeb..635bcab2b5a0 100644
--- a/content/html/document/src/ImageDocument.cpp
+++ b/content/html/document/src/ImageDocument.cpp
@@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ImageDocument.h"
+#include "mozilla/dom/ImageDocumentBinding.h"
#include "nsRect.h"
#include "nsIImageLoadingContent.h"
#include "nsGenericHTMLElement.h"
@@ -124,7 +125,7 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
}
ImageDocument::ImageDocument()
- : MediaDocument(true),
+ : MediaDocument(),
mOriginalZoomLevel(1.0)
{
// NOTE! nsDocument::operator new() zeroes out all members, so don't
@@ -147,8 +148,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(ImageDocument, MediaDocument)
NS_IMPL_RELEASE_INHERITED(ImageDocument, MediaDocument)
-DOMCI_NODE_DATA(ImageDocument, ImageDocument)
-
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(ImageDocument)
NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(ImageDocument)
NS_INTERFACE_TABLE_ENTRY(ImageDocument, nsIImageDocument)
@@ -156,7 +155,6 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(ImageDocument)
NS_INTERFACE_TABLE_ENTRY(ImageDocument, nsIDOMEventListener)
NS_OFFSET_AND_INTERFACE_TABLE_END
NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
- NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ImageDocument)
NS_INTERFACE_MAP_END_INHERITING(MediaDocument)
@@ -174,6 +172,16 @@ ImageDocument::Init()
return NS_OK;
}
+JSObject*
+ImageDocument::WrapNode(JSContext* aCx, JS::Handle aScope)
+{
+ JS::Rooted obj(aCx, ImageDocumentBinding::Wrap(aCx, aScope, this));
+ if (obj && !PostCreateWrapper(aCx, obj)) {
+ return nullptr;
+ }
+ return obj;
+}
+
nsresult
ImageDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@@ -287,46 +295,53 @@ ImageDocument::OnPageShow(bool aPersisted,
NS_IMETHODIMP
ImageDocument::GetImageResizingEnabled(bool* aImageResizingEnabled)
{
- *aImageResizingEnabled = true;
+ *aImageResizingEnabled = ImageResizingEnabled();
return NS_OK;
}
NS_IMETHODIMP
ImageDocument::GetImageIsOverflowing(bool* aImageIsOverflowing)
{
- *aImageIsOverflowing = mImageIsOverflowing;
+ *aImageIsOverflowing = ImageIsOverflowing();
return NS_OK;
}
NS_IMETHODIMP
ImageDocument::GetImageIsResized(bool* aImageIsResized)
{
- *aImageIsResized = mImageIsResized;
+ *aImageIsResized = ImageIsResized();
return NS_OK;
}
+already_AddRefed
+ImageDocument::GetImageRequest(ErrorResult& aRv)
+{
+ nsCOMPtr imageLoader = do_QueryInterface(mImageContent);
+ nsCOMPtr imageRequest;
+ if (imageLoader) {
+ aRv = imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
+ getter_AddRefs(imageRequest));
+ }
+ return imageRequest.forget();
+}
+
NS_IMETHODIMP
ImageDocument::GetImageRequest(imgIRequest** aImageRequest)
{
- nsCOMPtr imageLoader = do_QueryInterface(mImageContent);
- if (imageLoader) {
- return imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
- aImageRequest);
- }
-
- *aImageRequest = nullptr;
- return NS_OK;
+ ErrorResult rv;
+ *aImageRequest = GetImageRequest(rv).get();
+ return rv.ErrorCode();
}
-NS_IMETHODIMP
+void
ImageDocument::ShrinkToFit()
{
if (!mImageContent) {
- return NS_OK;
+ return;
}
if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized &&
!nsContentUtils::IsChildOfSameType(this)) {
- return NS_OK;
+ return;
}
// Keep image content alive while changing the attributes.
@@ -337,24 +352,30 @@ ImageDocument::ShrinkToFit()
// The view might have been scrolled when zooming in, scroll back to the
// origin now that we're showing a shrunk-to-window version.
- (void) ScrollImageTo(0, 0, false);
+ ScrollImageTo(0, 0, false);
SetModeClass(eShrinkToFit);
mImageIsResized = true;
UpdateTitleAndCharset();
+}
+NS_IMETHODIMP
+ImageDocument::DOMShrinkToFit()
+{
+ ShrinkToFit();
return NS_OK;
}
NS_IMETHODIMP
-ImageDocument::RestoreImageTo(int32_t aX, int32_t aY)
+ImageDocument::DOMRestoreImageTo(int32_t aX, int32_t aY)
{
- return ScrollImageTo(aX, aY, true);
+ RestoreImageTo(aX, aY);
+ return NS_OK;
}
-nsresult
+void
ImageDocument::ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage)
{
float ratio = GetRatio();
@@ -366,24 +387,23 @@ ImageDocument::ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage)
nsIPresShell *shell = GetShell();
if (!shell)
- return NS_OK;
+ return;
nsIScrollableFrame* sf = shell->GetRootScrollFrameAsScrollable();
if (!sf)
- return NS_OK;
+ return;
nsRect portRect = sf->GetScrollPortRect();
sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(aX/ratio) - portRect.width/2,
nsPresContext::CSSPixelsToAppUnits(aY/ratio) - portRect.height/2),
nsIScrollableFrame::INSTANT);
- return NS_OK;
}
-NS_IMETHODIMP
+void
ImageDocument::RestoreImage()
{
if (!mImageContent) {
- return NS_OK;
+ return;
}
// Keep image content alive while changing the attributes.
nsCOMPtr imageContent = mImageContent;
@@ -400,11 +420,16 @@ ImageDocument::RestoreImage()
mImageIsResized = false;
UpdateTitleAndCharset();
-
- return NS_OK;
}
NS_IMETHODIMP
+ImageDocument::DOMRestoreImage()
+{
+ RestoreImage();
+ return NS_OK;
+}
+
+void
ImageDocument::ToggleImageSize()
{
mShouldResize = true;
@@ -417,7 +442,12 @@ ImageDocument::ToggleImageSize()
ResetZoomLevel();
ShrinkToFit();
}
+}
+NS_IMETHODIMP
+ImageDocument::DOMToggleImageSize()
+{
+ ToggleImageSize();
return NS_OK;
}
diff --git a/content/html/document/src/ImageDocument.h b/content/html/document/src/ImageDocument.h
index 7e12f8773aed..2d0dd99cbc25 100644
--- a/content/html/document/src/ImageDocument.h
+++ b/content/html/document/src/ImageDocument.h
@@ -51,7 +51,31 @@ public:
void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
- virtual nsXPCClassInfo* GetClassInfo();
+ // WebIDL API
+ virtual JSObject* WrapNode(JSContext* aCx, JS::Handle aScope)
+ MOZ_OVERRIDE;
+
+ bool ImageResizingEnabled() const
+ {
+ return true;
+ }
+ bool ImageIsOverflowing() const
+ {
+ return mImageIsOverflowing;
+ }
+ bool ImageIsResized() const
+ {
+ return mImageIsResized;
+ }
+ already_AddRefed GetImageRequest(ErrorResult& aRv);
+ void ShrinkToFit();
+ void RestoreImage();
+ void RestoreImageTo(int32_t aX, int32_t aY)
+ {
+ ScrollImageTo(aX, aY, true);
+ }
+ void ToggleImageSize();
+
protected:
virtual nsresult CreateSyntheticDocument();
@@ -59,7 +83,7 @@ protected:
void UpdateTitleAndCharset();
- nsresult ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
+ void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
float GetRatio() {
return std::min(mVisibleWidth / mImageWidth,
diff --git a/content/html/document/src/MediaDocument.cpp b/content/html/document/src/MediaDocument.cpp
index 4bb7a309abc5..26210f5a2100 100644
--- a/content/html/document/src/MediaDocument.cpp
+++ b/content/html/document/src/MediaDocument.cpp
@@ -97,8 +97,8 @@ const char* const MediaDocument::sFormatNames[4] =
"" // eWithDimAndFile
};
-MediaDocument::MediaDocument(bool aUseXPConnectToWrap)
- : nsHTMLDocument(aUseXPConnectToWrap),
+MediaDocument::MediaDocument()
+ : nsHTMLDocument(),
mDocumentElementInserted(false)
{
}
diff --git a/content/html/document/src/MediaDocument.h b/content/html/document/src/MediaDocument.h
index acd350d694a8..c319adc6f837 100644
--- a/content/html/document/src/MediaDocument.h
+++ b/content/html/document/src/MediaDocument.h
@@ -19,7 +19,7 @@ namespace dom {
class MediaDocument : public nsHTMLDocument
{
public:
- MediaDocument(bool aUseXPConnectToWrap = false);
+ MediaDocument();
virtual ~MediaDocument();
virtual nsresult Init();
diff --git a/content/html/document/src/moz.build b/content/html/document/src/moz.build
index 0be0dcfa08c8..86ccea5efa70 100644
--- a/content/html/document/src/moz.build
+++ b/content/html/document/src/moz.build
@@ -10,3 +10,6 @@ EXPORTS += [
'nsIHTMLDocument.h',
]
+EXPORTS.mozilla.dom += [
+ 'ImageDocument.h',
+]
diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index ac9670b15bc1..e624b0cf169c 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -197,7 +197,7 @@ NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
// NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0.
-nsHTMLDocument::nsHTMLDocument(bool aUseXPConnectToWrap)
+nsHTMLDocument::nsHTMLDocument()
: nsDocument("text/html")
{
// NOTE! nsDocument::operator new() zeroes out all members, so don't
@@ -207,9 +207,7 @@ nsHTMLDocument::nsHTMLDocument(bool aUseXPConnectToWrap)
mDefaultElementType = kNameSpaceID_XHTML;
mCompatMode = eCompatibility_NavQuirks;
- if (!aUseXPConnectToWrap) {
- SetIsDOMBinding();
- }
+ SetIsDOMBinding();
}
@@ -260,12 +258,6 @@ NS_INTERFACE_MAP_END_INHERITING(nsDocument)
JSObject*
nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle aScope)
{
-#ifdef DEBUG
- // Don't do it yet for image documents
- nsCOMPtr imgDoc = do_QueryObject(this);
- MOZ_ASSERT(!imgDoc, "Who called SetIsDOMBinding()?");
-#endif
-
JS::Rooted obj(aCx, HTMLDocumentBinding::Wrap(aCx, aScope, this));
if (obj && !PostCreateWrapper(aCx, obj)) {
return nullptr;
diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h
index fdc8034fe1f5..599c404ed8d7 100644
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -42,7 +42,7 @@ public:
using nsDocument::SetDocumentURI;
using nsDocument::GetPlugins;
- nsHTMLDocument(bool aUseXPConnectToWrap = false);
+ nsHTMLDocument();
virtual nsresult Init();
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp
index 9b280c42a9a6..6aa552195903 100644
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -221,8 +221,6 @@
#include "nsIDOMSVGNumber.h"
#include "nsIDOMSVGRect.h"
-#include "nsIImageDocument.h"
-
// Storage includes
#include "DOMStorage.h"
@@ -662,9 +660,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DEFAULT_SCRIPTABLE_FLAGS |
WINDOW_SCRIPTABLE_FLAGS)
- NS_DEFINE_CLASSINFO_DATA(ImageDocument, nsHTMLDocumentSH,
- DOCUMENT_SCRIPTABLE_FLAGS)
-
#ifdef MOZ_XUL
NS_DEFINE_CLASSINFO_DATA(XULTemplateBuilder, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS)
@@ -1883,12 +1878,6 @@ nsDOMClassInfo::Init()
#endif
DOM_CLASSINFO_MAP_END
- DOM_CLASSINFO_MAP_BEGIN(ImageDocument, nsIImageDocument)
- DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDocument)
- DOM_CLASSINFO_MAP_ENTRY(nsIImageDocument)
- DOM_CLASSINFO_DOCUMENT_MAP_ENTRIES
- DOM_CLASSINFO_MAP_END
-
#ifdef MOZ_XUL
DOM_CLASSINFO_MAP_BEGIN(XULTemplateBuilder, nsIXULTemplateBuilder)
DOM_CLASSINFO_MAP_ENTRY(nsIXULTemplateBuilder)
diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h
index 3f1d537e4d35..8c579a56cbed 100644
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -82,8 +82,6 @@ DOMCI_CLASS(CSSRect)
// DOM Chrome Window class, almost identical to Window
DOMCI_CLASS(ChromeWindow)
-DOMCI_CLASS(ImageDocument)
-
#ifdef MOZ_XUL
DOMCI_CLASS(XULTemplateBuilder)
DOMCI_CLASS(XULTreeBuilder)
diff --git a/dom/webidl/ImageDocument.webidl b/dom/webidl/ImageDocument.webidl
new file mode 100644
index 000000000000..4f266342a77e
--- /dev/null
+++ b/dom/webidl/ImageDocument.webidl
@@ -0,0 +1,43 @@
+/* -*- Mode: IDL; 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/.
+ *
+ * The origin of this IDL file is:
+ * content/html/document/public/nsIImageDocument.idl
+ */
+
+interface imgIRequest;
+
+interface ImageDocument : HTMLDocument {
+ /* Whether the pref for image resizing has been set. */
+ readonly attribute boolean imageResizingEnabled;
+
+ /* Whether the image is overflowing visible area. */
+ readonly attribute boolean imageIsOverflowing;
+
+ /* Whether the image has been resized to fit visible area. */
+ readonly attribute boolean imageIsResized;
+
+ /* The image request being displayed in the content area */
+ [Throws]
+ readonly attribute imgIRequest? imageRequest;
+
+ /* Resize the image to fit visible area. */
+ void shrinkToFit();
+
+ /* Restore image original size. */
+ void restoreImage();
+
+ /* Restore the image, trying to keep a certain pixel in the same position.
+ * The coordinate system is that of the shrunken image.
+ */
+ void restoreImageTo(long x, long y);
+
+ /* A helper method for switching between states.
+ * The switching logic is as follows. If the image has been resized
+ * restore image original size, otherwise if the image is overflowing
+ * current visible area resize the image to fit the area.
+ */
+ void toggleImageSize();
+};
diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk
index e90c067b4e91..1c6c8845f3a0 100644
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -153,6 +153,7 @@ webidl_files = \
IDBFactory.webidl \
IDBVersionChangeEvent.webidl \
ImageData.webidl \
+ ImageDocument.webidl \
InspectorUtils.webidl \
KeyEvent.webidl \
LinkStyle.webidl \