зеркало из https://github.com/mozilla/pjs.git
New files necessary for phase 1 of editor reorganization checkin.
r=jfrancis, sr=kin,sfraser
This commit is contained in:
Родитель
bf66c168dd
Коммит
a82b0338ad
|
@ -0,0 +1,259 @@
|
|||
/* -*- 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 Communicator client 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):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Ryan Cassin <rcassin@supernova.org>
|
||||
*/
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsComposerController.h"
|
||||
#include "nsIEditorShell.h"
|
||||
|
||||
#if 0
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIEditorMailSupport.h"
|
||||
#include "nsIFormControlFrame.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include "nsISelectionController.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
|
||||
#include "nsEditorCommands.h"
|
||||
#endif
|
||||
|
||||
#include "nsComposerCommands.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsComposerController)
|
||||
NS_IMPL_RELEASE(nsComposerController)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsComposerController)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIController)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIEditorController)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
nsComposerController::nsComposerController()
|
||||
{
|
||||
}
|
||||
|
||||
nsComposerController::~nsComposerController()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// get our ref to the singleton command manager
|
||||
rv = GetComposerCommandManager(getter_AddRefs(mCommandManager));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mCommandRefCon = aCommandRefCon; // no addref
|
||||
|
||||
mCommandManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// register the commands.
|
||||
rv = nsComposerController::RegisterComposerCommands(mCommandManager);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::SetCommandRefCon(nsISupports *aCommandRefCon)
|
||||
{
|
||||
mCommandRefCon = aCommandRefCon; // no addref
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::GetInterface(const nsIID & aIID, void * *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
if (NS_SUCCEEDED(QueryInterface(aIID, result)))
|
||||
return NS_OK;
|
||||
|
||||
if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
|
||||
return mCommandManager->QueryInterface(aIID, result);
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
#define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
|
||||
{ \
|
||||
_cmdClass* theCmd; \
|
||||
NS_NEWXPCOM(theCmd, _cmdClass); \
|
||||
if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
|
||||
}
|
||||
|
||||
#define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName) \
|
||||
{ \
|
||||
_cmdClass* theCmd; \
|
||||
NS_NEWXPCOM(theCmd, _cmdClass); \
|
||||
if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd));
|
||||
|
||||
#define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd));
|
||||
|
||||
#define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
|
||||
}
|
||||
|
||||
#define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \
|
||||
{ \
|
||||
_cmdClass* theCmd = new _cmdClass(_styleTag); \
|
||||
if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// File menu
|
||||
NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print");
|
||||
NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup");
|
||||
NS_REGISTER_NEXT_COMMAND(nsPrintingCommands,"cmd_print_button");
|
||||
NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview");
|
||||
|
||||
// Edit menu
|
||||
NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
|
||||
|
||||
// indent/outdent
|
||||
NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent");
|
||||
NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent");
|
||||
|
||||
// Styles
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u");
|
||||
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr");
|
||||
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
|
||||
|
||||
// lists
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
|
||||
NS_REGISTER_ONE_COMMAND(nsRemoveListCommand, "cmd_removeList");
|
||||
|
||||
// format stuff
|
||||
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
|
||||
NS_REGISTER_ONE_COMMAND(nsFontFaceStateCommand, "cmd_fontFace");
|
||||
NS_REGISTER_ONE_COMMAND(nsFontColorStateCommand, "cmd_fontColor");
|
||||
NS_REGISTER_ONE_COMMAND(nsBackgroundColorStateCommand, "cmd_backgroundColor");
|
||||
|
||||
NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align");
|
||||
NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles");
|
||||
|
||||
NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
|
||||
NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* =======================================================================
|
||||
* nsIController
|
||||
* ======================================================================= */
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::IsCommandEnabled(const nsAReadableString & aCommand,
|
||||
PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::SupportsCommand(const nsAReadableString & aCommand,
|
||||
PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::DoCommand(const nsAReadableString & aCommand)
|
||||
{
|
||||
return mCommandManager->DoCommand(aCommand, mCommandRefCon);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::OnEvent(const nsAReadableString & aEventName)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsWeakPtr nsComposerController::sComposerCommandManager = NULL;
|
||||
|
||||
// static
|
||||
nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outCommandManager);
|
||||
|
||||
nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sComposerCommandManager);
|
||||
if (!cmdManager)
|
||||
{
|
||||
nsresult rv;
|
||||
cmdManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// register the commands. This just happens once per instance
|
||||
rv = nsComposerController::RegisterComposerCommands(cmdManager);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// save the singleton in our static weak reference
|
||||
sComposerCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(*outCommandManager = cmdManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/* -*- 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 Communicator client 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):
|
||||
*/
|
||||
|
||||
#ifndef nsComposerController_h__
|
||||
#define nsComposerController_h__
|
||||
|
||||
#define NS_COMPOSERCONTROLLER_CID \
|
||||
{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsIEditorController.h"
|
||||
#include "nsIController.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIControllerCommand.h"
|
||||
#include "nsWeakPtr.h"
|
||||
|
||||
// the editor controller is used for composer only (and other HTML compose
|
||||
// areas). The refCon that gets passed to its commands is an nsIEditorShell.
|
||||
|
||||
class nsComposerController : public nsIController,
|
||||
public nsIEditorController,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
public:
|
||||
|
||||
nsComposerController();
|
||||
virtual ~nsComposerController();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIController
|
||||
NS_DECL_NSICONTROLLER
|
||||
|
||||
/** init the controller */
|
||||
NS_IMETHOD Init(nsISupports *aCommandRefCon);
|
||||
|
||||
/** Set the cookie that is passed to commands
|
||||
*/
|
||||
NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon);
|
||||
|
||||
// nsIInterfaceRequestor
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
protected:
|
||||
|
||||
//if editor is null then look to mContent. this is for dual use of window and content
|
||||
//attached controller.
|
||||
nsISupports *mCommandRefCon;
|
||||
|
||||
nsCOMPtr<nsIControllerCommandManager> mCommandManager; // our reference to the command manager
|
||||
|
||||
private:
|
||||
|
||||
static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager);
|
||||
static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager);
|
||||
|
||||
// the singleton command manager
|
||||
static nsWeakPtr sComposerCommandManager; // common composer commands
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsComposerController_h__ */
|
|
@ -0,0 +1,145 @@
|
|||
/* -*- 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):
|
||||
*/
|
||||
|
||||
#include "nsTextEditUtils.h"
|
||||
|
||||
#include "nsEditor.h"
|
||||
#include "nsPlaintextEditor.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/********************************************************
|
||||
* helper methods from nsTextEditRules
|
||||
********************************************************/
|
||||
|
||||
PRBool
|
||||
nsTextEditUtils::NodeIsType(nsIDOMNode *aNode, const nsAReadableString& aTag)
|
||||
{
|
||||
NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::NodeIsType");
|
||||
if (aNode)
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsEditor::GetTagString(aNode,tag);
|
||||
tag.ToLowerCase();
|
||||
if (tag.Equals(aTag))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
* helper methods from nsTextEditRules
|
||||
********************************************************/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IsBody: true if node an html body node
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::IsBody(nsIDOMNode *node)
|
||||
{
|
||||
return NodeIsType(node, NS_LITERAL_STRING("body"));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IsBreak: true if node an html break node
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::IsBreak(nsIDOMNode *node)
|
||||
{
|
||||
return NodeIsType(node, NS_LITERAL_STRING("br"));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IsMozBR: true if node an html br node with type = _moz
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::IsMozBR(nsIDOMNode *node)
|
||||
{
|
||||
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR");
|
||||
if (IsBreak(node) && HasMozAttr(node)) return PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// HasMozAttr: true if node has type attribute = _moz
|
||||
// (used to indicate the div's and br's we use in
|
||||
// mail compose rules)
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::HasMozAttr(nsIDOMNode *node)
|
||||
{
|
||||
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr");
|
||||
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
|
||||
if (elem)
|
||||
{
|
||||
nsAutoString typeAttrName; typeAttrName.AssignWithConversion("type");
|
||||
nsAutoString typeAttrVal;
|
||||
nsresult res = elem->GetAttribute(typeAttrName, typeAttrVal);
|
||||
typeAttrVal.ToLowerCase();
|
||||
if (NS_SUCCEEDED(res) && (typeAttrVal.EqualsWithConversion("_moz")))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// InBody: true if node is a descendant of the body
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::InBody(nsIDOMNode *node, nsIEditor *editor)
|
||||
{
|
||||
if ( node )
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> bodyElement;
|
||||
nsresult res = editor->GetRootElement(getter_AddRefs(bodyElement));
|
||||
if (NS_FAILED(res) || !bodyElement)
|
||||
return res?res:NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMNode> bodyNode = do_QueryInterface(bodyElement);
|
||||
nsCOMPtr<nsIDOMNode> tmp;
|
||||
nsCOMPtr<nsIDOMNode> p = node;
|
||||
while (p && p!= bodyNode)
|
||||
{
|
||||
if (NS_FAILED(p->GetParentNode(getter_AddRefs(tmp))) || !tmp)
|
||||
return PR_FALSE;
|
||||
p = tmp;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// nsAutoEditInitRulesTrigger methods
|
||||
//
|
||||
nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes) : mEd(aEd), mRes(aRes)
|
||||
{
|
||||
if (mEd) mEd->BeginEditorInit();
|
||||
}
|
||||
|
||||
nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger()
|
||||
{
|
||||
if (mEd) mRes = mEd->EndEditorInit();
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* -*- 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):
|
||||
*/
|
||||
|
||||
#ifndef nsTextEditUtils_h__
|
||||
#define nsTextEditUtils_h__
|
||||
|
||||
#include "prtypes.h" // for PRBool
|
||||
#include "nsError.h" // for nsresult
|
||||
#include "nsString.h" // for nsAReadableString
|
||||
class nsIDOMNode;
|
||||
class nsIEditor;
|
||||
class nsPlaintextEditor;
|
||||
|
||||
class nsTextEditUtils
|
||||
{
|
||||
public:
|
||||
static PRBool NodeIsType(nsIDOMNode *aNode, const nsAReadableString& aTag);
|
||||
|
||||
// from nsTextEditRules:
|
||||
static PRBool IsBody(nsIDOMNode *aNode);
|
||||
static PRBool IsBreak(nsIDOMNode *aNode);
|
||||
static PRBool IsMozBR(nsIDOMNode *aNode);
|
||||
static PRBool HasMozAttr(nsIDOMNode *aNode);
|
||||
static PRBool InBody(nsIDOMNode *aNode, nsIEditor *aEditor);
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
* stack based helper class for detecting end of editor initialization, in
|
||||
* order to triger "end of init" initialization of the edit rules.
|
||||
*/
|
||||
class nsAutoEditInitRulesTrigger
|
||||
{
|
||||
private:
|
||||
nsPlaintextEditor *mEd;
|
||||
nsresult &mRes;
|
||||
public:
|
||||
nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes);
|
||||
~nsAutoEditInitRulesTrigger();
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsTextEditUtils_h__ */
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
/* -*- 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 Communicator client 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):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Ryan Cassin <rcassin@supernova.org>
|
||||
*/
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsComposerController.h"
|
||||
#include "nsIEditorShell.h"
|
||||
|
||||
#if 0
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIEditorMailSupport.h"
|
||||
#include "nsIFormControlFrame.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include "nsISelectionController.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
|
||||
#include "nsEditorCommands.h"
|
||||
#endif
|
||||
|
||||
#include "nsComposerCommands.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsComposerController)
|
||||
NS_IMPL_RELEASE(nsComposerController)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsComposerController)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIController)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIEditorController)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
nsComposerController::nsComposerController()
|
||||
{
|
||||
}
|
||||
|
||||
nsComposerController::~nsComposerController()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// get our ref to the singleton command manager
|
||||
rv = GetComposerCommandManager(getter_AddRefs(mCommandManager));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mCommandRefCon = aCommandRefCon; // no addref
|
||||
|
||||
mCommandManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// register the commands.
|
||||
rv = nsComposerController::RegisterComposerCommands(mCommandManager);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::SetCommandRefCon(nsISupports *aCommandRefCon)
|
||||
{
|
||||
mCommandRefCon = aCommandRefCon; // no addref
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::GetInterface(const nsIID & aIID, void * *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
if (NS_SUCCEEDED(QueryInterface(aIID, result)))
|
||||
return NS_OK;
|
||||
|
||||
if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
|
||||
return mCommandManager->QueryInterface(aIID, result);
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
#define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
|
||||
{ \
|
||||
_cmdClass* theCmd; \
|
||||
NS_NEWXPCOM(theCmd, _cmdClass); \
|
||||
if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
|
||||
}
|
||||
|
||||
#define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName) \
|
||||
{ \
|
||||
_cmdClass* theCmd; \
|
||||
NS_NEWXPCOM(theCmd, _cmdClass); \
|
||||
if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd));
|
||||
|
||||
#define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd));
|
||||
|
||||
#define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
|
||||
}
|
||||
|
||||
#define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \
|
||||
{ \
|
||||
_cmdClass* theCmd = new _cmdClass(_styleTag); \
|
||||
if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \
|
||||
rv = inCommandManager->RegisterCommand(NS_LITERAL_STRING(_cmdName), \
|
||||
NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// File menu
|
||||
NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print");
|
||||
NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup");
|
||||
NS_REGISTER_NEXT_COMMAND(nsPrintingCommands,"cmd_print_button");
|
||||
NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview");
|
||||
|
||||
// Edit menu
|
||||
NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
|
||||
|
||||
// indent/outdent
|
||||
NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent");
|
||||
NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent");
|
||||
|
||||
// Styles
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u");
|
||||
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr");
|
||||
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp");
|
||||
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
|
||||
|
||||
// lists
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
|
||||
NS_REGISTER_ONE_COMMAND(nsRemoveListCommand, "cmd_removeList");
|
||||
|
||||
// format stuff
|
||||
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
|
||||
NS_REGISTER_ONE_COMMAND(nsFontFaceStateCommand, "cmd_fontFace");
|
||||
NS_REGISTER_ONE_COMMAND(nsFontColorStateCommand, "cmd_fontColor");
|
||||
NS_REGISTER_ONE_COMMAND(nsBackgroundColorStateCommand, "cmd_backgroundColor");
|
||||
|
||||
NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align");
|
||||
NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles");
|
||||
|
||||
NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
|
||||
NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* =======================================================================
|
||||
* nsIController
|
||||
* ======================================================================= */
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::IsCommandEnabled(const nsAReadableString & aCommand,
|
||||
PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::SupportsCommand(const nsAReadableString & aCommand,
|
||||
PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::DoCommand(const nsAReadableString & aCommand)
|
||||
{
|
||||
return mCommandManager->DoCommand(aCommand, mCommandRefCon);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposerController::OnEvent(const nsAReadableString & aEventName)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsWeakPtr nsComposerController::sComposerCommandManager = NULL;
|
||||
|
||||
// static
|
||||
nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outCommandManager);
|
||||
|
||||
nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sComposerCommandManager);
|
||||
if (!cmdManager)
|
||||
{
|
||||
nsresult rv;
|
||||
cmdManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// register the commands. This just happens once per instance
|
||||
rv = nsComposerController::RegisterComposerCommands(cmdManager);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// save the singleton in our static weak reference
|
||||
sComposerCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(*outCommandManager = cmdManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/* -*- 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 Communicator client 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):
|
||||
*/
|
||||
|
||||
#ifndef nsComposerController_h__
|
||||
#define nsComposerController_h__
|
||||
|
||||
#define NS_COMPOSERCONTROLLER_CID \
|
||||
{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsIEditorController.h"
|
||||
#include "nsIController.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIControllerCommand.h"
|
||||
#include "nsWeakPtr.h"
|
||||
|
||||
// the editor controller is used for composer only (and other HTML compose
|
||||
// areas). The refCon that gets passed to its commands is an nsIEditorShell.
|
||||
|
||||
class nsComposerController : public nsIController,
|
||||
public nsIEditorController,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
public:
|
||||
|
||||
nsComposerController();
|
||||
virtual ~nsComposerController();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIController
|
||||
NS_DECL_NSICONTROLLER
|
||||
|
||||
/** init the controller */
|
||||
NS_IMETHOD Init(nsISupports *aCommandRefCon);
|
||||
|
||||
/** Set the cookie that is passed to commands
|
||||
*/
|
||||
NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon);
|
||||
|
||||
// nsIInterfaceRequestor
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
protected:
|
||||
|
||||
//if editor is null then look to mContent. this is for dual use of window and content
|
||||
//attached controller.
|
||||
nsISupports *mCommandRefCon;
|
||||
|
||||
nsCOMPtr<nsIControllerCommandManager> mCommandManager; // our reference to the command manager
|
||||
|
||||
private:
|
||||
|
||||
static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager);
|
||||
static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager);
|
||||
|
||||
// the singleton command manager
|
||||
static nsWeakPtr sComposerCommandManager; // common composer commands
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsComposerController_h__ */
|
|
@ -0,0 +1,145 @@
|
|||
/* -*- 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):
|
||||
*/
|
||||
|
||||
#include "nsTextEditUtils.h"
|
||||
|
||||
#include "nsEditor.h"
|
||||
#include "nsPlaintextEditor.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/********************************************************
|
||||
* helper methods from nsTextEditRules
|
||||
********************************************************/
|
||||
|
||||
PRBool
|
||||
nsTextEditUtils::NodeIsType(nsIDOMNode *aNode, const nsAReadableString& aTag)
|
||||
{
|
||||
NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::NodeIsType");
|
||||
if (aNode)
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsEditor::GetTagString(aNode,tag);
|
||||
tag.ToLowerCase();
|
||||
if (tag.Equals(aTag))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
* helper methods from nsTextEditRules
|
||||
********************************************************/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IsBody: true if node an html body node
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::IsBody(nsIDOMNode *node)
|
||||
{
|
||||
return NodeIsType(node, NS_LITERAL_STRING("body"));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IsBreak: true if node an html break node
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::IsBreak(nsIDOMNode *node)
|
||||
{
|
||||
return NodeIsType(node, NS_LITERAL_STRING("br"));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IsMozBR: true if node an html br node with type = _moz
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::IsMozBR(nsIDOMNode *node)
|
||||
{
|
||||
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR");
|
||||
if (IsBreak(node) && HasMozAttr(node)) return PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// HasMozAttr: true if node has type attribute = _moz
|
||||
// (used to indicate the div's and br's we use in
|
||||
// mail compose rules)
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::HasMozAttr(nsIDOMNode *node)
|
||||
{
|
||||
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr");
|
||||
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
|
||||
if (elem)
|
||||
{
|
||||
nsAutoString typeAttrName; typeAttrName.AssignWithConversion("type");
|
||||
nsAutoString typeAttrVal;
|
||||
nsresult res = elem->GetAttribute(typeAttrName, typeAttrVal);
|
||||
typeAttrVal.ToLowerCase();
|
||||
if (NS_SUCCEEDED(res) && (typeAttrVal.EqualsWithConversion("_moz")))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// InBody: true if node is a descendant of the body
|
||||
//
|
||||
PRBool
|
||||
nsTextEditUtils::InBody(nsIDOMNode *node, nsIEditor *editor)
|
||||
{
|
||||
if ( node )
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> bodyElement;
|
||||
nsresult res = editor->GetRootElement(getter_AddRefs(bodyElement));
|
||||
if (NS_FAILED(res) || !bodyElement)
|
||||
return res?res:NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMNode> bodyNode = do_QueryInterface(bodyElement);
|
||||
nsCOMPtr<nsIDOMNode> tmp;
|
||||
nsCOMPtr<nsIDOMNode> p = node;
|
||||
while (p && p!= bodyNode)
|
||||
{
|
||||
if (NS_FAILED(p->GetParentNode(getter_AddRefs(tmp))) || !tmp)
|
||||
return PR_FALSE;
|
||||
p = tmp;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// nsAutoEditInitRulesTrigger methods
|
||||
//
|
||||
nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes) : mEd(aEd), mRes(aRes)
|
||||
{
|
||||
if (mEd) mEd->BeginEditorInit();
|
||||
}
|
||||
|
||||
nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger()
|
||||
{
|
||||
if (mEd) mRes = mEd->EndEditorInit();
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* -*- 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):
|
||||
*/
|
||||
|
||||
#ifndef nsTextEditUtils_h__
|
||||
#define nsTextEditUtils_h__
|
||||
|
||||
#include "prtypes.h" // for PRBool
|
||||
#include "nsError.h" // for nsresult
|
||||
#include "nsString.h" // for nsAReadableString
|
||||
class nsIDOMNode;
|
||||
class nsIEditor;
|
||||
class nsPlaintextEditor;
|
||||
|
||||
class nsTextEditUtils
|
||||
{
|
||||
public:
|
||||
static PRBool NodeIsType(nsIDOMNode *aNode, const nsAReadableString& aTag);
|
||||
|
||||
// from nsTextEditRules:
|
||||
static PRBool IsBody(nsIDOMNode *aNode);
|
||||
static PRBool IsBreak(nsIDOMNode *aNode);
|
||||
static PRBool IsMozBR(nsIDOMNode *aNode);
|
||||
static PRBool HasMozAttr(nsIDOMNode *aNode);
|
||||
static PRBool InBody(nsIDOMNode *aNode, nsIEditor *aEditor);
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
* stack based helper class for detecting end of editor initialization, in
|
||||
* order to triger "end of init" initialization of the edit rules.
|
||||
*/
|
||||
class nsAutoEditInitRulesTrigger
|
||||
{
|
||||
private:
|
||||
nsPlaintextEditor *mEd;
|
||||
nsresult &mRes;
|
||||
public:
|
||||
nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes);
|
||||
~nsAutoEditInitRulesTrigger();
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsTextEditUtils_h__ */
|
||||
|
Загрузка…
Ссылка в новой задаче