2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-03-10 19:53:26 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
#ifndef mozilla_TextEditRules_h
|
|
|
|
#define mozilla_TextEditRules_h
|
1999-03-10 19:53:26 +00:00
|
|
|
|
2018-01-12 10:01:04 +00:00
|
|
|
#include "mozilla/EditAction.h"
|
2018-10-24 09:42:06 +00:00
|
|
|
#include "mozilla/EditorBase.h"
|
2018-01-12 10:01:04 +00:00
|
|
|
#include "mozilla/EditorDOMPoint.h"
|
2018-05-11 06:52:24 +00:00
|
|
|
#include "mozilla/EditorUtils.h"
|
2018-04-26 13:41:34 +00:00
|
|
|
#include "mozilla/HTMLEditor.h" // for nsIEditor::AsHTMLEditor()
|
|
|
|
#include "mozilla/TextEditor.h"
|
1999-03-10 19:53:26 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIEditor.h"
|
2017-07-26 18:18:20 +00:00
|
|
|
#include "nsINamed.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
2009-11-02 15:37:25 +00:00
|
|
|
#include "nsITimer.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2016-07-09 02:34:41 +00:00
|
|
|
|
2016-06-24 12:19:18 +00:00
|
|
|
class AutoLockRulesSniffing;
|
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 11:12:34 +00:00
|
|
|
class EditSubActionInfo;
|
2018-04-26 13:41:34 +00:00
|
|
|
class HTMLEditor;
|
2017-12-21 05:52:32 +00:00
|
|
|
class HTMLEditRules;
|
2014-04-10 16:09:40 +00:00
|
|
|
namespace dom {
|
2012-07-13 06:33:42 +00:00
|
|
|
class Selection;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
1999-03-10 19:53:26 +00:00
|
|
|
|
2016-07-09 02:34:41 +00: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.
|
2018-05-18 03:38:32 +00:00
|
|
|
* 3. Stop handling edit action if method returns NS_ERROR_EDITOR_DESTROYED
|
|
|
|
* since if mutation event lister or selectionchange event listener disables
|
|
|
|
* the editor, we should not modify the DOM tree anymore.
|
|
|
|
* 4. Any method callers have to check nsresult return value (both directly or
|
|
|
|
* with simple class like EditActionResult) whether the value is
|
|
|
|
* NS_ERROR_EDITOR_DESTROYED at least.
|
|
|
|
* 5. Callers of methods of other classes such as TextEditor, have to check
|
|
|
|
* CanHandleEditAction() before checking its result and if the result is
|
|
|
|
* false, the method have to return NS_ERROR_EDITOR_DESTROYED. In other
|
|
|
|
* words, any methods which may change Selection or the DOM tree have to
|
|
|
|
* return nsresult directly or with simple class like EditActionResult.
|
|
|
|
* And such methods should be marked as MOZ_MUST_USE.
|
2016-07-09 02:34:41 +00:00
|
|
|
*/
|
2017-12-21 05:52:32 +00:00
|
|
|
class TextEditRules : public nsITimerCallback
|
2017-07-26 18:18:20 +00:00
|
|
|
, public nsINamed
|
1999-03-10 19:53:26 +00:00
|
|
|
{
|
2018-10-24 09:42:06 +00:00
|
|
|
protected:
|
|
|
|
typedef EditorBase::AutoSelectionRestorer
|
|
|
|
AutoSelectionRestorer;
|
|
|
|
typedef EditorBase::AutoTopLevelEditSubActionNotifier
|
|
|
|
AutoTopLevelEditSubActionNotifier;
|
|
|
|
typedef EditorBase::AutoTransactionsConserveSelection
|
|
|
|
AutoTransactionsConserveSelection;
|
1999-03-10 19:53:26 +00:00
|
|
|
public:
|
2016-07-09 02:34:41 +00:00
|
|
|
typedef dom::Element Element;
|
|
|
|
typedef dom::Selection Selection;
|
|
|
|
typedef dom::Text Text;
|
|
|
|
template<typename T> using OwningNonNull = OwningNonNull<T>;
|
2016-05-01 13:15:14 +00:00
|
|
|
|
2009-11-02 15:37:25 +00:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2017-12-21 05:52:32 +00:00
|
|
|
NS_DECL_NSINAMED
|
2009-05-09 04:59:25 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2017-12-21 05:52:32 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TextEditRules, nsITimerCallback)
|
2014-06-23 22:40:02 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
TextEditRules();
|
1999-03-10 19:53:26 +00:00
|
|
|
|
2017-12-21 05:52:32 +00:00
|
|
|
HTMLEditRules* AsHTMLEditRules();
|
|
|
|
const HTMLEditRules* AsHTMLEditRules() const;
|
|
|
|
|
|
|
|
virtual nsresult Init(TextEditor* aTextEditor);
|
|
|
|
virtual nsresult SetInitialValue(const nsAString& aValue);
|
|
|
|
virtual nsresult DetachEditor();
|
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 11:12:34 +00:00
|
|
|
virtual nsresult BeforeEdit(EditSubAction aEditSubAction,
|
2017-12-21 05:52:32 +00:00
|
|
|
nsIEditor::EDirection aDirection);
|
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 11:12:34 +00:00
|
|
|
virtual nsresult AfterEdit(EditSubAction aEditSubAction,
|
2017-12-21 05:52:32 +00:00
|
|
|
nsIEditor::EDirection aDirection);
|
2018-10-25 03:35:26 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2018-10-30 10:02:58 +00:00
|
|
|
virtual nsresult WillDoAction(EditSubActionInfo& aInfo,
|
2017-12-21 05:52:32 +00:00
|
|
|
bool* aCancel,
|
|
|
|
bool* aHandled);
|
2018-10-30 10:02:58 +00:00
|
|
|
virtual nsresult DidDoAction(EditSubActionInfo& aInfo,
|
2017-12-21 05:52:32 +00:00
|
|
|
nsresult aResult);
|
2018-05-18 03:38:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return false if the editor has non-empty text nodes or non-text
|
|
|
|
* nodes. Otherwise, i.e., there is no meaningful content,
|
|
|
|
* return true.
|
|
|
|
*/
|
2017-12-21 05:52:32 +00:00
|
|
|
virtual bool DocumentIsEmpty();
|
2018-05-18 03:38:32 +00:00
|
|
|
|
2014-06-23 22:40:02 +00:00
|
|
|
protected:
|
2016-07-09 02:34:41 +00:00
|
|
|
virtual ~TextEditRules();
|
2014-06-23 22:40:02 +00:00
|
|
|
|
2001-06-06 01:21:05 +00:00
|
|
|
public:
|
2012-06-01 11:03:17 +00:00
|
|
|
void ResetIMETextPWBuf();
|
2001-06-06 01:21:05 +00:00
|
|
|
|
2010-02-01 18:12:31 +00:00
|
|
|
/**
|
2018-07-24 08:46:12 +00:00
|
|
|
* Handles the newline characters according to the default system prefs
|
|
|
|
* (editor.singleLine.pasteNewlines).
|
|
|
|
* Each value means:
|
|
|
|
* nsIPlaintextEditor::eNewlinesReplaceWithSpaces (2, Firefox default):
|
|
|
|
* replace newlines with spaces.
|
|
|
|
* nsIPlaintextEditor::eNewlinesStrip (3):
|
|
|
|
* remove newlines from the string.
|
|
|
|
* nsIPlaintextEditor::eNewlinesReplaceWithCommas (4, Thunderbird default):
|
|
|
|
* replace newlines with commas.
|
|
|
|
* nsIPlaintextEditor::eNewlinesStripSurroundingWhitespace (5):
|
|
|
|
* collapse newlines and surrounding whitespace characters and
|
|
|
|
* remove them from the string.
|
|
|
|
* nsIPlaintextEditor::eNewlinesPasteIntact (0):
|
|
|
|
* only remove the leading and trailing newlines.
|
|
|
|
* nsIPlaintextEditor::eNewlinesPasteToFirst (1) or any other value:
|
|
|
|
* remove the first newline and all characters following it.
|
2010-02-01 18:12:31 +00:00
|
|
|
*
|
|
|
|
* @param aString the string to be modified in place.
|
|
|
|
*/
|
2018-07-24 08:46:12 +00:00
|
|
|
void HandleNewLines(nsString& aString);
|
2010-02-01 18:12:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare a string buffer for being displayed as the contents of a password
|
|
|
|
* field. This function uses the platform-specific character for representing
|
|
|
|
* characters entered into password fields.
|
|
|
|
*
|
|
|
|
* @param aOutString the output string. When this function returns,
|
|
|
|
* aOutString will contain aLength password characters.
|
|
|
|
* @param aLength the number of password characters that aOutString should
|
|
|
|
* contain.
|
|
|
|
*/
|
2016-07-09 02:34:41 +00:00
|
|
|
static void FillBufWithPWChars(nsAString* aOutString, int32_t aLength);
|
2010-02-01 18:12:31 +00:00
|
|
|
|
2017-08-24 10:53:34 +00:00
|
|
|
bool HasBogusNode()
|
|
|
|
{
|
|
|
|
return !!mBogusNode;
|
|
|
|
}
|
|
|
|
|
2018-10-25 03:35:26 +00:00
|
|
|
/**
|
2018-10-30 10:02:58 +00:00
|
|
|
* HideLastPasswordInput() is called when Nodify() calls
|
2018-10-30 09:59:33 +00:00
|
|
|
* TextEditor::HideLastPasswordInput(). It guarantees that there is a
|
|
|
|
* AutoEditActionDataSetter instance in the editor.
|
2018-10-25 03:35:26 +00:00
|
|
|
*/
|
2018-10-30 10:02:58 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult HideLastPasswordInput();
|
2018-10-25 03:35:26 +00:00
|
|
|
|
1999-04-05 17:21:59 +00:00
|
|
|
protected:
|
1999-03-10 19:53:26 +00:00
|
|
|
|
2014-05-09 21:02:29 +00:00
|
|
|
void InitFields();
|
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
// TextEditRules implementation methods
|
2018-05-11 09:29:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before inserting text.
|
|
|
|
* This method may actually inserts text into the editor. Therefore, this
|
|
|
|
* might cause destroying the editor.
|
|
|
|
*
|
2018-05-28 12:44:39 +00:00
|
|
|
* @param aEditSubAction Must be EditSubAction::eInsertTextComingFromIME
|
|
|
|
* or EditSubAction::eInsertText.
|
2018-05-11 09:29:54 +00:00
|
|
|
* @param aCancel Returns true if the operation is canceled.
|
|
|
|
* @param aHandled Returns true if the edit action is handled.
|
|
|
|
* @param inString String to be inserted.
|
|
|
|
* @param outString String actually inserted.
|
|
|
|
* @param aMaxLength The maximum string length which the editor
|
|
|
|
* allows to set.
|
|
|
|
*/
|
2018-10-25 03:35:26 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-05-11 09:29:54 +00:00
|
|
|
MOZ_MUST_USE nsresult
|
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 11:12:34 +00:00
|
|
|
WillInsertText(EditSubAction aEditSubAction, bool* aCancel, bool* aHandled,
|
2018-05-11 09:29:54 +00:00
|
|
|
const nsAString* inString, nsAString* outString,
|
|
|
|
int32_t aMaxLength);
|
1999-03-13 04:53:21 +00:00
|
|
|
|
2018-05-11 09:49:44 +00:00
|
|
|
/**
|
|
|
|
* Called before inserting a line break into the editor.
|
|
|
|
* This method removes selected text if selection isn't collapsed.
|
|
|
|
* Therefore, this might cause destroying the editor.
|
|
|
|
*
|
|
|
|
* @param aMaxLength The maximum string length which the editor
|
|
|
|
* allows to set.
|
|
|
|
*/
|
2018-11-03 11:20:06 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
MOZ_MUST_USE EditActionResult WillInsertLineBreak(int32_t aMaxLength);
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-28 21:24:18 +00:00
|
|
|
|
2018-05-11 08:33:55 +00:00
|
|
|
/**
|
|
|
|
* Called before setting text to the text editor.
|
|
|
|
* This method may actually set text to it. Therefore, this might cause
|
|
|
|
* destroying the text editor.
|
|
|
|
*
|
|
|
|
* @param aCancel Returns true if the operation is canceled.
|
|
|
|
* @param aHandled Returns true if the edit action is handled.
|
|
|
|
* @param inString String to be set.
|
|
|
|
* @param aMaxLength The maximum string length which the text editor
|
|
|
|
* allows to set.
|
|
|
|
*/
|
|
|
|
MOZ_MUST_USE nsresult
|
|
|
|
WillSetText(bool* aCancel, bool* aHandled,
|
|
|
|
const nsAString* inString, int32_t aMaxLength);
|
2017-05-25 05:30:50 +00:00
|
|
|
|
2018-05-11 10:06:07 +00:00
|
|
|
/**
|
|
|
|
* Called before inserting something into the editor.
|
|
|
|
* This method may removes mBougsNode if there is. Therefore, this method
|
|
|
|
* might cause destroying the editor.
|
|
|
|
*
|
|
|
|
* @param aCancel Returns true if the operation is canceled.
|
|
|
|
* This can be nullptr.
|
|
|
|
*/
|
|
|
|
MOZ_MUST_USE nsresult WillInsert(bool* aCancel = nullptr);
|
1999-03-13 04:53:21 +00:00
|
|
|
|
2018-05-11 08:15:53 +00:00
|
|
|
/**
|
|
|
|
* Called before deleting selected content.
|
|
|
|
* This method may actually remove the selected content with
|
|
|
|
* DeleteSelectionWithTransaction(). So, this might cause destroying the
|
|
|
|
* editor.
|
|
|
|
*
|
|
|
|
* @param aCaollapsedAction Direction to extend the selection.
|
|
|
|
* @param aCancel Returns true if the operation is canceled.
|
|
|
|
* @param aHandled Returns true if the edit action is handled.
|
|
|
|
*/
|
2018-10-25 03:35:26 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-05-11 08:15:53 +00:00
|
|
|
MOZ_MUST_USE nsresult
|
|
|
|
WillDeleteSelection(nsIEditor::EDirection aCollapsedAction,
|
|
|
|
bool* aCancel, bool* aHandled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DeleteSelectionWithTransaction() is internal method of
|
|
|
|
* WillDeleteSelection() since it needs to create SelectionBatcher in
|
|
|
|
* big scope and destroying it might causes destroying the editor.
|
|
|
|
* So, after calling this method, callers need to check CanHandleEditAction()
|
|
|
|
* manually.
|
|
|
|
*
|
|
|
|
* @param aCaollapsedAction Direction to extend the selection.
|
|
|
|
* @param aCancel Returns true if the operation is canceled.
|
|
|
|
* @param aHandled Returns true if the edit action is handled.
|
|
|
|
*/
|
2018-10-25 03:35:26 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-05-11 08:15:53 +00:00
|
|
|
MOZ_MUST_USE nsresult
|
|
|
|
DeleteSelectionWithTransaction(nsIEditor::EDirection aCollapsedAction,
|
|
|
|
bool* aCancel, bool* aHandled);
|
|
|
|
|
2018-05-11 07:48:29 +00:00
|
|
|
/**
|
|
|
|
* Called after deleted selected content.
|
|
|
|
* This method may remove empty text node and makes guarantee that caret
|
|
|
|
* is never at left of <br> element.
|
|
|
|
*/
|
|
|
|
MOZ_MUST_USE nsresult DidDeleteSelection();
|
1999-03-12 02:28:24 +00:00
|
|
|
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult WillSetTextProperty(bool* aCancel, bool* aHandled);
|
1999-06-08 06:04:51 +00:00
|
|
|
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult WillRemoveTextProperty(bool* aCancel, bool* aHandled);
|
1999-06-08 06:04:51 +00:00
|
|
|
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult WillUndo(bool* aCancel, bool* aHandled);
|
|
|
|
nsresult DidUndo(nsresult aResult);
|
1999-03-15 05:08:30 +00:00
|
|
|
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult WillRedo(bool* aCancel, bool* aHandled);
|
|
|
|
nsresult DidRedo(nsresult aResult);
|
1999-03-15 05:08:30 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
|
|
|
* Called prior to nsIEditor::OutputToString.
|
2018-05-10 06:03:21 +00:00
|
|
|
*
|
2016-07-09 02:34:41 +00:00
|
|
|
* @param aInFormat The format requested for the output, a MIME type.
|
|
|
|
* @param aOutText The string to use for output, if aCancel is set to true.
|
|
|
|
* @param aOutCancel If set to true, the caller should cancel the operation
|
|
|
|
* and use aOutText as the result.
|
|
|
|
*/
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult WillOutputText(const nsAString* aInFormat,
|
2016-07-09 02:34:41 +00:00
|
|
|
nsAString* aOutText,
|
2017-06-16 10:08:10 +00:00
|
|
|
uint32_t aFlags,
|
2016-07-09 02:34:41 +00:00
|
|
|
bool* aOutCancel,
|
|
|
|
bool* aHandled);
|
1999-09-09 19:39:36 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
|
|
|
* Check for and replace a redundant trailing break.
|
|
|
|
*/
|
2018-05-11 07:36:07 +00:00
|
|
|
MOZ_MUST_USE nsresult RemoveRedundantTrailingBR();
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
|
|
|
* Creates a trailing break in the text doc if there is not one already.
|
|
|
|
*/
|
2018-05-11 07:31:53 +00:00
|
|
|
MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
2018-05-11 07:24:15 +00:00
|
|
|
* Creates a bogus <br> node if the root element has no editable content.
|
2016-07-09 02:34:41 +00:00
|
|
|
*/
|
2018-05-11 07:24:15 +00:00
|
|
|
MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
|
1999-06-24 23:36:56 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
|
|
|
* Returns a truncated insertion string if insertion would place us over
|
|
|
|
* aMaxLength
|
|
|
|
*/
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult TruncateInsertionIfNeeded(const nsAString* aInString,
|
2016-07-09 02:34:41 +00:00
|
|
|
nsAString* aOutString,
|
|
|
|
int32_t aMaxLength,
|
|
|
|
bool* aTruncated);
|
1999-08-24 08:56:51 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
|
|
|
* Remove IME composition text from password buffer.
|
|
|
|
*/
|
2017-03-09 19:44:45 +00:00
|
|
|
void RemoveIMETextFromPWBuf(uint32_t& aStart, nsAString* aIMEString);
|
2001-06-06 01:21:05 +00:00
|
|
|
|
2017-08-01 13:38:50 +00:00
|
|
|
/**
|
2017-12-11 07:37:10 +00:00
|
|
|
* Create a normal <br> element and insert it to aPointToInsert.
|
2017-08-01 13:38:50 +00:00
|
|
|
*
|
2017-12-11 07:37:10 +00:00
|
|
|
* @param aPointToInsert The point where the new <br> element will be
|
|
|
|
* inserted.
|
2018-05-11 06:52:24 +00:00
|
|
|
* @return Returns created <br> element or an error code
|
|
|
|
* if couldn't create new <br> element.
|
2017-08-01 13:38:50 +00:00
|
|
|
*/
|
2018-03-20 05:05:47 +00:00
|
|
|
template<typename PT, typename CT>
|
2018-05-11 06:52:24 +00:00
|
|
|
CreateElementResult
|
2018-03-20 05:05:47 +00:00
|
|
|
CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert)
|
2017-08-01 13:38:50 +00:00
|
|
|
{
|
2018-05-11 06:52:24 +00:00
|
|
|
CreateElementResult ret = CreateBRInternal(aPointToInsert, false);
|
|
|
|
#ifdef DEBUG
|
|
|
|
// If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
|
|
|
|
if (!CanHandleEditAction()) {
|
|
|
|
MOZ_ASSERT(ret.Rv() == NS_ERROR_EDITOR_DESTROYED);
|
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
return ret;
|
2017-08-01 13:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-11 07:37:10 +00:00
|
|
|
* Create a moz-<br> element and insert it to aPointToInsert.
|
2017-08-01 13:38:50 +00:00
|
|
|
*
|
2017-12-11 07:37:10 +00:00
|
|
|
* @param aPointToInsert The point where the new moz-<br> element will be
|
|
|
|
* inserted.
|
2018-05-11 06:52:24 +00:00
|
|
|
* @return Returns created <br> element or an error code
|
|
|
|
* if couldn't create new <br> element.
|
2017-08-01 13:38:50 +00:00
|
|
|
*/
|
2018-03-20 05:05:47 +00:00
|
|
|
template<typename PT, typename CT>
|
2018-05-11 06:52:24 +00:00
|
|
|
CreateElementResult
|
2018-03-20 05:05:47 +00:00
|
|
|
CreateMozBR(const EditorDOMPointBase<PT, CT>& aPointToInsert)
|
2017-08-01 13:38:50 +00:00
|
|
|
{
|
2018-05-11 06:52:24 +00:00
|
|
|
CreateElementResult ret = CreateBRInternal(aPointToInsert, true);
|
|
|
|
#ifdef DEBUG
|
|
|
|
// If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
|
|
|
|
if (!CanHandleEditAction()) {
|
|
|
|
MOZ_ASSERT(ret.Rv() == NS_ERROR_EDITOR_DESTROYED);
|
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
return ret;
|
2017-08-01 13:38:50 +00:00
|
|
|
}
|
1999-11-29 08:28:46 +00:00
|
|
|
|
2018-05-10 06:03:21 +00:00
|
|
|
void UndefineCaretBidiLevel();
|
2015-06-01 19:19:57 +00:00
|
|
|
|
2018-05-10 06:03:21 +00:00
|
|
|
nsresult CheckBidiLevelForDeletion(const EditorRawDOMPoint& aSelectionPoint,
|
2001-05-21 23:57:55 +00:00
|
|
|
nsIEditor::EDirection aAction,
|
2016-07-09 02:34:41 +00:00
|
|
|
bool* aCancel);
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2018-05-11 07:08:47 +00:00
|
|
|
/**
|
2018-10-25 03:35:26 +00:00
|
|
|
* HideLastPasswordInputInternal() replaces last password characters which
|
|
|
|
* have not been replaced with mask character like '*' with with the mask
|
|
|
|
* character. This method may cause destroying the editor.
|
2018-05-11 07:08:47 +00:00
|
|
|
*/
|
2018-10-25 03:35:26 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
MOZ_MUST_USE nsresult HideLastPasswordInputInternal();
|
2009-11-02 15:37:25 +00:00
|
|
|
|
2018-05-11 09:40:47 +00:00
|
|
|
/**
|
|
|
|
* CollapseSelectionToTrailingBRIfNeeded() collapses selection after the
|
|
|
|
* text node if:
|
|
|
|
* - the editor is text editor
|
|
|
|
* - and Selection is collapsed at the end of the text node
|
|
|
|
* - and the text node is followed by moz-<br>.
|
|
|
|
*/
|
|
|
|
MOZ_MUST_USE nsresult CollapseSelectionToTrailingBRIfNeeded();
|
2010-09-01 22:06:52 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
bool IsPasswordEditor() const;
|
|
|
|
bool IsSingleLineEditor() const;
|
|
|
|
bool IsPlaintextEditor() const;
|
|
|
|
bool IsReadonly() const;
|
|
|
|
bool IsDisabled() const;
|
|
|
|
bool IsMailEditor() const;
|
|
|
|
bool DontEchoPassword() const;
|
|
|
|
|
2017-02-08 09:32:32 +00:00
|
|
|
private:
|
2018-04-26 13:41:34 +00:00
|
|
|
TextEditor* MOZ_NON_OWNING_REF mTextEditor;
|
2017-02-08 09:32:32 +00:00
|
|
|
|
2018-05-11 06:52:24 +00:00
|
|
|
/**
|
|
|
|
* Create a normal <br> element or a moz-<br> element and insert it to
|
|
|
|
* aPointToInsert.
|
|
|
|
*
|
|
|
|
* @param aParentToInsert The point where the new <br> element will be
|
|
|
|
* inserted.
|
|
|
|
* @param aCreateMozBR true if the caller wants to create a moz-<br>
|
|
|
|
* element. Otherwise, false.
|
|
|
|
* @return Returns created <br> element and error code.
|
|
|
|
* If it succeeded, never returns nullptr.
|
|
|
|
*/
|
|
|
|
template<typename PT, typename CT>
|
|
|
|
CreateElementResult
|
|
|
|
CreateBRInternal(const EditorDOMPointBase<PT, CT>& aPointToInsert,
|
|
|
|
bool aCreateMozBR);
|
|
|
|
|
2017-02-08 09:32:32 +00:00
|
|
|
protected:
|
2018-04-26 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* AutoSafeEditorData grabs editor instance and related instances during
|
|
|
|
* handling an edit action. When this is created, its pointer is set to
|
|
|
|
* the mSafeData, and this guarantees the lifetime of grabbing objects
|
|
|
|
* until it's destroyed.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS AutoSafeEditorData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoSafeEditorData(TextEditRules& aTextEditRules,
|
2018-10-30 10:02:58 +00:00
|
|
|
TextEditor& aTextEditor)
|
2018-04-26 13:41:34 +00:00
|
|
|
: mTextEditRules(aTextEditRules)
|
|
|
|
, mHTMLEditor(nullptr)
|
|
|
|
{
|
|
|
|
// mTextEditRules may have AutoSafeEditorData instance since in some
|
|
|
|
// cases. E.g., while public methods of *EditRules are called, it
|
|
|
|
// calls attaching editor's method, then, editor will call public
|
|
|
|
// methods of *EditRules again.
|
|
|
|
if (mTextEditRules.mData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTextEditor = &aTextEditor;
|
|
|
|
mHTMLEditor = aTextEditor.AsHTMLEditor();
|
|
|
|
mTextEditRules.mData = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSafeEditorData()
|
|
|
|
{
|
|
|
|
if (mTextEditRules.mData != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTextEditRules.mData = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextEditor& TextEditorRef() const { return *mTextEditor; }
|
|
|
|
HTMLEditor& HTMLEditorRef() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mHTMLEditor);
|
|
|
|
return *mHTMLEditor;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// This class should be created by public methods TextEditRules and
|
|
|
|
// HTMLEditRules and in the stack. So, the lifetime of this should
|
|
|
|
// be guaranteed the callers of the public methods.
|
|
|
|
TextEditRules& MOZ_NON_OWNING_REF mTextEditRules;
|
|
|
|
RefPtr<TextEditor> mTextEditor;
|
|
|
|
// Shortcut for HTMLEditorRef(). So, not necessary to use RefPtr.
|
|
|
|
HTMLEditor* MOZ_NON_OWNING_REF mHTMLEditor;
|
|
|
|
};
|
|
|
|
AutoSafeEditorData* mData;
|
|
|
|
|
|
|
|
TextEditor& TextEditorRef() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mData);
|
|
|
|
return mData->TextEditorRef();
|
|
|
|
}
|
2018-10-30 10:02:58 +00:00
|
|
|
// SelectionRefPtr() won't return nullptr unless editor instance accidentally
|
|
|
|
// ignored result of AutoEditActionDataSetter::CanHandle() and keep handling
|
|
|
|
// edit action.
|
|
|
|
const RefPtr<Selection>& SelectionRefPtr() const
|
2018-04-26 13:41:34 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mData);
|
2018-10-30 10:02:58 +00:00
|
|
|
return TextEditorRef().SelectionRefPtr();
|
2018-04-26 13:41:34 +00:00
|
|
|
}
|
2018-04-24 06:23:01 +00:00
|
|
|
bool CanHandleEditAction() const
|
|
|
|
{
|
|
|
|
if (!mTextEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mTextEditor->Destroyed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mTextEditor->IsInitialized());
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-26 13:41:34 +00:00
|
|
|
|
2018-04-26 15:09:10 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsEditorDataAvailable() const { return !!mData; }
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
Bug 1463327 - part 1: Change scope of some methods of EditorBase which won't be called by non-helper classes of editing to protected r=m_kato
EditorBase (and other editor classes) have 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 EditorBase 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 EditorBase.h
(except removes GetName() since there is no body of this method and removes
IterDirection since it's unused).
MozReview-Commit-ID: HBseKLL6pxx
--HG--
extra : rebase_source : 2251ff659d831d01a6778d38f4e2714fcf2d6ef4
2018-05-22 07:08:43 +00:00
|
|
|
/**
|
|
|
|
* GetTextNodeAroundSelectionStartContainer() may return a Text node around
|
|
|
|
* start container of Selection. If current selection container is not
|
|
|
|
* a text node, this will look for descendants and next siblings of the
|
|
|
|
* container.
|
|
|
|
*/
|
|
|
|
inline already_AddRefed<nsINode> GetTextNodeAroundSelectionStartContainer();
|
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
// A buffer we use to store the real value of password editors.
|
|
|
|
nsString mPasswordText;
|
|
|
|
// A buffer we use to track the IME composition string.
|
|
|
|
nsString mPasswordIMEText;
|
|
|
|
uint32_t mPasswordIMEIndex;
|
|
|
|
// Magic node acts as placeholder in empty doc.
|
2017-04-24 10:40:12 +00:00
|
|
|
nsCOMPtr<nsIContent> mBogusNode;
|
2016-07-09 02:34:41 +00:00
|
|
|
// Cached selected node.
|
2017-04-24 10:40:12 +00:00
|
|
|
nsCOMPtr<nsINode> mCachedSelectionNode;
|
2016-07-09 02:34:41 +00:00
|
|
|
// Cached selected offset.
|
2017-11-29 09:00:11 +00:00
|
|
|
uint32_t mCachedSelectionOffset;
|
2016-07-09 02:34:41 +00:00
|
|
|
uint32_t mActionNesting;
|
|
|
|
bool mLockRulesSniffing;
|
|
|
|
bool mDidExplicitlySetInterline;
|
|
|
|
// In bidirectional text, delete characters not visually adjacent to the
|
|
|
|
// caret without moving the caret first.
|
|
|
|
bool mDeleteBidiImmediately;
|
2017-12-21 05:52:32 +00:00
|
|
|
bool mIsHTMLEditRules;
|
2016-07-09 02:34:41 +00:00
|
|
|
// The top level editor action.
|
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 11:12:34 +00:00
|
|
|
EditSubAction mTopLevelEditSubAction;
|
2016-07-09 02:34:41 +00:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
uint32_t mLastStart;
|
|
|
|
uint32_t mLastLength;
|
2009-11-02 15:37:25 +00:00
|
|
|
|
1999-12-07 08:30:19 +00:00
|
|
|
// friends
|
2016-06-24 12:19:18 +00:00
|
|
|
friend class AutoLockRulesSniffing;
|
1999-03-10 19:53:26 +00:00
|
|
|
};
|
|
|
|
|
2017-12-21 05:52:32 +00:00
|
|
|
/**
|
|
|
|
* An object to encapsulate any additional info needed to be passed
|
|
|
|
* to rules system by the editor.
|
|
|
|
* TODO: This class (almost struct, though) is ugly and its size isn't
|
|
|
|
* optimized. Should be refined later.
|
|
|
|
*/
|
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 11:12:34 +00:00
|
|
|
class MOZ_STACK_CLASS EditSubActionInfo final
|
1999-04-12 12:01:32 +00:00
|
|
|
{
|
2016-06-24 12:12:16 +00:00
|
|
|
public:
|
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 11:12:34 +00:00
|
|
|
explicit EditSubActionInfo(EditSubAction aEditSubAction)
|
|
|
|
: mEditSubAction(aEditSubAction)
|
2016-06-24 12:12:16 +00:00
|
|
|
, inString(nullptr)
|
|
|
|
, outString(nullptr)
|
|
|
|
, outputFormat(nullptr)
|
|
|
|
, maxLength(-1)
|
2017-06-16 10:08:10 +00:00
|
|
|
, flags(0)
|
2016-06-24 12:12:16 +00:00
|
|
|
, collapsedAction(nsIEditor::eNext)
|
|
|
|
, stripWrappers(nsIEditor::eStrip)
|
|
|
|
, entireList(false)
|
|
|
|
, bulletType(nullptr)
|
|
|
|
, alignType(nullptr)
|
|
|
|
, blockType(nullptr)
|
|
|
|
{}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
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 11:12:34 +00:00
|
|
|
EditSubAction mEditSubAction;
|
2017-12-21 05:52:32 +00:00
|
|
|
|
2018-05-28 12:44:39 +00:00
|
|
|
// EditSubAction::eInsertText / EditSubAction::eInsertTextComingFromIME
|
2016-06-24 12:12:16 +00:00
|
|
|
const nsAString* inString;
|
|
|
|
nsAString* outString;
|
|
|
|
const nsAString* outputFormat;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t maxLength;
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2018-05-28 13:09:55 +00:00
|
|
|
// EditSubAction::eComputeTextToOutput
|
2017-06-16 10:08:10 +00:00
|
|
|
uint32_t flags;
|
|
|
|
|
2018-05-28 12:49:56 +00:00
|
|
|
// EditSubAction::eDeleteSelectedContent
|
1999-12-07 08:30:19 +00:00
|
|
|
nsIEditor::EDirection collapsedAction;
|
2012-05-10 14:54:33 +00:00
|
|
|
nsIEditor::EStripWrappers stripWrappers;
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2018-05-28 13:36:19 +00:00
|
|
|
// EditSubAction::eCreateOrChangeList
|
2011-09-29 06:19:26 +00:00
|
|
|
bool entireList;
|
2016-06-24 12:12:16 +00:00
|
|
|
const nsAString* bulletType;
|
2000-09-14 05:59:19 +00:00
|
|
|
|
2018-05-28 13:51:31 +00:00
|
|
|
// EditSubAction::eSetOrClearAlignment
|
2016-06-24 12:12:16 +00:00
|
|
|
const nsAString* alignType;
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2018-05-28 14:01:19 +00:00
|
|
|
// EditSubAction::eCreateOrRemoveBlock
|
2016-06-24 12:12:16 +00:00
|
|
|
const nsAString* blockType;
|
1999-04-12 12:01:32 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 12:19:18 +00:00
|
|
|
/**
|
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 11:12:34 +00:00
|
|
|
* Stack based helper class for managing TextEditRules::mLockRluesSniffing.
|
2016-06-24 12:19:18 +00:00
|
|
|
* This class sets a bool letting us know to ignore any rules sniffing
|
2015-05-28 15:58:42 +00:00
|
|
|
* that tries to occur reentrantly.
|
1999-12-07 08:30:19 +00:00
|
|
|
*/
|
2016-06-24 12:19:18 +00:00
|
|
|
class MOZ_STACK_CLASS AutoLockRulesSniffing final
|
1999-12-07 08:30:19 +00:00
|
|
|
{
|
2016-06-24 12:19:18 +00:00
|
|
|
public:
|
|
|
|
explicit AutoLockRulesSniffing(TextEditRules* aRules)
|
|
|
|
: mRules(aRules)
|
|
|
|
{
|
|
|
|
if (mRules) {
|
|
|
|
mRules->mLockRulesSniffing = true;
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-06-24 12:19:18 +00:00
|
|
|
~AutoLockRulesSniffing()
|
|
|
|
{
|
|
|
|
if (mRules) {
|
|
|
|
mRules->mLockRulesSniffing = false;
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-06-24 12:19:18 +00:00
|
|
|
protected:
|
|
|
|
TextEditRules* mRules;
|
1999-12-07 08:30:19 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 12:22:26 +00:00
|
|
|
/**
|
|
|
|
* Stack based helper class for turning on/off the edit listener.
|
2000-03-24 00:26:47 +00:00
|
|
|
*/
|
2016-06-24 12:22:26 +00:00
|
|
|
class MOZ_STACK_CLASS AutoLockListener final
|
2000-03-24 00:26:47 +00:00
|
|
|
{
|
2016-01-12 18:16:59 +00:00
|
|
|
public:
|
2016-06-24 12:22:26 +00:00
|
|
|
explicit AutoLockListener(bool* aEnabled)
|
|
|
|
: mEnabled(aEnabled)
|
|
|
|
, mOldState(false)
|
2016-01-12 18:16:59 +00:00
|
|
|
{
|
|
|
|
if (mEnabled) {
|
|
|
|
mOldState = *mEnabled;
|
|
|
|
*mEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-06-24 12:22:26 +00:00
|
|
|
~AutoLockListener()
|
2016-01-12 18:16:59 +00:00
|
|
|
{
|
|
|
|
if (mEnabled) {
|
|
|
|
*mEnabled = mOldState;
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-01-12 18:16:59 +00:00
|
|
|
protected:
|
2016-06-24 12:22:26 +00:00
|
|
|
bool* mEnabled;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mOldState;
|
2000-03-24 00:26:47 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 12:22:26 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
#endif // #ifndef mozilla_TextEditRules_h
|