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"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2016-07-09 02:34:41 +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
|
|
|
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 {
|
2019-08-02 05:44:40 +00:00
|
|
|
class HTMLBRElement;
|
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
|
|
|
*/
|
2019-07-22 03:53:58 +00:00
|
|
|
class TextEditRules {
|
2018-10-24 09:42:06 +00:00
|
|
|
protected:
|
|
|
|
typedef EditorBase::AutoSelectionRestorer AutoSelectionRestorer;
|
2019-08-20 01:52:50 +00:00
|
|
|
typedef EditorBase::AutoEditSubActionNotifier AutoEditSubActionNotifier;
|
2018-10-24 09:42:06 +00:00
|
|
|
typedef EditorBase::AutoTransactionsConserveSelection
|
|
|
|
AutoTransactionsConserveSelection;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
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
|
|
|
|
2019-08-20 01:52:23 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(TextEditRules)
|
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;
|
|
|
|
|
2019-03-30 11:55:29 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2017-12-21 05:52:32 +00:00
|
|
|
virtual nsresult Init(TextEditor* aTextEditor);
|
|
|
|
virtual nsresult DetachEditor();
|
2019-08-13 04:41:18 +00:00
|
|
|
virtual nsresult BeforeEdit();
|
|
|
|
MOZ_CAN_RUN_SCRIPT virtual nsresult AfterEdit();
|
2019-03-30 11:55:29 +00:00
|
|
|
// NOTE: Don't mark WillDoAction() nor DidDoAction() as MOZ_CAN_RUN_SCRIPT
|
|
|
|
// because they are too generic and doing it makes a lot of public
|
|
|
|
// editor methods marked as MOZ_CAN_RUN_SCRIPT too, but some of them
|
|
|
|
// may not causes running script. So, ideal fix must be that we make
|
|
|
|
// each method callsed by this method public.
|
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, bool* aCancel,
|
2017-12-21 05:52:32 +00:00
|
|
|
bool* aHandled);
|
2019-03-30 11:55:29 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2018-10-30 10:02:58 +00:00
|
|
|
virtual nsresult DidDoAction(EditSubActionInfo& aInfo, 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.
|
|
|
|
*/
|
2019-08-02 05:44:40 +00:00
|
|
|
virtual bool DocumentIsEmpty() const;
|
2018-05-18 03:38:32 +00:00
|
|
|
|
2019-07-22 03:53:36 +00:00
|
|
|
bool DontEchoPassword() const;
|
|
|
|
|
2014-06-23 22:40:02 +00:00
|
|
|
protected:
|
2019-07-22 03:53:58 +00:00
|
|
|
virtual ~TextEditRules() = default;
|
2014-06-23 22:40:02 +00:00
|
|
|
|
2001-06-06 01:21:05 +00:00
|
|
|
public:
|
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
|
|
|
|
1999-04-05 17:21:59 +00:00
|
|
|
protected:
|
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
|
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
|
|
|
MOZ_MUST_USE nsresult 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.
|
|
|
|
*/
|
2019-03-30 11:55:29 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-05-11 08:33:55 +00:00
|
|
|
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 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.
|
|
|
|
*/
|
2019-08-20 01:50:02 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT 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
|
|
|
|
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, nsAString* aOutText,
|
2016-07-09 02:34:41 +00:00
|
|
|
uint32_t aFlags, bool* aOutCancel, bool* aHandled);
|
1999-09-09 19:39:36 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
|
|
|
* Creates a trailing break in the text doc if there is not one already.
|
|
|
|
*/
|
2019-05-07 22:34:28 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
/**
|
2019-08-02 05:44:40 +00:00
|
|
|
* Creates a padding <br> element for empty editor if the root element has no
|
|
|
|
* editable content.
|
2016-07-09 02:34:41 +00:00
|
|
|
*/
|
2019-08-02 05:44:40 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
|
|
|
|
CreatePaddingBRElementForEmptyEditorIfNeeded();
|
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
|
|
|
|
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 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
|
2019-08-02 05:45:18 +00:00
|
|
|
* - and the text node is followed by a padding <br> element for empty last
|
|
|
|
* line.
|
2018-05-11 09:40:47 +00:00
|
|
|
*/
|
|
|
|
MOZ_MUST_USE nsresult CollapseSelectionToTrailingBRIfNeeded();
|
2010-09-01 22:06:52 +00:00
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
bool IsPasswordEditor() const;
|
2019-07-22 03:53:58 +00:00
|
|
|
bool IsMaskingPassword() const;
|
2016-07-09 02:34:41 +00:00
|
|
|
bool IsSingleLineEditor() const;
|
|
|
|
bool IsPlaintextEditor() const;
|
|
|
|
bool IsReadonly() const;
|
|
|
|
bool IsDisabled() const;
|
|
|
|
bool IsMailEditor() 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
|
|
|
|
|
|
|
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, TextEditor& aTextEditor)
|
|
|
|
: 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();
|
|
|
|
|
2019-08-13 02:42:25 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mIsHandling;
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
2017-12-21 05:52:32 +00:00
|
|
|
bool mIsHTMLEditRules;
|
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 {
|
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:22:26 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-07-09 02:34:41 +00:00
|
|
|
#endif // #ifndef mozilla_TextEditRules_h
|