зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
893bf6ac64
Коммит
a340410615
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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<JSObject*> aScope)
|
||||
{
|
||||
JS::Rooted<JSObject*> 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<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
|
||||
ImageDocument::GetImageRequest(imgIRequest** aImageRequest)
|
||||
{
|
||||
nsCOMPtr<nsIImageLoadingContent> 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<nsIContent> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,31 @@ public:
|
|||
|
||||
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:
|
||||
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,
|
||||
|
|
|
@ -97,8 +97,8 @@ const char* const MediaDocument::sFormatNames[4] =
|
|||
"" // eWithDimAndFile
|
||||
};
|
||||
|
||||
MediaDocument::MediaDocument(bool aUseXPConnectToWrap)
|
||||
: nsHTMLDocument(aUseXPConnectToWrap),
|
||||
MediaDocument::MediaDocument()
|
||||
: nsHTMLDocument(),
|
||||
mDocumentElementInserted(false)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace dom {
|
|||
class MediaDocument : public nsHTMLDocument
|
||||
{
|
||||
public:
|
||||
MediaDocument(bool aUseXPConnectToWrap = false);
|
||||
MediaDocument();
|
||||
virtual ~MediaDocument();
|
||||
|
||||
virtual nsresult Init();
|
||||
|
|
|
@ -10,3 +10,6 @@ EXPORTS += [
|
|||
'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
|
||||
// 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<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));
|
||||
if (obj && !PostCreateWrapper(aCx, obj)) {
|
||||
return nullptr;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 \
|
||||
IDBVersionChangeEvent.webidl \
|
||||
ImageData.webidl \
|
||||
ImageDocument.webidl \
|
||||
InspectorUtils.webidl \
|
||||
KeyEvent.webidl \
|
||||
LinkStyle.webidl \
|
||||
|
|
Загрузка…
Ссылка в новой задаче