1999-12-06 06:32:12 +00:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "MPL"); you may not use this file
|
|
|
|
* except in compliance with the MPL. You may obtain a copy of
|
|
|
|
* the MPL at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the MPL is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the MPL for the specific language governing
|
|
|
|
* rights and limitations under the MPL.
|
|
|
|
*
|
|
|
|
* The Original Code is XMLterm.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Ramalingam Saravanan.
|
|
|
|
* Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
|
|
|
|
* Copyright (C) 1999 Ramalingam Saravanan. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1999-12-06 06:32:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// mozXMLTerminal.cpp: implementation of mozIXMLTerminal interface
|
|
|
|
// to manage all XMLTerm operations.
|
|
|
|
// Creates a new mozXMLTermSession object to manage session input/output.
|
|
|
|
// Creates a mozLineTermAux object to access LineTerm operations.
|
|
|
|
// Creates key/text/mouse/drag listener objects to handle user events.
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nspr.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIObserver.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsISelectionController.h"
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
#include "nsIPresContext.h"
|
2000-03-13 15:48:32 +00:00
|
|
|
#include "nsICaret.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsIURI.h"
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
|
2000-04-04 04:42:27 +00:00
|
|
|
#include "nsFont.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
2000-09-19 23:01:42 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
2000-04-04 04:42:27 +00:00
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
#include "mozXMLT.h"
|
|
|
|
#include "mozXMLTermUtils.h"
|
|
|
|
#include "mozXMLTerminal.h"
|
|
|
|
|
2000-09-20 19:26:44 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2001-05-04 20:15:38 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2001-05-04 20:15:38 +00:00
|
|
|
#include "nsIWebProgress.h"
|
2000-09-20 19:26:44 +00:00
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
|
|
|
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
2000-09-19 23:01:42 +00:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-09-07 21:33:32 +00:00
|
|
|
// mozXMLTerminal implementation
|
1999-12-06 06:32:12 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-09-07 21:33:32 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS4(mozXMLTerminal,
|
|
|
|
mozIXMLTerminal,
|
|
|
|
nsIWebProgressListener,
|
|
|
|
nsIObserver,
|
|
|
|
nsISupportsWeakReference);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
mozXMLTerminal::mozXMLTerminal() :
|
|
|
|
mInitialized(PR_FALSE),
|
|
|
|
|
2000-04-28 10:55:20 +00:00
|
|
|
mCookie(nsAutoString()),
|
1999-12-06 06:32:12 +00:00
|
|
|
|
2000-04-28 10:55:20 +00:00
|
|
|
mCommand(nsAutoString()),
|
|
|
|
mPromptExpr(nsAutoString()),
|
1999-12-26 15:19:45 +00:00
|
|
|
|
2000-04-28 10:55:20 +00:00
|
|
|
mInitInput(nsAutoString()),
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
mXMLTermShell(nsnull),
|
2000-02-14 01:17:55 +00:00
|
|
|
mDocShell(nsnull),
|
1999-12-06 06:32:12 +00:00
|
|
|
mPresShell(nsnull),
|
|
|
|
mDOMDocument(nsnull),
|
|
|
|
|
|
|
|
mXMLTermSession(nsnull),
|
|
|
|
|
|
|
|
mLineTermAux(nsnull),
|
2000-04-21 14:01:43 +00:00
|
|
|
mNeedsResizing(PR_FALSE),
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
mKeyListener(nsnull),
|
|
|
|
mTextListener(nsnull),
|
|
|
|
mMouseListener(nsnull),
|
|
|
|
mDragListener(nsnull)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mozXMLTerminal::~mozXMLTerminal()
|
|
|
|
{
|
2000-10-10 04:51:11 +00:00
|
|
|
Finalize();
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetCurrentEntryNumber(PRInt32 *aNumber)
|
|
|
|
{
|
2000-02-29 15:55:36 +00:00
|
|
|
if (!mXMLTermSession)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 15:55:36 +00:00
|
|
|
|
|
|
|
return mXMLTermSession->GetCurrentEntryNumber(aNumber);
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetHistory(PRInt32 *aHistory)
|
|
|
|
{
|
2000-02-29 15:55:36 +00:00
|
|
|
if (!mXMLTermSession)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 15:55:36 +00:00
|
|
|
|
|
|
|
return mXMLTermSession->GetHistory(aHistory);
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::SetHistory(PRInt32 aHistory)
|
|
|
|
{
|
2000-02-29 15:55:36 +00:00
|
|
|
if (!mXMLTermSession)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 15:55:36 +00:00
|
|
|
|
|
|
|
return mXMLTermSession->SetHistory(aHistory);
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetPrompt(PRUnichar **aPrompt)
|
|
|
|
{
|
2000-02-29 15:55:36 +00:00
|
|
|
if (!mXMLTermSession)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 15:55:36 +00:00
|
|
|
|
|
|
|
return mXMLTermSession->GetPrompt(aPrompt);
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::SetPrompt(const PRUnichar* aPrompt)
|
|
|
|
{
|
2000-02-29 15:55:36 +00:00
|
|
|
if (!mXMLTermSession)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 15:55:36 +00:00
|
|
|
|
|
|
|
return mXMLTermSession->SetPrompt(aPrompt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetKeyIgnore(PRBool* aIgnore)
|
|
|
|
{
|
|
|
|
if (!mKeyListener)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<mozIXMLTermSuspend> suspend= do_QueryInterface(mKeyListener);
|
|
|
|
if (!suspend)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return suspend->GetSuspend(aIgnore);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::SetKeyIgnore(const PRBool aIgnore)
|
|
|
|
{
|
|
|
|
if (!mKeyListener)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<mozIXMLTermSuspend> suspend= do_QueryInterface(mKeyListener);
|
|
|
|
if (!suspend)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return suspend->SetSuspend(aIgnore);
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize by starting load of Init page for XMLTerm
|
2000-02-14 01:17:55 +00:00
|
|
|
NS_IMETHODIMP mozXMLTerminal::Init(nsIDocShell* aDocShell,
|
1999-12-06 06:32:12 +00:00
|
|
|
mozIXMLTermShell* aXMLTermShell,
|
|
|
|
const PRUnichar* aURL,
|
|
|
|
const PRUnichar* args)
|
|
|
|
{
|
|
|
|
XMLT_LOG(mozXMLTerminal::Init,20,("\n"));
|
|
|
|
|
2000-02-14 01:17:55 +00:00
|
|
|
if (!aDocShell)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-10-10 04:51:11 +00:00
|
|
|
if (mInitialized)
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
2000-10-10 04:51:11 +00:00
|
|
|
// Initialization flag
|
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
// Containing docshell
|
|
|
|
mDocShell = getter_AddRefs(NS_GetWeakReference(aDocShell)); // weak ref
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
mXMLTermShell = aXMLTermShell; // containing xmlterm shell; no addref
|
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// NOTE: Need to parse args string!!!
|
2000-04-28 10:55:20 +00:00
|
|
|
mCommand.SetLength(0);
|
|
|
|
mPromptExpr.SetLength(0);
|
2000-02-29 15:55:36 +00:00
|
|
|
mInitInput = args;
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
if ((aURL != nsnull) && (*aURL != 0)) {
|
|
|
|
// Load URL and activate XMLTerm after loading
|
|
|
|
XMLT_LOG(mozXMLTerminal::Init,22,("setting DocLoaderObs\n"));
|
|
|
|
|
|
|
|
// About to create owning reference to this
|
2001-05-04 20:15:38 +00:00
|
|
|
nsCOMPtr<nsIWebProgress> progress(do_GetInterface(aDocShell, &result));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
result = progress->AddProgressListener((nsIWebProgressListener*)this);
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Init,22,("done setting DocLoaderObs\n"));
|
|
|
|
|
|
|
|
// Load initial XMLterm background document
|
2000-04-28 10:55:20 +00:00
|
|
|
nsCAutoString urlCString;
|
|
|
|
urlCString.AssignWithConversion(aURL);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
2000-02-14 01:17:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2001-03-02 09:26:57 +00:00
|
|
|
result = uri->SetSpec(urlCString.get());
|
2000-02-14 01:17:55 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-11-30 23:54:30 +00:00
|
|
|
result = aDocShell->LoadURI(uri, nsnull, nsIWebNavigation::LOAD_FLAGS_NONE);
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Document already loaded; activate XMLTerm
|
|
|
|
result = Activate();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Init,21,("exiting\n"));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// De-initialize XMLTerminal
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::Finalize(void)
|
|
|
|
{
|
2000-10-10 04:51:11 +00:00
|
|
|
if (!mInitialized)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Finalize,20,("\n"));
|
|
|
|
|
|
|
|
mInitialized = PR_FALSE;
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
if (mXMLTermSession) {
|
|
|
|
// Finalize XMLTermSession object and delete it (it is not ref. counted)
|
|
|
|
mXMLTermSession->Finalize();
|
|
|
|
delete mXMLTermSession;
|
|
|
|
mXMLTermSession = nsnull;
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryReferent(mDOMDocument);
|
|
|
|
|
|
|
|
if (domDoc) {
|
1999-12-06 06:32:12 +00:00
|
|
|
// Release any event listeners for the document
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> eventReceiver;
|
2000-11-08 22:20:18 +00:00
|
|
|
nsresult result = domDoc->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(eventReceiver));
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && eventReceiver) {
|
|
|
|
if (mKeyListener) {
|
|
|
|
eventReceiver->RemoveEventListenerByIID(mKeyListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMKeyListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
mKeyListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTextListener) {
|
|
|
|
eventReceiver->RemoveEventListenerByIID(mTextListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMTextListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
mTextListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMouseListener) {
|
|
|
|
eventReceiver->RemoveEventListenerByIID(mMouseListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMMouseListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
mMouseListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDragListener) {
|
|
|
|
eventReceiver->RemoveEventListenerByIID(mDragListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMDragListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
mDragListener = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
mDOMDocument = nsnull;
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
if (mLineTermAux) {
|
|
|
|
// Finalize and release reference to LineTerm object owned by us
|
|
|
|
mLineTermAux->CloseAux();
|
|
|
|
mLineTermAux = nsnull;
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
mDocShell = nsnull;
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
mPresShell = nsnull;
|
|
|
|
mXMLTermShell = nsnull;
|
|
|
|
|
2000-10-10 04:51:11 +00:00
|
|
|
XMLT_LOG(mozXMLTerminal::Finalize,22,("END\n"));
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Activates XMLterm and instantiates LineTerm;
|
|
|
|
* called at the the end of Init page loading.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::Activate(void)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// TEMPORARY: Testing mozIXMLTermStream
|
2000-09-02 21:26:17 +00:00
|
|
|
nsAutoString streamData( "<HTML><HEAD><TITLE>Stream Title</TITLE>"
|
1999-12-06 06:32:12 +00:00
|
|
|
"<SCRIPT language='JavaScript'>"
|
|
|
|
"function clik(){ dump('click\\n');return(false);}"
|
|
|
|
"</SCRIPT></HEAD>"
|
|
|
|
"<BODY><B>Stream Body "
|
|
|
|
"<SPAN STYLE='color: blue' onClick='return clik();'>Clik</SPAN></B><BR>"
|
|
|
|
"<TABLE WIDTH=720><TR><TD WIDTH=700 BGCOLOR=maroon> </TABLE>"
|
|
|
|
"<BR>ABCD<BR>EFGH<BR>JKLM<BR>"
|
2000-09-02 21:26:17 +00:00
|
|
|
"</BODY></HTML>" );
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
nsCOMPtr<mozIXMLTermStream> stream;
|
|
|
|
result = NS_NewXMLTermStream(getter_AddRefs(stream));
|
|
|
|
if (NS_FAILED(result)) {
|
2001-09-07 21:33:32 +00:00
|
|
|
XMLT_ERROR("mozXMLTerminal::Activate: Failed to create stream\n");
|
1999-12-06 06:32:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
|
|
|
|
if (!docShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-09-01 01:54:35 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> outerDOMWindow;
|
2000-11-08 22:20:18 +00:00
|
|
|
result = mozXMLTermUtils::ConvertDocShellToDOMWindow(docShell,
|
1999-12-06 06:32:12 +00:00
|
|
|
getter_AddRefs(outerDOMWindow));
|
|
|
|
|
1999-12-26 15:19:45 +00:00
|
|
|
if (NS_FAILED(result) || !outerDOMWindow) {
|
2001-09-07 21:33:32 +00:00
|
|
|
XMLT_ERROR("mozXMLTerminal::Activate: Failed to convert docshell\n");
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-12-26 15:19:45 +00:00
|
|
|
}
|
1999-12-06 06:32:12 +00:00
|
|
|
|
1999-12-26 15:19:45 +00:00
|
|
|
result = stream->Open(outerDOMWindow, "iframet", "chrome://dummy",
|
1999-12-06 06:32:12 +00:00
|
|
|
"text/html", 800);
|
|
|
|
if (NS_FAILED(result)) {
|
2001-09-07 21:33:32 +00:00
|
|
|
XMLT_ERROR("mozXMLTerminal::Activate: Failed to open stream\n");
|
1999-12-06 06:32:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-06-30 11:02:25 +00:00
|
|
|
result = stream->Write(streamData.get());
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
2001-09-07 21:33:32 +00:00
|
|
|
XMLT_ERROR("mozXMLTerminal::Activate: Failed to write to stream\n");
|
1999-12-06 06:32:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = stream->Close();
|
|
|
|
if (NS_FAILED(result)) {
|
2001-09-07 21:33:32 +00:00
|
|
|
XMLT_ERROR("mozXMLTerminal::Activate: Failed to close stream\n");
|
1999-12-06 06:32:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Activate,20,("\n"));
|
|
|
|
|
|
|
|
if (!mInitialized)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-02-14 01:17:55 +00:00
|
|
|
PR_ASSERT(mDocShell != nsnull);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
if ((mDOMDocument != nsnull) || (mPresShell != nsnull))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
|
|
|
|
if (!docShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
// Get reference to presentation shell
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
2000-11-08 22:20:18 +00:00
|
|
|
result = docShell->GetPresContext(getter_AddRefs(presContext));
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result) || !presContext)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
2000-11-08 22:20:18 +00:00
|
|
|
result = docShell->GetPresShell(getter_AddRefs(presShell));
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result) || !presShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-22 07:16:01 +00:00
|
|
|
|
|
|
|
// Get reference to DOMDocument
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
2000-02-22 20:18:19 +00:00
|
|
|
result = presShell->GetDocument(getter_AddRefs(document));
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || !document)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-22 07:16:01 +00:00
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(document);
|
|
|
|
if (!domDoc)
|
2000-02-22 07:16:01 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-12-06 06:32:12 +00:00
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
// Save weak references to presentation shell and DOMDocument
|
|
|
|
mPresShell = getter_AddRefs(NS_GetWeakReference(presShell)); // weak ref
|
|
|
|
mDOMDocument = getter_AddRefs(NS_GetWeakReference(domDoc)); // weak ref
|
1999-12-06 06:32:12 +00:00
|
|
|
|
2000-04-04 04:42:27 +00:00
|
|
|
// Show caret
|
|
|
|
ShowCaret();
|
|
|
|
|
|
|
|
// Determine current screen dimensions
|
|
|
|
PRInt32 nRows, nCols, xPixels, yPixels;
|
2001-09-07 21:33:32 +00:00
|
|
|
result = ScreenSize(&nRows, &nCols, &xPixels, &yPixels);
|
2000-04-04 04:42:27 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// The above call does not return the correct screen dimensions.
|
|
|
|
// (because rendering is still in progress?)
|
|
|
|
// As a workaround, explicitly set screen dimensions
|
|
|
|
nRows = 24;
|
|
|
|
nCols = 80;
|
|
|
|
xPixels = 0;
|
|
|
|
yPixels = 0;
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
// Instantiate and initialize XMLTermSession object
|
|
|
|
mXMLTermSession = new mozXMLTermSession();
|
|
|
|
|
|
|
|
if (!mXMLTermSession) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
result = mXMLTermSession->Init(this, presShell, domDoc, nRows, nCols);
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to initialize XMLTermSession\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate LineTerm
|
2000-04-04 04:42:27 +00:00
|
|
|
XMLT_LOG(mozXMLTerminal::Activate,22,
|
|
|
|
("instantiating lineterm, nRows=%d, nCols=%d\n", nRows, nCols));
|
2001-09-07 21:33:32 +00:00
|
|
|
mLineTermAux = do_CreateInstance(MOZLINETERM_CONTRACTID, &result);
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to instantiate LineTermAux\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open LineTerm to execute command
|
|
|
|
// Non-owning reference to this; delete LineTerm before deleting self
|
2000-01-17 01:16:14 +00:00
|
|
|
PRInt32 options = 0;
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Activate,22,("Opening LineTerm\n"));
|
|
|
|
nsCOMPtr<nsIObserver> anObserver = this;
|
|
|
|
#ifdef NO_CALLBACK
|
|
|
|
anObserver = nsnull;
|
|
|
|
#endif
|
|
|
|
nsAutoString cookie;
|
2001-06-30 11:02:25 +00:00
|
|
|
result = mLineTermAux->OpenAux(mCommand.get(),
|
|
|
|
mInitInput.get(),
|
|
|
|
mPromptExpr.get(),
|
1999-12-06 06:32:12 +00:00
|
|
|
options, LTERM_DETERMINE_PROCESS,
|
2000-04-04 04:42:27 +00:00
|
|
|
nRows, nCols, xPixels, yPixels,
|
2000-11-08 22:20:18 +00:00
|
|
|
domDoc, anObserver, cookie);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to open LineTermAux\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
XMLT_LOG(mozXMLTerminal::Activate,22,("Opened LineTerm\n"));
|
|
|
|
|
|
|
|
// Save cookie
|
|
|
|
mCookie = cookie;
|
|
|
|
|
|
|
|
// Get the DOM event receiver for document
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> eventReceiver;
|
2000-11-08 22:20:18 +00:00
|
|
|
result = domDoc->QueryInterface(NS_GET_IID(nsIDOMEventReceiver),
|
1999-12-06 06:32:12 +00:00
|
|
|
getter_AddRefs(eventReceiver));
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get DOM receiver\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a key listener
|
|
|
|
result = NS_NewXMLTermKeyListener(getter_AddRefs(mKeyListener), this);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get key listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the key listener with the DOM event receiver
|
|
|
|
result = eventReceiver->AddEventListenerByIID(mKeyListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMKeyListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register key listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a text listener
|
|
|
|
result = NS_NewXMLTermTextListener(getter_AddRefs(mTextListener), this);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get text listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the text listener with the DOM event receiver
|
|
|
|
result = eventReceiver->AddEventListenerByIID(mTextListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMTextListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register text listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a mouse listener
|
|
|
|
result = NS_NewXMLTermMouseListener(getter_AddRefs(mMouseListener), this);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get mouse listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the mouse listener with the DOM event receiver
|
|
|
|
result = eventReceiver->AddEventListenerByIID(mMouseListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMMouseListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register mouse listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a drag listener
|
|
|
|
result = NS_NewXMLTermDragListener(getter_AddRefs(mDragListener), this);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get drag listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the drag listener with the DOM event receiver
|
|
|
|
result = eventReceiver->AddEventListenerByIID(mDragListener,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMDragListener));
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register drag listener\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-04 04:42:27 +00:00
|
|
|
/** Returns current screen size in rows/cols and in pixels
|
|
|
|
* @param (output) rows
|
|
|
|
* @param (output) cols
|
|
|
|
* @param (output) xPixels
|
|
|
|
* @param (output) yPixels
|
|
|
|
*/
|
2001-09-07 21:33:32 +00:00
|
|
|
NS_IMETHODIMP mozXMLTerminal::ScreenSize(PRInt32* rows, PRInt32* cols,
|
|
|
|
PRInt32* xPixels, PRInt32* yPixels)
|
2000-04-04 04:42:27 +00:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::ScreenSize,70,("\n"));
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (!presShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-04-04 04:42:27 +00:00
|
|
|
// Get presentation context
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
2000-11-08 22:20:18 +00:00
|
|
|
result = presShell->GetPresContext( getter_AddRefs(presContext) );
|
2000-04-04 04:42:27 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Get the default fixed pitch font
|
|
|
|
nsFont defaultFixedFont("dummyfont", NS_FONT_STYLE_NORMAL,
|
|
|
|
NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL,
|
|
|
|
NS_FONT_DECORATION_NONE, 16);
|
|
|
|
|
2001-09-27 18:28:24 +00:00
|
|
|
result = presContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, defaultFixedFont);
|
2000-04-04 04:42:27 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Get metrics for fixed font
|
|
|
|
nsCOMPtr<nsIFontMetrics> fontMetrics;
|
|
|
|
result = presContext->GetMetricsFor(defaultFixedFont,
|
|
|
|
getter_AddRefs(fontMetrics));
|
|
|
|
if (NS_FAILED(result) || !fontMetrics)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Get font height (includes leading?)
|
|
|
|
nscoord fontHeight, fontWidth;
|
|
|
|
result = fontMetrics->GetHeight(fontHeight);
|
|
|
|
result = fontMetrics->GetMaxAdvance(fontWidth);
|
|
|
|
|
|
|
|
// Determine docshell size in twips
|
|
|
|
nsRect shellArea;
|
|
|
|
result = presContext->GetVisibleArea(shellArea);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Determine twips to pixels conversion factor
|
|
|
|
float pixelScale;
|
|
|
|
presContext->GetTwipsToPixels(&pixelScale);
|
|
|
|
|
|
|
|
// Convert dimensions to pixels
|
|
|
|
float xdel, ydel;
|
|
|
|
xdel = pixelScale * fontWidth;
|
|
|
|
ydel = pixelScale * fontHeight + 2;
|
|
|
|
|
2001-09-07 21:33:32 +00:00
|
|
|
*xPixels = (int) (pixelScale * shellArea.width);
|
|
|
|
*yPixels = (int) (pixelScale * shellArea.height);
|
2000-04-04 04:42:27 +00:00
|
|
|
|
|
|
|
// Determine number of rows/columns
|
2001-09-07 21:33:32 +00:00
|
|
|
*rows = (int) ((*yPixels-16) / ydel);
|
|
|
|
*cols = (int) ((*xPixels-20) / xdel);
|
2000-04-04 04:42:27 +00:00
|
|
|
|
2001-09-07 21:33:32 +00:00
|
|
|
if (*rows < 1) *rows = 1;
|
|
|
|
if (*cols < 1) *cols = 1;
|
2000-04-04 04:42:27 +00:00
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::ScreenSize,72,
|
|
|
|
("rows=%d, cols=%d, xPixels=%d, yPixels=%d\n",
|
2001-09-07 21:33:32 +00:00
|
|
|
*rows, *cols, *xPixels, *yPixels));
|
2000-04-04 04:42:27 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
// Transmit string to LineTerm (use saved cookie)
|
2001-09-07 21:33:32 +00:00
|
|
|
NS_IMETHODIMP mozXMLTerminal::SendTextAux(const PRUnichar* aString)
|
1999-12-06 06:32:12 +00:00
|
|
|
{
|
2001-06-30 11:02:25 +00:00
|
|
|
return SendText(aString, mCookie.get());
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Transmit string to LineTerm
|
2001-09-07 21:33:32 +00:00
|
|
|
NS_IMETHODIMP mozXMLTerminal::SendText(const PRUnichar* aString,
|
1999-12-06 06:32:12 +00:00
|
|
|
const PRUnichar* aCookie)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (!mLineTermAux)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-09-02 21:26:17 +00:00
|
|
|
nsAutoString sendStr(aString);
|
1999-12-26 15:19:45 +00:00
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
// Preprocess string and check if it is to be consumed
|
2000-04-05 01:51:34 +00:00
|
|
|
PRBool consumed, checkSize;
|
|
|
|
result = mXMLTermSession->Preprocess(sendStr, consumed, checkSize);
|
|
|
|
|
|
|
|
PRBool screenMode;
|
|
|
|
GetScreenMode(&screenMode);
|
|
|
|
|
|
|
|
if (!screenMode && (checkSize || mNeedsResizing)) {
|
|
|
|
// Resize terminal, if need be
|
|
|
|
mXMLTermSession->Resize(mLineTermAux);
|
2000-04-21 14:01:43 +00:00
|
|
|
mNeedsResizing = PR_FALSE;
|
2000-04-05 01:51:34 +00:00
|
|
|
}
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
if (!consumed) {
|
2001-06-30 11:02:25 +00:00
|
|
|
result = mLineTermAux->Write(sendStr.get(), aCookie);
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result)) {
|
2000-04-04 04:42:27 +00:00
|
|
|
// Abort XMLterm session
|
2000-04-28 10:55:20 +00:00
|
|
|
nsAutoString abortCode;
|
2001-12-16 11:58:03 +00:00
|
|
|
abortCode.Assign(NS_LITERAL_STRING("SendText"));
|
2000-04-04 04:42:27 +00:00
|
|
|
mXMLTermSession->Abort(mLineTermAux, abortCode);
|
1999-12-06 06:32:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-13 15:48:32 +00:00
|
|
|
/** Shows the caret and make it editable.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::ShowCaret(void)
|
|
|
|
{
|
|
|
|
// In principle, this method needs to be called only once;
|
|
|
|
// in practice, certain operations seem to hide the caret
|
|
|
|
// especially when one starts mucking around with the display:
|
|
|
|
// style property.
|
|
|
|
// Under those circumstances, call this method to re-display the caret.
|
|
|
|
|
2000-11-27 21:38:14 +00:00
|
|
|
XMLT_LOG(mozXMLTerminal::ShowCaret,70,("\n"));
|
|
|
|
|
2000-03-13 15:48:32 +00:00
|
|
|
if (!mPresShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (!presShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(presShell);
|
2000-09-19 23:01:42 +00:00
|
|
|
|
|
|
|
if (!selCon) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::ShowCaret: Warning - Failed to get SelectionController\n");
|
2000-11-27 22:15:50 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-19 23:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 pixelWidth;
|
|
|
|
nsresult result;
|
|
|
|
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsILookAndFeel> look(do_GetService(kLookAndFeelCID, &result));
|
2000-09-19 23:01:42 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && look) {
|
|
|
|
look->GetMetric(nsILookAndFeel::eMetric_SingleLineCaretWidth, pixelWidth);
|
|
|
|
|
|
|
|
selCon->SetCaretWidth(pixelWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
selCon->SetCaretEnabled(PR_TRUE);
|
|
|
|
selCon->SetCaretReadOnly(PR_FALSE);
|
2000-03-13 15:48:32 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
2000-11-27 22:15:50 +00:00
|
|
|
if (NS_SUCCEEDED(presShell->GetCaret(getter_AddRefs(caret))) && caret) {
|
2000-09-19 23:01:42 +00:00
|
|
|
|
|
|
|
caret->SetCaretVisible(PR_TRUE);
|
|
|
|
caret->SetCaretReadOnly(PR_FALSE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> sel;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel))) && sel) {
|
|
|
|
caret->SetCaretDOMSelection(sel);
|
2000-05-11 04:33:55 +00:00
|
|
|
}
|
2000-11-27 22:15:50 +00:00
|
|
|
} else {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::ShowCaret: Warning - Failed to get caret\n");
|
2000-03-13 15:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
// Paste data from clipboard to terminal
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::Paste()
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
nsAutoString pasteString;
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Paste,20,("\n"));
|
|
|
|
|
|
|
|
// Get Clipboard service
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &result));
|
1999-12-06 06:32:12 +00:00
|
|
|
if ( NS_FAILED(result) )
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Generic transferable for getting clipboard data
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
result = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsITransferable),
|
1999-12-06 06:32:12 +00:00
|
|
|
(void**) getter_AddRefs(trans));
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || !trans)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// DataFlavors to get out of transferable
|
|
|
|
trans->AddDataFlavor(kHTMLMime);
|
2000-02-01 22:26:21 +00:00
|
|
|
trans->AddDataFlavor(kUnicodeMime);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
// Get data from clipboard
|
2000-04-21 13:06:28 +00:00
|
|
|
result = clipboard->GetData(trans, nsIClipboard::kSelectionClipboard);
|
1999-12-06 06:32:12 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
char* bestFlavor = nsnull;
|
|
|
|
nsCOMPtr<nsISupports> genericDataObj;
|
|
|
|
PRUint32 objLen = 0;
|
|
|
|
result = trans->GetAnyTransferData(&bestFlavor,
|
|
|
|
getter_AddRefs(genericDataObj), &objLen);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-04-28 10:55:20 +00:00
|
|
|
nsAutoString flavor;
|
|
|
|
flavor.AssignWithConversion(bestFlavor);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
2001-09-29 08:28:41 +00:00
|
|
|
char* temCStr = ToNewCString(flavor);
|
1999-12-06 06:32:12 +00:00
|
|
|
XMLT_LOG(mozXMLTerminal::Paste,20,("flavour=%s\n", temCStr));
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(temCStr);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
2000-04-28 10:55:20 +00:00
|
|
|
if (flavor.EqualsWithConversion(kHTMLMime) || flavor.EqualsWithConversion(kUnicodeMime)) {
|
1999-12-06 06:32:12 +00:00
|
|
|
nsCOMPtr<nsISupportsWString> textDataObj ( do_QueryInterface(genericDataObj) );
|
|
|
|
if (textDataObj && objLen > 0) {
|
|
|
|
PRUnichar* text = nsnull;
|
|
|
|
textDataObj->ToString ( &text );
|
2000-04-28 10:55:20 +00:00
|
|
|
pasteString.Assign( text, objLen / 2 );
|
2001-09-07 21:33:32 +00:00
|
|
|
result = SendTextAux(pasteString.get());
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(bestFlavor);
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Poll for readable data from LineTerm
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::Poll(void)
|
|
|
|
{
|
|
|
|
if (!mLineTermAux)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Poll,20,("\n"));
|
|
|
|
|
1999-12-26 15:19:45 +00:00
|
|
|
nsresult result;
|
|
|
|
PRBool processedData;
|
|
|
|
|
|
|
|
result = mXMLTermSession->ReadAll(mLineTermAux, processedData);
|
2000-02-22 20:18:19 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
XMLT_WARNING("mozXMLTerminal::Poll: Warning - Error return 0x%x from ReadAll\n", result);
|
1999-12-26 15:19:45 +00:00
|
|
|
return result;
|
2000-02-22 20:18:19 +00:00
|
|
|
}
|
1999-12-26 15:19:45 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Handle callback from LineTerm when new input/output needs to be displayed
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::Observe(nsISupports *aSubject,
|
2001-10-19 22:56:19 +00:00
|
|
|
const char *aTopic,
|
1999-12-06 06:32:12 +00:00
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
|
|
|
nsCOMPtr<mozILineTermAux> lineTermAux = do_QueryInterface(aSubject);
|
|
|
|
PR_ASSERT(lineTermAux != nsnull);
|
|
|
|
|
1999-12-26 15:19:45 +00:00
|
|
|
PR_ASSERT(lineTermAux.get() == mLineTermAux.get());
|
|
|
|
|
|
|
|
return Poll();
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns document associated with XMLTerminal
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetDocument(nsIDOMDocument** aDoc)
|
|
|
|
{
|
|
|
|
if (!aDoc)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-02-22 20:18:19 +00:00
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
*aDoc = nsnull;
|
|
|
|
|
|
|
|
NS_PRECONDITION(mDOMDocument, "bad state, null mDOMDocument");
|
|
|
|
if (!mDOMDocument)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2000-11-08 22:20:18 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryReferent(mDOMDocument);
|
|
|
|
if (!domDoc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return domDoc->QueryInterface(NS_GET_IID(nsIDOMDocument),
|
1999-12-06 06:32:12 +00:00
|
|
|
(void **)aDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-14 01:17:55 +00:00
|
|
|
// Returns doc shell associated with XMLTerm
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetDocShell(nsIDocShell** aDocShell)
|
1999-12-26 15:19:45 +00:00
|
|
|
{
|
2000-02-14 01:17:55 +00:00
|
|
|
if (!aDocShell)
|
1999-12-26 15:19:45 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-02-22 20:18:19 +00:00
|
|
|
|
2000-02-14 01:17:55 +00:00
|
|
|
*aDocShell = nsnull;
|
1999-12-26 15:19:45 +00:00
|
|
|
|
2000-02-14 01:17:55 +00:00
|
|
|
NS_PRECONDITION(mDocShell, "bad state, null mDocShell");
|
|
|
|
if (!mDocShell)
|
1999-12-26 15:19:45 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2000-11-08 22:20:18 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
|
|
|
|
if (!docShell) {
|
|
|
|
XMLT_ERROR("mozXMLTerminal::GetDocShell: Error - Invalid weak reference\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return docShell->QueryInterface(NS_GET_IID(nsIDocShell),
|
2000-02-14 01:17:55 +00:00
|
|
|
(void **)aDocShell);
|
1999-12-26 15:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
// Returns presentation shell associated with XMLTerm
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetPresShell(nsIPresShell** aPresShell)
|
|
|
|
{
|
|
|
|
if (!aPresShell)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-02-22 20:18:19 +00:00
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
*aPresShell = nsnull;
|
|
|
|
|
|
|
|
NS_PRECONDITION(mPresShell, "bad state, null mPresShell");
|
|
|
|
if (!mPresShell)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2000-11-08 22:20:18 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (!presShell) {
|
|
|
|
XMLT_ERROR("mozXMLTerminal::GetPresShell: Error - Invalid weak reference\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return presShell->QueryInterface(NS_GET_IID(nsIPresShell),
|
1999-12-06 06:32:12 +00:00
|
|
|
(void **)aPresShell);
|
|
|
|
}
|
|
|
|
|
1999-12-26 15:19:45 +00:00
|
|
|
|
2000-11-08 22:20:18 +00:00
|
|
|
// Returns DOMDocument associated with XMLTerm
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetDOMDocument(nsIDOMDocument** aDOMDocument)
|
|
|
|
{
|
|
|
|
if (!aDOMDocument)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aDOMDocument = nsnull;
|
|
|
|
|
|
|
|
NS_PRECONDITION(mDOMDocument, "bad state, null mDOMDocument");
|
|
|
|
if (!mDOMDocument)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryReferent(mDOMDocument);
|
|
|
|
if (!domDoc) {
|
|
|
|
XMLT_ERROR("mozXMLTerminal::GetDOMDocument: Error - Invalid weak reference\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return domDoc->QueryInterface(NS_GET_IID(nsIDOMDocument),
|
|
|
|
(void **)aDOMDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns SelectionController associated with XMLTerm
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetSelectionController(nsISelectionController** aSelectionController)
|
|
|
|
{
|
|
|
|
if (!aSelectionController)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aSelectionController = nsnull;
|
|
|
|
|
|
|
|
NS_PRECONDITION(mPresShell, "bad state, null mPresShell");
|
|
|
|
if (!mPresShell)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (!presShell) {
|
|
|
|
XMLT_ERROR("mozXMLTerminal::GetSelectionControlle: Error - Invalid weak reference\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return presShell->QueryInterface(NS_GET_IID(nsISelectionController),
|
|
|
|
(void **)aSelectionController);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-13 15:48:32 +00:00
|
|
|
/** Gets flag denoting whether terminal is in full screen mode
|
|
|
|
* @param aFlag (output) screen mode flag
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::GetScreenMode(PRBool* aFlag)
|
|
|
|
{
|
|
|
|
return mXMLTermSession->GetScreenMode(aFlag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-22 20:18:19 +00:00
|
|
|
/** Checks if supplied cookie is valid for XMLTerm
|
|
|
|
* @param aCookie supplied cookie string
|
2000-04-21 14:01:43 +00:00
|
|
|
* @param _retval PR_TRUE if supplied cookie matches XMLTerm cookie
|
2000-02-22 20:18:19 +00:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::MatchesCookie(const PRUnichar* aCookie,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
XMLT_LOG(mozXMLTerminal::MatchesCookie,20,("\n"));
|
|
|
|
|
|
|
|
if (!_retval)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Check if supplied cookie matches XMLTerm cookie
|
2000-04-28 10:55:20 +00:00
|
|
|
*_retval = mCookie.EqualsWithConversion(aCookie);
|
2000-02-22 20:18:19 +00:00
|
|
|
|
|
|
|
if (!(*_retval)) {
|
|
|
|
XMLT_ERROR("mozXMLTerminal::MatchesCookie: Error - Cookie mismatch\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Resizes XMLterm to match a resized window.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP mozXMLTerminal::Resize(void)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
XMLT_LOG(mozXMLTerminal::Resize,20,("\n"));
|
|
|
|
|
|
|
|
if (!mXMLTermSession)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-04-05 01:51:34 +00:00
|
|
|
PRBool screenMode;
|
|
|
|
GetScreenMode(&screenMode);
|
|
|
|
|
|
|
|
if (screenMode) {
|
|
|
|
// Delay resizing until next input processing
|
2000-04-21 14:01:43 +00:00
|
|
|
mNeedsResizing = PR_TRUE;
|
2000-04-05 01:51:34 +00:00
|
|
|
} else {
|
|
|
|
// Resize session
|
|
|
|
result = mXMLTermSession->Resize(mLineTermAux);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
2000-02-22 20:18:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-04 20:15:38 +00:00
|
|
|
// nsIWebProgressListener methods
|
1999-12-06 06:32:12 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-04 20:15:38 +00:00
|
|
|
mozXMLTerminal::OnStateChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 progressStateFlags,
|
|
|
|
nsresult aStatus) {
|
|
|
|
if (progressStateFlags & nsIWebProgressListener::STATE_IS_REQUEST)
|
|
|
|
if (progressStateFlags & nsIWebProgressListener::STATE_START) {
|
|
|
|
XMLT_LOG(mozXMLTerminal::OnStateChange,20,("\n"));
|
|
|
|
|
|
|
|
// Activate XMLTerm
|
|
|
|
Activate();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-12-06 06:32:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-04 20:15:38 +00:00
|
|
|
mozXMLTerminal::OnProgressChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 aCurSelfProgress,
|
|
|
|
PRInt32 aMaxSelfProgress,
|
|
|
|
PRInt32 aCurTotalProgress,
|
|
|
|
PRInt32 aMaxTotalProgress) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-04 20:15:38 +00:00
|
|
|
mozXMLTerminal::OnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsIURI *location) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 20:15:38 +00:00
|
|
|
|
1999-12-06 06:32:12 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-04 20:15:38 +00:00
|
|
|
mozXMLTerminal::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aMessage) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-04 20:15:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
mozXMLTerminal::OnSecurityChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 state) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-06 06:32:12 +00:00
|
|
|
}
|