Граф коммитов

188 Коммитов

Автор SHA1 Сообщение Дата
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
Ehsan Akhgari 1eb17afc4f Bug 1385392 - Avoid needlessly looking up the selection twice when DoTransaction() is called from TextEditRules::WillSetText(); r=masayuki 2017-07-31 10:57:10 -04:00
Ehsan Akhgari 423b388329 Bug 1385384 - Don't store mPlaceholderTransactionWeak as a weak pointer; r=masayuki 2017-07-31 10:55:22 -04:00
Masayuki Nakano 8ac3f6520d Bug 1377989 - part9: Rename aEndParent and aEndNode related to nsRange to aEndContainer r=smaug
MozReview-Commit-ID: 8XJbHfsg2hu

--HG--
extra : rebase_source : 0ee22f0b0cf5fd8c0a8fea610c54be8492436488
2017-07-12 00:09:37 +09:00