Commit Graph

291 Commits

Author SHA1 Message Date
Masayuki Nakano
7f8df77fb6 Bug 1465702 - part 1: Add EditorBase::AutoEditActionDataSetter to store edit action and grab Selection instance while editor classes handle an edit action r=m_kato
Like TextEditRules, EditorBase should have a stack class which cache necessary
objects and current handling edit action.  The edit action will be necessary
when we implement InputEvent.inputType.

Different from TextEditRules, this adds |const RefPtr<Selection>&| instead
of |Selection&|.  The reason is, when I add MOZ_CAN_RUN_SCRIPT to some methods,
it's not allowed like this:

> foo->CanRunScriptMethod(SelectionRef());

I'll update TextEditRules for consistency in the following patches.

Differential Revision: https://phabricator.services.mozilla.com/D10005

--HG--
extra : moz-landing-system : lando
2018-10-30 09:56:41 +00:00
Masayuki Nakano
cb95d44ffc Bug 1500862 - part 3: Change all stack base helper classes which access protected members of EditorBase to nested classes of EditorBase r=m_kato
AutoTransactionBatch, AutoPlaceholderBatch, AutoSelectionRestorer,
AutoTopLevelEditSubActionNotifier, AutoTransactionsConserveSelection and
AutoUpdateViewBatch access protected members of EditorBase.  The access
scope management assume that they are used only by EditorBase or its
subclasses or TextEditRules or its inherited class (i.e., HTMLEditRules).

For guaranteeing this at build-time, we should change them to nested classes
of EditorBase.  Then, EditorBase and its subclasses and friends can use them.

Differential Revision: https://phabricator.services.mozilla.com/D9479

--HG--
extra : moz-landing-system : lando
2018-10-24 09:42:06 +00:00
Makoto Kato
eed71e1db2 Bug 1487301 - Part 1. FindSelectionRoot should return Element. r=masayuki
FindSelectionRoot isn't const method and returns already_AddRefed<nsIContent>.
But this method doesn't modify any members and nodes, so we can change to const
method

Also, this method already returns Element, so it shouldn't return nsIContent.

Differential Revision: https://phabricator.services.mozilla.com/D6373

--HG--
extra : rebase_source : d4a5dbe96dfc0a71b39f3d5c6d1a4c7ce85f4fa9
2018-09-20 18:53:35 +09:00
Masayuki Nakano
4bf13b90c7 Bug 1483132 - Make EditorBase::AreNodesSameType() non-virtual r=m_kato
EditorBase::AreNodesSameType() is overridden only by HTMLEditor and the
implementation is enough simple to re-implement in EditorBase.

Additionally, this is called from condition of a loop in
JoinNodesDeepWithTransaction().  So, the virtual call cost may make damage
to the performance.

Differential Revision: https://phabricator.services.mozilla.com/D3460

--HG--
extra : moz-landing-system : lando
2018-08-16 10:29:20 +00:00
Masayuki Nakano
b8fd63d7b5 Bug 1482020 - Make all callers of CreateElementWithDefaults() use non-virtual method r=m_kato
Fortunately, despite of becoming public method,
HTMLEditor::CreateElementWithDefaults() can be used by internal methods too
since it does not touch undo transactions nor the DOM tree, and does not
refer mRules nor GetSelection().  So, we can make it public and make any
C++ callers use it.
2018-08-10 19:36:24 +09:00
Masayuki Nakano
89e5796790 Bug 1482007 - part 1: Create a helper class to guarantee to call nsIEditor::EndTransaction() after nsIEditor::BeginTransaction() call r=m_kato
This patch also creates non-virtual methods,
EditorBase::BeginTransactionInternal(), EditorBase::EndTransactionInternal(),
TransactionManager::BeginBatchInternal() and
TransactionManager::EndBatchInternal().

Although, this could be replaced with API to use PlaceholderTransaction,
we should investigate it when we have much time.

Differential Revision: https://phabricator.services.mozilla.com/D2989

--HG--
extra : moz-landing-system : lando
2018-08-09 11:45:41 +00:00
Masayuki Nakano
2413e81af0 Bug 1480666 - Make EditorBase::EndUpdateViewBatch() non-virtual r=m_kato
Although HTMLEditor::EndUpdateViewBatch() calls a method of nsIHTMLEditor,
the additional work after calling EditorBase::EndUpdateViewBatch() is enough
simple. So, we can move the implementation in HTMLEditor to EditorBase and
make it non-virtual.

Differential Revision: https://phabricator.services.mozilla.com/D2705

--HG--
extra : moz-landing-system : lando
2018-08-06 04:42:39 +00:00
Masayuki Nakano
45a67c4b77 Bug 1480663 - Make EditorBase::IsModifiableNode() non-virtual r=m_kato
HTMLEditor::IsModifiableNode() is enough simple and can be checked in
EditorBase. So, we should make it non-virtual and check if instance is
HTMLEditor in EditorBase::IsModifiableNode().

Differential Revision: https://phabricator.services.mozilla.com/D2706

--HG--
extra : moz-landing-system : lando
2018-08-03 11:10:46 +00:00
Masayuki Nakano
4292293e8c Bug 1480055 - part 3: Create non-virtual method to set EditorBase::mAllowsTransactionsToChangeSelection r=m_kato
There is no non-virtual method to modify
EditorBase::mAllowsTransactionsToChangeSelection.  Therefore,
AutoTransactionsConserveSelection calls virtual method,
nsIEditor::SetShouldTxnSetSelection() twice (from both constructor and
destructor).  So, we should save this unnecessary cost.

MozReview-Commit-ID: B7TYGnGtuLB

--HG--
extra : rebase_source : 26ce77fb63a1967cca88b002cd65e1105477a63d
2018-08-01 21:11:44 +09:00
Masayuki Nakano
a9559a1d82 Bug 1480055 - part 2: Rename EditorBase::GetShouldTxnSetSelection() to EditorBase::AllowsTransactionsToChangeSelection() r=m_kato
For explaining what it does clearer, we should rename it and corresponding
member.

MozReview-Commit-ID: 6U8FgfHBbCL

--HG--
extra : rebase_source : 50bc3ce0d3b9900939c7e6e8a137abe2288cf727
2018-08-01 20:53:57 +09:00
Masayuki Nakano
470feacd31 Bug 1480055 - part 1: Remove nsIEditor::shouldTxnSetSelection() r=m_kato
nsIEditor::ShouldTxnSetSelection() is used only by DeleteRangeTransaction
(even if including comm-central and BlueGriffon) and there is a non-virtual
method EditorBase::GetShouldTxnSetSelection().  So, we can remove this.

MozReview-Commit-ID: JWSCw9k6lI0

--HG--
extra : rebase_source : 2509274216a1493134757a7d106464f06ea0ba57
2018-08-01 20:16:30 +09:00
Makoto Kato
a8ca18700d Bug 1479383 - Use const method for some GetEditorRoot methods. r=masayuki
Some methods to get editor root etc has unnecessary refcounting and it isn't
const method.  So we should remove unnecessary refcounting and change to
const method.

Differential Revision: https://phabricator.services.mozilla.com/D2499

--HG--
extra : moz-landing-system : lando
2018-07-30 10:35:43 +00:00
Masayuki Nakano
91c0a26b3f Bug 1467802 - part 3: Create EditorBase::GetDocumentCharsetInternal() for internal use of nsIEditor::GetDocumentCharacterSet() r=m_kato
This patch creates non-virtual method, EditorBase::GetDocumentCharsetInternal(),
for internal use of nsIEditor::GetDocumentCharacterSet() since the virtual
call method is redundant and the caller cannot be marked as const.

MozReview-Commit-ID: v6kDo2eKg3

--HG--
extra : rebase_source : 07f6dd8341cb6686835db2ee3ded479323cccca9
2018-07-18 21:11:32 +09:00
Masayuki Nakano
85b94e287c Bug 1467802 - part 2: Mark TextEditor::GetAndInitDocEncoder() as const r=m_kato
TextEditor::GetAndInitDocEncoder() modifies only mCachedDocumentEncoder and
mCachedDocumentEncoderType which are cache of the method to save recreation
cost of document encoder when same type document encoder is requested.

So, with marking them mutable, we can change the method to a const method.

MozReview-Commit-ID: 80W0NtQhJOR

--HG--
extra : rebase_source : 84f4b49fe3a3124c0de99b39a2141a8cee553e54
2018-07-18 20:51:55 +09:00
Makoto Kato
16910a6e95 Bug 1443902 - Reinitilize selection after destroying nsIEditingSession. r=masayuki
When setting contenteditable to false, editing session destroys HTMLEditor.
Destroying HTMLEditor means that selection visibility is reset by
FinalizeSelection.

So after calling TearDownEditorOnWindow on nsHTMLDocument, we should initialize
selection visibility if current focus is text control that has editor.

MozReview-Commit-ID: 4V8kZtOtKO3

--HG--
extra : rebase_source : 9d90c12b3c93e4dfd95095ce29a26e5fdd83f952
2018-07-09 16:53:47 +09:00
Ciure Andrei
b37e54e443 Backed out 1 changesets (bug 1443902) for reftest failures reftest/tests/editor/reftests/1443902-2.html CLOSED TREE
Backed out changeset 4c31558d3481 (bug 1443902)
2018-07-10 05:50:31 +03:00
Makoto Kato
98611161ee Bug 1443902 - Reinitilize selection after destroying nsIEditingSession. r=masayuki
When setting contenteditable to false, editing session destroys HTMLEditor.
Destroying HTMLEditor means that selection visibility is reset by
FinalizeSelection.

So after calling TearDownEditorOnWindow on nsHTMLDocument, we should initialize
selection visibility if current focus is text control that has editor.

MozReview-Commit-ID: 4V8kZtOtKO3

--HG--
extra : rebase_source : 773c06bb22cf2da24fd11be9be8d7b0376da3e36
2018-07-09 16:53:47 +09:00
Masayuki Nakano
2b43129579 Bug 1473515 - Make AutoDisableUndo restores enabled state of undo/redo with previous number of maximum transactions r=m_kato
Calling EditorBase::EnableUndoRedo() without argument means that editor supports
unlimited undo/redo stack.  AutoDisableUndo class calls it without argument
when it needs to restore undo/redo feature.

However, <input type="text"> and <textarea> limits number of maximum
transactions up to 1,000, perhaps for footprint.  So, AutoDisableUndo should
store the last number of maximum transactions before disabling undo/redo from
the constructor.

