Bug 868929 - Convert ImageDocument to WebIDL, switch to WebIDL. r=bz.

--HG--
rename : content/html/document/src/ImageDocument.cpp => content/html/document/src/ImageDocument.h
extra : rebase_source : 18af4f816c456e9a642f12b504651b19765141dc
This commit is contained in:
Peter Van der Beken 2013-05-06 15:42:00 +02:00
Родитель 893bf6ac64
Коммит a340410615
12 изменённых файлов: 143 добавлений и 59 удалений

Просмотреть файл

@ -11,7 +11,7 @@
interface imgIRequest; interface imgIRequest;
[scriptable, uuid(7b80eebc-c98e-4461-8bdb-6e3b6e828890)] [scriptable, uuid(87c27f98-37dc-4b64-a8cd-92003624bcee)]
interface nsIImageDocument : nsISupports { interface nsIImageDocument : nsISupports {
/* Whether the pref for image resizing has been set. */ /* Whether the pref for image resizing has been set. */
@ -27,14 +27,17 @@ interface nsIImageDocument : nsISupports {
readonly attribute imgIRequest imageRequest; readonly attribute imgIRequest imageRequest;
/* Resize the image to fit visible area. */ /* Resize the image to fit visible area. */
[binaryname(DOMShrinkToFit)]
void shrinkToFit(); void shrinkToFit();
/* Restore image original size. */ /* Restore image original size. */
[binaryname(DOMRestoreImage)]
void restoreImage(); void restoreImage();
/* Restore the image, trying to keep a certain pixel in the same position. /* Restore the image, trying to keep a certain pixel in the same position.
* The coordinate system is that of the shrunken image. * The coordinate system is that of the shrunken image.
*/ */
[binaryname(DOMRestoreImageTo)]
void restoreImageTo(in long x, in long y); void restoreImageTo(in long x, in long y);
/* A helper method for switching between states. /* A helper method for switching between states.
@ -42,5 +45,6 @@ interface nsIImageDocument : nsISupports {
* restore image original size, otherwise if the image is overflowing * restore image original size, otherwise if the image is overflowing
* current visible area resize the image to fit the area. * current visible area resize the image to fit the area.
*/ */
[binaryname(DOMToggleImageSize)]
void toggleImageSize(); void toggleImageSize();
}; };

Просмотреть файл

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ImageDocument.h" #include "ImageDocument.h"
#include "mozilla/dom/ImageDocumentBinding.h"
#include "nsRect.h" #include "nsRect.h"
#include "nsIImageLoadingContent.h" #include "nsIImageLoadingContent.h"
#include "nsGenericHTMLElement.h" #include "nsGenericHTMLElement.h"
@ -124,7 +125,7 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
} }
ImageDocument::ImageDocument() ImageDocument::ImageDocument()
: MediaDocument(true), : MediaDocument(),
mOriginalZoomLevel(1.0) mOriginalZoomLevel(1.0)
{ {
// NOTE! nsDocument::operator new() zeroes out all members, so don't // 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_ADDREF_INHERITED(ImageDocument, MediaDocument)
NS_IMPL_RELEASE_INHERITED(ImageDocument, MediaDocument) NS_IMPL_RELEASE_INHERITED(ImageDocument, MediaDocument)
DOMCI_NODE_DATA(ImageDocument, ImageDocument)
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(ImageDocument) NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(ImageDocument)
NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(ImageDocument) NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(ImageDocument)
NS_INTERFACE_TABLE_ENTRY(ImageDocument, nsIImageDocument) 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_INTERFACE_TABLE_ENTRY(ImageDocument, nsIDOMEventListener)
NS_OFFSET_AND_INTERFACE_TABLE_END NS_OFFSET_AND_INTERFACE_TABLE_END
NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ImageDocument)
NS_INTERFACE_MAP_END_INHERITING(MediaDocument) NS_INTERFACE_MAP_END_INHERITING(MediaDocument)
@ -174,6 +172,16 @@ ImageDocument::Init()
return NS_OK; return NS_OK;
} }
JSObject*
ImageDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
JS::Rooted<JSObject*> obj(aCx, ImageDocumentBinding::Wrap(aCx, aScope, this));
if (obj && !PostCreateWrapper(aCx, obj)) {
return nullptr;
}
return obj;
}
nsresult nsresult
ImageDocument::StartDocumentLoad(const char* aCommand, ImageDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel, nsIChannel* aChannel,
@ -287,46 +295,53 @@ ImageDocument::OnPageShow(bool aPersisted,
NS_IMETHODIMP NS_IMETHODIMP
ImageDocument::GetImageResizingEnabled(bool* aImageResizingEnabled) ImageDocument::GetImageResizingEnabled(bool* aImageResizingEnabled)
{ {
*aImageResizingEnabled = true; *aImageResizingEnabled = ImageResizingEnabled();
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageDocument::GetImageIsOverflowing(bool* aImageIsOverflowing) ImageDocument::GetImageIsOverflowing(bool* aImageIsOverflowing)
{ {
*aImageIsOverflowing = mImageIsOverflowing; *aImageIsOverflowing = ImageIsOverflowing();
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageDocument::GetImageIsResized(bool* aImageIsResized) ImageDocument::GetImageIsResized(bool* aImageIsResized)
{ {
*aImageIsResized = mImageIsResized; *aImageIsResized = ImageIsResized();
return NS_OK; return NS_OK;
} }
already_AddRefed<imgIRequest>
ImageDocument::GetImageRequest(ErrorResult& aRv)
{
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
nsCOMPtr<imgIRequest> imageRequest;
if (imageLoader) {
aRv = imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
getter_AddRefs(imageRequest));
}
return imageRequest.forget();
}
NS_IMETHODIMP NS_IMETHODIMP
ImageDocument::GetImageRequest(imgIRequest** aImageRequest) ImageDocument::GetImageRequest(imgIRequest** aImageRequest)
{ {
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent); ErrorResult rv;
if (imageLoader) { *aImageRequest = GetImageRequest(rv).get();
return imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, return rv.ErrorCode();
aImageRequest);
}
*aImageRequest = nullptr;
return NS_OK;
} }
NS_IMETHODIMP void
ImageDocument::ShrinkToFit() ImageDocument::ShrinkToFit()
{ {
if (!mImageContent) { if (!mImageContent) {
return NS_OK; return;
} }
if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized && if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized &&
!nsContentUtils::IsChildOfSameType(this)) { !nsContentUtils::IsChildOfSameType(this)) {
return NS_OK; return;
} }
// Keep image content alive while changing the attributes. // 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 // The view might have been scrolled when zooming in, scroll back to the
// origin now that we're showing a shrunk-to-window version. // origin now that we're showing a shrunk-to-window version.
(void) ScrollImageTo(0, 0, false); ScrollImageTo(0, 0, false);
SetModeClass(eShrinkToFit); SetModeClass(eShrinkToFit);
mImageIsResized = true; mImageIsResized = true;
UpdateTitleAndCharset(); UpdateTitleAndCharset();
}
NS_IMETHODIMP
ImageDocument::DOMShrinkToFit()
{
ShrinkToFit();
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP 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) ImageDocument::ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage)
{ {
float ratio = GetRatio(); float ratio = GetRatio();
@ -366,24 +387,23 @@ ImageDocument::ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage)
nsIPresShell *shell = GetShell(); nsIPresShell *shell = GetShell();
if (!shell) if (!shell)
return NS_OK; return;
nsIScrollableFrame* sf = shell->GetRootScrollFrameAsScrollable(); nsIScrollableFrame* sf = shell->GetRootScrollFrameAsScrollable();
if (!sf) if (!sf)
return NS_OK; return;
nsRect portRect = sf->GetScrollPortRect(); nsRect portRect = sf->GetScrollPortRect();
sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(aX/ratio) - portRect.width/2, sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(aX/ratio) - portRect.width/2,
nsPresContext::CSSPixelsToAppUnits(aY/ratio) - portRect.height/2), nsPresContext::CSSPixelsToAppUnits(aY/ratio) - portRect.height/2),
nsIScrollableFrame::INSTANT); nsIScrollableFrame::INSTANT);
return NS_OK;
} }
NS_IMETHODIMP void
ImageDocument::RestoreImage() ImageDocument::RestoreImage()
{ {
if (!mImageContent) { if (!mImageContent) {
return NS_OK; return;
} }
// Keep image content alive while changing the attributes. // Keep image content alive while changing the attributes.
nsCOMPtr<nsIContent> imageContent = mImageContent; nsCOMPtr<nsIContent> imageContent = mImageContent;
@ -400,11 +420,16 @@ ImageDocument::RestoreImage()
mImageIsResized = false; mImageIsResized = false;
UpdateTitleAndCharset(); UpdateTitleAndCharset();
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageDocument::DOMRestoreImage()
{
RestoreImage();
return NS_OK;
}
void
ImageDocument::ToggleImageSize() ImageDocument::ToggleImageSize()
{ {
mShouldResize = true; mShouldResize = true;
@ -417,7 +442,12 @@ ImageDocument::ToggleImageSize()
ResetZoomLevel(); ResetZoomLevel();
ShrinkToFit(); ShrinkToFit();
} }
}
NS_IMETHODIMP
ImageDocument::DOMToggleImageSize()
{
ToggleImageSize();
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -51,7 +51,31 @@ public:
void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); } void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
virtual nsXPCClassInfo* GetClassInfo(); // WebIDL API
virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
MOZ_OVERRIDE;
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();
protected: protected:
virtual nsresult CreateSyntheticDocument(); virtual nsresult CreateSyntheticDocument();
@ -59,7 +83,7 @@ protected:
void UpdateTitleAndCharset(); void UpdateTitleAndCharset();
nsresult ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage); void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
float GetRatio() { float GetRatio() {
return std::min(mVisibleWidth / mImageWidth, return std::min(mVisibleWidth / mImageWidth,

Просмотреть файл

@ -97,8 +97,8 @@ const char* const MediaDocument::sFormatNames[4] =
"" // eWithDimAndFile "" // eWithDimAndFile
}; };
MediaDocument::MediaDocument(bool aUseXPConnectToWrap) MediaDocument::MediaDocument()
: nsHTMLDocument(aUseXPConnectToWrap), : nsHTMLDocument(),
mDocumentElementInserted(false) mDocumentElementInserted(false)
{ {
} }

Просмотреть файл

@ -19,7 +19,7 @@ namespace dom {
class MediaDocument : public nsHTMLDocument class MediaDocument : public nsHTMLDocument
{ {
public: public:
MediaDocument(bool aUseXPConnectToWrap = false); MediaDocument();
virtual ~MediaDocument(); virtual ~MediaDocument();
virtual nsresult Init(); virtual nsresult Init();

Просмотреть файл

@ -10,3 +10,6 @@ EXPORTS += [
'nsIHTMLDocument.h', 'nsIHTMLDocument.h',
] ]
EXPORTS.mozilla.dom += [
'ImageDocument.h',
]

Просмотреть файл

@ -197,7 +197,7 @@ NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
// NOTE! nsDocument::operator new() zeroes out all members, so don't // NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0. // bother initializing members to 0.
nsHTMLDocument::nsHTMLDocument(bool aUseXPConnectToWrap) nsHTMLDocument::nsHTMLDocument()
: nsDocument("text/html") : nsDocument("text/html")
{ {
// NOTE! nsDocument::operator new() zeroes out all members, so don't // NOTE! nsDocument::operator new() zeroes out all members, so don't
@ -207,9 +207,7 @@ nsHTMLDocument::nsHTMLDocument(bool aUseXPConnectToWrap)
mDefaultElementType = kNameSpaceID_XHTML; mDefaultElementType = kNameSpaceID_XHTML;
mCompatMode = eCompatibility_NavQuirks; mCompatMode = eCompatibility_NavQuirks;
if (!aUseXPConnectToWrap) { SetIsDOMBinding();
SetIsDOMBinding();
}
} }
@ -260,12 +258,6 @@ NS_INTERFACE_MAP_END_INHERITING(nsDocument)
JSObject* JSObject*
nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope) nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
{ {
#ifdef DEBUG
// Don't do it yet for image documents
nsCOMPtr<nsIImageDocument> imgDoc = do_QueryObject(this);
MOZ_ASSERT(!imgDoc, "Who called SetIsDOMBinding()?");
#endif
JS::Rooted<JSObject*> obj(aCx, HTMLDocumentBinding::Wrap(aCx, aScope, this)); JS::Rooted<JSObject*> obj(aCx, HTMLDocumentBinding::Wrap(aCx, aScope, this));
if (obj && !PostCreateWrapper(aCx, obj)) { if (obj && !PostCreateWrapper(aCx, obj)) {
return nullptr; return nullptr;

Просмотреть файл

@ -42,7 +42,7 @@ public:
using nsDocument::SetDocumentURI; using nsDocument::SetDocumentURI;
using nsDocument::GetPlugins; using nsDocument::GetPlugins;
nsHTMLDocument(bool aUseXPConnectToWrap = false); nsHTMLDocument();
virtual nsresult Init(); virtual nsresult Init();
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);

Просмотреть файл

@ -221,8 +221,6 @@
#include "nsIDOMSVGNumber.h" #include "nsIDOMSVGNumber.h"
#include "nsIDOMSVGRect.h" #include "nsIDOMSVGRect.h"
#include "nsIImageDocument.h"
// Storage includes // Storage includes
#include "DOMStorage.h" #include "DOMStorage.h"
@ -662,9 +660,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DEFAULT_SCRIPTABLE_FLAGS | DEFAULT_SCRIPTABLE_FLAGS |
WINDOW_SCRIPTABLE_FLAGS) WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(ImageDocument, nsHTMLDocumentSH,
DOCUMENT_SCRIPTABLE_FLAGS)
#ifdef MOZ_XUL #ifdef MOZ_XUL
NS_DEFINE_CLASSINFO_DATA(XULTemplateBuilder, nsDOMGenericSH, NS_DEFINE_CLASSINFO_DATA(XULTemplateBuilder, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS) DEFAULT_SCRIPTABLE_FLAGS)
@ -1883,12 +1878,6 @@ nsDOMClassInfo::Init()
#endif #endif
DOM_CLASSINFO_MAP_END 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 #ifdef MOZ_XUL
DOM_CLASSINFO_MAP_BEGIN(XULTemplateBuilder, nsIXULTemplateBuilder) DOM_CLASSINFO_MAP_BEGIN(XULTemplateBuilder, nsIXULTemplateBuilder)
DOM_CLASSINFO_MAP_ENTRY(nsIXULTemplateBuilder) DOM_CLASSINFO_MAP_ENTRY(nsIXULTemplateBuilder)

Просмотреть файл

@ -82,8 +82,6 @@ DOMCI_CLASS(CSSRect)
// DOM Chrome Window class, almost identical to Window // DOM Chrome Window class, almost identical to Window
DOMCI_CLASS(ChromeWindow) DOMCI_CLASS(ChromeWindow)
DOMCI_CLASS(ImageDocument)
#ifdef MOZ_XUL #ifdef MOZ_XUL
DOMCI_CLASS(XULTemplateBuilder) DOMCI_CLASS(XULTemplateBuilder)
DOMCI_CLASS(XULTreeBuilder) DOMCI_CLASS(XULTreeBuilder)

Просмотреть файл

@ -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();
};

Просмотреть файл

@ -153,6 +153,7 @@ webidl_files = \
IDBFactory.webidl \ IDBFactory.webidl \
IDBVersionChangeEvent.webidl \ IDBVersionChangeEvent.webidl \
ImageData.webidl \ ImageData.webidl \
ImageDocument.webidl \
InspectorUtils.webidl \ InspectorUtils.webidl \
KeyEvent.webidl \ KeyEvent.webidl \
LinkStyle.webidl \ LinkStyle.webidl \