mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
aa072a423f
--HG-- rename : editor/libeditor/text/crashtests/403965-1.xhtml => editor/libeditor/crashtests/403965-1.xhtml rename : editor/libeditor/text/crashtests/580151-1.xhtml => editor/libeditor/crashtests/580151-1.xhtml rename : editor/libeditor/text/nsInternetCiter.cpp => editor/libeditor/nsInternetCiter.cpp rename : editor/libeditor/text/nsInternetCiter.h => editor/libeditor/nsInternetCiter.h rename : editor/libeditor/text/nsPlaintextDataTransfer.cpp => editor/libeditor/nsPlaintextDataTransfer.cpp rename : editor/libeditor/text/nsPlaintextEditor.cpp => editor/libeditor/nsPlaintextEditor.cpp rename : editor/libeditor/text/nsPlaintextEditor.h => editor/libeditor/nsPlaintextEditor.h rename : editor/libeditor/text/nsTextEditRules.cpp => editor/libeditor/nsTextEditRules.cpp rename : editor/libeditor/text/nsTextEditRules.h => editor/libeditor/nsTextEditRules.h rename : editor/libeditor/text/nsTextEditRulesBidi.cpp => editor/libeditor/nsTextEditRulesBidi.cpp rename : editor/libeditor/text/nsTextEditUtils.cpp => editor/libeditor/nsTextEditUtils.cpp rename : editor/libeditor/text/nsTextEditUtils.h => editor/libeditor/nsTextEditUtils.h rename : editor/libeditor/text/tests/test_bug1026397.html => editor/libeditor/tests/test_bug1026397.html rename : editor/libeditor/text/tests/test_bug318065.html => editor/libeditor/tests/test_bug318065.html rename : editor/libeditor/text/tests/test_bug471319.html => editor/libeditor/tests/test_bug471319.html rename : editor/libeditor/text/tests/test_bug471722.html => editor/libeditor/tests/test_bug471722.html rename : editor/libeditor/text/tests/test_bug483651.html => editor/libeditor/tests/test_bug483651.html rename : editor/libeditor/text/tests/test_bug527935.html => editor/libeditor/tests/test_bug527935.html rename : editor/libeditor/text/tests/test_bug569988.html => editor/libeditor/tests/test_bug569988.html rename : editor/libeditor/text/tests/test_bug590554.html => editor/libeditor/tests/test_bug590554.html rename : editor/libeditor/text/tests/test_bug596001.html => editor/libeditor/tests/test_bug596001.html rename : editor/libeditor/text/tests/test_bug596333.html => editor/libeditor/tests/test_bug596333.html rename : editor/libeditor/text/tests/test_bug596506.html => editor/libeditor/tests/test_bug596506.html rename : editor/libeditor/text/tests/test_bug597331.html => editor/libeditor/tests/test_bug597331.html rename : editor/libeditor/text/tests/test_bug600570.html => editor/libeditor/tests/test_bug600570.html rename : editor/libeditor/text/tests/test_bug602130.html => editor/libeditor/tests/test_bug602130.html rename : editor/libeditor/text/tests/test_bug603556.html => editor/libeditor/tests/test_bug603556.html rename : editor/libeditor/text/tests/test_bug604532.html => editor/libeditor/tests/test_bug604532.html rename : editor/libeditor/text/tests/test_bug625452.html => editor/libeditor/tests/test_bug625452.html rename : editor/libeditor/text/tests/test_bug629172.html => editor/libeditor/tests/test_bug629172.html rename : editor/libeditor/text/tests/test_bug636465.xul => editor/libeditor/tests/test_bug636465.xul rename : editor/libeditor/text/tests/test_bug638596.html => editor/libeditor/tests/test_bug638596.html rename : editor/libeditor/text/tests/test_bug641466.html => editor/libeditor/tests/test_bug641466.html rename : editor/libeditor/text/tests/test_bug645914.html => editor/libeditor/tests/test_bug645914.html rename : editor/libeditor/text/tests/test_bug681229.html => editor/libeditor/tests/test_bug681229.html rename : editor/libeditor/text/tests/test_bug692520.html => editor/libeditor/tests/test_bug692520.html rename : editor/libeditor/text/tests/test_bug740784.html => editor/libeditor/tests/test_bug740784.html rename : editor/libeditor/text/tests/test_bug757771.html => editor/libeditor/tests/test_bug757771.html rename : editor/libeditor/text/tests/test_bug830600.html => editor/libeditor/tests/test_bug830600.html rename : editor/libeditor/text/tests/test_dom_input_event_on_texteditor.html => editor/libeditor/tests/test_dom_input_event_on_texteditor.html rename : editor/libeditor/text/tests/test_texteditor_keyevent_handling.html => editor/libeditor/tests/test_texteditor_keyevent_handling.html
227 lines
8.2 KiB
C++
227 lines
8.2 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef nsPlaintextEditor_h__
|
|
#define nsPlaintextEditor_h__
|
|
|
|
#include "nsCOMPtr.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsEditor.h"
|
|
#include "nsIEditor.h"
|
|
#include "nsIEditorMailSupport.h"
|
|
#include "nsIPlaintextEditor.h"
|
|
#include "nsISupportsImpl.h"
|
|
#include "nscore.h"
|
|
|
|
class nsIContent;
|
|
class nsIDOMDataTransfer;
|
|
class nsIDOMDocument;
|
|
class nsIDOMElement;
|
|
class nsIDOMEvent;
|
|
class nsIDOMEventTarget;
|
|
class nsIDOMKeyEvent;
|
|
class nsIDOMNode;
|
|
class nsIDocumentEncoder;
|
|
class nsIEditRules;
|
|
class nsIOutputStream;
|
|
class nsISelection;
|
|
class nsISelectionController;
|
|
class nsITransferable;
|
|
|
|
/**
|
|
* The text editor implementation.
|
|
* Use to edit text document represented as a DOM tree.
|
|
*/
|
|
class nsPlaintextEditor : public nsEditor,
|
|
public nsIPlaintextEditor,
|
|
public nsIEditorMailSupport
|
|
{
|
|
|
|
public:
|
|
|
|
// Interfaces for addref and release and queryinterface
|
|
// NOTE macro used is for classes that inherit from
|
|
// another class. Only the base class should use NS_DECL_ISUPPORTS
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor)
|
|
|
|
/* below used by TypedText() */
|
|
enum ETypingAction {
|
|
eTypedText, /* user typed text */
|
|
eTypedBR, /* user typed shift-enter to get a br */
|
|
eTypedBreak /* user typed enter */
|
|
};
|
|
|
|
nsPlaintextEditor();
|
|
|
|
/* ------------ nsIPlaintextEditor methods -------------- */
|
|
NS_DECL_NSIPLAINTEXTEDITOR
|
|
|
|
/* ------------ nsIEditorMailSupport overrides -------------- */
|
|
NS_DECL_NSIEDITORMAILSUPPORT
|
|
|
|
/* ------------ Overrides of nsEditor interface methods -------------- */
|
|
NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
|
|
const nsAString & aAttribute,
|
|
const nsAString & aValue,
|
|
bool aSuppressTransaction);
|
|
NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
|
|
const nsAString & aAttribute,
|
|
bool aSuppressTransaction);
|
|
|
|
/** prepare the editor for use */
|
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot,
|
|
nsISelectionController *aSelCon, uint32_t aFlags,
|
|
const nsAString& aValue);
|
|
|
|
NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty);
|
|
NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable);
|
|
|
|
NS_IMETHOD DeleteSelection(EDirection aAction,
|
|
EStripWrappers aStripWrappers);
|
|
|
|
NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
|
|
|
|
NS_IMETHOD Undo(uint32_t aCount);
|
|
NS_IMETHOD Redo(uint32_t aCount);
|
|
|
|
NS_IMETHOD Cut();
|
|
NS_IMETHOD CanCut(bool *aCanCut);
|
|
NS_IMETHOD Copy();
|
|
NS_IMETHOD CanCopy(bool *aCanCopy);
|
|
NS_IMETHOD Paste(int32_t aSelectionType);
|
|
NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste);
|
|
NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
|
|
NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste);
|
|
|
|
NS_IMETHOD OutputToString(const nsAString& aFormatType,
|
|
uint32_t aFlags,
|
|
nsAString& aOutputString);
|
|
|
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
|
const nsAString& aFormatType,
|
|
const nsACString& aCharsetOverride,
|
|
uint32_t aFlags);
|
|
|
|
|
|
/** All editor operations which alter the doc should be prefaced
|
|
* with a call to StartOperation, naming the action and direction */
|
|
NS_IMETHOD StartOperation(EditAction opID,
|
|
nsIEditor::EDirection aDirection);
|
|
|
|
/** All editor operations which alter the doc should be followed
|
|
* with a call to EndOperation */
|
|
NS_IMETHOD EndOperation();
|
|
|
|
/** make the given selection span the entire document */
|
|
NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
|
|
|
|
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
|
|
|
|
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
|
|
|
|
virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent);
|
|
virtual nsresult UpdateIMEComposition(nsIDOMEvent* aTextEvent) MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent();
|
|
|
|
/* ------------ Utility Routines, not part of public API -------------- */
|
|
NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);
|
|
|
|
nsresult InsertTextAt(const nsAString &aStringToInsert,
|
|
nsIDOMNode *aDestinationNode,
|
|
int32_t aDestOffset,
|
|
bool aDoDeleteSelection);
|
|
|
|
virtual nsresult InsertFromDataTransfer(mozilla::dom::DataTransfer *aDataTransfer,
|
|
int32_t aIndex,
|
|
nsIDOMDocument *aSourceDoc,
|
|
nsIDOMNode *aDestinationNode,
|
|
int32_t aDestOffset,
|
|
bool aDoDeleteSelection);
|
|
|
|
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent);
|
|
|
|
/**
|
|
* Extends the selection for given deletion operation
|
|
* If done, also update aAction to what's actually left to do after the
|
|
* extension.
|
|
*/
|
|
nsresult ExtendSelectionForDelete(nsISelection* aSelection,
|
|
nsIEditor::EDirection *aAction);
|
|
|
|
// Return true if the data is safe to insert as the source and destination
|
|
// principals match, or we are in a editor context where this doesn't matter.
|
|
// Otherwise, the data must be sanitized first.
|
|
bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
|
|
|
|
static void GetDefaultEditorPrefs(int32_t &aNewLineHandling,
|
|
int32_t &aCaretStyle);
|
|
|
|
protected:
|
|
virtual ~nsPlaintextEditor();
|
|
|
|
NS_IMETHOD InitRules();
|
|
void BeginEditorInit();
|
|
nsresult EndEditorInit();
|
|
|
|
// Helpers for output routines
|
|
NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
|
|
uint32_t aFlags,
|
|
const nsACString& aCharset,
|
|
nsIDocumentEncoder** encoder);
|
|
|
|
// key event helpers
|
|
NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset,
|
|
nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
|
|
already_AddRefed<mozilla::dom::Element>
|
|
CreateBRImpl(nsCOMPtr<nsINode>* aInOutParent, int32_t* aInOutOffset,
|
|
EDirection aSelect);
|
|
nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
|
|
int32_t* aInOutOffset,
|
|
nsCOMPtr<nsIDOMNode>* outBRNode,
|
|
EDirection aSelect);
|
|
nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
|
|
|
|
// factored methods for handling insertion of data from transferables (drag&drop or clipboard)
|
|
NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
|
|
NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
|
|
nsIDOMNode *aDestinationNode,
|
|
int32_t aDestOffset,
|
|
bool aDoDeleteSelection);
|
|
|
|
/** shared outputstring; returns whether selection is collapsed and resulting string */
|
|
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult);
|
|
|
|
/* small utility routine to test the eEditorReadonly bit */
|
|
bool IsModifiable();
|
|
|
|
bool CanCutOrCopy();
|
|
bool FireClipboardEvent(int32_t aType, int32_t aSelectionType);
|
|
|
|
bool UpdateMetaCharset(nsIDOMDocument* aDocument,
|
|
const nsACString& aCharacterSet);
|
|
|
|
// Data members
|
|
protected:
|
|
|
|
nsCOMPtr<nsIEditRules> mRules;
|
|
bool mWrapToWindow;
|
|
int32_t mWrapColumn;
|
|
int32_t mMaxTextLength;
|
|
int32_t mInitTriggerCounter;
|
|
int32_t mNewlineHandling;
|
|
int32_t mCaretStyle;
|
|
|
|
// friends
|
|
friend class nsHTMLEditRules;
|
|
friend class nsTextEditRules;
|
|
friend class nsAutoEditInitRulesTrigger;
|
|
|
|
};
|
|
|
|
#endif //nsPlaintextEditor_h__
|
|
|