MozReview-Commit-ID: CoI6ZXyTd3X

--HG--
extra : rebase_source : e2b9af17e5857dcc0a6781e254e45fdb790c9a9e
2018-07-05 19:44:23 +09:00
Emilio Cobos Álvarez
6a2e3606ae Bug 1470361: Remove nsIEditorStyleSheets.addStyleSheet / removeStyleSheet / replaceStyleSheet. r=m_kato
These are effectively equivalent to appending a <link> element to the body, are
not unused, and bring in a fair amount of complexity because even though they're
owned by the document and stored in the document's mStyleSheets, they're not
owned by it per se, which causes confusion.

Unless I've missed something, both bluegriffon and common-central use the
*Override APIs, which this patch leaves untouched.

MozReview-Commit-ID: EOSMOHj3A95
2018-06-25 10:46:38 +02:00
Masayuki Nakano
65a183e7d5 Bug 1467692 - Create EditorBase::SelectAllInternal() for internal use r=m_kato
For preparing to fix bug 1465702, we need to split public methods of editor
which are used by both outside and itself or friends.

SelectAll() is used by both outside and TextEditor.  So, we need to create
SelectAllInternal() and make TextEditor use it instead.

MozReview-Commit-ID: JtIlrfBYBSD

--HG--
extra : rebase_source : 5c29a9c1bb99f457f66f320b873b2c7b0f93fcde
2018-06-07 22:30:14 +09:00
Ryan VanderMeulen
8e415eb4c0 Merge m-c to autoland. a=merge 2018-06-09 11:41:36 -04:00
Masayuki Nakano
235de70472 Bug 1467693 - Merge EditorBase::SwitchTextDirection() and EditorBase::SwitchTextDirectionTo() r=m_kato
There are two similar methods, but they are created with copy & paste.
So, the common code should be merged into new method, SetTextDirection().

Additionally, EditorBase::SwitchTextDirection() is a scriptable method but
nobody uses this from JS.  So, we can make it from nsIEditor and this
patch renames it to ToggleTextDirection() since current name is too
similar to SwitchTextDirectionTo().

MozReview-Commit-ID: BX3M1OKxiD5

--HG--
extra : rebase_source : 74a5ff65adc96ba69792f2e63daf14828c505270
2018-06-07 23:26:59 +09:00
Masayuki Nakano
a6f0eec408 Bug 1467691 - Make some methods of EditorBase non-public r=m_kato
This moves NotifyEditorObservers() and GetInputEventTargetContent() into
protected member which should not be used by friends.

And also this moves IsModifiableNode() into protected member which can be
used by friends.

MozReview-Commit-ID: AxDBgTVED3V

--HG--
extra : rebase_source : 979c6cb0d075b3fd0106bd1c381aa3ef3b98ba78
2018-06-06 13:30:44 +09:00
Olli Pettay
5dad9cd69b Bug 1467790 - Inline nsINode::IsEditable, r=masayuki 2018-06-08 15:57:13 -04:00
Makoto Kato
ef31f52f39 Bug 1467670 - Devirtualize InsertFromDrop. r=masayuki
InsertFromDrop is implemented on TextEditor only, so it can do devirtualize
this method.  Also, this method is only called by drop event handler of
EditorEventListener, so it should rename to better name (OnDrop).

Differential Revision: https://phabricator.services.mozilla.com/D1592
2018-06-08 05:19:51 +00:00
Masayuki Nakano
82c12dc72d Bug 1463985 - part 2: Rename EditSubAction::none to EditSubAction::eNone r=m_kato
MozReview-Commit-ID: 4wJyaNS1P1y

--HG--
extra : rebase_source : 169e2faffa25ed42875c8dccb5c49ae5aaa54ebb
2018-05-28 20:29:34 +09:00
Masayuki Nakano
99341a9445 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 20:12:34 +09:00
Boris Zbarsky
c73f664888 Bug 1463981 part 3. Remove nsIDOMNode usage in editor. r=masayuki 2018-05-24 13:18:34 -04:00
Masayuki Nakano
11ae2207cf Bug 1463327 - part 4: Add comments to explain which kind of methods should be public methods r=m_kato
MozReview-Commit-ID: 6l8ZiMWEYCI

--HG--
extra : rebase_source : 024625012c917b17710016b91db10bfbaace2134
2018-05-22 20:15:05 +09:00
Masayuki Nakano
40ab33fe29 Bug 1463327 - part 1: Change scope of some methods of EditorBase which won't be called by non-helper classes of editing to protected r=m_kato
EditorBase (and other editor classes) have 2 type of public methods.  One is
true-public methods.  I.e., they should be able to be called by anybody.
E.g., command handlers, event listeners, or JS via nsIEditor interface.
The other is semi-public methods.  They are not called by the above examples
but called by other classes which are helper classes to handle edit actions.
E.g., TextEditRules, HTMLEditRules, HTMLEditUtils, CSSEditUtils and Transaction
classes.

When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData).  Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.

For preventing this issue, we should make EditorBase have only the true-public
methods as public.  The other public methods should be protected and their
users should be friend classes.  Then, we can protect such method from external
classes.

Note that this patch just moves the methods without any changes in EditorBase.h
(except removes GetName() since there is no body of this method and removes
IterDirection since it's unused).

MozReview-Commit-ID: HBseKLL6pxx

--HG--
extra : rebase_source : 2251ff659d831d01a6778d38f4e2714fcf2d6ef4
2018-05-22 16:08:43 +09:00
Makoto Kato
71b2579c1e Bug 1463330 - Move CanPasteTransferable and PreDestroy to out of nsIEditor. r=masayuki
CanPasteTransferable and PreDestroy aren't used from script (inc. comm-central
and bluegriffon), so we should move these to out of nsIEditor.

MozReview-Commit-ID: GRfBobAm2qi

--HG--
extra : rebase_source : 812792ff43da24bfd9cb99c4b3127e6acdc43ba1
2018-05-22 18:23:21 +09:00
Masayuki Nakano
5f8ba21730 Bug 1457083 - part 1: Make public methods of TextEditUtils and HTMLEditUtils guarantee that the editor instance and selection instance won't be destroyed while it handles any edit actions r=m_kato
This patch creates a stack class in TextEditRules, its name is
AutoSafeEditorData and make all public methods (except editor observer methods)
which may change DOM tree, fire some DOM events or calling some XPCOM listeners
create its instance in the stack.  Then, it grabs associated editor instance
and its selection instance.

Next patch will make remaining public methods create AutoSafeEditorData.

MozReview-Commit-ID: 8oshdhL3ONQ

--HG--
extra : rebase_source : 591db71e45fe28ca93cbebd9bb7da8c16eae4466
2018-04-26 22:41:34 +09:00
Adrian Wielgosik
3a8ef6cf8a Bug 1460940 - Remove nsIDOMDocument uses in editor/. r=bz
MozReview-Commit-ID: 8doC9drkrG9

--HG--
extra : rebase_source : 24ac8ea960faff10b04ef0f419bc6dc7b6556452
2018-05-11 19:46:15 +02:00
Boris Zbarsky
46cae9462a Bug 1387143 part 3. Stop using nsISelection in nsISelectionController. r=mats 2018-05-08 13:52:36 -04:00
Makoto Kato
db7992dc59 Bug 1457431 - Devirtualize mozInlineSpellChecker::SpellCheckAfterEditorChange. r=masayuki
It is unnecessary to keep virtual method for
mozInlineSpellChecker::SpellCheckAfterEditorChange, so we should remove virtual
keyword.

MozReview-Commit-ID: 2ry5uhMTFVC

--HG--
extra : rebase_source : ba86bb7c4e47598f83e3869733a238a740cef6b2
2018-04-27 21:11:31 +09:00
Boris Zbarsky
2348052be1 Bug 1455674 part 3. Stop using nsIDOMElement in nsITableEditor. r=masayuki
The patch is a bit large because all these methods except
SswitchTableCellHeaderType call each other; doing it piecemeal would have
required introducing, then removing, a bunch of QIs.
2018-04-26 23:35:18 -04:00
Boris Zbarsky
c9bcb72283 Bug 1455674 part 1. Stop using nsIDOMElement in nsIEditor. r=masayuki 2018-04-26 23:35:18 -04:00
Masayuki Nakano
552423e58f Bug 1456377 - Move composition event handlers from EditorBase to TextEditor r=m_kato
Currently, EditorBase handles most composition events.  However, only
eCompositionChange event handler is in TextEditor and it's the main event
of handling composition.  Therefore, we should make all composition event
handlers in one place for easier to read, and make them non-virtual.

MozReview-Commit-ID: BYDhiPyGKvo

--HG--
extra : rebase_source : ed9db0f49d7ae268c85359e48015e86584f9c999
2018-04-19 00:31:51 +09:00
Makoto Kato
da20106275 Bug 1455533 - Part 2. Devirtualize EditorBase::PostCreate. r=masayuki
No one uses postCreate from script even if c-c and BlueGriffon. So we should
devirtualize this

MozReview-Commit-ID: D3FKVEvG7Go

--HG--
extra : rebase_source : 9915a93ea8ae18bee251507a4c94fe66c0f03d0f
2018-04-20 16:40:24 +09:00
Makoto Kato
bda5448bb6 Bug 1455533 - Part 1. Devirtualize EditorBase::SyncRealTimeSpell. r=masayuki
No one uses syncRealTimeSpell from script even if c-c and BlueGriffon. So
we should devirtualize this

MozReview-Commit-ID: AoOb165dOFa

--HG--
extra : rebase_source : e1a9dcdfa6cfe6c918a06a2738c38a6cb9441a1d
2018-04-20 16:27:16 +09:00
Masayuki Nakano
5af458988b Bug 1451672 - part 18: Rename EditorBase::CloneAttributes() to EditorBase::CloneAttributesWithTransaction() r=m_kato
MozReview-Commit-ID: 5tL31gRDVc9

--HG--
extra : rebase_source : dede345becde79dd9363f1df1980715713a80ef1
2018-04-13 18:44:08 +09:00
Masayuki Nakano
3da9675a5e Bug 1451672 - part 17: Rename EditorBase::InsertContainerAbove() to EditorBase::InsertContainerWithTransactionInternal() and wraps it with new inline methods, EditorBase::InsertContainerWithTransaction() r=m_kato
Similar to EditorBase::ReplaceContainerWithTransaction(),
EditorBase::InsertContainerAbove() may set an attribute to newly created element
if it's specified.  However, for avoiding the null check, let's make them
as references rather than pointers and treat nsGkAtoms::_empty as nullptr for
making the code safer.

