1998-07-27 17:50:58 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-07-27 17:50:58 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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.
|
1998-07-27 17:50:58 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:40:37 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-07-27 17:50:58 +00:00
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-09 16:19:30 +00:00
|
|
|
#include "nsHTMLDocument.h"
|
1998-07-27 17:50:58 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsIImageGroup.h"
|
|
|
|
#include "nsIImageRequest.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsIHTMLStyleSheet.h"
|
|
|
|
#include "nsIHTMLCSSStyleSheet.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-08-04 21:16:13 +00:00
|
|
|
#include "nsIViewManager.h"
|
1999-07-01 19:30:20 +00:00
|
|
|
#include "nsIChannel.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsINodeInfo.h"
|
2001-02-06 23:39:46 +00:00
|
|
|
// Needed for Localization
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsIStringBundle.h"
|
2001-03-14 07:35:29 +00:00
|
|
|
// Needed to fetch scrollbar prefs for image documents that are iframes/frameset frames
|
|
|
|
#include "nsIScrollable.h"
|
|
|
|
#include "nsWeakReference.h"
|
2001-02-06 23:39:46 +00:00
|
|
|
|
|
|
|
#define NSIMAGEDOCUMENT_PROPERTIES_URI "chrome://communicator/locale/layout/ImageDocument.properties"
|
|
|
|
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
|
|
|
|
|
|
|
// done L10N
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
// XXX TODO:
|
|
|
|
|
|
|
|
// 1. hookup the original stream to the image library directly so that we
|
|
|
|
// don't have to load the image twice.
|
|
|
|
|
|
|
|
// 2. have a synthetic document url that we load that has patterns in it
|
|
|
|
// that we replace with the image url (so that we can customize the
|
|
|
|
// the presentation of the image): we could add script code to set the
|
|
|
|
// width/height to provide scale buttons, we could show the image
|
|
|
|
// attributes; etc.; should we have a seperate style sheet?
|
|
|
|
|
|
|
|
// 3. override the save-as methods so that we don't write out our synthetic
|
|
|
|
// html
|
|
|
|
|
|
|
|
|
1998-09-09 16:19:30 +00:00
|
|
|
class nsImageDocument : public nsHTMLDocument {
|
1998-07-27 17:50:58 +00:00
|
|
|
public:
|
|
|
|
nsImageDocument();
|
|
|
|
virtual ~nsImageDocument();
|
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
NS_IMETHOD StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-15 22:17:54 +00:00
|
|
|
nsISupports* aContainer,
|
2000-05-01 06:58:53 +00:00
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
PRBool aReset = PR_TRUE);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
nsresult CreateSyntheticDocument();
|
1998-09-09 16:19:30 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsresult StartImageLoad(nsIURI* aURL, nsIStreamListener*& aListener);
|
1999-07-07 07:31:24 +00:00
|
|
|
nsresult EndLayout(nsISupports *ctxt,
|
|
|
|
nsresult status,
|
|
|
|
const PRUnichar *errorMsg);
|
2000-01-27 02:15:19 +00:00
|
|
|
nsresult UpdateTitle( void );
|
1998-09-09 16:19:30 +00:00
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
void StartLayout();
|
|
|
|
|
2000-03-16 22:58:12 +00:00
|
|
|
nsIImageRequest* mImageRequest;
|
|
|
|
nscolor mBlack;
|
2001-03-14 07:35:29 +00:00
|
|
|
nsWeakPtr mContainer;
|
1998-07-27 17:50:58 +00:00
|
|
|
};
|
|
|
|
|
1998-09-09 16:19:30 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
class ImageListener : public nsIStreamListener {
|
|
|
|
public:
|
|
|
|
ImageListener(nsImageDocument* aDoc);
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~ImageListener();
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
1999-06-25 01:53:22 +00:00
|
|
|
// nsIStreamObserver methods:
|
1999-08-22 13:26:18 +00:00
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
|
|
|
|
1999-06-25 01:53:22 +00:00
|
|
|
// nsIStreamListener methods:
|
1999-08-22 13:26:18 +00:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
nsImageDocument* mDocument;
|
1998-09-09 16:19:30 +00:00
|
|
|
nsIStreamListener* mNextStream;
|
1998-07-27 17:50:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ImageListener::ImageListener(nsImageDocument* aDoc)
|
|
|
|
{
|
2001-02-20 13:46:59 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
1998-07-27 17:50:58 +00:00
|
|
|
mDocument = aDoc;
|
|
|
|
NS_ADDREF(aDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageListener::~ImageListener()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mDocument);
|
1998-09-09 16:19:30 +00:00
|
|
|
NS_IF_RELEASE(mNextStream);
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 13:46:59 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(ImageListener, nsIStreamListener)
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
1998-07-27 17:50:58 +00:00
|
|
|
{
|
1999-07-01 19:30:20 +00:00
|
|
|
nsresult rv;
|
1999-06-25 01:53:22 +00:00
|
|
|
nsIURI* uri;
|
2001-02-21 20:38:08 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (!channel) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-07-01 19:30:20 +00:00
|
|
|
rv = channel->GetURI(&uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-25 01:53:22 +00:00
|
|
|
|
|
|
|
mDocument->StartImageLoad(uri, mNextStream);
|
1999-07-01 19:30:20 +00:00
|
|
|
NS_RELEASE(uri);
|
1998-09-09 16:19:30 +00:00
|
|
|
if (nsnull == mNextStream) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-02-21 20:38:08 +00:00
|
|
|
return mNextStream->OnStartRequest(request, ctxt);
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
ImageListener::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsresult status, const PRUnichar *errorMsg)
|
1998-07-27 17:50:58 +00:00
|
|
|
{
|
2000-03-16 22:58:12 +00:00
|
|
|
if(mDocument){
|
|
|
|
mDocument->EndLayout(ctxt, status, errorMsg);
|
|
|
|
}
|
|
|
|
|
1998-09-09 16:19:30 +00:00
|
|
|
if (nsnull == mNextStream) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-02-21 20:38:08 +00:00
|
|
|
return mNextStream->OnStopRequest(request, ctxt, status, errorMsg);
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
ImageListener::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
|
1998-07-27 17:50:58 +00:00
|
|
|
{
|
1998-09-09 16:19:30 +00:00
|
|
|
if (nsnull == mNextStream) {
|
|
|
|
return NS_ERROR_FAILURE;
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
2001-02-21 20:38:08 +00:00
|
|
|
return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_LAYOUT nsresult
|
|
|
|
NS_NewImageDocument(nsIDocument** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
nsImageDocument* doc = new nsImageDocument();
|
1999-07-18 06:35:52 +00:00
|
|
|
if(doc)
|
2001-01-04 20:44:42 +00:00
|
|
|
return doc->QueryInterface(NS_GET_IID(nsIDocument), (void**) aInstancePtrResult);
|
1999-07-18 06:35:52 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsImageDocument::nsImageDocument()
|
|
|
|
{
|
1998-09-09 16:19:30 +00:00
|
|
|
mImageRequest = nsnull;
|
|
|
|
mBlack = NS_RGB(0, 0, 0);
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsImageDocument::~nsImageDocument()
|
|
|
|
{
|
1998-09-09 16:19:30 +00:00
|
|
|
NS_IF_RELEASE(mImageRequest);
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-16 11:14:36 +00:00
|
|
|
nsImageDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-15 22:17:54 +00:00
|
|
|
nsISupports* aContainer,
|
2000-05-01 06:58:53 +00:00
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
PRBool aReset)
|
1998-07-27 17:50:58 +00:00
|
|
|
{
|
2001-02-20 13:46:59 +00:00
|
|
|
NS_ASSERTION(aDocListener, "null aDocListener");
|
2001-03-14 07:35:29 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aContainer);
|
|
|
|
mContainer = dont_AddRef(NS_GetWeakReference(aContainer));
|
2001-02-20 13:46:59 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_ALREADY_INITIALIZED) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
|
|
|
|
aContainer, aDocListener, aReset);
|
1998-12-11 02:47:25 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-01-27 02:15:19 +00:00
|
|
|
|
1998-09-09 16:19:30 +00:00
|
|
|
// Create synthetic document
|
|
|
|
rv = CreateSyntheticDocument();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
1998-07-27 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aDocListener = new ImageListener(this);
|
2001-02-20 13:46:59 +00:00
|
|
|
if (!*aDocListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aDocListener);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-09 16:19:30 +00:00
|
|
|
nsresult
|
1999-06-23 03:29:44 +00:00
|
|
|
nsImageDocument::StartImageLoad(nsIURI* aURL, nsIStreamListener*& aListener)
|
1998-09-09 16:19:30 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
aListener = nsnull;
|
|
|
|
|
|
|
|
// Tell image group to load the stream now. This will get the image
|
|
|
|
// hooked up to the open stream and return the underlying listener
|
|
|
|
// so that we can pass it back upwards.
|
|
|
|
nsIPresShell* shell = GetShellAt(0);
|
|
|
|
if (nsnull != shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (cx) {
|
1998-09-09 16:19:30 +00:00
|
|
|
nsIImageGroup* group = nsnull;
|
1999-02-12 17:45:58 +00:00
|
|
|
cx->GetImageGroup(&group);
|
1998-09-09 16:19:30 +00:00
|
|
|
if (nsnull != group) {
|
2000-07-20 01:52:35 +00:00
|
|
|
|
1999-06-25 01:53:22 +00:00
|
|
|
char* spec;
|
1998-12-16 05:40:20 +00:00
|
|
|
(void)aURL->GetSpec(&spec);
|
1998-09-09 16:19:30 +00:00
|
|
|
nsIStreamListener* listener = nsnull;
|
1999-03-17 00:13:31 +00:00
|
|
|
rv = group->GetImageFromStream(spec, nsnull, nsnull,
|
1998-09-09 16:19:30 +00:00
|
|
|
0, 0, 0,
|
|
|
|
mImageRequest, listener);
|
2000-07-20 01:52:35 +00:00
|
|
|
|
|
|
|
//set flag to indicate view-image needs to use imgcache
|
|
|
|
group->SetImgLoadAttributes(nsImageLoadFlags_kSticky);
|
|
|
|
|
1999-06-25 01:53:22 +00:00
|
|
|
nsCRT::free(spec);
|
1998-09-09 16:19:30 +00:00
|
|
|
aListener = listener;
|
|
|
|
NS_RELEASE(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
|
2000-07-20 01:52:35 +00:00
|
|
|
|
1998-09-09 16:19:30 +00:00
|
|
|
// Finally, start the layout going
|
|
|
|
StartLayout();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
nsresult
|
|
|
|
nsImageDocument::CreateSyntheticDocument()
|
|
|
|
{
|
|
|
|
// Synthesize an html document that refers to the image
|
|
|
|
nsresult rv;
|
2000-05-10 13:13:39 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull,
|
|
|
|
kNameSpaceID_None,
|
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
nsIHTMLContent* root;
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = NS_NewHTMLHtmlElement(&root, nodeInfo);
|
1998-07-27 17:50:58 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-19 04:48:43 +00:00
|
|
|
root->SetDocument(this, PR_FALSE, PR_TRUE);
|
1998-09-08 22:38:17 +00:00
|
|
|
SetRootContent(root);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::body, nsnull,
|
|
|
|
kNameSpaceID_None,
|
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
nsIHTMLContent* body;
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = NS_NewHTMLBodyElement(&body, nodeInfo);
|
1998-07-27 17:50:58 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-19 04:48:43 +00:00
|
|
|
body->SetDocument(this, PR_FALSE, PR_TRUE);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::p, nsnull, kNameSpaceID_None,
|
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
nsIHTMLContent* center;
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = NS_NewHTMLParagraphElement(¢er, nodeInfo);
|
1998-07-27 17:50:58 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-19 04:48:43 +00:00
|
|
|
center->SetDocument(this, PR_FALSE, PR_TRUE);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::img, nsnull,
|
|
|
|
kNameSpaceID_None,
|
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
nsIHTMLContent* image;
|
2000-05-10 13:13:39 +00:00
|
|
|
rv = NS_NewHTMLImageElement(&image, nodeInfo);
|
1998-07-27 17:50:58 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-19 04:48:43 +00:00
|
|
|
image->SetDocument(this, PR_FALSE, PR_TRUE);
|
1998-09-09 16:19:30 +00:00
|
|
|
|
1999-06-25 01:53:22 +00:00
|
|
|
char* src;
|
|
|
|
mDocumentURL->GetSpec(&src);
|
2000-04-16 11:19:26 +00:00
|
|
|
|
|
|
|
nsString src_string; src_string.AssignWithConversion(src);
|
|
|
|
nsHTMLValue val(src_string);
|
1999-05-26 22:53:12 +00:00
|
|
|
delete[] src;
|
1998-12-20 01:21:23 +00:00
|
|
|
image->SetHTMLAttribute(nsHTMLAtoms::src, val, PR_FALSE);
|
|
|
|
image->SetHTMLAttribute(nsHTMLAtoms::alt, val, PR_FALSE);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
1998-08-21 21:38:26 +00:00
|
|
|
root->AppendChildTo(body, PR_FALSE);
|
|
|
|
center->AppendChildTo(image, PR_FALSE);
|
|
|
|
body->AppendChildTo(center, PR_FALSE);
|
1998-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
NS_RELEASE(image);
|
|
|
|
NS_RELEASE(center);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
NS_RELEASE(root);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageDocument::StartLayout()
|
|
|
|
{
|
2001-03-14 07:35:29 +00:00
|
|
|
|
|
|
|
// Reset scrolling to default settings for this shell.
|
|
|
|
// This must happen before the initial reflow, when we create the root frame
|
|
|
|
nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryReferent(mContainer));
|
|
|
|
if (scrollableContainer) {
|
|
|
|
scrollableContainer->ResetScrollbarPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
PRInt32 i, ns = GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsIPresShell* shell = GetShellAt(i);
|
|
|
|
if (nsnull != shell) {
|
|
|
|
// Make shell an observer for next time
|
|
|
|
shell->BeginObservingDocument();
|
|
|
|
|
|
|
|
// Resize-reflow this time
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
1998-07-27 17:50:58 +00:00
|
|
|
nsRect r;
|
|
|
|
cx->GetVisibleArea(r);
|
1998-09-11 04:20:30 +00:00
|
|
|
shell->InitialReflow(r.width, r.height);
|
1998-08-04 21:16:13 +00:00
|
|
|
|
|
|
|
// Now trigger a refresh
|
|
|
|
// XXX It's unfortunate that this has to be here
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (vm) {
|
2000-02-09 15:48:01 +00:00
|
|
|
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
1998-08-04 21:16:13 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 17:50:58 +00:00
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-07 07:31:24 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageDocument::EndLayout(nsISupports *ctxt,
|
|
|
|
nsresult status,
|
|
|
|
const PRUnichar *errorMsg)
|
|
|
|
{
|
2000-02-12 18:09:40 +00:00
|
|
|
// Layout has completed: now update the title
|
|
|
|
UpdateTitle();
|
|
|
|
|
2000-01-27 02:15:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: call this AFTER the shell has been installed as an observer of the
|
|
|
|
// document so the update notification gets processed by the shell
|
|
|
|
// and it updates the titlebar
|
|
|
|
nsresult nsImageDocument::UpdateTitle( void )
|
|
|
|
{
|
2001-01-03 23:37:28 +00:00
|
|
|
#ifdef USE_EXTENSION_FOR_TYPE
|
2000-03-16 22:58:12 +00:00
|
|
|
// XXX TEMPORARY XXX
|
|
|
|
// We want to display the image type, however there is no way to right now
|
|
|
|
// so instead we just get the image-extension
|
|
|
|
// - get the URL interface, get the extension, convert to upper-case
|
|
|
|
// Unless the Imagerequest or Image can tell us the type this is the best we can do.
|
|
|
|
nsIURL *pURL=nsnull;
|
2001-01-04 20:44:42 +00:00
|
|
|
if(NS_SUCCEEDED(mDocumentURL->QueryInterface(NS_GET_IID(nsIURL),(void **)&pURL))){
|
2000-03-16 22:58:12 +00:00
|
|
|
char *pExtension=nsnull;
|
|
|
|
pURL->GetFileExtension(&pExtension);
|
|
|
|
if(pExtension){
|
2000-04-15 20:15:37 +00:00
|
|
|
nsString strExt; strExt.AssignWithConversion(pExtension);
|
2000-03-16 22:58:12 +00:00
|
|
|
strExt.ToUpperCase();
|
|
|
|
titleStr.Append(strExt);
|
|
|
|
nsCRT::free(pExtension);
|
|
|
|
pExtension=nsnull;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pURL);
|
|
|
|
}
|
2001-01-03 23:37:28 +00:00
|
|
|
#endif
|
2001-02-06 23:39:46 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
nsresult rv;
|
|
|
|
// Create a bundle for the localization
|
|
|
|
NS_WITH_SERVICE(nsIStringBundleService, stringService, kStringBundleServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && stringService) {
|
|
|
|
nsCOMPtr<nsILocale> locale = nsnull;
|
|
|
|
rv = stringService->CreateBundle(NSIMAGEDOCUMENT_PROPERTIES_URI, locale, getter_AddRefs(bundle));
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) && bundle) {
|
|
|
|
nsAutoString key;
|
|
|
|
nsXPIDLString valUni;
|
|
|
|
if (mImageRequest) {
|
|
|
|
PRUint32 width, height;
|
|
|
|
mImageRequest->GetNaturalDimensions(&width, &height);
|
|
|
|
// if we got a valid size (sometimes we do not) then display it
|
|
|
|
if (width != 0 && height != 0){
|
|
|
|
key.AssignWithConversion("ImageTitleWithDimensions");
|
|
|
|
nsAutoString widthStr; widthStr.AppendInt(width);
|
|
|
|
nsAutoString heightStr; heightStr.AppendInt(height);
|
|
|
|
const PRUnichar *formatStrings[2] = {widthStr.GetUnicode(), heightStr.GetUnicode()};
|
|
|
|
rv = bundle->FormatStringFromName(key.GetUnicode(), formatStrings, 2, getter_Copies(valUni));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nsLiteralString(valUni).IsEmpty()) {
|
|
|
|
key.AssignWithConversion("ImageTitleWithoutDimensions");
|
|
|
|
rv = bundle->GetStringFromName(key.GetUnicode(), getter_Copies(valUni));
|
2000-01-27 02:15:19 +00:00
|
|
|
}
|
2001-02-06 23:39:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && valUni) {
|
|
|
|
nsString titleStr;
|
|
|
|
titleStr.Assign(valUni);
|
|
|
|
// set it on the document
|
|
|
|
SetTitle(titleStr);
|
|
|
|
}
|
|
|
|
}
|
1999-07-07 07:31:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|