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

452 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano f213a8f6d0 Bug 1574852 - part 67-10: Move `HTMLEditRules::WillDeleteSelection()` and related methods to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44460

--HG--
extra : moz-landing-system : lando
2019-09-06 04:31:38 +00:00
Masayuki Nakano 0382baf2fe Bug 1574852 - part 66: Move `HTMLEditRules::ExpandSelectionForDelete()` to `HTMLEditor` r=m_kato
And this patch makes the new method do not touch `Selection`, instead, return
new `StaticRange`.  Although the creation cost may make damage to the
performance but let's keep using `StaticRange` for now.  There should be
a stack only class which have 2 `RangeBoundaryBase` or `EditorDOMPointBase`.

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

--HG--
extra : moz-landing-system : lando
2019-09-05 07:25:51 +00:00
Masayuki Nakano 656648d70f Bug 1574852 - part 64: Move `HTMLEditRules::MaybeDeleteTopMostEmptyAncestor()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44203

--HG--
extra : moz-landing-system : lando
2019-09-05 01:30:37 +00:00
Masayuki Nakano c6648a62df Bug 1574852 - part 63: Move `HTMLEditRules::GetGoodSelPointForNode()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44202

--HG--
extra : moz-landing-system : lando
2019-09-05 01:14:24 +00:00
Masayuki Nakano d2ce733c6a Bug 1574852 - part 62: Move `HTMLEditRules::TryToJoinBlocksWithTransaction()` to `HTMLEditor` r=m_kato
Additionally, `WSRunObject::ScrabBlockBoundary()` and
`WSRunObject::PreparetToJoinBlocks()` are used only the it.  Therefore, we
can clean them up.

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

--HG--
extra : moz-landing-system : lando
2019-09-04 08:43:12 +00:00
Masayuki Nakano e0847a6b6d Bug 1574852 - part 61: Move `HTMLEditRules::MoveBlock()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44200

--HG--
extra : moz-landing-system : lando
2019-09-04 05:00:11 +00:00
Masayuki Nakano e06533766b Bug 1574852 - part 60: Move `HTMLEditRules::MoveNodeSmart()` and `HTMLEditRules::MoveContents()` to `HTMLEditor` r=m_kato
Making them return next insertion point with `nsresult` makes the callers
easier to understand.  Therefore, this patch declares `MoveNodeResult` class
newly and make them use it.

And also we can get rid of the case of setting `*aInOutDestOffset` to -1
because it's a hacky case of `HTMLEditRules::MoveBlock()`.  If we keep it,
`MoveNodeSmart()` needs to compute new insertion point with different logic.
Therefore, this patch makes `HTMLEditRules::MoveBlock()` adjust new insertion
point with checking its argument.

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

--HG--
extra : moz-landing-system : lando
2019-09-04 03:32:26 +00:00
Masayuki Nakano 9c8bc82f51 Bug 1574852 - part 59: Move `HTMLEditRules::JoinNearestEditableNodesWithTransaction()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44198

--HG--
extra : moz-landing-system : lando
2019-09-04 00:18:18 +00:00
Masayuki Nakano e9b4c8468b Bug 1574852 - part 58: Move `HTMLEditRules::CheckForInvisibleBR()` to `HTMLEditor` r=m_kato
This is defined as too complicated than what it does actually since there
was not `EditorDOMPointBase`.

If given point's offset is `0`, returns `nullptr`.  If `aWhere` is
`BRLocation::blockEnd`, treats `aOffset` is length of `aBlock`.  Otherwise,
using given point.  Then, if the `WSRun` start reason is `br`, returns the
start reason node.  This means that this method just retrieves invisible
`<br>` element if it starts `WSRun` at given point.

Now, callers can specify end of block with `EditorDOMPointBase::SetToEndOf()`
easier.  Therefore, we can make it take only an `EditorDOMPointBase` instance.

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

--HG--
extra : moz-landing-system : lando
2019-09-03 10:31:41 +00:00
Masayuki Nakano e1d468e330 Bug 1574852 - part 57: Move `HTMLEditRules::DeleteNodeIfCollapsedText()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44196

--HG--
extra : moz-landing-system : lando
2019-09-03 09:57:28 +00:00
Masayuki Nakano 1edcec042e Bug 1574852 - part 56: Merge `HTMLEditRules::WillMakeList()` and `HTMLEditRules::WillMakeDefinitionList()` and make `HTMLEditor` call it directly r=m_kato
`HTMLEditRules::WillMakeDefinitionList()` just calls
`HTMLEditRules::WillMakeList()` and `HTMLEditRules::WillMakeList()` can be
called as `HTMLEditRules::MakeOrChangeListAndListItemAsSubAction()` so that
we should merge them and make `HTMLEditor` call it directly.

This patch also removes default action part of
`HTMLEditor::MakeOrChangeListAsAction()` because it runs only when
`HTMLEditRules::WillDoAction()` does not return canceled nor error but not
handled, however, it's won't occur since `HTMLEditRules::WillMakeList()`
always sets `aHandled` to `true` when it returns `NS_OK`.

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

--HG--
extra : moz-landing-system : lando
2019-09-03 09:32:17 +00:00
Masayuki Nakano 447a15d680 Bug 1574852 - part 55: Move `HTMLEditRules::MakeList()` to `HTMLEditor` r=m_kato
Additionally, this patch makes it use early-return style with `continue` as
far as making number of changing line minimized.

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

--HG--
extra : moz-landing-system : lando
2019-09-03 07:24:41 +00:00
Masayuki Nakano d4fab048af Bug 1574852 - part 54: Move `HTMLEditRules::ConvertListType()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44193

--HG--
extra : moz-landing-system : lando
2019-09-03 05:13:35 +00:00
Masayuki Nakano 2fc50edf06 Bug 1574852 - part 53: Move `HTMLEditRuies::InDifferentTableElements()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44191

--HG--
extra : moz-landing-system : lando
2019-09-03 04:18:02 +00:00
Masayuki Nakano f92de6dd34 Bug 1574852 - part 52: Make `HTMLEditRules::WillInsertParagraph()` merged with `HTMLEditor::InsertParagraphSeparatorAsSubAction()` r=m_kato
Meaningful job of `HTMLEditor::InsertParagraphSeparatorAsSubAction()` is only
calling `HTMLEditRules::WillInsertParagraph()` via
`HTMLEditRules::WillDoAction()`.  Therefore, we can move all jobs in them
into `HTMLEditRules::WillInsertParagraph()` and rename it to
`HTMLEditor::InsertParagraphSeparatorAsSubAction()`.

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

--HG--
extra : moz-landing-system : lando
2019-09-03 03:59:11 +00:00
Masayuki Nakano 298b98043f Bug 1574852 - part 51: Move `HTMLEditRules::IsInListItem()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44189

--HG--
extra : moz-landing-system : lando
2019-09-02 23:59:49 +00:00
Masayuki Nakano d6d83bd331 Bug 1574852 - part 49: Move `HTMLEditRules::ReturnInListItem()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44186

--HG--
extra : moz-landing-system : lando
2019-09-02 09:16:31 +00:00
Masayuki Nakano 5941cef758 Bug 1574852 - part 48: Move `HTMLEditRules::ReturnInHeader()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44185

--HG--
extra : moz-landing-system : lando
2019-09-02 09:14:23 +00:00
Masayuki Nakano e356eee3f9 Bug 1574852 - part 47: Move `HTMLEditRules::ReturnInParagraph()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44184

--HG--
extra : moz-landing-system : lando
2019-09-02 08:49:18 +00:00
Masayuki Nakano 425de0b16f Bug 1574852 - part 46: Move `HTMLEditRules::SplitParagraph()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44183

--HG--
extra : moz-landing-system : lando
2019-09-02 08:09:47 +00:00
Masayuki Nakano 16447ba211 Bug 1574852 - part 45: Move `HTMLEditRules::DefaultParagraphSeparator()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44182

--HG--
extra : moz-landing-system : lando
2019-09-02 08:06:56 +00:00
Masayuki Nakano 7c64e596da Bug 1574852 - part 44: Move `HTMLEditRules::IsEmptyBlockElement()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44181

