2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
#ifndef mozilla_TextEditor_h
|
|
|
|
#define mozilla_TextEditor_h
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
#include "mozilla/EditorBase.h"
|
2001-01-28 23:13:07 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nscore.h"
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIContent;
|
2001-01-28 23:13:07 +03:00
|
|
|
class nsIDocumentEncoder;
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIOutputStream;
|
|
|
|
class nsISelectionController;
|
|
|
|
class nsITransferable;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
namespace mozilla {
|
2016-06-23 13:18:13 +03:00
|
|
|
class AutoEditInitRulesTrigger;
|
Bug 1463985 - part 1: Rename EditAction to EditSubAction and related stuff r=m_kato
When we implement InputEvent.inputType, we need to set a stack class to record
which edit action is currently handled. However, currently, we call smaller
jobs as edit action. For example, when user types a character at selecting
some characters, then, EditAction::deleteSelection is performed first, then,
EditAction::insertText is performed. However, for the InputEvent.inputType,
we need inserText information. So, for making new enum EditAction, we need
to rename current EditAction to EditSubAction.
And also this renames related stuff:
EditorBase::mIsInEditAction -> EditorBase::mIsInEditSubAction
EditorBase::IsInEditAction() -> EditorBase::IsInEditSubAction()
EditorBase::mAction -> EditorBase::mTopLevelEditSubAction
TextEditRules::mTheAction -> TextEditRules::mTopLevelEditSubAction
EditorBase::StartOperation() ->
EditorBase::OnStartToHandleTopLevelEditSubAction()
EditorBase::EndOperation() ->
EditorBase::OnEndHandlingTopLevelEditSubAction()
AutoRules -> AutoTopLevelEditSubActionNotifier
RulesInfo -> EditSubActionInfo
MozReview-Commit-ID: cvSkPUjFm1
--HG--
extra : rebase_source : baf527a3e353b7a8ebe9a46be2243b059c500234
2018-05-28 14:12:34 +03:00
|
|
|
enum class EditSubAction : int32_t;
|
2018-01-12 13:01:04 +03:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
namespace dom {
|
2018-03-13 23:24:00 +03:00
|
|
|
class DragEvent;
|
2014-11-02 15:04:13 +03:00
|
|
|
class Selection;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
/**
|
|
|
|
* The text editor implementation.
|
2015-05-28 18:58:42 +03:00
|
|
|
* Use to edit text document represented as a DOM tree.
|
2001-01-28 23:13:07 +03:00
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
class TextEditor : public EditorBase
|
2016-07-09 05:54:50 +03:00
|
|
|
, public nsIPlaintextEditor
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
public:
|
2018-05-22 14:15:05 +03:00
|
|
|
/****************************************************************************
|
|
|
|
* NOTE: DO NOT MAKE YOUR NEW METHODS PUBLIC IF they are called by other
|
|
|
|
* classes under libeditor except EditorEventListener and
|
|
|
|
* HTMLEditorEventListener because each public method which may fire
|
|
|
|
* eEditorInput event will need to instantiate new stack class for
|
|
|
|
* managing input type value of eEditorInput and cache some objects
|
|
|
|
* for smarter handling. In other words, when you add new root
|
|
|
|
* method to edit the DOM tree, you can make your new method public.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-07-08 07:10:13 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextEditor, EditorBase)
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
TextEditor();
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
// nsIPlaintextEditor methods
|
2001-01-28 23:13:07 +03:00
|
|
|
NS_DECL_NSIPLAINTEXTEDITOR
|
|
|
|
|
2018-04-11 11:37:49 +03:00
|
|
|
// Overrides of nsIEditor
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD GetDocumentIsEmpty(bool* aDocumentIsEmpty) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2012-05-10 18:54:33 +04:00
|
|
|
NS_IMETHOD DeleteSelection(EDirection aAction,
|
2015-03-21 19:28:04 +03:00
|
|
|
EStripWrappers aStripWrappers) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD SetDocumentCharacterSet(const nsACString& characterSet) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2018-03-22 19:21:17 +03:00
|
|
|
// If there are some good name to create non-virtual Undo()/Redo() methods,
|
|
|
|
// we should create them and those methods should just run them.
|
|
|
|
NS_IMETHOD Undo(uint32_t aCount) final;
|
|
|
|
NS_IMETHOD Redo(uint32_t aCount) final;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Cut() override;
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD CanCut(bool* aCanCut) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Copy() override;
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD CanCopy(bool* aCanCopy) override;
|
|
|
|
NS_IMETHOD CanDelete(bool* aCanDelete) override;
|
|
|
|
NS_IMETHOD CanPaste(int32_t aSelectionType, bool* aCanPaste) override;
|
|
|
|
NS_IMETHOD PasteTransferable(nsITransferable* aTransferable) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2002-03-26 01:39:19 +03:00
|
|
|
NS_IMETHOD OutputToString(const nsAString& aFormatType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAString& aOutputString) override;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2018-05-22 12:23:21 +03:00
|
|
|
/** Can we paste |aTransferable| or, if |aTransferable| is null, will a call
|
|
|
|
* to pasteTransferable later possibly succeed if given an instance of
|
|
|
|
* nsITransferable then? True if the doc is modifiable, and, if
|
|
|
|
* |aTransfeable| is non-null, we have pasteable data in |aTransfeable|.
|
|
|
|
*/
|
|
|
|
virtual bool CanPasteTransferable(nsITransferable* aTransferable);
|
|
|
|
|
2018-04-11 11:37:49 +03:00
|
|
|
// Overrides of EditorBase
|
|
|
|
virtual nsresult Init(nsIDocument& aDoc, Element* aRoot,
|
|
|
|
nsISelectionController* aSelCon, uint32_t aFlags,
|
|
|
|
const nsAString& aValue) override;
|
|
|
|
|
2018-07-18 11:44:14 +03:00
|
|
|
/**
|
|
|
|
* IsEmpty() checks whether the editor is empty. If editor has only bogus
|
|
|
|
* node, returns true. If editor's root element has non-empty text nodes or
|
|
|
|
* other nodes like <br>, returns false.
|
|
|
|
*/
|
|
|
|
nsresult IsEmpty(bool* aIsEmpty) const;
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
bool isEmpty = false;
|
|
|
|
nsresult rv = IsEmpty(&isEmpty);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Checking whether the editor is empty failed");
|
|
|
|
return NS_SUCCEEDED(rv) && isEmpty;
|
|
|
|
}
|
2018-04-11 11:37:49 +03:00
|
|
|
|
2017-02-08 14:18:17 +03:00
|
|
|
virtual nsresult HandleKeyPressEvent(
|
|
|
|
WidgetKeyboardEvent* aKeyboardEvent) override;
|
2010-06-10 05:16:58 +04:00
|
|
|
|
2018-01-09 16:41:42 +03:00
|
|
|
virtual dom::EventTarget* GetDOMEventTarget() override;
|
2010-06-17 09:30:10 +04:00
|
|
|
|
2018-08-13 07:37:56 +03:00
|
|
|
/**
|
|
|
|
* PasteAsAction() pastes clipboard content to Selection. This method
|
|
|
|
* may dispatch ePaste event first. If its defaultPrevent() is called,
|
|
|
|
* this does nothing but returns NS_OK.
|
|
|
|
*
|
|
|
|
* @param aClipboardType nsIClipboard::kGlobalClipboard or
|
|
|
|
* nsIClipboard::kSelectionClipboard.
|
2018-10-10 15:05:39 +03:00
|
|
|
* @param aDispatchPasteEvent true if this should dispatch ePaste event
|
|
|
|
* before pasting. Otherwise, false.
|
2018-08-13 07:37:56 +03:00
|
|
|
*/
|
2018-10-10 15:05:39 +03:00
|
|
|
nsresult PasteAsAction(int32_t aClipboardType,
|
|
|
|
bool aDispatchPasteEvent);
|
2018-08-13 07:37:56 +03:00
|
|
|
|
2018-04-16 17:43:36 +03:00
|
|
|
/**
|
|
|
|
* InsertTextAsAction() inserts aStringToInsert at selection.
|
|
|
|
* Although this method is implementation of nsIPlaintextEditor.insertText(),
|
2018-07-02 14:12:22 +03:00
|
|
|
* this treats the input is an edit action. If you'd like to insert text
|
|
|
|
* as part of edit action, you probably should use InsertTextAsSubAction().
|
2018-04-16 17:43:36 +03:00
|
|
|
*
|
|
|
|
* @param aStringToInsert The string to insert.
|
|
|
|
*/
|
|
|
|
nsresult InsertTextAsAction(const nsAString& aStringToInsert);
|
|
|
|
|
2018-07-23 10:34:03 +03:00
|
|
|
/**
|
|
|
|
* PasteAsQuotationAsAction() pastes content in clipboard as quotation.
|
|
|
|
* If the editor is TextEditor or in plaintext mode, will paste the content
|
|
|
|
* with appending ">" to start of each line.
|
|
|
|
*
|
|
|
|
* @param aClipboardType nsIClipboard::kGlobalClipboard or
|
|
|
|
* nsIClipboard::kSelectionClipboard.
|
2018-10-10 15:05:39 +03:00
|
|
|
* @param aDispatchPasteEvent true if this should dispatch ePaste event
|
|
|
|
* before pasting. Otherwise, false.
|
2018-07-23 10:34:03 +03:00
|
|
|
*/
|
2018-10-10 15:05:39 +03:00
|
|
|
virtual nsresult PasteAsQuotationAsAction(int32_t aClipboardType,
|
|
|
|
bool aDispatchPasteEvent);
|
2018-07-23 10:34:03 +03:00
|
|
|
|
2018-04-16 17:43:36 +03:00
|
|
|
/**
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
* DeleteSelectionAsAction() removes selection content or content around
|
|
|
|
* caret with transactions. This should be used for handling it as an
|
Bug 1467794 - Split TextEditor::DeleteSelectionAsAction() to itself and TextEditor::DeleteSelectionAsSubAction() r=m_kato
TextEditor::DeleteSelectionAsAction() is called even if it's a part of edit
action. For example, it's called to prepare for inserting text.
For bug 1465702, editor itself and edit rules classes should not call
public DeleteSelectionAsAction() directly. Therefore, this patch creates
DeleteSelectionAsSubAction() for internal use.
Note that this patch adds NS_ASSERTION() to detect wrong caller. However,
it cannot distinguish if the call is valid, for example, it's allowed to
call DeleteSelectionAsSelection() even if it's handling an edit action but
the method is called via mutation event listener. So, we need to allow
some assertions with some tests. But unfortunately, 1405747.html uses
mutation event listener too many times (about 1,000 times) and the number
of assertion isn't stable. Therefore, this patch makes the test stop using
the mutation event listener 2nd time since I can reproduce the crash with
ESR 52 at the 2nd time.
MozReview-Commit-ID: 1TWaypmnoCC
--HG--
extra : rebase_source : a6a4fb1cbcaf2ab6f10c5f3e7168a6bc0fcb02ed
2018-06-29 14:16:50 +03:00
|
|
|
* edit action. If you'd like to remove selection for preparing to insert
|
|
|
|
* something, you probably should use DeleteSelectionAsSubAction().
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
*
|
|
|
|
* @param aDirection How much range should be removed.
|
|
|
|
* @param aStripWrappers Whether the parent blocks should be removed
|
|
|
|
* when they become empty.
|
2016-07-09 05:54:50 +03:00
|
|
|
*/
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
nsresult DeleteSelectionAsAction(EDirection aDirection,
|
|
|
|
EStripWrappers aStripWrappers);
|
2010-02-01 21:12:31 +03:00
|
|
|
|
2018-02-21 07:21:57 +03:00
|
|
|
/**
|
|
|
|
* The maximum number of characters allowed.
|
|
|
|
* default: -1 (unlimited).
|
|
|
|
*/
|
2017-06-20 16:57:08 +03:00
|
|
|
int32_t MaxTextLength() const { return mMaxTextLength; }
|
2018-02-21 07:21:57 +03:00
|
|
|
void SetMaxTextLength(int32_t aLength) { mMaxTextLength = aLength; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace existed string with a string.
|
|
|
|
* This is fast path to replace all string when using single line control.
|
|
|
|
*
|
|
|
|
* @ param aString the string to be set
|
|
|
|
*/
|
|
|
|
nsresult SetText(const nsAString& aString);
|
2017-06-20 16:57:08 +03:00
|
|
|
|
2018-07-03 16:25:52 +03:00
|
|
|
/**
|
2018-07-04 16:51:55 +03:00
|
|
|
* Replace text in aReplaceRange or all text in this editor with aString and
|
|
|
|
* treat the change as inserting the string.
|
2018-07-03 16:25:52 +03:00
|
|
|
*
|
2018-07-04 16:51:55 +03:00
|
|
|
* @param aString The string to set.
|
|
|
|
* @param aReplaceRange The range to be replaced.
|
|
|
|
* If nullptr, all contents will be replaced.
|
2018-07-03 16:25:52 +03:00
|
|
|
*/
|
2018-07-04 16:51:55 +03:00
|
|
|
nsresult ReplaceTextAsAction(const nsAString& aString,
|
|
|
|
nsRange* aReplaceRange = nullptr);
|
2018-07-03 16:25:52 +03:00
|
|
|
|
2018-11-03 14:22:13 +03:00
|
|
|
/**
|
|
|
|
* InsertLineBreakAsAction() is called when user inputs a line break with
|
|
|
|
* Enter or something.
|
|
|
|
*/
|
|
|
|
virtual nsresult InsertLineBreakAsAction();
|
|
|
|
|
2018-04-18 18:31:51 +03:00
|
|
|
/**
|
|
|
|
* OnCompositionStart() is called when editor receives eCompositionStart
|
|
|
|
* event which should be handled in this editor.
|
|
|
|
*/
|
|
|
|
nsresult OnCompositionStart(WidgetCompositionEvent& aCompositionStartEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OnCompositionChange() is called when editor receives an eCompositioChange
|
|
|
|
* event which should be handled in this editor.
|
|
|
|
*
|
|
|
|
* @param aCompositionChangeEvent eCompositionChange event which should
|
|
|
|
* be handled in this editor.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
OnCompositionChange(WidgetCompositionEvent& aCompositionChangeEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OnCompositionEnd() is called when editor receives an eCompositionChange
|
|
|
|
* event and it's followed by eCompositionEnd event and after
|
|
|
|
* OnCompositionChange() is called.
|
|
|
|
*/
|
|
|
|
void OnCompositionEnd(WidgetCompositionEvent& aCompositionEndEvent);
|
|
|
|
|
2018-06-08 08:19:51 +03:00
|
|
|
/**
|
|
|
|
* OnDrop() is called from EditorEventListener::Drop that is handler of drop
|
|
|
|
* event.
|
|
|
|
*/
|
2018-10-10 15:03:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-06-08 08:19:51 +03:00
|
|
|
nsresult OnDrop(dom::DragEvent* aDropEvent);
|
|
|
|
|
2018-07-18 15:27:30 +03:00
|
|
|
/**
|
|
|
|
* ComputeTextValue() computes plaintext value of this editor. This may be
|
|
|
|
* too expensive if it's in hot path.
|
|
|
|
*
|
|
|
|
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
|
|
|
|
* @param aCharset Encoding of the document.
|
|
|
|
*/
|
|
|
|
nsresult ComputeTextValue(uint32_t aDocumentEncoderFlags,
|
|
|
|
nsAString& aOutputString) const
|
|
|
|
{
|
2018-10-30 12:59:33 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-07-18 15:27:30 +03:00
|
|
|
return ComputeValueInternal(NS_LITERAL_STRING("text/plain"),
|
|
|
|
aDocumentEncoderFlags, aOutputString);
|
|
|
|
}
|
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
protected: // May be called by friends.
|
2018-05-22 14:15:05 +03:00
|
|
|
/****************************************************************************
|
|
|
|
* Some classes like TextEditRules, HTMLEditRules, WSRunObject which are
|
|
|
|
* part of handling edit actions are allowed to call the following protected
|
|
|
|
* methods. However, those methods won't prepare caches of some objects
|
|
|
|
* which are necessary for them. So, if you want some following methods
|
|
|
|
* to do that for you, you need to create a wrapper method in public scope
|
|
|
|
* and call it.
|
|
|
|
****************************************************************************/
|
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
// Overrides of EditorBase
|
|
|
|
virtual nsresult RemoveAttributeOrEquivalent(
|
|
|
|
Element* aElement,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
bool aSuppressTransaction) override;
|
|
|
|
virtual nsresult SetAttributeOrEquivalent(Element* aElement,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
bool aSuppressTransaction) override;
|
|
|
|
using EditorBase::RemoveAttributeOrEquivalent;
|
|
|
|
using EditorBase::SetAttributeOrEquivalent;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2018-07-02 14:12:22 +03:00
|
|
|
/**
|
|
|
|
* InsertTextAsSubAction() inserts aStringToInsert at selection. This
|
|
|
|
* should be used for handling it as an edit sub-action.
|
|
|
|
*
|
|
|
|
* @param aStringToInsert The string to insert.
|
|
|
|
*/
|
|
|
|
nsresult InsertTextAsSubAction(const nsAString& aStringToInsert);
|
|
|
|
|
Bug 1467794 - Split TextEditor::DeleteSelectionAsAction() to itself and TextEditor::DeleteSelectionAsSubAction() r=m_kato
TextEditor::DeleteSelectionAsAction() is called even if it's a part of edit
action. For example, it's called to prepare for inserting text.
For bug 1465702, editor itself and edit rules classes should not call
public DeleteSelectionAsAction() directly. Therefore, this patch creates
DeleteSelectionAsSubAction() for internal use.
Note that this patch adds NS_ASSERTION() to detect wrong caller. However,
it cannot distinguish if the call is valid, for example, it's allowed to
call DeleteSelectionAsSelection() even if it's handling an edit action but
the method is called via mutation event listener. So, we need to allow
some assertions with some tests. But unfortunately, 1405747.html uses
mutation event listener too many times (about 1,000 times) and the number
of assertion isn't stable. Therefore, this patch makes the test stop using
the mutation event listener 2nd time since I can reproduce the crash with
ESR 52 at the 2nd time.
MozReview-Commit-ID: 1TWaypmnoCC
--HG--
extra : rebase_source : a6a4fb1cbcaf2ab6f10c5f3e7168a6bc0fcb02ed
2018-06-29 14:16:50 +03:00
|
|
|
/**
|
|
|
|
* DeleteSelectionAsSubAction() removes selection content or content around
|
|
|
|
* caret with transactions. This should be used for handling it as an
|
|
|
|
* edit sub-action.
|
|
|
|
*
|
|
|
|
* @param aDirection How much range should be removed.
|
|
|
|
* @param aStripWrappers Whether the parent blocks should be removed
|
|
|
|
* when they become empty.
|
|
|
|
*/
|
|
|
|
nsresult DeleteSelectionAsSubAction(EDirection aDirection,
|
|
|
|
EStripWrappers aStripWrappers);
|
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
/**
|
|
|
|
* DeleteSelectionWithTransaction() removes selected content or content
|
|
|
|
* around caret with transactions.
|
|
|
|
*
|
|
|
|
* @param aDirection How much range should be removed.
|
|
|
|
* @param aStripWrappers Whether the parent blocks should be removed
|
|
|
|
* when they become empty.
|
|
|
|
*/
|
|
|
|
virtual nsresult
|
|
|
|
DeleteSelectionWithTransaction(EDirection aAction,
|
|
|
|
EStripWrappers aStripWrappers);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2018-07-03 16:25:52 +03:00
|
|
|
/**
|
|
|
|
* Replace existed string with aString. Caller must guarantee that there
|
|
|
|
* is a placeholder transaction which will have the transaction.
|
|
|
|
*
|
|
|
|
* @ param aString The string to be set.
|
|
|
|
*/
|
|
|
|
nsresult SetTextAsSubAction(const nsAString& aString);
|
|
|
|
|
2018-07-04 16:51:55 +03:00
|
|
|
/**
|
|
|
|
* ReplaceSelectionAsSubAction() replaces selection with aString.
|
|
|
|
*
|
|
|
|
* @param aString The string to replace.
|
|
|
|
*/
|
|
|
|
nsresult ReplaceSelectionAsSubAction(const nsAString& aString);
|
|
|
|
|
2017-11-21 08:38:19 +03:00
|
|
|
/**
|
2018-04-16 13:21:29 +03:00
|
|
|
* InsertBrElementWithTransaction() creates a <br> element and inserts it
|
|
|
|
* before aPointToInsert. Then, tries to collapse selection at or after the
|
|
|
|
* new <br> node if aSelect is not eNone.
|
2017-11-21 08:38:19 +03:00
|
|
|
*
|
|
|
|
* @param aPointToInsert The DOM point where should be <br> node inserted
|
|
|
|
* before.
|
|
|
|
* @param aSelect If eNone, this won't change selection.
|
|
|
|
* If eNext, selection will be collapsed after
|
|
|
|
* the <br> element.
|
|
|
|
* If ePrevious, selection will be collapsed at
|
|
|
|
* the <br> element.
|
|
|
|
* @return The new <br> node. If failed to create new
|
|
|
|
* <br> node, returns nullptr.
|
|
|
|
*/
|
2018-03-20 08:05:47 +03:00
|
|
|
template<typename PT, typename CT>
|
2017-11-21 08:38:19 +03:00
|
|
|
already_AddRefed<Element>
|
2018-04-16 13:21:29 +03:00
|
|
|
InsertBrElementWithTransaction(
|
|
|
|
const EditorDOMPointBase<PT, CT>& aPointToInsert,
|
|
|
|
EDirection aSelect = eNone);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
/**
|
|
|
|
* Extends the selection for given deletion operation
|
|
|
|
* If done, also update aAction to what's actually left to do after the
|
|
|
|
* extension.
|
|
|
|
*/
|
2018-10-30 13:01:38 +03:00
|
|
|
nsresult ExtendSelectionForDelete(nsIEditor::EDirection* aAction);
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
|
2018-10-25 06:35:26 +03:00
|
|
|
/**
|
|
|
|
* HideLastPasswordInput() is called by timer callback of TextEditRules.
|
|
|
|
* This should be called only by TextEditRules::Notify().
|
|
|
|
* When this is called, the TextEditRules wants to call its
|
2018-10-30 12:59:33 +03:00
|
|
|
* HideLastPasswordInput() with AutoEditActionDataSetter instance.
|
2018-10-25 06:35:26 +03:00
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult HideLastPasswordInput();
|
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
static void GetDefaultEditorPrefs(int32_t& aNewLineHandling,
|
|
|
|
int32_t& aCaretStyle);
|
|
|
|
|
|
|
|
protected: // Called by helper classes.
|
|
|
|
|
Bug 1463985 - part 1: Rename EditAction to EditSubAction and related stuff r=m_kato
When we implement InputEvent.inputType, we need to set a stack class to record
which edit action is currently handled. However, currently, we call smaller
jobs as edit action. For example, when user types a character at selecting
some characters, then, EditAction::deleteSelection is performed first, then,
EditAction::insertText is performed. However, for the InputEvent.inputType,
we need inserText information. So, for making new enum EditAction, we need
to rename current EditAction to EditSubAction.
And also this renames related stuff:
EditorBase::mIsInEditAction -> EditorBase::mIsInEditSubAction
EditorBase::IsInEditAction() -> EditorBase::IsInEditSubAction()
EditorBase::mAction -> EditorBase::mTopLevelEditSubAction
TextEditRules::mTheAction -> TextEditRules::mTopLevelEditSubAction
EditorBase::StartOperation() ->
EditorBase::OnStartToHandleTopLevelEditSubAction()
EditorBase::EndOperation() ->
EditorBase::OnEndHandlingTopLevelEditSubAction()
AutoRules -> AutoTopLevelEditSubActionNotifier
RulesInfo -> EditSubActionInfo
MozReview-Commit-ID: cvSkPUjFm1
--HG--
extra : rebase_source : baf527a3e353b7a8ebe9a46be2243b059c500234
2018-05-28 14:12:34 +03:00
|
|
|
virtual void
|
|
|
|
OnStartToHandleTopLevelEditSubAction(
|
|
|
|
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
|
|
|
virtual void OnEndHandlingTopLevelEditSubAction() override;
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
|
|
|
|
void BeginEditorInit();
|
|
|
|
nsresult EndEditorInit();
|
|
|
|
|
|
|
|
protected: // Shouldn't be used by friend classes
|
|
|
|
virtual ~TextEditor();
|
|
|
|
|
2018-07-18 14:31:17 +03:00
|
|
|
int32_t WrapWidth() const { return mWrapColumn; }
|
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
/**
|
|
|
|
* Make the given selection span the entire document.
|
|
|
|
*/
|
2018-10-30 13:01:38 +03:00
|
|
|
virtual nsresult SelectEntireDocument() override;
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OnInputText() is called when user inputs text with keyboard or something.
|
|
|
|
*
|
|
|
|
* @param aStringToInsert The string to insert.
|
|
|
|
*/
|
|
|
|
nsresult OnInputText(const nsAString& aStringToInsert);
|
|
|
|
|
2018-11-03 14:22:13 +03:00
|
|
|
/**
|
|
|
|
* InsertLineBreakAsSubAction() inserts a line break, i.e., \n if it's
|
|
|
|
* TextEditor or <br> if it's HTMLEditor.
|
|
|
|
*/
|
|
|
|
nsresult InsertLineBreakAsSubAction();
|
|
|
|
|
2018-11-09 11:40:57 +03:00
|
|
|
/**
|
|
|
|
* InsertTextAt() inserts aStringToInsert at aPointToInsert.
|
|
|
|
*
|
|
|
|
* @param aStringToInsert The string which you want to insert.
|
|
|
|
* @param aPointToInsert The insertion point.
|
|
|
|
* @param aDoDeleteSelection true if you want this to delete selected
|
|
|
|
* content. Otherwise, false.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
nsresult InsertTextAt(const nsAString& aStringToInsert,
|
2018-11-09 11:40:57 +03:00
|
|
|
const EditorDOMPoint& aPointToInsert,
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
bool aDoDeleteSelection);
|
|
|
|
|
2018-11-09 11:40:57 +03:00
|
|
|
/**
|
|
|
|
* InsertFromDataTransfer() inserts the data in aDataTransfer at aIndex.
|
|
|
|
* This is intended to handle "drop" event.
|
|
|
|
*
|
|
|
|
* @param aDataTransfer Dropped data transfer.
|
|
|
|
* @param aIndex Index of the data which should be inserted.
|
|
|
|
* @param aSourceDoc The document which the source comes from.
|
|
|
|
* @param aDroppedAt The dropped position.
|
|
|
|
* @param aDoDeleteSelection true if this should delete selected content.
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
virtual nsresult InsertFromDataTransfer(dom::DataTransfer* aDataTransfer,
|
|
|
|
int32_t aIndex,
|
|
|
|
nsIDocument* aSourceDoc,
|
2018-11-09 11:40:57 +03:00
|
|
|
const EditorDOMPoint& aDroppedAt,
|
|
|
|
bool aDoDeleteSelection);
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
|
2018-07-23 10:05:30 +03:00
|
|
|
/**
|
|
|
|
* InsertWithQuotationsAsSubAction() inserts aQuotedText with appending ">"
|
|
|
|
* to start of every line.
|
|
|
|
*
|
|
|
|
* @param aQuotedText String to insert. This will be quoted by ">"
|
|
|
|
* automatically.
|
|
|
|
*/
|
|
|
|
nsresult InsertWithQuotationsAsSubAction(const nsAString& aQuotedText);
|
|
|
|
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
/**
|
|
|
|
* 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(nsIDocument* aSourceDoc);
|
|
|
|
|
|
|
|
virtual nsresult InitRules();
|
|
|
|
|
2018-07-18 14:51:55 +03:00
|
|
|
/**
|
|
|
|
* GetAndInitDocEncoder() returns a document encoder instance for aFormatType
|
|
|
|
* after initializing it. The result may be cached for saving recreation
|
|
|
|
* cost.
|
|
|
|
*
|
|
|
|
* @param aFormatType MIME type like "text/plain".
|
|
|
|
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
|
|
|
|
* @param aCharset Encoding of the document.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIDocumentEncoder>
|
|
|
|
GetAndInitDocEncoder(const nsAString& aFormatType,
|
|
|
|
uint32_t aDocumentEncoderFlags,
|
|
|
|
const nsACString& aCharset) const;
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
|
2018-07-18 15:27:30 +03:00
|
|
|
/**
|
|
|
|
* ComputeValueInternal() computes string value of this editor for given
|
|
|
|
* format. This may be too expensive if it's in hot path.
|
|
|
|
*
|
|
|
|
* @param aFormatType MIME type like "text/plain".
|
|
|
|
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
|
|
|
|
* @param aCharset Encoding of the document.
|
|
|
|
*/
|
|
|
|
nsresult ComputeValueInternal(const nsAString& aFormatType,
|
|
|
|
uint32_t aDocumentEncoderFlags,
|
|
|
|
nsAString& aOutputString) const;
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
/**
|
|
|
|
* Factored methods for handling insertion of data from transferables
|
|
|
|
* (drag&drop or clipboard).
|
|
|
|
*/
|
Bug 1463327 - part 2: Change scope of some methods of TextEditor which won't be called by non-helper classes of editing to protected r=m_kato
TextEditor has 2 type of public methods. One is true-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make TextEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in TextEditor.h.
MozReview-Commit-ID: Db3H6d1V8IU
--HG--
extra : rebase_source : d928a6bb378d02944c5a207de83211c33bb63613
2018-05-22 10:40:44 +03:00
|
|
|
virtual nsresult PrepareTransferable(nsITransferable** transferable);
|
|
|
|
|
2018-03-27 14:19:35 +03:00
|
|
|
nsresult InsertTextFromTransferable(nsITransferable* transferable);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2018-04-11 11:37:49 +03:00
|
|
|
/**
|
|
|
|
* DeleteSelectionAndCreateElement() creates a element whose name is aTag.
|
|
|
|
* And insert it into the DOM tree after removing the selected content.
|
|
|
|
*
|
|
|
|
* @param aTag The element name to be created.
|
|
|
|
* @return Created new element.
|
|
|
|
*/
|
|
|
|
already_AddRefed<Element> DeleteSelectionAndCreateElement(nsAtom& aTag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method first deletes the selection, if it's not collapsed. Then if
|
|
|
|
* the selection lies in a CharacterData node, it splits it. If the
|
|
|
|
* selection is at this point collapsed in a CharacterData node, it's
|
|
|
|
* adjusted to be collapsed right before or after the node instead (which is
|
|
|
|
* always possible, since the node was split).
|
|
|
|
*/
|
|
|
|
nsresult DeleteSelectionAndPrepareToCreateNode();
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
/**
|
|
|
|
* Shared outputstring; returns whether selection is collapsed and resulting
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed,
|
|
|
|
nsAString& aResult);
|
2003-07-28 17:13:50 +04:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
enum PasswordFieldAllowed
|
|
|
|
{
|
2015-01-16 00:47:56 +03:00
|
|
|
ePasswordFieldAllowed,
|
|
|
|
ePasswordFieldNotAllowed
|
|
|
|
};
|
|
|
|
bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
|
2016-07-09 05:54:50 +03:00
|
|
|
bool FireClipboardEvent(EventMessage aEventMessage,
|
2015-08-26 15:56:59 +03:00
|
|
|
int32_t aSelectionType,
|
|
|
|
bool* aActionTaken = nullptr);
|
2007-07-26 08:14:33 +04:00
|
|
|
|
2017-03-17 10:32:06 +03:00
|
|
|
bool UpdateMetaCharset(nsIDocument& aDocument,
|
2012-02-01 14:54:22 +04:00
|
|
|
const nsACString& aCharacterSet);
|
|
|
|
|
2018-04-18 18:31:51 +03:00
|
|
|
/**
|
|
|
|
* EnsureComposition() should be called by composition event handlers. This
|
|
|
|
* tries to get the composition for the event and set it to mComposition.
|
|
|
|
* However, this may fail because the composition may be committed before
|
|
|
|
* the event comes to the editor.
|
|
|
|
*
|
|
|
|
* @return true if there is a composition. Otherwise, for example,
|
|
|
|
* a composition event handler in web contents moved focus
|
|
|
|
* for committing the composition, returns false.
|
|
|
|
*/
|
|
|
|
bool EnsureComposition(WidgetCompositionEvent& aCompositionEvent);
|
|
|
|
|
2018-06-06 07:30:44 +03:00
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() override;
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
protected:
|
2018-07-18 14:51:55 +03:00
|
|
|
mutable nsCOMPtr<nsIDocumentEncoder> mCachedDocumentEncoder;
|
|
|
|
mutable nsString mCachedDocumentEncoderType;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mWrapColumn;
|
|
|
|
int32_t mMaxTextLength;
|
|
|
|
int32_t mInitTriggerCounter;
|
|
|
|
int32_t mNewlineHandling;
|
|
|
|
int32_t mCaretStyle;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
friend class AutoEditInitRulesTrigger;
|
|
|
|
friend class TextEditRules;
|
2001-01-28 23:13:07 +03:00
|
|
|
};
|
|
|
|
|
2017-08-04 09:01:36 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
mozilla::TextEditor*
|
|
|
|
nsIEditor::AsTextEditor()
|
2017-08-04 00:18:50 +03:00
|
|
|
{
|
2017-08-04 09:01:36 +03:00
|
|
|
return static_cast<mozilla::TextEditor*>(this);
|
2017-08-04 00:18:50 +03:00
|
|
|
}
|
|
|
|
|
2017-08-04 09:01:36 +03:00
|
|
|
const mozilla::TextEditor*
|
|
|
|
nsIEditor::AsTextEditor() const
|
2017-08-04 00:18:50 +03:00
|
|
|
{
|
2017-08-04 09:01:36 +03:00
|
|
|
return static_cast<const mozilla::TextEditor*>(this);
|
2017-08-04 00:18:50 +03:00
|
|
|
}
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
#endif // #ifndef mozilla_TextEditor_h
|