mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 11:27:49 +00:00
BUG115229 files not in build yet. checking in new files to make tree landing of editor embedded work go more smoothely
This commit is contained in:
parent
bb03fef0ac
commit
ca4de4f1e9
51
docshell/base/nsIEditorDocShell.idl
Normal file
51
docshell/base/nsIEditorDocShell.idl
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIEditor;
|
||||
|
||||
/**
|
||||
* nsIEditorDocShell provides a way to get an editor from
|
||||
* a specific frame in a docShell hierarchy. It is intended
|
||||
* to be only used internally. Use nsIEditingShell.getEditorForFrame
|
||||
* from out side.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(3BDB8F01-F141-11D4-A73C-FBA4ABA8A3FC)]
|
||||
interface nsIEditorDocShell : nsISupports
|
||||
{
|
||||
attribute nsIEditor editor;
|
||||
readonly attribute boolean editable; /* this docShell is editable */
|
||||
readonly attribute boolean hasEditingSession; /* this docShell has an editing session */
|
||||
|
||||
/**
|
||||
* Make this docShell editable, setting a flag that causes
|
||||
* an editor to get created, either immediately, or after
|
||||
* a url has been loaded.
|
||||
* @param inWaitForUriLoad true to wait for a URI before
|
||||
* creating the editor.
|
||||
*/
|
||||
void makeEditable(in boolean inWaitForUriLoad);
|
||||
|
||||
};
|
||||
|
333
editor/composer/src/nsComposerCommandsUpdater.cpp
Normal file
333
editor/composer/src/nsComposerCommandsUpdater.cpp
Normal file
@ -0,0 +1,333 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "nsComposerCommandsUpdater.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
#include "nsICommandManager.h"
|
||||
#include "nsPICommandUpdater.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsITransactionManager.h"
|
||||
|
||||
nsComposerCommandsUpdater::nsComposerCommandsUpdater()
|
||||
: mEditor(nsnull)
|
||||
, mDocShell(nsnull)
|
||||
, mDirtyState(eStateUninitialized)
|
||||
, mSelectionCollapsed(eStateUninitialized)
|
||||
, mFirstDoOfFirstUndo(PR_TRUE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsComposerCommandsUpdater::~nsComposerCommandsUpdater()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener, nsIDocumentStateListener, nsITransactionListener, nsITimerCallback);
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerCommandsUpdater::NotifyDocumentCreated()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed()
|
||||
{
|
||||
// cancel any outstanding udpate timer
|
||||
if (mUpdateTimer)
|
||||
mUpdateTimer->Cancel();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerCommandsUpdater::NotifyDocumentStateChanged(PRBool aNowDirty)
|
||||
{
|
||||
// update document modified. We should have some other notifications for this too.
|
||||
return UpdateDirtyState(aNowDirty);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short)
|
||||
{
|
||||
return PrimeUpdateTimer();
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::WillDo(nsITransactionManager *aManager,
|
||||
nsITransaction *aTransaction, PRBool *aInterrupt)
|
||||
{
|
||||
*aInterrupt = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
|
||||
nsITransaction *aTransaction, nsresult aDoResult)
|
||||
{
|
||||
// only need to update if the status of the Undo menu item changes.
|
||||
PRInt32 undoCount;
|
||||
aManager->GetNumberOfUndoItems(&undoCount);
|
||||
if (undoCount == 1)
|
||||
{
|
||||
if (mFirstDoOfFirstUndo)
|
||||
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo"));
|
||||
mFirstDoOfFirstUndo = PR_FALSE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager,
|
||||
nsITransaction *aTransaction, PRBool *aInterrupt)
|
||||
{
|
||||
*aInterrupt = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager,
|
||||
nsITransaction *aTransaction, nsresult aUndoResult)
|
||||
{
|
||||
PRInt32 undoCount;
|
||||
aManager->GetNumberOfUndoItems(&undoCount);
|
||||
if (undoCount == 0)
|
||||
mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do
|
||||
|
||||
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo"));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::WillRedo(nsITransactionManager *aManager,
|
||||
nsITransaction *aTransaction, PRBool *aInterrupt)
|
||||
{
|
||||
*aInterrupt = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager,
|
||||
nsITransaction *aTransaction, nsresult aRedoResult)
|
||||
{
|
||||
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo"));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::WillBeginBatch(nsITransactionManager *aManager, PRBool *aInterrupt)
|
||||
{
|
||||
*aInterrupt = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager, PRBool *aInterrupt)
|
||||
{
|
||||
*aInterrupt = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager,
|
||||
nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool *aInterrupt)
|
||||
{
|
||||
*aInterrupt = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager,
|
||||
nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge,
|
||||
PRBool aDidMerge, nsresult aMergeResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
nsComposerCommandsUpdater::SetEditor(nsIEditor* aEditor)
|
||||
{
|
||||
mEditor = aEditor; // no addreffing here
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComposerCommandsUpdater::PrimeUpdateTimer()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mUpdateTimer)
|
||||
{
|
||||
// i'd love to be able to just call SetDelay on the existing timer, but
|
||||
// i think i have to tear it down and make a new one.
|
||||
mUpdateTimer->Cancel();
|
||||
mUpdateTimer = NULL; // free it
|
||||
}
|
||||
|
||||
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
const PRUint32 kUpdateTimerDelay = 150;
|
||||
return mUpdateTimer->Init(NS_STATIC_CAST(nsITimerCallback*, this), kUpdateTimerDelay);
|
||||
}
|
||||
|
||||
|
||||
void nsComposerCommandsUpdater::TimerCallback()
|
||||
{
|
||||
// if the selection state has changed, update stuff
|
||||
PRBool isCollapsed = SelectionIsCollapsed();
|
||||
if (isCollapsed != mSelectionCollapsed)
|
||||
{
|
||||
CallUpdateCommands(NS_ConvertASCIItoUCS2("select"));
|
||||
mSelectionCollapsed = isCollapsed;
|
||||
}
|
||||
|
||||
CallUpdateCommands(NS_ConvertASCIItoUCS2("style"));
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComposerCommandsUpdater::UpdateDirtyState(PRBool aNowDirty)
|
||||
{
|
||||
if (mDirtyState != aNowDirty)
|
||||
{
|
||||
CallUpdateCommands(NS_ConvertASCIItoUCS2("save"));
|
||||
|
||||
mDirtyState = aNowDirty;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComposerCommandsUpdater::CallUpdateCommands(const nsAReadableString& aCommand)
|
||||
{
|
||||
if (!mDocShell)
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
editor->GetDocument(getter_AddRefs(domDoc));
|
||||
if (!domDoc) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocument> theDoc = do_QueryInterface(domDoc);
|
||||
if (!theDoc) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
||||
theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
mDocShell = docShell.get();
|
||||
}
|
||||
|
||||
if (!mDocShell) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell);
|
||||
nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager);
|
||||
if (!commandUpdater) return NS_ERROR_FAILURE;
|
||||
|
||||
commandUpdater->CommandStatusChanged(NS_LITERAL_STRING("cmd_bold"));
|
||||
commandUpdater->CommandStatusChanged(NS_LITERAL_STRING("cmd_italic"));
|
||||
commandUpdater->CommandStatusChanged(NS_LITERAL_STRING("cmd_underline"));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsComposerCommandsUpdater::SelectionIsCollapsed()
|
||||
{
|
||||
nsresult rv;
|
||||
// we don't care too much about failures here.
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsISelection> domSelection;
|
||||
rv = editor->GetSelection(getter_AddRefs(domSelection));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool selectionCollapsed = PR_FALSE;
|
||||
rv = domSelection->GetIsCollapsed(&selectionCollapsed);
|
||||
return selectionCollapsed;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
void
|
||||
nsComposerCommandsUpdater::Notify(nsITimer *timer)
|
||||
{
|
||||
NS_ASSERTION(timer == mUpdateTimer.get(), "Hey, this ain't my timer!");
|
||||
mUpdateTimer = NULL; // release my hold
|
||||
TimerCallback();
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
|
||||
nsresult NS_NewComposerCommandsUpdater(nsIEditor* aEditor, nsISelectionListener** aInstancePtrResult)
|
||||
{
|
||||
nsComposerCommandsUpdater* newThang = new nsComposerCommandsUpdater;
|
||||
if (!newThang)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aInstancePtrResult = nsnull;
|
||||
nsresult rv = newThang->SetEditor(aEditor);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete newThang;
|
||||
return rv;
|
||||
}
|
||||
|
||||
return newThang->QueryInterface(NS_GET_IID(nsISelectionListener), (void **)aInstancePtrResult);
|
||||
}
|
121
editor/composer/src/nsComposerCommandsUpdater.h
Normal file
121
editor/composer/src/nsComposerCommandsUpdater.h
Normal file
@ -0,0 +1,121 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef nsComposerCommandsUpdater_h__
|
||||
#define nsComposerCommandsUpdater_h__
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
#include "nsISelectionListener.h"
|
||||
#include "nsIDocumentStateListener.h"
|
||||
#include "nsITransactionListener.h"
|
||||
#include "nsITimerCallback.h"
|
||||
|
||||
|
||||
class nsIEditor;
|
||||
class nsIDocShell;
|
||||
class nsITransactionManager;
|
||||
|
||||
class nsComposerCommandsUpdater : public nsISelectionListener,
|
||||
public nsIDocumentStateListener,
|
||||
public nsITransactionListener,
|
||||
public nsITimerCallback
|
||||
{
|
||||
public:
|
||||
|
||||
nsComposerCommandsUpdater();
|
||||
virtual ~nsComposerCommandsUpdater();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISelectionListener
|
||||
NS_DECL_NSISELECTIONLISTENER
|
||||
|
||||
// nsIDocumentStateListener
|
||||
NS_DECL_NSIDOCUMENTSTATELISTENER
|
||||
|
||||
// nsITimerCallback interfaces
|
||||
NS_IMETHOD_(void) Notify(nsITimer *timer);
|
||||
|
||||
/** nsITransactionListener interfaces
|
||||
*/
|
||||
NS_IMETHOD WillDo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt);
|
||||
NS_IMETHOD DidDo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult);
|
||||
NS_IMETHOD WillUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt);
|
||||
NS_IMETHOD DidUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aUndoResult);
|
||||
NS_IMETHOD WillRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt);
|
||||
NS_IMETHOD DidRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult);
|
||||
NS_IMETHOD WillBeginBatch(nsITransactionManager *aManager, PRBool *aInterrupt);
|
||||
NS_IMETHOD DidBeginBatch(nsITransactionManager *aManager, nsresult aResult);
|
||||
NS_IMETHOD WillEndBatch(nsITransactionManager *aManager, PRBool *aInterrupt);
|
||||
NS_IMETHOD DidEndBatch(nsITransactionManager *aManager, nsresult aResult);
|
||||
NS_IMETHOD WillMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction,
|
||||
nsITransaction *aTransactionToMerge, PRBool *aInterrupt);
|
||||
NS_IMETHOD DidMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction,
|
||||
nsITransaction *aTransactionToMerge,
|
||||
PRBool aDidMerge, nsresult aMergeResult);
|
||||
|
||||
|
||||
nsresult SetEditor(nsIEditor* aEditor);
|
||||
|
||||
protected:
|
||||
|
||||
enum {
|
||||
eStateUninitialized = -1,
|
||||
eStateOff = PR_FALSE,
|
||||
eStateOn = PR_TRUE
|
||||
};
|
||||
|
||||
PRBool SelectionIsCollapsed();
|
||||
nsresult UpdateDirtyState(PRBool aNowDirty);
|
||||
nsresult CallUpdateCommands(const nsAReadableString& aCommand);
|
||||
|
||||
nsresult PrimeUpdateTimer();
|
||||
void TimerCallback();
|
||||
|
||||
|
||||
// this class should not hold references to the editor or editorShell. Doing
|
||||
// so would result in cirular reference chains.
|
||||
|
||||
nsIEditor* mEditor; // the HTML editor
|
||||
|
||||
nsIDocShell* mDocShell;
|
||||
|
||||
nsCOMPtr<nsITimer> mUpdateTimer;
|
||||
|
||||
PRInt8 mDirtyState;
|
||||
PRInt8 mSelectionCollapsed;
|
||||
PRPackedBool mFirstDoOfFirstUndo;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern "C" nsresult NS_NewComposerCommandsUpdater(nsIEditor* aEditor, nsISelectionListener** aInstancePtrResult);
|
||||
|
||||
|
||||
#endif // nsComposerCommandsUpdater_h__
|
685
editor/composer/src/nsEditingSession.cpp
Normal file
685
editor/composer/src/nsEditingSession.cpp
Normal file
@ -0,0 +1,685 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.org 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):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsISelectionPrivate.h"
|
||||
#include "nsITransactionManager.h"
|
||||
|
||||
#include "nsIEditorDocShell.h"
|
||||
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIWebProgress.h"
|
||||
|
||||
#include "nsIControllers.h"
|
||||
#include "nsIController.h"
|
||||
#include "nsIEditorController.h"
|
||||
|
||||
#include "nsIPresShell.h"
|
||||
|
||||
#include "nsComposerCommandsUpdater.h"
|
||||
|
||||
#include "nsEditingSession.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsISelectionController.h"
|
||||
|
||||
|
||||
#if DEBUG
|
||||
#define NOISY_DOC_LOADING 1
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
nsEditingSession
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
nsEditingSession::nsEditingSession()
|
||||
: mDoneSetup(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
~nsEditingSession
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
nsEditingSession::~nsEditingSession()
|
||||
{
|
||||
NS_IF_RELEASE(mStateMaintainer);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsEditingSession, nsIEditingSession, nsIWebProgressListener, nsISupportsWeakReference)
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
GetEditingShell
|
||||
|
||||
void init (in nsIDOMWindow aWindow)
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::Init(nsIDOMWindow *aWindow)
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mEditingShell = getter_AddRefs(NS_GetWeakReference(docShell));
|
||||
if (!mEditingShell) return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
MakeWindowEditable
|
||||
|
||||
void makeWindowEditable (in nsIDOMWindow aWindow, in boolean inDoAfterUriLoad);
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, PRBool inDoAfterUriLoad)
|
||||
{
|
||||
nsresult rv = PrepareForEditing();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell;
|
||||
rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// set the flag on the docShell to say that it's editable
|
||||
rv = editorDocShell->MakeEditable(inDoAfterUriLoad);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetupFrameControllers(aWindow);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// make an editor immediately
|
||||
if (!inDoAfterUriLoad)
|
||||
{
|
||||
rv = SetupEditorOnWindow(aWindow);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
WindowIsEditable
|
||||
|
||||
boolean windowIsEditable (in nsIDOMWindow aWindow);
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, PRBool *outIsEditable)
|
||||
{
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell;
|
||||
nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return editorDocShell->GetEditable(outIsEditable);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
SetupEditorOnWindow
|
||||
|
||||
nsIEditor setupEditorOnWindow (in nsIDOMWindow aWindow);
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow)
|
||||
{
|
||||
nsresult rv = PrepareForEditing();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(docShell, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEditor> editor(do_CreateInstance("@mozilla.org/editor/htmleditor;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// set the editor on the docShell. The docShell now owns it.
|
||||
rv = editorDocShell->SetEditor(editor);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
rv = docShell->GetPresShell(getter_AddRefs(presShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!presShell) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!contentViewer) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rv = contentViewer->GetDOMDocument(getter_AddRefs(domDoc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!domDoc) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(presShell);
|
||||
|
||||
rv = editor->Init(domDoc, presShell, nsnull /* root content */, selCon, 0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = editor->PostCreate();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// set the editor on the controller
|
||||
rv = SetEditorOnControllers(aWindow, editor);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// make the UI state maintainer
|
||||
NS_NEWXPCOM(mStateMaintainer, nsComposerCommandsUpdater);
|
||||
if (!mStateMaintainer) return NS_ERROR_OUT_OF_MEMORY;
|
||||
mStateMaintainer->AddRef(); // the owning reference
|
||||
|
||||
// now init the state maintainer
|
||||
// XXX this needs to swap out editors
|
||||
rv = mStateMaintainer->SetEditor(editor);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
editor->GetSelection(getter_AddRefs(selection));
|
||||
nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection);
|
||||
if (!selPriv) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = selPriv->AddSelectionListener(mStateMaintainer);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// and set it up as a doc state listener
|
||||
rv = editor->AddDocumentStateListener(NS_STATIC_CAST(nsIDocumentStateListener*, mStateMaintainer));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// and as a transaction listener
|
||||
nsCOMPtr<nsITransactionManager> txnMgr;
|
||||
editor->GetTransactionManager(getter_AddRefs(txnMgr));
|
||||
if (txnMgr)
|
||||
{
|
||||
txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
TearDownEditorOnWindow
|
||||
|
||||
void tearDownEditorOnWindow (in nsIDOMWindow aWindow);
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// null out the editor on the controller
|
||||
rv = SetEditorOnControllers(aWindow, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell;
|
||||
rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// null out the editor on the docShell
|
||||
rv = editorDocShell->SetEditor(nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
GetEditorForFrame
|
||||
|
||||
nsIEditor getEditorForFrame (in nsIDOMWindow aWindow);
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsIEditor **outEditor)
|
||||
{
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell;
|
||||
nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return editorDocShell->GetEditor(outEditor);
|
||||
}
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
OnStateChange
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
|
||||
{
|
||||
//
|
||||
// A Request has started...
|
||||
//
|
||||
if (aStateFlags & nsIWebProgressListener::STATE_START)
|
||||
{
|
||||
// Page level notification...
|
||||
if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK)
|
||||
{
|
||||
StartPageLoad(aWebProgress);
|
||||
}
|
||||
|
||||
// Document level notification...
|
||||
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT)
|
||||
{
|
||||
if (NotifyingCurrentDocument(aWebProgress))
|
||||
(void)StartDocumentLoad(aWebProgress);
|
||||
}
|
||||
}
|
||||
//
|
||||
// A Request is being processed
|
||||
//
|
||||
else if (aStateFlags & nsIWebProgressListener::STATE_TRANSFERRING)
|
||||
{
|
||||
if (aStateFlags * nsIWebProgressListener::STATE_IS_DOCUMENT)
|
||||
{
|
||||
// document transfer started
|
||||
}
|
||||
}
|
||||
//
|
||||
// Got a redirection
|
||||
//
|
||||
else if (aStateFlags & nsIWebProgressListener::STATE_REDIRECTING)
|
||||
{
|
||||
if (aStateFlags * nsIWebProgressListener::STATE_IS_DOCUMENT)
|
||||
{
|
||||
// got a redirect
|
||||
}
|
||||
}
|
||||
//
|
||||
// A network or document Request as finished...
|
||||
//
|
||||
else if (aStateFlags & nsIWebProgressListener::STATE_STOP)
|
||||
{
|
||||
|
||||
// Document level notification...
|
||||
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT)
|
||||
{
|
||||
if (NotifyingCurrentDocument(aWebProgress))
|
||||
{
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||
(void)EndDocumentLoad(aWebProgress, channel, aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
// Page level notification...
|
||||
if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK)
|
||||
{
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||
(void)EndPageLoad(aWebProgress, channel, aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
OnProgressChange
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
OnLocationChange
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
OnStatusChange
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
OnSecurityChange
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsEditingSession::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
NotifyingCurrentDocument
|
||||
|
||||
Check that this notification is for our document. Necessary?
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
PRBool
|
||||
nsEditingSession::NotifyingCurrentDocument(nsIWebProgress *aWebProgress)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
StartDocumentLoad
|
||||
|
||||
Called on start of load in a single frame
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::StartDocumentLoad(nsIWebProgress *aWebProgress)
|
||||
{
|
||||
#ifdef NOISY_DOC_LOADING
|
||||
printf("Editing session StartDocumentLoad\n");
|
||||
#endif
|
||||
|
||||
NS_ENSURE_ARG(aWebProgress);
|
||||
|
||||
// If we have an editor here, then we got a reload after making the editor.
|
||||
// We need to blow it away and make a new one at the end of the load.
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
||||
|
||||
if (domWindow)
|
||||
{
|
||||
nsresult rv = TearDownEditorOnWindow(domWindow);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
EndDocumentLoad
|
||||
|
||||
Called on end of load in a single frame
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus)
|
||||
{
|
||||
NS_ENSURE_ARG(aWebProgress);
|
||||
|
||||
#ifdef NOISY_DOC_LOADING
|
||||
printf("Editing shell EndDocumentLoad\n");
|
||||
#endif
|
||||
// we want to call the base class EndDocumentLoad, but avoid some of the stuff
|
||||
// that nsWebShell does (need to refactor).
|
||||
|
||||
// OK, time to make an editor on this document
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsresult rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv; // better error handling?
|
||||
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(docShell));
|
||||
// did someone set the flag to make this shell editable?
|
||||
if (editorDocShell)
|
||||
{
|
||||
PRBool makeEditable;
|
||||
editorDocShell->GetEditable(&makeEditable);
|
||||
|
||||
if (makeEditable)
|
||||
{
|
||||
nsresult rv = SetupEditorOnWindow(domWindow);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
StartPageLoad
|
||||
|
||||
Called on start load of the entire page (incl. subframes)
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::StartPageLoad(nsIWebProgress *aWebProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
EndPageLoad
|
||||
|
||||
Called on end load of the entire page (incl. subframes)
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
GetDocShellFromWindow
|
||||
|
||||
Utility method. This will always return an error if no docShell
|
||||
is returned.
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGO(do_QueryInterface(inWindow));
|
||||
if (!scriptGO) return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = scriptGO->GetDocShell(outDocShell);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!*outDocShell) return NS_ERROR_FAILURE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
GetEditorDocShellFromWindow
|
||||
|
||||
Utility method. This will always return an error if no docShell
|
||||
is returned.
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *inWindow, nsIEditorDocShell** outDocShell)
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsresult rv = GetDocShellFromWindow(inWindow, getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell), (void **)outDocShell);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
PrepareForEditing
|
||||
|
||||
Set up this editing session for one or more editors
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::PrepareForEditing()
|
||||
{
|
||||
if (mDoneSetup)
|
||||
return NS_OK;
|
||||
|
||||
mDoneSetup = PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mEditingShell);
|
||||
if (!docShell) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(docShell);
|
||||
if (!domWindow) return NS_ERROR_FAILURE;
|
||||
|
||||
// register callback
|
||||
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
|
||||
if (!webProgress) return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = webProgress->AddProgressListener(this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
SetupFrameControllers
|
||||
|
||||
Set up the controller for this frame.
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::SetupFrameControllers(nsIDOMWindow *inWindow)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindowInt(do_QueryInterface(inWindow, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
rv = domWindowInt->GetControllers(getter_AddRefs(controllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// the first is an editor controller, and takes an nsIEditor as the refCon
|
||||
nsCOMPtr<nsIController> controller(do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEditorController> editorController(do_QueryInterface(controller));
|
||||
rv = editorController->Init(nsnull); // we set the editor later when we have one
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = controllers->InsertControllerAt(0, controller);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// the second is an composer controller, and also takes an nsIEditor as the refCon
|
||||
controller = do_CreateInstance("@mozilla.org/editor/composercontroller;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEditorController> composerController(do_QueryInterface(controller));
|
||||
rv = composerController->Init(nsnull); // we set the editor later when we have one
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = controllers->InsertControllerAt(1, controller);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
SetEditorOnControllers
|
||||
|
||||
Set the editor on the controller(s) for this window
|
||||
----------------------------------------------------------------------------*/
|
||||
nsresult
|
||||
nsEditingSession::SetEditorOnControllers(nsIDOMWindow *inWindow, nsIEditor* inEditor)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// set the editor on the controller
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindowInt(do_QueryInterface(inWindow, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
rv = domWindowInt->GetControllers(getter_AddRefs(controllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// find the editor controllers by QIing each one. This sucks.
|
||||
// Controllers need to have IDs of some kind.
|
||||
PRUint32 numControllers;
|
||||
rv = controllers->GetControllerCount(&numControllers);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (PRUint32 i = 0; i < numControllers; i ++)
|
||||
{
|
||||
nsCOMPtr<nsIController> thisController;
|
||||
controllers->GetControllerAt(i, getter_AddRefs(thisController));
|
||||
|
||||
nsCOMPtr<nsIEditorController> editorController(do_QueryInterface(thisController)); // ok with nil controller
|
||||
if (editorController)
|
||||
{
|
||||
rv = editorController->SetCommandRefCon(inEditor);
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
35
embedding/tests/mfcembed/CCommandObserver.cpp
Normal file
35
embedding/tests/mfcembed/CCommandObserver.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "stdafx.h"
|
||||
#include "CCommandObserver.h"
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(CCommandObserver)
|
||||
NS_IMPL_RELEASE(CCommandObserver)
|
||||
NS_IMPL_QUERY_INTERFACE1(CCommandObserver, nsIObserver)
|
||||
|
||||
|
||||
|
||||
CCommandObserver::CCommandObserver()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mFrame = 0;
|
||||
}
|
||||
|
||||
|
||||
/* void observe (in nsISupports aSubject, in string aTopic, in wstring aData); */
|
||||
NS_IMETHODIMP
|
||||
CCommandObserver::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
|
||||
{
|
||||
if (!mFrame)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
mFrame->KillTimer(mTimerId);
|
||||
mFrame->SetTimer(mTimerId,mDelay,0);//reset delay on update.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
CCommandObserver::SetFrame(CFrameWnd *frame,UINT timerId,UINT delay) //update if 100 ticks goes by and no more changes
|
||||
{
|
||||
mFrame = frame;
|
||||
mDelay = delay;
|
||||
mTimerId = timerId;
|
||||
}
|
24
embedding/tests/mfcembed/CCommandObserver.h
Normal file
24
embedding/tests/mfcembed/CCommandObserver.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class CFrameWnd;
|
||||
|
||||
|
||||
class CCommandObserver : public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
CCommandObserver();
|
||||
~CCommandObserver(){}
|
||||
//NSIOBSERVER
|
||||
NS_DECL_NSIOBSERVER
|
||||
//CCommandObserver
|
||||
void SetFrame(CFrameWnd *frame,UINT timerId,UINT delay); //update if 100 ticks goes by and no more changes
|
||||
private:
|
||||
CFrameWnd *mFrame;
|
||||
UINT mDelay;
|
||||
UINT mTimerId;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user