--HG--
extra : moz-landing-system : lando
2019-09-02 06:37:43 +00:00
Masayuki Nakano fc08e740d8 Bug 1574852 - part 43: Move `HTMLEditRules::DidMakeBasicBlock()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44180

--HG--
extra : moz-landing-system : lando
2019-09-02 06:36:33 +00:00
Masayuki Nakano 8438c04ae7 Bug 1574852 - part 42: Merge `HTMLEditRules::WillMakeBasicBlock()` into `HTMLEditor::InsertBasicBlockWithTransaction()` r=m_kato
`HTMLEditRules::WillMakeBasicBlock()` just calls
`HTMLEditor::FormatBlockContainer()` and it's called only for
`EditSubAction::eCreateOrRemoveBlock` and it's used only in
`HTMLEditor::InsertBasicBlockWithTransaction()`.  Therefore, we can replace
calling `HTMLEditRules::WillDoAction()` in it with what
`HTMLEditRules::WIllMakeBasicBlock()` does.

First, `HTMLEditRules::WillDoAction()` checks whether first selection range
is editable.  If it's not so, it returns `NS_OK` with setting `aCancel` to
`true`.  Therefore, this patch moves this part to
`HTMLEditor::CanHandleHTMLEditSubAction()` for making
`HTMLEditor::InsertBasicBlockWithTransaction()` can check it easier.

Next, `HTMLEditor::InsertBasicBlockWithTransaction()` does something if
`HTMLEditRules::WillDoAction()` returns as not handled nor canceled.
However, this special handling requires at least one selection range:
https://searchfox.org/mozilla-central/rev/597a69c70a5cce6f42f159eb54ad1ef6745f5432/editor/libeditor/HTMLEditor.cpp#2284-2288
Surprisingly, `handled` is set to `false` only when there is an error or
there is no selection range.  Therefore, this long block has already been
dead code so that we can remove this.  Removing this block causes that we
become not throwing exception when `Document.execCommand("formatblock")`
without selection ranges.  But this is better since Chrome does not throw
excption.

Finally, this patch renames some related methods:
- `HTMLEditor::FormatBlockContainer()` -> `HTMLEditor::FormatBlockContainerWithTransaction()`
- `HTMLEditor::InsertBasicBlockWithTransaction()` -> `HTMLEditor::FormatBlockContainerAsSubAction()`

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

--HG--
extra : moz-landing-system : lando
2019-09-02 06:08:43 +00:00
Masayuki Nakano 816dbbb57d Bug 1574852 - part 41: Move `HTMLEditRules::InsertBRIfNeeded(nsINode&)` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44178

--HG--
extra : moz-landing-system : lando
2019-09-02 03:17:14 +00:00
Masayuki Nakano 08108eda15 Bug 1574852 - part 40: Move `HTMLEditRules::InsertPaddingBRElementForEmptyLastLineIfNeeded()` to `HTMLEditor` r=m_kato
And this fixes the caller which has not guaranteed the lifetime of the
start container.

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

--HG--
extra : moz-landing-system : lando
2019-09-02 03:16:26 +00:00
Masayuki Nakano 1155464d4c Bug 1574852 - part 39: Move `HTMLEditRules::InsertBRIfNeeded()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44174

--HG--
extra : moz-landing-system : lando
2019-09-02 01:47:14 +00:00
Masayuki Nakano 1779535bf3 Bug 1574852 - part 38: Move `HTMLEditRules::MakeBasicBlock()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43199

--HG--
extra : moz-landing-system : lando
2019-08-26 07:09:11 +00:00
Masayuki Nakano a6be29d2bf Bug 1574852 - part 37: Move `HTMLEditRules::ApplyBlockStyle()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43198

--HG--
extra : moz-landing-system : lando
2019-08-26 04:48:21 +00:00
Masayuki Nakano 364649f84e Bug 1574852 - part 36: Move `HTMLEditRules::RemvoeBlockStyle()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43197

--HG--
extra : moz-landing-system : lando
2019-08-26 04:00:15 +00:00
Masayuki Nakano 72ea02b6a7 Bug 1574852 - part 35: Move `HTMLEditRules::SplitRangeOffFromBlockAndRemoveMiddleContainer()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43196

--HG--
extra : moz-landing-system : lando
2019-08-26 03:59:48 +00:00
Masayuki Nakano 627c9ff582 Bug 1574852 - part 34: Move `HTMLEditRules::SplitRangeOffFromBlock()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43195

--HG--
extra : moz-landing-system : lando
2019-08-26 03:20:35 +00:00
Masayuki Nakano d42fe61844 Bug 1574852 - part 33: Move `HTMLEditRules::MakeBlockquote()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43194

--HG--
extra : moz-landing-system : lando
2019-08-26 01:55:01 +00:00
Masayuki Nakano 337a97617a Bug 1574852 - part 32: Move `HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43193

--HG--
extra : moz-landing-system : lando
2019-08-26 01:38:56 +00:00
Masayuki Nakano 1a76778801 Bug 1574852 - part 31: Move `HTMLEditRules::IsEmptyInline()` and `HTMLEditRules::ListIsEmptyLine()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43192

--HG--
extra : moz-landing-system : lando
2019-08-25 06:59:24 +00:00
Masayuki Nakano bff247acdd Bug 1574852 - part 30: Move `HTMLEditRules::NormalizeSelection()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D43191

--HG--
extra : moz-landing-system : lando
2019-08-25 06:19:48 +00:00
Masayuki Nakano ff26989c8d Bug 1574852 - part 29: Merge `HTMLEditRules::GetListActionNodes()` with `HTMLEditor::CollectEditTargetNodes()` r=m_kato
This patch fixes an existing bug with this clean up.

Except `HTMLEditRules::MoveBlock()`, `GetListActionNodes()` is called after
calling `SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges()`
or `CollectEditTargetNodesInExtendedSelectionRanges()` **with**
`EditSubAction::eCreateOrChangeList`.  I think that `HTMLEditRules::MoveBlock()`
using the edit sub-action is a simple mistake.  Perhaps, it should be
`EditSubAction::eCreateOrRemvoeBlock`.  However, I'm not 100% sure because
`HTMLEditor::CollectEditTargetNodes()` does special handling for
`EditSubAction::eCreateOrRemvoeBlock` but not so for
`EditSubAction::eCreateOrChangeList`.  The behavior of difference between
those edit sub-actions are only here.  Therefore, this patch creates new
`EditSubAction` `eMergeBlockContents` for `MoveBlock()`.

Then, this patch makes `HTMLEditor::CollectEditTargetNodes()` handle
`EditSubAction::eCreateOrChangeList` insead of `GetListActionNodes()`.
This causes one logic change in `SplitInlinesAndCollectEditTargetNodes()`.
It calls `MaybeSplitElementsAtEveryBRElement()` after `CollectEditTargetNodes()`
so that this change makes calling `MaybeSplitElementsAtEveryBRElement()` at
last.  According to my tests, new behavior must be expected since `<br>`
elements outside and in `<table>` should be handled consistently.  Therefore,
this patch adds some simple testcases into WPT.

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

--HG--
extra : moz-landing-system : lando
2019-08-25 04:20:34 +00:00
Masayuki Nakano 24835249e4 Bug 1574852 - part 28: Make methods collecting event target nodes take additional argument which can specify whether `aOutArrayOfNodes` includes non-editable nodes or not r=m_kato
`HTMLEditRules::GetListActionNodes()` removes non-editable element.  However,
this should've been done by collector methods.

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

--HG--
extra : moz-landing-system : lando
2019-08-25 04:11:06 +00:00
Masayuki Nakano 071b3d92c1 Bug 1574852 - part 27: Move first half of `HTMLEditRules::GetListActionNodes()` to `HTMLEditor` and each caller r=m_kato
First half of `HTMLEditoRules::GetListActionNodes()` does 2 things.  One is
trying to get parent list element of `Selection` ranges if `aEntireList` is
`EntireList::yes`.  If it found a list element, it does nothing anymore.
Otherwise, falls backs to `EntireList::no` case.  So, if each caller which
calls it with `EntireList::yes`, `GetListActionNodes()` does not need the
argument.  Therefore, this patch does it first.

Then, `GetListActionNodes()` calls
`CollectEditTargetNodesInExtendedSelectionRanges()` or
`SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges()`.  It's
considered with `aTouchContent` is `yes` or `no`.  So, this should be done
by each caller for making it clearer.

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

--HG--
extra : moz-landing-system : lando
2019-08-25 03:45:34 +00:00
Masayuki Nakano 4b1fe5b646 Bug 1574852 - part 26: Move a part of `HTMLEditRules::LookInsideDivBQandList()` and remove the others r=m_kato
`HTMLEditRules::LookInsideDivBQandList()` does complicated things and I cannot
explain with a method name what it does.  Fortunately, there are only 2 callers.
Therefore, this patch duplicates the part of modifying the range and creates
a method to retrieve "deepest and only editable child of `<div>`, `<blockquote>`
and one of list items".

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

--HG--
extra : moz-landing-system : lando
2019-08-23 09:20:05 +00:00
Masayuki Nakano 7002a0f988 Bug 1574852 - part 25: Move `HTMLEditRules::GetChildNodesForOperation()` to `HTMLEditor` r=m_kato
It just collects all children of given node so that it can be a static method
in `HTMLEditor`.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 07:34:38 +00:00
Masayuki Nakano 6b6f24ee0f Bug 1574852 - part 24: Move `HTMLEditRules::GetNodesFromPoint()` to `HTMLEditor` r=m_kato
It's called only from `HTMLEditRules::MoveBlock()`.  Even though it has 4
patters to call different methods, we need only one of them.  Therefore,
this patch moves it into `HTMLEditor.h` as
`SplitInlinesAndCollectEditTargetNodesInOneHardLine()`.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 07:33:50 +00:00
Masayuki Nakano 6a2026a28d Bug 1574852 - part 23: Move `HTMLEditRules::GetNodesFromSelection()` to `HTMLEditor` r=m_kato
`HTMLEditRules::GetNodesFromSelection()` has a patch to call
`HTMLEditor::GetSelectionRangesExtendedToIncludeAdjuscentWhiteSpaces()`.
However, nobody uses this path so that we can get rid of this path.
Then, it becomes just calling `SplitInlinesAndCollectEditTargetNodes()` or
`CollectEditTargetNodes()` with result of
`GetSelectionRangesExtendedToHardLineStartAndEnd()`.  Therefore, we can split
it to `SplitInlinesAndCollectEditTargetNodesInExtendedSelectionRanges()` and
`CollectEditTargetNodesInExtendedSelectionRanges()`.  Then, we can mark
only the former as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 07:04:15 +00:00
Masayuki Nakano dd792e1d82 Bug 1574852 - part 22: Move `HTMLEditRules::GetPromotedRanges()` to `HTMLEditor` r=m_kato
`HTMLEditRules::GetPromotedRanges()` does 2 things.  Calling
`CreateRangeIncludingAdjuscentWhiteSpaces()` or
`CreateRangeExtendedToHardLineStartAndEnd()` with each range of `Selection`.
The difference is considered with current edit sub-action.  Therefore, we cal
split it to `GetSelectionRangesExtendedToIncludeAdjuscentWhiteSpaces()` and
`GetSelectionRangesExtendedToHardLineStartAndEnd()`.  Then, we got clearer code
at each caller.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 06:55:34 +00:00
Masayuki Nakano 620c07b2bb Bug 1574852 - part 21: Move `HTMLEditRules::PromoteRange()` to `HTMLEditor` r=m_kato
The method name is really unclear what's done.  The method does 3 things.
One is try to select a `<br>` element in empty block if given range is
collapsed in the block.  This is moved as
`HTMLEditor::SelectBRElementIfCollapsedInEmptyBlock()`.  Next, it extends the
given range to include adjuscent whitespaces only when edit sub-action is
inserting or deleting text.  This is moved as
`HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces()`.  Finally, when
handling the other edit sub-actions, extends the given range to start/end
of line at both edges.  This is moved as
`HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd()`.

And also this patch makes each caller of `PromoteRange()` to check edit
sub-action by themselves.  Unfortunately, this duplicates same logic to
multiple places, but makes what they do clearer.  I think that the duplication
issue should be fixed later if necessary.  Instead, we should shine the
blackbox of `HTMLEditRules` right now.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 06:32:27 +00:00
Masayuki Nakano 39bbc90bb9 Bug 1574852 - part 20: Move `HTMLEditRules::GetPromotedPoint()` to `HTMLEditor` r=m_kato
`HTMLEditRules::GetPromotedPoint()` does too many things.  Therefore, this patch
splits it to 3 methods.  One is for specific `EditSubAction` values, that's
the first block in `GetPromotedPoint()`.  It's named as
`GetWhiteSpaceEndPoint()`.  Next one is for expanding start of the range to
start of its line.  It's named as `GetCurrentHardLineStartPoint()`.  The last
one is for expanding end of the range to end of its line.  It's named as
`GetCurrentHardLineEndPoint()`.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 06:05:38 +00:00
Masayuki Nakano b8dba99d81 Bug 1574852 - part 19: Move `HTMLEditRules::GetNodesForOperation()` to `HTMLEditor` r=m_kato
This does not move the method simply.  Instead, splits it to 4 simpler
methods.

Despite of the name, it modifies the DOM tree if `aTouchContent` is
`TouchContent::yes`.  For avoiding this confusion and avoiding unnecessary
`MOZ_CAN_RUN_SCRIPT` attribute, the main part is split to
`HTMLEditor::CollectEditTargetNodes()`.

 If callers want to call `HTMLEditRules::GetNodesForOperation()` with
`TouchContent::no`, only calling this method equals to the call of
`GetNodesForOperation()`.

Otherwise, the callers should call
`HTMLEditor::SplitInlinesAndCollectEditTargetNodes()`.  This calls internal
methods automatically.

First, `HTMLEditor::SplitTextNodesAtRangeEnd()` splits text nodes at end of
each range.  Then, `HTMLEditor::SplitParentInlineElementsAtRangeEdges()`
overload splits inline elements at both edges of each range.  Then, collects
event target nodes with calling `HTMLEditor::CollectEditTargetNodes()`.
Finally, `HTMLEditor::MaybeSplitElementsAtEveryBRElement()` may split the
result nodes at every <br> element in them.

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

--HG--
extra : moz-landing-system : lando
2019-08-23 04:38:28 +00:00
Masayuki Nakano 2271a1a433 Bug 1574852 - part 18: Move `HTMLEditRules::BustUpInlinesAtBRs()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42789