This patch removes "Above" from the method name since it's redundant.
"Insert" sounds like inserting a node, and "Container" means to keep existing
children with new element in EditorBase.

MozReview-Commit-ID: 6EnkKHynYSP

--HG--
extra : rebase_source : d4b4c1a611c46a0f4d86389aab3331af565199d2
2018-04-13 18:17:04 +09:00
Masayuki Nakano
2d04b175d7 Bug 1451672 - part 16: Rename EditorBase::MoveNode() to EditorBase::MoveNodeWithTransaction() and create EditorBase::MoveNodeToEndWithTransaction() r=m_kato
This patch renames EditorBase::MoveNode() to
EditorBase::MoveNodeWithTransaction() and redesign its parameters including
replacing a set of container node and offset in it to EditorDOMPointBase.
However, it takes magic number -1 as meaning end of the container.
Therefore, this patch adds MoveNodeToEndWithTransaction() for keeping the
callers simple.

MozReview-Commit-ID: BeTq5c7GQNN

--HG--
extra : rebase_source : b3a617a5a1a493cb0fcbefe2d9a9708b0257b1a8
2018-04-12 23:58:52 +09:00
Masayuki Nakano
71964e6004 Bug 1451672 - part 15: Rename EditorBase::RemoveContainer() and HTMLEditor::RemoveBlockContainer() with "WithTransaction" postfix and make their argument |Element&| r=m_kato
MozReview-Commit-ID: 2toj48mqHM9

--HG--
extra : rebase_source : 621cb7a3137137dab45c311836b8304e7bd772f2
2018-04-12 22:23:04 +09:00
Masayuki Nakano
b7fe9939db Bug 1451672 - part 14: Rename EditorBase::ReplaceContainer() to EditorBase::ReplaceContainerWithTransactionInternal() and create some wrappers of it r=m_kato
The parameters of EditorBase::ReplaceContainer() are complicated.  For example,
if it's specified as cloning all attributes, aAttribute and aValue are ignored
because CloneAttributes() removes all existing attributes but ReplaceContainer()
sets attributes before calling CloneAttributes().  This method has 3 modes:
1. Just replaces aOldContainer with new element.
2. #1 and clones all attributes from aOldContainer to the new element.
3. #1 and sets aAttribute of the new element to aValue.

Therefore, this patch creates 3 inline wrappers of the renamed method.

MozReview-Commit-ID: IsPu2uZuU8f

--HG--
extra : rebase_source : 02a23f48a91e0c9558126552a4c8d4b12c8b76bc
2018-04-12 21:45:55 +09:00
Masayuki Nakano
e31bcb6efe Bug 1451672 - part 13: Rename EditorBase::InsertTextImpl() and EditorBase::InsertTextIntoTextNodeImpl() to EditorBase::InsertTextWithTransaction() and EditorBase::InsertTextIntoTextNodeWithTransaction() r=m_kato
MozReview-Commit-ID: DF3HBVyu4P2

--HG--
extra : rebase_source : 1ce6c2b005c06df340524d2d617673f4ce93df07
2018-04-12 17:58:14 +09:00
Masayuki Nakano
bd0aa50472 Bug 1451672 - part 11: Rename EditorBase::SetAttribute(), EditorBase::RemoveAttribute() and EditorBase::CloneAttribute() with "WithTransaction" postfix r=m_kato
MozReview-Commit-ID: I8T9MNkY8Yq

--HG--
extra : rebase_source : 767e52098233c5f6a2c0e7efca433ddd9f246749
2018-04-12 16:58:33 +09:00
Masayuki Nakano
80c2ea82ed Bug 1451672 - part 9: Create TextEditor::DeleteSelectionAsAction() as implementation of nsIEditor::DeleteSelection() r=m_kato
First, EditorBase::DeleteSelection() is never used since
TextEditor::DeleteSelection() overrides it but does not call it.  So, this patch
makes EditorBase::DeleteSelection() only returns NS_ERROR_NOT_IMPLEMENTED.

Next, EditorBase::DeleteSelectionImpl() actually removes content for
TextEditor::DeleteSelection().  So, it should be named as
DeleteSelectionWithTransaction().  However, it'll be done in the following
patch.  On the other hand, its callers are EditorBase::HandleKeyPressEvent()
and EditorBase::DeleteSelectionAndPrepareToCreateNode().  Fortunately, they
can be moved to TextEditor simply.  Therefore this patch moves the methods
to TextEditor for making related methods in a place.

Then, we can make the implementation of nsIEditor::TextEditor() as a non-virtual
method, TextEditor::DeleteSelectionAsAction().

MozReview-Commit-ID: KXFDhW3G9lA

--HG--
extra : rebase_source : 15986979279b2cae3b61cda1bf6bf3d9e4987f3f
2018-04-11 17:37:49 +09:00
Masayuki Nakano
526463cade Bug 1451672 - part 8: Rename EditorBase::DeleteText() to EditorBase::DeleteTextWithTransaction() r=m_kato
MozReview-Commit-ID: KK4dTpKbpLc

--HG--
extra : rebase_source : 060e5183efd6570cbdd59429552b318fd3865d54
2018-04-10 16:50:06 +09:00
Masayuki Nakano
0a1cfd5226 Bug 1451672 - part 7: Rename EditorBase::DeleteNode() to EditorBase::DeleteNodeWithTransaction() r=m_kato
MozReview-Commit-ID: AQVVTjfXJv

--HG--
extra : rebase_source : 9678e8f2e16c9ec193e292c577912b6df7782202
2018-04-10 16:23:54 +09:00
Masayuki Nakano
7a1b5de42f Bug 1451672 - part 6: Rename EditorBase::JoinNodesImpl() to EditorBase::DoJoinNodes() r=m_kato
MozReview-Commit-ID: 9fqa4fKkAF5

--HG--
extra : rebase_source : 6ec753824488235a03677ef1238aabe607b7d786
2018-04-10 03:56:46 +09:00
Masayuki Nakano
8b1e0b6b9c Bug 1451672 - part 5: Rename EditorBase::JoinNodes() and related methods with "WithTransaction" postfix r=m_kato
This patch renames:
EditorBase::JoinNodes() -> EditorBase::JoinNodesWithTransaction()
EditorBase::JoinNodeDeep() -> EditorBase::JoinNodesDeepWithTransaction()
HTMLEditRules::JoinNodesSmart() ->
  HTMLEditRules::JoinNearestEditableNodesWithTransaction()
HTMLEditRules::TryToJoinBlocks() ->
  HTMLEditRules::TryToJoinBlocksWithTransaction()

MozReview-Commit-ID: Ao16GhAcyIZ

--HG--
extra : rebase_source : 6746735c339cf2799e94137de87c7a7dce6efded
2018-04-10 03:46:44 +09:00
Masayuki Nakano
a1a45ac179 Bug 1451672 - part 4: Rename EditorBase::SplitNodeImpl() to EditorBase::DoSplitNode() r=m_kato
EditorBase::SplitNodeImpl() is called by SplitNodeTransaction::DoTransaction()
for actually splitting a node.  However, "WithoutTransaction" postfix is really
redundant.  Perhaps, just naming DoSplitNode() is better since "Impl" isn't
unclear and not useful if somebody wants to use it as a utility method and
there has already been EditorBase::SplitNode() which is an override of
nsIEditor::SplitNode().  It must not be good to use same name for different
purpose (EditorBase::SplitNode() creates a transaction).

MozReview-Commit-ID: Akjeyp52vVv

--HG--
extra : rebase_source : dcb29cec2749431b59068b670b68e5cd61b18588
2018-04-10 02:32:33 +09:00
Masayuki Nakano
7967ef5834 Bug 1451672 - part 3: Rename EditorBase::SplitNode() and related methods to ending with "WithTransaction" r=m_kato
This patch renames:
EditorBase::SplitNode() -> EditorBase::SplitNodeWithTransaction()
EditorBase::SplitNodeDeep() -> EditorBase::SplitNodeDeepWithTransaction()
HTMLEditRules::MaybeSplitAncestorsForInsert() ->
  HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction()

Note it might be that some callers of those methods should be renamed too.
However, we should do it in follow up bug after landing those patches since
we can investigate it with searchfox.org after landing patches.

MozReview-Commit-ID: FfxCfaI85z5

--HG--
extra : rebase_source : 143960de45791c72dbf4d436f65e55452b4f7b10
2018-04-10 02:16:49 +09:00
Masayuki Nakano
49d8961486 Bug 1451672 - part 2: Rename EditorBase::InsertNode() to EditorBase::InsertNodeWithTransaction() r=m_kato
MozReview-Commit-ID: 4n5EVvUKrux

--HG--
extra : rebase_source : ebee5f0b1da029866653112546973a3bdc9e8e01
2018-04-10 01:34:29 +09:00
Masayuki Nakano
b78528ad78 Bug 1451672 - part 1: Rename EditorBase::CreateNode() to EditorBase::CreateNodeWithTransaction() r=m_kato
EditorBase::CreateNode() creates an element node with transaction.  I.e., it's
undoable.  So, if somebody would use this method as a helper method for changing
the DOM tree, that would cause unexpected undoable transaction.  So, we should
make the method name clearer to avoid such bug.

MozReview-Commit-ID: GZsOGBfqog

--HG--
extra : rebase_source : 8b7539a680ee88f3557acb0837fe1a021d842323
2018-04-10 01:17:26 +09:00
Dorel Luca
65669dae30 Merge mozilla-inbound to mozilla-central. a=merge 2018-04-21 02:00:04 +03:00
Boris Zbarsky
945feaec17 Bug 1455052 part 6. Stop using nsIDOMEvent in editor code. r=masayuki
MozReview-Commit-ID: JoP6kMuYQLQ
2018-04-20 12:53:17 -04:00
Masayuki Nakano
9000054fed Bug 1454945 - Get rid of nsIEditor.suppressDispatchingInputEvent since nobody uses it from JS r=m_kato
So, this patch replaces the setter with non-virtual method and removing the
getter since where is already non-virtual getter method.

MozReview-Commit-ID: Is19Yriz8t8

--HG--
extra : rebase_source : bb2f49f380ddb2e2f96e8690effd8d47d24ae0ae
2018-04-18 22:57:41 +09:00
Makoto Kato
5d349b958c Bug 1442499 - EditorBase::IsPreformatted should return bool. r=masayuki
It is unnecessary to get PresShell for nsStyleText, so we can return bool
instead of nsresult and can change it to static method.

