2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Morten Nilsen <morten@nilsen.com>
|
|
|
|
* Christian Biesinger <cbiesinger@web.de>
|
|
|
|
* Jan Varga <varga@ku.sk>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsHTMLDocument.h"
|
|
|
|
#include "nsIImageDocument.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgILoader.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsStubImageDecoderObserver.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsMediaDocument.h"
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNSHTMLElement.h"
|
|
|
|
#include "nsContentErrors.h"
|
2009-02-16 03:27:22 -08:00
|
|
|
#include "nsURILoader.h"
|
2008-02-07 11:58:05 -08:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
2009-10-14 19:20:50 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2009-11-19 20:39:11 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2010-01-11 13:45:04 -08:00
|
|
|
#include "nsIScrollableFrame.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define AUTOMATIC_IMAGE_RESIZING_PREF "browser.enable_automatic_image_resizing"
|
2009-07-28 20:02:55 -07:00
|
|
|
#define CLICK_IMAGE_RESIZING_PREF "browser.enable_click_image_resizing"
|
2009-09-09 13:04:05 -07:00
|
|
|
//XXX A hack needed for Firefox's site specific zoom.
|
|
|
|
#define SITE_SPECIFIC_ZOOM "browser.zoom.siteSpecific"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsImageDocument;
|
|
|
|
|
|
|
|
class ImageListener: public nsMediaDocumentStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageListener(nsImageDocument* aDocument);
|
|
|
|
virtual ~ImageListener();
|
|
|
|
|
2010-09-12 08:22:26 -07:00
|
|
|
/* nsIRequestObserver */
|
|
|
|
NS_IMETHOD OnStartRequest(nsIRequest* request, nsISupports *ctxt);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsImageDocument : public nsMediaDocument,
|
|
|
|
public nsIImageDocument,
|
|
|
|
public nsStubImageDecoderObserver,
|
|
|
|
public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsImageDocument();
|
|
|
|
virtual ~nsImageDocument();
|
|
|
|
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual nsresult Init();
|
|
|
|
|
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
PRBool aReset = PR_TRUE,
|
|
|
|
nsIContentSink* aSink = nsnull);
|
|
|
|
|
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
|
|
|
|
virtual void Destroy();
|
2009-09-01 06:15:33 -07:00
|
|
|
virtual void OnPageShow(PRBool aPersisted,
|
|
|
|
nsIDOMEventTarget* aDispatchStartTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_NSIIMAGEDOCUMENT
|
|
|
|
|
|
|
|
// imgIDecoderObserver (override nsStubImageDecoderObserver)
|
|
|
|
NS_IMETHOD OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage);
|
2010-09-12 08:22:26 -07:00
|
|
|
NS_IMETHOD OnStopDecode(imgIRequest *aRequest, nsresult aStatus, const PRUnichar *aStatusArg);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMEventListener
|
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
|
|
|
|
2008-12-03 02:30:26 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsImageDocument, nsMediaDocument)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
friend class ImageListener;
|
2009-11-19 20:39:11 -08:00
|
|
|
|
|
|
|
void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
virtual nsXPCClassInfo* GetClassInfo();
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2008-10-29 22:20:08 -07:00
|
|
|
virtual nsresult CreateSyntheticDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult CheckOverflowing(PRBool changeState);
|
|
|
|
|
|
|
|
void UpdateTitleAndCharset();
|
|
|
|
|
2008-04-21 21:41:38 -07:00
|
|
|
nsresult ScrollImageTo(PRInt32 aX, PRInt32 aY, PRBool restoreImage);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
float GetRatio() {
|
2010-02-22 11:41:19 -08:00
|
|
|
return NS_MIN((float)mVisibleWidth / mImageWidth,
|
2007-03-22 10:30:00 -07:00
|
|
|
(float)mVisibleHeight / mImageHeight);
|
|
|
|
}
|
|
|
|
|
2009-09-01 06:15:33 -07:00
|
|
|
void ResetZoomLevel();
|
2008-02-07 11:58:05 -08:00
|
|
|
float GetZoomLevel();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> mImageContent;
|
|
|
|
|
|
|
|
PRInt32 mVisibleWidth;
|
|
|
|
PRInt32 mVisibleHeight;
|
|
|
|
PRInt32 mImageWidth;
|
|
|
|
PRInt32 mImageHeight;
|
|
|
|
|
|
|
|
PRPackedBool mResizeImageByDefault;
|
2009-07-28 20:02:55 -07:00
|
|
|
PRPackedBool mClickResizingEnabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRPackedBool mImageIsOverflowing;
|
|
|
|
// mImageIsResized is true if the image is currently resized
|
|
|
|
PRPackedBool 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
|
|
|
|
PRPackedBool mShouldResize;
|
|
|
|
PRPackedBool mFirstResize;
|
2008-08-01 13:58:59 -07:00
|
|
|
// mObservingImageLoader is true while the observer is set.
|
|
|
|
PRPackedBool mObservingImageLoader;
|
2009-09-01 06:15:33 -07:00
|
|
|
|
|
|
|
float mOriginalZoomLevel;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ImageListener::ImageListener(nsImageDocument* aDocument)
|
|
|
|
: nsMediaDocumentStreamListener(aDocument)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageListener::~ImageListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsImageDocument *imgDoc = (nsImageDocument*)mDocument.get();
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (!channel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> domWindow =
|
|
|
|
do_QueryInterface(imgDoc->GetScriptGlobalObject());
|
|
|
|
NS_ENSURE_TRUE(domWindow, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// Do a ShouldProcess check to see whether to keep loading the image.
|
|
|
|
nsCOMPtr<nsIURI> channelURI;
|
|
|
|
channel->GetURI(getter_AddRefs(channelURI));
|
|
|
|
|
|
|
|
nsCAutoString mimeType;
|
|
|
|
channel->GetContentType(mimeType);
|
2007-08-07 18:16:09 -07:00
|
|
|
|
|
|
|
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
nsCOMPtr<nsIPrincipal> channelPrincipal;
|
|
|
|
if (secMan) {
|
|
|
|
secMan->GetChannelPrincipal(channel, getter_AddRefs(channelPrincipal));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt16 decision = nsIContentPolicy::ACCEPT;
|
|
|
|
nsresult rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_IMAGE,
|
|
|
|
channelURI,
|
2007-08-07 18:16:09 -07:00
|
|
|
channelPrincipal,
|
2007-03-22 10:30:00 -07:00
|
|
|
domWindow->GetFrameElementInternal(),
|
|
|
|
mimeType,
|
|
|
|
nsnull,
|
|
|
|
&decision,
|
2007-08-07 18:16:09 -07:00
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
secMan);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv) || NS_CP_REJECTED(decision)) {
|
|
|
|
request->Cancel(NS_ERROR_CONTENT_BLOCKED);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(imgDoc->mImageContent);
|
|
|
|
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
imageLoader->AddObserver(imgDoc);
|
2008-08-01 13:58:59 -07:00
|
|
|
imgDoc->mObservingImageLoader = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
imageLoader->LoadImageWithChannel(channel, getter_AddRefs(mNextStream));
|
|
|
|
|
|
|
|
return nsMediaDocumentStreamListener::OnStartRequest(request, ctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2009-09-01 06:15:33 -07:00
|
|
|
nsImageDocument::nsImageDocument() : mOriginalZoomLevel(1.0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageDocument::~nsImageDocument()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-03 02:30:26 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsImageDocument)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsImageDocument, nsMediaDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mImageContent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsImageDocument, nsMediaDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mImageContent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsImageDocument, nsMediaDocument)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsImageDocument, nsMediaDocument)
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
DOMCI_NODE_DATA(ImageDocument, nsImageDocument)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2010-12-02 08:18:51 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsImageDocument)
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(nsImageDocument)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsImageDocument, nsIImageDocument)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsImageDocument, imgIDecoderObserver)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsImageDocument, imgIContainerObserver)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsImageDocument, nsIDOMEventListener)
|
|
|
|
NS_OFFSET_AND_INTERFACE_TABLE_END
|
|
|
|
NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ImageDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsMediaDocument)
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageDocument::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = nsMediaDocument::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mResizeImageByDefault =
|
|
|
|
nsContentUtils::GetBoolPref(AUTOMATIC_IMAGE_RESIZING_PREF);
|
2009-07-28 20:02:55 -07:00
|
|
|
mClickResizingEnabled =
|
|
|
|
nsContentUtils::GetBoolPref(CLICK_IMAGE_RESIZING_PREF);
|
2007-03-22 10:30:00 -07:00
|
|
|
mShouldResize = mResizeImageByDefault;
|
|
|
|
mFirstResize = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
PRBool aReset,
|
|
|
|
nsIContentSink* aSink)
|
|
|
|
{
|
|
|
|
nsresult rv =
|
|
|
|
nsMediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
|
|
|
|
aContainer, aDocListener, aReset,
|
|
|
|
aSink);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-09-09 13:04:05 -07:00
|
|
|
mOriginalZoomLevel =
|
|
|
|
nsContentUtils::GetBoolPref(SITE_SPECIFIC_ZOOM, PR_FALSE) ?
|
|
|
|
1.0 : GetZoomLevel();
|
2009-09-01 06:15:33 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aDocListener, "null aDocListener");
|
|
|
|
*aDocListener = new ImageListener(this);
|
|
|
|
if (!*aDocListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aDocListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageDocument::Destroy()
|
|
|
|
{
|
|
|
|
if (mImageContent) {
|
|
|
|
// Remove our event listener from the image content.
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mImageContent);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
|
|
|
|
|
|
|
|
// Break reference cycle with mImageContent, if we have one
|
2008-08-01 13:58:59 -07:00
|
|
|
if (mObservingImageLoader) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->RemoveObserver(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mImageContent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMediaDocument::Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
|
|
|
{
|
|
|
|
// If the script global object is changing, we need to unhook our event
|
|
|
|
// listeners on the window.
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
if (mScriptGlobalObject &&
|
|
|
|
aScriptGlobalObject != mScriptGlobalObject) {
|
|
|
|
target = do_QueryInterface(mScriptGlobalObject);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this,
|
|
|
|
PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the script global object on the superclass before doing
|
|
|
|
// anything that might require it....
|
|
|
|
nsHTMLDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
|
|
|
|
|
|
|
if (aScriptGlobalObject) {
|
2010-04-30 06:12:05 -07:00
|
|
|
if (!GetRootElement()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Create synthetic document
|
2008-09-23 21:37:56 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
CreateSyntheticDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");
|
|
|
|
|
|
|
|
target = do_QueryInterface(mImageContent);
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
target = do_QueryInterface(aScriptGlobalObject);
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("keypress"), this, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 06:15:33 -07:00
|
|
|
void
|
|
|
|
nsImageDocument::OnPageShow(PRBool aPersisted,
|
|
|
|
nsIDOMEventTarget* aDispatchStartTarget)
|
|
|
|
{
|
|
|
|
if (aPersisted) {
|
2009-09-09 13:04:05 -07:00
|
|
|
mOriginalZoomLevel =
|
|
|
|
nsContentUtils::GetBoolPref(SITE_SPECIFIC_ZOOM, PR_FALSE) ?
|
|
|
|
1.0 : GetZoomLevel();
|
2009-09-01 06:15:33 -07:00
|
|
|
}
|
|
|
|
nsMediaDocument::OnPageShow(aPersisted, aDispatchStartTarget);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::GetImageResizingEnabled(PRBool* aImageResizingEnabled)
|
|
|
|
{
|
|
|
|
*aImageResizingEnabled = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::GetImageIsOverflowing(PRBool* aImageIsOverflowing)
|
|
|
|
{
|
|
|
|
*aImageIsOverflowing = mImageIsOverflowing;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::GetImageIsResized(PRBool* aImageIsResized)
|
|
|
|
{
|
|
|
|
*aImageIsResized = mImageIsResized;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::GetImageRequest(imgIRequest** aImageRequest)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
return imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
aImageRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aImageRequest = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::ShrinkToFit()
|
|
|
|
{
|
2010-10-14 21:03:33 -07:00
|
|
|
if (!mImageContent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-14 19:20:50 -07:00
|
|
|
if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized &&
|
|
|
|
!nsContentUtils::IsChildOfSameType(this)) {
|
2008-02-07 11:58:05 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-05 06:24:30 -07:00
|
|
|
// Keep image content alive while changing the attributes.
|
|
|
|
nsCOMPtr<nsIContent> imageContent = mImageContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(mImageContent);
|
2010-02-22 11:41:19 -08:00
|
|
|
image->SetWidth(NS_MAX(1, NSToCoordFloor(GetRatio() * mImageWidth)));
|
|
|
|
image->SetHeight(NS_MAX(1, NSToCoordFloor(GetRatio() * mImageHeight)));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-21 21:41:38 -07:00
|
|
|
// 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, PR_FALSE);
|
|
|
|
|
2007-08-05 06:24:30 -07:00
|
|
|
imageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
|
|
|
|
NS_LITERAL_STRING("cursor: -moz-zoom-in"), PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mImageIsResized = PR_TRUE;
|
|
|
|
|
|
|
|
UpdateTitleAndCharset();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::RestoreImageTo(PRInt32 aX, PRInt32 aY)
|
2008-04-21 21:41:38 -07:00
|
|
|
{
|
|
|
|
return ScrollImageTo(aX, aY, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageDocument::ScrollImageTo(PRInt32 aX, PRInt32 aY, PRBool restoreImage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
float ratio = GetRatio();
|
|
|
|
|
2008-04-21 21:41:38 -07:00
|
|
|
if (restoreImage) {
|
|
|
|
RestoreImage();
|
|
|
|
FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *shell = GetShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!shell)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-11 13:45:04 -08:00
|
|
|
nsIScrollableFrame* sf = shell->GetRootScrollFrameAsScrollable();
|
|
|
|
if (!sf)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-11 13:45:04 -08:00
|
|
|
nsRect portRect = sf->GetScrollPortRect();
|
|
|
|
sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(aX/ratio) - portRect.width/2,
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aY/ratio) - portRect.height/2),
|
|
|
|
nsIScrollableFrame::INSTANT);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::RestoreImage()
|
|
|
|
{
|
2010-10-14 21:03:33 -07:00
|
|
|
if (!mImageContent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-05 06:24:30 -07:00
|
|
|
// Keep image content alive while changing the attributes.
|
|
|
|
nsCOMPtr<nsIContent> imageContent = mImageContent;
|
|
|
|
imageContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::width, PR_TRUE);
|
|
|
|
imageContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::height, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mImageIsOverflowing) {
|
2007-08-05 06:24:30 -07:00
|
|
|
imageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
|
|
|
|
NS_LITERAL_STRING("cursor: -moz-zoom-out"), PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-08-05 06:24:30 -07:00
|
|
|
imageContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mImageIsResized = PR_FALSE;
|
|
|
|
|
|
|
|
UpdateTitleAndCharset();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::ToggleImageSize()
|
|
|
|
{
|
|
|
|
mShouldResize = PR_TRUE;
|
|
|
|
if (mImageIsResized) {
|
|
|
|
mShouldResize = PR_FALSE;
|
2009-09-01 06:15:33 -07:00
|
|
|
ResetZoomLevel();
|
2007-03-22 10:30:00 -07:00
|
|
|
RestoreImage();
|
|
|
|
}
|
|
|
|
else if (mImageIsOverflowing) {
|
2009-09-01 06:15:33 -07:00
|
|
|
ResetZoomLevel();
|
2007-03-22 10:30:00 -07:00
|
|
|
ShrinkToFit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage)
|
|
|
|
{
|
|
|
|
aImage->GetWidth(&mImageWidth);
|
|
|
|
aImage->GetHeight(&mImageHeight);
|
2009-11-19 20:39:11 -08:00
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2010-04-20 16:21:35 -07:00
|
|
|
NS_NewRunnableMethod(this, &nsImageDocument::DefaultCheckOverflowing);
|
2009-11-19 20:39:11 -08:00
|
|
|
nsContentUtils::AddScriptRunner(runnable);
|
2007-03-22 10:30:00 -07:00
|
|
|
UpdateTitleAndCharset();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-12 08:22:26 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar *aStatusArg)
|
|
|
|
{
|
|
|
|
UpdateTitleAndCharset();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
mObservingImageLoader = PR_FALSE;
|
|
|
|
imageLoader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mImageContent can be null if the document is already destroyed
|
|
|
|
if (NS_FAILED(aStatus) && mStringBundle && mImageContent) {
|
|
|
|
nsCAutoString src;
|
|
|
|
mDocumentURI->GetSpec(src);
|
|
|
|
NS_ConvertUTF8toUTF16 srcString(src);
|
|
|
|
const PRUnichar* formatString[] = { srcString.get() };
|
|
|
|
nsXPIDLString errorMsg;
|
|
|
|
NS_NAMED_LITERAL_STRING(str, "InvalidImage");
|
|
|
|
mStringBundle->FormatStringFromName(str.get(), formatString, 1,
|
|
|
|
getter_Copies(errorMsg));
|
|
|
|
|
|
|
|
mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, errorMsg, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageDocument::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
if (eventType.EqualsLiteral("resize")) {
|
|
|
|
CheckOverflowing(PR_FALSE);
|
|
|
|
}
|
2009-07-28 20:02:55 -07:00
|
|
|
else if (eventType.EqualsLiteral("click") && mClickResizingEnabled) {
|
2009-09-01 06:15:33 -07:00
|
|
|
ResetZoomLevel();
|
2007-03-22 10:30:00 -07:00
|
|
|
mShouldResize = PR_TRUE;
|
|
|
|
if (mImageIsResized) {
|
|
|
|
PRInt32 x = 0, y = 0;
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> event(do_QueryInterface(aEvent));
|
|
|
|
if (event) {
|
|
|
|
event->GetClientX(&x);
|
|
|
|
event->GetClientY(&y);
|
|
|
|
PRInt32 left = 0, top = 0;
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLElement> nsElement(do_QueryInterface(mImageContent));
|
|
|
|
nsElement->GetOffsetLeft(&left);
|
|
|
|
nsElement->GetOffsetTop(&top);
|
|
|
|
x -= left;
|
|
|
|
y -= top;
|
|
|
|
}
|
|
|
|
mShouldResize = PR_FALSE;
|
|
|
|
RestoreImageTo(x, y);
|
|
|
|
}
|
|
|
|
else if (mImageIsOverflowing) {
|
|
|
|
ShrinkToFit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eventType.EqualsLiteral("keypress")) {
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
|
|
|
|
PRUint32 charCode;
|
2008-06-10 17:22:03 -07:00
|
|
|
PRBool ctrlKey, metaKey, altKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->GetCharCode(&charCode);
|
2008-06-10 17:22:03 -07:00
|
|
|
keyEvent->GetCtrlKey(&ctrlKey);
|
|
|
|
keyEvent->GetMetaKey(&metaKey);
|
|
|
|
keyEvent->GetAltKey(&altKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
// plus key
|
2008-06-10 17:22:03 -07:00
|
|
|
if (charCode == 0x2B && !ctrlKey && !metaKey && !altKey) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mShouldResize = PR_FALSE;
|
|
|
|
if (mImageIsResized) {
|
2009-09-01 06:15:33 -07:00
|
|
|
ResetZoomLevel();
|
2007-03-22 10:30:00 -07:00
|
|
|
RestoreImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// minus key
|
2008-06-10 17:22:03 -07:00
|
|
|
else if (charCode == 0x2D && !ctrlKey && !metaKey && !altKey) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mShouldResize = PR_TRUE;
|
|
|
|
if (mImageIsOverflowing) {
|
2009-09-01 06:15:33 -07:00
|
|
|
ResetZoomLevel();
|
2007-03-22 10:30:00 -07:00
|
|
|
ShrinkToFit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageDocument::CreateSyntheticDocument()
|
|
|
|
{
|
|
|
|
// Synthesize an html document that refers to the image
|
|
|
|
nsresult rv = nsMediaDocument::CreateSyntheticDocument();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* body = GetBodyElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on image document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-12 15:32:18 -07:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::img, nsnull,
|
2009-06-09 00:41:19 -07:00
|
|
|
kNameSpaceID_XHTML);
|
2008-09-25 15:46:52 -07:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
mImageContent = NS_NewHTMLImageElement(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mImageContent) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
|
|
|
|
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCAutoString src;
|
|
|
|
mDocumentURI->GetSpec(src);
|
|
|
|
|
2011-01-31 20:50:01 -08:00
|
|
|
// Push a null JSContext on the stack so that code that runs within
|
|
|
|
// the below code doesn't think it's being called by JS. See bug
|
|
|
|
// 604262.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ConvertUTF8toUTF16 srcString(src);
|
|
|
|
// Make sure not to start the image load from here...
|
|
|
|
imageLoader->SetLoadingEnabled(PR_FALSE);
|
|
|
|
mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src, srcString, PR_FALSE);
|
|
|
|
mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, srcString, PR_FALSE);
|
|
|
|
|
|
|
|
body->AppendChildTo(mImageContent, PR_FALSE);
|
|
|
|
imageLoader->SetLoadingEnabled(PR_TRUE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageDocument::CheckOverflowing(PRBool changeState)
|
|
|
|
{
|
2007-07-26 13:20:30 -07:00
|
|
|
/* Create a scope so that the style context gets destroyed before we might
|
2008-01-09 01:38:28 -08:00
|
|
|
* call RebuildStyleData. Also, holding onto pointers to the
|
2007-07-26 13:20:30 -07:00
|
|
|
* presentatation through style resolution is potentially dangerous.
|
|
|
|
*/
|
|
|
|
{
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *shell = GetShell();
|
2007-07-26 13:20:30 -07:00
|
|
|
if (!shell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-26 13:20:30 -07:00
|
|
|
nsPresContext *context = shell->GetPresContext();
|
|
|
|
nsRect visibleArea = context->GetVisibleArea();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* body = GetBodyElement();
|
|
|
|
if (!body) {
|
2007-07-26 13:20:30 -07:00
|
|
|
NS_WARNING("no body on image document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-26 13:20:30 -07:00
|
|
|
nsRefPtr<nsStyleContext> styleContext =
|
2010-04-30 06:12:05 -07:00
|
|
|
context->StyleSet()->ResolveStyleFor(body, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-26 13:20:30 -07:00
|
|
|
nsMargin m;
|
|
|
|
if (styleContext->GetStyleMargin()->GetMargin(m))
|
|
|
|
visibleArea.Deflate(m);
|
2008-07-16 23:30:25 -07:00
|
|
|
m = styleContext->GetStyleBorder()->GetActualBorder();
|
2007-03-22 10:30:00 -07:00
|
|
|
visibleArea.Deflate(m);
|
2007-07-26 13:20:30 -07:00
|
|
|
if (styleContext->GetStylePadding()->GetPadding(m))
|
|
|
|
visibleArea.Deflate(m);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-14 19:20:50 -07:00
|
|
|
mVisibleWidth = nsPresContext::AppUnitsToIntCSSPixels(visibleArea.width);
|
|
|
|
mVisibleHeight = nsPresContext::AppUnitsToIntCSSPixels(visibleArea.height);
|
2007-07-26 13:20:30 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool imageWasOverflowing = mImageIsOverflowing;
|
|
|
|
mImageIsOverflowing =
|
|
|
|
mImageWidth > mVisibleWidth || mImageHeight > mVisibleHeight;
|
|
|
|
PRBool windowBecameBigEnough = imageWasOverflowing && !mImageIsOverflowing;
|
|
|
|
|
|
|
|
if (changeState || mShouldResize || mFirstResize ||
|
|
|
|
windowBecameBigEnough) {
|
|
|
|
if (mImageIsOverflowing && (changeState || mShouldResize)) {
|
|
|
|
ShrinkToFit();
|
|
|
|
}
|
|
|
|
else if (mImageIsResized || mFirstResize || windowBecameBigEnough) {
|
|
|
|
RestoreImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFirstResize = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageDocument::UpdateTitleAndCharset()
|
|
|
|
{
|
|
|
|
nsCAutoString typeStr;
|
|
|
|
nsCOMPtr<imgIRequest> imageRequest;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imageRequest));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imageRequest) {
|
|
|
|
nsXPIDLCString mimeType;
|
|
|
|
imageRequest->GetMimeType(getter_Copies(mimeType));
|
|
|
|
ToUpperCase(mimeType);
|
|
|
|
nsXPIDLCString::const_iterator start, end;
|
|
|
|
mimeType.BeginReading(start);
|
|
|
|
mimeType.EndReading(end);
|
|
|
|
nsXPIDLCString::const_iterator iter = end;
|
|
|
|
if (FindInReadable(NS_LITERAL_CSTRING("IMAGE/"), start, iter) &&
|
|
|
|
iter != end) {
|
|
|
|
// strip out "X-" if any
|
|
|
|
if (*iter == 'X') {
|
|
|
|
++iter;
|
|
|
|
if (iter != end && *iter == '-') {
|
|
|
|
++iter;
|
|
|
|
if (iter == end) {
|
|
|
|
// looks like "IMAGE/X-" is the type?? Bail out of here.
|
|
|
|
mimeType.BeginReading(iter);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
--iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
typeStr = Substring(iter, end);
|
|
|
|
} else {
|
|
|
|
typeStr = mimeType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLString status;
|
|
|
|
if (mImageIsResized) {
|
|
|
|
nsAutoString ratioStr;
|
|
|
|
ratioStr.AppendInt(NSToCoordFloor(GetRatio() * 100));
|
|
|
|
|
|
|
|
const PRUnichar* formatString[1] = { ratioStr.get() };
|
|
|
|
mStringBundle->FormatStringFromName(NS_LITERAL_STRING("ScaledImage").get(),
|
|
|
|
formatString, 1,
|
|
|
|
getter_Copies(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* const formatNames[4] =
|
|
|
|
{
|
|
|
|
"ImageTitleWithNeitherDimensionsNorFile",
|
|
|
|
"ImageTitleWithoutDimensions",
|
|
|
|
"ImageTitleWithDimensions",
|
|
|
|
"ImageTitleWithDimensionsAndFile",
|
|
|
|
};
|
|
|
|
|
|
|
|
nsMediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
|
|
|
|
mImageWidth, mImageHeight, status);
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:58:05 -08:00
|
|
|
void
|
2009-09-01 06:15:33 -07:00
|
|
|
nsImageDocument::ResetZoomLevel()
|
2008-02-07 11:58:05 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
|
|
|
|
if (docShell) {
|
2009-10-14 19:20:50 -07:00
|
|
|
if (nsContentUtils::IsChildOfSameType(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:58:05 -08:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(cv);
|
|
|
|
if (mdv) {
|
2009-09-01 06:15:33 -07:00
|
|
|
mdv->SetFullZoom(mOriginalZoomLevel);
|
2008-02-07 11:58:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
nsImageDocument::GetZoomLevel()
|
|
|
|
{
|
2009-09-01 06:15:33 -07:00
|
|
|
float zoomLevel = mOriginalZoomLevel;
|
2008-02-07 11:58:05 -08:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(cv);
|
|
|
|
if (mdv) {
|
|
|
|
mdv->GetFullZoom(&zoomLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return zoomLevel;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewImageDocument(nsIDocument** aResult)
|
|
|
|
{
|
|
|
|
nsImageDocument* doc = new nsImageDocument();
|
|
|
|
if (!doc) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = doc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|