--HG--
extra : moz-landing-system : lando
2019-08-23 04:14:56 +00:00
Masayuki Nakano 6cb490583d Bug 1574852 - part 17: Move `HTMLEditRules::GetInnerContent()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42788

--HG--
extra : moz-landing-system : lando
2019-08-23 03:35:40 +00:00
Masayuki Nakano 9cd140da4a Bug 1574852 - part 16: Move `HTMLEditRules::BustUpInlinesAtRangeEndpoints()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42787

--HG--
extra : moz-landing-system : lando
2019-08-23 01:28:26 +00:00
Masayuki Nakano 495df615e7 Bug 1574852 - part 15: Move `HTMLEditUtils::GetHighestInlineParent()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42786

--HG--
extra : moz-landing-system : lando
2019-08-22 08:47:50 +00:00
Masayuki Nakano bee148c761 Bug 1574852 - part 14: Move `HTMLEditRules::InsertBRElement()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42785

--HG--
extra : moz-landing-system : lando
2019-08-22 08:33:28 +00:00
Masayuki Nakano 6c17e180aa Bug 1574852 - part 13: Move `HTMLEditRules::CanContainParagraph()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42784

--HG--
extra : moz-landing-system : lando
2019-08-22 08:29:38 +00:00
Masayuki Nakano d0797846a4 Bug 1574852 - part 12: Move `HTMLEditRules::SplitMailCites()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42783

--HG--
extra : moz-landing-system : lando
2019-08-22 08:29:16 +00:00
Masayuki Nakano ba9cfcb2a7 Bug 1574852 - part 11: Move `HTMLEditRules::GetTopEnclosingMailCite()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42782

--HG--
extra : moz-landing-system : lando
2019-08-22 13:11:16 +00:00
Masayuki Nakano f23c09bbd0 Bug 1574852 - part 10: Move `HTMLEditRules::WillInsertText()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42781

--HG--
extra : moz-landing-system : lando
2019-08-22 08:01:39 +00:00
Masayuki Nakano 3822de5442 Bug 1574852 - part 9: Move `HTMLEditRules::CreateStyleForInsertText()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42780

--HG--
extra : moz-landing-system : lando
2019-08-22 07:33:41 +00:00
Masayuki Nakano 7ed950a31c Bug 1574852 - part 8: Move `HTMLEditRules::WillInsert()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42778

--HG--
extra : moz-landing-system : lando
2019-08-22 07:08:19 +00:00
Masayuki Nakano f135e00456 Bug 1574852 - part 6: Move `HTMLEditRules::CacheInlineStyles()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42776

--HG--
extra : moz-landing-system : lando
2019-08-22 05:13:50 +00:00
Masayuki Nakano ab4e7103b0 Bug 1574852 - part 5: Move `HTMLEditRules::ReapplyCachedStyles()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42775