MozReview-Commit-ID: LGrdcaJuLO

--HG--
extra : rebase_source : bb6b6d990741c7b478e9699ae84cc6b89a765bf7
2018-04-17 13:08:51 +09:00
Makoto Kato
6c2bc77ccf Bug 1451972 - Remove more nsIDOMDocument usages from editor. r=masayuki
We should not use nsIDOMDocument if unnecessary. Because it needs QI to access
nsIDocument.

MozReview-Commit-ID: CMF3tmvBTB9

--HG--
extra : rebase_source : e832023be8d59a2c1e01bd423e6f058b0708dfe9
2018-04-06 14:53:05 +09:00
Makoto Kato
8c5d5f7c30 Bug 1449147 - Clean up more nsIDOMNode usages in editor. r=masayuki
To reduce QI, I would like to replace nsIDOMNode with nsINode.  And some
parameters in *DataTransder.cpp's methods is unused (it uses as nullptr),
so we should remove these parameters.

Also nsIDOMNodeList is unused now, so we should remove this including.

MozReview-Commit-ID: 1QTIkxDazjJ

--HG--
extra : rebase_source : 3961e897fcaa96975facc822821f1e223cab358d
2018-03-27 20:19:35 +09:00
Masayuki Nakano
52cffc3290 Bug 1447924 - part 7: Implement AddTransactionListener() and RemoveTransactionListener() in EditorBase and TransactionManager r=m_kato
nsITransactionListener::AddListener() and
nsITransactionListener::RemoveListener() are of course virtual methods.
Additionally, they are safe to call without grabbing the TransactionManager's
instance with local variable.  Therefore, if EditorBase has methods to
add/remove transaction listener to/from its transaction manager, we don't
need EditorBase::GetTransactionManager() anymore.

