2016-07-09 05:42:33 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_HTMLEditor_h
|
|
|
|
#define mozilla_HTMLEditor_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2018-01-26 08:38:05 +03:00
|
|
|
#include "mozilla/ComposerCommandsUpdater.h"
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/CSSEditUtils.h"
|
2021-06-11 06:01:09 +03:00
|
|
|
#include "mozilla/EditorBase.h"
|
Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once. Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.
For the former case, we should sort out it with
`EditorUtils::IsEditableContent()`, but for now, this patch moves it to
`HTMLEditUtils::IsSimplyEditable()`. On the other hand, for the latter case,
we obviously has a bug. Therefore, this patch creates
`HTMLEditUtils::IsRemovableFromParentNode()` and make it check whether the
removing node is also editable.
Unfortunately, `EditorUtils::IsEditableContent()` needs to take editor type.
But it's most callers are in `HTMLEditor` and most of remains are in
common methods of `EditorBase`. I guess we could remove this ugly argument
in the future.
Depends on D70874
Differential Revision: https://phabricator.services.mozilla.com/D70875
--HG--
extra : moz-landing-system : lando
2020-04-15 18:27:38 +03:00
|
|
|
#include "mozilla/EditorUtils.h"
|
2017-08-02 22:37:44 +03:00
|
|
|
#include "mozilla/ManualNAC.h"
|
2020-04-15 18:55:20 +03:00
|
|
|
#include "mozilla/Result.h"
|
2017-02-08 12:14:24 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/BlobImpl.h"
|
2016-07-09 05:42:33 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/File.h"
|
|
|
|
|
|
|
|
#include "nsAttrName.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDocumentObserver.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsIHTMLAbsPosEditor.h"
|
|
|
|
#include "nsIHTMLEditor.h"
|
|
|
|
#include "nsIHTMLInlineTableEditor.h"
|
|
|
|
#include "nsIHTMLObjectResizer.h"
|
|
|
|
#include "nsITableEditor.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
class nsDocumentFragment;
|
2020-08-07 09:12:17 +03:00
|
|
|
class nsFrameSelection;
|
2018-04-06 08:53:05 +03:00
|
|
|
class nsHTMLDocument;
|
2016-07-09 05:42:33 +03:00
|
|
|
class nsITransferable;
|
|
|
|
class nsIClipboard;
|
2020-04-09 10:58:46 +03:00
|
|
|
class nsRange;
|
2020-04-09 13:10:34 +03:00
|
|
|
class nsStaticAtom;
|
2020-08-26 07:48:28 +03:00
|
|
|
class nsStyledElement;
|
2020-04-09 13:10:34 +03:00
|
|
|
class nsTableWrapperFrame;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2019-09-18 09:26:56 +03:00
|
|
|
class AlignStateAtSelection;
|
2017-08-08 04:57:19 +03:00
|
|
|
class AutoSelectionSetterAfterTableEdit;
|
2018-09-20 13:03:24 +03:00
|
|
|
class AutoSetTemporaryAncestorLimiter;
|
2019-08-22 11:29:16 +03:00
|
|
|
class EditActionResult;
|
2019-10-07 03:55:02 +03:00
|
|
|
class EditResult;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
class EmptyEditableFunctor;
|
2020-04-30 18:26:09 +03:00
|
|
|
class JoinNodeTransaction;
|
2019-09-18 06:39:00 +03:00
|
|
|
class ListElementSelectionState;
|
2019-09-18 07:42:55 +03:00
|
|
|
class ListItemElementSelectionState;
|
2019-09-04 06:32:26 +03:00
|
|
|
class MoveNodeResult;
|
2019-09-18 11:20:29 +03:00
|
|
|
class ParagraphStateAtSelection;
|
2018-01-26 09:14:04 +03:00
|
|
|
class ResizerSelectionListener;
|
2020-04-16 18:15:26 +03:00
|
|
|
class Runnable;
|
2020-04-30 16:33:40 +03:00
|
|
|
class SplitNodeTransaction;
|
2019-08-26 06:20:35 +03:00
|
|
|
class SplitRangeOffFromNodeResult;
|
2019-10-07 04:11:31 +03:00
|
|
|
class SplitRangeOffResult;
|
2020-07-14 15:40:13 +03:00
|
|
|
class WhiteSpaceVisibilityKeeper;
|
2020-02-25 15:10:04 +03:00
|
|
|
class WSRunScanner;
|
|
|
|
class WSScanResult;
|
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;
|
Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element). Then, unlink the new link element (i.e.,
clearing the "link style"). At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.
On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.
Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded. And then,
when preparing for inserting text, this patch makes it pass to the utility
method.
For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.
Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 10:19:33 +03:00
|
|
|
enum class SpecifiedStyle : uint8_t;
|
2016-07-09 05:42:33 +03:00
|
|
|
struct PropItem;
|
|
|
|
template <class T>
|
|
|
|
class OwningNonNull;
|
|
|
|
namespace dom {
|
2019-08-22 10:33:41 +03:00
|
|
|
class AbstractRange;
|
2018-09-09 01:44:23 +03:00
|
|
|
class Blob;
|
2016-07-09 05:42:33 +03:00
|
|
|
class DocumentFragment;
|
2018-04-20 19:53:17 +03:00
|
|
|
class Event;
|
2018-03-20 07:16:05 +03:00
|
|
|
class MouseEvent;
|
2019-09-05 10:25:51 +03:00
|
|
|
class StaticRange;
|
2016-07-09 05:42:33 +03:00
|
|
|
} // namespace dom
|
|
|
|
namespace widget {
|
|
|
|
struct IMEState;
|
|
|
|
} // namespace widget
|
|
|
|
|
2016-08-24 15:53:52 +03:00
|
|
|
enum class ParagraphSeparator { div, p, br };
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/**
|
|
|
|
* The HTML editor implementation.<br>
|
|
|
|
* Use to edit HTML document represented as a DOM tree.
|
|
|
|
*/
|
2021-06-11 06:01:09 +03:00
|
|
|
class HTMLEditor final : public EditorBase,
|
2016-07-09 05:42:33 +03:00
|
|
|
public nsIHTMLEditor,
|
|
|
|
public nsIHTMLObjectResizer,
|
|
|
|
public nsIHTMLAbsPosEditor,
|
|
|
|
public nsITableEditor,
|
|
|
|
public nsIHTMLInlineTableEditor,
|
|
|
|
public nsStubMutationObserver,
|
2018-07-23 10:45:07 +03:00
|
|
|
public nsIEditorMailSupport {
|
2016-07-09 05:42:33 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2021-06-11 06:01:09 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLEditor, EditorBase)
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
// nsStubMutationObserver overrides
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
// nsIHTMLEditor methods
|
|
|
|
NS_DECL_NSIHTMLEDITOR
|
|
|
|
|
|
|
|
// nsIHTMLObjectResizer methods (implemented in HTMLObjectResizer.cpp)
|
|
|
|
NS_DECL_NSIHTMLOBJECTRESIZER
|
|
|
|
|
|
|
|
// nsIHTMLAbsPosEditor methods (implemented in HTMLAbsPositionEditor.cpp)
|
|
|
|
NS_DECL_NSIHTMLABSPOSEDITOR
|
|
|
|
|
|
|
|
// nsIHTMLInlineTableEditor methods (implemented in HTMLInlineTableEditor.cpp)
|
|
|
|
NS_DECL_NSIHTMLINLINETABLEEDITOR
|
|
|
|
|
|
|
|
// nsIEditorMailSupport methods
|
|
|
|
NS_DECL_NSIEDITORMAILSUPPORT
|
|
|
|
|
|
|
|
// nsITableEditor methods
|
2017-01-27 05:11:09 +03:00
|
|
|
NS_DECL_NSITABLEEDITOR
|
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
// nsISelectionListener overrides
|
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
HTMLEditor();
|
|
|
|
|
2021-06-28 07:37:54 +03:00
|
|
|
/**
|
|
|
|
* @param aDocument The document whose content will be editable.
|
|
|
|
* @param aFlags Some of nsIEditor::eEditor*Mask flags.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult Init(Document& aDocument, uint32_t aFlags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PostCreate() should be called after Init, and is the time that the editor
|
|
|
|
* tells its documentStateObservers that the document has been created.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult PostCreate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PreDestroy() is called before the editor goes away, and gives the editor a
|
|
|
|
* chance to tell its documentStateObservers that the document is going away.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT void PreDestroy();
|
|
|
|
|
2021-06-11 06:01:08 +03:00
|
|
|
static HTMLEditor* GetFrom(nsIEditor* aEditor) {
|
|
|
|
return aEditor ? aEditor->GetAsHTMLEditor() : nullptr;
|
|
|
|
}
|
|
|
|
static const HTMLEditor* GetFrom(const nsIEditor* aEditor) {
|
|
|
|
return aEditor ? aEditor->GetAsHTMLEditor() : nullptr;
|
2021-01-13 04:55:32 +03:00
|
|
|
}
|
|
|
|
|
2021-07-02 11:23:44 +03:00
|
|
|
/**
|
|
|
|
* Adds or removes transaction listener to or from the transaction manager.
|
|
|
|
* Note that TransactionManager does not check if the listener is in the
|
|
|
|
* array. So, caller of AddTransactionListener() needs to manage if it's
|
|
|
|
* already been registered to the transaction manager.
|
|
|
|
*/
|
|
|
|
bool AddTransactionListener(nsITransactionListener& aListener) {
|
|
|
|
if (!mTransactionManager) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mTransactionManager->AddTransactionListener(aListener);
|
|
|
|
}
|
|
|
|
bool RemoveTransactionListener(nsITransactionListener& aListener) {
|
|
|
|
if (!mTransactionManager) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mTransactionManager->RemoveTransactionListener(aListener);
|
|
|
|
}
|
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
bool GetReturnInParagraphCreatesNewParagraph();
|
2018-06-26 07:29:36 +03:00
|
|
|
|
2021-06-11 06:01:09 +03:00
|
|
|
// EditorBase overrides
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT NS_IMETHOD BeginningOfDocument() final;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2021-05-26 10:45:02 +03:00
|
|
|
NS_IMETHOD GetDocumentCharacterSet(nsACString& aCharacterSet) final;
|
|
|
|
MOZ_CAN_RUN_SCRIPT NS_IMETHOD
|
|
|
|
SetDocumentCharacterSet(const nsACString& aCharacterSet) final;
|
|
|
|
|
2021-05-25 07:53:01 +03:00
|
|
|
bool IsEmpty() const final;
|
2019-09-17 09:58:06 +03:00
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
bool CanPaste(int32_t aClipboardType) const final;
|
2019-04-25 10:14:39 +03:00
|
|
|
using EditorBase::CanPaste;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult PasteTransferableAsAction(
|
|
|
|
nsITransferable* aTransferable, nsIPrincipal* aPrincipal = nullptr) final;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT NS_IMETHOD DeleteNode(nsINode* aNode) final;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT NS_IMETHOD InsertLineBreak() final;
|
2018-11-03 07:19:22 +03:00
|
|
|
|
2021-01-13 04:55:27 +03:00
|
|
|
/**
|
|
|
|
* PreHandleMouseDown() and PreHandleMouseUp() are called before
|
|
|
|
* HTMLEditorEventListener handles them. The coming event may be
|
|
|
|
* non-acceptable event.
|
|
|
|
*/
|
|
|
|
void PreHandleMouseDown(const dom::MouseEvent& aMouseDownEvent);
|
|
|
|
void PreHandleMouseUp(const dom::MouseEvent& aMouseUpEvent);
|
|
|
|
|
Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.
However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.
Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style. This helps advanced users who are familiar with keyboard navigatin
in editor.
Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.
Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too. But a following patch will add a new
reason to notify selection listeners of caused by JS. So, the problem
will be fixed by the following patch.
Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 04:55:29 +03:00
|
|
|
/**
|
2021-01-13 04:55:32 +03:00
|
|
|
* PreHandleSelectionChangeCommand() and PostHandleSelectionChangeCommand()
|
|
|
|
* are called before or after handling a command which may change selection
|
|
|
|
* and/or scroll position.
|
Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.
However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.
Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style. This helps advanced users who are familiar with keyboard navigatin
in editor.
Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.
Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too. But a following patch will add a new
reason to notify selection listeners of caused by JS. So, the problem
will be fixed by the following patch.
Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 04:55:29 +03:00
|
|
|
*/
|
|
|
|
void PreHandleSelectionChangeCommand(Command aCommand);
|
2021-01-13 04:55:32 +03:00
|
|
|
void PostHandleSelectionChangeCommand(Command aCommand);
|
Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.
However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.
Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style. This helps advanced users who are familiar with keyboard navigatin
in editor.
Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.
Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too. But a following patch will add a new
reason to notify selection listeners of caused by JS. So, the problem
will be fixed by the following patch.
Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 04:55:29 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) final;
|
|
|
|
nsIContent* GetFocusedContent() const final;
|
|
|
|
nsIContent* GetFocusedContentForIME() const final;
|
|
|
|
bool IsActiveInDOMWindow() const final;
|
|
|
|
dom::EventTarget* GetDOMEventTarget() const final;
|
|
|
|
Element* FindSelectionRoot(nsINode* aNode) const final;
|
|
|
|
bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) const final;
|
|
|
|
nsresult GetPreferredIMEState(widget::IMEState* aState) final;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2020-01-30 11:50:41 +03:00
|
|
|
/**
|
|
|
|
* GetBackgroundColorState() returns what the background color of the
|
|
|
|
* selection.
|
|
|
|
*
|
|
|
|
* @param aMixed true if there is more than one font color
|
|
|
|
* @param aOutColor Color string. "" is returned for none.
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult GetBackgroundColorState(bool* aMixed,
|
|
|
|
nsAString& aOutColor);
|
2020-01-30 11:50:41 +03:00
|
|
|
|
2021-06-04 08:01:39 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT NS_IMETHOD Paste(int32_t aClipboardType) final {
|
|
|
|
const nsresult rv = HTMLEditor::PasteAsAction(aClipboardType, true);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2021-06-11 06:01:09 +03:00
|
|
|
"HTMLEditor::PasteAsAction() failed");
|
2021-06-04 08:01:39 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
PasteAsAction(int32_t aClipboardType, bool aDispatchPasteEvent,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr) final;
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
/**
|
2021-06-28 15:08:50 +03:00
|
|
|
* PasteNoFormattingAsAction() pastes content in clipboard without any style
|
2019-06-10 13:27:07 +03:00
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* @param aSelectionType nsIClipboard::kGlobalClipboard or
|
|
|
|
* nsIClipboard::kSelectionClipboard.
|
|
|
|
* @param aPrincipal Set subject principal if it may be called by
|
|
|
|
* JS. If set to nullptr, will be treated as
|
|
|
|
* called by system.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult PasteNoFormattingAsAction(
|
|
|
|
int32_t aSelectionType, nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
PasteAsQuotationAsAction(int32_t aClipboardType, bool aDispatchPasteEvent,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr) final;
|
2018-07-23 10:34:03 +03:00
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
bool CanPasteTransferable(nsITransferable* aTransferable) final;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
InsertLineBreakAsAction(nsIPrincipal* aPrincipal = nullptr) final;
|
2018-11-02 17:24:33 +03:00
|
|
|
|
2018-11-03 07:19:22 +03:00
|
|
|
/**
|
|
|
|
* InsertParagraphSeparatorAsAction() is called when user tries to separate
|
|
|
|
* current paragraph with Enter key press in HTMLEditor or something.
|
2019-06-10 13:27:07 +03:00
|
|
|
*
|
|
|
|
* @param aPrincipal Set subject principal if it may be called by
|
|
|
|
* JS. If set to nullptr, will be treated as
|
|
|
|
* called by system.
|
2018-11-03 07:19:22 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-03 06:59:11 +03:00
|
|
|
InsertParagraphSeparatorAsAction(nsIPrincipal* aPrincipal = nullptr);
|
2019-06-10 13:27:07 +03:00
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
InsertElementAtSelectionAsAction(Element* aElement, bool aDeleteSelection,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertLinkAroundSelectionAsAction(
|
|
|
|
Element* aAnchorElement, nsIPrincipal* aPrincipal = nullptr);
|
2018-11-03 07:19:22 +03:00
|
|
|
|
2018-08-10 13:36:24 +03:00
|
|
|
/**
|
|
|
|
* CreateElementWithDefaults() creates new element whose name is
|
|
|
|
* aTagName with some default attributes are set. Note that this is a
|
|
|
|
* public utility method. I.e., just creates element, not insert it
|
|
|
|
* into the DOM tree.
|
|
|
|
* NOTE: This is available for internal use too since this does not change
|
|
|
|
* the DOM tree nor undo transactions, and does not refer Selection,
|
2019-09-18 11:40:08 +03:00
|
|
|
* etc.
|
2018-08-10 13:36:24 +03:00
|
|
|
*
|
|
|
|
* @param aTagName The new element's tag name. If the name is
|
|
|
|
* one of "href", "anchor" or "namedanchor",
|
|
|
|
* this creates an <a> element.
|
|
|
|
* @return Newly created element.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> CreateElementWithDefaults(
|
|
|
|
const nsAtom& aTagName);
|
2018-08-10 13:36:24 +03:00
|
|
|
|
2018-08-14 11:30:09 +03:00
|
|
|
/**
|
|
|
|
* Indent or outdent content around Selection.
|
2019-06-10 13:27:07 +03:00
|
|
|
*
|
|
|
|
* @param aPrincipal Set subject principal if it may be called by
|
|
|
|
* JS. If set to nullptr, will be treated as
|
|
|
|
* called by system.
|
2018-08-14 11:30:09 +03:00
|
|
|
*/
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
IndentAsAction(nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
OutdentAsAction(nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetParagraphFormatAsAction(
|
|
|
|
const nsAString& aParagraphFormat, nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
2019-09-09 07:57:50 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult AlignAsAction(const nsAString& aAlignType,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr);
|
2019-06-10 13:27:07 +03:00
|
|
|
|
2019-09-06 09:01:57 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RemoveListAsAction(
|
|
|
|
const nsAString& aListType, nsIPrincipal* aPrincipal = nullptr);
|
2019-06-10 13:27:07 +03:00
|
|
|
|
2019-09-03 12:32:17 +03:00
|
|
|
/**
|
|
|
|
* MakeOrChangeListAsAction() makes selected hard lines list element(s).
|
|
|
|
*
|
|
|
|
* @param aListElementTagName The new list element tag name. Must be
|
|
|
|
* nsGkAtoms::ul, nsGkAtoms::ol or
|
|
|
|
* nsGkAtoms::dl.
|
|
|
|
* @param aBulletType If this is not empty string, it's set
|
|
|
|
* to `type` attribute of new list item
|
|
|
|
* elements. Otherwise, existing `type`
|
|
|
|
* attributes will be removed.
|
|
|
|
* @param aSelectAllOfCurrentList Yes if this should treat all of
|
|
|
|
* ancestor list element at selection.
|
|
|
|
*/
|
|
|
|
enum class SelectAllOfCurrentList { Yes, No };
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult MakeOrChangeListAsAction(
|
2019-09-03 12:32:17 +03:00
|
|
|
nsAtom& aListElementTagName, const nsAString& aBulletType,
|
|
|
|
SelectAllOfCurrentList aSelectAllOfCurrentList,
|
2019-06-10 13:27:07 +03:00
|
|
|
nsIPrincipal* aPrincipal = nullptr);
|
2018-08-14 11:30:09 +03:00
|
|
|
|
2017-10-26 16:54:30 +03:00
|
|
|
/**
|
2021-01-13 04:54:17 +03:00
|
|
|
* If aTargetElement is a resizer, start to drag the resizer. Otherwise, if
|
|
|
|
* aTargetElement is the grabber, start to handle drag gester on it.
|
|
|
|
*
|
|
|
|
* @param aMouseDownEvent A `mousedown` event fired on aTargetElement.
|
|
|
|
* @param aEventTargetElement The target element being pressed. This must
|
|
|
|
* be same as explicit original event target of
|
|
|
|
* aMouseDownEvent.
|
2017-10-26 16:54:30 +03:00
|
|
|
*/
|
2021-01-13 04:54:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult StartToDragResizerOrHandleDragGestureOnGrabber(
|
|
|
|
dom::MouseEvent& aMouseDownEvent, Element& aEventTargetElement);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
2021-01-13 04:54:17 +03:00
|
|
|
* If the editor is handling dragging a resizer, handling drag gesture on
|
|
|
|
* the grabber or dragging the grabber, this finalize it. Otherwise,
|
|
|
|
* does nothing.
|
|
|
|
*
|
|
|
|
* @param aClientPoint The final point of the drag.
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
*/
|
2021-01-13 04:54:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
StopDraggingResizerOrGrabberAt(const CSSIntPoint& aClientPoint);
|
2018-02-07 09:28:04 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/**
|
2021-01-13 04:54:17 +03:00
|
|
|
* If the editor is handling dragging a resizer, handling drag gesture to
|
|
|
|
* start dragging the grabber or dragging the grabber, this method updates
|
|
|
|
* it's position.
|
|
|
|
*
|
|
|
|
* @param aClientPoint The new point of the drag.
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2021-01-13 04:54:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
UpdateResizerOrGrabberPositionTo(const CSSIntPoint& aClientPoint);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-08-28 12:46:53 +03:00
|
|
|
/**
|
|
|
|
* IsCSSEnabled() returns true if this editor treats styles with style
|
|
|
|
* attribute of HTML elements. Otherwise, if this editor treats all styles
|
|
|
|
* with "font style elements" like <b>, <i>, etc, and <blockquote> to indent,
|
|
|
|
* align attribute to align contents, returns false.
|
|
|
|
*/
|
|
|
|
bool IsCSSEnabled() const {
|
2021-06-22 03:18:07 +03:00
|
|
|
return !IsMailEditor() && mCSSEditUtils &&
|
|
|
|
mCSSEditUtils->IsCSSPrefChecked();
|
2018-08-28 12:46:53 +03:00
|
|
|
}
|
|
|
|
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
/**
|
|
|
|
* Enable/disable object resizers for <img> elements, <table> elements,
|
|
|
|
* absolute positioned elements (required absolute position editor enabled).
|
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void EnableObjectResizer(bool aEnable) {
|
2018-08-17 13:03:02 +03:00
|
|
|
if (mIsObjectResizingEnabled == aEnable) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-30 13:00:17 +03:00
|
|
|
|
|
|
|
AutoEditActionDataSetter editActionData(
|
|
|
|
*this, EditAction::eEnableOrDisableResizer);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
mIsObjectResizingEnabled = aEnable;
|
2019-05-09 10:37:51 +03:00
|
|
|
RefreshEditingUI();
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
}
|
|
|
|
bool IsObjectResizerEnabled() const { return mIsObjectResizingEnabled; }
|
|
|
|
|
Bug 1551185 - Make nsImageFrame::ShouldDisplaySelection() check whether resizer target element is its content or not r=smaug
Currently, `nsISelectionDisplay::DISPLAY_ALL` is used only by `HTMLEditor`.
And only when it's set, `nsImageFrame::ShouldDisplaySelection()` returns `false`
if only its `mContent` is selected. However, this is based on an assumption,
that is, when only one `<img>` is selected in an HTML editor, it's target of
resizers. However, this is completely wrong. Web apps can disable resizers
with `document.execCommand("enableObjectResizing", false, false)` and now,
it's disabled by default.
Therefore, this patch makes the method check whether its `mContent` is
target of resizers at the moment.
Differential Revision: https://phabricator.services.mozilla.com/D32449
--HG--
extra : moz-landing-system : lando
2019-05-24 15:02:34 +03:00
|
|
|
Element* GetResizerTarget() const { return mResizedObject; }
|
|
|
|
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
/**
|
|
|
|
* Enable/disable inline table editor, e.g., adding new row or column,
|
|
|
|
* removing existing row or column.
|
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void EnableInlineTableEditor(bool aEnable) {
|
2018-08-17 13:03:02 +03:00
|
|
|
if (mIsInlineTableEditingEnabled == aEnable) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-30 13:00:17 +03:00
|
|
|
|
|
|
|
AutoEditActionDataSetter editActionData(
|
|
|
|
*this, EditAction::eEnableOrDisableInlineTableEditingUI);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
mIsInlineTableEditingEnabled = aEnable;
|
2019-05-09 10:37:51 +03:00
|
|
|
RefreshEditingUI();
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
}
|
|
|
|
bool IsInlineTableEditorEnabled() const {
|
|
|
|
return mIsInlineTableEditingEnabled;
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:27:49 +03:00
|
|
|
/**
|
|
|
|
* Enable/disable absolute position editor, resizing absolute positioned
|
|
|
|
* elements (required object resizers enabled) or positioning them with
|
|
|
|
* dragging grabber.
|
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void EnableAbsolutePositionEditor(bool aEnable) {
|
2018-08-17 13:03:02 +03:00
|
|
|
if (mIsAbsolutelyPositioningEnabled == aEnable) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-30 13:00:17 +03:00
|
|
|
|
|
|
|
AutoEditActionDataSetter editActionData(
|
|
|
|
*this, EditAction::eEnableOrDisableAbsolutePositionEditor);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:27:49 +03:00
|
|
|
mIsAbsolutelyPositioningEnabled = aEnable;
|
2019-05-09 10:37:51 +03:00
|
|
|
RefreshEditingUI();
|
2018-04-04 16:27:49 +03:00
|
|
|
}
|
|
|
|
bool IsAbsolutePositionEditorEnabled() const {
|
2017-08-04 12:30:13 +03:00
|
|
|
return mIsAbsolutelyPositioningEnabled;
|
|
|
|
}
|
2018-02-01 04:55:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns the deepest absolutely positioned container of the selection
|
|
|
|
* if it exists or null.
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element>
|
|
|
|
GetAbsolutelyPositionedSelectionContainer() const;
|
2018-02-01 04:55:25 +03:00
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
Element* GetPositionedElement() const { return mAbsolutelyPositionedObject; }
|
2018-02-01 04:55:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* extracts the selection from the normal flow of the document and
|
|
|
|
* positions it.
|
2019-06-10 13:27:07 +03:00
|
|
|
*
|
2018-02-01 04:55:25 +03:00
|
|
|
* @param aEnabled [IN] true to absolutely position the selection,
|
|
|
|
* false to put it back in the normal flow
|
2019-06-10 13:27:07 +03:00
|
|
|
* @param aPrincipal Set subject principal if it may be called by
|
|
|
|
* JS. If set to nullptr, will be treated as
|
|
|
|
* called by system.
|
2018-02-01 04:55:25 +03:00
|
|
|
*/
|
2019-09-12 08:45:13 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetSelectionToAbsoluteOrStaticAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
bool aEnabled, nsIPrincipal* aPrincipal = nullptr);
|
2018-02-01 04:55:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns the absolute z-index of a positioned element. Never returns 'auto'
|
|
|
|
* @return the z-index of the element
|
|
|
|
* @param aElement [IN] the element.
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT int32_t GetZIndex(Element& aElement);
|
2018-02-01 04:55:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* adds aChange to the z-index of the currently positioned element.
|
2019-06-10 13:27:07 +03:00
|
|
|
*
|
2018-02-01 04:55:25 +03:00
|
|
|
* @param aChange [IN] relative change to apply to current z-index
|
2019-06-10 13:27:07 +03:00
|
|
|
* @param aPrincipal Set subject principal if it may be called by
|
|
|
|
* JS. If set to nullptr, will be treated as
|
|
|
|
* called by system.
|
2018-02-01 04:55:25 +03:00
|
|
|
*/
|
2019-09-12 09:20:49 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
AddZIndexAsAction(int32_t aChange, nsIPrincipal* aPrincipal = nullptr);
|
2019-06-10 13:27:07 +03:00
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetBackgroundColorAsAction(
|
|
|
|
const nsAString& aColor, nsIPrincipal* aPrincipal = nullptr);
|
2018-02-01 04:55:25 +03:00
|
|
|
|
2018-10-24 07:17:42 +03:00
|
|
|
/**
|
|
|
|
* SetInlinePropertyAsAction() sets a property which changes inline style of
|
|
|
|
* text. E.g., bold, italic, super and sub.
|
|
|
|
* This automatically removes exclusive style, however, treats all changes
|
|
|
|
* as a transaction.
|
2019-06-10 13:27:07 +03:00
|
|
|
*
|
|
|
|
* @param aPrincipal Set subject principal if it may be called by
|
|
|
|
* JS. If set to nullptr, will be treated as
|
|
|
|
* called by system.
|
2018-10-24 07:17:42 +03:00
|
|
|
*/
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetInlinePropertyAsAction(
|
|
|
|
nsAtom& aProperty, nsAtom* aAttribute, const nsAString& aValue,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr);
|
2018-08-13 08:16:10 +03:00
|
|
|
|
2021-06-28 15:08:50 +03:00
|
|
|
/**
|
|
|
|
* GetInlineProperty() gets aggregate properties of the current selection.
|
|
|
|
* All object in the current selection are scanned and their attributes are
|
|
|
|
* represented in a list of Property object.
|
|
|
|
* TODO: Make this return Result<Something> instead of bool out arguments.
|
|
|
|
*
|
|
|
|
* @param aHTMLProperty the property to get on the selection
|
|
|
|
* @param aAttribute the attribute of the property, if applicable.
|
|
|
|
* May be null.
|
|
|
|
* Example: aHTMLProperty=nsGkAtoms::font,
|
|
|
|
* aAttribute=nsGkAtoms::color
|
|
|
|
* @param aValue if aAttribute is not null, the value of the
|
|
|
|
* attribute. May be null.
|
|
|
|
* Example: aHTMLProperty=nsGkAtoms::font,
|
|
|
|
* aAttribute=nsGkAtoms::color,
|
|
|
|
* aValue="0x00FFFF"
|
|
|
|
* @param aFirst [OUT] true if the first text node in the
|
|
|
|
* selection has the property
|
|
|
|
* @param aAny [OUT] true if any of the text nodes in the
|
|
|
|
* selection have the property
|
|
|
|
* @param aAll [OUT] true if all of the text nodes in the
|
|
|
|
* selection have the property
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult GetInlineProperty(
|
|
|
|
nsAtom* aHTMLProperty, nsAtom* aAttribute, const nsAString& aValue,
|
|
|
|
bool* aFirst, bool* aAny, bool* aAll) const;
|
2021-06-28 15:08:50 +03:00
|
|
|
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult GetInlinePropertyWithAttrValue(
|
|
|
|
nsAtom* aHTMLProperty, nsAtom* aAttribute, const nsAString& aValue,
|
|
|
|
bool* aFirst, bool* aAny, bool* aAll, nsAString& outValue);
|
2018-10-30 13:00:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* RemoveInlinePropertyAsAction() removes a property which changes inline
|
|
|
|
* style of text. E.g., bold, italic, super and sub.
|
2018-11-30 04:21:59 +03:00
|
|
|
*
|
2020-04-09 13:10:34 +03:00
|
|
|
* @param aHTMLProperty Tag name whcih represents the inline style you want
|
|
|
|
* to remove. E.g., nsGkAtoms::strong, nsGkAtoms::b,
|
|
|
|
* etc. If nsGkAtoms::href, <a> element which has
|
|
|
|
* href attribute will be removed.
|
|
|
|
* If nsGkAtoms::name, <a> element which has non-empty
|
|
|
|
* name attribute will be removed.
|
|
|
|
* @param aAttribute If aHTMLProperty is nsGkAtoms::font, aAttribute should
|
|
|
|
* be nsGkAtoms::fase, nsGkAtoms::size, nsGkAtoms::color
|
|
|
|
* or nsGkAtoms::bgcolor. Otherwise, set nullptr.
|
2018-11-30 04:21:59 +03:00
|
|
|
* Must not use nsGkAtoms::_empty here.
|
2019-06-10 13:27:07 +03:00
|
|
|
* @param aPrincipal Set subject principal if it may be called by JS. If
|
|
|
|
* set to nullptr, will be treated as called by system.
|
2018-10-30 13:00:17 +03:00
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RemoveInlinePropertyAsAction(
|
|
|
|
nsStaticAtom& aHTMLProperty, nsStaticAtom* aAttribute,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr);
|
2019-06-10 13:27:07 +03:00
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
RemoveAllInlinePropertiesAsAction(nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
IncreaseFontSizeAsAction(nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DecreaseFontSizeAsAction(nsIPrincipal* aPrincipal = nullptr);
|
2018-01-26 08:38:05 +03:00
|
|
|
|
2018-08-27 09:52:35 +03:00
|
|
|
/**
|
|
|
|
* GetFontColorState() returns foreground color information in first
|
|
|
|
* range of Selection.
|
|
|
|
* If first range of Selection is collapsed and there is a cache of style for
|
|
|
|
* new text, aIsMixed is set to false and aColor is set to the cached color.
|
|
|
|
* If first range of Selection is collapsed and there is no cached color,
|
|
|
|
* this returns the color of the node, aIsMixed is set to false and aColor is
|
|
|
|
* set to the color.
|
|
|
|
* If first range of Selection is not collapsed, this collects colors of
|
|
|
|
* each node in the range. If there are two or more colors, aIsMixed is set
|
|
|
|
* to true and aColor is truncated. If only one color is set to all of the
|
|
|
|
* range, aIsMixed is set to false and aColor is set to the color.
|
|
|
|
* If there is no Selection ranges, aIsMixed is set to false and aColor is
|
|
|
|
* truncated.
|
|
|
|
*
|
|
|
|
* @param aIsMixed Must not be nullptr. This is set to true
|
|
|
|
* if there is two or more colors in first
|
|
|
|
* range of Selection.
|
|
|
|
* @param aColor Returns the color if only one color is set to
|
|
|
|
* all of first range in Selection. Otherwise,
|
|
|
|
* returns empty string.
|
|
|
|
* @return Returns error only when illegal cases, e.g.,
|
|
|
|
* Selection instance has gone, first range
|
|
|
|
* Selection is broken.
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
GetFontColorState(bool* aIsMixed, nsAString& aColor);
|
2018-08-27 09:52:35 +03:00
|
|
|
|
2018-01-26 08:38:05 +03:00
|
|
|
/**
|
|
|
|
* SetComposerCommandsUpdater() sets or unsets mComposerCommandsUpdater.
|
|
|
|
* This will crash in debug build if the editor already has an instance
|
|
|
|
* but called with another instance.
|
|
|
|
*/
|
|
|
|
void SetComposerCommandsUpdater(
|
|
|
|
ComposerCommandsUpdater* aComposerCommandsUpdater) {
|
|
|
|
MOZ_ASSERT(!aComposerCommandsUpdater || !mComposerCommandsUpdater ||
|
|
|
|
aComposerCommandsUpdater == mComposerCommandsUpdater);
|
|
|
|
mComposerCommandsUpdater = aComposerCommandsUpdater;
|
|
|
|
}
|
|
|
|
|
2019-09-02 11:06:56 +03:00
|
|
|
nsStaticAtom& DefaultParagraphSeparatorTagName() const {
|
|
|
|
return HTMLEditor::ToParagraphSeparatorTagName(mDefaultParagraphSeparator);
|
|
|
|
}
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
ParagraphSeparator GetDefaultParagraphSeparator() const {
|
|
|
|
return mDefaultParagraphSeparator;
|
|
|
|
}
|
|
|
|
void SetDefaultParagraphSeparator(ParagraphSeparator aSep) {
|
|
|
|
mDefaultParagraphSeparator = aSep;
|
|
|
|
}
|
2019-09-02 11:06:56 +03:00
|
|
|
static nsStaticAtom& ToParagraphSeparatorTagName(
|
|
|
|
ParagraphSeparator aSeparator) {
|
|
|
|
switch (aSeparator) {
|
|
|
|
case ParagraphSeparator::div:
|
|
|
|
return *nsGkAtoms::div;
|
|
|
|
case ParagraphSeparator::p:
|
|
|
|
return *nsGkAtoms::p;
|
|
|
|
case ParagraphSeparator::br:
|
|
|
|
return *nsGkAtoms::br;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("New paragraph separator isn't handled here");
|
|
|
|
return *nsGkAtoms::div;
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Modifies the table containing the selection according to the
|
|
|
|
* activation of an inline table editing UI element
|
|
|
|
* @param aUIAnonymousElement [IN] the inline table editing UI element
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DoInlineTableEditingAction(const Element& aUIAnonymousElement);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
/**
|
2020-04-09 13:10:36 +03:00
|
|
|
* GetInclusiveAncestorByTagName() looks for an element node whose name
|
|
|
|
* matches aTagName from aNode or anchor node of Selection to <body> element.
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
*
|
|
|
|
* @param aTagName The tag name which you want to look for.
|
|
|
|
* Must not be nsGkAtoms::_empty.
|
|
|
|
* If nsGkAtoms::list, the result may be <ul>, <ol> or
|
|
|
|
* <dl> element.
|
|
|
|
* If nsGkAtoms::td, the result may be <td> or <th>.
|
|
|
|
* If nsGkAtoms::href, the result may be <a> element
|
|
|
|
* which has "href" attribute with non-empty value.
|
2018-08-17 17:50:56 +03:00
|
|
|
* If nsGkAtoms::anchor, the result may be <a> which
|
|
|
|
* has "name" attribute with non-empty value.
|
2020-04-09 13:10:36 +03:00
|
|
|
* @param aContent Start node to look for the result.
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
* @return If an element which matches aTagName, returns
|
|
|
|
* an Element. Otherwise, nullptr.
|
|
|
|
*/
|
2020-04-09 13:10:36 +03:00
|
|
|
Element* GetInclusiveAncestorByTagName(const nsStaticAtom& aTagName,
|
|
|
|
nsIContent& aContent) const;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-06-04 11:45:34 +03:00
|
|
|
/**
|
|
|
|
* Get an active editor's editing host in DOM window. If this editor isn't
|
|
|
|
* active in the DOM window, this returns NULL.
|
|
|
|
*/
|
Bug 1677566 - part 3: Ignore non-deletable ranges in `HTMLEditor::HandleDeleteSelection()` r=m_kato
For making delete handlers simpler, and set better target ranges to the
corresponding `beforeinput` event, we should ignore non-editable ranges
before handling deletion.
This patch makes editor stop handling deleteion when a range crosses editing
host boundaries. In this case, Gecko has done nothing, but fired
`beforeinput` event. Note that Blink deletes editable contents in the range
**until** it meets first non-editable content, but I don't think this is
a good behavior because it makes things complicated. Therefore, I filed
a spec issue: https://github.com/w3c/editing/issues/283
On the other hand, this behavior change causes different behavior in
https://searchfox.org/mozilla-central/source/editor/libeditor/crashtests/1345015.html
It tries to insert paragraph into `<html>` element, but our editor currently
does not support it. Therefore, it hits `MOZ_ASSERT`. Therefore, this patch
added a new check into `HTMLEditor::InsertParagraphSeparatorAsSubAction()`.
Differential Revision: https://phabricator.services.mozilla.com/D107588
2021-03-10 02:57:54 +03:00
|
|
|
enum class LimitInBodyElement { No, Yes };
|
|
|
|
Element* GetActiveEditingHost(
|
|
|
|
LimitInBodyElement aLimitInBodyElement = LimitInBodyElement::Yes) const;
|
2018-06-04 11:45:34 +03:00
|
|
|
|
Bug 1597829 - part 2: Make `TextEditor::OnDrop()` move focus before inserting dropped content r=m_kato
Chrome moves focus to dropped element or editing host containing dropped
element, but we don't do it. For compatibility with Chrome, it's better to
follow their behavior. Additionally, this fixes 2 issues. One is, when
dropping something into non-focused contenteditable element, we've failed to
initialize selection from `TextEditor::PrepareToInsertContent()` because
`pointToInsert` is outside of selection limiter if another editing host
has focus. The other is, when same case, we've failed to insert dropped
content because edit action handlers of `HTMLEditor` check whether editing
position is in active editing host.
Finally, this patch makes `TextEditor::OnDrop()` cancels to dispatch "input"
event if it fails something before trying to insert dropped content. Without
this change, `EditorBase::DispatchInputEvent()` tries to dispatch without
proper `data` or `dataTransfer` and that hits `MOZ_ASSERT` in `nsContentUtils`.
Additionally, this fixes an existing bug which `HTMLEditor` may insert `\r`
as-is if it comes from paste or drop. Otherwise, we need complicated `todo_is`
paths in `test_dragdrop.html`.
Differential Revision: https://phabricator.services.mozilla.com/D57447
--HG--
extra : moz-landing-system : lando
2019-12-21 15:28:56 +03:00
|
|
|
/**
|
|
|
|
* Retruns true if we're in designMode.
|
|
|
|
*/
|
|
|
|
bool IsInDesignMode() const {
|
|
|
|
Document* document = GetDocument();
|
|
|
|
return document && document->HasFlag(NODE_IS_EDITABLE);
|
|
|
|
}
|
|
|
|
|
2021-06-22 03:18:07 +03:00
|
|
|
/**
|
|
|
|
* Basically, this always returns true if we're for `contenteditable` or
|
|
|
|
* `designMode` editor in web apps. However, e.g., Composer of SeaMonkey
|
|
|
|
* can make the editor not tabbable.
|
|
|
|
*/
|
|
|
|
bool IsTabbable() const { return IsInteractionAllowed(); }
|
|
|
|
|
2019-06-04 11:42:43 +03:00
|
|
|
/**
|
|
|
|
* NotifyEditingHostMaybeChanged() is called when new element becomes
|
|
|
|
* contenteditable when the document already had contenteditable elements.
|
|
|
|
*/
|
|
|
|
void NotifyEditingHostMaybeChanged();
|
|
|
|
|
2019-03-30 01:42:32 +03:00
|
|
|
/** Insert a string as quoted text
|
|
|
|
* (whose representation is dependant on the editor type),
|
|
|
|
* replacing the selected text (if any).
|
|
|
|
*
|
|
|
|
* @param aQuotedText The actual text to be quoted
|
|
|
|
* @parem aNodeInserted Return the node which was inserted.
|
|
|
|
*/
|
2019-03-30 14:55:29 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT // USED_BY_COMM_CENTRAL
|
|
|
|
nsresult
|
|
|
|
InsertAsQuotation(const nsAString& aQuotedText, nsINode** aNodeInserted);
|
2019-03-30 01:42:32 +03:00
|
|
|
|
2018-09-14 13:03:24 +03:00
|
|
|
/**
|
|
|
|
* Inserts a plaintext string at the current location,
|
|
|
|
* with special processing for lines beginning with ">",
|
|
|
|
* which will be treated as mail quotes and inserted
|
|
|
|
* as plaintext quoted blocks.
|
|
|
|
* If the selection is not collapsed, the selection is deleted
|
|
|
|
* and the insertion takes place at the resulting collapsed selection.
|
|
|
|
*
|
|
|
|
* @param aString the string to be inserted
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
InsertTextWithQuotations(const nsAString& aStringToInsert);
|
2018-09-14 13:03:24 +03:00
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertHTMLAsAction(
|
|
|
|
const nsAString& aInString, nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
2021-06-28 15:08:49 +03:00
|
|
|
/**
|
|
|
|
* Refresh positions of resizers. If you change size of target of resizers,
|
|
|
|
* you need to refresh position of resizers with calling this.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RefreshResizers();
|
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
protected: // May be called by friends.
|
2018-05-22 14:15:05 +03:00
|
|
|
/****************************************************************************
|
2019-09-18 11:40:08 +03:00
|
|
|
* Some friend classes 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 call them from friend classes, you need
|
|
|
|
* to make sure that AutoEditActionDataSetter is created.
|
2018-05-22 14:15:05 +03:00
|
|
|
****************************************************************************/
|
|
|
|
|
Bug 1569902 - part 4: Make `TextEditor` inserts padding `<br>` element for empty last line after setting flags to `NS_PADDING_FOR_EMPTY_LAST_LINE` r=m_kato
Stopping using attribute for "moz-br", `IMEContentObserver` cannot know when
new `<br>` element is changed to padding element for empty last line.
Therefore, editor needs to insert padding `<br>` element after setting the
flag properly. Then, `IMEContentObserver` does not need to recompute the
length of `<br>` element (if it's for padding, it computes the length as 0).
Unfortunately, `TextEditor::InsertBrElementWithTransaction()` is used in too
many places and it already has optional argument. Therefore, it's difficult
to change it. However, we should share the preparation before creating `<br>`
element in it with new method. Therefore, this patch creates
`EditorBase::PrepareToInsertBRElement()` to share the preparation point (almost
just moved from the method). Then, new method is created as
`EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction()` because
it's used both in `TextEditor` and `HTMLEditor`. Finally, `TextEditor` won't
insert `<br>` element with `InsertBrElementWithTransaction()`. Therefore, it's
moved to `HTMLEditor` with renaming to `InsertBRElementWithTransaction()`.
Differential Revision: https://phabricator.services.mozilla.com/D39860
--HG--
extra : moz-landing-system : lando
2019-08-02 08:46:41 +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.
|
|
|
|
*
|
|
|
|
* @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
|
2021-04-28 06:33:25 +03:00
|
|
|
* <br> node, returns error.
|
Bug 1569902 - part 4: Make `TextEditor` inserts padding `<br>` element for empty last line after setting flags to `NS_PADDING_FOR_EMPTY_LAST_LINE` r=m_kato
Stopping using attribute for "moz-br", `IMEContentObserver` cannot know when
new `<br>` element is changed to padding element for empty last line.
Therefore, editor needs to insert padding `<br>` element after setting the
flag properly. Then, `IMEContentObserver` does not need to recompute the
length of `<br>` element (if it's for padding, it computes the length as 0).
Unfortunately, `TextEditor::InsertBrElementWithTransaction()` is used in too
many places and it already has optional argument. Therefore, it's difficult
to change it. However, we should share the preparation before creating `<br>`
element in it with new method. Therefore, this patch creates
`EditorBase::PrepareToInsertBRElement()` to share the preparation point (almost
just moved from the method). Then, new method is created as
`EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction()` because
it's used both in `TextEditor` and `HTMLEditor`. Finally, `TextEditor` won't
insert `<br>` element with `InsertBrElementWithTransaction()`. Therefore, it's
moved to `HTMLEditor` with renaming to `InsertBRElementWithTransaction()`.
Differential Revision: https://phabricator.services.mozilla.com/D39860
--HG--
extra : moz-landing-system : lando
2019-08-02 08:46:41 +03:00
|
|
|
*/
|
2021-04-28 06:33:25 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT Result<RefPtr<Element>, nsresult>
|
|
|
|
InsertBRElementWithTransaction(const EditorDOMPoint& aPointToInsert,
|
|
|
|
EDirection aSelect = eNone);
|
Bug 1569902 - part 4: Make `TextEditor` inserts padding `<br>` element for empty last line after setting flags to `NS_PADDING_FOR_EMPTY_LAST_LINE` r=m_kato
Stopping using attribute for "moz-br", `IMEContentObserver` cannot know when
new `<br>` element is changed to padding element for empty last line.
Therefore, editor needs to insert padding `<br>` element after setting the
flag properly. Then, `IMEContentObserver` does not need to recompute the
length of `<br>` element (if it's for padding, it computes the length as 0).
Unfortunately, `TextEditor::InsertBrElementWithTransaction()` is used in too
many places and it already has optional argument. Therefore, it's difficult
to change it. However, we should share the preparation before creating `<br>`
element in it with new method. Therefore, this patch creates
`EditorBase::PrepareToInsertBRElement()` to share the preparation point (almost
just moved from the method). Then, new method is created as
`EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction()` because
it's used both in `TextEditor` and `HTMLEditor`. Finally, `TextEditor` won't
insert `<br>` element with `InsertBrElementWithTransaction()`. Therefore, it's
moved to `HTMLEditor` with renaming to `InsertBRElementWithTransaction()`.
Differential Revision: https://phabricator.services.mozilla.com/D39860
--HG--
extra : moz-landing-system : lando
2019-08-02 08:46:41 +03:00
|
|
|
|
2018-04-10 10:23:54 +03:00
|
|
|
/**
|
Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once. Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.
For the former case, we should sort out it with
`EditorUtils::IsEditableContent()`, but for now, this patch moves it to
`HTMLEditUtils::IsSimplyEditable()`. On the other hand, for the latter case,
we obviously has a bug. Therefore, this patch creates
`HTMLEditUtils::IsRemovableFromParentNode()` and make it check whether the
removing node is also editable.
Unfortunately, `EditorUtils::IsEditableContent()` needs to take editor type.
But it's most callers are in `HTMLEditor` and most of remains are in
common methods of `EditorBase`. I guess we could remove this ugly argument
in the future.
Depends on D70874
Differential Revision: https://phabricator.services.mozilla.com/D70875
--HG--
extra : moz-landing-system : lando
2020-04-15 18:27:38 +03:00
|
|
|
* DeleteNodeWithTransaction() removes aContent from the DOM tree if it's
|
2018-04-10 10:23:54 +03:00
|
|
|
* modifiable. Note that this is not an override of same method of
|
|
|
|
* EditorBase.
|
|
|
|
*
|
Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once. Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.
For the former case, we should sort out it with
`EditorUtils::IsEditableContent()`, but for now, this patch moves it to
`HTMLEditUtils::IsSimplyEditable()`. On the other hand, for the latter case,
we obviously has a bug. Therefore, this patch creates
`HTMLEditUtils::IsRemovableFromParentNode()` and make it check whether the
removing node is also editable.
Unfortunately, `EditorUtils::IsEditableContent()` needs to take editor type.
But it's most callers are in `HTMLEditor` and most of remains are in
common methods of `EditorBase`. I guess we could remove this ugly argument
in the future.
Depends on D70874
Differential Revision: https://phabricator.services.mozilla.com/D70875
--HG--
extra : moz-landing-system : lando
2020-04-15 18:27:38 +03:00
|
|
|
* @param aContent The node to be removed from the DOM tree.
|
2018-04-10 10:23:54 +03:00
|
|
|
*/
|
Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once. Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.
For the former case, we should sort out it with
`EditorUtils::IsEditableContent()`, but for now, this patch moves it to
`HTMLEditUtils::IsSimplyEditable()`. On the other hand, for the latter case,
we obviously has a bug. Therefore, this patch creates
`HTMLEditUtils::IsRemovableFromParentNode()` and make it check whether the
removing node is also editable.
Unfortunately, `EditorUtils::IsEditableContent()` needs to take editor type.
But it's most callers are in `HTMLEditor` and most of remains are in
common methods of `EditorBase`. I guess we could remove this ugly argument
in the future.
Depends on D70874
Differential Revision: https://phabricator.services.mozilla.com/D70875
--HG--
extra : moz-landing-system : lando
2020-04-15 18:27:38 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult DeleteNodeWithTransaction(nsIContent& aContent);
|
2018-04-10 10:23:54 +03:00
|
|
|
|
2018-04-10 10:50:06 +03:00
|
|
|
/**
|
2019-07-22 06:53:29 +03:00
|
|
|
* DeleteTextWithTransaction() removes text in the range from aTextNode if
|
2018-04-10 10:50:06 +03:00
|
|
|
* it's modifiable. Note that this not an override of same method of
|
|
|
|
* EditorBase.
|
|
|
|
*
|
2019-07-22 06:53:29 +03:00
|
|
|
* @param aTextNode The text node which should be modified.
|
|
|
|
* @param aOffset Start offset of removing text in aTextNode.
|
2018-04-10 10:50:06 +03:00
|
|
|
* @param aLength Length of removing text.
|
|
|
|
*/
|
2019-07-22 06:53:29 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult DeleteTextWithTransaction(dom::Text& aTextNode,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength);
|
2018-04-10 10:50:06 +03:00
|
|
|
|
2020-05-21 05:30:09 +03:00
|
|
|
/**
|
|
|
|
* ReplaceTextWithTransaction() replaces text in the range with
|
|
|
|
* aStringToInsert.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult ReplaceTextWithTransaction(
|
|
|
|
dom::Text& aTextNode, uint32_t aOffset, uint32_t aLength,
|
|
|
|
const nsAString& aStringToInsert);
|
|
|
|
|
2018-04-12 11:58:14 +03:00
|
|
|
/**
|
|
|
|
* InsertTextWithTransaction() inserts aStringToInsert at aPointToInsert.
|
|
|
|
*/
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertTextWithTransaction(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document& aDocument, const nsAString& aStringToInsert,
|
2018-04-12 11:58:14 +03:00
|
|
|
const EditorRawDOMPoint& aPointToInsert,
|
2021-06-18 02:25:55 +03:00
|
|
|
EditorRawDOMPoint* aPointAfterInsertedString = nullptr) final;
|
2018-04-12 11:58:14 +03:00
|
|
|
|
2018-04-16 19:15:23 +03:00
|
|
|
/**
|
|
|
|
* CopyLastEditableChildStyles() clones inline container elements into
|
|
|
|
* aPreviousBlock to aNewBlock to keep using same style in it.
|
|
|
|
*
|
|
|
|
* @param aPreviousBlock The previous block element. All inline
|
|
|
|
* elements which are last sibling of each level
|
|
|
|
* are cloned to aNewBlock.
|
|
|
|
* @param aNewBlock New block container element.
|
2020-03-18 05:02:17 +03:00
|
|
|
* @param aNewBRElement If this method creates a new <br> element for
|
2018-04-16 19:15:23 +03:00
|
|
|
* placeholder, this is set to the new <br>
|
|
|
|
* element.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult CopyLastEditableChildStylesWithTransaction(
|
2018-04-16 19:15:23 +03:00
|
|
|
Element& aPreviousBlock, Element& aNewBlock,
|
2020-03-18 05:02:17 +03:00
|
|
|
RefPtr<Element>* aNewBRElement);
|
2018-04-16 19:15:23 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* RemoveBlockContainerWithTransaction() removes aElement from the DOM tree
|
|
|
|
* but moves its all children to its parent node and if its parent needs <br>
|
|
|
|
* element to have at least one line-height, this inserts <br> element
|
|
|
|
* automatically.
|
|
|
|
*
|
|
|
|
* @param aElement Block element to be removed.
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
RemoveBlockContainerWithTransaction(Element& aElement);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
Element* GetEditorRoot() const final;
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RemoveAttributeOrEquivalent(
|
|
|
|
Element* aElement, nsAtom* aAttribute, bool aSuppressTransaction) final;
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetAttributeOrEquivalent(
|
2020-03-18 05:02:17 +03:00
|
|
|
Element* aElement, nsAtom* aAttribute, const nsAString& aValue,
|
2021-06-18 02:25:55 +03:00
|
|
|
bool aSuppressTransaction) final;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
using EditorBase::RemoveAttributeOrEquivalent;
|
|
|
|
using EditorBase::SetAttributeOrEquivalent;
|
|
|
|
|
2018-08-16 18:12:51 +03:00
|
|
|
/**
|
|
|
|
* Returns container element of ranges in Selection. If Selection is
|
|
|
|
* collapsed, returns focus container node (or its parent element).
|
|
|
|
* If Selection selects only one element node, returns the element node.
|
|
|
|
* If Selection is only one range, returns common ancestor of the range.
|
|
|
|
* XXX If there are two or more Selection ranges, this returns parent node
|
|
|
|
* of start container of a range which starts with different node from
|
|
|
|
* start container of the first range.
|
|
|
|
*/
|
2018-10-30 13:01:38 +03:00
|
|
|
Element* GetSelectionContainerElement() const;
|
2018-08-16 18:12:51 +03:00
|
|
|
|
2018-09-19 04:58:48 +03:00
|
|
|
/**
|
|
|
|
* DeleteTableCellContentsWithTransaction() removes any contents in cell
|
|
|
|
* elements. If two or more cell elements are selected, this removes
|
|
|
|
* all selected cells' contents. Otherwise, this removes contents of
|
|
|
|
* a cell which contains first selection range. This does not return
|
|
|
|
* error even if selection is not in cell element, just does nothing.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult DeleteTableCellContentsWithTransaction();
|
2018-09-19 04:58:48 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
|
|
|
* extracts an element from the normal flow of the document and
|
|
|
|
* positions it, and puts it back in the normal flow.
|
|
|
|
* @param aElement [IN] the element
|
|
|
|
* @param aEnabled [IN] true to absolutely position the element,
|
|
|
|
* false to put it back in the normal flow
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetPositionToAbsoluteOrStatic(Element& aElement,
|
|
|
|
bool aEnabled);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* adds aChange to the z-index of an arbitrary element.
|
2020-08-26 07:48:28 +03:00
|
|
|
* @param aElement [IN] the element
|
|
|
|
* @param aChange [IN] relative change to apply to current z-index of
|
|
|
|
* the element
|
|
|
|
* @return The new z-index of the element
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
*/
|
2020-08-26 07:48:28 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<int32_t, nsresult>
|
|
|
|
AddZIndexWithTransaction(nsStyledElement& aStyledElement, int32_t aChange);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Join together any adjacent editable text nodes in the range.
|
|
|
|
*/
|
2020-02-13 05:54:45 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult CollapseAdjacentTextNodes(nsRange& aRange);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
static bool HasAttributes(Element* aElement) {
|
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
uint32_t attrCount = aElement->GetAttrCount();
|
|
|
|
return attrCount > 1 ||
|
|
|
|
(1 == attrCount &&
|
|
|
|
!aElement->GetAttrNameAt(0)->Equals(nsGkAtoms::mozdirty));
|
|
|
|
}
|
|
|
|
|
2018-08-30 08:20:24 +03:00
|
|
|
static dom::Element* GetLinkElement(nsINode* aNode);
|
2018-01-10 06:47:16 +03:00
|
|
|
|
2018-01-19 10:41:41 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Helper routines for font size changing.
|
2018-01-19 10:41:41 +03:00
|
|
|
*/
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
enum class FontSize { incr, decr };
|
2021-06-30 10:07:28 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
RelativeFontChangeOnTextNode(FontSize aDir, Text& aTextNode,
|
|
|
|
uint32_t aStartOffset, uint32_t aEndOffset);
|
2018-01-19 10:41:41 +03:00
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetInlinePropertyOnNode(nsIContent& aNode,
|
|
|
|
nsAtom& aProperty,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue);
|
Bug 662591 - HTMLEditor should set caret to start of first editable text node or before first editable inline node r=m_kato
Currently, HTMLEditor doesn't initialize caret position when it gets focus by
itself in most cases. Only when it's in designMode, it may move caret to the
first visible (not checking CSS actually).
In most cases, caret position is adjusted when EditorBase::InitializeSelection()
calls Selection::SetAncestorLimiter(). If selected range is outside of
new limiter, it moves caret to start of the new limiter. However, this is
really different behavior from the other browsers. The other browsers try
to move caret to the first editable text node or before the first editable
content such as <img>, <input>, etc.
This difference causes a serious incompatible issue with Draft.js. It doesn't
initialize caret position when it gets focus but it assumes that caret is
always set to before <br> element if there is no other content.
So, let's try to behave as what other browsers do as far as possible.
This patch makes editor behave as:
* if selection is already in the editing host except start of the editing host,
does nothing.
* if there is non-editable element before any editable node, move caret to
start of the editing host.
* if there is editable text node or element node which cannot have a text node,
move its start or before it.
* if there is no editable nodes which can contain text nodes, move caret to
start of the editing host.
Note that before applying this patch, in designMode, BeginningOfDocument() used
document element instead of <body> element. Therefore, it may set odd position
if <head> element has some text nodes with <script> or <style>. However,
this doesn't make sense and for making more consistent behavior between
designMode and contenteditable, this patch makes it use editing host (it's
<body> element if it's in designMode).
MozReview-Commit-ID: 5neYoTMq6Cc
--HG--
extra : rebase_source : c4d06b6864a221d7cd2833a007d73f7d67821e95
2018-03-02 08:20:25 +03:00
|
|
|
|
2019-10-07 04:11:31 +03:00
|
|
|
/**
|
|
|
|
* SplitAncestorStyledInlineElementsAtRangeEdges() splits all ancestor inline
|
|
|
|
* elements in the block at both aStartPoint and aEndPoint if given style
|
|
|
|
* matches with some of them.
|
|
|
|
*
|
|
|
|
* @param aStartPoint Start of range to split ancestor inline elements.
|
|
|
|
* @param aEndPoint End of range to split ancestor inline elements.
|
|
|
|
* @param aProperty The style tag name which you want to split. Set
|
|
|
|
* nullptr if you want to split any styled elements.
|
|
|
|
* @param aAttribute Attribute name if aProperty has some styles like
|
|
|
|
* nsGkAtoms::font.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitRangeOffResult
|
2019-10-07 04:11:31 +03:00
|
|
|
SplitAncestorStyledInlineElementsAtRangeEdges(
|
|
|
|
const EditorDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
|
|
|
|
nsAtom* aProperty, nsAtom* aAttribute);
|
|
|
|
|
2019-10-07 03:55:02 +03:00
|
|
|
/**
|
|
|
|
* SplitAncestorStyledInlineElementsAt() splits ancestor inline elements at
|
|
|
|
* aPointToSplit if specified style matches with them.
|
|
|
|
*
|
|
|
|
* @param aPointToSplit The point to split style at.
|
|
|
|
* @param aProperty The style tag name which you want to split.
|
|
|
|
* Set nullptr if you want to split any styled
|
|
|
|
* elements.
|
|
|
|
* @param aAttribute Attribute name if aProperty has some styles
|
|
|
|
* like nsGkAtoms::font.
|
|
|
|
* @return The result of SplitNodeDeepWithTransaction()
|
|
|
|
* with topmost split element. If this didn't
|
|
|
|
* find inline elements to be split, Handled()
|
|
|
|
* returns false.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitNodeResult
|
2019-10-07 03:55:02 +03:00
|
|
|
SplitAncestorStyledInlineElementsAt(const EditorDOMPoint& aPointToSplit,
|
|
|
|
nsAtom* aProperty, nsAtom* aAttribute);
|
2018-04-06 08:53:05 +03:00
|
|
|
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult GetInlinePropertyBase(
|
|
|
|
nsAtom& aHTMLProperty, nsAtom* aAttribute, const nsAString* aValue,
|
|
|
|
bool* aFirst, bool* aAny, bool* aAll, nsAString* outValue) const;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2019-10-07 03:55:02 +03:00
|
|
|
/**
|
|
|
|
* ClearStyleAt() splits parent elements to remove the specified style.
|
|
|
|
* If this splits some parent elements at near their start or end, such
|
|
|
|
* empty elements will be removed. Then, remove the specified style
|
|
|
|
* from the point and returns DOM point to put caret.
|
|
|
|
*
|
|
|
|
* @param aPoint The point to clear style at.
|
|
|
|
* @param aProperty An HTML tag name which represents a style.
|
|
|
|
* Set nullptr if you want to clear all styles.
|
|
|
|
* @param aAttribute Attribute name if aProperty has some styles like
|
|
|
|
* nsGkAtoms::font.
|
Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element). Then, unlink the new link element (i.e.,
clearing the "link style"). At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.
On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.
Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded. And then,
when preparing for inserting text, this patch makes it pass to the utility
method.
For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.
Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 10:19:33 +03:00
|
|
|
* @param aSpecifiedStyle Whether the class and style attributes should
|
|
|
|
* be preserved or discareded.
|
2019-10-07 03:55:02 +03:00
|
|
|
*/
|
Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element). Then, unlink the new link element (i.e.,
clearing the "link style"). At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.
On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.
Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded. And then,
when preparing for inserting text, this patch makes it pass to the utility
method.
For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.
Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 10:19:33 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditResult
|
|
|
|
ClearStyleAt(const EditorDOMPoint& aPoint, nsAtom* aProperty,
|
|
|
|
nsAtom* aAttribute, SpecifiedStyle aSpecifiedStyle);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2019-05-08 01:34:28 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetPositionToAbsolute(Element& aElement);
|
2020-08-26 07:48:16 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SetPositionToStatic(Element& aElement);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-10-25 08:55:04 +03:00
|
|
|
/**
|
|
|
|
* OnModifyDocument() is called when the editor is changed. This should
|
2019-09-18 11:40:08 +03:00
|
|
|
* be called only by runnable in HTMLEditor::OnDocumentModified() to call
|
|
|
|
* HTMLEditor::OnModifyDocument() with AutoEditActionDataSetter instance.
|
2018-10-25 08:55:04 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult OnModifyDocument();
|
2018-10-25 08:55:04 +03:00
|
|
|
|
2020-04-30 16:33:40 +03:00
|
|
|
/**
|
|
|
|
* DoSplitNode() creates a new node (left node) identical to an existing
|
|
|
|
* node (right node), and split the contents between the same point in both
|
|
|
|
* nodes.
|
|
|
|
*
|
|
|
|
* @param aStartOfRightNode The point to split. Its container will be
|
|
|
|
* the right node, i.e., become the new node's
|
|
|
|
* next sibling. And the point will be start
|
|
|
|
* of the right node.
|
|
|
|
* @param aNewLeftNode The new node called as left node, so, this
|
|
|
|
* becomes the container of aPointToSplit's
|
|
|
|
* previous sibling.
|
|
|
|
* @param aError Must have not already failed.
|
|
|
|
* If succeed to insert aLeftNode before the
|
|
|
|
* right node and remove unnecessary contents
|
|
|
|
* (and collapse selection at end of the left
|
|
|
|
* node if necessary), returns no error.
|
|
|
|
* Otherwise, an error.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT void DoSplitNode(const EditorDOMPoint& aStartOfRightNode,
|
|
|
|
nsIContent& aNewLeftNode,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2020-04-30 18:26:09 +03:00
|
|
|
/**
|
|
|
|
* DoJoinNodes() merges contents in aContentToJoin to aContentToKeep and
|
|
|
|
* remove aContentToJoin from the DOM tree. aContentToJoin and aContentToKeep
|
|
|
|
* must have same parent, aParent. Additionally, if one of aContentToJoin or
|
|
|
|
* aContentToKeep is a text node, the other must be a text node.
|
|
|
|
*
|
|
|
|
* @param aContentToKeep The node that will remain after the join.
|
|
|
|
* @param aContentToJoin The node that will be joined with aContentToKeep.
|
|
|
|
* There is no requirement that the two nodes be of the
|
|
|
|
* same type.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DoJoinNodes(nsIContent& aContentToKeep, nsIContent& aContentToJoin);
|
|
|
|
|
2021-07-02 11:23:45 +03:00
|
|
|
/**
|
|
|
|
* Routines for managing the preservation of selection across
|
|
|
|
* various editor actions.
|
|
|
|
*/
|
|
|
|
bool ArePreservingSelection() const;
|
|
|
|
void PreserveSelectionAcrossActions();
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RestorePreservedSelection();
|
|
|
|
void StopPreservingSelection();
|
|
|
|
|
2019-08-22 04:10:30 +03:00
|
|
|
protected: // edit sub-action handler
|
2019-09-02 09:08:43 +03:00
|
|
|
/**
|
|
|
|
* CanHandleHTMLEditSubAction() checks whether there is at least one
|
|
|
|
* selection range or not, and whether the first range is editable.
|
|
|
|
* If it's not editable, `Canceled()` of the result returns true.
|
|
|
|
* If `Selection` is in odd situation, returns an error.
|
|
|
|
*
|
|
|
|
* XXX I think that `IsSelectionEditable()` is better name, but it's already
|
|
|
|
* in `EditorBase`...
|
|
|
|
*/
|
|
|
|
EditActionResult CanHandleHTMLEditSubAction() const;
|
|
|
|
|
2019-08-22 10:08:19 +03:00
|
|
|
/**
|
2019-09-17 05:21:53 +03:00
|
|
|
* EnsureCaretNotAfterPaddingBRElement() makes sure that caret is NOT after
|
|
|
|
* padding `<br>` element for preventing insertion after padding `<br>`
|
|
|
|
* element at empty last line.
|
|
|
|
* NOTE: This method should be called only when `Selection` is collapsed
|
|
|
|
* because `Selection` is a pain to work with when not collapsed.
|
|
|
|
* (no good way to extend start or end of selection), so we need to
|
|
|
|
* ignore those types of selections.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-17 05:21:53 +03:00
|
|
|
EnsureCaretNotAfterPaddingBRElement();
|
|
|
|
|
2021-06-21 04:48:59 +03:00
|
|
|
/**
|
|
|
|
* MaybeCreatePaddingBRElementForEmptyEditor() creates padding <br> element
|
|
|
|
* for empty editor if there is no children.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
MaybeCreatePaddingBRElementForEmptyEditor();
|
|
|
|
|
2021-06-21 04:49:00 +03:00
|
|
|
/**
|
|
|
|
* EnsureNoPaddingBRElementForEmptyEditor() removes padding <br> element
|
|
|
|
* for empty editor if there is.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
EnsureNoPaddingBRElementForEmptyEditor();
|
|
|
|
|
2021-06-21 04:49:00 +03:00
|
|
|
/**
|
|
|
|
* ReflectPaddingBRElementForEmptyEditor() scans the tree from the root
|
|
|
|
* element and sets mPaddingBRElementForEmptyEditor if exists, or otherwise
|
|
|
|
* nullptr. Can be used to manage undo/redo.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] nsresult ReflectPaddingBRElementForEmptyEditor();
|
|
|
|
|
2019-09-17 05:21:53 +03:00
|
|
|
/**
|
|
|
|
* PrepareInlineStylesForCaret() consider inline styles from top level edit
|
|
|
|
* sub-action and setting it to `mTypeInState` and clear inline style cache
|
|
|
|
* if necessary.
|
|
|
|
* NOTE: This method should be called only when `Selection` is collapsed.
|
2019-08-22 10:08:19 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult PrepareInlineStylesForCaret();
|
2019-08-22 10:08:19 +03:00
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult HandleInsertText(
|
2019-09-13 05:40:09 +03:00
|
|
|
EditSubAction aEditSubAction, const nsAString& aInsertionString) final;
|
2019-08-22 11:01:39 +03:00
|
|
|
|
2021-06-07 07:18:08 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertDroppedDataTransferAsAction(
|
|
|
|
AutoEditActionDataSetter& aEditActionData,
|
|
|
|
dom::DataTransfer& aDataTransfer, const EditorDOMPoint& aDroppedAt,
|
2021-06-07 09:20:25 +03:00
|
|
|
dom::Document* aSrcDocument) final;
|
|
|
|
|
2019-08-22 04:10:30 +03:00
|
|
|
/**
|
|
|
|
* GetInlineStyles() retrieves the style of aNode and modifies each item of
|
|
|
|
* aStyleCacheArray. This might cause flushing layout at retrieving computed
|
|
|
|
* values of CSS properties.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2020-04-09 13:08:37 +03:00
|
|
|
GetInlineStyles(nsIContent& aContent, AutoStyleCacheArray& aStyleCacheArray);
|
2019-08-22 04:10:30 +03:00
|
|
|
|
2019-08-22 08:13:50 +03:00
|
|
|
/**
|
2020-04-09 13:08:37 +03:00
|
|
|
* CacheInlineStyles() caches style of aContent into mCachedInlineStyles of
|
2019-08-22 08:13:50 +03:00
|
|
|
* TopLevelEditSubAction. This may cause flushing layout at retrieving
|
|
|
|
* computed value of CSS properties.
|
|
|
|
*/
|
2020-04-09 13:08:37 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
CacheInlineStyles(nsIContent& aContent);
|
2019-08-22 08:13:50 +03:00
|
|
|
|
2019-08-22 08:12:28 +03:00
|
|
|
/**
|
|
|
|
* ReapplyCachedStyles() restores some styles which are disappeared during
|
|
|
|
* handling edit action and it should be restored. This may cause flushing
|
|
|
|
* layout at retrieving computed value of CSS properties.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult ReapplyCachedStyles();
|
2019-08-22 08:12:28 +03:00
|
|
|
|
2019-08-22 10:33:41 +03:00
|
|
|
/**
|
|
|
|
* CreateStyleForInsertText() sets CSS properties which are stored in
|
|
|
|
* TypeInState to proper element node.
|
|
|
|
* XXX This modifies Selection, but should return insertion point instead.
|
|
|
|
*
|
|
|
|
* @param aAbstractRange Set current selection range where new text
|
|
|
|
* should be inserted.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2020-05-03 02:44:46 +03:00
|
|
|
CreateStyleForInsertText(const dom::AbstractRange& aAbstractRange);
|
2019-08-22 10:33:41 +03:00
|
|
|
|
2019-08-22 16:11:16 +03:00
|
|
|
/**
|
|
|
|
* GetMostAncestorMailCiteElement() returns most-ancestor mail cite element.
|
|
|
|
* "mail cite element" is <pre> element when it's in plaintext editor mode
|
|
|
|
* or an element with which calling HTMLEditUtils::IsMailCite() returns true.
|
|
|
|
*
|
|
|
|
* @param aNode The start node to look for parent mail cite elements.
|
|
|
|
*/
|
|
|
|
Element* GetMostAncestorMailCiteElement(nsINode& aNode) const;
|
|
|
|
|
2019-08-22 11:29:16 +03:00
|
|
|
/**
|
|
|
|
* SplitMailCiteElements() splits mail-cite elements at start of Selection if
|
|
|
|
* Selection starts from inside a mail-cite element. Of course, if it's
|
|
|
|
* necessary, this inserts <br> node to new left nodes or existing right
|
|
|
|
* nodes.
|
|
|
|
* XXX This modifies Selection, but should return SplitNodeResult() instead.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-08-22 11:29:16 +03:00
|
|
|
SplitMailCiteElements(const EditorDOMPoint& aPointToSplit);
|
|
|
|
|
2019-08-22 11:33:28 +03:00
|
|
|
/**
|
|
|
|
* InsertBRElement() inserts a <br> element into aInsertToBreak.
|
|
|
|
* This may split container elements at the point and/or may move following
|
|
|
|
* <br> element to immediately after the new <br> element if necessary.
|
|
|
|
* XXX This method name is too generic and unclear whether such complicated
|
|
|
|
* things will be done automatically or not.
|
|
|
|
* XXX This modifies Selection, but should return CreateElementResult instead.
|
|
|
|
*
|
|
|
|
* @param aInsertToBreak The point where new <br> element will be
|
|
|
|
* inserted before.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-22 11:33:28 +03:00
|
|
|
InsertBRElement(const EditorDOMPoint& aInsertToBreak);
|
|
|
|
|
2019-08-23 04:28:26 +03:00
|
|
|
/**
|
|
|
|
* SplitParentInlineElementsAtRangeEdges() splits parent inline nodes at both
|
|
|
|
* start and end of aRangeItem. If this splits at every point, this modifies
|
|
|
|
* aRangeItem to point each split point (typically, right node).
|
|
|
|
*
|
|
|
|
* @param aRangeItem [in/out] One or two DOM points where should be
|
|
|
|
* split. Will be modified to split point if
|
|
|
|
* they're split.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-23 04:28:26 +03:00
|
|
|
SplitParentInlineElementsAtRangeEdges(RangeItem& aRangeItem);
|
|
|
|
|
2019-08-23 07:38:28 +03:00
|
|
|
/**
|
|
|
|
* SplitParentInlineElementsAtRangeEdges(nsTArray<RefPtr<nsRange>>&) calls
|
|
|
|
* SplitParentInlineElementsAtRangeEdges(RangeItem&) for each range. Then,
|
|
|
|
* updates given range to keep edit target ranges as expected.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-23 07:38:28 +03:00
|
|
|
SplitParentInlineElementsAtRangeEdges(
|
|
|
|
nsTArray<RefPtr<nsRange>>& aArrayOfRanges);
|
|
|
|
|
2019-08-23 07:14:56 +03:00
|
|
|
/**
|
|
|
|
* SplitElementsAtEveryBRElement() splits before all <br> elements in
|
|
|
|
* aMostAncestorToBeSplit. All <br> nodes will be moved before right node
|
|
|
|
* at splitting its parent. Finally, this returns left node, first <br>
|
|
|
|
* element, next left node, second <br> element... and right-most node.
|
|
|
|
*
|
|
|
|
* @param aMostAncestorToBeSplit Most-ancestor element which should
|
|
|
|
* be split.
|
|
|
|
* @param aOutArrayOfNodes First left node, first <br> element,
|
|
|
|
* Second left node, second <br> element,
|
2019-08-23 07:38:28 +03:00
|
|
|
* ...right-most node. So, all nodes
|
|
|
|
* in this list should be siblings (may be
|
2019-08-23 07:14:56 +03:00
|
|
|
* broken the relation by mutation event
|
2019-08-23 07:38:28 +03:00
|
|
|
* listener though). If first <br> element
|
|
|
|
* is first leaf node of
|
|
|
|
* aMostAncestorToBeSplit, starting from
|
|
|
|
* the first <br> element.
|
2019-08-23 07:14:56 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SplitElementsAtEveryBRElement(
|
2019-08-23 07:14:56 +03:00
|
|
|
nsIContent& aMostAncestorToBeSplit,
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents);
|
2019-08-23 07:14:56 +03:00
|
|
|
|
2019-08-23 07:38:28 +03:00
|
|
|
/**
|
|
|
|
* MaybeSplitElementsAtEveryBRElement() calls SplitElementsAtEveryBRElement()
|
|
|
|
* for each given node when this needs to do that for aEditSubAction.
|
2020-02-12 08:52:30 +03:00
|
|
|
* If split a node, it in aArrayOfContents is replaced with split nodes and
|
2019-08-23 07:38:28 +03:00
|
|
|
* <br> elements.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult MaybeSplitElementsAtEveryBRElement(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents,
|
2019-08-23 07:38:28 +03:00
|
|
|
EditSubAction aEditSubAction);
|
|
|
|
|
2019-08-23 06:35:40 +03:00
|
|
|
/**
|
|
|
|
* CollectEditableChildren() collects child nodes of aNode (starting from
|
|
|
|
* first editable child, but may return non-editable children after it).
|
|
|
|
*
|
|
|
|
* @param aNode Parent node of retrieving children.
|
2020-02-12 08:52:30 +03:00
|
|
|
* @param aOutArrayOfContents [out] This method will inserts found children
|
2019-08-23 06:35:40 +03:00
|
|
|
* into this array.
|
|
|
|
* @param aIndexToInsertChildren Starting from this index, found
|
|
|
|
* children will be inserted to the array.
|
|
|
|
* @param aCollectListChildren If Yes, will collect children of list
|
|
|
|
* and list-item elements recursively.
|
|
|
|
* @param aCollectTableChildren If Yes, will collect children of table
|
|
|
|
* related elements recursively.
|
2019-08-25 07:11:06 +03:00
|
|
|
* @param aCollectNonEditableNodes If Yes, will collect found children
|
|
|
|
* even if they are not editable.
|
2019-08-23 06:35:40 +03:00
|
|
|
* @return Number of found children.
|
|
|
|
*/
|
|
|
|
enum class CollectListChildren { No, Yes };
|
|
|
|
enum class CollectTableChildren { No, Yes };
|
2019-08-25 07:11:06 +03:00
|
|
|
enum class CollectNonEditableNodes { No, Yes };
|
2019-08-23 06:35:40 +03:00
|
|
|
size_t CollectChildren(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsINode& aNode, nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
size_t aIndexToInsertChildren, CollectListChildren aCollectListChildren,
|
|
|
|
CollectTableChildren aCollectTableChildren,
|
|
|
|
CollectNonEditableNodes aCollectNonEditableNodes) const;
|
2019-08-23 06:35:40 +03:00
|
|
|
|
2019-08-23 07:38:28 +03:00
|
|
|
/**
|
|
|
|
* SplitInlinessAndCollectEditTargetNodes() splits text nodes and inline
|
|
|
|
* elements around aArrayOfRanges. Then, collects edit target nodes to
|
|
|
|
* aOutArrayOfNodes. Finally, each edit target nodes is split at every
|
|
|
|
* <br> element in it.
|
2019-08-23 10:33:50 +03:00
|
|
|
* FYI: You can use SplitInlinesAndCollectEditTargetNodesInOneHardLine()
|
|
|
|
* or SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges()
|
|
|
|
* instead if you want to call this with a hard line including
|
|
|
|
* specific DOM point or extended selection ranges.
|
2019-08-23 07:38:28 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-23 07:38:28 +03:00
|
|
|
SplitInlinesAndCollectEditTargetNodes(
|
|
|
|
nsTArray<RefPtr<nsRange>>& aArrayOfRanges,
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
EditSubAction aEditSubAction,
|
|
|
|
CollectNonEditableNodes aCollectNonEditableNodes);
|
2019-08-23 07:38:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SplitTextNodesAtRangeEnd() splits text nodes if each range end is in
|
|
|
|
* middle of a text node.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-23 07:38:28 +03:00
|
|
|
SplitTextNodesAtRangeEnd(nsTArray<RefPtr<nsRange>>& aArrayOfRanges);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CollectEditTargetNodes() collects edit target nodes in aArrayOfRanges.
|
|
|
|
* First, this collects all nodes in given ranges, then, modifies the
|
|
|
|
* result for specific edit sub-actions.
|
2019-08-23 10:04:15 +03:00
|
|
|
* FYI: You can use CollectEditTargetNodesInExtendedSelectionRanges() instead
|
|
|
|
* if you want to call this with extended selection ranges.
|
2019-08-23 07:38:28 +03:00
|
|
|
*/
|
|
|
|
nsresult CollectEditTargetNodes(
|
|
|
|
nsTArray<RefPtr<nsRange>>& aArrayOfRanges,
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
EditSubAction aEditSubAction,
|
2019-08-25 07:20:34 +03:00
|
|
|
CollectNonEditableNodes aCollectNonEditableNodes);
|
2019-08-23 07:38:28 +03:00
|
|
|
|
2019-08-23 09:05:38 +03:00
|
|
|
/**
|
|
|
|
* GetCurrentHardLineStartPoint() returns start point of hard line
|
|
|
|
* including aPoint. If the line starts after a `<br>` element, returns
|
|
|
|
* next sibling of the `<br>` element. If the line is first line of a block,
|
|
|
|
* returns point of the block.
|
|
|
|
* NOTE: The result may be point of editing host. I.e., the container may
|
|
|
|
* be outside of editing host.
|
|
|
|
*/
|
2019-08-23 09:32:27 +03:00
|
|
|
template <typename PT, typename RT>
|
|
|
|
EditorDOMPoint GetCurrentHardLineStartPoint(
|
2020-09-14 13:54:42 +03:00
|
|
|
const RangeBoundaryBase<PT, RT>& aPoint,
|
|
|
|
EditSubAction aEditSubAction) const;
|
2019-08-23 09:05:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GetCurrentHardLineEndPoint() returns end point of hard line including
|
|
|
|
* aPoint. If the line ends with a `<br>` element, returns the `<br>`
|
|
|
|
* element unless it's the last node of a block. If the line is last line
|
|
|
|
* of a block, returns next sibling of the block. Additionally, if the
|
|
|
|
* line ends with a linefeed in pre-formated text node, returns point of
|
|
|
|
* the linefeed.
|
|
|
|
* NOTE: This result may be point of editing host. I.e., the container
|
|
|
|
* may be outside of editing host.
|
|
|
|
*/
|
2019-08-23 09:32:27 +03:00
|
|
|
template <typename PT, typename RT>
|
|
|
|
EditorDOMPoint GetCurrentHardLineEndPoint(
|
2020-09-14 13:54:42 +03:00
|
|
|
const RangeBoundaryBase<PT, RT>& aPoint) const;
|
2019-08-23 09:32:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CreateRangeIncludingAdjuscentWhiteSpaces() creates an nsRange instance
|
|
|
|
* which may be expanded from the given range to include adjuscent
|
2020-06-10 16:44:10 +03:00
|
|
|
* white-spaces. If this fails handling something, returns nullptr.
|
2019-08-23 09:32:27 +03:00
|
|
|
*/
|
|
|
|
already_AddRefed<nsRange> CreateRangeIncludingAdjuscentWhiteSpaces(
|
|
|
|
const dom::AbstractRange& aAbstractRange);
|
|
|
|
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
|
|
|
already_AddRefed<nsRange> CreateRangeIncludingAdjuscentWhiteSpaces(
|
|
|
|
const RangeBoundaryBase<SPT, SRT>& aStartRef,
|
|
|
|
const RangeBoundaryBase<EPT, ERT>& aEndRef);
|
|
|
|
|
2019-08-23 09:55:34 +03:00
|
|
|
/**
|
|
|
|
* GetSelectionRangesExtendedToIncludeAdjuscentWhiteSpaces() collects
|
2020-06-10 16:44:10 +03:00
|
|
|
* selection ranges with extending to include adjuscent white-spaces
|
2019-08-23 09:55:34 +03:00
|
|
|
* of each range start and end.
|
|
|
|
*
|
|
|
|
* @param aOutArrayOfRanges [out] Always appended same number of ranges
|
|
|
|
* as Selection::RangeCount(). Must be empty
|
|
|
|
* when you call this.
|
|
|
|
*/
|
|
|
|
void GetSelectionRangesExtendedToIncludeAdjuscentWhiteSpaces(
|
|
|
|
nsTArray<RefPtr<nsRange>>& aOutArrayOfRanges);
|
|
|
|
|
2019-08-23 09:32:27 +03:00
|
|
|
/**
|
|
|
|
* CreateRangeExtendedToHardLineStartAndEnd() creates an nsRange instance
|
|
|
|
* which may be expanded to start/end of hard line at both edges of the given
|
|
|
|
* range. If this fails handling something, returns nullptr.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsRange> CreateRangeExtendedToHardLineStartAndEnd(
|
2020-09-14 13:54:42 +03:00
|
|
|
const dom::AbstractRange& aAbstractRange,
|
|
|
|
EditSubAction aEditSubAction) const;
|
2019-08-23 09:32:27 +03:00
|
|
|
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
|
|
|
already_AddRefed<nsRange> CreateRangeExtendedToHardLineStartAndEnd(
|
|
|
|
const RangeBoundaryBase<SPT, SRT>& aStartRef,
|
2020-09-14 13:54:42 +03:00
|
|
|
const RangeBoundaryBase<EPT, ERT>& aEndRef,
|
|
|
|
EditSubAction aEditSubAction) const;
|
2019-08-23 09:32:27 +03:00
|
|
|
|
2019-08-23 09:55:34 +03:00
|
|
|
/**
|
|
|
|
* GetSelectionRangesExtendedToHardLineStartAndEnd() collects selection ranges
|
|
|
|
* with extending to start/end of hard line from each range start and end.
|
|
|
|
* XXX This means that same range may be included in the result.
|
|
|
|
*
|
|
|
|
* @param aOutArrayOfRanges [out] Always appended same number of ranges
|
|
|
|
* as Selection::RangeCount(). Must be empty
|
|
|
|
* when you call this.
|
|
|
|
*/
|
|
|
|
void GetSelectionRangesExtendedToHardLineStartAndEnd(
|
|
|
|
nsTArray<RefPtr<nsRange>>& aOutArrayOfRanges,
|
|
|
|
EditSubAction aEditSubAction);
|
|
|
|
|
2019-08-23 10:04:15 +03:00
|
|
|
/**
|
|
|
|
* SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges() calls
|
|
|
|
* SplitInlinesAndCollectEditTargetNodes() with result of
|
|
|
|
* GetSelectionRangesExtendedToHardLineStartAndEnd(). See comments for these
|
|
|
|
* methods for the detail.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-23 10:04:15 +03:00
|
|
|
SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
EditSubAction aEditSubAction,
|
|
|
|
CollectNonEditableNodes aCollectNonEditableNodes) {
|
2019-08-23 10:04:15 +03:00
|
|
|
AutoTArray<RefPtr<nsRange>, 4> extendedSelectionRanges;
|
|
|
|
GetSelectionRangesExtendedToHardLineStartAndEnd(extendedSelectionRanges,
|
|
|
|
aEditSubAction);
|
|
|
|
nsresult rv = SplitInlinesAndCollectEditTargetNodes(
|
2020-02-12 08:52:30 +03:00
|
|
|
extendedSelectionRanges, aOutArrayOfContents, aEditSubAction,
|
2019-08-25 07:11:06 +03:00
|
|
|
aCollectNonEditableNodes);
|
2019-08-23 10:04:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"SplitInlinesAndCollectEditTargetNodes() failed");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:33:50 +03:00
|
|
|
/**
|
|
|
|
* SplitInlinesAndCollectEditTargetNodesInOneHardLine() just calls
|
|
|
|
* SplitInlinesAndCollectEditTargetNodes() with result of calling
|
|
|
|
* CreateRangeExtendedToHardLineStartAndEnd() with aPointInOneHardLine.
|
|
|
|
* In other words, returns nodes in the hard line including
|
|
|
|
* `aPointInOneHardLine`. See the comments for these methods for the
|
|
|
|
* detail.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-23 10:33:50 +03:00
|
|
|
SplitInlinesAndCollectEditTargetNodesInOneHardLine(
|
|
|
|
const EditorDOMPoint& aPointInOneHardLine,
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
EditSubAction aEditSubAction,
|
|
|
|
CollectNonEditableNodes aCollectNonEditableNodes) {
|
2019-08-23 10:33:50 +03:00
|
|
|
if (NS_WARN_IF(!aPointInOneHardLine.IsSet())) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
RefPtr<nsRange> oneLineRange = CreateRangeExtendedToHardLineStartAndEnd(
|
|
|
|
aPointInOneHardLine.ToRawRangeBoundary(),
|
|
|
|
aPointInOneHardLine.ToRawRangeBoundary(), aEditSubAction);
|
|
|
|
if (!oneLineRange) {
|
|
|
|
// XXX It seems odd to create collapsed range for one line range...
|
|
|
|
ErrorResult error;
|
|
|
|
oneLineRange =
|
|
|
|
nsRange::Create(aPointInOneHardLine.ToRawRangeBoundary(),
|
|
|
|
aPointInOneHardLine.ToRawRangeBoundary(), error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AutoTArray<RefPtr<nsRange>, 1> arrayOfLineRanges;
|
|
|
|
arrayOfLineRanges.AppendElement(oneLineRange);
|
|
|
|
nsresult rv = SplitInlinesAndCollectEditTargetNodes(
|
2020-02-12 08:52:30 +03:00
|
|
|
arrayOfLineRanges, aOutArrayOfContents, aEditSubAction,
|
2019-08-25 07:11:06 +03:00
|
|
|
aCollectNonEditableNodes);
|
2019-08-23 10:33:50 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"SplitInlinesAndCollectEditTargetNodes() failed");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:04:15 +03:00
|
|
|
/**
|
|
|
|
* CollectEditTargetNodesInExtendedSelectionRanges() calls
|
|
|
|
* CollectEditTargetNodes() with result of
|
|
|
|
* GetSelectionRangesExtendedToHardLineStartAndEnd(). See comments for these
|
|
|
|
* methods for the detail.
|
|
|
|
*/
|
|
|
|
nsresult CollectEditTargetNodesInExtendedSelectionRanges(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
EditSubAction aEditSubAction,
|
|
|
|
CollectNonEditableNodes aCollectNonEditableNodes) {
|
2019-08-23 10:04:15 +03:00
|
|
|
AutoTArray<RefPtr<nsRange>, 4> extendedSelectionRanges;
|
|
|
|
GetSelectionRangesExtendedToHardLineStartAndEnd(extendedSelectionRanges,
|
|
|
|
aEditSubAction);
|
2019-08-25 07:11:06 +03:00
|
|
|
nsresult rv =
|
2020-02-12 08:52:30 +03:00
|
|
|
CollectEditTargetNodes(extendedSelectionRanges, aOutArrayOfContents,
|
2019-08-25 07:11:06 +03:00
|
|
|
aEditSubAction, aCollectNonEditableNodes);
|
2019-08-23 10:04:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "CollectEditTargetNodes() failed");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-08-23 09:32:27 +03:00
|
|
|
/**
|
|
|
|
* SelectBRElementIfCollapsedInEmptyBlock() helper method for
|
|
|
|
* CreateRangeIncludingAdjuscentWhiteSpaces() and
|
|
|
|
* CreateRangeExtendedToLineStartAndEnd(). If the given range is collapsed
|
|
|
|
* in a block and the block has only one `<br>` element, this makes
|
|
|
|
* aStartRef and aEndRef select the `<br>` element.
|
|
|
|
*/
|
|
|
|
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
|
|
|
void SelectBRElementIfCollapsedInEmptyBlock(
|
|
|
|
RangeBoundaryBase<SPT, SRT>& aStartRef,
|
2020-09-14 13:54:42 +03:00
|
|
|
RangeBoundaryBase<EPT, ERT>& aEndRef) const;
|
2019-08-23 09:05:38 +03:00
|
|
|
|
2019-08-23 10:34:38 +03:00
|
|
|
/**
|
|
|
|
* GetChildNodesOf() returns all child nodes of aParent with an array.
|
|
|
|
*/
|
2020-02-12 08:52:30 +03:00
|
|
|
static void GetChildNodesOf(
|
|
|
|
nsINode& aParentNode,
|
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents) {
|
|
|
|
MOZ_ASSERT(aOutArrayOfContents.IsEmpty());
|
|
|
|
aOutArrayOfContents.SetCapacity(aParentNode.GetChildCount());
|
2019-08-23 10:34:38 +03:00
|
|
|
for (nsIContent* childContent = aParentNode.GetFirstChild(); childContent;
|
|
|
|
childContent = childContent->GetNextSibling()) {
|
2020-02-12 08:52:30 +03:00
|
|
|
aOutArrayOfContents.AppendElement(*childContent);
|
2019-08-23 10:34:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 06:45:34 +03:00
|
|
|
/**
|
|
|
|
* Try to get parent list element at `Selection`. This returns first find
|
|
|
|
* parent list element of common ancestor of ranges (looking for it from
|
|
|
|
* first range to last range).
|
|
|
|
*/
|
|
|
|
Element* GetParentListElementAtSelection() const;
|
|
|
|
|
2019-08-25 09:19:48 +03:00
|
|
|
/**
|
|
|
|
* MaybeExtendSelectionToHardLineEdgesForBlockEditAction() adjust Selection if
|
|
|
|
* there is only one range. If range start and/or end point is <br> node or
|
|
|
|
* something non-editable point, they should be moved to nearest text node or
|
|
|
|
* something where the other methods easier to handle edit action.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-08-25 09:19:48 +03:00
|
|
|
MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
|
|
|
|
|
2019-08-26 04:38:56 +03:00
|
|
|
/**
|
|
|
|
* MaybeSplitAncestorsForInsertWithTransaction() does nothing if container of
|
|
|
|
* aStartOfDeepestRightNode can have an element whose tag name is aTag.
|
|
|
|
* Otherwise, looks for an ancestor node which is or is in active editing
|
|
|
|
* host and can have an element whose name is aTag. If there is such
|
|
|
|
* ancestor, its descendants are split.
|
|
|
|
*
|
|
|
|
* Note that this may create empty elements while splitting ancestors.
|
|
|
|
*
|
|
|
|
* @param aTag The name of element to be inserted
|
|
|
|
* after calling this method.
|
|
|
|
* @param aStartOfDeepestRightNode The start point of deepest right node.
|
|
|
|
* This point must be descendant of
|
|
|
|
* active editing host.
|
|
|
|
* @return When succeeded, SplitPoint() returns
|
|
|
|
* the point to insert the element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitNodeResult
|
2019-08-26 04:38:56 +03:00
|
|
|
MaybeSplitAncestorsForInsertWithTransaction(
|
|
|
|
nsAtom& aTag, const EditorDOMPoint& aStartOfDeepestRightNode);
|
|
|
|
|
2019-08-26 06:20:35 +03:00
|
|
|
/**
|
|
|
|
* SplitRangeOffFromBlock() splits aBlockElement at two points, before
|
|
|
|
* aStartOfMiddleElement and after aEndOfMiddleElement. If they are very
|
|
|
|
* start or very end of aBlcok, this won't create empty block.
|
|
|
|
*
|
|
|
|
* @param aBlockElement A block element which will be split.
|
|
|
|
* @param aStartOfMiddleElement Start node of middle block element.
|
|
|
|
* @param aEndOfMiddleElement End node of middle block element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitRangeOffFromNodeResult
|
2019-08-26 06:20:35 +03:00
|
|
|
SplitRangeOffFromBlock(Element& aBlockElement,
|
|
|
|
nsIContent& aStartOfMiddleElement,
|
|
|
|
nsIContent& aEndOfMiddleElement);
|
|
|
|
|
2019-08-26 06:59:48 +03:00
|
|
|
/**
|
|
|
|
* SplitRangeOffFromBlockAndRemoveMiddleContainer() splits the nodes
|
|
|
|
* between aStartOfRange and aEndOfRange, then, removes the middle element
|
|
|
|
* and moves its content to where the middle element was.
|
|
|
|
*
|
|
|
|
* @param aBlockElement The node which will be split.
|
|
|
|
* @param aStartOfRange The first node which will be unwrapped
|
|
|
|
* from aBlockElement.
|
|
|
|
* @param aEndOfRange The last node which will be unwrapped from
|
|
|
|
* aBlockElement.
|
|
|
|
* @return The left content is new created left
|
|
|
|
* element of aBlockElement.
|
|
|
|
* The right content is split element,
|
|
|
|
* i.e., must be aBlockElement.
|
|
|
|
* The middle content is nullptr since
|
|
|
|
* removing it is the job of this method.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitRangeOffFromNodeResult
|
2019-08-26 06:59:48 +03:00
|
|
|
SplitRangeOffFromBlockAndRemoveMiddleContainer(Element& aBlockElement,
|
|
|
|
nsIContent& aStartOfRange,
|
|
|
|
nsIContent& aEndOfRange);
|
|
|
|
|
2019-08-26 04:55:01 +03:00
|
|
|
/**
|
|
|
|
* MoveNodesIntoNewBlockquoteElement() inserts at least one <blockquote>
|
2020-02-12 08:52:30 +03:00
|
|
|
* element and moves nodes in aArrayOfContents into new <blockquote>
|
|
|
|
* elements.
|
|
|
|
* If aArrayOfContents includes a table related element except <table>,
|
|
|
|
* this calls itself recursively to insert <blockquote> into the cell.
|
2019-08-26 04:55:01 +03:00
|
|
|
*
|
2020-02-12 08:52:30 +03:00
|
|
|
* @param aArrayOfContents Nodes which will be moved into created
|
2019-08-26 04:55:01 +03:00
|
|
|
* <blockquote> elements.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult MoveNodesIntoNewBlockquoteElement(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents);
|
2019-08-26 04:55:01 +03:00
|
|
|
|
2019-08-26 07:00:15 +03:00
|
|
|
/**
|
|
|
|
* RemoveBlockContainerElements() removes all format blocks, table related
|
2020-02-12 08:52:30 +03:00
|
|
|
* element, etc in aArrayOfContents from the DOM tree.
|
|
|
|
* If aArrayOfContents has a format node, it will be removed and its contents
|
2019-08-26 07:00:15 +03:00
|
|
|
* will be moved to where it was.
|
2020-02-12 08:52:30 +03:00
|
|
|
* If aArrayOfContents has a table related element, <li>, <blockquote> or
|
|
|
|
* <div>, it will be removed and its contents will be moved to where it was.
|
2019-08-26 07:00:15 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveBlockContainerElements(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents);
|
2019-08-26 07:00:15 +03:00
|
|
|
|
2019-08-26 07:48:21 +03:00
|
|
|
/**
|
2020-02-12 08:52:30 +03:00
|
|
|
* CreateOrChangeBlockContainerElement() formats all nodes in aArrayOfContents
|
2019-08-26 07:48:21 +03:00
|
|
|
* with block elements whose name is aBlockTag.
|
2020-02-12 08:52:30 +03:00
|
|
|
* If aArrayOfContents has an inline element, a block element is created and
|
|
|
|
* the inline element and following inline elements are moved into the new
|
|
|
|
* block element.
|
|
|
|
* If aArrayOfContents has <br> elements, they'll be removed from the DOM
|
|
|
|
* tree and new block element will be created when there are some remaining
|
|
|
|
* inline elements.
|
|
|
|
* If aArrayOfContents has a block element, this calls itself with children
|
|
|
|
* of the block element. Then, new block element will be created when there
|
2019-08-26 07:48:21 +03:00
|
|
|
* are some remaining inline elements.
|
|
|
|
*
|
2020-02-12 08:52:30 +03:00
|
|
|
* @param aArrayOfContents Must be descendants of a node.
|
|
|
|
* @param aBlockTag The element name of new block elements.
|
2019-08-26 07:48:21 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult CreateOrChangeBlockContainerElement(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents, nsAtom& aBlockTag);
|
2019-08-26 07:48:21 +03:00
|
|
|
|
2019-08-26 10:09:11 +03:00
|
|
|
/**
|
2019-09-02 09:08:43 +03:00
|
|
|
* FormatBlockContainerWithTransaction() is implementation of "formatBlock"
|
|
|
|
* command of `Document.execCommand()`. This applies block style or removes
|
|
|
|
* it.
|
2019-08-26 10:09:11 +03:00
|
|
|
* NOTE: This creates AutoSelectionRestorer. Therefore, even when this
|
|
|
|
* return NS_OK, editor may have been destroyed.
|
|
|
|
*
|
|
|
|
* @param aBlockType New block tag name.
|
|
|
|
* If nsGkAtoms::normal or nsGkAtoms::_empty,
|
|
|
|
* RemoveBlockContainerElements() will be called.
|
|
|
|
* If nsGkAtoms::blockquote,
|
|
|
|
* MoveNodesIntoNewBlockquoteElement() will be
|
|
|
|
* called. Otherwise,
|
|
|
|
* CreateOrChangeBlockContainerElement() will be
|
|
|
|
* called.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 09:08:43 +03:00
|
|
|
FormatBlockContainerWithTransaction(nsAtom& aBlockType);
|
2019-08-26 10:09:11 +03:00
|
|
|
|
2019-09-02 04:47:14 +03:00
|
|
|
/**
|
|
|
|
* InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary() determines if
|
|
|
|
* aPointToInsert is start of a hard line and end of the line (i.e, the
|
|
|
|
* line is empty) and the line ends with block boundary, inserts a `<br>`
|
|
|
|
* element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 04:47:14 +03:00
|
|
|
InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
|
2020-07-29 15:19:07 +03:00
|
|
|
const EditorDOMPoint& aPointToInsert);
|
2019-09-02 04:47:14 +03:00
|
|
|
|
2019-09-02 06:17:14 +03:00
|
|
|
/**
|
|
|
|
* Insert a `<br>` element if aElement is a block element and empty.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 06:17:14 +03:00
|
|
|
InsertBRElementIfEmptyBlockElement(Element& aElement);
|
|
|
|
|
2019-09-02 06:16:26 +03:00
|
|
|
/**
|
|
|
|
* Insert padding `<br>` element for empty last line into aElement if
|
|
|
|
* aElement is a block element and empty.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 06:16:26 +03:00
|
|
|
InsertPaddingBRElementForEmptyLastLineIfNeeded(Element& aElement);
|
|
|
|
|
2019-09-02 09:36:33 +03:00
|
|
|
/**
|
|
|
|
* This method inserts a padding `<br>` element for empty last line if
|
|
|
|
* selection is collapsed and container of the range needs it.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 09:36:33 +03:00
|
|
|
MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
|
|
|
|
|
2019-09-02 11:09:47 +03:00
|
|
|
/**
|
|
|
|
* SplitParagraph() splits the parent block, aParentDivOrP, at
|
|
|
|
* aStartOfRightNode.
|
|
|
|
*
|
|
|
|
* @param aParentDivOrP The parent block to be split. This must be <p>
|
|
|
|
* or <div> element.
|
|
|
|
* @param aStartOfRightNode The point to be start of right node after
|
|
|
|
* split. This must be descendant of
|
|
|
|
* aParentDivOrP.
|
|
|
|
* @param aNextBRNode Next <br> node if there is. Otherwise, nullptr.
|
|
|
|
* If this is not nullptr, the <br> node may be
|
|
|
|
* removed.
|
|
|
|
*/
|
|
|
|
template <typename PT, typename CT>
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SplitParagraph(
|
2019-09-02 11:09:47 +03:00
|
|
|
Element& aParentDivOrP,
|
|
|
|
const EditorDOMPointBase<PT, CT>& aStartOfRightNode, nsIContent* aBRNode);
|
|
|
|
|
2019-09-02 11:49:18 +03:00
|
|
|
/**
|
|
|
|
* HandleInsertParagraphInParagraph() does the right thing for Enter key
|
|
|
|
* press or 'insertParagraph' command in aParentDivOrP. aParentDivOrP will
|
|
|
|
* be split at start of first selection range.
|
|
|
|
*
|
|
|
|
* @param aParentDivOrP The parent block. This must be <p> or <div>
|
|
|
|
* element.
|
|
|
|
* @return Returns with NS_OK if this doesn't meat any
|
|
|
|
* unexpected situation. If this method tries to
|
|
|
|
* split the paragraph, marked as handled.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-02 11:49:18 +03:00
|
|
|
HandleInsertParagraphInParagraph(Element& aParentDivOrP);
|
|
|
|
|
2019-09-02 12:14:23 +03:00
|
|
|
/**
|
|
|
|
* HandleInsertParagraphInHeadingElement() handles insertParagraph command
|
|
|
|
* (i.e., handling Enter key press) in a heading element. This splits
|
|
|
|
* aHeader element at aOffset in aNode. Then, if right heading element is
|
|
|
|
* empty, it'll be removed and new paragraph is created (its type is decided
|
|
|
|
* with default paragraph separator).
|
|
|
|
*
|
|
|
|
* @param aHeader The heading element to be split.
|
|
|
|
* @param aNode Typically, Selection start container,
|
|
|
|
* where to be split.
|
|
|
|
* @param aOffset Typically, Selection start offset in the
|
|
|
|
* start container, where to be split.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 12:14:23 +03:00
|
|
|
HandleInsertParagraphInHeadingElement(Element& aHeader, nsINode& aNode,
|
2021-06-30 10:07:28 +03:00
|
|
|
uint32_t aOffset);
|
2019-09-02 12:14:23 +03:00
|
|
|
|
2019-09-02 12:16:31 +03:00
|
|
|
/**
|
|
|
|
* HandleInsertParagraphInListItemElement() handles insertParagraph command
|
|
|
|
* (i.e., handling Enter key press) in a list item element.
|
|
|
|
*
|
|
|
|
* @param aListItem The list item which has the following point.
|
|
|
|
* @param aNode Typically, Selection start container, where to
|
|
|
|
* insert a break.
|
|
|
|
* @param aOffset Typically, Selection start offset in the
|
|
|
|
* start container, where to insert a break.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-02 12:16:31 +03:00
|
|
|
HandleInsertParagraphInListItemElement(Element& aListItem, nsINode& aNode,
|
2021-06-30 10:07:28 +03:00
|
|
|
uint32_t aOffset);
|
2019-09-02 12:16:31 +03:00
|
|
|
|
2019-09-03 06:59:11 +03:00
|
|
|
/**
|
|
|
|
* InsertParagraphSeparatorAsSubAction() handles insertPargraph commad
|
|
|
|
* (i.e., handling Enter key press) with the above helper methods.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-03 06:59:11 +03:00
|
|
|
InsertParagraphSeparatorAsSubAction();
|
|
|
|
|
2019-09-03 08:13:35 +03:00
|
|
|
/**
|
|
|
|
* ChangeListElementType() replaces child list items of aListElement with
|
|
|
|
* new list item element whose tag name is aNewListItemTag.
|
|
|
|
* Note that if there are other list elements as children of aListElement,
|
|
|
|
* this calls itself recursively even though it's invalid structure.
|
|
|
|
*
|
|
|
|
* @param aListElement The list element whose list items will be
|
|
|
|
* replaced.
|
|
|
|
* @param aNewListTag New list tag name.
|
|
|
|
* @param aNewListItemTag New list item tag name.
|
|
|
|
* @return New list element or an error code if it fails.
|
|
|
|
* New list element may be aListElement if its
|
|
|
|
* tag name is same as aNewListTag.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT CreateElementResult ChangeListElementType(
|
2019-09-03 08:13:35 +03:00
|
|
|
Element& aListElement, nsAtom& aListType, nsAtom& aItemType);
|
|
|
|
|
2019-09-03 10:24:41 +03:00
|
|
|
/**
|
|
|
|
* ChangeSelectedHardLinesToList() converts selected ranges to specified
|
|
|
|
* list element. If there is different type of list elements, this method
|
|
|
|
* converts them to specified list items too. Basically, each hard line
|
|
|
|
* will be wrapped with a list item element. However, only when `<p>`
|
|
|
|
* element is selected, its child `<br>` elements won't be treated as
|
|
|
|
* hard line separators. Perhaps, this is a bug.
|
|
|
|
* NOTE: This method creates AutoSelectionRestorer. Therefore, each caller
|
|
|
|
* need to check if the editor is still available even if this returns
|
|
|
|
* NS_OK.
|
|
|
|
*
|
|
|
|
* @param aListElementTagName The new list element tag name.
|
|
|
|
* @param aListItemElementTagName The new list item element tag name.
|
2019-09-03 12:32:17 +03:00
|
|
|
* @param aBulletType If this is not empty string, it's set
|
|
|
|
* to `type` attribute of new list item
|
|
|
|
* elements. Otherwise, existing `type`
|
|
|
|
* attributes will be removed.
|
|
|
|
* @param aSelectAllOfCurrentList Yes if this should treat all of
|
|
|
|
* ancestor list element at selection.
|
2019-09-03 10:24:41 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-03 10:24:41 +03:00
|
|
|
ChangeSelectedHardLinesToList(nsAtom& aListElementTagName,
|
2019-09-03 12:32:17 +03:00
|
|
|
nsAtom& aListItemElementTagName,
|
|
|
|
const nsAString& aBulletType,
|
|
|
|
SelectAllOfCurrentList aSelectAllOfCurrentList);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MakeOrChangeListAndListItemAsSubAction() handles create list commands with
|
|
|
|
* current selection. If
|
|
|
|
*
|
|
|
|
* @param aListElementOrListItemElementTagName
|
|
|
|
* The new list element tag name or
|
|
|
|
* new list item tag name.
|
|
|
|
* If the former, list item tag name will
|
|
|
|
* be computed automatically. Otherwise,
|
|
|
|
* list tag name will be computed.
|
|
|
|
* @param aBulletType If this is not empty string, it's set
|
|
|
|
* to `type` attribute of new list item
|
|
|
|
* elements. Otherwise, existing `type`
|
|
|
|
* attributes will be removed.
|
|
|
|
* @param aSelectAllOfCurrentList Yes if this should treat all of
|
|
|
|
* ancestor list element at selection.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-03 12:32:17 +03:00
|
|
|
MakeOrChangeListAndListItemAsSubAction(
|
|
|
|
nsAtom& aListElementOrListItemElementTagName,
|
|
|
|
const nsAString& aBulletType,
|
|
|
|
SelectAllOfCurrentList aSelectAllOfCurrentList);
|
2019-09-03 10:24:41 +03:00
|
|
|
|
2020-05-18 08:12:16 +03:00
|
|
|
/**
|
2020-07-29 09:28:40 +03:00
|
|
|
* DeleteTextAndTextNodesWithTransaction() removes text or text nodes in
|
|
|
|
* the given range.
|
|
|
|
*/
|
|
|
|
enum class TreatEmptyTextNodes {
|
|
|
|
// KeepIfContainerOfRangeBoundaries:
|
|
|
|
// Will remove empty text nodes middle of the range, but keep empty
|
|
|
|
// text nodes which are containers of range boundaries.
|
|
|
|
KeepIfContainerOfRangeBoundaries,
|
|
|
|
// Remove:
|
|
|
|
// Will remove all empty text nodes.
|
|
|
|
Remove,
|
|
|
|
// RemoveAllEmptyInlineAncestors:
|
|
|
|
// Will remove all empty text nodes and its inline ancestors which
|
|
|
|
// become empty due to removing empty text nodes.
|
|
|
|
RemoveAllEmptyInlineAncestors,
|
|
|
|
};
|
2020-05-18 08:12:16 +03:00
|
|
|
template <typename EditorDOMPointType>
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2020-07-29 09:28:40 +03:00
|
|
|
DeleteTextAndTextNodesWithTransaction(
|
|
|
|
const EditorDOMPointType& aStartPoint,
|
|
|
|
const EditorDOMPointType& aEndPoint,
|
|
|
|
TreatEmptyTextNodes aTreatEmptyTextNodes);
|
2020-05-18 08:12:16 +03:00
|
|
|
|
2020-04-30 12:31:11 +03:00
|
|
|
/**
|
|
|
|
* JoinNodesWithTransaction() joins aLeftNode and aRightNode. Content of
|
|
|
|
* aLeftNode will be merged into aRightNode. Actual implemenation of this
|
|
|
|
* method is JoinNodesImpl(). So, see its explanation for the detail.
|
|
|
|
*
|
|
|
|
* @param aLeftNode Will be removed from the DOM tree.
|
|
|
|
* @param aRightNode The node which will be new container of the content of
|
|
|
|
* aLeftNode.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult JoinNodesWithTransaction(nsINode& aLeftNode,
|
|
|
|
nsINode& aRightNode);
|
|
|
|
|
2019-09-04 03:18:18 +03:00
|
|
|
/**
|
|
|
|
* JoinNearestEditableNodesWithTransaction() joins two editable nodes which
|
|
|
|
* are themselves or the nearest editable node of aLeftNode and aRightNode.
|
|
|
|
* XXX This method's behavior is odd. For example, if user types Backspace
|
|
|
|
* key at the second editable paragraph in this case:
|
|
|
|
* <div contenteditable>
|
|
|
|
* <p>first editable paragraph</p>
|
|
|
|
* <p contenteditable="false">non-editable paragraph</p>
|
|
|
|
* <p>second editable paragraph</p>
|
|
|
|
* </div>
|
|
|
|
* The first editable paragraph's content will be moved into the second
|
|
|
|
* editable paragraph and the non-editable paragraph becomes the first
|
|
|
|
* paragraph of the editor. I don't think that it's expected behavior of
|
|
|
|
* any users...
|
|
|
|
*
|
|
|
|
* @param aLeftNode The node which will be removed.
|
|
|
|
* @param aRightNode The node which will be inserted the content of
|
|
|
|
* aLeftNode.
|
|
|
|
* @param aNewFirstChildOfRightNode
|
|
|
|
* [out] The point at the first child of aRightNode.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-04 03:18:18 +03:00
|
|
|
JoinNearestEditableNodesWithTransaction(
|
|
|
|
nsIContent& aLeftNode, nsIContent& aRightNode,
|
|
|
|
EditorDOMPoint* aNewFirstChildOfRightNode);
|
|
|
|
|
2020-04-30 09:35:38 +03:00
|
|
|
/**
|
|
|
|
* ReplaceContainerAndCloneAttributesWithTransaction() creates new element
|
|
|
|
* whose name is aTagName, copies all attributes from aOldContainer to the
|
|
|
|
* new element, moves all children in aOldContainer to the new element, then,
|
|
|
|
* removes aOldContainer from the DOM tree.
|
|
|
|
*
|
|
|
|
* @param aOldContainer The element node which should be replaced
|
|
|
|
* with new element.
|
|
|
|
* @param aTagName The name of new element node.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element>
|
|
|
|
ReplaceContainerAndCloneAttributesWithTransaction(Element& aOldContainer,
|
|
|
|
nsAtom& aTagName) {
|
|
|
|
return ReplaceContainerWithTransactionInternal(
|
2020-09-23 18:17:15 +03:00
|
|
|
aOldContainer, aTagName, *nsGkAtoms::_empty, u""_ns, true);
|
2020-04-30 09:35:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ReplaceContainerWithTransaction() creates new element whose name is
|
|
|
|
* aTagName, sets aAttributes of the new element to aAttributeValue, moves
|
|
|
|
* all children in aOldContainer to the new element, then, removes
|
|
|
|
* aOldContainer from the DOM tree.
|
|
|
|
*
|
|
|
|
* @param aOldContainer The element node which should be replaced
|
|
|
|
* with new element.
|
|
|
|
* @param aTagName The name of new element node.
|
|
|
|
* @param aAttribute Attribute name to be set to the new element.
|
|
|
|
* @param aAttributeValue Attribute value to be set to aAttribute.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> ReplaceContainerWithTransaction(
|
|
|
|
Element& aOldContainer, nsAtom& aTagName, nsAtom& aAttribute,
|
|
|
|
const nsAString& aAttributeValue) {
|
|
|
|
return ReplaceContainerWithTransactionInternal(
|
|
|
|
aOldContainer, aTagName, aAttribute, aAttributeValue, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ReplaceContainerWithTransaction() creates new element whose name is
|
|
|
|
* aTagName, moves all children in aOldContainer to the new element, then,
|
|
|
|
* removes aOldContainer from the DOM tree.
|
|
|
|
*
|
|
|
|
* @param aOldContainer The element node which should be replaced
|
|
|
|
* with new element.
|
|
|
|
* @param aTagName The name of new element node.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> ReplaceContainerWithTransaction(
|
|
|
|
Element& aOldContainer, nsAtom& aTagName) {
|
|
|
|
return ReplaceContainerWithTransactionInternal(
|
2020-09-23 18:17:15 +03:00
|
|
|
aOldContainer, aTagName, *nsGkAtoms::_empty, u""_ns, false);
|
2020-04-30 09:35:38 +03:00
|
|
|
}
|
|
|
|
|
2020-04-30 09:36:41 +03:00
|
|
|
/**
|
|
|
|
* RemoveContainerWithTransaction() removes aElement from the DOM tree and
|
|
|
|
* moves all its children to the parent of aElement.
|
|
|
|
*
|
|
|
|
* @param aElement The element to be removed.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RemoveContainerWithTransaction(Element& aElement);
|
|
|
|
|
2020-04-30 09:36:53 +03:00
|
|
|
/**
|
|
|
|
* InsertContainerWithTransaction() creates new element whose name is
|
|
|
|
* aTagName, moves aContent into the new element, then, inserts the new
|
|
|
|
* element into where aContent was.
|
|
|
|
* Note that this method does not check if aContent is valid child of
|
|
|
|
* the new element. So, callers need to guarantee it.
|
|
|
|
*
|
|
|
|
* @param aContent The content which will be wrapped with new
|
|
|
|
* element.
|
|
|
|
* @param aTagName Element name of new element which will wrap
|
|
|
|
* aContent and be inserted into where aContent
|
|
|
|
* was.
|
|
|
|
* @return The new element.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> InsertContainerWithTransaction(
|
|
|
|
nsIContent& aContent, nsAtom& aTagName) {
|
2020-09-23 18:17:15 +03:00
|
|
|
return InsertContainerWithTransactionInternal(aContent, aTagName,
|
|
|
|
*nsGkAtoms::_empty, u""_ns);
|
2020-04-30 09:36:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* InsertContainerWithTransaction() creates new element whose name is
|
|
|
|
* aTagName, sets its aAttribute to aAttributeValue, moves aContent into the
|
|
|
|
* new element, then, inserts the new element into where aContent was.
|
|
|
|
* Note that this method does not check if aContent is valid child of
|
|
|
|
* the new element. So, callers need to guarantee it.
|
|
|
|
*
|
|
|
|
* @param aContent The content which will be wrapped with new
|
|
|
|
* element.
|
|
|
|
* @param aTagName Element name of new element which will wrap
|
|
|
|
* aContent and be inserted into where aContent
|
|
|
|
* was.
|
|
|
|
* @param aAttribute Attribute which should be set to the new
|
|
|
|
* element.
|
|
|
|
* @param aAttributeValue Value to be set to aAttribute.
|
|
|
|
* @return The new element.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> InsertContainerWithTransaction(
|
|
|
|
nsIContent& aContent, nsAtom& aTagName, nsAtom& aAttribute,
|
|
|
|
const nsAString& aAttributeValue) {
|
|
|
|
return InsertContainerWithTransactionInternal(aContent, aTagName,
|
|
|
|
aAttribute, aAttributeValue);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:46:37 +03:00
|
|
|
/**
|
|
|
|
* MoveNodeWithTransaction() moves aContent to aPointToInsert.
|
|
|
|
*
|
|
|
|
* @param aContent The node to be moved.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult MoveNodeWithTransaction(
|
|
|
|
nsIContent& aContent, const EditorDOMPoint& aPointToInsert);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MoveNodeToEndWithTransaction() moves aContent to end of aNewContainer.
|
|
|
|
*
|
|
|
|
* @param aContent The node to be moved.
|
|
|
|
* @param aNewContainer The new container which will contain aContent as
|
|
|
|
* its last child.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
MoveNodeToEndWithTransaction(nsIContent& aContent, nsINode& aNewContainer) {
|
|
|
|
EditorDOMPoint pointToInsert;
|
|
|
|
pointToInsert.SetToEndOf(&aNewContainer);
|
|
|
|
return MoveNodeWithTransaction(aContent, pointToInsert);
|
|
|
|
}
|
|
|
|
|
2019-09-04 06:32:26 +03:00
|
|
|
/**
|
2020-04-30 20:47:20 +03:00
|
|
|
* MoveNodeOrChildrenWithTransaction() moves aContent to aPointToInsert. If
|
|
|
|
* cannot insert aContent due to invalid relation, moves only its children
|
|
|
|
* recursively and removes aContent from the DOM tree.
|
2019-09-04 06:32:26 +03:00
|
|
|
*
|
|
|
|
* @param aContent Content which should be moved.
|
|
|
|
* @param aPointToInsert The point to be inserted aContent or its
|
|
|
|
* descendants.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult
|
2020-04-30 20:47:20 +03:00
|
|
|
MoveNodeOrChildrenWithTransaction(nsIContent& aNode,
|
|
|
|
const EditorDOMPoint& aPointToInsert);
|
2019-09-04 06:32:26 +03:00
|
|
|
|
2020-09-14 13:54:42 +03:00
|
|
|
/**
|
|
|
|
* CanMoveNodeOrChildren() returns true if
|
|
|
|
* `MoveNodeOrChildrenWithTransaction()` can move or delete at least a
|
|
|
|
* descendant of aElement into aNewContainer. I.e., when this returns true,
|
|
|
|
* `MoveNodeOrChildrenWithTransaction()` must return "handled".
|
|
|
|
*/
|
|
|
|
Result<bool, nsresult> CanMoveNodeOrChildren(
|
|
|
|
const nsIContent& aContent, const nsINode& aNewContainer) const;
|
|
|
|
|
2019-09-04 06:32:26 +03:00
|
|
|
/**
|
2020-04-30 20:47:20 +03:00
|
|
|
* MoveChildrenWithTransaction() moves the children of aElement to
|
|
|
|
* aPointToInsert. If cannot insert some children due to invalid relation,
|
|
|
|
* calls MoveNodeOrChildrenWithTransaction() to remove the children but keep
|
|
|
|
* moving its children.
|
2019-09-04 06:32:26 +03:00
|
|
|
*
|
|
|
|
* @param aElement Container element whose children should be
|
|
|
|
* moved.
|
|
|
|
* @param aPointToInsert The point to be inserted children of aElement
|
|
|
|
* or its descendants.
|
|
|
|
*/
|
2020-04-30 20:47:20 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult MoveChildrenWithTransaction(
|
|
|
|
Element& aElement, const EditorDOMPoint& aPointToInsert);
|
2019-09-04 06:32:26 +03:00
|
|
|
|
2020-09-14 13:54:42 +03:00
|
|
|
/**
|
|
|
|
* CanMoveChildren() returns true if `MoveChildrenWithTransaction()` can move
|
|
|
|
* at least a descendant of aElement into aNewContainer. I.e., when this
|
|
|
|
* returns true, `MoveChildrenWithTransaction()` return "handled".
|
|
|
|
*/
|
|
|
|
Result<bool, nsresult> CanMoveChildren(const Element& aElement,
|
|
|
|
const nsINode& aNewContainer) const;
|
|
|
|
|
2020-04-30 18:31:33 +03:00
|
|
|
/**
|
|
|
|
* MoveAllChildren() moves all children of aContainer to before
|
|
|
|
* aPointToInsert.GetChild().
|
2020-04-30 19:24:20 +03:00
|
|
|
* See explanation of MoveChildrenBetween() for the detail of the behavior.
|
2020-04-30 18:31:33 +03:00
|
|
|
*
|
|
|
|
* @param aContainer The container node whose all children should
|
|
|
|
* be moved.
|
|
|
|
* @param aPointToInsert The insertion point. The container must not
|
|
|
|
* be a data node like a text node.
|
|
|
|
* @param aError The result. If this succeeds to move children,
|
|
|
|
* returns NS_OK. Otherwise, an error.
|
|
|
|
*/
|
|
|
|
void MoveAllChildren(nsINode& aContainer,
|
|
|
|
const EditorRawDOMPoint& aPointToInsert,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2020-04-30 19:24:20 +03:00
|
|
|
/**
|
|
|
|
* MoveChildrenBetween() moves all children between aFirstChild and aLastChild
|
|
|
|
* to before aPointToInsert.GetChild(). If some children are moved to
|
|
|
|
* different container while this method moves other children, they are just
|
|
|
|
* ignored. If the child node referred by aPointToInsert is moved to different
|
|
|
|
* container while this method moves children, returns error.
|
|
|
|
*
|
|
|
|
* @param aFirstChild The first child which should be moved to
|
|
|
|
* aPointToInsert.
|
|
|
|
* @param aLastChild The last child which should be moved. This
|
|
|
|
* must be a sibling of aFirstChild and it should
|
|
|
|
* be positioned after aFirstChild in the DOM tree
|
|
|
|
* order.
|
|
|
|
* @param aPointToInsert The insertion point. The container must not
|
|
|
|
* be a data node like a text node.
|
|
|
|
* @param aError The result. If this succeeds to move children,
|
|
|
|
* returns NS_OK. Otherwise, an error.
|
|
|
|
*/
|
|
|
|
void MoveChildrenBetween(nsIContent& aFirstChild, nsIContent& aLastChild,
|
|
|
|
const EditorRawDOMPoint& aPointToInsert,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2020-04-30 18:52:20 +03:00
|
|
|
/**
|
|
|
|
* MovePreviousSiblings() moves all siblings before aChild (i.e., aChild
|
|
|
|
* won't be moved) to before aPointToInsert.GetChild().
|
2020-04-30 19:24:20 +03:00
|
|
|
* See explanation of MoveChildrenBetween() for the detail of the behavior.
|
2020-04-30 18:52:20 +03:00
|
|
|
*
|
|
|
|
* @param aChild The node which is next sibling of the last
|
|
|
|
* node to be moved.
|
|
|
|
* @param aPointToInsert The insertion point. The container must not
|
|
|
|
* be a data node like a text node.
|
|
|
|
* @param aError The result. If this succeeds to move children,
|
|
|
|
* returns NS_OK. Otherwise, an error.
|
|
|
|
*/
|
|
|
|
void MovePreviousSiblings(nsIContent& aChild,
|
|
|
|
const EditorRawDOMPoint& aPointToInsert,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2019-09-04 08:00:11 +03:00
|
|
|
/**
|
|
|
|
* MoveOneHardLineContents() moves the content in a hard line which contains
|
|
|
|
* aPointInHardLine to aPointToInsert or end of aPointToInsert's container.
|
|
|
|
*
|
|
|
|
* @param aPointInHardLine A point in a hard line. All nodes in
|
|
|
|
* same hard line will be moved.
|
|
|
|
* @param aPointToInsert Point to insert contents of the hard
|
|
|
|
* line.
|
|
|
|
* @param aMoveToEndOfContainer If `Yes`, aPointToInsert.Offset() will
|
|
|
|
* be ignored and instead, all contents
|
|
|
|
* will be appended to the container of
|
|
|
|
* aPointToInsert. The result may be
|
|
|
|
* different from setting this to `No`
|
|
|
|
* and aPointToInsert points end of the
|
|
|
|
* container because mutation event
|
|
|
|
* listeners may modify children of the
|
|
|
|
* container while we're moving nodes.
|
|
|
|
*/
|
|
|
|
enum class MoveToEndOfContainer { Yes, No };
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult MoveOneHardLineContents(
|
2019-09-04 08:00:11 +03:00
|
|
|
const EditorDOMPoint& aPointInHardLine,
|
|
|
|
const EditorDOMPoint& aPointToInsert,
|
|
|
|
MoveToEndOfContainer aMoveToEndOfContainer = MoveToEndOfContainer::No);
|
|
|
|
|
2020-09-14 13:54:42 +03:00
|
|
|
/**
|
|
|
|
* CanMoveOrDeleteSomethingInHardLine() returns true if there are some content
|
|
|
|
* nodes which can be moved to another place or deleted. Note that if there
|
|
|
|
* is only a padding `<br>` element in empty block element, this returns
|
|
|
|
* false even though it may be deleted.
|
|
|
|
*
|
|
|
|
* @param aPointInHardLine A point in a hard line.
|
|
|
|
*/
|
|
|
|
template <typename PT, typename CT>
|
|
|
|
Result<bool, nsresult> CanMoveOrDeleteSomethingInHardLine(
|
|
|
|
const EditorDOMPointBase<PT, CT>& aPointInHardLine) const;
|
|
|
|
|
2020-04-30 14:27:33 +03:00
|
|
|
/**
|
|
|
|
* SplitNodeWithTransaction() creates a transaction to create a new node
|
|
|
|
* (left node) identical to an existing node (right node), and split the
|
|
|
|
* contents between the same point in both nodes, then, execute the
|
|
|
|
* transaction.
|
|
|
|
*
|
|
|
|
* @param aStartOfRightNode The point to split. Its container will be
|
|
|
|
* the right node, i.e., become the new node's
|
|
|
|
* next sibling. And the point will be start
|
|
|
|
* of the right node.
|
|
|
|
* @param aError If succeed, returns no error. Otherwise, an
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<nsIContent> SplitNodeWithTransaction(
|
|
|
|
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aResult);
|
|
|
|
|
2020-04-30 10:29:27 +03:00
|
|
|
enum class SplitAtEdges {
|
|
|
|
// SplitNodeDeepWithTransaction() won't split container element
|
|
|
|
// nodes at their edges. I.e., when split point is start or end of
|
|
|
|
// container, it won't be split.
|
|
|
|
eDoNotCreateEmptyContainer,
|
|
|
|
// SplitNodeDeepWithTransaction() always splits containers even
|
|
|
|
// if the split point is at edge of a container. E.g., if split point is
|
|
|
|
// start of an inline element, empty inline element is created as a new left
|
|
|
|
// node.
|
|
|
|
eAllowToCreateEmptyContainer,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SplitNodeDeepWithTransaction() splits aMostAncestorToSplit deeply.
|
|
|
|
*
|
|
|
|
* @param aMostAncestorToSplit The most ancestor node which should be
|
|
|
|
* split.
|
|
|
|
* @param aStartOfDeepestRightNode The start point of deepest right node.
|
|
|
|
* This point must be descendant of
|
|
|
|
* aMostAncestorToSplit.
|
|
|
|
* @param aSplitAtEdges Whether the caller allows this to
|
|
|
|
* create empty container element when
|
|
|
|
* split point is start or end of an
|
|
|
|
* element.
|
|
|
|
* @return SplitPoint() returns split point in
|
|
|
|
* aMostAncestorToSplit. The point must
|
|
|
|
* be good to insert something if the
|
|
|
|
* caller want to do it.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT SplitNodeResult
|
|
|
|
SplitNodeDeepWithTransaction(nsIContent& aMostAncestorToSplit,
|
|
|
|
const EditorDOMPoint& aDeepestStartOfRightNode,
|
|
|
|
SplitAtEdges aSplitAtEdges);
|
|
|
|
|
2020-04-27 03:36:10 +03:00
|
|
|
/**
|
|
|
|
* RemoveEmptyInclusiveAncestorInlineElements() removes empty inclusive
|
|
|
|
* ancestor inline elements in inclusive ancestor block element of aContent.
|
|
|
|
*
|
|
|
|
* @param aContent Must be an empty content.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
RemoveEmptyInclusiveAncestorInlineElements(nsIContent& aContent);
|
|
|
|
|
Bug 1642594 - part 5: Implement first version of new white-space normalizer which simulates Blink's one r=m_kato
This patch tries to implement Blink-compat white-space normalizer for
`HTMLEditor`.
It's difficult to list up our traditional white-space normalization rules
because `WSRunObject` touches white space sequence only when there is not
acceptable case, e.g., an ASCII white-spaces will be adjacent to another
one, and replaces only unacceptable white-space only. Therefore, whether
white-space sequence may start with either an ASCII white-space or an NBSP.
On the other hand, Blink and WebKit makes white-space sequence always
starts with an NBSP or an ASCII white-space (unfortunately, they behave
differently!). So, for web-compat, we should simulate Blink's behavior
because either behavior is reasonable but Blink have more market share.
This patch simply adds new white-space normalization path for the new one,
and it's switchable with a pref, and still disabled by default.
The other reason why we should do this is, our traditional white-space
normalizer touches the DOM a lot of times per edit action, and the timing
is both before and after touches the DOM tree. Therefore, it's difficult
to compute actual deleting range for `InputEvent.getTargetRanges()` and
touching a lot of times causes running mutation event listeners a lot and
creates a lot of transaction class instances. So, new one have a lot of
merits:
1. Improve web-compat
2. Improve the peformance
3. Improve the security
4. Improve the footprint (but this is now worse then traditional one)
5. Simplify the implementation
The new normalizer is mostly implemented with only 3 `HTMLEditor` methods.
One is `HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces()`. This is
semi-public method for the edit action handlers. This takes a range with
2 `EditorDOMPoinInText` to delete the range simply. This also replaces
surrounding white-space sequence if necessary. For inserting text case,
this method also handles only white-space normalization when it's called
with collapsed range, i.e., same `EditorDOMPointInText`. This tries to use
`RepaceTextWithTransaction()` as far as possible to reduce creation cost of
transaction classes and the footprint.
Another one is `HTMLEditor::ExtendRangeToDeleteWithNormalizingWhiteSpaces()`.
This tries to extend the given range to normalize surrounding white-spaces.
This is currently not optimized for footprint because this may include
white-spaces which do not need to be replaced. This optimization should be
done before shipping, but for now, enabling `InputEvent.getTargetRanges()` in
Nightly channel is more important. So that it should be done in a follow-up
bug.
The other is `HTMLEditor::GenerateWhitepaceSequence()`. This creates
normalized white-space sequence with surrounding character information.
For keeping this method simple as far as possible, we shouldn't optimize
the range of generation even in follow-ups.
Finally, the white-space sequence is not tested in mochitests, so that we
can enable this new normalizer when we run mochitests under
`editor/libeditor/tests`. However, WPT has some tests. We should keep
them running with current normalizer for checking regression. Instead,
we should enable the pref only for the new WPT added by the previous patch.
Depends on D78655
Differential Revision: https://phabricator.services.mozilla.com/D78656
2020-06-15 10:37:56 +03:00
|
|
|
/**
|
|
|
|
* DeleteTextAndNormalizeSurroundingWhiteSpaces() deletes text between
|
2020-07-29 15:19:07 +03:00
|
|
|
* aStartToDelete and immediately before aEndToDelete and return new caret
|
|
|
|
* position. If surrounding characters are white-spaces, this normalize them
|
|
|
|
* too. Finally, inserts `<br>` element if it's required.
|
Bug 1642594 - part 5: Implement first version of new white-space normalizer which simulates Blink's one r=m_kato
This patch tries to implement Blink-compat white-space normalizer for
`HTMLEditor`.
It's difficult to list up our traditional white-space normalization rules
because `WSRunObject` touches white space sequence only when there is not
acceptable case, e.g., an ASCII white-spaces will be adjacent to another
one, and replaces only unacceptable white-space only. Therefore, whether
white-space sequence may start with either an ASCII white-space or an NBSP.
On the other hand, Blink and WebKit makes white-space sequence always
starts with an NBSP or an ASCII white-space (unfortunately, they behave
differently!). So, for web-compat, we should simulate Blink's behavior
because either behavior is reasonable but Blink have more market share.
This patch simply adds new white-space normalization path for the new one,
and it's switchable with a pref, and still disabled by default.
The other reason why we should do this is, our traditional white-space
normalizer touches the DOM a lot of times per edit action, and the timing
is both before and after touches the DOM tree. Therefore, it's difficult
to compute actual deleting range for `InputEvent.getTargetRanges()` and
touching a lot of times causes running mutation event listeners a lot and
creates a lot of transaction class instances. So, new one have a lot of
merits:
1. Improve web-compat
2. Improve the peformance
3. Improve the security
4. Improve the footprint (but this is now worse then traditional one)
5. Simplify the implementation
The new normalizer is mostly implemented with only 3 `HTMLEditor` methods.
One is `HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces()`. This is
semi-public method for the edit action handlers. This takes a range with
2 `EditorDOMPoinInText` to delete the range simply. This also replaces
surrounding white-space sequence if necessary. For inserting text case,
this method also handles only white-space normalization when it's called
with collapsed range, i.e., same `EditorDOMPointInText`. This tries to use
`RepaceTextWithTransaction()` as far as possible to reduce creation cost of
transaction classes and the footprint.
Another one is `HTMLEditor::ExtendRangeToDeleteWithNormalizingWhiteSpaces()`.
This tries to extend the given range to normalize surrounding white-spaces.
This is currently not optimized for footprint because this may include
white-spaces which do not need to be replaced. This optimization should be
done before shipping, but for now, enabling `InputEvent.getTargetRanges()` in
Nightly channel is more important. So that it should be done in a follow-up
bug.
The other is `HTMLEditor::GenerateWhitepaceSequence()`. This creates
normalized white-space sequence with surrounding character information.
For keeping this method simple as far as possible, we shouldn't optimize
the range of generation even in follow-ups.
Finally, the white-space sequence is not tested in mochitests, so that we
can enable this new normalizer when we run mochitests under
`editor/libeditor/tests`. However, WPT has some tests. We should keep
them running with current normalizer for checking regression. Instead,
we should enable the pref only for the new WPT added by the previous patch.
Depends on D78655
Differential Revision: https://phabricator.services.mozilla.com/D78656
2020-06-15 10:37:56 +03:00
|
|
|
* Note that if you wants only normalizing white-spaces, you can set same
|
|
|
|
* point to both aStartToDelete and aEndToDelete. Then, this tries to
|
|
|
|
* normalize white-space sequence containing previous character of
|
|
|
|
* aStartToDelete.
|
|
|
|
*/
|
2020-07-29 15:19:07 +03:00
|
|
|
enum class DeleteDirection {
|
|
|
|
Forward,
|
|
|
|
Backward,
|
|
|
|
};
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditorDOMPoint, nsresult>
|
Bug 1642594 - part 5: Implement first version of new white-space normalizer which simulates Blink's one r=m_kato
This patch tries to implement Blink-compat white-space normalizer for
`HTMLEditor`.
It's difficult to list up our traditional white-space normalization rules
because `WSRunObject` touches white space sequence only when there is not
acceptable case, e.g., an ASCII white-spaces will be adjacent to another
one, and replaces only unacceptable white-space only. Therefore, whether
white-space sequence may start with either an ASCII white-space or an NBSP.
On the other hand, Blink and WebKit makes white-space sequence always
starts with an NBSP or an ASCII white-space (unfortunately, they behave
differently!). So, for web-compat, we should simulate Blink's behavior
because either behavior is reasonable but Blink have more market share.
This patch simply adds new white-space normalization path for the new one,
and it's switchable with a pref, and still disabled by default.
The other reason why we should do this is, our traditional white-space
normalizer touches the DOM a lot of times per edit action, and the timing
is both before and after touches the DOM tree. Therefore, it's difficult
to compute actual deleting range for `InputEvent.getTargetRanges()` and
touching a lot of times causes running mutation event listeners a lot and
creates a lot of transaction class instances. So, new one have a lot of
merits:
1. Improve web-compat
2. Improve the peformance
3. Improve the security
4. Improve the footprint (but this is now worse then traditional one)
5. Simplify the implementation
The new normalizer is mostly implemented with only 3 `HTMLEditor` methods.
One is `HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces()`. This is
semi-public method for the edit action handlers. This takes a range with
2 `EditorDOMPoinInText` to delete the range simply. This also replaces
surrounding white-space sequence if necessary. For inserting text case,
this method also handles only white-space normalization when it's called
with collapsed range, i.e., same `EditorDOMPointInText`. This tries to use
`RepaceTextWithTransaction()` as far as possible to reduce creation cost of
transaction classes and the footprint.
Another one is `HTMLEditor::ExtendRangeToDeleteWithNormalizingWhiteSpaces()`.
This tries to extend the given range to normalize surrounding white-spaces.
This is currently not optimized for footprint because this may include
white-spaces which do not need to be replaced. This optimization should be
done before shipping, but for now, enabling `InputEvent.getTargetRanges()` in
Nightly channel is more important. So that it should be done in a follow-up
bug.
The other is `HTMLEditor::GenerateWhitepaceSequence()`. This creates
normalized white-space sequence with surrounding character information.
For keeping this method simple as far as possible, we shouldn't optimize
the range of generation even in follow-ups.
Finally, the white-space sequence is not tested in mochitests, so that we
can enable this new normalizer when we run mochitests under
`editor/libeditor/tests`. However, WPT has some tests. We should keep
them running with current normalizer for checking regression. Instead,
we should enable the pref only for the new WPT added by the previous patch.
Depends on D78655
Differential Revision: https://phabricator.services.mozilla.com/D78656
2020-06-15 10:37:56 +03:00
|
|
|
DeleteTextAndNormalizeSurroundingWhiteSpaces(
|
|
|
|
const EditorDOMPointInText& aStartToDelete,
|
2020-07-29 15:19:07 +03:00
|
|
|
const EditorDOMPointInText& aEndToDelete,
|
|
|
|
TreatEmptyTextNodes aTreatEmptyTextNodes,
|
|
|
|
DeleteDirection aDeleteDirection);
|
Bug 1642594 - part 5: Implement first version of new white-space normalizer which simulates Blink's one r=m_kato
This patch tries to implement Blink-compat white-space normalizer for
`HTMLEditor`.
It's difficult to list up our traditional white-space normalization rules
because `WSRunObject` touches white space sequence only when there is not
acceptable case, e.g., an ASCII white-spaces will be adjacent to another
one, and replaces only unacceptable white-space only. Therefore, whether
white-space sequence may start with either an ASCII white-space or an NBSP.
On the other hand, Blink and WebKit makes white-space sequence always
starts with an NBSP or an ASCII white-space (unfortunately, they behave
differently!). So, for web-compat, we should simulate Blink's behavior
because either behavior is reasonable but Blink have more market share.
This patch simply adds new white-space normalization path for the new one,
and it's switchable with a pref, and still disabled by default.
The other reason why we should do this is, our traditional white-space
normalizer touches the DOM a lot of times per edit action, and the timing
is both before and after touches the DOM tree. Therefore, it's difficult
to compute actual deleting range for `InputEvent.getTargetRanges()` and
touching a lot of times causes running mutation event listeners a lot and
creates a lot of transaction class instances. So, new one have a lot of
merits:
1. Improve web-compat
2. Improve the peformance
3. Improve the security
4. Improve the footprint (but this is now worse then traditional one)
5. Simplify the implementation
The new normalizer is mostly implemented with only 3 `HTMLEditor` methods.
One is `HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces()`. This is
semi-public method for the edit action handlers. This takes a range with
2 `EditorDOMPoinInText` to delete the range simply. This also replaces
surrounding white-space sequence if necessary. For inserting text case,
this method also handles only white-space normalization when it's called
with collapsed range, i.e., same `EditorDOMPointInText`. This tries to use
`RepaceTextWithTransaction()` as far as possible to reduce creation cost of
transaction classes and the footprint.
Another one is `HTMLEditor::ExtendRangeToDeleteWithNormalizingWhiteSpaces()`.
This tries to extend the given range to normalize surrounding white-spaces.
This is currently not optimized for footprint because this may include
white-spaces which do not need to be replaced. This optimization should be
done before shipping, but for now, enabling `InputEvent.getTargetRanges()` in
Nightly channel is more important. So that it should be done in a follow-up
bug.
The other is `HTMLEditor::GenerateWhitepaceSequence()`. This creates
normalized white-space sequence with surrounding character information.
For keeping this method simple as far as possible, we shouldn't optimize
the range of generation even in follow-ups.
Finally, the white-space sequence is not tested in mochitests, so that we
can enable this new normalizer when we run mochitests under
`editor/libeditor/tests`. However, WPT has some tests. We should keep
them running with current normalizer for checking regression. Instead,
we should enable the pref only for the new WPT added by the previous patch.
Depends on D78655
Differential Revision: https://phabricator.services.mozilla.com/D78656
2020-06-15 10:37:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ExtendRangeToDeleteWithNormalizingWhiteSpaces() is a helper method of
|
|
|
|
* DeleteTextAndNormalizeSurroundingWhiteSpaces(). This expands
|
|
|
|
* aStartToDelete and/or aEndToDelete if there are white-spaces which need
|
|
|
|
* normalizing.
|
|
|
|
*
|
|
|
|
* @param aStartToDelete [In/Out] Start to delete. If this point
|
|
|
|
* follows white-spaces, this may be modified.
|
|
|
|
* @param aEndToDelete [In/Out] Next point of last content to be
|
|
|
|
* deleted. If this point is a white-space,
|
|
|
|
* this may be modified.
|
|
|
|
* @param aNormalizedWhiteSpacesInStartNode
|
|
|
|
* [Out] If container text node of aStartToDelete
|
|
|
|
* should be modified, this offers new string
|
|
|
|
* in the range in the text node.
|
|
|
|
* @param aNormalizedWhiteSpacesInEndNode
|
|
|
|
* [Out] If container text node of aEndToDelete
|
|
|
|
* is different from the container of
|
|
|
|
* aStartToDelete and it should be modified, this
|
|
|
|
* offers new string in the range in the text node.
|
|
|
|
*/
|
|
|
|
void ExtendRangeToDeleteWithNormalizingWhiteSpaces(
|
|
|
|
EditorDOMPointInText& aStartToDelete, EditorDOMPointInText& aEndToDelete,
|
|
|
|
nsAString& aNormalizedWhiteSpacesInStartNode,
|
|
|
|
nsAString& aNormalizedWhiteSpacesInEndNode) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CharPointType let the following helper methods of
|
|
|
|
* ExtendRangeToDeleteWithNormalizingWhiteSpaces() know what type of
|
|
|
|
* character will be previous or next char point after deletion.
|
|
|
|
*/
|
|
|
|
enum class CharPointType {
|
|
|
|
TextEnd, // Start or end of the text (hardline break or replaced inline
|
|
|
|
// element)
|
|
|
|
ASCIIWhiteSpace, // One of ASCII white-spaces (collapsible white-space)
|
|
|
|
NoBreakingSpace, // NBSP
|
|
|
|
VisibleChar, // Non-white-space characters
|
|
|
|
PreformattedChar, // Any character (including white-space) in preformatted
|
|
|
|
// element
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetPreviousCharPointType() and GetCharPointType() get type of
|
|
|
|
* previous/current char point from current DOM tree. In other words, if the
|
|
|
|
* point will be deleted, you cannot use these methods.
|
|
|
|
*/
|
|
|
|
template <typename EditorDOMPointType>
|
|
|
|
static CharPointType GetPreviousCharPointType(
|
|
|
|
const EditorDOMPointType& aPoint) {
|
|
|
|
MOZ_ASSERT(aPoint.IsInTextNode());
|
|
|
|
if (aPoint.IsStartOfContainer()) {
|
|
|
|
return CharPointType::TextEnd;
|
|
|
|
}
|
|
|
|
if (EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText())) {
|
|
|
|
return CharPointType::PreformattedChar;
|
|
|
|
}
|
|
|
|
if (aPoint.IsPreviousCharASCIISpace()) {
|
|
|
|
return CharPointType::ASCIIWhiteSpace;
|
|
|
|
}
|
|
|
|
return aPoint.IsPreviousCharNBSP() ? CharPointType::NoBreakingSpace
|
|
|
|
: CharPointType::VisibleChar;
|
|
|
|
}
|
|
|
|
template <typename EditorDOMPointType>
|
|
|
|
static CharPointType GetCharPointType(const EditorDOMPointType& aPoint) {
|
|
|
|
MOZ_ASSERT(aPoint.IsInTextNode());
|
|
|
|
if (aPoint.IsEndOfContainer()) {
|
|
|
|
return CharPointType::TextEnd;
|
|
|
|
}
|
|
|
|
if (EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText())) {
|
|
|
|
return CharPointType::PreformattedChar;
|
|
|
|
}
|
|
|
|
if (aPoint.IsCharASCIISpace()) {
|
|
|
|
return CharPointType::ASCIIWhiteSpace;
|
|
|
|
}
|
|
|
|
return aPoint.IsCharNBSP() ? CharPointType::NoBreakingSpace
|
|
|
|
: CharPointType::VisibleChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CharPointData let the following helper methods of
|
|
|
|
* ExtendRangeToDeleteWithNormalizingWhiteSpaces() know what type of
|
|
|
|
* character will be previous or next char point and the point is
|
|
|
|
* in same or different text node after deletion.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS CharPointData final {
|
|
|
|
public:
|
|
|
|
static CharPointData InDifferentTextNode(CharPointType aCharPointType) {
|
|
|
|
CharPointData result;
|
|
|
|
result.mIsInDifferentTextNode = true;
|
|
|
|
result.mType = aCharPointType;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
static CharPointData InSameTextNode(CharPointType aCharPointType) {
|
|
|
|
CharPointData result;
|
|
|
|
// Let's mark this as in different text node if given one indicates
|
|
|
|
// that there is end of text because it means that adjacent content
|
|
|
|
// from point of text node view is another element.
|
|
|
|
result.mIsInDifferentTextNode = aCharPointType == CharPointType::TextEnd;
|
|
|
|
result.mType = aCharPointType;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AcrossTextNodeBoundary() const { return mIsInDifferentTextNode; }
|
|
|
|
bool IsWhiteSpace() const {
|
|
|
|
return mType == CharPointType::ASCIIWhiteSpace ||
|
|
|
|
mType == CharPointType::NoBreakingSpace;
|
|
|
|
}
|
|
|
|
CharPointType Type() const { return mType; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
CharPointData() = default;
|
|
|
|
|
|
|
|
CharPointType mType;
|
|
|
|
bool mIsInDifferentTextNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetPreviousCharPointDataForNormalizingWhiteSpaces() and
|
|
|
|
* GetInclusiveNextCharPointDataForNormalizingWhiteSpaces() is helper methods
|
|
|
|
* of ExtendRangeToDeleteWithNormalizingWhiteSpaces(). This retrieves
|
|
|
|
* previous or inclusive next editable char point and returns its data.
|
|
|
|
*/
|
|
|
|
CharPointData GetPreviousCharPointDataForNormalizingWhiteSpaces(
|
|
|
|
const EditorDOMPointInText& aPoint) const;
|
|
|
|
CharPointData GetInclusiveNextCharPointDataForNormalizingWhiteSpaces(
|
|
|
|
const EditorDOMPointInText& aPoint) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GenerateWhiteSpaceSequence() generates white-space sequence which won't
|
|
|
|
* be collapsed.
|
|
|
|
*
|
|
|
|
* @param aResult [out] White space sequence which won't be
|
|
|
|
* collapsed, but wrapable.
|
|
|
|
* @param aLength Length of generating white-space sequence.
|
|
|
|
* Must be 1 or larger.
|
|
|
|
* @param aPreviousCharPointData
|
|
|
|
* Specify the previous char point where it'll be
|
|
|
|
* inserted. Currently, for keepin this method
|
|
|
|
* simple, does not support to generate a part
|
|
|
|
* of white-space sequence in a text node. So,
|
|
|
|
* if the type is white-space, it must indicate
|
|
|
|
* different text nodes white-space.
|
|
|
|
* @param aNextCharPointData Specify the next char point where it'll be
|
|
|
|
* inserted. Same as aPreviousCharPointData,
|
|
|
|
* this must node indidate white-space in same
|
|
|
|
* text node.
|
|
|
|
*/
|
|
|
|
static void GenerateWhiteSpaceSequence(
|
|
|
|
nsAString& aResult, uint32_t aLength,
|
|
|
|
const CharPointData& aPreviousCharPointData,
|
|
|
|
const CharPointData& aNextCharPointData);
|
|
|
|
|
2020-08-31 06:48:39 +03:00
|
|
|
/**
|
|
|
|
* ComputeTargetRanges() computes actual delete ranges which will be deleted
|
|
|
|
* unless the following `beforeinput` event is canceled.
|
|
|
|
*
|
|
|
|
* @param aDirectionAndAmount The direction and amount of deletion.
|
|
|
|
* @param aRangesToDelete [In/Out] The ranges to be deleted,
|
|
|
|
* typically, initialized with the
|
|
|
|
* selection ranges. This may be modified
|
|
|
|
* if selection ranges should be extened.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
ComputeTargetRanges(nsIEditor::EDirection aDirectionAndAmount,
|
|
|
|
AutoRangeArray& aRangesToDelete);
|
|
|
|
|
2019-09-06 07:31:38 +03:00
|
|
|
/**
|
|
|
|
* This method handles "delete selection" commands.
|
|
|
|
*
|
|
|
|
* @param aDirectionAndAmount Direction of the deletion.
|
|
|
|
* @param aStripWrappers Must be eStrip or eNoStrip.
|
|
|
|
*/
|
2021-06-18 02:25:55 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-06 07:31:38 +03:00
|
|
|
HandleDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
|
2019-09-13 05:49:43 +03:00
|
|
|
nsIEditor::EStripWrappers aStripWrappers) final;
|
2019-09-06 07:31:38 +03:00
|
|
|
|
2020-08-24 03:52:44 +03:00
|
|
|
class AutoDeleteRangesHandler;
|
|
|
|
|
2019-09-12 10:27:30 +03:00
|
|
|
/**
|
|
|
|
* DeleteMostAncestorMailCiteElementIfEmpty() deletes most ancestor
|
|
|
|
* mail cite element (`<blockquote type="cite">` or
|
|
|
|
* `<span _moz_quote="true">`, the former can be created with middle click
|
|
|
|
* paste with `Control` or `Command` even in the web) of aContent if it
|
|
|
|
* becomes empty.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-12 10:27:30 +03:00
|
|
|
DeleteMostAncestorMailCiteElementIfEmpty(nsIContent& aContent);
|
|
|
|
|
2019-09-06 07:51:51 +03:00
|
|
|
/**
|
|
|
|
* LiftUpListItemElement() moves aListItemElement outside its parent.
|
|
|
|
* If it's in a middle of a list element, the parent list element is split
|
|
|
|
* before aListItemElement. Then, moves aListItemElement to before its
|
|
|
|
* parent list element. I.e., moves aListItemElement between the 2 list
|
|
|
|
* elements if original parent was split. Then, if new parent becomes not a
|
|
|
|
* list element, the list item element is removed and its contents are moved
|
|
|
|
* to where the list item element was. If aListItemElement becomse not a
|
|
|
|
* child of list element, its contents are unwrapped from aListItemElement.
|
|
|
|
*
|
|
|
|
* @param aListItemElement Must be a <li>, <dt> or <dd> element.
|
|
|
|
* @param aLiftUpFromAllParentListElements
|
|
|
|
* If Yes, this method calls itself recursively
|
|
|
|
* to unwrap the contents in aListItemElement
|
|
|
|
* from any ancestor list elements.
|
|
|
|
* XXX This checks only direct parent of list
|
|
|
|
* elements. Therefore, if a parent list
|
|
|
|
* element in a list item element, the
|
|
|
|
* list item element and its list element
|
|
|
|
* won't be unwrapped.
|
|
|
|
*/
|
|
|
|
enum class LiftUpFromAllParentListElements { Yes, No };
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult LiftUpListItemElement(
|
2019-09-06 07:51:51 +03:00
|
|
|
dom::Element& aListItemElement,
|
|
|
|
LiftUpFromAllParentListElements aLiftUpFromAllParentListElements);
|
|
|
|
|
2019-09-06 08:46:15 +03:00
|
|
|
/**
|
|
|
|
* DestroyListStructureRecursively() destroys the list structure of
|
|
|
|
* aListElement recursively.
|
|
|
|
* If aListElement has <li>, <dl> or <dt> as a child, the element is removed
|
|
|
|
* but its descendants are moved to where the list item element was.
|
|
|
|
* If aListElement has another <ul>, <ol> or <dl> as a child, this method is
|
|
|
|
* called recursively.
|
|
|
|
* If aListElement has other nodes as its child, they are just removed.
|
|
|
|
* Finally, aListElement is removed. and its all children are moved to
|
|
|
|
* where the aListElement was.
|
|
|
|
*
|
|
|
|
* @param aListElement A <ul>, <ol> or <dl> element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-06 08:46:15 +03:00
|
|
|
DestroyListStructureRecursively(Element& aListElement);
|
|
|
|
|
2019-09-06 09:01:57 +03:00
|
|
|
/**
|
|
|
|
* RemoveListAtSelectionAsSubAction() removes list elements and list item
|
|
|
|
* elements at Selection. And move contents in them where the removed list
|
|
|
|
* was.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveListAtSelectionAsSubAction();
|
2019-09-06 09:01:57 +03:00
|
|
|
|
2019-09-06 11:51:36 +03:00
|
|
|
/**
|
|
|
|
* ChangeMarginStart() changes margin of aElement to indent or outdent.
|
|
|
|
* If it's rtl text, margin-right will be changed. Otherwise, margin-left.
|
|
|
|
* XXX This is not aware of vertical writing-mode.
|
|
|
|
*/
|
|
|
|
enum class ChangeMargin { Increase, Decrease };
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-06 11:51:36 +03:00
|
|
|
ChangeMarginStart(Element& aElement, ChangeMargin aChangeMargin);
|
|
|
|
|
2019-09-06 15:57:56 +03:00
|
|
|
/**
|
2019-09-08 07:35:52 +03:00
|
|
|
* HandleCSSIndentAtSelectionInternal() indents around Selection with CSS.
|
2019-09-06 15:57:56 +03:00
|
|
|
* This method creates AutoSelectionRestorer. Therefore, each caller
|
|
|
|
* need to check if the editor is still available even if this returns
|
|
|
|
* NS_OK.
|
2019-09-08 07:35:52 +03:00
|
|
|
* NOTE: Use HandleCSSIndentAtSelection() instead.
|
2019-09-06 15:57:56 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
HandleCSSIndentAtSelectionInternal();
|
2019-09-06 15:57:56 +03:00
|
|
|
|
2019-09-08 06:05:46 +03:00
|
|
|
/**
|
2019-09-08 07:35:52 +03:00
|
|
|
* HandleHTMLIndentAtSelectionInternal() indents around Selection with HTML.
|
2019-09-08 06:05:46 +03:00
|
|
|
* This method creates AutoSelectionRestorer. Therefore, each caller
|
|
|
|
* need to check if the editor is still available even if this returns
|
|
|
|
* NS_OK.
|
2019-09-08 07:35:52 +03:00
|
|
|
* NOTE: Use HandleHTMLIndentAtSelection() instead.
|
2019-09-08 06:05:46 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-08 07:35:52 +03:00
|
|
|
HandleHTMLIndentAtSelectionInternal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HandleCSSIndentAtSelection() indents around Selection with CSS.
|
|
|
|
* NOTE: This is a helper method of `HandleIndentAtSelection()`. If you
|
|
|
|
* want to call this directly, you should check whether you need
|
|
|
|
* do do something which `HandleIndentAtSelection()` does.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandleCSSIndentAtSelection();
|
2019-09-08 07:35:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HandleHTMLIndentAtSelection() indents around Selection with HTML.
|
|
|
|
* NOTE: This is a helper method of `HandleIndentAtSelection()`. If you
|
|
|
|
* want to call this directly, you should check whether you need
|
|
|
|
* do do something which `HandleIndentAtSelection()` does.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandleHTMLIndentAtSelection();
|
2019-09-08 07:35:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HandleIndentAtSelection() indents around Selection with HTML or CSS.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult HandleIndentAtSelection();
|
2019-09-08 06:05:46 +03:00
|
|
|
|
2019-09-08 06:23:16 +03:00
|
|
|
/**
|
|
|
|
* OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and
|
|
|
|
* aEndOfOutdent. This splits the range off from aBlockElement first.
|
|
|
|
* Then, removes the middle element if aIsBlockIndentedWithCSS is false.
|
|
|
|
* Otherwise, decreases the margin of the middle element.
|
|
|
|
*
|
|
|
|
* @param aBlockElement A block element which includes both
|
|
|
|
* aStartOfOutdent and aEndOfOutdent.
|
|
|
|
* @param aStartOfOutdent First node which is descendant of
|
|
|
|
* aBlockElement will be outdented.
|
|
|
|
* @param aEndOfOutdent Last node which is descandant of
|
|
|
|
* aBlockElement will be outdented.
|
|
|
|
* @param aBlockIndentedWith `CSS` if aBlockElement is indented with
|
|
|
|
* CSS margin property.
|
|
|
|
* `HTML` if aBlockElement is `<blockquote>`
|
|
|
|
* or something.
|
|
|
|
* @return The left content is new created element
|
|
|
|
* splitting before aStartOfOutdent.
|
|
|
|
* The right content is existing element.
|
|
|
|
* The middle content is outdented element
|
|
|
|
* if aBlockIndentedWith is `CSS`.
|
|
|
|
* Otherwise, nullptr.
|
|
|
|
*/
|
|
|
|
enum class BlockIndentedWith { CSS, HTML };
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitRangeOffFromNodeResult
|
2019-09-08 06:23:16 +03:00
|
|
|
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
|
|
|
|
nsIContent& aEndOutdent,
|
|
|
|
BlockIndentedWith aBlockIndentedWith);
|
|
|
|
|
2019-09-08 07:03:06 +03:00
|
|
|
/**
|
2019-09-08 08:05:38 +03:00
|
|
|
* HandleOutdentAtSelectionInternal() outdents contents around Selection.
|
2019-09-08 07:03:06 +03:00
|
|
|
* This method creates AutoSelectionRestorer. Therefore, each caller
|
|
|
|
* needs to check if the editor is still available even if this returns
|
|
|
|
* NS_OK.
|
2019-09-08 08:05:38 +03:00
|
|
|
* NOTE: Call `HandleOutdentAtSelection()` instead.
|
2019-09-08 07:03:06 +03:00
|
|
|
*
|
|
|
|
* @return The left content is left content of last
|
|
|
|
* outdented element.
|
|
|
|
* The right content is right content of last
|
|
|
|
* outdented element.
|
|
|
|
* The middle content is middle content of last
|
|
|
|
* outdented element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT SplitRangeOffFromNodeResult
|
2019-09-08 08:05:38 +03:00
|
|
|
HandleOutdentAtSelectionInternal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HandleOutdentAtSelection() outdents contents around Selection.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult HandleOutdentAtSelection();
|
2019-09-08 07:03:06 +03:00
|
|
|
|
2019-09-08 08:28:56 +03:00
|
|
|
/**
|
|
|
|
* AlignBlockContentsWithDivElement() sets align attribute of <div> element
|
|
|
|
* which is only child of aBlockElement to aAlignType. If aBlockElement
|
|
|
|
* has 2 or more children or does not have a `<div>` element, inserts a
|
|
|
|
* new `<div>` element into aBlockElement and move all children of
|
|
|
|
* aBlockElement into the new `<div>` element.
|
|
|
|
*
|
|
|
|
* @param aBlockElement The element node whose contents should be
|
|
|
|
* aligned to aAlignType. This should be
|
|
|
|
* an element which can have `<div>` element
|
|
|
|
* as its child.
|
|
|
|
* @param aAlignType New value of align attribute of `<div>`
|
|
|
|
* element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult AlignBlockContentsWithDivElement(
|
2019-09-08 08:28:56 +03:00
|
|
|
dom::Element& aBlockElement, const nsAString& aAlignType);
|
|
|
|
|
2019-09-08 08:29:24 +03:00
|
|
|
/**
|
|
|
|
* AlignContentsInAllTableCellsAndListItems() calls
|
|
|
|
* AlignBlockContentsWithDivElement() for aligning contents in every list
|
|
|
|
* item element and table cell element in aElement.
|
|
|
|
*
|
|
|
|
* @param aElement The node which is or whose descendants should
|
|
|
|
* be aligned to aAlignType.
|
|
|
|
* @param aAlignType New value of `align` attribute of `<div>`.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-08 08:29:24 +03:00
|
|
|
AlignContentsInAllTableCellsAndListItems(dom::Element& aElement,
|
|
|
|
const nsAString& aAlignType);
|
|
|
|
|
2019-09-09 13:46:17 +03:00
|
|
|
/**
|
|
|
|
* MakeTransitionList() detects all the transitions in the array, where a
|
|
|
|
* transition means that adjacent nodes in the array don't have the same
|
|
|
|
* parent.
|
|
|
|
*/
|
|
|
|
static void MakeTransitionList(
|
2020-02-12 08:52:30 +03:00
|
|
|
const nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents,
|
2019-09-09 13:46:17 +03:00
|
|
|
nsTArray<bool>& aTransitionArray);
|
|
|
|
|
2019-09-09 13:47:08 +03:00
|
|
|
/**
|
|
|
|
* EnsureHardLineBeginsWithFirstChildOf() inserts `<br>` element before
|
|
|
|
* first child of aRemovingContainerElement if it will not be start of a
|
|
|
|
* hard line after removing aRemovingContainerElement.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-09 13:47:08 +03:00
|
|
|
EnsureHardLineBeginsWithFirstChildOf(dom::Element& aRemovingContainerElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EnsureHardLineEndsWithLastChildOf() inserts `<br>` element after last
|
|
|
|
* child of aRemovingContainerElement if it will not be end of a hard line
|
|
|
|
* after removing aRemovingContainerElement.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-09 13:47:08 +03:00
|
|
|
EnsureHardLineEndsWithLastChildOf(dom::Element& aRemovingContainerElement);
|
|
|
|
|
2019-09-09 13:47:47 +03:00
|
|
|
/**
|
|
|
|
* RemoveAlignFromDescendants() removes align attributes, text-align
|
|
|
|
* properties and <center> elements in aElement.
|
|
|
|
*
|
|
|
|
* @param aElement Alignment information of the node and/or its
|
|
|
|
* descendants will be removed.
|
|
|
|
* NOTE: aElement must not be a `<table>` element.
|
|
|
|
* @param aAlignType New align value to be set only when it's in
|
|
|
|
* CSS mode and this method meets <table> or <hr>.
|
|
|
|
* XXX This is odd and not clear when you see caller of
|
|
|
|
* this method. Do you have better idea?
|
|
|
|
* @param aEditTarget If `OnlyDescendantsExceptTable`, modifies only
|
|
|
|
* descendants of aElement.
|
|
|
|
* If `NodeAndDescendantsExceptTable`, modifies `aElement`
|
|
|
|
* and its descendants.
|
|
|
|
*/
|
|
|
|
enum class EditTarget {
|
|
|
|
OnlyDescendantsExceptTable,
|
|
|
|
NodeAndDescendantsExceptTable
|
|
|
|
};
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveAlignFromDescendants(
|
2019-09-09 13:47:47 +03:00
|
|
|
Element& aElement, const nsAString& aAlignType, EditTarget aEditTarget);
|
|
|
|
|
2019-09-09 05:48:56 +03:00
|
|
|
/**
|
|
|
|
* SetBlockElementAlign() resets `align` attribute, `text-align` property
|
|
|
|
* of descendants of aBlockOrHRElement except `<table>` element descendants.
|
|
|
|
* Then, set `align` attribute or `text-align` property of aBlockOrHRElement.
|
|
|
|
*
|
|
|
|
* @param aBlockOrHRElement The element whose contents will be aligned.
|
|
|
|
* This must be a block element or `<hr>` element.
|
|
|
|
* If we're not in CSS mode, this element has
|
|
|
|
* to support `align` attribute (i.e.,
|
|
|
|
* `HTMLEditUtils::SupportsAlignAttr()` must
|
|
|
|
* return true).
|
|
|
|
* @param aAlignType Boundary or "center" which contents should be
|
|
|
|
* aligned on.
|
|
|
|
* @param aEditTarget If `OnlyDescendantsExceptTable`, modifies only
|
|
|
|
* descendants of aBlockOrHRElement.
|
|
|
|
* If `NodeAndDescendantsExceptTable`, modifies
|
|
|
|
* aBlockOrHRElement and its descendants.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-09 05:48:56 +03:00
|
|
|
SetBlockElementAlign(Element& aBlockOrHRElement, const nsAString& aAlignType,
|
|
|
|
EditTarget aEditTarget);
|
|
|
|
|
2019-09-09 07:57:50 +03:00
|
|
|
/**
|
|
|
|
* AlignContentsAtSelectionWithEmptyDivElement() inserts new `<div>` element
|
|
|
|
* at `Selection` to align selected contents. This returns as "handled"
|
|
|
|
* if this modifies `Selection` so that callers shouldn't modify `Selection`
|
|
|
|
* in such case especially when using AutoSelectionRestorer.
|
|
|
|
*
|
|
|
|
* @param aAlignType New align attribute value where the contents
|
|
|
|
* should be aligned to.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-09 07:57:50 +03:00
|
|
|
AlignContentsAtSelectionWithEmptyDivElement(const nsAString& aAlignType);
|
|
|
|
|
|
|
|
/**
|
2020-02-12 08:52:30 +03:00
|
|
|
* AlignNodesAndDescendants() make contents of nodes in aArrayOfContents and
|
2019-09-09 07:57:50 +03:00
|
|
|
* their descendants aligned to aAlignType.
|
|
|
|
*
|
|
|
|
* @param aAlignType New align attribute value where the contents
|
|
|
|
* should be aligned to.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult AlignNodesAndDescendants(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents,
|
|
|
|
const nsAString& aAlignType);
|
2019-09-09 07:57:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AlignContentsAtSelection() aligns contents around Selection to aAlignType.
|
|
|
|
* This creates AutoSelectionRestorer. Therefore, even if this returns
|
|
|
|
* NS_OK, we might have been destroyed. So, every caller needs to check if
|
|
|
|
* Destroyed() returns false before modifying the DOM tree or changing
|
|
|
|
* Selection.
|
|
|
|
* NOTE: Call AlignAsSubAction() instead.
|
|
|
|
*
|
|
|
|
* @param aAlignType New align attribute value where the contents
|
|
|
|
* should be aligned to.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-09 07:57:50 +03:00
|
|
|
AlignContentsAtSelection(const nsAString& aAlignType);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AlignAsSubAction() handles "align" command with `Selection`.
|
|
|
|
*
|
|
|
|
* @param aAlignType New align attribute value where the contents
|
|
|
|
* should be aligned to.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-09 07:57:50 +03:00
|
|
|
AlignAsSubAction(const nsAString& aAlignType);
|
|
|
|
|
2019-09-10 06:38:04 +03:00
|
|
|
/**
|
|
|
|
* AdjustCaretPositionAndEnsurePaddingBRElement() may adjust caret
|
|
|
|
* position to nearest editable content and if padding `<br>` element is
|
|
|
|
* necessary at caret position, this creates it.
|
|
|
|
*
|
|
|
|
* @param aDirectionAndAmount Direction of the edit action.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-10 06:38:04 +03:00
|
|
|
AdjustCaretPositionAndEnsurePaddingBRElement(
|
|
|
|
nsIEditor::EDirection aDirectionAndAmount);
|
|
|
|
|
2019-09-10 06:52:44 +03:00
|
|
|
/**
|
|
|
|
* EnsureSelectionInBodyOrDocumentElement() collapse `Selection` to the
|
|
|
|
* primary `<body>` element or document element when `Selection` crosses
|
|
|
|
* `<body>` element's boundary.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-10 06:52:44 +03:00
|
|
|
EnsureSelectionInBodyOrDocumentElement();
|
|
|
|
|
2019-09-10 07:32:21 +03:00
|
|
|
/**
|
|
|
|
* InsertBRElementToEmptyListItemsAndTableCellsInRange() inserts
|
|
|
|
* `<br>` element into empty list item or table cell elements between
|
|
|
|
* aStartRef and aEndRef.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-10 07:32:21 +03:00
|
|
|
InsertBRElementToEmptyListItemsAndTableCellsInRange(
|
|
|
|
const RawRangeBoundary& aStartRef, const RawRangeBoundary& aEndRef);
|
|
|
|
|
2019-09-10 07:46:55 +03:00
|
|
|
/**
|
|
|
|
* RemoveEmptyNodesIn() removes all empty nodes in aRange. However, if
|
|
|
|
* mail-cite node has only a `<br>` element, the node will be removed
|
|
|
|
* but <br> element is moved to where the mail-cite node was.
|
|
|
|
* XXX This method is expensive if aRange is too wide and may remove
|
|
|
|
* unexpected empty element, e.g., it was created by JS, but we haven't
|
|
|
|
* touched it. Cannot we remove this method and make guarantee that
|
|
|
|
* empty nodes won't be created?
|
|
|
|
*
|
|
|
|
* @param aRange Must be positioned.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveEmptyNodesIn(nsRange& aRange);
|
2019-09-10 07:46:55 +03:00
|
|
|
|
2019-09-11 04:07:27 +03:00
|
|
|
/**
|
|
|
|
* SetSelectionInterlinePosition() may set interline position if caret is
|
|
|
|
* positioned around `<br>` or block boundary. Don't call this when
|
|
|
|
* `Selection` is not collapsed.
|
|
|
|
*/
|
|
|
|
void SetSelectionInterlinePosition();
|
|
|
|
|
2019-09-11 12:44:39 +03:00
|
|
|
/**
|
|
|
|
* EnsureSelectionInBlockElement() may move caret into aElement or its
|
|
|
|
* parent block if caret is outside of them. Don't call this when
|
|
|
|
* `Selection` is not collapsed.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-11 12:44:39 +03:00
|
|
|
EnsureCaretInBlockElement(dom::Element& aElement);
|
|
|
|
|
2019-09-11 13:39:38 +03:00
|
|
|
/**
|
2019-09-18 11:40:08 +03:00
|
|
|
* Called by `HTMLEditor::OnEndHandlingTopLevelEditSubAction()`. This may
|
|
|
|
* adjust Selection, remove unnecessary empty nodes, create `<br>` elements
|
|
|
|
* if needed, etc.
|
2019-09-11 13:39:38 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-11 13:39:38 +03:00
|
|
|
OnEndHandlingTopLevelEditSubActionInternal();
|
|
|
|
|
2019-09-12 07:07:30 +03:00
|
|
|
/**
|
|
|
|
* MoveSelectedContentsToDivElementToMakeItAbsolutePosition() looks for
|
|
|
|
* a `<div>` element in selection first. If not, creates new `<div>`
|
|
|
|
* element. Then, move all selected contents into the target `<div>`
|
|
|
|
* element.
|
|
|
|
* Note that this creates AutoSelectionRestorer. Therefore, callers need
|
|
|
|
* to check whether we have been destroyed even when this returns NS_OK.
|
|
|
|
*
|
|
|
|
* @param aTargetElement Returns target `<div>` element which should be
|
|
|
|
* changed to absolute positioned.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-12 07:07:30 +03:00
|
|
|
MoveSelectedContentsToDivElementToMakeItAbsolutePosition(
|
|
|
|
RefPtr<Element>* aTargetElement);
|
|
|
|
|
2019-09-12 08:45:13 +03:00
|
|
|
/**
|
|
|
|
* SetSelectionToAbsoluteAsSubAction() move selected contents to first
|
|
|
|
* selected `<div>` element or newly created `<div>` element and make
|
|
|
|
* the `<div>` element positioned absolutely.
|
|
|
|
* mNewBlockElement of TopLevelEditSubActionData will be set to the `<div>`
|
|
|
|
* element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-12 08:45:13 +03:00
|
|
|
SetSelectionToAbsoluteAsSubAction();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetSelectionToStaticAsSubAction() sets the `position` property of a
|
|
|
|
* selection parent's block whose `position` is `absolute` to `static`.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-12 08:45:13 +03:00
|
|
|
SetSelectionToStaticAsSubAction();
|
|
|
|
|
2019-09-12 09:20:49 +03:00
|
|
|
/**
|
|
|
|
* AddZIndexAsSubAction() adds aChange to `z-index` of nearest parent
|
|
|
|
* absolute-positioned element from current selection.
|
|
|
|
*
|
|
|
|
* @param aChange Amount to change `z-index`.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-09-12 09:20:49 +03:00
|
|
|
AddZIndexAsSubAction(int32_t aChange);
|
|
|
|
|
2019-09-17 10:22:01 +03:00
|
|
|
/**
|
|
|
|
* OnDocumentModified() is called when editor content is changed.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult OnDocumentModified();
|
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
protected: // Called by helper classes.
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void OnStartToHandleTopLevelEditSubAction(
|
2019-09-18 06:01:28 +03:00
|
|
|
EditSubAction aTopLevelEditSubAction,
|
|
|
|
nsIEditor::EDirection aDirectionOfTopLevelEditSubAction,
|
2021-06-18 02:25:55 +03:00
|
|
|
ErrorResult& aRv) final;
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult OnEndHandlingTopLevelEditSubAction() final;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
protected: // Shouldn't be used by friend classes
|
|
|
|
virtual ~HTMLEditor();
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
template <typename PT, typename CT>
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MOZ_NEVER_INLINE_DEBUG nsresult
|
2020-09-01 05:04:02 +03:00
|
|
|
CollapseSelectionTo(const EditorDOMPointBase<PT, CT>& aPoint) const {
|
2020-03-18 05:02:17 +03:00
|
|
|
ErrorResult error;
|
|
|
|
CollapseSelectionTo(aPoint, error);
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PT, typename CT>
|
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_NEVER_INLINE_DEBUG void CollapseSelectionTo(
|
2020-09-01 05:04:02 +03:00
|
|
|
const EditorDOMPointBase<PT, CT>& aPoint, ErrorResult& aRv) const {
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_ASSERT(IsEditActionDataAvailable());
|
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
|
|
|
|
2021-04-08 04:31:54 +03:00
|
|
|
SelectionRef().CollapseInLimiter(aPoint, aRv);
|
2020-03-18 05:02:17 +03:00
|
|
|
if (NS_WARN_IF(Destroyed())) {
|
|
|
|
aRv = NS_ERROR_EDITOR_DESTROYED;
|
|
|
|
return;
|
|
|
|
}
|
2020-09-03 06:45:26 +03:00
|
|
|
NS_WARNING_ASSERTION(!aRv.Failed(),
|
|
|
|
"Selection::CollapseInLimiter() failed");
|
2020-03-18 05:02:17 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MOZ_NEVER_INLINE_DEBUG nsresult
|
2020-03-18 05:02:17 +03:00
|
|
|
CollapseSelectionToStartOf(nsINode& aNode) {
|
|
|
|
return CollapseSelectionTo(EditorRawDOMPoint(&aNode, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_NEVER_INLINE_DEBUG void CollapseSelectionToStartOf(
|
2020-09-01 05:04:02 +03:00
|
|
|
nsINode& aNode, ErrorResult& aRv) const {
|
2020-03-18 05:02:17 +03:00
|
|
|
CollapseSelectionTo(EditorRawDOMPoint(&aNode, 0), aRv);
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:21:37 +03:00
|
|
|
/**
|
|
|
|
* InitEditorContentAndSelection() may insert `<br>` elements and padding
|
|
|
|
* `<br>` elements if they are required for `<body>` or document element.
|
|
|
|
* And collapse selection at the end if there is no selection ranges.
|
|
|
|
* XXX I think that this should work with active editing host unless
|
|
|
|
* all over the document is ediable (i.e., in design mode or `<body>`
|
|
|
|
* or `<html>` has `contenteditable` attribute).
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InitEditorContentAndSelection();
|
2019-09-18 11:21:37 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SelectAllInternal() final;
|
2018-06-07 16:30:14 +03:00
|
|
|
|
2021-07-02 11:23:46 +03:00
|
|
|
/**
|
|
|
|
* Creates a range with just the supplied node and appends that to the
|
|
|
|
* selection.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
AppendContentToSelectionAsRange(nsIContent& aContent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When you are using AppendContentToSelectionAsRange(), call this first to
|
|
|
|
* start a new selection.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult ClearSelection();
|
|
|
|
|
2018-08-15 11:59:40 +03:00
|
|
|
/**
|
|
|
|
* SelectContentInternal() sets Selection to aContentToSelect to
|
|
|
|
* aContentToSelect + 1 in parent of aContentToSelect.
|
|
|
|
*
|
|
|
|
* @param aContentToSelect The content which should be selected.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SelectContentInternal(nsIContent& aContentToSelect);
|
2018-08-15 11:59:40 +03:00
|
|
|
|
2018-08-14 09:13:54 +03:00
|
|
|
/**
|
|
|
|
* CollapseSelectionAfter() collapses Selection after aElement.
|
|
|
|
* If aElement is an orphan node or not in editing host, returns error.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2020-04-01 04:32:11 +03:00
|
|
|
CollapseSelectionAfter(Element& aElement);
|
2018-08-14 09:13:54 +03:00
|
|
|
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
/**
|
2020-04-09 13:10:36 +03:00
|
|
|
* GetInclusiveAncestorByTagNameAtSelection() looks for an element node whose
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
* name matches aTagName from anchor node of Selection to <body> element.
|
|
|
|
*
|
|
|
|
* @param aTagName The tag name which you want to look for.
|
|
|
|
* Must not be nsGkAtoms::_empty.
|
|
|
|
* If nsGkAtoms::list, the result may be <ul>, <ol> or
|
|
|
|
* <dl> element.
|
|
|
|
* If nsGkAtoms::td, the result may be <td> or <th>.
|
|
|
|
* If nsGkAtoms::href, the result may be <a> element
|
|
|
|
* which has "href" attribute with non-empty value.
|
2018-08-17 17:50:56 +03:00
|
|
|
* If nsGkAtoms::anchor, the result may be <a> which
|
|
|
|
* has "name" attribute with non-empty value.
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
* @return If an element which matches aTagName, returns
|
|
|
|
* an Element. Otherwise, nullptr.
|
|
|
|
*/
|
2020-04-09 13:10:36 +03:00
|
|
|
Element* GetInclusiveAncestorByTagNameAtSelection(
|
|
|
|
const nsStaticAtom& aTagName) const;
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
|
|
|
|
/**
|
2020-04-09 13:10:36 +03:00
|
|
|
* GetInclusiveAncestorByTagNameInternal() looks for an element node whose
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
* name matches aTagName from aNode to <body> element.
|
|
|
|
*
|
|
|
|
* @param aTagName The tag name which you want to look for.
|
|
|
|
* Must not be nsGkAtoms::_empty.
|
|
|
|
* If nsGkAtoms::list, the result may be <ul>, <ol> or
|
|
|
|
* <dl> element.
|
|
|
|
* If nsGkAtoms::td, the result may be <td> or <th>.
|
|
|
|
* If nsGkAtoms::href, the result may be <a> element
|
|
|
|
* which has "href" attribute with non-empty value.
|
2018-08-17 17:50:56 +03:00
|
|
|
* If nsGkAtoms::anchor, the result may be <a> which
|
|
|
|
* has "name" attribute with non-empty value.
|
2020-04-09 13:10:36 +03:00
|
|
|
* @param aContent Start node to look for the element. This should
|
|
|
|
* not be an orphan node.
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
* @return If an element which matches aTagName, returns
|
|
|
|
* an Element. Otherwise, nullptr.
|
|
|
|
*/
|
2020-04-09 13:10:36 +03:00
|
|
|
Element* GetInclusiveAncestorByTagNameInternal(const nsStaticAtom& aTagName,
|
|
|
|
nsIContent& aContent) const;
|
Bug 1484092 - part 1: Make HTMLEditor::GetElementOrParentByTagName() use nsAtom for the tag name r=m_kato
HTMLElementOrParentByTagName() is the last user of IsLinkTag(const nsAString&)
and IsNamedAnchorTag(const nsAString&). For making their maintenance easier,
let's make GetElementOrParentByTagName() take const nsAtom& for tag name.
GetElementOrParentByTagName() has two functions, one is looking for an element
starting from a node. The other is, if the start node is nullptr, it retrieves
anchor node of Selection as start node. Therefore, this patch splits the
first part to GetElementOrParentByTagNameInternal(). Then, creates its
wrapper which retrieves anchor of Selection automatically,
GetElementOrParentByTagNameAtSelection().
Additionally, this patch makes all internal callers of HTMLEditor use
GetElementOrParentByTagNameInternal() or
GetElementOrParentByTagNameAtSelection() directly. Then, public method,
GetElementOrParentByTagName() is called only by outer classes.
Note that some callers use both GetElementOrParentByTagNameInternal()
and GetElementOrParentByTagNameAtSelection() since they don't check whether
setting node is nullptr. They may be bug of them. We should investigate
the API callers later.
Differential Revision: https://phabricator.services.mozilla.com/D3584
--HG--
extra : moz-landing-system : lando
2018-08-17 17:06:18 +03:00
|
|
|
|
2018-08-10 10:51:52 +03:00
|
|
|
/**
|
2018-11-05 14:38:10 +03:00
|
|
|
* GetSelectedElement() returns a "selected" element node. "selected" means:
|
|
|
|
* - there is only one selection range
|
|
|
|
* - the range starts from an element node or in an element
|
|
|
|
* - the range ends at immediately after same element
|
|
|
|
* - and the range does not include any other element nodes.
|
|
|
|
* Additionally, only when aTagName is nsGkAtoms::href, this thinks that an
|
|
|
|
* <a> element which has non-empty "href" attribute includes the range, the
|
|
|
|
* <a> element is selected.
|
2018-08-10 10:51:52 +03:00
|
|
|
*
|
2018-11-05 14:38:10 +03:00
|
|
|
* NOTE: This method is implementation of nsIHTMLEditor.getSelectedElement()
|
|
|
|
* and comm-central depends on this behavior. Therefore, if you need to use
|
|
|
|
* this method internally but you need to change, perhaps, you should create
|
|
|
|
* another method for avoiding breakage of comm-central apps.
|
|
|
|
*
|
|
|
|
* @param aTagName The atom of tag name in lower case. Set this to
|
2020-04-09 13:10:36 +03:00
|
|
|
* result of EditorUtils::GetTagNameAtom() if you have a
|
|
|
|
* tag name with nsString.
|
2018-11-05 14:38:10 +03:00
|
|
|
* If nullptr, this returns any element node or nullptr.
|
|
|
|
* If nsGkAtoms::href, this returns an <a> element which
|
|
|
|
* has non-empty "href" attribute or nullptr.
|
|
|
|
* If nsGkAtoms::anchor, this returns an <a> element which
|
|
|
|
* has non-empty "name" attribute or nullptr.
|
|
|
|
* Otherwise, returns an element node whose name is
|
|
|
|
* same as aTagName or nullptr.
|
|
|
|
* @param aRv Returns error code.
|
|
|
|
* @return A "selected" element.
|
2018-08-10 10:51:52 +03:00
|
|
|
*/
|
2018-10-30 13:01:38 +03:00
|
|
|
already_AddRefed<Element> GetSelectedElement(const nsAtom* aTagName,
|
2018-08-10 12:01:42 +03:00
|
|
|
ErrorResult& aRv);
|
2018-08-10 10:51:52 +03:00
|
|
|
|
2018-08-22 04:20:23 +03:00
|
|
|
/**
|
|
|
|
* GetFirstTableRowElement() returns the first <tr> element in the most
|
|
|
|
* nearest ancestor of aTableOrElementInTable or itself.
|
|
|
|
*
|
|
|
|
* @param aTableOrElementInTable <table> element or another element.
|
|
|
|
* If this is a <table> element, returns
|
|
|
|
* first <tr> element in it. Otherwise,
|
|
|
|
* returns first <tr> element in nearest
|
|
|
|
* ancestor <table> element.
|
|
|
|
* @param aRv Returns an error code. When
|
|
|
|
* aTableOrElementInTable is neither
|
|
|
|
* <table> nor in a <table> element,
|
|
|
|
* returns NS_ERROR_FAILURE.
|
|
|
|
* However, if <table> does not have
|
|
|
|
* <tr> element, returns NS_OK.
|
|
|
|
*/
|
|
|
|
Element* GetFirstTableRowElement(Element& aTableOrElementInTable,
|
|
|
|
ErrorResult& aRv) const;
|
|
|
|
|
2018-08-22 09:52:07 +03:00
|
|
|
/**
|
|
|
|
* GetNextTableRowElement() returns next <tr> element of aTableRowElement.
|
|
|
|
* This won't cross <table> element boundary but may cross table section
|
|
|
|
* elements like <tbody>.
|
|
|
|
*
|
|
|
|
* @param aTableRowElement A <tr> element.
|
|
|
|
* @param aRv Returns error. If given element is <tr> but
|
|
|
|
* there is no next <tr> element, this returns
|
|
|
|
* nullptr but does not return error.
|
|
|
|
*/
|
|
|
|
Element* GetNextTableRowElement(Element& aTableRowElement,
|
|
|
|
ErrorResult& aRv) const;
|
|
|
|
|
2018-10-12 16:40:25 +03:00
|
|
|
struct CellData;
|
2018-09-14 15:51:05 +03:00
|
|
|
|
2018-08-22 06:34:40 +03:00
|
|
|
/**
|
|
|
|
* CellIndexes store both row index and column index of a table cell.
|
|
|
|
*/
|
|
|
|
struct MOZ_STACK_CLASS CellIndexes final {
|
|
|
|
int32_t mRow;
|
|
|
|
int32_t mColumn;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor initializes mRowIndex and mColumnIndex with indexes of
|
|
|
|
* aCellElement.
|
|
|
|
*
|
|
|
|
* @param aCellElement An <td> or <th> element.
|
|
|
|
* @param aRv Returns error if layout information is not
|
|
|
|
* available or given element is not a table cell.
|
|
|
|
*/
|
2020-05-14 13:08:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT CellIndexes(Element& aCellElement, PresShell* aPresShell,
|
|
|
|
ErrorResult& aRv)
|
2018-08-22 06:34:40 +03:00
|
|
|
: mRow(-1), mColumn(-1) {
|
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
2020-05-14 13:08:32 +03:00
|
|
|
Update(aCellElement, aPresShell, aRv);
|
2018-08-22 06:34:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update mRowIndex and mColumnIndex with indexes of aCellElement.
|
|
|
|
*
|
|
|
|
* @param See above.
|
|
|
|
*/
|
2020-05-14 13:08:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void Update(Element& aCellElement, PresShell* aPresShell,
|
|
|
|
ErrorResult& aRv);
|
2018-08-22 06:34:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor initializes mRowIndex and mColumnIndex with indexes of
|
|
|
|
* cell element which contains anchor of Selection.
|
|
|
|
*
|
|
|
|
* @param aHTMLEditor The editor which creates the instance.
|
|
|
|
* @param aSelection The Selection for the editor.
|
|
|
|
* @param aRv Returns error if there is no cell element
|
|
|
|
* which contains anchor of Selection, or layout
|
|
|
|
* information is not available.
|
|
|
|
*/
|
2020-05-14 13:08:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT CellIndexes(HTMLEditor& aHTMLEditor,
|
|
|
|
Selection& aSelection, ErrorResult& aRv)
|
2018-08-22 06:34:40 +03:00
|
|
|
: mRow(-1), mColumn(-1) {
|
|
|
|
Update(aHTMLEditor, aSelection, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update mRowIndex and mColumnIndex with indexes of cell element which
|
|
|
|
* contains anchor of Selection.
|
|
|
|
*
|
|
|
|
* @param See above.
|
|
|
|
*/
|
2020-05-14 13:08:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void Update(HTMLEditor& aHTMLEditor,
|
|
|
|
Selection& aSelection, ErrorResult& aRv);
|
2018-09-14 15:51:05 +03:00
|
|
|
|
2018-10-12 16:40:25 +03:00
|
|
|
bool operator==(const CellIndexes& aOther) const {
|
|
|
|
return mRow == aOther.mRow && mColumn == aOther.mColumn;
|
|
|
|
}
|
|
|
|
bool operator!=(const CellIndexes& aOther) const {
|
|
|
|
return mRow != aOther.mRow || mColumn != aOther.mColumn;
|
|
|
|
}
|
|
|
|
|
2018-09-14 15:51:05 +03:00
|
|
|
private:
|
|
|
|
CellIndexes() : mRow(-1), mColumn(-1) {}
|
|
|
|
|
2018-10-12 16:40:25 +03:00
|
|
|
friend struct CellData;
|
2018-09-14 15:51:05 +03:00
|
|
|
};
|
|
|
|
|
2018-10-12 16:40:25 +03:00
|
|
|
struct MOZ_STACK_CLASS CellData final {
|
2021-07-02 11:23:46 +03:00
|
|
|
MOZ_KNOWN_LIVE RefPtr<Element> mElement;
|
2018-10-12 16:40:25 +03:00
|
|
|
// Current indexes which this is initialized with.
|
|
|
|
CellIndexes mCurrent;
|
|
|
|
// First column/row indexes of the cell. When current position is spanned
|
|
|
|
// from other column/row, this value becomes different from mCurrent.
|
|
|
|
CellIndexes mFirst;
|
|
|
|
// Computed rowspan/colspan values which are specified to the cell.
|
|
|
|
// Note that if the cell has larger rowspan/colspan value than actual
|
|
|
|
// table size, these values are the larger values.
|
|
|
|
int32_t mRowSpan;
|
|
|
|
int32_t mColSpan;
|
|
|
|
// Effective rowspan/colspan value at the index. For example, if first
|
|
|
|
// cell element in first row has rowspan="3", then, if this is initialized
|
|
|
|
// with 0-0 indexes, effective rowspan is 3. However, if this is
|
|
|
|
// initialized with 1-0 indexes, effective rowspan is 2.
|
|
|
|
int32_t mEffectiveRowSpan;
|
|
|
|
int32_t mEffectiveColSpan;
|
|
|
|
// mIsSelected is set to true if mElement itself or its parent <tr> or
|
|
|
|
// <table> is selected. Otherwise, e.g., the cell just contains selection
|
|
|
|
// range, this is set to false.
|
|
|
|
bool mIsSelected;
|
|
|
|
|
2018-10-16 04:10:44 +03:00
|
|
|
CellData()
|
|
|
|
: mRowSpan(-1),
|
|
|
|
mColSpan(-1),
|
|
|
|
mEffectiveRowSpan(-1),
|
|
|
|
mEffectiveColSpan(-1),
|
|
|
|
mIsSelected(false) {}
|
|
|
|
|
2018-10-12 16:40:25 +03:00
|
|
|
/**
|
|
|
|
* Those constructors initializes the members with a <table> element and
|
|
|
|
* both row and column index to specify a cell element.
|
|
|
|
*/
|
|
|
|
CellData(HTMLEditor& aHTMLEditor, Element& aTableElement, int32_t aRowIndex,
|
|
|
|
int32_t aColumnIndex, ErrorResult& aRv) {
|
|
|
|
Update(aHTMLEditor, aTableElement, aRowIndex, aColumnIndex, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
CellData(HTMLEditor& aHTMLEditor, Element& aTableElement,
|
|
|
|
const CellIndexes& aIndexes, ErrorResult& aRv) {
|
|
|
|
Update(aHTMLEditor, aTableElement, aIndexes, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Those Update() methods updates the members with a <table> element and
|
|
|
|
* both row and column index to specify a cell element.
|
|
|
|
*/
|
|
|
|
void Update(HTMLEditor& aHTMLEditor, Element& aTableElement,
|
|
|
|
int32_t aRowIndex, int32_t aColumnIndex, ErrorResult& aRv) {
|
|
|
|
mCurrent.mRow = aRowIndex;
|
|
|
|
mCurrent.mColumn = aColumnIndex;
|
|
|
|
Update(aHTMLEditor, aTableElement, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update(HTMLEditor& aHTMLEditor, Element& aTableElement,
|
|
|
|
const CellIndexes& aIndexes, ErrorResult& aRv) {
|
|
|
|
mCurrent = aIndexes;
|
|
|
|
Update(aHTMLEditor, aTableElement, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update(HTMLEditor& aHTMLEditor, Element& aTableElement,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FailedOrNotFound() returns true if this failed to initialize/update
|
|
|
|
* or succeeded but found no cell element.
|
|
|
|
*/
|
|
|
|
bool FailedOrNotFound() const { return !mElement; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsSpannedFromOtherRowOrColumn(), IsSpannedFromOtherColumn and
|
|
|
|
* IsSpannedFromOtherRow() return true if there is no cell element
|
|
|
|
* at the index because of spanning from other row and/or column.
|
|
|
|
*/
|
|
|
|
bool IsSpannedFromOtherRowOrColumn() const {
|
|
|
|
return mElement && mCurrent != mFirst;
|
|
|
|
}
|
|
|
|
bool IsSpannedFromOtherColumn() const {
|
|
|
|
return mElement && mCurrent.mColumn != mFirst.mColumn;
|
|
|
|
}
|
|
|
|
bool IsSpannedFromOtherRow() const {
|
|
|
|
return mElement && mCurrent.mRow != mFirst.mRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NextColumnIndex() and NextRowIndex() return column/row index of
|
|
|
|
* next cell. Note that this does not check whether there is next
|
|
|
|
* cell or not actually.
|
|
|
|
*/
|
|
|
|
int32_t NextColumnIndex() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mCurrent.mColumn + mEffectiveColSpan;
|
|
|
|
}
|
|
|
|
int32_t NextRowIndex() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mCurrent.mRow + mEffectiveRowSpan;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LastColumnIndex() and LastRowIndex() return column/row index of
|
|
|
|
* column/row which is spanned by the cell.
|
|
|
|
*/
|
|
|
|
int32_t LastColumnIndex() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return NextColumnIndex() - 1;
|
|
|
|
}
|
|
|
|
int32_t LastRowIndex() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return NextRowIndex() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NumberOfPrecedingColmuns() and NumberOfPrecedingRows() return number of
|
|
|
|
* preceding columns/rows if current index is spanned from other column/row.
|
|
|
|
* Otherwise, i.e., current point is not spanned form other column/row,
|
|
|
|
* returns 0.
|
|
|
|
*/
|
|
|
|
int32_t NumberOfPrecedingColmuns() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mCurrent.mColumn - mFirst.mColumn;
|
|
|
|
}
|
|
|
|
int32_t NumberOfPrecedingRows() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mCurrent.mRow - mFirst.mRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NumberOfFollowingColumns() and NumberOfFollowingRows() return
|
|
|
|
* number of remaining columns/rows if the cell spans to other
|
|
|
|
* column/row.
|
|
|
|
*/
|
|
|
|
int32_t NumberOfFollowingColumns() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mEffectiveColSpan - 1;
|
|
|
|
}
|
|
|
|
int32_t NumberOfFollowingRows() const {
|
|
|
|
if (NS_WARN_IF(FailedOrNotFound())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mEffectiveRowSpan - 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-23 10:32:16 +03:00
|
|
|
/**
|
|
|
|
* TableSize stores and computes number of rows and columns of a <table>
|
|
|
|
* element.
|
|
|
|
*/
|
|
|
|
struct MOZ_STACK_CLASS TableSize final {
|
|
|
|
int32_t mRowCount;
|
|
|
|
int32_t mColumnCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param aHTMLEditor The editor which creates the instance.
|
|
|
|
* @param aTableOrElementInTable If a <table> element, computes number
|
|
|
|
* of rows and columns of it.
|
|
|
|
* If another element in a <table> element,
|
|
|
|
* computes number of rows and columns
|
|
|
|
* of nearest ancestor <table> element.
|
|
|
|
* Otherwise, i.e., non-<table> element
|
|
|
|
* not in <table>, returns error.
|
|
|
|
* @param aRv Returns error if the element is not
|
|
|
|
* in <table> or layout information is
|
|
|
|
* not available.
|
|
|
|
*/
|
|
|
|
TableSize(HTMLEditor& aHTMLEditor, Element& aTableOrElementInTable,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
: mRowCount(-1), mColumnCount(-1) {
|
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
|
|
|
Update(aHTMLEditor, aTableOrElementInTable, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update mRowCount and mColumnCount for aTableOrElementInTable.
|
|
|
|
* See above for the detail.
|
|
|
|
*/
|
|
|
|
void Update(HTMLEditor& aHTMLEditor, Element& aTableOrElementInTable,
|
|
|
|
ErrorResult& aRv);
|
2018-09-19 12:00:06 +03:00
|
|
|
|
|
|
|
bool IsEmpty() const { return !mRowCount || !mColumnCount; }
|
2018-08-23 10:32:16 +03:00
|
|
|
};
|
|
|
|
|
2018-08-23 09:39:30 +03:00
|
|
|
/**
|
|
|
|
* GetTableCellElementAt() returns a <td> or <th> element of aTableElement
|
|
|
|
* if there is a cell at the indexes.
|
|
|
|
*
|
|
|
|
* @param aTableElement Must be a <table> element.
|
|
|
|
* @param aCellIndexes Indexes of cell which you want.
|
|
|
|
* If rowspan and/or colspan is specified 2 or
|
|
|
|
* larger, any indexes are allowed to retrieve
|
|
|
|
* the cell in the area.
|
|
|
|
* @return The cell element if there is in the <table>.
|
|
|
|
* Returns nullptr without error if the indexes
|
|
|
|
* are out of bounds.
|
|
|
|
*/
|
|
|
|
Element* GetTableCellElementAt(Element& aTableElement,
|
|
|
|
const CellIndexes& aCellIndexes) const {
|
|
|
|
return GetTableCellElementAt(aTableElement, aCellIndexes.mRow,
|
|
|
|
aCellIndexes.mColumn);
|
|
|
|
}
|
|
|
|
Element* GetTableCellElementAt(Element& aTableElement, int32_t aRowIndex,
|
|
|
|
int32_t aColumnIndex) const;
|
|
|
|
|
2018-09-14 15:56:22 +03:00
|
|
|
/**
|
|
|
|
* GetSelectedOrParentTableElement() returns <td>, <th>, <tr> or <table>
|
|
|
|
* element:
|
|
|
|
* #1 if the first selection range selects a cell, returns it.
|
|
|
|
* #2 if the first selection range does not select a cell and
|
|
|
|
* the selection anchor refers a <table>, returns it.
|
|
|
|
* #3 if the first selection range does not select a cell and
|
|
|
|
* the selection anchor refers a <tr>, returns it.
|
|
|
|
* #4 if the first selection range does not select a cell and
|
|
|
|
* the selection anchor refers a <td>, returns it.
|
|
|
|
* #5 otherwise, nearest ancestor <td> or <th> element of the
|
|
|
|
* selection anchor if there is.
|
|
|
|
* In #1 and #4, *aIsCellSelected will be set to true (i.e,, when
|
|
|
|
* a selection range selects a cell element).
|
|
|
|
*/
|
2018-10-30 13:01:38 +03:00
|
|
|
already_AddRefed<Element> GetSelectedOrParentTableElement(
|
2018-09-14 15:56:22 +03:00
|
|
|
ErrorResult& aRv, bool* aIsCellSelected = nullptr) const;
|
|
|
|
|
2018-08-13 07:15:34 +03:00
|
|
|
/**
|
|
|
|
* PasteInternal() pasts text with replacing selected content.
|
|
|
|
* This tries to dispatch ePaste event first. If its defaultPrevent() is
|
|
|
|
* called, this does nothing but returns NS_OK.
|
|
|
|
*
|
2018-10-10 15:05:39 +03:00
|
|
|
* @param aClipboardType nsIClipboard::kGlobalClipboard or
|
|
|
|
* nsIClipboard::kSelectionClipboard.
|
2018-08-13 07:15:34 +03:00
|
|
|
*/
|
Bug 970802 - part 5: Make `AutoEditActionDataSetter` created method dispatch "beforeinput" event r=smaug,m_kato
`AutoEditActionDataSetter` is created in the stack when editor's public method
is called and that guarantees lifetime of global objects in editor such as
editor itself, selection controller, etc.
The dispatcher of `beforeinput` event returns `NS_ERROR_EDITOR_ACTION_CANCELED`
if an event is actually dispatched but canceled. The reason why it's an error
is, editor code must stop handling anything when any methods return error.
So, returning an error code is reasonable in editor module. But when it's
filtered by `EditorBase::ToGenericNSResult()` at return statement of public
methods, it's converted to `NS_SUCCESS_DOM_NO_OPERATION`. This avoids throwing
new exception, but editor class users in C++ can distinguish whether each edit
action is canceled or handled. The reason why we should not throw new
exception from XPCOM API is, without taking care of each caller may break some
our UI (especially for avoiding to break comm-central). Therefore, this patch
does not make XPCOM methods return error code when `beforeinput` event is
canceled.
In most cases, immediately after creating `AutoEditActionDataSetter` is good
timing to dispatch `beforeinput` event since editor has not touched the DOM
yet. If `beforeinput` requires `data` or `dataTransfer`, methods need to
dispatch `beforeinput` event after that. Alhtough this is not a good thing
from point of view of consistency of the code. However, I have no better
idea.
Note 1: Our implementation does NOT conform to the spec about event order
between `keypress` and `beforeinput` (dispatching `beforeinput` event after
`keypress` event). However, we follow all other browsers' behavior so that it
must be safe and the spec should be updated for backward compatibility.
Spec issue: https://github.com/w3c/uievents/issues/220
Note 2: Our implementation does NOT conform to the spec about event order
between `compositionupdate` and `beforeinput`. Our behavior is same as
Safari, but different from Chrome. This might cause web-compat issues.
However, our behavior does make sense from point of view of consistency of
event spec. Additionally, at both `compositionupdate` and `beforeinput`,
composition string in editor has not been modified yet. Therefore, this
may not cause web-compat issues (and I hope so).
Spec issue: https://github.com/w3c/input-events/issues/49
Note that this patch makes editor detect bugs that `beforeinput` event hasn't
been handled yet when it dispatches `input` event or modifying `data` and
`dataTransfer` value are modified after dispatching `beforeinput` event with
`MOZ_ASSERT`s.
Differential Revision: https://phabricator.services.mozilla.com/D58127
--HG--
extra : moz-landing-system : lando
2020-01-14 10:18:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult PasteInternal(int32_t aClipboardType);
|
2018-08-13 07:15:34 +03:00
|
|
|
|
2021-05-26 05:00:45 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-17 05:47:26 +03:00
|
|
|
InsertWithQuotationsAsSubAction(const nsAString& aQuotedText) final;
|
|
|
|
|
2018-10-25 07:49:13 +03:00
|
|
|
/**
|
|
|
|
* InsertAsCitedQuotationInternal() inserts a <blockquote> element whose
|
|
|
|
* cite attribute is aCitation and whose content is aQuotedText.
|
2021-06-18 23:35:48 +03:00
|
|
|
* Note that this shouldn't be called when IsInPlaintextMode() is true.
|
2018-10-25 07:49:13 +03:00
|
|
|
*
|
|
|
|
* @param aQuotedText HTML source if aInsertHTML is true. Otherwise,
|
|
|
|
* plain text. This is inserted into new <blockquote>
|
|
|
|
* element.
|
|
|
|
* @param aCitation cite attribute value of new <blockquote> element.
|
|
|
|
* @param aInsertHTML true if aQuotedText should be treated as HTML
|
|
|
|
* source.
|
|
|
|
* false if aQuotedText should be treated as plain
|
|
|
|
* text.
|
|
|
|
* @param aNodeInserted [OUT] The new <blockquote> element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertAsCitedQuotationInternal(
|
2019-09-17 06:13:09 +03:00
|
|
|
const nsAString& aQuotedText, const nsAString& aCitation,
|
|
|
|
bool aInsertHTML, nsINode** aNodeInserted);
|
2018-10-25 07:49:13 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* InsertNodeIntoProperAncestorWithTransaction() attempts to insert aNode
|
|
|
|
* into the document, at aPointToInsert. Checks with strict dtd to see if
|
|
|
|
* containment is allowed. If not allowed, will attempt to find a parent
|
|
|
|
* in the parent hierarchy of aPointToInsert.GetContainer() that will accept
|
|
|
|
* aNode as a child. If such a parent is found, will split the document
|
|
|
|
* tree from aPointToInsert up to parent, and then insert aNode.
|
|
|
|
* aPointToInsert is then adjusted to point to the actual location that
|
|
|
|
* aNode was inserted at. aSplitAtEdges specifies if the splitting process
|
|
|
|
* is allowed to result in empty nodes.
|
2016-07-09 05:42:33 +03:00
|
|
|
*
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* @param aNode Node to insert.
|
|
|
|
* @param aPointToInsert Insertion point.
|
|
|
|
* @param aSplitAtEdges Splitting can result in empty nodes?
|
|
|
|
* @return Returns inserted point if succeeded.
|
|
|
|
* Otherwise, the result is not set.
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2019-03-30 14:55:29 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT EditorDOMPoint InsertNodeIntoProperAncestorWithTransaction(
|
2019-05-08 12:40:17 +03:00
|
|
|
nsIContent& aNode, const EditorDOMPoint& aPointToInsert,
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
SplitAtEdges aSplitAtEdges);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
2020-03-18 05:02:17 +03:00
|
|
|
* InsertBRElementAtSelectionWithTransaction() inserts a new <br> element at
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* selection. If there is non-collapsed selection ranges, the selected
|
|
|
|
* ranges is deleted first.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertBRElementAtSelectionWithTransaction();
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-08-09 15:24:53 +03:00
|
|
|
/**
|
|
|
|
* InsertTextWithQuotationsInternal() replaces selection with new content.
|
|
|
|
* First, this method splits aStringToInsert to multiple chunks which start
|
|
|
|
* with non-linebreaker except first chunk and end with a linebreaker except
|
|
|
|
* last chunk. Then, each chunk starting with ">" is inserted after wrapping
|
|
|
|
* with <span _moz_quote="true">, and each chunk not starting with ">" is
|
|
|
|
* inserted as normal text.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
InsertTextWithQuotationsInternal(const nsAString& aStringToInsert);
|
2018-08-09 15:24:53 +03:00
|
|
|
|
2020-04-30 09:35:38 +03:00
|
|
|
/**
|
|
|
|
* ReplaceContainerWithTransactionInternal() is implementation of
|
|
|
|
* ReplaceContainerWithTransaction() and
|
|
|
|
* ReplaceContainerAndCloneAttributesWithTransaction().
|
|
|
|
*
|
|
|
|
* @param aOldContainer The element which will be replaced with new
|
|
|
|
* element.
|
|
|
|
* @param aTagName The name of new element node.
|
|
|
|
* @param aAttribute Attribute name which will be set to the new
|
|
|
|
* element. This will be ignored if
|
|
|
|
* aCloneAllAttributes is set to true.
|
|
|
|
* @param aAttributeValue Attribute value which will be set to
|
|
|
|
* aAttribute.
|
|
|
|
* @param aCloneAllAttributes If true, all attributes of aOldContainer will
|
|
|
|
* be copied to the new element.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element>
|
|
|
|
ReplaceContainerWithTransactionInternal(Element& aElement, nsAtom& aTagName,
|
|
|
|
nsAtom& aAttribute,
|
|
|
|
const nsAString& aAttributeValue,
|
|
|
|
bool aCloneAllAttributes);
|
|
|
|
|
2020-04-30 09:36:53 +03:00
|
|
|
/**
|
|
|
|
* InsertContainerWithTransactionInternal() creates new element whose name is
|
|
|
|
* aTagName, moves aContent into the new element, then, inserts the new
|
|
|
|
* element into where aContent was. If aAttribute is not nsGkAtoms::_empty,
|
|
|
|
* aAttribute of the new element will be set to aAttributeValue.
|
|
|
|
*
|
|
|
|
* @param aContent The content which will be wrapped with new
|
|
|
|
* element.
|
|
|
|
* @param aTagName Element name of new element which will wrap
|
|
|
|
* aContent and be inserted into where aContent
|
|
|
|
* was.
|
|
|
|
* @param aAttribute Attribute which should be set to the new
|
|
|
|
* element. If this is nsGkAtoms::_empty,
|
|
|
|
* this does not set any attributes to the new
|
|
|
|
* element.
|
|
|
|
* @param aAttributeValue Value to be set to aAttribute.
|
|
|
|
* @return The new element.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element>
|
|
|
|
InsertContainerWithTransactionInternal(nsIContent& aContent, nsAtom& aTagName,
|
|
|
|
nsAtom& aAttribute,
|
|
|
|
const nsAString& aAttributeValue);
|
|
|
|
|
2020-04-30 12:54:55 +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.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT 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).
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult DeleteSelectionAndPrepareToCreateNode();
|
|
|
|
|
2020-04-30 13:49:04 +03:00
|
|
|
/**
|
|
|
|
* PrepareToInsertBRElement() returns a point where new <br> element should
|
|
|
|
* be inserted. If aPointToInsert points middle of a text node, this method
|
|
|
|
* splits the text node and returns the point before right node.
|
|
|
|
*
|
|
|
|
* @param aPointToInsert Candidate point to insert new <br> element.
|
|
|
|
* @return Computed point to insert new <br> element.
|
2021-04-28 06:33:26 +03:00
|
|
|
* If something failed, this return error.
|
2020-04-30 13:49:04 +03:00
|
|
|
*/
|
2021-04-28 06:33:26 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT Result<EditorDOMPoint, nsresult> PrepareToInsertBRElement(
|
|
|
|
const EditorDOMPoint& aPointToInsert);
|
2020-04-30 13:49:04 +03:00
|
|
|
|
2018-08-14 11:30:09 +03:00
|
|
|
/**
|
2019-09-08 08:12:43 +03:00
|
|
|
* IndentAsSubAction() indents the content around Selection.
|
2018-08-14 11:30:09 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult IndentAsSubAction();
|
2019-09-08 08:12:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OutdentAsSubAction() outdents the content around Selection.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult OutdentAsSubAction();
|
2018-08-14 11:30:09 +03:00
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult LoadHTML(const nsAString& aInputString);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2021-05-26 10:45:02 +03:00
|
|
|
/**
|
|
|
|
* UpdateMetaCharsetWithTransaction() scans all <meta> elements in the
|
|
|
|
* document and if and only if there is a <meta> element having `httpEquiv`
|
|
|
|
* attribute and whose value includes `content-type`, updates its `content`
|
|
|
|
* attribute value to aCharacterSet.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT bool UpdateMetaCharsetWithTransaction(
|
|
|
|
Document& aDocument, const nsACString& aCharacterSet);
|
|
|
|
|
2019-09-12 12:13:00 +03:00
|
|
|
/**
|
|
|
|
* SetInlinePropertyInternal() stores new style with `mTypeInState` if
|
|
|
|
* `Selection` is collapsed. Otherwise, applying the style at all selection
|
|
|
|
* ranges.
|
|
|
|
*
|
|
|
|
* @param aProperty One of the presentation tag names which we
|
|
|
|
* support in style editor.
|
|
|
|
* @param aAttribute For some aProperty values, needs to be set to
|
|
|
|
* its attribute name. Otherwise, nullptr.
|
|
|
|
* @param aAttributeValue The value of aAttribute.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetInlinePropertyInternal(
|
2019-09-12 12:13:00 +03:00
|
|
|
nsAtom& aProperty, nsAtom* aAttribute, const nsAString& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RemoveInlinePropertyInternal() removes specified style from `mTypeInState`
|
|
|
|
* if `Selection` is collapsed. Otherwise, removing the style.
|
|
|
|
*
|
2020-04-09 13:10:34 +03:00
|
|
|
* @param aHTMLProperty nullptr if you want to remove all inline styles.
|
2019-09-12 12:13:00 +03:00
|
|
|
* Otherwise, one of the presentation tag names
|
|
|
|
* which we support in style editor.
|
2020-04-09 13:10:34 +03:00
|
|
|
* @param aAttribute For some aHTMLProperty values, need to be set to
|
2019-09-12 12:13:00 +03:00
|
|
|
* its attribute name. Otherwise, nullptr.
|
2020-01-14 10:14:55 +03:00
|
|
|
* @param aRemoveRelatedElements If Yes, this method removes different
|
|
|
|
* name's elements in the block if
|
2020-04-09 13:10:34 +03:00
|
|
|
* necessary. For example, if
|
|
|
|
* aHTMLProperty is nsGkAtoms::b,
|
|
|
|
* `<strong>` elements are also removed.
|
2019-09-12 12:13:00 +03:00
|
|
|
*/
|
2020-01-14 10:14:55 +03:00
|
|
|
enum class RemoveRelatedElements { Yes, No };
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveInlinePropertyInternal(
|
|
|
|
nsStaticAtom* aHTMLProperty, nsStaticAtom* aAttribute,
|
|
|
|
RemoveRelatedElements aRemoveRelatedElements);
|
2018-08-13 08:16:10 +03:00
|
|
|
|
2018-07-19 15:31:19 +03:00
|
|
|
/**
|
|
|
|
* ReplaceHeadContentsWithSourceWithTransaction() replaces all children of
|
|
|
|
* <head> element with given source code. This is undoable.
|
|
|
|
*
|
|
|
|
* @param aSourceToInsert HTML source fragment to replace the children
|
|
|
|
* of <head> element.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult ReplaceHeadContentsWithSourceWithTransaction(
|
2018-07-19 15:31:19 +03:00
|
|
|
const nsAString& aSourceToInsert);
|
|
|
|
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult GetCSSBackgroundColorState(
|
|
|
|
bool* aMixed, nsAString& aOutColor, bool aBlockLevel);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
nsresult GetHTMLBackgroundColorState(bool* aMixed, nsAString& outColor);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
nsresult GetLastCellInRow(nsINode* aRowNode, nsINode** aCellNode);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* This sets background on the appropriate container element (table, cell,)
|
2021-06-11 06:01:09 +03:00
|
|
|
* or calls to set the page background.
|
2017-12-05 09:36:49 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-12 12:13:00 +03:00
|
|
|
SetCSSBackgroundColorWithTransaction(const nsAString& aColor);
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SetHTMLBackgroundColorWithTransaction(const nsAString& aColor);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void InitializeSelectionAncestorLimit(
|
|
|
|
nsIContent& aAncestorLimit) const final;
|
2018-04-16 14:33:27 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Make the given selection span the entire document.
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2021-06-18 02:25:55 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SelectEntireDocument() final;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Use this to assure that selection is set after attribute nodes when
|
|
|
|
* trying to collapse selection at begining of a block node
|
|
|
|
* e.g., when setting at beginning of a table cell
|
|
|
|
* This will stop at a table, however, since we don't want to
|
|
|
|
* "drill down" into nested tables.
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseSelectionToDeepestNonTableFirstChild(
|
|
|
|
nsINode* aNode);
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* MaybeCollapseSelectionAtFirstEditableNode() may collapse selection at
|
|
|
|
* proper position to staring to edit. If there is a non-editable node
|
|
|
|
* before any editable text nodes or inline elements which can have text
|
|
|
|
* nodes as their children, collapse selection at start of the editing
|
|
|
|
* host. If there is an editable text node which is not collapsed, collapses
|
|
|
|
* selection at the start of the text node. If there is an editable inline
|
|
|
|
* element which cannot have text nodes as its child, collapses selection at
|
|
|
|
* before the element node. Otherwise, collapses selection at start of the
|
|
|
|
* editing host.
|
|
|
|
*
|
|
|
|
* @param aIgnoreIfSelectionInEditingHost
|
|
|
|
* This method does nothing if selection is in the
|
|
|
|
* editing host except if it's collapsed at start of
|
|
|
|
* the editing host.
|
|
|
|
* Note that if selection ranges were outside of
|
|
|
|
* current selection limiter, selection was collapsed
|
|
|
|
* at the start of the editing host therefore, if
|
|
|
|
* you call this with setting this to true, you can
|
|
|
|
* keep selection ranges if user has already been
|
|
|
|
* changed.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2020-03-18 05:02:17 +03:00
|
|
|
MaybeCollapseSelectionAtFirstEditableNode(
|
2020-09-01 05:04:02 +03:00
|
|
|
bool aIgnoreIfSelectionInEditingHost) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-18 07:34:21 +03:00
|
|
|
class BlobReader final {
|
2018-11-05 05:12:27 +03:00
|
|
|
typedef EditorBase::AutoEditActionDataSetter AutoEditActionDataSetter;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
public:
|
|
|
|
BlobReader(dom::BlobImpl* aBlob, HTMLEditor* aHTMLEditor, bool aIsSafe,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aSourceDoc, const EditorDOMPoint& aPointToInsert,
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
bool aDoDeleteSelection);
|
|
|
|
|
2018-09-18 07:34:21 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BlobReader)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(BlobReader)
|
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult OnResult(const nsACString& aResult);
|
2018-09-18 07:34:21 +03:00
|
|
|
nsresult OnError(const nsAString& aErrorName);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
private:
|
2020-03-04 12:10:03 +03:00
|
|
|
~BlobReader() = default;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
RefPtr<dom::BlobImpl> mBlob;
|
|
|
|
RefPtr<HTMLEditor> mHTMLEditor;
|
2020-01-20 04:41:55 +03:00
|
|
|
RefPtr<dom::DataTransfer> mDataTransfer;
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> mSourceDoc;
|
2018-11-09 11:40:57 +03:00
|
|
|
EditorDOMPoint mPointToInsert;
|
2018-11-05 05:12:27 +03:00
|
|
|
EditAction mEditAction;
|
|
|
|
bool mIsSafe;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
bool mDoDeleteSelection;
|
2020-01-20 04:41:55 +03:00
|
|
|
bool mNeedsToDispatchBeforeInputEvent;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
};
|
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
void CreateEventListeners() final;
|
|
|
|
nsresult InstallEventListeners() final;
|
|
|
|
void RemoveEventListeners() final;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2020-04-13 04:43:41 +03:00
|
|
|
bool ShouldReplaceRootElement() const;
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void NotifyRootChanged();
|
2020-04-13 04:43:41 +03:00
|
|
|
Element* GetBodyElement() const;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the focused node of this editor.
|
|
|
|
* @return If the editor has focus, this returns the focused node.
|
|
|
|
* Otherwise, returns null.
|
|
|
|
*/
|
2020-04-13 04:43:41 +03:00
|
|
|
nsINode* GetFocusedNode() const;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2021-06-18 02:25:55 +03:00
|
|
|
already_AddRefed<Element> GetInputEventTargetElement() const final;
|
2018-06-06 07:30:44 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
|
|
|
* Return TRUE if aElement is a table-related elemet and caret was set.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT bool SetCaretInTableCell(dom::Element* aElement);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2019-11-07 05:59:51 +03:00
|
|
|
/**
|
|
|
|
* HandleTabKeyPressInTable() handles "Tab" key press in table if selection
|
|
|
|
* is in a `<table>` element.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
2019-11-07 05:59:51 +03:00
|
|
|
HandleTabKeyPressInTable(WidgetKeyboardEvent* aKeyboardEvent);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2018-09-20 09:55:17 +03:00
|
|
|
/**
|
|
|
|
* InsertPosition is an enum to indicate where the method should insert to.
|
|
|
|
*/
|
|
|
|
enum class InsertPosition {
|
|
|
|
// Before selected cell or a cell containing first selection range.
|
|
|
|
eBeforeSelectedCell,
|
|
|
|
// After selected cell or a cell containing first selection range.
|
|
|
|
eAfterSelectedCell,
|
|
|
|
};
|
|
|
|
|
2018-09-20 14:44:35 +03:00
|
|
|
/**
|
|
|
|
* InsertTableCellsWithTransaction() inserts <td> elements before or after
|
|
|
|
* a cell element containing first selection range. I.e., if the cell
|
|
|
|
* spans columns and aInsertPosition is eAfterSelectedCell, new columns
|
|
|
|
* will be inserted after the right-most column which contains the cell.
|
|
|
|
* Note that this simply inserts <td> elements, i.e., colspan and rowspan
|
|
|
|
* around the cell containing selection are not modified. So, for example,
|
|
|
|
* adding a cell to rectangular table changes non-rectangular table.
|
|
|
|
* And if the cell containing selection is at left of row-spanning cell,
|
|
|
|
* it may be moved to right side of the row-spanning cell after inserting
|
|
|
|
* some cell elements before it. Similarly, colspan won't be adjusted
|
|
|
|
* for keeping table rectangle.
|
|
|
|
* If first selection range is not in table cell element, this does nothing
|
|
|
|
* but does not return error.
|
|
|
|
*
|
|
|
|
* @param aNumberOfCellssToInsert Number of cells to insert.
|
|
|
|
* @param aInsertPosition Before or after the target cell which
|
|
|
|
* contains first selection range.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertTableCellsWithTransaction(
|
|
|
|
int32_t aNumberOfCellsToInsert, InsertPosition aInsertPosition);
|
2018-09-20 14:44:35 +03:00
|
|
|
|
2018-09-20 12:15:08 +03:00
|
|
|
/**
|
|
|
|
* InsertTableColumnsWithTransaction() inserts columns before or after
|
|
|
|
* a cell element containing first selection range. I.e., if the cell
|
|
|
|
* spans columns and aInsertPosition is eAfterSelectedCell, new columns
|
|
|
|
* will be inserted after the right-most row which contains the cell.
|
|
|
|
* If first selection range is not in table cell element, this does nothing
|
|
|
|
* but does not return error.
|
|
|
|
*
|
|
|
|
* @param aNumberOfColumnsToInsert Number of columns to insert.
|
|
|
|
* @param aInsertPosition Before or after the target cell which
|
|
|
|
* contains first selection range.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertTableColumnsWithTransaction(
|
|
|
|
int32_t aNumberOfColumnsToInsert, InsertPosition aInsertPosition);
|
2018-09-20 12:15:08 +03:00
|
|
|
|
2018-09-20 09:55:17 +03:00
|
|
|
/**
|
|
|
|
* InsertTableRowsWithTransaction() inserts <tr> elements before or after
|
|
|
|
* a cell element containing first selection range. I.e., if the cell
|
|
|
|
* spans rows and aInsertPosition is eAfterSelectedCell, new rows will be
|
|
|
|
* inserted after the most-bottom row which contains the cell. If first
|
|
|
|
* selection range is not in table cell element, this does nothing but
|
|
|
|
* does not return error.
|
|
|
|
*
|
|
|
|
* @param aNumberOfRowsToInsert Number of rows to insert.
|
|
|
|
* @param aInsertPosition Before or after the target cell which
|
|
|
|
* contains first selection range.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertTableRowsWithTransaction(
|
|
|
|
int32_t aNumberOfRowsToInsert, InsertPosition aInsertPosition);
|
2018-09-20 09:55:17 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
|
|
|
* Insert a new cell after or before supplied aCell.
|
|
|
|
* Optional: If aNewCell supplied, returns the newly-created cell (addref'd,
|
|
|
|
* of course)
|
|
|
|
* This doesn't change or use the current selection.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertCell(Element* aCell, int32_t aRowSpan,
|
|
|
|
int32_t aColSpan, bool aAfter,
|
|
|
|
bool aIsHeader, Element** aNewCell);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2018-09-19 09:34:33 +03:00
|
|
|
/**
|
|
|
|
* DeleteSelectedTableColumnsWithTransaction() removes cell elements which
|
|
|
|
* belong to same columns of selected cell elements.
|
|
|
|
* If only one cell element is selected or first selection range is
|
|
|
|
* in a cell, removes cell elements which belong to same column.
|
|
|
|
* If 2 or more cell elements are selected, removes cell elements which
|
|
|
|
* belong to any of all selected columns. In this case,
|
|
|
|
* aNumberOfColumnsToDelete is ignored.
|
|
|
|
* If there is no selection ranges, returns error.
|
|
|
|
* If selection is not in a cell element, this does not return error,
|
|
|
|
* just does nothing.
|
|
|
|
* WARNING: This does not remove <col> nor <colgroup> elements.
|
|
|
|
*
|
|
|
|
* @param aNumberOfColumnsToDelete Number of columns to remove. This is
|
|
|
|
* ignored if 2 ore more cells are
|
|
|
|
* selected.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DeleteSelectedTableColumnsWithTransaction(int32_t aNumberOfColumnsToDelete);
|
2018-09-19 09:34:33 +03:00
|
|
|
|
2018-09-19 09:39:31 +03:00
|
|
|
/**
|
|
|
|
* DeleteTableColumnWithTransaction() removes cell elements which belong
|
|
|
|
* to the specified column.
|
|
|
|
* This method adjusts colspan attribute value if cells spanning the
|
|
|
|
* column to delete.
|
|
|
|
* WARNING: This does not remove <col> nor <colgroup> elements.
|
|
|
|
*
|
|
|
|
* @param aTableElement The <table> element which contains the
|
|
|
|
* column which you want to remove.
|
|
|
|
* @param aRowIndex Index of the column which you want to remove.
|
|
|
|
* 0 is the first column.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult DeleteTableColumnWithTransaction(
|
|
|
|
Element& aTableElement, int32_t aColumnIndex);
|
2018-09-19 09:39:31 +03:00
|
|
|
|
2018-09-18 10:56:45 +03:00
|
|
|
/**
|
|
|
|
* DeleteSelectedTableRowsWithTransaction() removes <tr> elements.
|
|
|
|
* If only one cell element is selected or first selection range is
|
|
|
|
* in a cell, removes <tr> elements starting from a <tr> element
|
|
|
|
* containing the selected cell or first selection range.
|
|
|
|
* If 2 or more cell elements are selected, all <tr> elements
|
|
|
|
* which contains selected cell(s). In this case, aNumberOfRowsToDelete
|
|
|
|
* is ignored.
|
|
|
|
* If there is no selection ranges, returns error.
|
|
|
|
* If selection is not in a cell element, this does not return error,
|
|
|
|
* just does nothing.
|
|
|
|
*
|
|
|
|
* @param aNumberOfRowsToDelete Number of rows to remove. This is ignored
|
|
|
|
* if 2 or more cells are selected.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DeleteSelectedTableRowsWithTransaction(int32_t aNumberOfRowsToDelete);
|
2018-09-18 10:56:45 +03:00
|
|
|
|
2018-09-18 11:31:00 +03:00
|
|
|
/**
|
|
|
|
* DeleteTableRowWithTransaction() removes a <tr> element whose index in
|
|
|
|
* the <table> is aRowIndex.
|
|
|
|
* This method adjusts rowspan attribute value if the <tr> element contains
|
|
|
|
* cells which spans rows.
|
|
|
|
*
|
|
|
|
* @param aTableElement The <table> element which contains the
|
|
|
|
* <tr> element which you want to remove.
|
|
|
|
* @param aRowIndex Index of the <tr> element which you want to
|
|
|
|
* remove. 0 is the first row.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DeleteTableRowWithTransaction(Element& aTableElement, int32_t aRowIndex);
|
2018-09-18 11:31:00 +03:00
|
|
|
|
2018-09-19 11:50:11 +03:00
|
|
|
/**
|
|
|
|
* DeleteTableCellWithTransaction() removes table cell elements. If two or
|
|
|
|
* more cell elements are selected, this removes all selected cell elements.
|
|
|
|
* Otherwise, this removes some cell elements starting from selected cell
|
|
|
|
* element or a cell containing first selection range. When this removes
|
|
|
|
* last cell element in <tr> or <table>, this removes the <tr> or the
|
|
|
|
* <table> too. Note that when removing a cell causes number of its row
|
|
|
|
* becomes less than the others, this method does NOT fill the place with
|
|
|
|
* rowspan nor colspan. This does not return error even if selection is not
|
|
|
|
* in cell element, just does nothing.
|
|
|
|
*
|
|
|
|
* @param aNumberOfCellsToDelete Number of cells to remove. This is ignored
|
|
|
|
* if 2 or more cells are selected.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DeleteTableCellWithTransaction(int32_t aNumberOfCellsToDelete);
|
2018-09-19 11:50:11 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
2018-09-19 04:58:48 +03:00
|
|
|
* DeleteAllChildrenWithTransaction() removes all children of aElement from
|
|
|
|
* the tree.
|
|
|
|
*
|
|
|
|
* @param aElement The element whose children you want to remove.
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DeleteAllChildrenWithTransaction(Element& aElement);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move all contents from aCellToMerge into aTargetCell (append at end).
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult MergeCells(RefPtr<Element> aTargetCell,
|
|
|
|
RefPtr<Element> aCellToMerge,
|
|
|
|
bool aDeleteCellToMerge);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2018-09-18 10:56:45 +03:00
|
|
|
/**
|
|
|
|
* DeleteTableElementAndChildren() removes aTableElement (and its children)
|
|
|
|
* from the DOM tree with transaction.
|
|
|
|
*
|
|
|
|
* @param aTableElement The <table> element which you want to remove.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
DeleteTableElementAndChildrenWithTransaction(Element& aTableElement);
|
2018-09-18 10:56:45 +03:00
|
|
|
|
2019-05-08 09:26:25 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetColSpan(Element* aCell, int32_t aColSpan);
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetRowSpan(Element* aCell, int32_t aRowSpan);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper used to get nsTableWrapperFrame for a table.
|
|
|
|
*/
|
2018-08-23 09:39:30 +03:00
|
|
|
static nsTableWrapperFrame* GetTableFrame(Element* aTable);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
2018-09-19 07:32:10 +03:00
|
|
|
* GetNumberOfCellsInRow() returns number of actual cell elements in the row.
|
|
|
|
* If some cells appear by "rowspan" in other rows, they are ignored.
|
|
|
|
*
|
|
|
|
* @param aTableElement The <table> element.
|
|
|
|
* @param aRowIndex Valid row index in aTableElement. This method
|
|
|
|
* counts cell elements in the row.
|
|
|
|
* @return -1 if this meets unexpected error.
|
|
|
|
* Otherwise, number of cells which this method found.
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
*/
|
2018-09-19 07:32:10 +03:00
|
|
|
int32_t GetNumberOfCellsInRow(Element& aTableElement, int32_t aRowIndex);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if all cells in row or column at given index are selected.
|
|
|
|
*/
|
|
|
|
bool AllCellsInRowSelected(Element* aTable, int32_t aRowIndex,
|
|
|
|
int32_t aNumberOfColumns);
|
|
|
|
bool AllCellsInColumnSelected(Element* aTable, int32_t aColIndex,
|
|
|
|
int32_t aNumberOfRows);
|
|
|
|
|
|
|
|
bool IsEmptyCell(Element* aCell);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Most insert methods need to get the same basic context data.
|
|
|
|
* Any of the pointers may be null if you don't need that datum (for more
|
|
|
|
* efficiency).
|
|
|
|
* Input: *aCell is a known cell,
|
|
|
|
* if null, cell is obtained from the anchor node of the selection.
|
|
|
|
* Returns NS_EDITOR_ELEMENT_NOT_FOUND if cell is not found even if aCell is
|
|
|
|
* null.
|
|
|
|
*/
|
2020-05-14 13:08:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult GetCellContext(Element** aTable, Element** aCell,
|
|
|
|
nsINode** aCellParent,
|
|
|
|
int32_t* aCellOffset,
|
|
|
|
int32_t* aRowIndex,
|
|
|
|
int32_t* aColIndex);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
nsresult GetCellSpansAt(Element* aTable, int32_t aRowIndex, int32_t aColIndex,
|
|
|
|
int32_t& aActualRowSpan, int32_t& aActualColSpan);
|
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SplitCellIntoColumns(
|
|
|
|
Element* aTable, int32_t aRowIndex, int32_t aColIndex,
|
|
|
|
int32_t aColSpanLeft, int32_t aColSpanRight, Element** aNewCell);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SplitCellIntoRows(
|
|
|
|
Element* aTable, int32_t aRowIndex, int32_t aColIndex,
|
|
|
|
int32_t aRowSpanAbove, int32_t aRowSpanBelow, Element** aNewCell);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2019-05-08 09:26:25 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult CopyCellBackgroundColor(Element* aDestCell,
|
|
|
|
Element* aSourceCell);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduce rowspan/colspan when cells span into nonexistent rows/columns.
|
|
|
|
*/
|
2019-05-08 09:26:25 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult FixBadRowSpan(Element* aTable, int32_t aRowIndex,
|
|
|
|
int32_t& aNewRowCount);
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult FixBadColSpan(Element* aTable, int32_t aColIndex,
|
|
|
|
int32_t& aNewColCount);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
2018-10-30 13:01:38 +03:00
|
|
|
* XXX NormalizeTableInternal() is broken. If it meets a cell which has
|
|
|
|
* bigger or smaller rowspan or colspan than actual number of cells,
|
|
|
|
* this always failed to scan the table. Therefore, this does nothing
|
|
|
|
* when the table should be normalized.
|
2018-09-13 11:03:56 +03:00
|
|
|
*
|
|
|
|
* @param aTableOrElementInTable An element which is in a <table> element
|
|
|
|
* or <table> element itself. Otherwise,
|
|
|
|
* this returns NS_OK but does nothing.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
NormalizeTableInternal(Element& aTableOrElementInTable);
|
2018-09-13 11:03:56 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Fallback method: Call this after using ClearSelection() and you
|
|
|
|
* failed to set selection to some other content in the document.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetSelectionAtDocumentStart();
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
// Methods for handling plaintext quotations
|
2019-05-08 01:27:29 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult PasteAsPlaintextQuotation(int32_t aSelectionType);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a string as quoted text, replacing the selected text (if any).
|
|
|
|
* @param aQuotedText The string to insert.
|
|
|
|
* @param aAddCites Whether to prepend extra ">" to each line
|
|
|
|
* (usually true, unless those characters
|
|
|
|
* have already been added.)
|
|
|
|
* @return aNodeInserted The node spanning the insertion, if applicable.
|
|
|
|
* If aAddCites is false, this will be null.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertAsPlaintextQuotation(
|
2019-09-17 06:13:09 +03:00
|
|
|
const nsAString& aQuotedText, bool aAddCites, nsINode** aNodeInserted);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2018-11-09 11:40:57 +03:00
|
|
|
/**
|
|
|
|
* InsertObject() inserts given object at aPointToInsert.
|
2020-09-23 11:15:21 +03:00
|
|
|
*
|
|
|
|
* @param aType one of kFileMime, kJPEGImageMime, kJPGImageMime,
|
|
|
|
* kPNGImageMime, kGIFImageMime.
|
2018-11-09 11:40:57 +03:00
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertObject(const nsACString& aType,
|
|
|
|
nsISupports* aObject, bool aIsSafe,
|
|
|
|
Document* aSourceDoc,
|
|
|
|
const EditorDOMPoint& aPointToInsert,
|
|
|
|
bool aDoDeleteSelection);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2020-09-24 15:39:59 +03:00
|
|
|
class HTMLTransferablePreparer;
|
2020-09-22 19:03:55 +03:00
|
|
|
nsresult PrepareHTMLTransferable(nsITransferable** aTransferable) const;
|
2020-09-24 15:39:59 +03:00
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertFromTransferable(
|
|
|
|
nsITransferable* aTransferable, Document* aSourceDoc,
|
|
|
|
const nsAString& aContextStr, const nsAString& aInfoStr,
|
|
|
|
bool aHavePrivateHTMLFlavor, bool aDoDeleteSelection);
|
2018-11-09 11:40:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* InsertFromDataTransfer() is called only when user drops data into
|
|
|
|
* this editor. Don't use this method for other purposes.
|
2020-09-23 11:15:21 +03:00
|
|
|
*
|
|
|
|
* @param aIndex index of aDataTransfer's item to insert.
|
2018-11-09 11:40:57 +03:00
|
|
|
*/
|
2021-06-09 06:47:39 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult InsertFromDataTransfer(
|
|
|
|
const dom::DataTransfer* aDataTransfer, uint32_t aIndex,
|
|
|
|
Document* aSourceDoc, const EditorDOMPoint& aDroppedAt,
|
|
|
|
bool aDoDeleteSelection);
|
2018-11-09 11:40:57 +03:00
|
|
|
|
2020-09-22 19:03:55 +03:00
|
|
|
static bool HavePrivateHTMLFlavor(nsIClipboard* clipboard);
|
2020-09-16 23:17:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CF_HTML:
|
|
|
|
* <https://docs.microsoft.com/en-us/windows/win32/dataxchg/html-clipboard-format>.
|
|
|
|
*
|
|
|
|
* @param[in] aCfhtml a CF_HTML string as defined above.
|
|
|
|
* @param[out] aStuffToPaste the fragment, excluding context.
|
|
|
|
* @param[out] aCfcontext the context, excluding the fragment, including a
|
|
|
|
* marker (`kInsertionCookie`) indicating where the
|
|
|
|
* fragment begins.
|
|
|
|
*/
|
|
|
|
nsresult ParseCFHTML(const nsCString& aCfhtml, char16_t** aStuffToPaste,
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
char16_t** aCfcontext);
|
|
|
|
|
2020-02-13 05:56:25 +03:00
|
|
|
/**
|
2020-07-02 14:53:03 +03:00
|
|
|
* AutoHTMLFragmentBoundariesFixer fixes both edges of topmost child contents
|
2020-02-14 05:59:32 +03:00
|
|
|
* which are created with SubtreeContentIterator.
|
2020-02-13 05:56:25 +03:00
|
|
|
*/
|
2020-02-14 05:59:32 +03:00
|
|
|
class MOZ_STACK_CLASS AutoHTMLFragmentBoundariesFixer final {
|
|
|
|
public:
|
|
|
|
/**
|
2020-02-14 10:16:27 +03:00
|
|
|
* @param aArrayOfTopMostChildContents
|
2020-07-02 14:53:03 +03:00
|
|
|
* [in/out] The topmost child contents which will be
|
2020-02-14 05:59:32 +03:00
|
|
|
* inserted into the DOM tree. Both edges, i.e.,
|
|
|
|
* first node and last node in this array will be
|
2020-07-02 14:53:03 +03:00
|
|
|
* checked whether they can be inserted into
|
2020-02-14 05:59:32 +03:00
|
|
|
* another DOM tree. If not, it'll replaces some
|
|
|
|
* orphan nodes around nodes with proper parent.
|
|
|
|
*/
|
|
|
|
explicit AutoHTMLFragmentBoundariesFixer(
|
2020-02-14 10:16:27 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfTopMostChildContents);
|
2020-02-13 05:56:25 +03:00
|
|
|
|
2020-02-14 05:59:32 +03:00
|
|
|
private:
|
2020-02-14 08:40:37 +03:00
|
|
|
/**
|
|
|
|
* EnsureBeginsOrEndsWithValidContent() replaces some nodes starting from
|
|
|
|
* start or end with proper element node if it's necessary.
|
2020-02-14 10:16:27 +03:00
|
|
|
* If first or last node of aArrayOfTopMostChildContents is in list and/or
|
2020-02-14 08:40:37 +03:00
|
|
|
* `<table>` element, looks for topmost list element or `<table>` element
|
2020-06-30 16:13:04 +03:00
|
|
|
* with `CollectTableAndAnyListElementsOfInclusiveAncestorsAt()` and
|
2020-07-03 12:27:45 +03:00
|
|
|
* `GetMostDistantAncestorListOrTableElement()`. Then, checks
|
|
|
|
* whether some nodes are in aArrayOfTopMostChildContents are the topmost
|
|
|
|
* list/table element or its descendant and if so, removes the nodes from
|
2020-02-14 10:16:27 +03:00
|
|
|
* aArrayOfTopMostChildContents and inserts the list/table element instead.
|
|
|
|
* Then, aArrayOfTopMostChildContents won't start/end with list-item nor
|
2020-02-14 08:40:37 +03:00
|
|
|
* table cells.
|
|
|
|
*/
|
|
|
|
enum class StartOrEnd { start, end };
|
|
|
|
void EnsureBeginsOrEndsWithValidContent(
|
|
|
|
StartOrEnd aStartOrEnd,
|
2020-02-14 10:16:27 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfTopMostChildContents)
|
|
|
|
const;
|
2020-02-14 08:40:37 +03:00
|
|
|
|
2020-02-14 05:59:32 +03:00
|
|
|
/**
|
2020-06-30 16:13:04 +03:00
|
|
|
* CollectTableAndAnyListElementsOfInclusiveAncestorsAt() collects list
|
|
|
|
* elements and table related elements from the inclusive ancestors
|
|
|
|
* (https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor) of aNode.
|
2020-02-14 05:59:32 +03:00
|
|
|
*/
|
2020-06-30 16:13:04 +03:00
|
|
|
static void CollectTableAndAnyListElementsOfInclusiveAncestorsAt(
|
2020-02-14 10:16:27 +03:00
|
|
|
nsIContent& aContent,
|
2020-06-30 16:13:04 +03:00
|
|
|
nsTArray<OwningNonNull<Element>>& aOutArrayOfListAndTableElements);
|
2020-02-13 11:42:22 +03:00
|
|
|
|
2020-02-14 05:59:32 +03:00
|
|
|
/**
|
2020-07-03 12:27:45 +03:00
|
|
|
* GetMostDistantAncestorListOrTableElement() returns a list or a
|
|
|
|
* `<table>` element which is in
|
|
|
|
* aInclusiveAncestorsTableOrListElements and they are actually
|
|
|
|
* valid ancestor of at least one of aArrayOfTopMostChildContents.
|
2020-02-14 05:59:32 +03:00
|
|
|
*/
|
2020-07-03 12:27:45 +03:00
|
|
|
static Element* GetMostDistantAncestorListOrTableElement(
|
2020-02-14 10:16:27 +03:00
|
|
|
const nsTArray<OwningNonNull<nsIContent>>& aArrayOfTopMostChildContents,
|
2020-02-14 06:27:16 +03:00
|
|
|
const nsTArray<OwningNonNull<Element>>&
|
2020-07-03 12:27:45 +03:00
|
|
|
aInclusiveAncestorsTableOrListElements);
|
2020-02-13 05:55:53 +03:00
|
|
|
|
2020-02-14 05:59:32 +03:00
|
|
|
/**
|
|
|
|
* FindReplaceableTableElement() is a helper method of
|
2020-02-14 08:40:37 +03:00
|
|
|
* EnsureBeginsOrEndsWithValidContent(). If aNodeMaybeInTableElement is
|
|
|
|
* a descendant of aTableElement, returns aNodeMaybeInTableElement or its
|
|
|
|
* nearest ancestor whose tag name is `<td>`, `<th>`, `<tr>`, `<thead>`,
|
|
|
|
* `<tfoot>`, `<tbody>` or `<caption>`.
|
2020-02-14 05:59:32 +03:00
|
|
|
*
|
|
|
|
* @param aTableElement Must be a `<table>` element.
|
2020-02-14 10:16:27 +03:00
|
|
|
* @param aContentMaybeInTableElement A node which may be in aTableElement.
|
2020-02-14 05:59:32 +03:00
|
|
|
*/
|
|
|
|
Element* FindReplaceableTableElement(
|
2020-02-14 10:16:27 +03:00
|
|
|
Element& aTableElement, nsIContent& aContentMaybeInTableElement) const;
|
2020-02-14 05:59:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsReplaceableListElement() is a helper method of
|
2020-02-14 08:40:37 +03:00
|
|
|
* EnsureBeginsOrEndsWithValidContent(). If aNodeMaybeInListElement is a
|
|
|
|
* descendant of aListElement, returns true. Otherwise, false.
|
2020-02-14 05:59:32 +03:00
|
|
|
*
|
|
|
|
* @param aListElement Must be a list element.
|
2020-02-14 10:16:27 +03:00
|
|
|
* @param aContentMaybeInListElement A node which may be in aListElement.
|
2020-02-14 05:59:32 +03:00
|
|
|
*/
|
|
|
|
bool IsReplaceableListElement(Element& aListElement,
|
2020-02-14 10:16:27 +03:00
|
|
|
nsIContent& aContentMaybeInListElement) const;
|
2020-02-14 05:59:32 +03:00
|
|
|
};
|
2020-02-13 05:55:20 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
|
|
|
* MakeDefinitionListItemWithTransaction() replaces parent list of current
|
|
|
|
* selection with <dl> or create new <dl> element and creates a definition
|
|
|
|
* list item whose name is aTagName.
|
|
|
|
*
|
|
|
|
* @param aTagName Must be nsGkAtoms::dt or nsGkAtoms::dd.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-09-03 12:32:17 +03:00
|
|
|
MakeDefinitionListItemWithTransaction(nsAtom& aTagName);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
2019-09-02 09:08:43 +03:00
|
|
|
* FormatBlockContainerAsSubAction() inserts a block element whose name
|
|
|
|
* is aTagName at selection. If selection is not collapsed and aTagName is
|
|
|
|
* nsGkAtoms::normal or nsGkAtoms::_empty, this removes block containers.
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
*
|
|
|
|
* @param aTagName A block level element name. Must NOT be
|
|
|
|
* nsGkAtoms::dt nor nsGkAtoms::dd.
|
|
|
|
*/
|
2019-09-02 09:08:43 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult FormatBlockContainerAsSubAction(nsAtom& aTagName);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase/decrease the font size of selection.
|
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RelativeFontChange(FontSize aDir);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RelativeFontChangeOnNode(int32_t aSizeChange,
|
|
|
|
nsIContent* aNode);
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RelativeFontChangeHelper(int32_t aSizeChange,
|
|
|
|
nsINode* aNode);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper routines for inline style.
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetInlinePropertyOnTextNode(
|
Bug 1566795 - part 6: Make `HTMLEditor::RemoveInlinePropertyInternal()` remove text node style which comes from block parent r=m_kato
Finally, `Document.execCommand()` still does not work fine if selection
starts from very start of block and/or end at very end of block because
`PromoteInlineRange()` extends selection range to contain the
containers, then, `SubtreeContentIterator` won't list up text nodes.
In this case, `RemoveInlinePropertyInternal()` expects that
`RemoveStyleInside()` removes text node style with creating
`<span>` elements. However, `RemoveStyleInsilde()` only handles
`Element`s and it handles elements from most-descendants.
Therefore, it cannot distinguish whether text node style comes
from removing inline elements or parent block.
This patch makes `RemoveInlinePropertyInternal()` collect
descendant text nodes in the range after handling all nodes in
the range except descendant text nodes, then, check the
final style of descendant text nodes, finally, remove the style
if coming from parent block.
Differential Revision: https://phabricator.services.mozilla.com/D47865
--HG--
extra : moz-landing-system : lando
2019-10-09 11:04:34 +03:00
|
|
|
Text& aData, uint32_t aStartOffset, uint32_t aEndOffset,
|
|
|
|
nsAtom& aProperty, nsAtom* aAttribute, const nsAString& aValue);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
nsresult PromoteInlineRange(nsRange& aRange);
|
|
|
|
nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange);
|
2019-10-07 04:11:31 +03:00
|
|
|
|
2019-10-07 06:33:11 +03:00
|
|
|
/**
|
|
|
|
* RemoveStyleInside() removes elements which represent aProperty/aAttribute
|
|
|
|
* and removes CSS style. This handles aElement and all its descendants
|
Bug 1566795 - part 6: Make `HTMLEditor::RemoveInlinePropertyInternal()` remove text node style which comes from block parent r=m_kato
Finally, `Document.execCommand()` still does not work fine if selection
starts from very start of block and/or end at very end of block because
`PromoteInlineRange()` extends selection range to contain the
containers, then, `SubtreeContentIterator` won't list up text nodes.
In this case, `RemoveInlinePropertyInternal()` expects that
`RemoveStyleInside()` removes text node style with creating
`<span>` elements. However, `RemoveStyleInsilde()` only handles
`Element`s and it handles elements from most-descendants.
Therefore, it cannot distinguish whether text node style comes
from removing inline elements or parent block.
This patch makes `RemoveInlinePropertyInternal()` collect
descendant text nodes in the range after handling all nodes in
the range except descendant text nodes, then, check the
final style of descendant text nodes, finally, remove the style
if coming from parent block.
Differential Revision: https://phabricator.services.mozilla.com/D47865
--HG--
extra : moz-landing-system : lando
2019-10-09 11:04:34 +03:00
|
|
|
* (including leaf text nodes) recursively.
|
Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element). Then, unlink the new link element (i.e.,
clearing the "link style"). At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.
On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.
Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded. And then,
when preparing for inserting text, this patch makes it pass to the utility
method.
For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.
Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 10:19:33 +03:00
|
|
|
*
|
|
|
|
* @param aSpecifiedStyle Whether the class and style attributes should
|
|
|
|
* be preserved or discareded.
|
2019-10-07 06:33:11 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element). Then, unlink the new link element (i.e.,
clearing the "link style"). At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.
On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.
Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded. And then,
when preparing for inserting text, this patch makes it pass to the utility
method.
For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.
Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 10:19:33 +03:00
|
|
|
RemoveStyleInside(Element& aElement, nsAtom* aProperty, nsAtom* aAttribute,
|
|
|
|
SpecifiedStyle aSpecifiedStyle);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
Bug 1566795 - part 6: Make `HTMLEditor::RemoveInlinePropertyInternal()` remove text node style which comes from block parent r=m_kato
Finally, `Document.execCommand()` still does not work fine if selection
starts from very start of block and/or end at very end of block because
`PromoteInlineRange()` extends selection range to contain the
containers, then, `SubtreeContentIterator` won't list up text nodes.
In this case, `RemoveInlinePropertyInternal()` expects that
`RemoveStyleInside()` removes text node style with creating
`<span>` elements. However, `RemoveStyleInsilde()` only handles
`Element`s and it handles elements from most-descendants.
Therefore, it cannot distinguish whether text node style comes
from removing inline elements or parent block.
This patch makes `RemoveInlinePropertyInternal()` collect
descendant text nodes in the range after handling all nodes in
the range except descendant text nodes, then, check the
final style of descendant text nodes, finally, remove the style
if coming from parent block.
Differential Revision: https://phabricator.services.mozilla.com/D47865
--HG--
extra : moz-landing-system : lando
2019-10-09 11:04:34 +03:00
|
|
|
/**
|
|
|
|
* CollectEditableLeafTextNodes() collects text nodes in aElement.
|
|
|
|
*/
|
|
|
|
void CollectEditableLeafTextNodes(
|
|
|
|
Element& aElement, nsTArray<OwningNonNull<Text>>& aLeafTextNodes) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsRemovableParentStyleWithNewSpanElement() checks whether
|
|
|
|
* aProperty/aAttribute of parent block can be removed from aContent with
|
|
|
|
* creating `<span>` element. Note that this does NOT check whether the
|
|
|
|
* specified style comes from parent block or not.
|
2020-04-09 13:10:34 +03:00
|
|
|
* XXX This may destroy the editor, but using `Result<bool, nsresult>`
|
|
|
|
* is not reasonable because code for accessing the result becomes
|
|
|
|
* messy. However, anybody must forget to check `Destroyed()` after
|
|
|
|
* calling this. Which is the way to smart to make every caller
|
|
|
|
* must check the editor state?
|
Bug 1566795 - part 6: Make `HTMLEditor::RemoveInlinePropertyInternal()` remove text node style which comes from block parent r=m_kato
Finally, `Document.execCommand()` still does not work fine if selection
starts from very start of block and/or end at very end of block because
`PromoteInlineRange()` extends selection range to contain the
containers, then, `SubtreeContentIterator` won't list up text nodes.
In this case, `RemoveInlinePropertyInternal()` expects that
`RemoveStyleInside()` removes text node style with creating
`<span>` elements. However, `RemoveStyleInsilde()` only handles
`Element`s and it handles elements from most-descendants.
Therefore, it cannot distinguish whether text node style comes
from removing inline elements or parent block.
This patch makes `RemoveInlinePropertyInternal()` collect
descendant text nodes in the range after handling all nodes in
the range except descendant text nodes, then, check the
final style of descendant text nodes, finally, remove the style
if coming from parent block.
Differential Revision: https://phabricator.services.mozilla.com/D47865
--HG--
extra : moz-landing-system : lando
2019-10-09 11:04:34 +03:00
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT bool IsRemovableParentStyleWithNewSpanElement(
|
|
|
|
nsIContent& aContent, nsAtom* aHTMLProperty, nsAtom* aAttribute) const;
|
Bug 1566795 - part 6: Make `HTMLEditor::RemoveInlinePropertyInternal()` remove text node style which comes from block parent r=m_kato
Finally, `Document.execCommand()` still does not work fine if selection
starts from very start of block and/or end at very end of block because
`PromoteInlineRange()` extends selection range to contain the
containers, then, `SubtreeContentIterator` won't list up text nodes.
In this case, `RemoveInlinePropertyInternal()` expects that
`RemoveStyleInside()` removes text node style with creating
`<span>` elements. However, `RemoveStyleInsilde()` only handles
`Element`s and it handles elements from most-descendants.
Therefore, it cannot distinguish whether text node style comes
from removing inline elements or parent block.
This patch makes `RemoveInlinePropertyInternal()` collect
descendant text nodes in the range after handling all nodes in
the range except descendant text nodes, then, check the
final style of descendant text nodes, finally, remove the style
if coming from parent block.
Differential Revision: https://phabricator.services.mozilla.com/D47865
--HG--
extra : moz-landing-system : lando
2019-10-09 11:04:34 +03:00
|
|
|
|
2020-03-19 15:48:42 +03:00
|
|
|
/**
|
|
|
|
* XXX These methods seem odd and except the only caller,
|
|
|
|
* `PromoteInlineRange()`, cannot use them.
|
|
|
|
*/
|
|
|
|
bool IsStartOfContainerOrBeforeFirstEditableChild(
|
|
|
|
const EditorRawDOMPoint& aPoint) const;
|
|
|
|
bool IsEndOfContainerOrEqualsOrAfterLastEditableChild(
|
|
|
|
const EditorRawDOMPoint& aPoint) const;
|
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
bool IsOnlyAttribute(const Element* aElement, nsAtom* aAttribute);
|
|
|
|
|
2019-10-07 06:33:11 +03:00
|
|
|
/**
|
|
|
|
* HasStyleOrIdOrClassAttribute() returns true when at least one of
|
|
|
|
* `style`, `id` or `class` attribute value of aElement is not empty.
|
|
|
|
*/
|
|
|
|
static bool HasStyleOrIdOrClassAttribute(Element& aElement);
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Whether the outer window of the DOM event target has focus or not.
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
*/
|
2020-04-13 04:43:41 +03:00
|
|
|
bool OurWindowHasFocus() const;
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
|
2020-07-07 15:32:05 +03:00
|
|
|
class HTMLWithContextInserter;
|
|
|
|
|
2017-11-09 17:31:59 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* This function is used to insert a string of HTML input optionally with some
|
|
|
|
* context information into the editable field. The HTML input either comes
|
|
|
|
* from a transferable object created as part of a drop/paste operation, or
|
|
|
|
* from the InsertHTML method. We may want the HTML input to be sanitized
|
|
|
|
* (for example, if it's coming from a transferable object), in which case
|
|
|
|
* aTrustedInput should be set to false, otherwise, the caller should set it
|
|
|
|
* to true, which means that the HTML will be inserted in the DOM verbatim.
|
|
|
|
*
|
|
|
|
* aClearStyle should be set to false if you want the paste to be affected by
|
|
|
|
* local style (e.g., for the insertHTML command).
|
2017-11-09 17:31:59 +03:00
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult DoInsertHTMLWithContext(
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
const nsAString& aInputString, const nsAString& aContextStr,
|
2019-01-02 16:05:23 +03:00
|
|
|
const nsAString& aInfoStr, const nsAString& aFlavor, Document* aSourceDoc,
|
|
|
|
const EditorDOMPoint& aPointToInsert, bool aDeleteSelection,
|
|
|
|
bool aTrustedInput, bool aClearStyle = true);
|
2017-11-09 17:31:59 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* sets the position of an element; warning it does NOT check if the
|
|
|
|
* element is already positioned or not and that's on purpose.
|
2020-08-26 07:48:28 +03:00
|
|
|
* @param aStyledElement [IN] the element
|
|
|
|
* @param aX [IN] the x position in pixels.
|
|
|
|
* @param aY [IN] the y position in pixels.
|
2017-11-09 17:31:59 +03:00
|
|
|
*/
|
2020-08-26 07:48:28 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetTopAndLeftWithTransaction(
|
|
|
|
nsStyledElement& aStyledElement, int32_t aX, int32_t aY);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Reset a selected cell or collapsed selection (the caret) after table
|
|
|
|
* editing.
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
*
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* @param aTable A table in the document.
|
|
|
|
* @param aRow The row ...
|
|
|
|
* @param aCol ... and column defining the cell where we will try to
|
|
|
|
* place the caret.
|
|
|
|
* @param aSelected If true, we select the whole cell instead of setting
|
|
|
|
* caret.
|
|
|
|
* @param aDirection If cell at (aCol, aRow) is not found, search for
|
|
|
|
* previous cell in the same column (aPreviousColumn) or
|
|
|
|
* row (ePreviousRow) or don't search for another cell
|
|
|
|
* (aNoSearch). If no cell is found, caret is place just
|
|
|
|
* before table; and if that fails, at beginning of
|
|
|
|
* document. Thus we generally don't worry about the
|
|
|
|
* return value and can use the
|
|
|
|
* AutoSelectionSetterAfterTableEdit stack-based object to
|
|
|
|
* insure we reset the caret in a table-editing method.
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
*/
|
2020-03-18 05:02:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionAfterTableEdit(Element* aTable,
|
|
|
|
int32_t aRow, int32_t aCol,
|
|
|
|
int32_t aDirection,
|
|
|
|
bool aSelected);
|
Bug 1406726 - HTMLEditRules::WillInsertBreak() should reset mNewNode with caret position r=m_kato
HTMLEditRules::WillInsertBreak() started to use HTMLEditRules::MakeBasicBlock()
to wrap existing inline elements with default paragraph separator if inline
elements are children of editing host. However,
HTMLEditRules::ApplyBlockStyle() called by HTMLEditRules::MakeBasicBlock() sets
mNewNode to last new block node. So, if it wraps inline elements after caret
position, mNewNode becomes after expected caret position and
HTMLEditRules::AfterEditInner() will move caret into it.
This patch make HTMLEditRules::WillInsertBreak() reset mNewNode with
caret position after calling HTMLEditRules::MakeBasicBlock().
Additionally, this patch fixes a bug of HTMLEditor::IsVisibleBRElement().
That is, it uses only editable nodes to check if given <br> element is
visible. However, editable state is not related to this check. If <br>
element is followed by non-editable inline node (except invisible data
nodes), it always visible. This bug caused getting wrong nodes with
HTMLEditRules::GetNodesFromSelection() which is used by
HTMLEditRules::MakeBasicBlock(). Therefore, this patch also adds lots of
EditorBase::Get(Next|Previous)ElementOrText*() and
HTMLEditor::Get(Next|Previous)HTMLElementOrText*() to ignore only invisible
data nodes.
Note that even with this fix, the range of nodes computed by
HTMLEditRules::GetNodesFromSelection() is still odd if only non-editable
elements follow a <br> node which is first <br> element after the caret
position. However, what is expected by the execCommand spec is unclear.
So, automated test added by this patch checks current inconsistent behavior
for now.
MozReview-Commit-ID: 2m52StwoEEH
--HG--
extra : rebase_source : 6b9b2338e35c4d2e89a405fd8e1ffc7b0873ca1e
2018-02-13 13:01:42 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
void RemoveListenerAndDeleteRef(const nsAString& aEvent,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture, ManualNACPtr aElement,
|
2019-03-15 08:01:10 +03:00
|
|
|
PresShell* aPresShell);
|
|
|
|
void DeleteRefToAnonymousNode(ManualNACPtr aContent, PresShell* aPresShell);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
2018-08-17 11:56:28 +03:00
|
|
|
/**
|
2019-05-09 10:37:51 +03:00
|
|
|
* RefreshEditingUI() may refresh editing UIs for current Selection, focus,
|
2018-08-17 11:56:28 +03:00
|
|
|
* etc. If this shows or hides some UIs, it causes reflow. So, this is
|
|
|
|
* not safe method.
|
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult RefreshEditingUI();
|
2018-08-17 11:56:28 +03:00
|
|
|
|
2017-11-09 18:12:22 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Returns the offset of an element's frame to its absolute containing block.
|
2017-11-09 18:12:22 +03:00
|
|
|
*/
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
nsresult GetElementOrigin(Element& aElement, int32_t& aX, int32_t& aY);
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult GetPositionAndDimensions(
|
|
|
|
Element& aElement, int32_t& aX, int32_t& aY, int32_t& aW, int32_t& aH,
|
|
|
|
int32_t& aBorderLeft, int32_t& aBorderTop, int32_t& aMarginLeft,
|
|
|
|
int32_t& aMarginTop);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
bool IsInObservedSubtree(nsIContent* aChild);
|
|
|
|
|
|
|
|
void UpdateRootElement();
|
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
/**
|
|
|
|
* SetAllResizersPosition() moves all resizers to proper position.
|
|
|
|
* If the resizers are hidden or replaced with another set of resizers
|
|
|
|
* while this is running, this returns error. So, callers shouldn't
|
|
|
|
* keep handling the resizers if this returns error.
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetAllResizersPosition();
|
2017-11-09 18:12:22 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Shows active resizers around an element's frame
|
|
|
|
* @param aResizedElement [IN] a DOM Element
|
2017-11-09 18:12:22 +03:00
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult ShowResizersInternal(Element& aResizedElement);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-09-06 08:02:46 +03:00
|
|
|
/**
|
|
|
|
* Hide resizers if they are visible. If this is called while there is no
|
|
|
|
* visible resizers, this does not return error, but does nothing.
|
|
|
|
*/
|
|
|
|
nsresult HideResizersInternal();
|
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
/**
|
|
|
|
* RefreshResizersInternal() moves resizers to proper position. This does
|
|
|
|
* nothing if there is no resizing target.
|
|
|
|
*/
|
2021-06-28 15:08:49 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RefreshResizersInternal();
|
2018-09-11 11:15:52 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
ManualNACPtr CreateResizer(int16_t aLocation, nsIContent& aParentContent);
|
2020-08-26 07:48:28 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2020-09-14 08:10:08 +03:00
|
|
|
SetAnonymousElementPositionWithoutTransaction(nsStyledElement& aStyledElement,
|
|
|
|
int32_t aX, int32_t aY);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
ManualNACPtr CreateShadow(nsIContent& aParentContent,
|
|
|
|
Element& aOriginalObject);
|
2018-09-11 11:15:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SetShadowPosition() moves the shadow element to proper position.
|
|
|
|
*
|
|
|
|
* @param aShadowElement Must be mResizingShadow or mPositioningShadow.
|
|
|
|
* @param aElement The element which has the shadow.
|
|
|
|
* @param aElementX Left of aElement.
|
|
|
|
* @param aElementY Top of aElement.
|
|
|
|
*/
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SetShadowPosition(Element& aShadowElement, Element& aElement,
|
|
|
|
int32_t aElementLeft, int32_t aElementTop);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
ManualNACPtr CreateResizingInfo(nsIContent& aParentContent);
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetResizingInfoPosition(int32_t aX, int32_t aY,
|
|
|
|
int32_t aW, int32_t aH);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
|
|
|
|
enum class ResizeAt {
|
|
|
|
eX,
|
|
|
|
eY,
|
|
|
|
eWidth,
|
|
|
|
eHeight,
|
|
|
|
};
|
|
|
|
int32_t GetNewResizingIncrement(int32_t aX, int32_t aY, ResizeAt aResizeAt);
|
|
|
|
|
2020-08-26 07:48:28 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult StartResizing(Element& aHandle);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
int32_t GetNewResizingX(int32_t aX, int32_t aY);
|
|
|
|
int32_t GetNewResizingY(int32_t aX, int32_t aY);
|
|
|
|
int32_t GetNewResizingWidth(int32_t aX, int32_t aY);
|
|
|
|
int32_t GetNewResizingHeight(int32_t aX, int32_t aY);
|
|
|
|
void HideShadowAndInfo();
|
2020-08-26 07:48:28 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SetFinalSizeWithTransaction(int32_t aX, int32_t aY);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH,
|
|
|
|
bool aPreserveRatio);
|
2018-08-17 13:03:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HideAnonymousEditingUIs() forcibly hides all editing UIs (resizers,
|
|
|
|
* inline-table-editing UI, absolute positioning UI).
|
|
|
|
*/
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
void HideAnonymousEditingUIs();
|
|
|
|
|
2018-08-17 13:03:02 +03:00
|
|
|
/**
|
|
|
|
* HideAnonymousEditingUIsIfUnnecessary() hides all editing UIs if some of
|
|
|
|
* visible UIs are now unnecessary.
|
|
|
|
*/
|
|
|
|
void HideAnonymousEditingUIsIfUnnecessary();
|
|
|
|
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
/**
|
|
|
|
* sets the z-index of an element.
|
|
|
|
* @param aElement [IN] the element
|
|
|
|
* @param aZorder [IN] the z-index
|
|
|
|
*/
|
2020-08-26 07:48:28 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SetZIndexWithTransaction(nsStyledElement& aElement, int32_t aZIndex);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* shows a grabber attached to an arbitrary element. The grabber is an image
|
|
|
|
* positioned on the left hand side of the top border of the element. Draggin
|
|
|
|
* and dropping it allows to change the element's absolute position in the
|
|
|
|
* document. See chrome://editor/content/images/grabber.gif
|
|
|
|
* @param aElement [IN] the element
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult ShowGrabberInternal(Element& aElement);
|
2018-09-11 08:30:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting grabber to proper position for current mAbsolutelyPositionedObject.
|
|
|
|
* For example, while an element has grabber, the element may be resized
|
|
|
|
* or repositioned by script or something. Then, you need to reset grabber
|
|
|
|
* position with this.
|
|
|
|
*/
|
2021-06-28 15:08:49 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RefreshGrabberInternal();
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* hide the grabber if it shown.
|
2016-07-09 05:42:33 +03:00
|
|
|
*/
|
2018-09-11 08:30:33 +03:00
|
|
|
void HideGrabberInternal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreateGrabberInternal() creates a grabber for moving aParentContent.
|
|
|
|
* This sets mGrabber to the new grabber. If this returns true, it's
|
|
|
|
* always non-nullptr. Otherwise, i.e., the grabber is hidden during
|
|
|
|
* creation, this returns false.
|
|
|
|
*/
|
|
|
|
bool CreateGrabberInternal(nsIContent& aParentContent);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult StartMoving();
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetFinalPosition(int32_t aX, int32_t aY);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
void AddPositioningOffset(int32_t& aX, int32_t& aY);
|
|
|
|
void SnapToGrid(int32_t& newX, int32_t& newY);
|
|
|
|
nsresult GrabberClicked();
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult EndMoving();
|
2020-04-09 13:10:34 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
GetTemporaryStyleForFocusedPositionedElement(Element& aElement,
|
|
|
|
nsAString& aReturn);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-02-01 04:55:25 +03:00
|
|
|
/**
|
2018-09-11 15:10:54 +03:00
|
|
|
* Shows inline table editing UI around a <table> element which contains
|
|
|
|
* aCellElement. This returns error if creating UI is hidden during this,
|
|
|
|
* or detects another set of UI during this. In such case, callers
|
|
|
|
* shouldn't keep handling anything for the UI.
|
|
|
|
*
|
|
|
|
* @param aCellElement Must be an <td> or <th> element.
|
|
|
|
*/
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
ShowInlineTableEditingUIInternal(Element& aCellElement);
|
2018-09-11 15:10:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide all inline table editing UI.
|
2018-02-01 04:55:25 +03:00
|
|
|
*/
|
2018-09-11 15:10:54 +03:00
|
|
|
void HideInlineTableEditingUIInternal();
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2017-08-08 04:57:19 +03:00
|
|
|
/**
|
2018-09-11 15:10:54 +03:00
|
|
|
* RefreshInlineTableEditingUIInternal() moves inline table editing UI to
|
|
|
|
* proper position. This returns error if the UI is hidden or replaced
|
|
|
|
* during moving.
|
2017-08-08 04:57:19 +03:00
|
|
|
*/
|
2021-06-28 15:08:49 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
RefreshInlineTableEditingUIInternal();
|
2017-08-08 04:57:19 +03:00
|
|
|
|
2020-08-26 07:48:36 +03:00
|
|
|
/**
|
|
|
|
* ElementIsGoodContainerForTheStyle() returns true if aElement is a
|
|
|
|
* good container for applying the style (aProperty/aAttribute/aValue)
|
|
|
|
* to a node. I.e., if this returns true, moving nodes into aElement
|
|
|
|
* is enough to apply the style to them. Otherwise, you need to create
|
|
|
|
* new element for the style.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<bool, nsresult>
|
|
|
|
ElementIsGoodContainerForTheStyle(Element& aElement, nsAtom* aProperty,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
const nsAString* aValue);
|
|
|
|
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
SetInlinePropertyOnNodeImpl(nsIContent& aNode, nsAtom& aProperty,
|
|
|
|
nsAtom* aAttribute, const nsAString& aValue);
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
typedef enum { eInserted, eAppended } InsertedOrAppended;
|
2019-09-17 10:22:01 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void DoContentInserted(
|
|
|
|
nsIContent* aChild, InsertedOrAppended aInsertedOrAppended);
|
2018-08-10 13:36:24 +03:00
|
|
|
|
2018-04-12 11:20:21 +03:00
|
|
|
/**
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
* Returns an anonymous Element of type aTag,
|
|
|
|
* child of aParentContent. If aIsCreatedHidden is true, the class
|
|
|
|
* "hidden" is added to the created element. If aAnonClass is not
|
|
|
|
* the empty string, it becomes the value of the attribute "_moz_anonclass"
|
|
|
|
* @return a Element
|
|
|
|
* @param aTag [IN] desired type of the element to create
|
|
|
|
* @param aParentContent [IN] the parent node of the created anonymous
|
|
|
|
* element
|
|
|
|
* @param aAnonClass [IN] contents of the _moz_anonclass attribute
|
|
|
|
* @param aIsCreatedHidden [IN] a boolean specifying if the class "hidden"
|
|
|
|
* is to be added to the created anonymous
|
|
|
|
* element
|
2018-04-12 11:20:21 +03:00
|
|
|
*/
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
ManualNACPtr CreateAnonymousElement(nsAtom* aTag, nsIContent& aParentContent,
|
|
|
|
const nsAString& aAnonClass,
|
|
|
|
bool aIsCreatedHidden);
|
2018-09-09 01:44:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a blob into memory and notifies the BlobReader object when the read
|
|
|
|
* operation is finished.
|
|
|
|
*
|
|
|
|
* @param aBlob The input blob
|
|
|
|
* @param aWindow The global object under which the read should happen.
|
|
|
|
* @param aBlobReader The blob reader object to be notified when finished.
|
|
|
|
*/
|
|
|
|
static nsresult SlurpBlob(dom::Blob* aBlob, nsPIDOMWindowOuter* aWindow,
|
|
|
|
BlobReader* aBlobReader);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-08-13 03:56:57 +03:00
|
|
|
/**
|
|
|
|
* OnModifyDocumentInternal() is called by OnModifyDocument().
|
|
|
|
*/
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult OnModifyDocumentInternal();
|
2019-08-13 03:56:57 +03:00
|
|
|
|
2019-08-20 04:51:19 +03:00
|
|
|
/**
|
|
|
|
* For saving allocation cost in the constructor of
|
|
|
|
* EditorBase::TopLevelEditSubActionData, we should reuse same RangeItem
|
|
|
|
* instance with all top level edit sub actions.
|
|
|
|
* The instance is always cleared when TopLevelEditSubActionData is
|
|
|
|
* destructed and the class is stack only class so that we don't need
|
|
|
|
* to (and also should not) add the RangeItem into the cycle collection.
|
|
|
|
*/
|
|
|
|
already_AddRefed<RangeItem> GetSelectedRangeItemForTopLevelEditSubAction()
|
|
|
|
const {
|
|
|
|
if (!mSelectedRangeForTopLevelEditSubAction) {
|
|
|
|
mSelectedRangeForTopLevelEditSubAction = new RangeItem();
|
|
|
|
}
|
|
|
|
return do_AddRef(mSelectedRangeForTopLevelEditSubAction);
|
|
|
|
}
|
|
|
|
|
2019-08-20 04:51:59 +03:00
|
|
|
/**
|
|
|
|
* For saving allocation cost in the constructor of
|
|
|
|
* EditorBase::TopLevelEditSubActionData, we should reuse same nsRange
|
|
|
|
* instance with all top level edit sub actions.
|
|
|
|
* The instance is always cleared when TopLevelEditSubActionData is
|
|
|
|
* destructed, but AbstractRange::mOwner keeps grabbing the owner document
|
|
|
|
* so that we need to make it in the cycle collection.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsRange> GetChangedRangeForTopLevelEditSubAction() const {
|
|
|
|
if (!mChangedRangeForTopLevelEditSubAction) {
|
2020-01-30 16:23:35 +03:00
|
|
|
mChangedRangeForTopLevelEditSubAction = nsRange::Create(GetDocument());
|
2019-08-20 04:51:59 +03:00
|
|
|
}
|
|
|
|
return do_AddRef(mChangedRangeForTopLevelEditSubAction);
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
protected:
|
2019-10-15 07:36:26 +03:00
|
|
|
// Helper for Handle[CSS|HTML]IndentAtSelectionInternal
|
2020-04-02 08:43:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
2019-10-15 07:36:26 +03:00
|
|
|
IndentListChild(RefPtr<Element>* aCurList, const EditorDOMPoint& aCurPoint,
|
2020-02-12 08:52:30 +03:00
|
|
|
nsIContent& aContent);
|
2019-10-15 07:36:26 +03:00
|
|
|
|
2021-07-02 11:23:45 +03:00
|
|
|
/**
|
|
|
|
* Stack based helper class for saving/restoring selection. Note that this
|
|
|
|
* assumes that the nodes involved are still around afterwords!
|
|
|
|
*/
|
|
|
|
class AutoSelectionRestorer final {
|
|
|
|
public:
|
|
|
|
AutoSelectionRestorer() = delete;
|
|
|
|
explicit AutoSelectionRestorer(const AutoSelectionRestorer& aOther) =
|
|
|
|
delete;
|
|
|
|
AutoSelectionRestorer(AutoSelectionRestorer&& aOther) = delete;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor responsible for remembering all state needed to restore
|
|
|
|
* aSelection.
|
|
|
|
* XXX This constructor and the destructor should be marked as
|
|
|
|
* `MOZ_CAN_RUN_SCRIPT`, but it's impossible due to this may be used
|
|
|
|
* with `Maybe`.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY explicit AutoSelectionRestorer(
|
|
|
|
HTMLEditor& aHTMLEditor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor restores mSelection to its former state
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY ~AutoSelectionRestorer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abort() cancels to restore the selection.
|
|
|
|
*/
|
|
|
|
void Abort();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// The lifetime must be guaranteed by the creator of this instance.
|
|
|
|
MOZ_KNOWN_LIVE HTMLEditor* mHTMLEditor = nullptr;
|
|
|
|
};
|
|
|
|
|
2021-07-02 11:23:45 +03:00
|
|
|
/**
|
|
|
|
* Stack based helper class for calling EditorBase::EndTransactionInternal().
|
|
|
|
* NOTE: This does not suppress multiple input events. In most cases,
|
|
|
|
* only one "input" event should be fired for an edit action rather
|
|
|
|
* than per edit sub-action. In such case, you should use
|
|
|
|
* EditorBase::AutoPlaceholderBatch instead.
|
|
|
|
*/
|
|
|
|
class MOZ_RAII AutoTransactionBatch final {
|
|
|
|
public:
|
|
|
|
MOZ_CAN_RUN_SCRIPT explicit AutoTransactionBatch(HTMLEditor& aHTMLEditor)
|
|
|
|
: mHTMLEditor(aHTMLEditor) {
|
|
|
|
MOZ_KnownLive(mHTMLEditor).BeginTransactionInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT ~AutoTransactionBatch() {
|
|
|
|
MOZ_KnownLive(mHTMLEditor).EndTransactionInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// The lifetime must be guaranteed by the creator of this instance.
|
|
|
|
MOZ_KNOWN_LIVE HTMLEditor& mHTMLEditor;
|
|
|
|
};
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
RefPtr<TypeInState> mTypeInState;
|
2018-01-26 08:38:05 +03:00
|
|
|
RefPtr<ComposerCommandsUpdater> mComposerCommandsUpdater;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2019-08-20 04:51:19 +03:00
|
|
|
// Used by TopLevelEditSubActionData::mSelectedRange.
|
|
|
|
mutable RefPtr<RangeItem> mSelectedRangeForTopLevelEditSubAction;
|
2019-08-20 04:51:59 +03:00
|
|
|
// Used by TopLevelEditSubActionData::mChangedRange.
|
|
|
|
mutable RefPtr<nsRange> mChangedRangeForTopLevelEditSubAction;
|
2019-08-20 04:51:19 +03:00
|
|
|
|
2020-04-16 18:15:26 +03:00
|
|
|
RefPtr<Runnable> mPendingRootElementUpdatedRunner;
|
|
|
|
RefPtr<Runnable> mPendingDocumentModifiedRunner;
|
|
|
|
|
2021-06-21 04:49:01 +03:00
|
|
|
// mPaddingBRElementForEmptyEditor should be used for placing caret
|
|
|
|
// at proper position when editor is empty.
|
|
|
|
RefPtr<dom::HTMLBRElement> mPaddingBRElementForEmptyEditor;
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
bool mCRInParagraphCreatesParagraph;
|
|
|
|
|
2017-02-08 12:14:24 +03:00
|
|
|
UniquePtr<CSSEditUtils> mCSSEditUtils;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
// resizing
|
|
|
|
bool mIsObjectResizingEnabled;
|
|
|
|
bool mIsResizing;
|
|
|
|
bool mPreserveRatio;
|
|
|
|
bool mResizedObjectIsAnImage;
|
|
|
|
|
|
|
|
// absolute positioning
|
|
|
|
bool mIsAbsolutelyPositioningEnabled;
|
|
|
|
bool mResizedObjectIsAbsolutelyPositioned;
|
|
|
|
bool mGrabberClicked;
|
|
|
|
bool mIsMoving;
|
|
|
|
|
|
|
|
bool mSnapToGridEnabled;
|
|
|
|
|
|
|
|
// inline table editing
|
|
|
|
bool mIsInlineTableEditingEnabled;
|
|
|
|
|
|
|
|
// resizing
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr mTopLeftHandle;
|
|
|
|
ManualNACPtr mTopHandle;
|
|
|
|
ManualNACPtr mTopRightHandle;
|
|
|
|
ManualNACPtr mLeftHandle;
|
|
|
|
ManualNACPtr mRightHandle;
|
|
|
|
ManualNACPtr mBottomLeftHandle;
|
|
|
|
ManualNACPtr mBottomHandle;
|
|
|
|
ManualNACPtr mBottomRightHandle;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-08-24 09:27:48 +03:00
|
|
|
RefPtr<Element> mActivatedHandle;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr mResizingShadow;
|
|
|
|
ManualNACPtr mResizingInfo;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2018-04-27 06:35:18 +03:00
|
|
|
RefPtr<Element> mResizedObject;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
int32_t mOriginalX;
|
|
|
|
int32_t mOriginalY;
|
|
|
|
|
|
|
|
int32_t mResizedObjectX;
|
|
|
|
int32_t mResizedObjectY;
|
|
|
|
int32_t mResizedObjectWidth;
|
|
|
|
int32_t mResizedObjectHeight;
|
|
|
|
|
|
|
|
int32_t mResizedObjectMarginLeft;
|
|
|
|
int32_t mResizedObjectMarginTop;
|
|
|
|
int32_t mResizedObjectBorderLeft;
|
|
|
|
int32_t mResizedObjectBorderTop;
|
|
|
|
|
|
|
|
int32_t mXIncrementFactor;
|
|
|
|
int32_t mYIncrementFactor;
|
|
|
|
int32_t mWidthIncrementFactor;
|
|
|
|
int32_t mHeightIncrementFactor;
|
|
|
|
|
|
|
|
int8_t mInfoXIncrement;
|
|
|
|
int8_t mInfoYIncrement;
|
|
|
|
|
|
|
|
// absolute positioning
|
|
|
|
int32_t mPositionedObjectX;
|
|
|
|
int32_t mPositionedObjectY;
|
|
|
|
int32_t mPositionedObjectWidth;
|
|
|
|
int32_t mPositionedObjectHeight;
|
|
|
|
|
|
|
|
int32_t mPositionedObjectMarginLeft;
|
|
|
|
int32_t mPositionedObjectMarginTop;
|
|
|
|
int32_t mPositionedObjectBorderLeft;
|
|
|
|
int32_t mPositionedObjectBorderTop;
|
|
|
|
|
2018-09-11 08:30:33 +03:00
|
|
|
RefPtr<Element> mAbsolutelyPositionedObject;
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr mGrabber;
|
|
|
|
ManualNACPtr mPositioningShadow;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
|
|
|
int32_t mGridSize;
|
|
|
|
|
|
|
|
// inline table editing
|
2017-12-15 19:14:54 +03:00
|
|
|
RefPtr<Element> mInlineEditedCell;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr mAddColumnBeforeButton;
|
|
|
|
ManualNACPtr mRemoveColumnButton;
|
|
|
|
ManualNACPtr mAddColumnAfterButton;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr mAddRowBeforeButton;
|
|
|
|
ManualNACPtr mRemoveRowButton;
|
|
|
|
ManualNACPtr mAddRowAfterButton;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2016-11-24 09:58:01 +03:00
|
|
|
void AddMouseClickListener(Element* aElement);
|
|
|
|
void RemoveMouseClickListener(Element* aElement);
|
2016-07-09 05:42:33 +03:00
|
|
|
|
2019-07-09 19:17:27 +03:00
|
|
|
bool mDisabledLinkHandling = false;
|
|
|
|
bool mOldLinkHandlingEnabled = false;
|
2016-07-09 05:42:33 +03:00
|
|
|
|
Bug 1668134 - part 3: Add telemetry probes to collect how percentage of `HTMLEditor` is or is not handled with `beforeinput` event listeners r=smaug data-review=tdsmith
Unfortunately, there is no official way to detect whether browser supports
or not `beforeinput` event in the wild because Chromium does not support
`onbeforeinput` event handler attribute. On the other hand, we're the
last browser vendor which does not support `beforeinput` event, and we
make `InputEvent.getTargetRanges()` enabled only when `beforeinput` event
because it returns meaningful value only when the event type is `beforeinput`.
So, web apps can detect `beforeinput` event support with checking type of
or existence of it instead. However, in our experience, it's guessed what
a lot of web apps check whether "Firefox" or not to consider whether it
can use `beforeinput` events. If so, we need to announce shipping
`beforeinput` event and the way to feature detection before actually shipping
it. Otherwise, we wouldn't get enough feedback from testers.
First of all for shipping `beforeinput` events, we should collect how much
web apps which use `HTMLEditor` use `beforeinput` event when it's enabled,
and how much web apps use mutation events or mutation observer instead of
`beforeinput` events even when it's enabled.
Honestly, I'd like to collect URLs which don't use `beforeinput` event, but
use mutation events or mutation observer. But it's really sensitive data
so that I believe that we shouldn't collect it.
Differential Revision: https://phabricator.services.mozilla.com/D92548
2020-10-10 02:54:19 +03:00
|
|
|
bool mHasBeforeInputBeenCanceled = false;
|
|
|
|
|
2017-04-06 15:02:42 +03:00
|
|
|
ParagraphSeparator mDefaultParagraphSeparator;
|
2016-08-24 15:53:52 +03:00
|
|
|
|
2019-09-18 09:26:56 +03:00
|
|
|
friend class AlignStateAtSelection;
|
2017-08-08 04:57:19 +03:00
|
|
|
friend class AutoSelectionSetterAfterTableEdit;
|
2018-09-20 13:03:24 +03:00
|
|
|
friend class AutoSetTemporaryAncestorLimiter;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
friend class CSSEditUtils;
|
2018-08-16 13:29:20 +03:00
|
|
|
friend class EditorBase;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-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 HTMLEditor 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 HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
friend class EmptyEditableFunctor;
|
2020-04-30 18:26:09 +03:00
|
|
|
friend class JoinNodeTransaction;
|
2019-09-18 06:39:00 +03:00
|
|
|
friend class ListElementSelectionState;
|
2019-09-18 07:42:55 +03:00
|
|
|
friend class ListItemElementSelectionState;
|
2019-09-18 11:20:29 +03:00
|
|
|
friend class ParagraphStateAtSelection;
|
2018-09-18 07:34:21 +03:00
|
|
|
friend class SlurpBlobEventListener;
|
2020-04-30 16:33:40 +03:00
|
|
|
friend class SplitNodeTransaction;
|
2020-07-14 15:40:13 +03:00
|
|
|
friend class WhiteSpaceVisibilityKeeper;
|
2019-08-12 11:30:57 +03:00
|
|
|
friend class WSRunScanner;
|
2020-02-25 15:10:04 +03:00
|
|
|
friend class WSScanResult;
|
2016-07-09 05:42:33 +03:00
|
|
|
};
|
|
|
|
|
2019-09-18 06:39:00 +03:00
|
|
|
/**
|
|
|
|
* ListElementSelectionState class gets which list element is selected right
|
|
|
|
* now.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS ListElementSelectionState final {
|
|
|
|
public:
|
|
|
|
ListElementSelectionState() = delete;
|
|
|
|
ListElementSelectionState(HTMLEditor& aHTMLEditor, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool IsOLElementSelected() const { return mIsOLElementSelected; }
|
|
|
|
bool IsULElementSelected() const { return mIsULElementSelected; }
|
|
|
|
bool IsDLElementSelected() const { return mIsDLElementSelected; }
|
|
|
|
bool IsNotOneTypeListElementSelected() const {
|
|
|
|
return (mIsOLElementSelected + mIsULElementSelected + mIsDLElementSelected +
|
|
|
|
mIsOtherContentSelected) > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mIsOLElementSelected = false;
|
|
|
|
bool mIsULElementSelected = false;
|
|
|
|
bool mIsDLElementSelected = false;
|
|
|
|
bool mIsOtherContentSelected = false;
|
|
|
|
};
|
|
|
|
|
2019-09-18 07:42:55 +03:00
|
|
|
/**
|
|
|
|
* ListItemElementSelectionState class gets which list item element is selected
|
|
|
|
* right now.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS ListItemElementSelectionState final {
|
|
|
|
public:
|
|
|
|
ListItemElementSelectionState() = delete;
|
|
|
|
ListItemElementSelectionState(HTMLEditor& aHTMLEditor, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool IsLIElementSelected() const { return mIsLIElementSelected; }
|
|
|
|
bool IsDTElementSelected() const { return mIsDTElementSelected; }
|
|
|
|
bool IsDDElementSelected() const { return mIsDDElementSelected; }
|
|
|
|
bool IsNotOneTypeDefinitionListItemElementSelected() const {
|
|
|
|
return (mIsDTElementSelected + mIsDDElementSelected +
|
|
|
|
mIsOtherElementSelected) > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mIsLIElementSelected = false;
|
|
|
|
bool mIsDTElementSelected = false;
|
|
|
|
bool mIsDDElementSelected = false;
|
|
|
|
bool mIsOtherElementSelected = false;
|
|
|
|
};
|
|
|
|
|
2019-09-18 09:26:56 +03:00
|
|
|
/**
|
|
|
|
* AlignStateAtSelection class gets alignment at selection.
|
|
|
|
* XXX This currently returns only first alignment.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS AlignStateAtSelection final {
|
|
|
|
public:
|
|
|
|
AlignStateAtSelection() = delete;
|
2020-04-09 13:10:34 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT AlignStateAtSelection(HTMLEditor& aHTMLEditor,
|
|
|
|
ErrorResult& aRv);
|
2019-09-18 09:26:56 +03:00
|
|
|
|
|
|
|
nsIHTMLEditor::EAlignment AlignmentAtSelectionStart() const {
|
|
|
|
return mFirstAlign;
|
|
|
|
}
|
2020-04-01 09:38:16 +03:00
|
|
|
bool IsSelectionRangesFound() const { return mFoundSelectionRanges; }
|
2019-09-18 09:26:56 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIHTMLEditor::EAlignment mFirstAlign = nsIHTMLEditor::eLeft;
|
2020-04-01 09:38:16 +03:00
|
|
|
bool mFoundSelectionRanges = false;
|
2019-09-18 09:26:56 +03:00
|
|
|
};
|
|
|
|
|
2019-09-18 11:20:29 +03:00
|
|
|
/**
|
|
|
|
* ParagraphStateAtSelection class gets format block types around selection.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS ParagraphStateAtSelection final {
|
|
|
|
public:
|
|
|
|
ParagraphStateAtSelection() = delete;
|
|
|
|
ParagraphStateAtSelection(HTMLEditor& aHTMLEditor, ErrorResult& aRv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetFirstParagraphStateAtSelection() returns:
|
|
|
|
* - nullptr if there is no format blocks nor inline nodes.
|
|
|
|
* - nsGkAtoms::_empty if first node is not in any format block.
|
|
|
|
* - a tag name of format block at first node.
|
|
|
|
* XXX See the private method explanations. If selection ranges contains
|
|
|
|
* non-format block first, it'll be check after its siblings. Therefore,
|
|
|
|
* this may return non-first paragraph state.
|
|
|
|
*/
|
|
|
|
nsAtom* GetFirstParagraphStateAtSelection() const {
|
|
|
|
return mFirstParagraphState;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If selected nodes are not in same format node nor only in no-format blocks,
|
|
|
|
* this returns true.
|
|
|
|
*/
|
|
|
|
bool IsMixed() const { return mIsMixed; }
|
|
|
|
|
|
|
|
private:
|
Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once. Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.
For the former case, we should sort out it with
`EditorUtils::IsEditableContent()`, but for now, this patch moves it to
`HTMLEditUtils::IsSimplyEditable()`. On the other hand, for the latter case,
we obviously has a bug. Therefore, this patch creates
`HTMLEditUtils::IsRemovableFromParentNode()` and make it check whether the
removing node is also editable.
Unfortunately, `EditorUtils::IsEditableContent()` needs to take editor type.
But it's most callers are in `HTMLEditor` and most of remains are in
common methods of `EditorBase`. I guess we could remove this ugly argument
in the future.
Depends on D70874
Differential Revision: https://phabricator.services.mozilla.com/D70875
--HG--
extra : moz-landing-system : lando
2020-04-15 18:27:38 +03:00
|
|
|
using EditorType = EditorBase::EditorType;
|
|
|
|
|
2019-09-18 11:20:29 +03:00
|
|
|
/**
|
|
|
|
* AppendDescendantFormatNodesAndFirstInlineNode() appends descendant
|
|
|
|
* format blocks and first inline child node in aNonFormatBlockElement to
|
|
|
|
* the last of the array (not inserting where aNonFormatBlockElement is,
|
|
|
|
* so that the node order becomes randomly).
|
|
|
|
*
|
2020-02-12 08:52:30 +03:00
|
|
|
* @param aArrayOfContents [in/out] Found descendant format blocks
|
2019-09-18 11:20:29 +03:00
|
|
|
* and first inline node in each non-format
|
|
|
|
* block will be appended to this.
|
|
|
|
* @param aNonFormatBlockElement Must be a non-format block element.
|
|
|
|
*/
|
|
|
|
static void AppendDescendantFormatNodesAndFirstInlineNode(
|
2020-02-12 08:52:30 +03:00
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents,
|
|
|
|
dom::Element& aNonFormatBlockElement);
|
2019-09-18 11:20:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CollectEditableFormatNodesInSelection() collects only editable nodes
|
|
|
|
* around selection ranges (with
|
|
|
|
* `HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges()`, see its
|
|
|
|
* document for the detail). If it includes list, list item or table
|
|
|
|
* related elements, they will be replaced their children.
|
|
|
|
*/
|
|
|
|
static nsresult CollectEditableFormatNodesInSelection(
|
2020-02-12 08:52:30 +03:00
|
|
|
HTMLEditor& aHTMLEditor,
|
|
|
|
nsTArray<OwningNonNull<nsIContent>>& aArrayOfContents);
|
2019-09-18 11:20:29 +03:00
|
|
|
|
|
|
|
RefPtr<nsAtom> mFirstParagraphState;
|
|
|
|
bool mIsMixed = false;
|
|
|
|
};
|
|
|
|
|
2017-08-04 09:01:36 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
mozilla::HTMLEditor* nsIEditor::AsHTMLEditor() {
|
2021-06-11 06:01:08 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsHTMLEditor());
|
|
|
|
return static_cast<mozilla::HTMLEditor*>(this);
|
2017-08-04 00:18:50 +03:00
|
|
|
}
|
|
|
|
|
2017-08-04 09:01:36 +03:00
|
|
|
const mozilla::HTMLEditor* nsIEditor::AsHTMLEditor() const {
|
2021-06-11 06:01:08 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsHTMLEditor());
|
|
|
|
return static_cast<const mozilla::HTMLEditor*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::HTMLEditor* nsIEditor::GetAsHTMLEditor() {
|
|
|
|
return AsEditorBase()->IsHTMLEditor() ? AsHTMLEditor() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const mozilla::HTMLEditor* nsIEditor::GetAsHTMLEditor() const {
|
|
|
|
return AsEditorBase()->IsHTMLEditor() ? AsHTMLEditor() : nullptr;
|
2017-08-04 00:18:50 +03:00
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
#endif // #ifndef mozilla_HTMLEditor_h
|