1999-03-10 22:53:26 +03:00
|
|
|
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsTextEditRules_h__
|
|
|
|
#define nsTextEditRules_h__
|
|
|
|
|
|
|
|
#include "nsIEditor.h"
|
1999-04-05 21:21:59 +04:00
|
|
|
#include "nsEditRules.h"
|
1999-03-10 22:53:26 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-03-15 03:57:32 +03:00
|
|
|
#include "nsIDOMNode.h"
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
#include "TypeInState.h"
|
1999-03-10 22:53:26 +03:00
|
|
|
|
1999-03-15 03:57:32 +03:00
|
|
|
class PlaceholderTxn;
|
1999-04-05 21:21:59 +04:00
|
|
|
class nsTextEditor;
|
1999-03-10 22:53:26 +03:00
|
|
|
|
|
|
|
/** Object that encapsulates HTML text-specific editing rules.
|
|
|
|
*
|
|
|
|
* To be a good citizen, edit rules must live by these restrictions:
|
|
|
|
* 1. All data manipulation is through the editor.
|
|
|
|
* Content nodes in the document tree must <B>not</B> be manipulated directly.
|
|
|
|
* Content nodes in document fragments that are not part of the document itself
|
|
|
|
* may be manipulated at will. Operations on document fragments must <B>not</B>
|
|
|
|
* go through the editor.
|
|
|
|
* 2. Selection must not be explicitly set by the rule method.
|
|
|
|
* Any manipulation of Selection must be done by the editor.
|
|
|
|
*/
|
1999-04-05 21:21:59 +04:00
|
|
|
class nsTextEditRules : public nsEditRules
|
1999-03-10 22:53:26 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsTextEditRules();
|
|
|
|
virtual ~nsTextEditRules();
|
|
|
|
|
1999-04-05 21:21:59 +04:00
|
|
|
// nsEditRules methods
|
|
|
|
NS_IMETHOD Init(nsIEditor *aEditor);
|
1999-04-12 16:01:32 +04:00
|
|
|
NS_IMETHOD WillDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel);
|
|
|
|
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
|
1999-04-05 21:21:59 +04:00
|
|
|
|
|
|
|
// nsTextEditRules action id's
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kUndo = 1000,
|
|
|
|
kRedo = 1001,
|
|
|
|
kInsertText = 2000,
|
|
|
|
kDeleteSelection = 2001
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
1999-03-10 22:53:26 +03:00
|
|
|
|
1999-04-05 21:21:59 +04:00
|
|
|
// nsTextEditRules implementation methods
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult WillInsertText(nsIDOMSelection *aSelection,
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
PRBool *aCancel,
|
1999-04-12 16:01:32 +04:00
|
|
|
PlaceholderTxn **aTxn,
|
|
|
|
const nsString *inString,
|
|
|
|
nsString *outString,
|
|
|
|
TypeInState typeInState);
|
|
|
|
nsresult DidInsertText(nsIDOMSelection *aSelection, nsresult aResult);
|
|
|
|
nsresult CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInState &aTypeInState);
|
1999-03-13 07:53:21 +03:00
|
|
|
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel);
|
|
|
|
nsresult DidInsert(nsIDOMSelection *aSelection, nsresult aResult);
|
1999-03-13 07:53:21 +03:00
|
|
|
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult WillDeleteSelection(nsIDOMSelection *aSelection, PRBool *aCancel);
|
|
|
|
nsresult DidDeleteSelection(nsIDOMSelection *aSelection, nsresult aResult);
|
1999-03-12 05:28:24 +03:00
|
|
|
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult WillUndo(nsIDOMSelection *aSelection, PRBool *aCancel);
|
|
|
|
nsresult DidUndo(nsIDOMSelection *aSelection, nsresult aResult);
|
1999-03-15 08:08:30 +03:00
|
|
|
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult WillRedo(nsIDOMSelection *aSelection, PRBool *aCancel);
|
|
|
|
nsresult DidRedo(nsIDOMSelection *aSelection, nsresult aResult);
|
1999-03-15 08:08:30 +03:00
|
|
|
|
1999-03-29 12:02:05 +04:00
|
|
|
// helper functions
|
|
|
|
static PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag);
|
|
|
|
static PRBool IsEditable(nsIDOMNode *aNode);
|
|
|
|
|
1999-04-05 00:10:39 +04:00
|
|
|
/** insert aNode into a new style node of type aTag.
|
|
|
|
* aSelection is optional. If provided, aSelection is set to (aNode, 0)
|
|
|
|
* if aNode was successfully placed in a new style node
|
|
|
|
*/
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult InsertStyleNode(nsIDOMNode *aNode,
|
1999-04-06 00:52:29 +04:00
|
|
|
nsIAtom *aTag,
|
|
|
|
nsIDOMSelection *aSelection);
|
|
|
|
|
|
|
|
/** create a new style node of type aTag in aParentNode, and put a new text node
|
|
|
|
* in the new style node.
|
|
|
|
* If aSelection is provided and points to a text node, just call InsertStyleNode instead.
|
|
|
|
* aSelection is optional. If provided, aSelection is set to (newTextNode, 0)
|
|
|
|
* if newTextNode was successfully created.
|
|
|
|
*/
|
1999-04-12 16:01:32 +04:00
|
|
|
nsresult InsertStyleAndNewTextNode(nsIDOMNode *aParentNode,
|
1999-04-06 00:52:29 +04:00
|
|
|
nsIAtom *aTag,
|
|
|
|
nsIDOMSelection *aSelection);
|
1999-04-05 00:10:39 +04:00
|
|
|
|
1999-04-05 21:21:59 +04:00
|
|
|
// data
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
nsTextEditor *mEditor; // note that we do not refcount the editor
|
1999-03-15 03:57:32 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> mBogusNode; // magic node acts as placeholder in empty doc
|
1999-03-10 22:53:26 +03:00
|
|
|
};
|
|
|
|
|
1999-04-12 16:01:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
class nsTextRulesInfo : public nsRulesInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsTextRulesInfo(int aAction) : nsRulesInfo(aAction),placeTxn(0),inString(0),outString(0),typeInState() {}
|
|
|
|
virtual ~nsTextRulesInfo() {}
|
|
|
|
|
|
|
|
// used by kInsertText
|
|
|
|
PlaceholderTxn **placeTxn;
|
|
|
|
const nsString *inString;
|
|
|
|
nsString *outString;
|
|
|
|
TypeInState typeInState;
|
|
|
|
};
|
|
|
|
|
1999-03-10 22:53:26 +03:00
|
|
|
#endif //nsTextEditRules_h__
|
|
|
|
|