--HG--
extra : source : 6456b7a6cc679d744637e639d37cb73e795c1357
2019-08-22 05:12:28 +00:00
Noemi Erli 8586a20580 Backed out changeset 6456b7a6cc67 (bug 1574852) for failing in browser_html_tooltip-05.js 2019-08-22 11:41:29 +03:00
Masayuki Nakano df6c33c509 Bug 1574852 - part 5: Move `HTMLEditRules::ReapplyCachedStyles()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42775

--HG--
extra : moz-landing-system : lando
2019-08-22 05:12:28 +00:00
Masayuki Nakano 0d08551fbd Bug 1574852 - part 4: Move `HTMLEditRules::GetInlineStyles()` to `HTMLEditor` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42774

--HG--
extra : moz-landing-system : lando
2019-08-22 01:10:30 +00:00
Masayuki Nakano d22d8c911e Bug 1574852 - part 2: Replace `HTMLEditRules::IsInlineNode()` with `HTMLEditor::NodeIsInlineStatic()` r=m_kato
`HTMLEditRules::IsInlineNode()` is a wrapper of
`HTMLEditor::NodeIsInlineStatic()`, but returns opposite value.

This patch moves it into `HTMLEditor` and names it with same rule as
`NodeIsBlockStatic()`.

Note that this method may return true if given node is unexpected node type.
E.g., comment node, CDATA node, etc.  However, it's not scope of this bug.

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

--HG--
extra : moz-landing-system : lando
2019-08-21 07:13:41 +00:00
Masayuki Nakano 24e7c7235d Bug 1574852 - part 1: Get rid of `HTMLEditRules::IsBlockNode()` r=m_kato
`HTMLEditRules::IsBlockNode()` just wraps `HTMLEditor::NodeIsBlockStatic()`
and all its users will be moved into `HTMLEditor`.  Therefore, we should
unwrap it.

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

--HG--
extra : moz-landing-system : lando
2019-08-21 06:21:05 +00:00
Masayuki Nakano 0cc09df825 Bug 1572685 - part 9: Move `HTMLEditRules::mDocChangeRange` to `TopLevelEditSubActionData` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42104

--HG--
extra : moz-landing-system : lando
2019-08-20 01:51:59 +00:00
Masayuki Nakano d696ee098d Bug 1572685 - part 7: Move `HTMLEditRules::mRangeItem` to `TopLevelEditSubActionData` r=m_kato
For avoiding allocation cost of `RangeItem`, it should be stored by `HTMLEditor`
and reused by all `TopLevelEditSubActionData` instances for the editor instance.

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

--HG--
extra : moz-landing-system : lando
2019-08-20 01:51:19 +00:00
Mirko Brodesser 81a41b2d7d Bug 1573119: declare more methods around `HTMLEditor` `const`/`static`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D41524

--HG--
extra : moz-landing-system : lando
2019-08-13 07:34:11 +00:00
Masayuki Nakano 485a59c303 Bug 1572375 - part 7: Get rid of `HTMLEditRules::OnModifyDocument()` r=m_kato
`HTMLEditRules::OnModifyDocument()` is same as just calling
`EditorBase::EnsureNoPaddingBRElementForEmptyEditor()` and
`EditorBase::MaybeCreatePaddingBRElementForEmptyEditor()` so that this patch
gets rid of the method, then, creates `HTMLEditor::OnModifyDocumentInternal()`
and makes it do same thing.

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

--HG--
extra : moz-landing-system : lando
2019-08-13 00:56:57 +00:00
Mirko Brodesser a83f7bfa50 Bug 1572715: part 2) Make some methods around `HTMLEditor` const-correct. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D41385

--HG--
extra : moz-landing-system : lando
2019-08-12 08:31:04 +00:00
Mirko Brodesser d0e7afc285 Bug 1572715: part 1) Factor out `WSRunScanner` from `WSRunObject`. r=masayuki
This allows users of `WSRunScanner`'s functionality to pass a `const
HTMLEditor*`, allowing themselves to become const-correct.

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

--HG--
extra : moz-landing-system : lando
2019-08-12 08:30:57 +00:00
Mirko Brodesser 1274c8140e Bug 1572060: declare a few methods around HTMLEditor static/const. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D40982

--HG--
extra : moz-landing-system : lando
2019-08-07 15:58:41 +00:00
Masayuki Nakano 11ae238f0f Bug 1569902 - part 4: Make `TextEditor` inserts padding `<br>` element for empty last line after setting flags to `NS_PADDING_FOR_EMPTY_LAST_LINE` r=m_kato
Stopping using attribute for "moz-br", `IMEContentObserver` cannot know when
new `<br>` element is changed to padding element for empty last line.
Therefore, editor needs to insert padding `<br>` element after setting the
flag properly.  Then, `IMEContentObserver` does not need to recompute the
length of `<br>` element (if it's for padding, it computes the length as 0).

Unfortunately, `TextEditor::InsertBrElementWithTransaction()` is used in too
many places and it already has optional argument.  Therefore, it's difficult
to change it.  However, we should share the preparation before creating `<br>`
element in it with new method.  Therefore, this patch creates
`EditorBase::PrepareToInsertBRElement()` to share the preparation point (almost
just moved from the method).  Then, new method is created as
`EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction()` because
it's used both in `TextEditor` and `HTMLEditor`.  Finally, `TextEditor` won't
insert `<br>` element with `InsertBrElementWithTransaction()`.  Therefore, it's
moved to `HTMLEditor` with renaming to `InsertBRElementWithTransaction()`.

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

--HG--
extra : moz-landing-system : lando
2019-08-02 05:46:41 +00:00
Masayuki Nakano 23a22c597a Bug 1569902 - part 2: Stop using attribute to consider whether a `<br>` element is a special node for empty last line or not r=m_kato,smaug
Editor creates a `<br>` element to end of a block if last line
of the block is empty because caret should be placed as there is an empty
line.  Such special `<br>` element has `type` attribute whose value is "_moz".
However, adding/removing the attribute is expensive and such hacky attribute
shouldn't be referred nor changed by web apps.

Therefore, this patch makes `HTMLBRElement` take another specific flag whether
it's a special node for empty last line.  For making the meaning clearer,
this patch calls the such `<br>` elements as "padding `<br>` element for
empty last line" insead of "moz-br".  So, this patch also includes a lot of
renaming methods and variables, and modifying related comments.

Note that with this change, `IMEContentObserver` counts the padding `<br>`
element in `<textarea>` because it's inserted before setting the new flag
and setting the flag does not cause DOM tree mutation.  This issue will be
fixed by the following patches.

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

--HG--
extra : moz-landing-system : lando
2019-08-02 05:45:18 +00:00
Masayuki Nakano ca49cc9d2d Bug 1548389 - part 0: Wrap modifying text node in editor with particular methods r=m_kato
In the next patch, we need to update unmasked range when anonymous text node
in `<input type="password">` is modified.  This patch makes editor manage it
easier to update the range.

Note that the next patch also handles text node creation and destruction.

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

--HG--
extra : moz-landing-system : lando
2019-07-22 03:53:29 +00:00
Emilio Cobos Álvarez 28801c9e84 Bug 1218456 - Allow navigating when there's no pres context. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D37404
2019-07-09 23:07:29 +02:00
Dorel Luca 9925ca654c Backed out 5 changesets (bug 1218456) for Crashtest failures on dom/l10n/tests/mochitest/dom_localization/test_overlay.html. CLOSED TREE
Backed out changeset 31afe89c2d42 (bug 1218456)
Backed out changeset 8bd57ebc4528 (bug 1218456)
Backed out changeset e5d37afff36a (bug 1218456)
Backed out changeset e3da86278ecf (bug 1218456)
Backed out changeset 343046089f8e (bug 1218456)

--HG--
extra : rebase_source : f092d903c8c80581d187493e036b1875d8668b3d
2019-07-09 22:04:13 +03:00
Emilio Cobos Álvarez d5db3842a0 Bug 1218456 - Allow navigating when there's no pres context. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D37404

--HG--
extra : moz-landing-system : lando
2019-07-09 16:17:27 +00:00
Masayuki Nakano a1b8ba8568 Bug 1556235 - Make `HTMLEditRules::WillDeleteSelection()` remove empty parent blocks when it's called by drop handler r=m_kato
Chromium removes new empty blocks only when the content is removed by dragging.
Before bug 1504910, we just removed the dragged range, i.e., kept the new
empty blocks.  However, now, we put `<br>` element from
`HTMLEditRules::AfterEditInner()` because a D&D action was split to the deletion
part and inserting part (It wasn't called after inserting the dropped content).

Therefore, this patch adds new path for D&D into
`HTMLEditRules::WillDeleteSelection()`.  If parent blocks become empty,
the path removes such blocks and collapse `Selection` to where the most
ancestor empty block was.  With this patch, we get same behavior as Chrome
in most cases.  You can check it in https://jsfiddle.net/d_toybox/9px07yLr/

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

--HG--
extra : moz-landing-system : lando
2019-06-10 10:31:13 +00:00
Masayuki Nakano 84cbc7e792 Bug 1529884 - part 6: Through subject principal at Document::ExecCommand() to constructor of EditorBase::AutoEditActionDataSetter r=smaug
`Document::ExecCommand()` knows subject principal.  This patch makes it tell
`EditorCommand::DoCommand()` and `EditorCommand::DoCommandParam()`.  Then,
makes they tell each editor public methods which may cause dispatching
`beforeinput` event once we implement it.  Finally, each editor public
method sets it to the constructor of `EditorBase::AutoEditActionDataSetter`.
This means that when editor tries to dispatch `beforeinput` event, editor
can check whether it's called by JS or not from everywhere.

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

--HG--
extra : moz-landing-system : lando
2019-06-10 10:27:07 +00:00
Masayuki Nakano d9e3ea7e57 Bug 1426709 - Make HTMLEditor update selection ancestor limit synchronously when editing host is changed to ancestor element r=smaug
`HTMLEditor` initializes selection ancestor limit when it receives `focus`
event.  If `Document.execCommand()` is called immediately after an
ancestor of active editing host becomes new editing host,
`HTMLEditor::GetActiveEditingHost()` returns the new one, but selection
ancestor limit is still the previous one.  This mismatch causes a lot of
bugs.  Therefore, this patch makes `nsGenericHTMLElement` notifies `HTMLEditor`
of an element becoming `contenteditable`, and makes `HTMLEditor` update
selection ancestor limit only when the new editing host is ancestor of
old selection ancestor limit.

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

--HG--
extra : moz-landing-system : lando
2019-06-04 08:42:43 +00:00
Masayuki Nakano e61b4bc007 Bug 1551185 - Make nsImageFrame::ShouldDisplaySelection() check whether resizer target element is its content or not r=smaug
Currently, `nsISelectionDisplay::DISPLAY_ALL` is used only by `HTMLEditor`.
And only when it's set, `nsImageFrame::ShouldDisplaySelection()` returns `false`
if only its `mContent` is selected.  However, this is based on an assumption,
that is, when only one `<img>` is selected in an HTML editor, it's target of
resizers.  However, this is completely wrong.  Web apps can disable resizers
with `document.execCommand("enableObjectResizing", false, false)` and now,
it's disabled by default.

Therefore, this patch makes the method check whether its `mContent` is
target of resizers at the moment.

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

--HG--
extra : moz-landing-system : lando
2019-05-24 12:02:34 +00:00
Masayuki Nakano 19fbb1a392 Bug 1549925 - Mark all methods of nsIDocumentStateListener as can_run_script r=m_kato
`nsIDocumentStateListener` is a scriptable interface and each method may run
any script.  So, we should mark them as `can_run_script`.  Then, we need to
mark a lot of editing methods because we need to mark
`EditorBase::EndTransactionInternal()` and `EditorBase::DoTransactionInternal()`
as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
2019-05-09 07:37:51 +00:00
Masayuki Nakano 4579004eac Bug 1549319 - Make template methods marked as MOZ_CAN_RUN_SCRIPT take only EditorDOMPoint (i.e., not allow EditorRawDOMPoint) r=m_kato
It'd be better to change copy constructor of `EditorDOMPointBase` to explicit,
but it'd require too many changes in editor code.  So, this patch just changes
each method callers only.

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

--HG--
extra : moz-landing-system : lando
2019-05-08 09:40:17 +00:00
Masayuki Nakano f761cbd2bc Bug 1549302 - Mark EditorBase::DeleteTextWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30049

--HG--
extra : moz-landing-system : lando
2019-05-08 06:31:48 +00:00
Masayuki Nakano ed4cc22661 Bug 1549270 - part 3: Mark EditorBase::SetAttributeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30047

--HG--
extra : moz-landing-system : lando
2019-05-08 06:26:25 +00:00
Masayuki Nakano 6d224d7259 Bug 1549270 - part 2: Mark EditorBase::RemoveAttributeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30044

--HG--
extra : moz-landing-system : lando
2019-05-08 05:09:56 +00:00
Masayuki Nakano 48d2fce863 Bug 1549268 - Mark EditorBase::JoinNodesWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30041

--HG--
extra : moz-landing-system : lando
2019-05-08 02:29:43 +00:00
Masayuki Nakano f440ac739a Bug 1549264 - Mark EditorBase::SplitNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30039

--HG--
extra : moz-landing-system : lando
2019-05-07 22:34:28 +00:00
Masayuki Nakano 0925cb9a70 Bug 1549155 - Mark EditorBase::DeleteNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D30038

--HG--
extra : moz-landing-system : lando
2019-05-07 22:27:29 +00:00
Masayuki Nakano 9405d61cb8 Bug 1546577 - Make overloads of CanCut(), CanCopy(), CanDelete() and CanPaste() which return bool instead of nsresult r=m_kato
`CanCut()`, `CanCopy()` and `CanPaste()` return error only when the editor has
already been destroyed or not been initialized yet, or when failed to access
clipboard when the document is not HTML/XHTML.

`CanDelete()` returns error only when the editor has already been destroyed or
not been initialized yet.

So, these error result won't be exposed to the web in most cases and such
exception shouldn't stop any content script because Chrome basically does not
throw exception in such situation as far as I know.

Therefore, there should be overloads of them to return `bool` result directly
for making their callers simpler.

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

--HG--
extra : moz-landing-system : lando
2019-04-25 07:14:39 +00:00
Masayuki Nakano 349901dac4 Bug 1539110 - Make HTMLEditor::RemoveStyleInside() and HTMLEditor::SplitStyleAbovePoint() check tag names with whitelist r=m_kato
`document.execCommand("removeformat")` removes any elements in the range which
are editable, not `<a>`, not block and a container.
https://searchfox.org/mozilla-central/rev/dd7e27f4a805e4115d0dbee70e1220b23b23c567/editor/libeditor/HTMLStyleEditor.cpp#760-763

This means that it removes hidden elements like `<script>` and `<style>`,
or non-HTML elements like SVG elements.  However, the unofficial document
of `execCommand()` lists up elements which should be handled by the command.
https://w3c.github.io/editing/execCommand.html#removeformat-candidate

Additionally, Chrome respects this list since not including `<del>` element
into the list does not make sense but Chrome ignores it.  So, we should
respect the list.

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

--HG--
extra : moz-landing-system : lando
2019-04-12 01:17:50 +00:00
Masayuki Nakano 3e64f2c30d Bug 1539356 - Mark EditorBase::InsertNodeTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
This patch marks `EditorBase::InsertNodeTransaction()` **and** its callers as `MOZ_CAN_RUN_SCRIPT`.

Unfortunately, this patch tells us that some `GetSomething()` methods may destroy the editor since `HTMLEditRules::GetNodesForOperation()`, `HTMLEditRules::GetNodesFromPoint()` and `HTMLEditRules::GetNodesFromSelection()` may change the DOM tree.  Additionally, initialization methods may destroy the editor since it may insert a bogus `<br>` node.

Note that this patch also removes some unused methods. I.e., they are not result of some cleaning up the code. This patch just avoids marking unused methods as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
2019-03-30 11:55:29 +00:00
Oana Pop Rus 43fadb6745 Backed out changeset 447c87c2d139 (bug 1539356) on request of Jorg K. a=backout 2019-03-30 00:42:32 +02:00
Masayuki Nakano 81b30d7143 Bug 1539356 - Mark EditorBase::InsertNodeTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
This patch marks `EditorBase::InsertNodeTransaction()` **and** its callers as `MOZ_CAN_RUN_SCRIPT`.

Unfortunately, this patch tells us that some `GetSomething()` methods may destroy the editor since `HTMLEditRules::GetNodesForOperation()`, `HTMLEditRules::GetNodesFromPoint()` and `HTMLEditRules::GetNodesFromSelection()` may change the DOM tree.  Additionally, initialization methods may destroy the editor since it may insert a bogus `<br>` node.

Note that this patch also removes some unused methods. I.e., they are not result of some cleaning up the code. This patch just avoids marking unused methods as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
2019-03-29 10:55:31 +00:00
Masayuki Nakano 0a753c3aac Bug 1533293 - part 3: Make editor and ContentEventHandler not use Selection::Extend() due to too slow r=m_kato
`Selection::Extend()` is too slow but editor and ContentEventHandler use it in
some places.  We should make them use `Selection::SetStartAndEndInLimiter()` or
`Selection::SetBaseAndExtentInLimiter()`.  The former is usable only when caller
guarantees the start point is prior to the end point in the DOM tree.
Otherwise, we need to use the latter even though it's slower than the former.

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

--HG--
extra : moz-landing-system : lando
2019-03-26 10:09:47 +00:00
Masayuki Nakano 534fd23ca4 Bug 1533293 - part 2: Rewrite EditorBase::SelectEntireDocument() and its overrides r=m_kato
`EditorBase::SelectEntierDocument()` uses `Selection::Extend()` but it's too
slow.  It should use `Selection::SetStartAndEndInLimiter()` instead.

Additionally, `TextEditor::SelectEntierDocument()` shrink the result of
`EditorBase::SelectEntierDocument()` with `Selection::Extend()` if there is
a `moz-<br>` element.  So, `TextEditor::SelectEntinerDocument()` should set
its expected selection with a call for saving the runtime cost.

Then, we don't need to make `EditorBase::SelectEntierDocument()` as non-pure
virtual method.  So, this patch makes each its callers call
`Selection->SelectAllChildren()` directly.

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

--HG--
extra : moz-landing-system : lando
2019-03-26 10:06:43 +00:00
Noemi Erli 165f0d8c1c Backed out 3 changesets (bug 1533293) for causing Bug 1536595 a=backout
Backed out changeset d011dfe83683 (bug 1533293)
Backed out changeset e536f6e123d8 (bug 1533293)
Backed out changeset 19cff61f4fed (bug 1533293)
2019-03-20 13:29:17 +02:00
Masayuki Nakano 6dd0ecdd8e Bug 1533293 - part 3: Make editor and ContentEventHandler not use Selection::Extend() due to too slow r=m_kato
`Selection::Extend()` is too slow but editor and ContentEventHandler use it in
some places.  We should make them use `Selection::SetStartAndEndInLimiter()` or
`Selection::SetBaseAndExtentInLimiter()`.  The former is usable only when caller
guarantees the start point is prior to the end point in the DOM tree.
Otherwise, we need to use the latter even though it's slower than the former.

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

--HG--
extra : moz-landing-system : lando
2019-03-18 01:52:36 +00:00
Masayuki Nakano 448571fd81 Bug 1533293 - part 2: Rewrite EditorBase::SelectEntireDocument() and its overrides r=m_kato
`EditorBase::SelectEntierDocument()` uses `Selection::Extend()` but it's too
slow.  It should use `Selection::SetStartAndEndInLimiter()` instead.

Additionally, `TextEditor::SelectEntierDocument()` shrink the result of
`EditorBase::SelectEntierDocument()` with `Selection::Extend()` if there is
a `moz-<br>` element.  So, `TextEditor::SelectEntinerDocument()` should set
its expected selection with a call for saving the runtime cost.

Then, we don't need to make `EditorBase::SelectEntierDocument()` as non-pure
virtual method.  So, this patch makes each its callers call
`Selection->SelectAllChildren()` directly.

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

--HG--
extra : moz-landing-system : lando
2019-03-18 01:51:53 +00:00
Masayuki Nakano 39daaa7db8 Bug 1534561 - Make editor use PresShell directly rather than nsIPresShell r=m_kato
`PresShell.h` is exposed as `mozilla/PresShell.h` and `PresShell` is the only
concrete class of `nsIPresShell`.  Therefore, we have no reason to access
`PresShell` via `nsIPresShell`.

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

--HG--
extra : moz-landing-system : lando
2019-03-15 05:01:10 +00:00
Boris Zbarsky 9a4ba73134 Bug 1534370 part 3. Mark InsertFromTransferable as MOZ_CAN_RUN_SCRIPT. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D23042

--HG--
extra : moz-landing-system : lando
2019-03-12 01:55:03 +00:00
Boris Zbarsky 358e378b63 Bug 1505029. Teach our static analysis about nsCOMPtr<nsISupports> being a strong ref. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D23021

--HG--
extra : moz-landing-system : lando
2019-03-12 21:04:07 +00:00
Masayuki Nakano f4e8c4a068 Bug 1528676 - Remove telemetry probes for HTMLEditors which have shown Gecko build-in editing UIs and if they are operated r=m_kato,Ehsan
Those probes are now expired and we got enough data:

- Almost no user uses the grip to move absolute positioned element
- There were over one thousand users using the inline table editor and the object resizers.
- Such users keep using even after we disabled the UIs by default.

Perhaps, such small number of users keep using the UIs, i.e., I guess the
number won't become smaller in short term.  Therefore, this patch removes the
telemetry probes and members of HTMLEditor which are necessary to call
Telemetry API.

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

--HG--
extra : moz-landing-system : lando
2019-02-22 02:17:27 +00:00
Masayuki Nakano 2eaf64e594 Bug 998941 - part 1-3: Make TextEditor (only when not HTMLEditor instance) set InputEvent.data to inserting string when InputEvent.inputType is "insertFromPaste", "insertFromDrop" or "insertReplacementText" r=smaug,m_kato
https://rawgit.com/w3c/input-events/v1/index.html#dfn-data
https://w3c.github.io/input-events/#dfn-data

Both Input Events Level 1 and Level 2 declare that InputEvent.data should be
set to inserting string only on TextEditor when InputEvent.inputType is
"insertFromPaste", "insertFromPasteAsQuotation", "insertFromDrop",
"insertTranspose", "insertReplacementText" or "insertFromYank".

Currently, we support only "insertFromPaste", "insertFromDrop",
"insertReplacementText".  Therefore, this patch makes TextEditor set
EditorBase::mEditActionData::mData only for them (and the instance is not
HTMLEditor's).

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

--HG--
extra : moz-landing-system : lando
2019-02-19 06:28:57 +00:00
Emilio Cobos Álvarez d2ed260822 Bug 1517241 - Rename nsIDocument to mozilla::dom::Document. r=smaug
Summary: Really sorry for the size of the patch. It's mostly automatic
s/nsIDocument/Document/ but I had to fix up in a bunch of places manually to
add the right namespacing and such.

Overall it's not a very interesting patch I think.

nsDocument.cpp turns into Document.cpp, nsIDocument.h into Document.h and
nsIDocumentInlines.h into DocumentInlines.h.

I also changed a bunch of nsCOMPtr usage to RefPtr, but not all of it.

While fixing up some of the bits I also removed some unneeded OwnerDoc() null
checks and such, but I didn't do anything riskier than that.
2019-01-03 17:48:33 +01:00
Sylvestre Ledru 265e672179 Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format
# ignore-this-changeset

--HG--
extra : amend_source : 4d301d3b0b8711c4692392aa76088ba7fd7d1022
2018-11-30 11:46:48 +01:00
Masayuki Nakano 7348477018 Bug 1510183 - Make HTMLEditor treat empty string attribute of style as nullptr of nsAtom rather than nsGkAtoms::_empty r=m_kato
After fixing bug 1427060, HTMLEditor treats attribute of style as nullptr.
However, if empty string is used to call NS_Atomize(), it returns
nsGkAtoms::_empty.  Therefore, HTMLEditor fails to check whether attribute is
specified or not with nullptr check since some root callers sets
nsGkAtoms::_empty instead of nullptr.

This patch makes HTMLEditor always use nullptr for empty string of attribute
of style with wrapping NS_Atomize() with AtomzieAttribute().  Additionally,
for safer change, this patch makes PropItem and TypeInState treat
nsGkAtom::_empty as nullptr.

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

--HG--
extra : moz-landing-system : lando
2018-11-30 01:21:59 +00:00
Masayuki Nakano abe138f771 Bug 1504911 - part 1: Make all "input" event dispatcher in C++ use new utility method r=smaug
Currently, a lot of code dispatch "input" event and some of them dispatch
"input" event with wrong interface and/or values.  Therefore this patch
creates nsContentUtils::DispatchInputEvent() to make all of them dispatch
correct event.

Unfortunately, due to bug 1506439, we cannot set pointer to refcountable
classes of MOZ_CAN_RUN_SCRIPT method to nullptr.  Therefore, this patch
creates temporary RefPtr<TextEditor> a lot even though it makes damage to
the performance if it's in a hot path.

This patch makes eEditorInput event dispatched with
InternalEditorInputEvent when "input" event should be dispatched with
dom::InputEvent.  However, this patch uses WidgetEvent whose message is
eUnidentifiedEvent and setting WidgetEvent::mSpecifiedEventType to
nsGkAtoms::oninput when "input" event should be dispatched with
dom::Event because we need to keep that eEditorInput and
InternalEditorInputEvent are mapped each other.

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

--HG--
extra : moz-landing-system : lando
2018-11-21 03:59:02 +00:00
Masayuki Nakano 9f7af9d8fc Bug 1504910 - part 1: Clean up methods which are called by TextEditor::OnDrop() r=m_kato
TextEditor::OnDrop() calls TextEditor::InsertFromDataTransfer() or
HTMLEditor::InsertFromDataTransfer() and they are called only by
TextEditor::OnDrop().

TextEditor::InsertFromDataTransfer() calls only TextEditor::InsertTextAt()
and TextEditor::InsertTextAt() calls only TextEditor::InsertTextAsSubAction() if
insertion point is nullptr.  Therefore, if the callers sets nullptr, they
should call TextEditor::InsertTextAsSubAction() directly.  Then, we can
make TextEditor::InsertTextAt() require non-nullptr insertion point.

HTMLEditor::InsertFromDataTransfer() calls HTMLEditor::InsertObject(),
HTMLEditor::DoInsertHTMLWithContext() or TextEditor::InsertTextAt().

HTMLEditor::InsertObject() calls HTMLEditor::DoInsertHTMLWithContext()
directly or via BlobReader (in this case, calls asynchronously).

Unfortunately both HTMLEditor::InsertObject() and
HTMLEditor::DoInsertHTMLWithContext() are called by
HTMLEditor::InsertFromTransferable() which is paste event handler.  Therefore,
we cannot make them require non-nullptr insertion point, though, anyway,
they cannot become simpler even if we could do that.

This patch marks them as MOZ_CAN_RUN_SCRIPT as far as possible and
makes them take |const EditorDOMPoint&| for insertion point.

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

--HG--
extra : moz-landing-system : lando
2018-11-09 08:40:57 +00:00
Masayuki Nakano dbc466a1f7 Bug 1504131 - part 2: Remove ResizerMouseMotionListener r=m_kato
ResizerMouseMotionListener listens to "mousemove" events for resizers
or grabber to move absolutely position element and it calls only
HTMLEditor::MouseMove().  Fortunately, neither EditorEventListener not
HTMLEditorEventListener listens to "mousemove" events.  Therefore, we
can use HTMLEditorEventListener instead.

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

--HG--
extra : moz-landing-system : lando
2018-11-06 06:09:18 +00:00
Masayuki Nakano b5f863bf51 Bug 1504131 - part 1: Remove DocumentResizeEventListener r=m_kato
DocumentResizeEventListener listens to only "resize" events of the window
and when it fired, it just calls HTMLEditor::RefreshResizers().  Fortunately,
neither EditorEventListener nor HTMLEditorEventListener listens to "resize"
events.  Therefore, we can move this implementation into
HTMLEditorEventListener.

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

--HG--
extra : moz-landing-system : lando
2018-11-06 04:58:29 +00:00
Masayuki Nakano 2bde324acf Bug 1501663 - part 7: HTMLEditor::GetSelectedElement() shouldn't return element node when Selection starts before the element node r=m_kato
This fixes odd case of this API.  GetSelectedElement() ignores non-element
nodes before an element node.  This must be intended to allow Selection to
start from in an element node.  However, current code allows to select starting
from previous text node.  This patch changes this behavior to stop looking
for element node if non-element node appears before an element node.

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

--HG--
extra : moz-landing-system : lando
2018-11-05 11:38:10 +00:00
Masayuki Nakano 2654031504 Bug 1501663 - part 2: HTMLEditor::GetSelectedElement() should return nullptr if 2 or more elements are in selected range r=m_kato
This is also regression of bug 1432944, but hidden by the optimization of
bug 1482019.

In bug 1482019, we removing the code clearing |found| flag when the loop
meets second element in selection range.
https://searchfox.org/mozilla-central/diff/0dd29e18302c5e6b07b88aac7164889d752acda7/editor/libeditor/HTMLEditor.cpp#2751-2753
because the flag won't be referred.

However, before the fix of bug 1432944, it's referred and the cleared flag
makes the method return nullptr.

Therefore, this patch makes it return nullptr when 2 or more elements are
in selected range.

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

--HG--
extra : moz-landing-system : lando
2018-11-05 04:57:02 +00:00
Masayuki Nakano fa95dc80c3 Bug 1501663 - part 1: HTMLEditor::GetSelectedElement() should return nullptr when first found element is not what the caller is looking for r=m_kato
This takes back old behavior, 59 or earlier version.

|selectedElement| may be set to an element which is not what the caller is
looking for.  Therefore, if the first element node in the selected range is
not what the caller is looking for, it should return nullptr.

This regression is caused by this changeset:
https://hg.mozilla.org/mozilla-central/rev/93c1d149d757 (bug 1432944)

Additionally, this patch modifies the automated test for conforming to
original idea of the API.  This API must not be intended to retrieve
usual inline elements like <b>, <i>, etc.

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

--HG--
extra : moz-landing-system : lando
2018-11-05 03:52:10 +00:00
Masayuki Nakano f6c59cabb6 Bug 1504093 - Make DocumentResizeEventListener::HandleEvent() call public methods of HTMLEditor r=m_kato
DocumentResizeEventListener::HandleEvent() calls protected method,
HTMLEditor::RefreshResizersInternal().  However, this method is an event
handler, i.e., called when the editor is not handling an edit action.

Therefore, for ensuring AutoEditActionDataSetter instance, it should call
public method, nsIHTMLEditor::RefereshResizers() instead.

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

--HG--
extra : moz-landing-system : lando
2018-11-05 06:28:53 +00:00
Masayuki Nakano dbbd5b9823 Bug 1503565 - Make HTMLEditor::BlobReader::OnResult() create AutoEditActionDataSetter r=m_kato
HTMLEditor::BlobReader::OnResult() is a callback method and it calls
non-public method of HTMLEditor, DoInsertHTMLWithContext().  So,
DoInsertHTMLWithContext() may need caller to have already created
AutoEditActionDataSetter instance.  Therefore, BlobReader should keep
EditAction which is the purpose of creating it and its OnResult() should
create AutoEditActionDataSetter instance with it.

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

--HG--
extra : moz-landing-system : lando
2018-11-05 02:12:27 +00:00
Masayuki Nakano 8e6dd0bc8a Bug 1503473 - part 5: Move InsertParagraphSeparator*() into HTMLEditor r=m_kato
Now, TextEditor needs only InsertLineBreak*() so that
InsertParagraphSeparator*() is necessary only in HTMLEditor.
With overriding nsIPlaintextEditor::InsertLineBreak() in HTMLEditor,
we can do it simply.

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

--HG--
extra : moz-landing-system : lando
2018-11-03 04:19:22 +00:00
Masayuki Nakano 9b49e5d514 Bug 1503473 - part 4: Create a new path to handle Enter key press in TextEditor r=m_kato
This patch creates new path to insert a line break in TextEditor.

Declares new EditSubAction::eInsertLineBreak and makes the path use
EditAction::eInsertLineBreak instead of EditAction::eInsertParagraphSeparator.

Unfortunately, this patch makes TextEditor::InsertLineBreakAsAction() as
a virtual method for keeping this change as small as possible.

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

--HG--
extra : moz-landing-system : lando
2018-11-03 11:22:13 +00:00
Masayuki Nakano 18ee481a2d Bug 1503473 - part 1: Rename TextEditor::OnInputParagraphSeparator() and HTMLEditor::OnInputLineBreak() r=m_kato
TextEditor::OnInputParagraphSeparator() and HTMLEditor::OnInputLineBreak() are
also used by command handlers.  Therefore, they should be renamed to
TextEditor::InsertParagraphSeparatorAsAction() and
HTMLEditor::InsertLineBreakAsAction().  Then, current
TextEditor::InsertParagraphSeparatorAsAction() should be renamed to
AsSubAction() and each caller of it should create AutoPlaceholderBatch
by themselves.

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

--HG--
extra : moz-landing-system : lando
2018-11-03 11:19:07 +00:00
Cosmin Sabou 7da86ef60f Backed out 5 changesets (bug 1503473) for crashes in Thunderbird on request of jorgk. a=backout
Backed out changeset a7f7d9f366b9 (bug 1503473)
Backed out changeset d067907793ef (bug 1503473)
Backed out changeset 130ba0de053f (bug 1503473)
Backed out changeset ec732243e9ad (bug 1503473)
Backed out changeset 13511cab2b41 (bug 1503473)
2018-11-03 02:08:42 +02:00
Masayuki Nakano d481dba0c1 Bug 1503473 - part 5: Move InsertParagraphSeparator*() into HTMLEditor r=m_kato
Now, TextEditor needs only InsertLineBreak*() so that
InsertParagraphSeparator*() is necessary only in HTMLEditor.
With overriding nsIPlaintextEditor::InsertLineBreak() in HTMLEditor,
we can do it simply.

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

--HG--
extra : moz-landing-system : lando
2018-11-02 14:24:33 +00:00
Masayuki Nakano b1587d8dd4 Bug 1503473 - part 4: Create a new path to handle Enter key press in TextEditor r=m_kato
This patch creates new path to insert a line break in TextEditor.

Declares new EditSubAction::eInsertLineBreak and makes the path use
EditAction::eInsertLineBreak instead of EditAction::eInsertParagraphSeparator.

Unfortunately, this patch makes TextEditor::InsertLineBreakAsAction() as
a virtual method for keeping this change as small as possible.

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

--HG--
extra : moz-landing-system : lando
2018-11-02 13:10:43 +00:00
Masayuki Nakano 6ba637600b Bug 1503473 - part 1: Rename TextEditor::OnInputParagraphSeparator() and HTMLEditor::OnInputLineBreak() r=m_kato
TextEditor::OnInputParagraphSeparator() and HTMLEditor::OnInputLineBreak() are
also used by command handlers.  Therefore, they should be renamed to
TextEditor::InsertParagraphSeparatorAsAction() and
HTMLEditor::InsertLineBreakAsAction().  Then, current
TextEditor::InsertParagraphSeparatorAsAction() should be renamed to
AsSubAction() and each caller of it should create AutoPlaceholderBatch
by themselves.

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

--HG--
extra : moz-landing-system : lando
2018-11-02 03:36:36 +00:00
Masayuki Nakano f91716e775 Bug 1465702 - part 5: Remove unnecessary Selection argument from editor module r=m_kato
EditorBase::SelectionRefPtr() is now safe to use in editor and really fast to
retrieve Selection than EditorBase::GetSelection().  Therefore, we can get rid of
all Selection pointer/reference argument of each method which always take
normal Selection.

Note that this changes nsIHTMLEditor.checkSelectionStateForAnonymousButtons()
because its argument is only Selection.  So, BlueGriffon should work even
though it calls the method with nsIEditor.selection.

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

--HG--
extra : moz-landing-system : lando
2018-10-30 10:01:38 +00:00
Masayuki Nakano 41166eca5f Bug 1465702 - part 4: Make public methods of HTMLEditor create AutoEditActionDataSetter if necessary r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D10008

--HG--
extra : moz-landing-system : lando
2018-10-30 10:00:17 +00:00
Makoto Kato 0ca1f40c1b Bug 1485890 - Remove dumpContentTree, debugDumpContent and debugUnitTests from nsIEditor. r=masayuki
Since bug 1491173 is landed, there is no users of dumpContentTree,
debugDumpContent and debugUnitTests.  So Let's remove these methods from
nsIEditor.

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

--HG--
extra : moz-landing-system : lando
2018-10-29 07:23:49 +00:00
Masayuki Nakano 51565faee9 Bug 1501260 - Make HTMLEditRules::DocumentModifiedWorker() create bogus node via editor instance r=m_kato
HTMLEditRules::DocumentModifiedWorker() may be called asynchronously via
AddScriptRunnder. Therefore, this may not be in the stack while editor handles
an edit action. Then, HTMLEditRules cannot access edit action data which will
be put on the stack after fixing bug 1465702. So, it should do it after once
calling a method of editor instance (and editor instance should call back
proper HTMLEditRules method).

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

--HG--
extra : moz-landing-system : lando
2018-10-25 05:55:04 +00:00
Masayuki Nakano 446538a446 Bug 1501177 - Create HTMLEditor::InsertAsCitedQuotationInternal() for internal use of nsIEditorMailSupport::InsertAsCitedQuotation() r=m_kato
HTMLEditor::InsertAsCitedQuotation() is an XPCOM method, so, it shouldn't be
used for internal use.  Instead, there should be non-virtual method and
InsertAsCitedQuotation() should use it.

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

--HG--
extra : moz-landing-system : lando
2018-10-25 04:49:13 +00:00
Masayuki Nakano 25b5b80801 Bug 1500862 - part 1: Make HTMLEditor::SetInlineProperty() remove exclusive style automatically r=m_kato
StyleUpdatingCommand::ToggleState() removes exclusive style when it sets
superscript style or subscript style.  However, it accesses protected
members of EditorBase via AutoTransactionBatch even though it's outside
of editor classes.

This patch moves the removing exclusive style code from the method to
HTMLEditor::SetInlineProperty() and rename it "AsAction".

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

--HG--
extra : moz-landing-system : lando
2018-10-24 04:17:42 +00:00
Masayuki Nakano cda6a9ac80 Bug 1484126 - part 21: Rewrite some loops in HTMLTableEditor.cpp with CellData::NextColumnIndex() or CellData::NextRowIndex() r=m_kato
A lot of loops in HTMLTableEditor.cpp scans cells along column-axis or
row-axis.  In those cases, they need to skip columns/rows which are spanned
from prior column/row.  So, we can rewrite them with CellData::NextColumnIndex()
or CellData::NextRowColumn().

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

--HG--
extra : moz-landing-system : lando
2018-10-16 01:10:44 +00:00
Masayuki Nakano 08c4b07fc9 Bug 1484126 - part 1: Create CellData struct which implements nsITableEditor::GetCellDataAt() r=m_kato
nsITableEditor::GetCellDataAt() is an XPCOM method but used internally a lot.
Additionally, it scatters a lot of variables (including unused) since it takes
a lot of out arguments to return.  Therefore, this should be implemented as
struct and users should refer each member as result.

This does not replaces the callers yet since it's too risky if the caller is
not tested by automated test.  Following patches will replace the method call
and each variable step by step.

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

--HG--
extra : moz-landing-system : lando
2018-10-12 13:40:25 +00:00
Masayuki Nakano 9b40433ef6 Bug 1461708 - part 7: Make EventStateManager::HandleMiddleClickPaste() dispatch ePaste event by itself r=smaug
This is preparation of the last patch.  Even if no editor is clicked with
middle button, we need to do:
- collapse Selection at the clicked point.
- dispatch "paste" event.

Therefore, HandleMiddleClickPaste() should dispatch ePaste event by itself
and each editor methods should have a bool argument which the caller wants
ePaste event automatically.

Note that Chromium dispatches "paste" event and pastes clipboard content
into clicked editor even if preceding "auxclick" event is consumed.
However, our traditional behavior is not dispatching "paste" event nor
pasting clipboard content.  Unless Chromium developer keeps their odd
behavior, we should keep our traditional behavior since our behavior is
conforming to DOM event model.

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

--HG--
extra : moz-landing-system : lando
2018-10-10 12:05:39 +00:00
Makoto Kato e851a155cb Bug 1487301 - Part 2. Set ancestor limitter if no set yet. r=masayuki
The ancestor limiter is set by focus event handler of editor. But window that
is run script has no focus, this event isn't fired by addRange etc.

Some execCommand's commands such as 'forwardDelete' uses WillDeleteSelection
then selection for deletion is set by selection controller (in
TextEditor::ExtendSelectionForDelete). So, due to no ancestor limiter, caret
(and any for delete commands such as CharacterExtendForDelete) can move to out
of editor's root.

So we should set ancestor limiter if nothing. If focus event is received by
user interaction etc, limiter will be set again.

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

--HG--
extra : rebase_source : 240c3bc09b37d46d1ce3245bcca55cafc59454c5
2018-09-20 19:03:24 +09: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 20d1804f6b Bug 1484111 - part 1: Create HTMLEditor::InsertTableCellsWithTransaction() for internal use of nsITableEditor::InsertTableCell() r=m_kato
nsITableEditor::InsertTableCell() is an XPCOM method but used internally.  So,
HTMLEditor should implement it with a non-virtual method and all internal users
should use it instead.

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

--HG--
extra : moz-landing-system : lando
2018-09-20 11:44:35 +00:00
Masayuki Nakano 9c1afc4bee Bug 1484116 - part 1: Create HTMLEditor::InsertTableColumnsWithTransaction() for internal use of nsITableEditor::InsertTableColumn() r=m_kato
nsITableEditor::InsertTableColumn() is an XPCOM method but it's used internally.
So, HTMLEditor should implement it with a non-virtual method and internal
users should use it instead.

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

--HG--
extra : moz-landing-system : lando
2018-09-20 09:15:08 +00:00
Masayuki Nakano 3e96aa79b3 Bug 1484117 - part 1: Create HTMLEditor::InsertTableRowsWithTransaction() for internal use of nsITableEditor::InsertTableRow() r=m_kato
nsITableEditor::InsertTableRow() is an XPCOM method but there are some internal
users.  So, HTMLEditor should implement it with a non-virtual method and
it should be used by all internal users.

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

--HG--
extra : moz-landing-system : lando
2018-09-20 06:55:17 +00:00
Masayuki Nakano 3113cbebc3 Bug 1484119 - part 2: Make HTMLEditor::DeleteTableCellWithTransaction() remove <table> element if it becomes empty r=m_kato
HTMLEditor::DeleteTableCellWithTransaction() does not remove <table> element
even if it becomes empty only when 2 or more cell elements are selected.
Therefore, we should check table size before removing a row and if it's the
last row, the method should remove <table>.

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

--HG--
extra : moz-landing-system : lando
2018-09-19 09:00:06 +00:00
Masayuki Nakano 80a2f99daf Bug 1484119 - part 1: Create HTMLEditor::DeleteTableCellWithTransaction() for internal use of nsITableEditor::DeleteTableCell() r=m_kato
nsITableEditor::DeleteTableCell() is an XPCOM method but used internally.
So, HTMLEditor should implement it with non-virtual method and use it
internally.

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

--HG--
extra : moz-landing-system : lando
2018-09-19 08:50:11 +00:00
Masayuki Nakano 2e78564a84 Bug 1484120 - part 1: Create HTMLEditor::DeleteTableCellContentsWithTransaction() for internal use of nsITableEditor::DeleteTableCellContents() r=m_kato
nsITableEditor::DeleteTableCellContents() is an XPCOM method but it's used
internally.  So, HTMLEditor should implement it with a non-virtual method
and all internal users should use the non-virtual method instead.

This patch adds HTMLEditor::DeleteTableCellContentsWithTransaction() for that.
Additionally, this patch renames its helper method DeleteCellContents() to
DeleteAllChidlrenWithTransaction() and moves it to HTMLEditor.cpp since it can
handle any element nodes.

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

--HG--
extra : moz-landing-system : lando
2018-09-19 01:58:48 +00:00
Masayuki Nakano 1a3e84fbef Bug 1484121 - part 2: Clean up HTMLEditor::DeleteColumn() r=m_kato
This patch renames HTMLEditor::DeleteColumn() to
HTMLEditor::DeleteTableColumnWithTransaction() and cleans up its implementation.

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

--HG--
extra : moz-landing-system : lando
2018-09-19 06:39:31 +00:00
Masayuki Nakano 7f96a82ad5 Bug 1484121 - part 1: Create HTMLEditor::DeleteSelectedTableColumnsWithTransaction() for internal use of nsITableEditor::DeleteTableColumn() r=m_kato
nsITableEditor::DeleteTableColumn() is an XPCOM method but used internally.
So, it should be implemented with non-virtual method and internal users
should use it.

Note that this changes only one thing.  This moves
|AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(...| from
below DeleteTableElementAndChildrenWithTransaction() to above it.
I.e., DeleteTableElementAndChildrenWithTransaction() works under
EditSubAction::eDeleteNode as the top level sub-action now.  This is same
as DeleteSelectedTableRowsWithTransaction().  Therefore, the difference
with it when it removes <table> is now fixed.

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

--HG--
extra : moz-landing-system : lando
2018-09-19 06:34:33 +00:00
Masayuki Nakano cf2eb50a7b Bug 1484121 - part 0: Add automated tests for nsITableEditor.deleteTableColumn() r=m_kato
This add automated tests for nsITableEditor.deleteTableColumn().

However, this contains some fixes of existing code since with those bugs,
the test isn't passed even in the simplest case.

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

--HG--
extra : moz-landing-system : lando
2018-09-19 04:32:10 +00:00
Makoto Kato a5335ab3ea Bug 1491199 - Get rid of nsIEditorBlobListener. r=masayuki
Since bug 1489812 is landed, we can get rid of nsIEditorBlobListener.

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

--HG--
extra : moz-landing-system : lando
2018-09-18 04:34:21 +00:00
Masayuki Nakano ee53372956 Bug 1484122 - part 2: Clean up HTMLEditor::DeleteRow() r=m_kato
This patch renames HTMLEditor::DeleteRow() to
HTMLEditor::DeleteTableRowWithTransaction() and cleans up its implementation.

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

--HG--
extra : moz-landing-system : lando
2018-09-18 08:31:00 +00:00
Masayuki Nakano 47fa32ffd8 Bug 1484122 - part 1: Create HTMLEditor::DeleteSelectedTableRowsWithTransaction() for internal use of nsITableEditor::DeleteTableRow() r=m_kato
nsITableEditor::DeleteTableRow() is an XPCOM method but there are some internal
users.  So, it should be implemented as non-virtual protected method and
internal users should use it instead.

This also renames (and reimplement) HTMLEditor::DeleteTable2() since it's
really bad name and the code dispatches unnecessary "selectionchange" events.

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

--HG--
extra : moz-landing-system : lando
2018-09-18 07:56:45 +00:00
Makoto Kato f3b8a60bde Bug 1491191 - Remove unused methods in nsIEditorMailSupport. r=masayuki
Since I have landed bug 1489939, comm-central only uses rewrap method in
nsIEditorMailSupport.  And insertAsCitedQuotation is used by the test of
editor/libeditor/tests/test_bug616590.xul.

Other methods are unused now, so let's remove these from nsIEditorMailSupprt,
and move it to HTMLEditor.  Also, pasteAsQuotation is unused now even if
BlueGriffon.

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

--HG--
extra : moz-landing-system : lando
2018-09-14 10:03:24 +00:00
Masayuki Nakano 6dae86b837 Bug 1484133 - part 1: Create non-virtual HTMLEditor::GetSelectedOrParentTableElement() r=m_kato
nsITableEditor::GetSelectedOrParentTableElement() is of course an XPCOM method,
but it's used internally.  So, there should be non-virtual method.

On the other hand, this API is too ugly.  Returns various information but each
meaning is not clear.  So, result of the new non-virtual method should be
simpler.

This patch creates the new method as:
- returns found element
- takes ErrorResult to return error code.
- takes optional out-param for returning if a cell is selected.

Then, nsITableEditor::GetSelectedOrParentTableElement() can compute its
result from them with Selection.

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

--HG--
extra : moz-landing-system : lando
2018-09-14 12:56:22 +00:00
Masayuki Nakano 34e624bd86 Bug 1484131 - part 1: Create HTMLEditor::CellAndIndexes struct to store cell element and its indexes in the <table> r=m_kato
If a cell element and its indexes in the <table> are stored in a struct,
it makes the user methods easier to read.  Therefore, this patch implement
such struct as HTMLEditor::CellAndIndexes and make it finds first selected
cell and indexes with its method.  Finally, this reimplement
HTMLEditor::GetFirstSelectedCellInTable() with it.

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

--HG--
extra : moz-landing-system : lando
2018-09-14 12:51:05 +00:00