So, this patch adds AddTransactionListener() and RemoveTransactionListener() to
EditorBase and TransactionManager, and remove
EditorBase::GetTransactionManager() (not nsIEditor's one).

MozReview-Commit-ID: FkPa1YgfagD

--HG--
extra : rebase_source : 8ef7796136804e3d7604c5ca5417fb3379606b93
2018-03-23 18:55:56 +09:00
Masayuki Nakano
f882fa6959 Bug 1447924 - part 6: Implement EnableUndoRedo(), DisableUndoRedo() and ClearUndoRedo() in EditorBase and TransactionManager r=m_kato
nsIEditor::EnableUndo() and nsITransactionManager::Clear(),
nsITransactionManager::SetMaxTransactionCount() are called a lot but they are
virtual and some of or all of them are called once.  There should be each
non-virtual method to do what each root caller wants.  Therefore, this patch
adds EditorBase::EnableUndoRedo(), EditorBase::DisableUndoRedo(),
EditorBase::ClearUndoRedo(), TransactionManager::EnableUndoRedo(),
TransactionManager::DisableUndoRedo() and TransactionManager::ClearUndoRedo().

Note that this patch makes TransactionManager won't clear mUndoStack nor
mRedoStack if mDoStack is not empty.  This is checked only by
TransactionManager::SetMaxTransactionCount() but according to the comment,
TransactionManager::Clear(), TransactionManager::UndoStack() and
TransactionManager::RedoStack() should check it too.

MozReview-Commit-ID: 6qBZOQNwdhw

--HG--
extra : rebase_source : 3249137f7acca0b4698713ab732774140bcc27e8
2018-03-23 15:25:13 +09:00
Masayuki Nakano
6273aa5604 Bug 1447924 - part 4: Optimize NumbeOfUndoItems(), NumbeOfRedoItems(), CanUndo() and CanRedo() of EditorBase r=m_kato
Now, both TransactionManager.h and TransactionStack.h are exposed.  So,
TransactionManager::GetNumberOfUndoItems() and
TransactionManager::GetNumberOfRedoItems() can be rewritten with non-virtual
inline methods because they just return mUndoStack.GetSize() and
mRedoStack.GetSize().  Then, we can implement EditorBase::NumbeOfUndoItems(),
EditorBase::NumberOfRedoItems(), EditorBase::CanUndo() and
EditorBase::CanRedo() as inline methods.

MozReview-Commit-ID: 3CJd0VrlvFY

--HG--
extra : rebase_source : 6848d80a395f1c161e10bfb50d15bd63de288095
2018-03-23 00:08:38 +09:00
Masayuki Nakano
c525b695b9 Bug 1447924 - part 1: Rename nsTransactionManager to mozilla::TransactionManager r=m_kato
We should rename nsTransactionManager to mozilla::TransactionManager before
adding new non-virtual methods.

MozReview-Commit-ID: JsivNVfDhex

--HG--
rename : editor/txmgr/nsTransactionManager.cpp => editor/txmgr/TransactionManager.cpp
rename : editor/txmgr/nsTransactionManager.h => editor/txmgr/TransactionManager.h
rename : editor/txmgr/nsTransactionManagerFactory.cpp => editor/txmgr/TransactionManagerFactory.cpp
extra : rebase_source : ff5bf76fec8be8f6a1202c17d488cf6c607d8f03
2018-03-22 22:15:54 +09:00
Masayuki Nakano
537b829474 Bug 1447213 - Change editor methods which take |const EditorRawDOMPoint&| but called with EditorDOMPoint.AsRaw() to template methods r=m_kato
A lot of methods take |const EditorRawDOMPoint&| as their argument.  However,
some of them are called with EditorDOMPoint::AsRaw(). This is not good for
performance because:
1. Needs to create temporary instance of EditorRawDOMPoint.
2. EditorRawDOMPoint::AsRaw() may be used by simple mistake.
3. Such methods may call EditorRawDOMPoint::Offset(), however, it's not copied
   to the original EditorDOMPoint instance.  So, callers may need to compute
   offset again.

So, such methods should be changed to template methods if they are not virtual
method and AsRaw() should be gotten rid of for prevent it looking not expensive.

MozReview-Commit-ID: DAqqW4a2EMS

--HG--
extra : rebase_source : 120b920477fe6e7231271411a00994325acdb842
2018-03-20 14:05:47 +09:00
Boris Zbarsky
b06aa7e061 Bug 1446533 part 1. Rename nsGenericDOMDataNode to CharacterData. r=mystor
This is not renaming the files yet; that will be a separate changeset.

MozReview-Commit-ID: 5TxkEiQlaKF
2018-03-19 15:18:06 -04:00
Masayuki Nakano
24e6e1496b Bug 1445569 - part 4: Get rid of EditorBase::GetStartNodeAndOffset() and EditorBase::GetEndNodeAndOffset() r=m_kato
EditorBase::GetStartNodeAndOffset() and EditorBase::GetEndNodeAndOffset() are
just wrappers of EditorBase::GetStartPoint() and EditorBase::GetEndPoint().
They may *compute* offset in the container node even if some callers don't
need the offset.  Therefore, we should get rid of them and make all callers
use EditorBase::GetStartPoint() or EditorBase::GetEndPoint() directly.

Note that EditorBase::GetStartNodeAndOffset() and
EditorBase::GetEndNodeAndOffset() returns NS_ERROR_FAILURE if
EditorBase::GetStartPoint() or EditorBase::GetEndPoint() returns not set point.
Therefore, checking the result is set equals checking the old nsresult as
an error.

MozReview-Commit-ID: JLwqRMFLjHC

--HG--
extra : rebase_source : 0eb6bf4ba80e8139c6b9f36723d77d23f2b9099e
2018-03-15 21:25:41 +09:00
Boris Zbarsky
145e566cd8 Bug 1444686 part 10. Remove nsIDOMDragEvent::GetDataTransfer. r=mystor
MozReview-Commit-ID: LwKqWBGXVcN
2018-03-13 16:24:00 -04:00
Makoto Kato
492ea93b80 Bug 1443714 - Remove already_AddRefed for GetDocument and GetPresSehll on EditorBase. r=masayuki
It is unnecessary to use already_AddRefed for GetDocument and GetPresShell.
Then, if we remove already_AddRefed, we can replace this with const method.

MozReview-Commit-ID: KTVS0rYrY2i

--HG--
extra : rebase_source : 0199026410fc674f112c960b599a09bc7906cf85
2018-03-07 18:26:00 +09:00
Masayuki Nakano
9d71742b36 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 14:20:25 +09:00
Makoto Kato
75f1d82f9b Bug 1436285 - Part 2. Get a rid of nsIDOMNode version of GetNodeLocation, GetStartNodeAndOffset, GetEndNodeAndOffset and etc. r=masayuki
Remove unused methods...

MozReview-Commit-ID: 4A8924wsEq3

--HG--
extra : rebase_source : dc3cc6c263bdd213e7dd2fb2442ad1ff16662aaf
2018-02-28 11:33:16 +09:00
Boris Zbarsky
b7f2b6976a Bug 1429903 part 3. Remove C++ uses of nsIDOMEventTarget. r=mccr8
MozReview-Commit-ID: 4NdssvnWn0H
2018-04-20 00:49:30 -04:00
Makoto Kato
4bc57cc3ec Bug 1437087 - Call Disconnect on Unlink of cycle collector. r=masayuki 2018-02-21 21:08:17 -05:00
Masayuki Nakano
18912959bd 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 19:01:42 +09:00
Makoto Kato
6e437ccf06 Bug 1436272 - Move noscript methods in nsIEditor to EditorBase. r=masayuki
Since We can use EditorBase/TextEditor/HTMLEditor directly,  we can
movei noscript methods in nsIEditor to each class.

Also, Init is unnecessary to use nsIDOMDocument and nsIContent since method
isn't in IDL.  And some methods are unused now.

MozReview-Commit-ID: D3B6oSlcT0L

--HG--
extra : rebase_source : 6cab2e6e7b4ba8cfb56d8320be24ca4afcbe55fb
extra : amend_source : 1d8c59086a9158a49dd270b64ecf8341ed4002ce
2018-02-07 15:28:04 +09:00
Boris Zbarsky
f60fd673d6 Bug 1432186 part 19. Remove the nsIDOMNode::*_NODE constants. r=mccr8
MozReview-Commit-ID: KvKjeKIOB9K
2018-01-29 23:10:53 -05:00
Boris Zbarsky
323cec654b Bug 1432186 part 13. Remove nsIDOMNode's nextSibling attribute. r=mccr8
MozReview-Commit-ID: DTaivhMORXr
2018-01-29 23:10:51 -05:00
Masayuki Nakano
4b7e512db0 Bug 1433345 - part 4: Make EditorBase derived from nsISelectionListener and notify its owning classes of selection change r=m_kato
This patch makes EditorBase derived from nsISelectionListener.  Then, we can
make IMEContentObserver, TextInputListener, ComposerCommandsUpdater,
TypeInState not derived from nsISelectionListener since EditorBase or
HTMLEditor can notify them of selection change directly.  Additionally,
ResizerSelectionListener is not necessary anymore since it just implements
nsISelectionListener and calls only a method of HTMLEditor.  So, HTMLEditor
can call it directly.

Note that the order of selection listeners may be different.  However,
according to what each selection listener does, changing the order isn't
problem.

MozReview-Commit-ID: 1JXZxQcS0tP

--HG--
extra : rebase_source : c2ebe622a74001ad4e421da492dcdab8e6fe1649
2018-01-26 17:25:45 +09:00
Masayuki Nakano
7dab388aae Bug 1432528 - part 3: Make EditorBase store IMEContentObserver directly and make it not derived from nsIEditorObserver r=m_kato
Similar to TextInputListener, EditorBase should store IMEContentObserver
directly instead of via nsIEditorObserver.  Then,
EditorBase::NotifyEditorObservers() can call each method directly.
Additionally, we can make IMEContentObserver not derived from nsIEditorObserver.

MozReview-Commit-ID: cNKWJe5eUC

--HG--
extra : rebase_source : 4ed3b3b3180b8ee4a7c514ce1f89eba4dad64fbe
2018-01-24 14:10:18 +09:00
Masayuki Nakano
74aaf9525b Bug 1432528 - part 2: Make EditorBase treat TextInputListener directly and make TextInputListener not derived from nsIEditorObserver r=m_kato
Now, EditorBase can store TextInputListener directly instead of as
nsIEditorObserver.  And then, EditorBase can call its EditAction() method
directly.  Therefore, we can make TextInputListener not derived from
nsIEditorObserver.

MozReview-Commit-ID: 4qPnnvReLKy

--HG--
extra : rebase_source : cde47e245c9856abf696dbaf8e26d8e4d6d98d42
2018-01-24 12:50:01 +09:00
Masayuki Nakano
2020349542 Bug 1430982 - part 10: Make EditorBase store TextServicesDocument for its mInlineSpellChecker for avoiding to run for loops to call nsIEditActionListener methods r=m_kato
Currently, first edit action listener is always TextServicesDocument for
EditorBase::mInlineSpellChecker if spell check is enabled and it requires
only DidDeleteNode() and DidJoinNodes().  So, in most cases, EditorBase
should call only them to avoid running redundant for loops for
nsIEditActionListener methods.

This patch makes that EditorBase::AddEditActionListener() and
RemoveEditActionListener() check whether coming nsIEditActionListener is
TextServicesDocument for mInlineSpellChecker.  If so, EditorBase should
store it as reference to TextServicesDocument.  And when edit action occurs,
its DidDeleteNode() and DidJoinNodes() should be called directly.

Unfortunately, this patch makes TextServiceDocument's maintaining rules
complicated.  However, it must be really rare case to add new edit action
listener because it's really old component.

Note that EditorSpellCheck may be created multiple instances for an editor
from chrome JS.  Therefore, we need to keep TextServicesDocument being
derived from nsIEditActionListener because in such case, TextServicesDocument
for other EditorSpellCheck instances should be supported via
nsIEditActionListener even though such case makes EditorBase slower.

MozReview-Commit-ID: KtlXsBCOzKL

--HG--
extra : rebase_source : 6827ed09a028f2049fd7afba2f5116d092bd14e5
2018-01-18 23:46:03 +09:00
Masayuki Nakano
04e3a3adfc Bug 1430982 - part 8: Make EditorBase store inline spell checker as mozInlineSpellChecker rather than nsIInlineSpellChecker r=m_kato
EditorBase::mInlineSpellChecker is always an instance of mozInlineSpellChecker.
Fortunately, it's easy to expose mozInlineSpellChecker.h.  So, making EditorBase
store it as mozInlineSpellChecker directly, EditorBase can access any of
mozInlineSpellChecker, EditorSpellCheck, mozSpellChecker and
TextServicesDocument with new accessors created by following patch.

MozReview-Commit-ID: 2oyS5tPeQcg

--HG--
extra : rebase_source : a9ce2e4dbceff7ca800d34d60d56eba184298677
2018-01-17 00:52:37 +09:00
Masayuki Nakano
31d493d9fa Bug 1430021 - part 2: Make HTMLEditRules not derived from nsIEditActionListener r=m_kato
HTMLEditRules implements only some of nsIEditActionListener and this is always
first edit action listener.  So, if we make EditorBase treat HTMLEditRules
directly before notifying edit action listeners, we can save a lot of runtime
cost (virtual calls especially unnecessary, copying array of edit action
listeners with strong pointer, redundant QIs), although the code becomes not
beautiful.

Perhaps, we should do same thing to nsTextServicesDocument and
mozInlineSpellChecker in other bugs.

MozReview-Commit-ID: Eveaxj398f2

--HG--
extra : rebase_source : 0b7b66ba1002e08591e8d95ef68b216e7ce1f93b
2018-01-13 00:21:17 +09:00
Masayuki Nakano
b2a3e52b16 Bug 1430021 - part 1: Move |RefPtr<TextEditRules> mRules| from TextEditor to EditorBase r=m_kato
For calling some methods of mRules from EditorBase, let's move mRules member
from TextEditor to EditorBase.

Unfortunately, TextEditRules.h depends on EditAction which is declared in
EditorBase.h and that caused unnecessary include hell of EditorBase.h.  So,
let's move it to an independent header file.

MozReview-Commit-ID: 5HiSZLP9WHH

--HG--
extra : rebase_source : 3e2c40385a6f3d6d1e03ef4e213434383bb37d5f
2018-01-12 19:01:04 +09:00
Olli Pettay
3a7a79b6b8 Bug 1428747 - Make EditorBase::GetDOMEventTarget() to return EventTarget* and GetFocusedContent() return nsIContent* in order to optimize out some AddRef/Release calls, r=masayuki
--HG--
extra : rebase_source : 86be9af360438fcb1fa63f07994e41cf12d9c2e2
2018-01-09 15:41:42 +02:00
Masayuki Nakano
bbbb83c937 Bug 1425412 - part 10: Create factory methods for AddStyleSheetTransaction and RemoveStyleSheetTransaction, and remove EditorBase::CreateTxnForAddStyleSheet() and EditorBase::CreateTxnForRemoveStyleSheet() r=m_kato
This patch creates factory methods for AddStyleSheetTransaction and
RemoveStyleSheetTransaction, and removes EditorBase::CreateTxnForAddStyleSheet()
and EditorBase::CreateTxnForRemoveStyleSheet() instead.

MozReview-Commit-ID: 6dnZctDtNik

--HG--
extra : rebase_source : 43eaadbde06e4a0b061ea8136e12ffeccfaf5592
2017-12-18 17:29:32 +09:00
Masayuki Nakano
07e48c2f29 Bug 1425412 - part 9: Create factory methods of ChangeAttributeTransaction and remove EditorBase::CreateTxnForSetAttribute() and EditorBase::CreateTxnForRemoveAttribute() r=m_kato
This patch creates two factory methods of ChangeAttributeTransaction.  One is
for setting an attribute to specific value.  The other is for removing an
attribute.  So, EditorBase::CreateTxnForSetAttribute() and
EditorBase::CreateTxnForRemoveAttribute() are unnecessary anymore.

MozReview-Commit-ID: 2fEVd3pDXsf

--HG--
extra : rebase_source : 674005a5b9fc623999a0f51dc8697027970f06c9
2017-12-18 17:07:52 +09:00
Masayuki Nakano
f2369df116 Bug 1425412 - part 8: Create JoinNodeTransaction::MaybeCreate() and remove EditorBase::CreateTxnForJoinNode() r=m_kato
EditorBase::CreateTxnForJoinNode() just hides what it does.
For making the caller clearer, let's create a factory method,
JoinNodeTransaction::MaybeCreate().

MozReview-Commit-ID: 8vADXdzMeuV

--HG--
extra : rebase_source : 6a281aff11bfa019c292d26cadd0cd29da12753f
2017-12-15 21:53:08 +09:00
Masayuki Nakano
2b43d139dd Bug 1425412 - part 7: Create SplitNodeTransaction::Create() and remove EditorBase::CreateTxnForSplitNode() r=m_kato
SplitNodeTransaction::Create() just hides what it does.  For making its caller
clearer, let's create a factory method, SplitNodeTransaction::Create().

MozReview-Commit-ID: KDiC8dDrLuQ

--HG--
extra : rebase_source : ac04544e10644b8a73375fb2b786e0bc86eb56ae
2017-12-15 21:37:23 +09:00
Masayuki Nakano
015555162f Bug 1425412 - part 6: Create DeleteNodeTransaction::MaybeCreate() and remove EditorBaseTransaction::CreateTxnForDeleteNode() r=m_kato
EditorBaseTransaction::CreateTxnForDeleteNode() just hides what it does.
Instead, let's create a factory method, DeleteNodeTransaction::MaybeCreate()
for making callers clearer.

MozReview-Commit-ID: 8WUYN0BjKSU

--HG--
extra : rebase_source : e0ff8b8434b720dc124c770cd7371d84b949ca8d
2017-12-15 21:24:33 +09:00
Masayuki Nakano
6b8e286ddc Bug 1425412 - part 5: Create some factory methods of DeleteTextTransaction and remove EditorBase::CreateTxnForDeleteText() and EditorBase::CreateTxnForDeleteCharacter() r=m_kato
DeleteTextTransaction should have 3 factory methods.  One is, simply to create
an instance with a pair of offset and length.  The others are, to create an
instance for deleting a previous or next character at offset.

The former was EditorBase::CreateTxnForDeleteText() and the latter was
EditorBase::CreateTxnForDeleteCharacter(), but this patch creates
DeleteTextTransaction::MaybeCreate() for the former,
DeleteTextTransaction::MaybeCreateForPreviousCharacter() and
DeleteTextTransaction::MaybeCreateForNextCharacter() for the latter.

MozReview-Commit-ID: DFELbmAJDo3

--HG--
extra : rebase_source : 1600984c704b460e1cc09777b81df2906c154cce
2017-12-15 20:43:26 +09:00
Masayuki Nakano
a5bd93a76e Bug 1425412 - part 4: Create CompositionTransaction::Create() and remove EditorBase::CreateTxnForComposition() r=m_kato
EditorBase::CreateTxnForComposition() just hides what it does.  For its caller,
creating a factory method, CompositionTransaction::Create(), is clearer what
it does.

Additionally, capsuling the creation in CompositionTransaction class can make
the text node information in TextComposition updated automatically.  So, now,
it might be better to update them in DoTransaction() because there is a lag
between creating the transaction and calling DoTransaction().  However, this
patch doesn't want to change any existing behavior.  So, this doesn't fix this
issue.

MozReview-Commit-ID: K8ci7ytwh1u

--HG--
extra : rebase_source : d468a0fc997c99f78f7eb46451082e7f1e052890
2017-12-15 18:26:37 +09:00
Masayuki Nakano
7443737c19 Bug 1425412 - part 3: Create CreateElementTransaction::Create() and remove EditorBase::CreateTxnForCreateElement() r=m_kato
EditorBase::CreateTxnForCreateElement() just hides what it does. Let's make
the caller what it does with creating CreateElementTransaction::Create().

MozReview-Commit-ID: DYcfQV6KiUZ

--HG--
extra : rebase_source : d3f31b8db92bd3b2af464c66e064dd7b21018960
2017-12-15 17:54:10 +09:00
Masayuki Nakano
1623a99bae Bug 1425412 - part 2: Create InsertNodeTransaction::Create() and remove EditorBase::CreateTxnForInsertNode() r=m_kato
EditorBase::CreateTxnForInsertNode() just hides what it does.  Let's create
InsertNodeTransaction::Create() and make the caller clearer.

MozReview-Commit-ID: 2J2WV73cdsm

--HG--
extra : rebase_source : 15b6391aee5beca4401e7c7a4ee8bf350a7590fd
2017-12-15 17:34:52 +09:00
Masayuki Nakano
ab059453f1 Bug 1425412 - part 1: Create InsertTextTransaction::Create() and remove EditorBase::CreateTxnForInsertText() r=m_kato
EditorBase::CreateTxnForInsertText() just hides what it exactly does.

Rewriting it with a static factory method, InsertTextTransaction::Create()
should be clearer for its caller.

MozReview-Commit-ID: Er7Zlhtbnb0

--HG--
extra : rebase_source : 9dc71b3baab839f61153b96806fac5baae5d46cb
2017-12-15 17:26:52 +09:00
Masayuki Nakano
30d3307a79 Bug 1426318 - Get rid of EditorBase::IsContainer(nsIDOMNode*) r=m_kato
The only caller is HTMLEditor::IsEmptyNodeImpl().  So, we can get rid of it.

MozReview-Commit-ID: GTJiXwSCrwM

--HG--
extra : rebase_source : a44b277547d0641f244ff363f5cde8ae44b13eda
2017-12-20 16:18:47 +09:00
Masayuki Nakano
6e8192fd45 Bug 1425390 - part 1: Move some IME related members of EditorBase into TextComposition r=m_kato
EditorBase stores a text node, offset in it and length in it of composition
string directly.  However, this wastes memory space if user never uses IME
or user only sometimes uses IME.  Additionally, storing all data in
TextComposition is better than current design when other classes like
CompositionTransaction wants some information of both EditorBase and
TextComposition.

This patch moves those 3 members from EditorBase to TextComposition.

MozReview-Commit-ID: 4N7wmGGfxmt

--HG--
extra : rebase_source : bd7cb37fe9631b959ec21da40c20751fec269dca
2017-12-15 13:14:51 +09:00
Masayuki Nakano
6b577ea0fa Bug 1423835 - part 3: Rename EditorDOMPointBase::GetChildAtOffset() to EditorDOMPointBase::GetChild() r=m_kato
Different from RangeBoundaryBase, EditorDOMPointBase can store only child node.
I.e., mOffset may be invalid until its Offset() is called.  So,
GetChildAtOffset() isn't good name.  It should be just GetChild().

Similarly, GetNextSiblingOfChildAtOffset() and
GetPreviousSiblingOfChildAtOffset() should be renamed to GetNextSiblingOfChild()
and GetPreviousSiblingOfChild().

MozReview-Commit-ID: WpkPmDwkrL

--HG--
extra : rebase_source : 2be1fcbee129f4c96e9b166be5a924845340708f
2017-12-07 19:08:56 +09:00
Masayuki Nakano
8496023596 Bug 1408125 - part 2: EditorBase::CreateTxnForInsertNode() and EditorBase::InsertNode() should take |const EditorRawDOMPoint&| as an argument specifying point to insert r=m_kato
EditorBase::CreateTxnForInsertNode() and EditorBase::InsertNode() should take
|const EditorRawDOMPoint&| as an argument specifying point to insert.

MozReview-Commit-ID: KhK19xS7wXb

--HG--
extra : rebase_source : f7b08b7d049eef8a9c03ee681e53e8d469915b15
2017-11-22 21:25:05 +09:00
Masayuki Nakano
5c35d9705d Bug 1421504 - EditorBase should move children carefully r=m_kato
While moving children of a container to another container, mutation observer
may move children before moving and/or move node immediately after the
insertion point.  Therefore, EditorBase should store all children which
should be moved with a local variable.  Then, move one by one carefully.
E.g., if a child before being moved is moved to different container, it
shouldn't be moved because JS already handles it as expected for the web
app.  If next sibling of the insertion point has been moved, EditorBase
should stop moving the remaining children because it may move children to
odd position and it may cause dataloss.

This patch creates EditorBase::MoveChildren() and it moves children carefully
with above checks.  Additionally, making its callers simpler, this patch also
creates EditorBase::MovePreviousSiblings() and MoveAllChildren().

MozReview-Commit-ID: FJDdSqXIlqD

--HG--
extra : rebase_source : 54bded29dbbd9547339a2c6e1a1264e22fbdc740
2017-11-29 17:57:00 +09:00
Makoto Kato
7f97c4e179 Bug 1408829 - Make spellCheckAfterEditorChange as noscript. r=masayuki
No one uses nsIInlineSpellChecker.spellCheckAfterEditorChange from script.
So I think we can mark this interface as noscript.

Since this method is scriptable, we need QI to get nsIDOMNode.  If we can
change to noscript, it can reduce QI to get nsIDOMNode.

MozReview-Commit-ID: GC0WuFyTlaZ

--HG--
extra : rebase_source : 16ca9fc548e86747ac17407be48295c709174fb5
2017-11-29 18:00:11 +09:00
Masayuki Nakano
419273aff1 Bug 1413181 - part 10: Redesign EditorBase::SplitNodeDeep() r=m_kato
First of all, this patches fixes a bug of EditorBase::CreateNode().  It takes
|EditorRawDOMPoint&| but it should be |const EditorRawDOMPoint&| for making
callers can specify temporary instances.

Next, this patch creates |SplitNodeResult| stack class for result of
EditorBase::SplitNodeDeep().  SplitNodeDeep() needs to return previous node
and next node of split point.  They are called as left node and right node,
but these calls are really different term usage.  Therefore, this patch names:

aOutLeftNode -> SplitNodeResult::GetPreviousNode()
aOutRightNode -> SplitNodeResult::GetNextNode()

and also declares SplitNodeResult::GetLeftNode() and
SplitNodeResult::GetRightNode() which are same meaning as left/right node of
other splitting methods.

Additionally, of course, this patch makes SplitNodeDeep() use
|const EditorRawDOMPoint&| to receive the start point of right node.

MozReview-Commit-ID: FnJpeKgtzm4

--HG--
extra : rebase_source : 3829e5528ef837b13fed305e0df1dbbf00e02a07
2017-11-16 12:09:57 +09:00
Masayuki Nakano
bf54c638b2 Bug 1413181 - part 6: Rename mozilla::EditorBase::EmptyContainers enum class to mozilla::SplitAtEdges for making its values clearer r=m_kato
EmptyContainers::yes and EmptyContainers::no are not so clear name what they
mean.

They means whether NodeSplitDeep() creates or won't create empty nodes when
split point is at start edge or end edge of an element.

This patch renames them to SplitAtEdges::eDoNotCreateEmptyContainer and
SplitAtEdges::eAllowToCreateEmptyContainer and make
HTMLEditor::InsertNodeAtPoint() use it instead of an bool argument.

Additionally, the argument of NodeSplitDeep() is now not optional because
this difference is really important when you read around the callers.

MozReview-Commit-ID: 9hpMRkVDvCg

--HG--
extra : rebase_source : ee892361d66c9c9c5ed45ee9d3321474257ac417
2017-11-13 14:35:16 +09:00
Masayuki Nakano
070ede0cf4 Bug 1413181 - part 3: EditorBase::CreateTxnForSplitNode() and EditorBase::SplitNode() should take EditorRawDOMPoint to specify the start of right node r=m_kato
EditorBase::CreateTxnForSplitNode() and EditorBase::SplitNode() takes a set of
container and offset in it for specifying a point to split.

Instead, they should take EditorRawDOMPoint for specifying start of right node.

MozReview-Commit-ID: 5VwS8oudzIT

--HG--
extra : rebase_source : 727948e5cf95f0713019f57ae9a007b85569fa56
2017-11-12 11:30:30 +09:00
Masayuki Nakano
1e31c0d7b6 Bug 1413181 - part 1: Redesign EditorBase::SplitNodeImpl() with EditorDOMPoint r=m_kato
EditorBaseSplitNodeImpl() should be clean up with EditorDOMPoint which should
be an argument to point the first point of right node (existing split node).

MozReview-Commit-ID: DN0yHm9G9yT

--HG--
extra : rebase_source : 256b4e2125e831b7be9e5c4aefc6f04c80e3c1f5
2017-11-12 08:38:56 +09:00
Masayuki Nakano
88120b8907 Bug 1415800 - part 2: Redesign EditorBase::GetNextNode() with EditorRawDOMPoint r=m_kato
An overload of EditorBase::GetNextNode() takes a set of container, child node
and offset of the child in the container.  Replacing it with EditorRawDOMPoint
makes the caller simpler.

Additionally, it has two bool arguments, one is for searching if editable node,
the other is for searching if in same block.  So, they can be hidden with
some human readable inline methods.

When I was creating this patch, I realized that
GetNextNodeInternal(const EditorRawDOMPoint& aPoint) may return
aPoint.GetChildAtOffset().  I.e., it starts to search from the specified point
rather than next node.  On the other hand, GetNextNodeInternal(nsINode& aNode)
never returns aNode itself.  So, it there is better name instead of "Next",
we should take it.  But I have no better idea.  So, this patch just explains
the difference with comments in EditorBase.h.

MozReview-Commit-ID: 4Lb6o9SJuhy

--HG--
extra : rebase_source : d20d728eae69659ef448b6679ae8f73d64c2d7e9
2017-11-09 17:57:00 +09:00
Masayuki Nakano
e28ddd6ec3 Bug 1415800 - part 1: Redesign EditorBase::GetPriorNode() with EditorRawDOMPoint r=m_kato
An overload of EditorBase::GetPriorNode() takes a set of container, child node
and offset of the child in the container.  Replacing it with EditorRawDOMPoint
makes the caller simpler.

Additionally, it has two bool arguments, one is for searching if editable node,
the other is for searching if in same block.  So, they can be hidden with
some human readable inline methods.

Finally, "Prior" isn't a term of DOM.  So, let's use "Previous" instead.

MozReview-Commit-ID: A9uKzHaikY9

--HG--
extra : rebase_source : 15bfdfde0ad89a5331d6c8a24351741eeef476d5
2017-11-09 17:08:10 +09:00
Masayuki Nakano
a3fa902a2d Bug 1415509 - part 2: EditorBase::InsertTextImpl() should take |const EditorRawDOMPoint&| argument as input and |EditorRawDOMPoint*| as out argument instead of a set of container, child and offset of the child in the container as in/out argument r=m_kato
EditorBase::InsertTextImpl() takes |nsCOMPtr<nsINode>*|, |nsCOMPtr<nsIContent>*|
and |int32_t| as in/out arguments for container, child and offset of the child
in the container.  But this makes the callers really hard to read and ugly.

So, we should make the method take |const EditorRawDOMPoint&| argument as input
and |EditorRawDOMPoint*| as out argument.

MozReview-Commit-ID: 2ijIfGl4Zo7

--HG--
extra : rebase_source : b309d9bdc04aac620f138769ba18ad7e4597fe6c
2017-11-09 01:00:36 +09:00
Masayuki Nakano
7adce402c2 Bug 1415509 - part 1: EditorBase::FindBetterInsertionPoint() should take an EditorRawDOMPoint argument for input and return EditorRawDOMPoint for the result r=m_kato
EditorBase::FindBetterInsertionPoint() now use 3 in/out arguments.  This is
really ugly and making the callers hard to read.  So, let's make it take an
argument whose type is |const EditorRawDOMPoint&| and return other
EditorRawDOMPoint instance.

Additionally, this fixes bugs of text node length checks in the method.
Basically, this shouldn't affect to any actual behavior, though.  That is
because text node shouldn't be able to have string longer than INT32_MAX.

MozReview-Commit-ID: FClUQSJzd8c

--HG--
extra : rebase_source : 3e2fbd345015f7068c7e35a94c31731e7936009f
2017-11-08 21:55:10 +09:00
Masayuki Nakano
68294ac1d3 Bug 1415445 - part 4: EditorBase::CreateNode() should take EditorRawDOMPoint as insertion point instead of a set of container, child and offset of the child in the container r=m_kato
EditorBase::CreateNode() should take EditorRawDOMPoint as insertion point of
the new element instead of a set of container, child and offset of the child
in the container.

This patch initializes EditorRawDOMPoint with original 3 arguments as far as
possible.  If the relation of them are broken, MOZ_ASSERT in RawRangeBoundary
constructor detects existing bugs.

MozReview-Commit-ID: 2N55S6pRv7k

--HG--
extra : rebase_source : 2b14a7715815ca0007635b8f791ca9edbe5b65f1
2017-11-08 20:23:10 +09:00
Masayuki Nakano
9dd0af5112 Bug 1415445 - part 2: EditorBase::CreateTxnForCreateElement() should take EditorRawDOMPoint for insertion point r=m_kato
The constructor of CreateElementTransaction now takes EditorRawDOMPoint instead
of a set of container node and offset in it.  So, its only user,
EditorBase::CreateTxnForCreateElement(), should take EditorRawDOMPoint too.

MozReview-Commit-ID: A8QfPM3LRii

--HG--
extra : rebase_source : 4a99e5cb58230649d19faca788a330fe02eb6bb1
2017-11-08 17:23:28 +09:00
Masayuki Nakano
8b6c211c36 Bug 1408544 - part 1: Reimplement EditorDOMPoint as a subclass of RangeBoundary r=catalinb,m_kato
A lot of methods in editor returns a child offset with an out param when it
returns its container and offset in the container.  This is ugly hack for
performance of nsINode::IndexOf().  However, there are a lot of regression
since the relation between offset and child node can be broken really easily.

So, we should make EditorDOMPoint as a subclass of RangeBoundary and manage
a set of container, reference child and its offset in it (e.g.,
SetNextSibling() added by this patch).

Note that RangeBoundary's performance is not good for temporary use if we set
a point with offset, it immediately retrieves mRef.  The following patch will
improve this performance.

MozReview-Commit-ID: 7mcJ1P1OjVr

--HG--
rename : editor/libeditor/EditorUtils.h => editor/libeditor/EditorDOMPoint.h
extra : rebase_source : 785094fcfc592d9e5b48cbc36ed225dbb8bb4111
2017-11-01 14:41:03 +09:00
Masayuki Nakano
f802692190 Bug 1411687 - part 2: Rewrite the check to insert a <br> element in HTMLEditRules::WillInsertBreak() r=m_kato
Currently, HTMLEditRules::WillInsertBreak() checks if the editing host can
contain a <p> element as a child or a descendant.  However, this is not enough.
If an inline element has a block element which can contain a <p> element,
current implementation considers to insert a <br>.  This is possible when
* The editing host is an unknown element including user defined element.
* The editing host is an inline element and its children and/or descendants
  were added by JS.  E.g., <span contenteditable> element can have <div>
  element.

I think that we should consider to insert a <br> element when:
- There is no block ancestors in the editing host.
- The editing host is the only block element and it cannot contain <p> element
  or the default paragraph separator is <br> element.
- The nearest block ancestor isn't a single-line container declared in the
  execCommand spec and there are no block elements which can contain <p>
  element.

Note that Chromium checks if CSS box of ancestors is block too.  However,
it must be out of scope of this bug.

MozReview-Commit-ID: HdjU9t83Nd1

--HG--
extra : rebase_source : 7030671268a610613359b5d8ae5d126e120f59bd
2017-10-27 01:27:44 +09:00
Emilio Cobos Álvarez
dd634e3981 Bug 1411612: Kill nsINode::eCONTENT. r=bz
MozReview-Commit-ID: ESlOqlwhcHI

--HG--
extra : rebase_source : fe6a02469dca1e50c24ba166e15e39160ab4551b
2017-10-25 17:19:11 +02:00
Makoto Kato
52ae993a2a Bug 1407924 - Avoid conversion from nsAtom to string if possible. r=masayuki
Editor sometimes extracts atom to string to compare element name.
It is unnecessary to use atom directly.

MozReview-Commit-ID: FEvyiIeaozs

--HG--
extra : rebase_source : 4418d0c82fa4fedd814b914f2cf3a86d74ad9835
2017-10-12 16:28:28 +09:00
Ehsan Akhgari
0e0b35e1aa Bug 1407854 - Part 3: Pass the child node at the offset as an extra argument where possible to CreateNode(); r=masayuki
This patch converts almost all of the call sites over to passing
the extra argument explicitly.
2017-10-12 17:13:56 -04:00
Ehsan Akhgari
bf1f474a3d Bug 1407854 - Part 2: Add an optional argument to CreateNode() to allow callers to pass the child node when they know it; r=masayuki 2017-10-12 17:13:55 -04:00
Ehsan Akhgari
92a2acc32a Bug 1407447 - Part 2: Remove some dead code; r=masayuki 2017-10-12 10:49:14 -04:00
Ehsan Akhgari
91afad1234 Bug 1407447 - Part 1: Remove the call to nsINode::GetChildAt() from HTMLEditor::DoInsertHTMLWithContext(); r=masayuki 2017-10-12 10:49:14 -04:00
Ehsan Akhgari
1bba75e15f Bug 1406482 - Avoid using nsINode::GetChildAt() in EditorBase::InsertTextImpl(); r=masayuki 2017-10-11 13:12:00 -04:00
Ehsan Akhgari
6a2135a0bb Bug 1407305 - Part 4: Avoid using GetChildAt() in EditorBase::GetNextNode(); r=masayuki 2017-10-11 11:27:57 -04:00
Ehsan Akhgari
40afcd0316 Bug 1407305 - Part 3: Avoid using GetChildAt() in EditorBase::GetPriorNode(); r=masayuki 2017-10-11 11:27:55 -04:00
Phil Ringnalda
5fee8a40bb Backed out changeset 9843839bf1df (bug 1406482) for mozilla::EditorBase::InsertTextImpl crashes
MozReview-Commit-ID: J7rX4lX2lxM
2017-10-09 21:32:12 -07:00
Ehsan Akhgari
8fff7a3eb8 Bug 1406482 - Avoid using nsINode::GetChildAt() in EditorBase::InsertTextImpl(); r=masayuki 2017-10-09 18:21:22 -04:00
Nicholas Nethercote
d225f7151b Bug 1400460 - Rename nsIAtom as nsAtom. r=hiro.
(Path is actually r=froydnj.)

Bug 1400459 devirtualized nsIAtom so that it is no longer a subclass of
nsISupports. This means that nsAtom is now a better name for it than nsIAtom.

MozReview-Commit-ID: 91U22X2NydP

--HG--
rename : xpcom/ds/nsIAtom.h => xpcom/ds/nsAtom.h
extra : rebase_source : ac3e904a21b8b48e74534fff964f1623ee937c67
2017-10-03 09:05:19 +11:00
Ehsan Akhgari
3674cbeaa1 Bug 1405794 - Avoid using nsINode::GetChildAt() in TextEditor::SelectEntireDocument(); r=masayuki 2017-10-06 11:12:04 -04:00
Masayuki Nakano
7fb91d43b5 Bug 1397178 - Make EditorBase::GetRoot() not call nsIEditor::GetRootElement() r=smaug
In the old design, EditorBase::mRootElement is initialized when
nsIEditor::GetRootElement() is called.  Therefore, EditorBase::GetRoot()
calls if mRootElement is nullptr.

However, mRootElement is now initialized when EditorBase::UpdateRootElement()
is called and it's always initialized when EditorBase::Init() is called.

So, EditorBase::GetRoot() doesn't need to call nsIEditor::GetRootElement()
anymore.

MozReview-Commit-ID: 6dNEJaGNMZe

--HG--
extra : rebase_source : ed29488cfd1434fb200387706ca5a96cb2185090
2017-09-05 23:32:17 +09:00
Olli Pettay
045eeefaaa Bug 1390402, add a faster variant of TextEditor::GetDocumentIsEmpty(), r=masayuki
--HG--
extra : rebase_source : 3238aec96be5b0393c395ce8cce9a0489d2e671d
2017-08-24 13:53:34 +03:00
Eric Rahm
a33f11e0f5 Bug 1391803 - Use nsStringFwd.h for forward declaring string classes. r=froydnj
We should not be declaring forward declarations for nsString classes directly,
instead we should use nsStringFwd.h. This will make changing the underlying
types easier.

--HG--
extra : rebase_source : b2c7554e8632f078167ff2f609392e63a136c299
2017-08-16 16:48:52 -07:00
Masayuki Nakano
a7240d8532 Bug 1391538 - nsTextFragment for text nodes in <input> or <textarea> shouldn't store text as single byte characters even if all characters are less than U+0100 r=smaug
nsTextFrame stores text as single byte character array if all characters are
less than U+0100.  Although, this saves footprint, but retrieving and modifying
text needs converting cost.  Therefore, if it's created for a text node in
<input> or <textarea>, it should store text as char16_t array.

MozReview-Commit-ID: 9Z82rketT7g

--HG--
extra : rebase_source : 59f59ac1488c21a57d95d253cc794a011d672c95
2017-08-18 16:05:16 +09:00
Masayuki Nakano
30fb5747b0 Bug 1391165 - part4: nsIEditor::EndOfDocument() should be implemented with an internal method which takes pointer to Selection r=smaug
EditorBase::GetSelection() sometimes appears in profile.  So, it shouldn't be
called in nsIEditor::EndOfDocument() if the callers of
nsIEditor::EndOfDocument() has a pointer to Selection.

This patch adds EditorBase::CollapseSelectionToEnd() for the internal method
and make all callers of nsIEditor::EndOfDocument() use it.

MozReview-Commit-ID: 8H4ThxzdKDf

--HG--
extra : rebase_source : 7436d7f286351fa9c91175b40e686f7ca1f3c69f
2017-08-17 17:08:22 +09:00
Masayuki Nakano
87f491432c Bug 1391165 - part1: EditorBase::GetChildOffset() and EditorBase::GetNodeLocation() shouldn't use nsINode::IndexOf() as far as possible r=smaug
nsINode::IndexOf() is expensive especially when it's in a hot path, it's too
expensive.  So, EditorBase::GetChildOffset() and EditorBase::GetNodeLocation()
should check child's siblings first.  If some of them are nullptr, it means
that it's first child or last child of the parent.

Note that EditorBase::GetChildOffset() may return wrong index if it's called
while aChild is being removed from aParent or aParent isn't actual parent of
aChild.  However, there are MOZ_ASSERTs to ensure value isn't -1.  Therefore,
it's safe to assume that aParent is always the parent of aChild and it won't
be called from ContentRemoved() of mutation observers.

MozReview-Commit-ID: 8JdYWuZbHe5

--HG--
extra : rebase_source : 6ded91a3aa8b00ab4d2d544c2c392d88cb769cef
2017-08-17 16:24:16 +09:00
Masayuki Nakano
e1a21d5a3e Bug 1387317 - part5: AutoPlaceHolderBatch should take EditorBase instead of nsIEditor r=m_kato
AutoPlaceHolderBatch can take EditorBase class and its inherited class, AutoEditBatch, can be removed if we implement other constructor which doesn't take transaction name.

Additionally, nsIEditor::(Begin|End)PlaceHolderTransaction() are referred only by AutoPlaceHolderBatch.  Therefore, they can be non-public methods and removed from nsIEditor interface.

Note that this patch also repalces "PlaceHolder" with "Placeholder" since it's a word.

MozReview-Commit-ID: 5dw3kcX3bOx

--HG--
extra : rebase_source : e926cc1c2ebea70eb08e43778a8b52912b559b7b
2017-08-14 14:56:39 +09:00
Masayuki Nakano
7c54bc878b Bug 1387317 - part2: EditorEventListener should stop using interface methods as far as possible r=m_kato
MozReview-Commit-ID: EPQeBez2tJh

--HG--
extra : rebase_source : b18b3399f703d3cdcb6f26cec3fcb8f707fb9519
2017-08-08 11:25:36 +09:00
Masayuki Nakano
de893ee82e Bug 1319340 - part8: EditorCommands should use TextEditor instead of nsIEditor, nsIPlaintextEditor and nsIEditorMailSupport r=m_kato
EditorCommands implements common edit commands.  So, we can use TextEditor even if the instance is HTMLEditor.

Then, EditorCommands can use non-virtual methods of the concrete classes.

MozReview-Commit-ID: DgKHqC0osRb

--HG--
extra : rebase_source : e9abd7ef8b48cfdc65bbeb56ebe81dc0548005dd
2017-08-04 20:41:20 +09:00
Masayuki Nakano
b5b8d1064d Bug 1319340 - part6: Implement some interface methods as non-virtual methods of EditorBase or HTMLEditor r=m_kato
nsComposerCommands uses some simple getter methods.  They can be simpler non-virtual methods.  So, we should do it.

Note that this changes that EditorBase::GetIsSelectionEditable() won't return error.  However, it has returned error only when selection controller isn't available.  That means that the selection controller has been destroyed and the editor will be destroyed.  So, this must not be problem since it returns false (non-editable) instead and won't break any behavior since the editor won't be editable by users nor JS anymore.

MozReview-Commit-ID: E9ccFspG6na

--HG--
extra : rebase_source : bcd1314cb386fcaf175adabfefde5885decd87c0
2017-08-04 18:30:13 +09:00
Masayuki Nakano
722bf07347 Bug 1319340 - part1 Move AsTextEditor() and AsHTMLEditor() to nsIEditor r=m_kato
nsIEditor is still first contact with editor class for some modules.  They should be accessible to the concrete classes without QI.  Therefore, nsIEditor should have As*Editor() methods.

Additionally, this adds AsEditorBase().  That is always implemented but it might be necessary for some files for minimizing its include files.

MozReview-Commit-ID: 8WqkDJLiVDs

--HG--
extra : rebase_source : e51282df244efad62bc6fe04ab449e3beab440f9
2017-08-04 15:01:36 +09:00
Ehsan Akhgari
4018b56c7c Bug 1386485 - Part 4: Devirtualize and inline EditorBase::IsEditable(); r=masayuki 2017-08-04 03:47:14 -04:00
Ehsan Akhgari
c6b7fe866d Bug 1386485 - Part 3: Devirtualize EditorBase::AsTextEditor()/AsHTMLEditor(); r=masayuki 2017-08-04 03:47:14 -04:00
Ehsan Akhgari
01af645785 Bug 1386485 - Part 1: Inline EditorBase::IsMozEditorBogusNode(); r=masayuki 2017-08-04 03:47:13 -04:00
Ehsan Akhgari
cf4e6a817c Bug 1386411 - Part 7: Inline EditorBase::GetSelection(); r=masayuki 2017-08-03 17:06:31 -04:00
Ehsan Akhgari
ad87011a1d Bug 1386411 - Part 5: Make BaseEditor::GetSelectionController() return nsISelectionController*, and inline it; r=masayuki
This method can be extremely hot, so we need to remove all sources of XPCOM
overhead from it.  This includes the usages of weak pointers (thanks to the
previous parts), refcounting, and QueryInterface.

I kept the callers hold the selection controller alive by assigning the
return value to an nsCOMPtr in places where the methods called on it could
have a remote chance of messing with the lifetime of objects.
2017-08-03 17:05:22 -04:00
Ehsan Akhgari
697fb3f83d Bug 1386411 - Part 4: Don't store the document as a weak reference on EditorBase; r=masayuki
This one also doesn't need to be a weak reference, and can be a strong
reference that the cycle collector knows about instead.
2017-08-03 17:05:21 -04:00
Ehsan Akhgari
ace85f9311 Bug 1386411 - Part 1: Don't store the selection controller as a weak reference on EditorBase; r=masayuki
This doesn't need to be a weak reference, and can instead be a simple strong
reference that we introduce to the cycle collector.
2017-08-03 17:05:15 -04:00
Ehsan Akhgari
34e6b544eb Bug 1386484 - Remove the SetTextTransaction class and embed its functionality into EditorBase::SetTextImpl(); r=masayuki
Besides some unnecessary copying and malloc overhead that this removes, it
also removes a call to dom::Text::GetData() which we used to only make to
get the old length of the text node before modifying it.  Turns out that
this old length was already obtained once in SetTextImpl().
2017-08-03 09:54:59 -04:00
Makoto Kato
9b683468d5 Bug 699703 - Need reframe before calling SetSelectionAfterTableEdit. r=masayuki
HTMLEditor::TabInTable inserts row element, then it selects a cell.  But when enabling lazy frame construction for editable node, it selects invalid cell and table.

Because HTMLEditor::SetSelectionAfterTableEdit doesn't select cell correctly on InsertTableRow().

HTMLEditor::SetSelectionAfterTableEdit uses HTMLEditor::GetCellAt, so it depends on frame.  So we need flush frame before calling it.

Also, a comment of HTMLEditor::InsertTableRow is invalid now because we don't use nsresult version of CreateElementWithDefualts.

MozReview-Commit-ID: 698TvmMZgwB

--HG--
extra : rebase_source : 95df12f1f870a2c68d02b24b8758dfe6d381a416
2017-07-14 15:48:40 +09:00
Ehsan Akhgari
30d4df5778 Bug 1385538 - Avoid dynamic memory allocation for EditorBase::mSelState; r=masayuki 2017-07-31 14:13:47 -04:00
Ehsan Akhgari
f3a8bf3251 Bug 1385525 - Part 2: Make SetTextTransaction lighter weight by making it a normal C++ class allocated on the stack; r=masayuki
This avoids the cost of allocation on the heap and cycle collection,
and removes some dead code.
2017-07-31 14:12:12 -04:00