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

10162 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano 5386e3310c Bug 1647556 - part 13: Rename `CreateWSFragmentForVisibleAndMiddleOfLine()` to `CreateWSFragmentForVisibleWhiteSpaces()` r=m_kato
Now, we know that it returns `WSFragment` for visible white-spaces and may
lie position in the line.  Therefore, we should rename it as just representing
visible white-spaces.

Differential Revision: https://phabricator.services.mozilla.com/D82292
2020-07-10 04:46:01 +00:00
Masayuki Nakano 9dd0f65471 Bug 1647556 - part 12: Get rid of `WSRunScanner::FindNearestRun()` and `WSRunScanner::mFragments` r=m_kato
Now, nobody uses `WSRunScanner::FindNearestRun()` so that we can remove it.
Then, there is no users of `WSRunScanner:mFragments`.  Therefore, we can remove
the member, accessors and initializers.

Differential Revision: https://phabricator.services.mozilla.com/D82291
2020-07-10 04:03:39 +00:00
Masayuki Nakano 2c944d309a Bug 1647556 - part 11-3: Make `WSRunObject::PrepareToDeleteRangePriv()` stop using `WSRunScanner::FindNearestRun()` r=m_kato
Unfortunately, remaining code which use `beforeRun` and `afterRun` of
`WSRunObject::PreareToDeleteRangePriv()` is completely broken.  It tries to
do what the new utility methods say, but as you see in the method, the
checking code does not make sense.  For now, we should keep this broken
check even with the expensive DOM point comparisons.  I hope that this does
not harm any benchmark score.

Note that I tested this with all automated tests with comparing the result
of these methods with `MOZ_ASSERT()` like this:
https://hg.mozilla.org/try/rev/29cb7840e404473a41d2d1fbdd229f762ccac5d3
So, I think that this is enough safe because the most edge cases are tested
by the first patch in this bug and `editing/run/(forwarddelete|delete).html`
of WPT.

Differential Revision: https://phabricator.services.mozilla.com/D82290
2020-07-10 04:03:21 +00:00
Masayuki Nakano f9e93231db Bug 1647556 - part 11-2: Make `WSRunObject::PrepareToDeleteRangePriv()` use `TextFragmentData::GetNewInvisibleLeadingWhiteSpaceRangeIfSplittingAt()` and `TextFragmentData::GetNewInvisibleTrailingWhiteSpaceRangeIfSplittingAt()` r=m_kato
Similar to the previous patches, it can use invisible white-space ranges.

Differential Revision: https://phabricator.services.mozilla.com/D82289
2020-07-10 02:27:47 +00:00
Masayuki Nakano 5542e44de3 Bug 1647556 - part 11-1: Make `WSRunObject::PrepareToDeleteRangePriv()` use `TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()` r=m_kato
Similar to the previous changes, `WSRunObject::PrepareToDeleteRangePriv()`
can use `TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()` and
result of comparing with deleting range.

Differential Revision: https://phabricator.services.mozilla.com/D82288
2020-07-10 02:11:20 +00:00
Masayuki Nakano 06d6743328 Bug 1647556 - part 10-4: Make `WSRunObject::InsertText()` stop rescan end of replacing range if it's collapsed r=m_kato
For handling composition, `WSRunObject::InsertText()` rescan white-spaces at
end of replacing range.  However, in most cases, `mScanStartPoint` and
`mScanEndPoint` are same.  Therefore, we can save the runtime cost of the
rescan easier than the old design.

Differential Revision: https://phabricator.services.mozilla.com/D82287
2020-07-09 16:53:25 +00:00
Masayuki Nakano 5e5e7fea51 Bug 1647556 - part 10-3: Make `WSRunObject::InsertText()` stop using `WSRunScanner::FindNearestFragment()` r=m_kato
I realized that `WSFragment::MarkAsVisible()` is called only by
`TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()`.  Therefore,
`beforeRun && !beforeRun->IsStartOfHardLine() && beforeRun->IsVisible()` can be
handled with `pointPositionWithVisibleWhiteSpacesAtStart` and
`afterRun && !afterRun->IsEndOfHardLine() && afterRun->IsVisible()` can be
handled with `pointPositionWithVisibleWhiteSpacesAtEnd`.  So, we can make
`WSRunObject::InsertText()` stop using `FindNearestFragment()` to compute
inserting string.

Differential Revision: https://phabricator.services.mozilla.com/D82286
2020-07-09 16:41:30 +00:00
Masayuki Nakano 12b7d18656 Bug 1647556 - part 10-2: Make `WSRunObject::InsertText()` use `TextFragmentData::GetNewInvisibleLeadingWhiteSpaceRangeIfSplittingAt()` and `TextFragmentData::GetNewInvisibleTrailingWhiteSpaceRangeIfSplittingAt()` r=m_kato
Similar to `WSRunObject::InsertBreak()`, `WSRunObject::InsertText()` can use
the new APIs for `InsertBreak()` even though the name is odd for `InsertText()`,
but the mismatching is caused by odd logic of it.  If replacing range starts
from and/or ends by middle of invisible white-space sequence, all of the
invisible white-spaces should be removed to prevent they become visible.
However, we shouldn't change any behavior in this bug.

Differential Revision: https://phabricator.services.mozilla.com/D82285
2020-07-09 16:23:42 +00:00
Masayuki Nakano d19cea4314 Bug 1647556 - part 10-1: Make `WSRunObject::InsertText()` use `TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()` r=m_kato
Similar to `WSRunObject::InsertBreak()`, `WSRunObject::InsertText()` can work
with the new API.

Differential Revision: https://phabricator.services.mozilla.com/D82284
2020-07-09 12:34:35 +00:00
Mirko Brodesser d127a6ed32 Bug 1649121: part 30) Move `RemoveBodyAndHead`, `FindTargetNode`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82885
2020-07-09 13:23:21 +00:00
Masayuki Nakano dd8f12dbc3 Bug 1647556 - part 9-2: Make `WSRunObject::InsertBreak()` stop using `FindNearestFragment()` r=m_kato
It removes some invisible leading and/or trailing white-spaces when it inserts
`<br>` element into the invisible white-space sequence.  It currently checks
whether the insertion point is in invisible leading and trailing white-spaces
or not with `FindNearestFragment()`, but we can do same thing with
comparing the insertion point with the result of
`TextFragmentData::GetInvisibleLeadingWhiteSpaceRange()` and
`TextFragmentData::GetInvisibleLeadingWhiteSpaceRange()`.  However, current
implementation does not make sense because:
- It checks trailing white-spaces with `!IsEndOfHardLine()` and
  `IsStartOfHardLine()`, but this means that it does ignores invisible
   white-spaces which are the only content in a line.
- It checks leading white-spaces with `!IsStartOfHardLine()` and
  `IsEndOfHardLine()`, so, this also ignores invisible white-spaces which
  are the only content in a line.
- The important thing of the logic is prevent that invisible leading and
  trailing white-spaces become visible with new `<br>` element, but this
  is done only for trailing white-spaces.

Differential Revision: https://phabricator.services.mozilla.com/D82283
2020-07-09 09:44:41 +00:00
Mirko Brodesser abe1457b3b Bug 1649121: part 29) Rename and simplify arguments of `InsertContents`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82662
2020-07-09 05:44:18 +00:00
Mirko Brodesser 4560c59527 Bug 1649121: part 28) Add `InsertContents`. r=masayuki
Its arguments are renamed in the following review.

Differential Revision: https://phabricator.services.mozilla.com/D82661
2020-07-09 05:41:48 +00:00
Mirko Brodesser 637ad4a65b Bug 1649121: part 27) Add `MoveCaretOutsideOfLink`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82520
2020-07-08 12:14:16 +00:00
Mirko Brodesser dcff5a5f40 Bug 1649121: part 26) Move `CollectTopMostChildContentsCompletelyInRange`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82518
2020-07-08 12:15:06 +00:00
Mirko Brodesser 47b1f0e01f Bug 1649121: part 25) Factor detecting invisible `<br>` out. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82517
2020-07-09 05:39:05 +00:00
Masayuki Nakano 7ffb8f8c90 Bug 1647556 - part 9-1: Make `WSRunObject::InsertBreak()` use `TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()` like previous patch r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D82282
2020-07-09 06:32:24 +00:00
Masayuki Nakano 3092ad9e61 Bug 1650972 - Fix wrong argument check of `EditorBase::AppendNodeToSelectionAsRange()` r=m_kato
This is just a mistake of my previous change.

Differential Revision: https://phabricator.services.mozilla.com/D82655
2020-07-09 06:46:19 +00:00
Masayuki Nakano e63d0f9e18 Bug 1647556 - part 8: Make `WSRunObject::PrepareToSplitAcrossBlocksPriv()` stop using `FindNearestFragment()` r=m_kato
It looks for same `WSFragment` twice with comparing text and what it looks for
is the instance whose `IsVisibleAndMiddleOfLine()` returns `true`.
Additionally, doing twice is for checking only whether the split point is
start or end of the range.  Therefore, we can make it simpler with using
`TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()`.

Differential Revision: https://phabricator.services.mozilla.com/D82281
2020-07-09 05:04:56 +00:00
Masayuki Nakano 60451652c9 Bug 1647556 - part 7: Make `ScanPreviousVisibleNodeOrBlockBoundaryFrom()` and `ScanNextVisibleNodeOrBlockBoundaryFrom()` use `TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()` instead of scanning all `WSFragment`s r=m_kato
They return a point in an `WSFragment` whose `IsVisibleAndMiddleOfLine()`
returns `true` or start/end of the range.  Therefore, they can ignore the
other `WSFragment`s and save comparing points to at most twice.

Differential Revision: https://phabricator.services.mozilla.com/D82280
2020-07-09 01:42:27 +00:00
Masayuki Nakano b546936467 Bug 1647556 - part 6: Make `WSRunObject::AdjustWhiteSpace()` use `TextFragmentData::CreateWSFragmentForVisibleAndMiddleOfLine()` instead of scanning all `WSFragment`s r=m_kato
It scans all `WSFragment`s in the array and call `NormalizeWhiteSpacesAtEndOf()`
only with visible instance.  However, as we know, there is at most one such
instance.  Therefore, it does not need to scan the fragments (i.e., don't need
to create all fragments).

Differential Revision: https://phabricator.services.mozilla.com/D82279
2020-07-08 10:11:35 +00:00
Masayuki Nakano 61003960ec Bug 1647556 - part 5-3: Implement the other case of `CreateWSFragmentForVisibleAndMiddleOfLine()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D82278
2020-07-08 09:08:39 +00:00
Masayuki Nakano 03b956b20d Bug 1647556 - part 5-2: Implement another case of `CreateWSFragmentForVisibleAndMiddleOfLine()` r=m_kato
This patch implements the case that when the range is not start of hard line.

Differential Revision: https://phabricator.services.mozilla.com/D82277
2020-07-08 07:37:48 +00:00
Masayuki Nakano d813074347 Bug 1647556 - part 5-1: Create new API to get `WSFragment` in middle of line and visible r=m_kato
Most methods handling something with `WSFragment` work only with instances
whose `IsVisibleAndMiddleOfHardLine()` return true, and currently, such
instance exists only one at most in the array.  Therefore, they just want
an API to get such fragment.

Differential Revision: https://phabricator.services.mozilla.com/D82276
2020-07-08 01:23:14 +00:00
Masayuki Nakano c28c0b9359 Bug 1647556 - part 4: Rewrite `WSRunObject::Scrub()` r=m_kato
`Scrub()` does remove leading white-spaces and trailing white-spaces if
there is.  So, it does not require `WSFragment` anymore.

Differential Revision: https://phabricator.services.mozilla.com/D82275
2020-07-07 16:21:50 +00:00
Mirko Brodesser df5c5a5851 Bug 1649121: part 24) Move `StripFormattingNodes`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82389
2020-07-07 12:32:40 +00:00
Mirko Brodesser db05434bca Bug 1649121: part 23) Move `MoveStartAndEndAccordingToHTMLInfo`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82388
2020-07-07 12:32:33 +00:00
Mirko Brodesser 28c0b32d43 Bug 1649121: part 22) Move `ParseFragment`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82387
2020-07-07 12:32:30 +00:00
Mirko Brodesser ce817796aa Bug 1649121: part 21) Move `CreateDOMFragmentFromPaste`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82386
2020-07-07 12:32:20 +00:00
Mirko Brodesser 1360293f83 Bug 1649121: part 20) Move `GetNewCaretPointAfterInsertingHTML` to `HTMLWithContextInserter`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82385
2020-07-07 12:32:13 +00:00
Mirko Brodesser b1c3499828 Bug 1649121: part 19) Add `HTMLWithContextInserter` and move content of `DoInsertHTMLWithContext` to it. r=masayuki
This is minimally invasive. In the following parts, methods will be
moved to it and potentially other methods will be extracted.

Differential Revision: https://phabricator.services.mozilla.com/D82384
2020-07-07 12:32:05 +00:00
Mirko Brodesser 1684d9040a Bug 1649121: part 18) Declare `CreateDOMFragmentFromPaste` `const`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82198
2020-07-07 12:31:58 +00:00
Masayuki Nakano ec9ecbc50f Bug 1647556 - part 3-3: Implement the other complicated case of `GetInvisibleLeadingWhiteSpaceRange()` r=m_kato
Different from `GetInvisibleTrailingWhiteSpaceRange()`, it always returns
the range even if it's collapsed (i.e., there is no leading white-space).

Differential Revision: https://phabricator.services.mozilla.com/D82274
2020-07-07 09:21:27 +00:00
Masayuki Nakano abb2c132b1 Bug 1647556 - part 3-2: Implement complicated case of `GetInvisibleTrailingWhiteSpaceRange()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D82273
2020-07-07 07:39:20 +00:00
Masayuki Nakano 0ed0d74c18 Bug 1647556 - part 3-1: Add API to `WSRunScanner::TextFragmentData` to get range of invisible leading or trailing white-spaces r=m_kato
One of the `WSFragment`users' purpose is, they remove invisible white-spaces
when there are.  So, `TextFragmentData` should have API to retrieve the
ranges and use them for initializing `WSFragment` which represents leading
or trailing white-spaces.  For making this patch smaller as far as possible,
these APIs implements only the case when there is no NBSP.

For result of the new API, this creates a template class, `EditorDOMRangeBase`,
whose boundary type is `EditorDOMPointBase`.  Its methods are named from
`nsRange`'s same methods.

Differential Revision: https://phabricator.services.mozilla.com/D82272
2020-07-07 05:31:34 +00:00
Masayuki Nakano 3d01ff0123 Bug 1647556 - part 2: Create `WSRunScanner::TextFragmentData` class for the alternative of `WSFragment`s r=m_kato
This patch just creates new stack only class and make it initializes
`WSRunScanner::mFragments` instead of `WSRunScanner`.

Differential Revision: https://phabricator.services.mozilla.com/D82270
2020-07-06 16:21:27 +00:00
Masayuki Nakano a639ed9828 Bug 1647556 - part 1: Get rid of `WSRunScanner::InitializeWithSingleFragment()` r=m_kato
For making easier to understand the contents of `WSRunScanner::mFragments`,
we should stop using `InitializeWithSingleFragment()` for now because it's
designed for doing same things a lot, but used only by 2 users and they set
different parameters so that it does not do same things for the callers.

Depends on D82268

Differential Revision: https://phabricator.services.mozilla.com/D82269
2020-07-06 10:33:06 +00:00
Sylvestre Ledru caf785c695 Bug 1519636 - Reformat recent changes to the Google coding style r=andi
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D82178
2020-07-04 09:38:43 +00:00
Mirko Brodesser 324ad8b2e7 Bug 1649121: part 17) Correct style for previous commit. r=masayuki
Separate commit to reduce possibility for typos.

Differential Revision: https://phabricator.services.mozilla.com/D82148
2020-07-03 09:55:37 +00:00
Mirko Brodesser 91f0344d40 Bug 1649121: part 16) Factor getting new caret point out of `DoInsertHTMLWithContext`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82147
2020-07-03 09:55:11 +00:00
Mirko Brodesser f5d347f5a7 Bug 1649121: part 15) Declare `IsVisibleBRElement` `const`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82009
2020-07-03 09:25:25 +00:00
Mirko Brodesser 17833bb634 Bug 1649121: part 14) Rename local variables `mostAncestorTableRelatedElement`, `maybeTableRelatedElement`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82008
2020-07-03 09:25:22 +00:00
Mirko Brodesser e79ae100d0 Bug 1649121: part 13) Rename `GetMostAncestorListOrTableElement`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81994
2020-07-03 09:27:45 +00:00
Mirko Brodesser 72ae1c4c1f Bug 1649121: part 12) Remove duplicated code in `IsReplaceableListElement`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81993
2020-07-03 09:25:18 +00:00
Mirko Brodesser bb175a0e82 Bug 1649121: part 11) Factor some functionality of `GetMostAncestorListOrTableElement` out. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81849
2020-07-03 09:26:19 +00:00
Mirko Brodesser aec19fc27a Bug 1649121: part 10) Rename `CollectTopMostChildNodesCompletelyInRange` to `CollectTopMostChildContentsCompletelyInRange`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81848
2020-07-02 11:53:03 +00:00
Masayuki Nakano 2c83c27c9c Bug 1644903 - Make `nsINode::InsertBefore()` callers call `ErrorResult::WouldReportJSException()` when inserting node may be in another document r=m_kato
`nsINode::InsertBefore()` removes inserting node from a document if it's in
a document including different document.  In this case, `UpdateReflectorGlobal`
in BindingUtils.cpp calls `ErrorResult::MightThrowJSException()`, but editor
never throws exception with `ErrorResult`.  Therefore, editor needs to call
`ErrorResult::WouldReportJSException()` explicitly if the inserting node may
be in another document.

As far as I checked, it can happen only when undoing or redoing a transaction.
Therefore, this patch touches only transaction classes.

Depends on D81683

Differential Revision: https://phabricator.services.mozilla.com/D81684
2020-07-01 13:13:13 +00:00
Masayuki Nakano 66545f5913 Bug 1648564 - Make `WSRunScanner::GetFirstASCIIWhiteSpacePointCollapsedTo()` and `WSRunScanner::GetEndOfCollapsibleASCIIWhiteSpaces()` not return point in empty text node r=m_kato
Although their callers may want to remove empty text nodes around white-space
sequence, but for now, we should make them not return empty text node because
the former's name means so, and the latter should behave similarly for
consistency.

Differential Revision: https://phabricator.services.mozilla.com/D81683
2020-07-02 08:30:25 +00:00
Simon Giesecke 9364b353d4 Bug 1648010 - Remove NS_NAMED_LITERAL_CSTRING and NS_NAMED_LITERAL_STRING macros. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D80631
2020-07-01 08:42:31 +00:00
Simon Giesecke e3c223da3e Bug 1648010 - Fix uses of NS_LITERAL_STRING with C string literals. r=geckoview-reviewers,agi,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D80861
2020-07-01 08:34:12 +00:00
Simon Giesecke cd8b8939b9 Bug 1648010 - Replace uses of NS_LITERAL_STRING/NS_LITERAL_CSTRING macros by _ns literals. r=geckoview-reviewers,jgilbert,agi,hsivonen,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D80860
2020-07-01 08:29:29 +00:00
Mirko Brodesser fb374f2e74 Bug 1649121: part 9) Simplify `GetMostAncestorListOrTableElement`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81547
2020-06-30 13:13:12 +00:00
Mirko Brodesser 4477882999 Bug 1649121: part 8) Rename `CollectListAndTableRelatedElementsAt` to `CollectTableAndAnyListElementsOfInclusiveAncestorsAt`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81546
2020-06-30 13:13:04 +00:00
Mirko Brodesser a533835579 Bug 1649121: part 7) Rename `HTMLEditUtils::IsList` to `HTMLEditUtils::IsAnyListElement`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81545
2020-06-30 13:12:56 +00:00
Mirko Brodesser a30c22f525 Bug 1649121: part 6) Rename `HTMLEditUtils::IsTableElementButNotTable` to `HTMLEditUtils::IsAnyTableElementButNotTable`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81544
2020-06-30 13:12:49 +00:00
Mirko Brodesser 7fe5d9f63c Bug 1649121: part 5) Declare `HTMLEditor::GetBetterInsertionPointFor` `const`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81543
2020-06-30 13:12:47 +00:00
Mirko Brodesser 592ca1c3b6 Bug 1649121: part 4) Rename `HTMLEditUtils::IsTableElement` to `HTMLEditUtils::IsAnyTableElement`. r=masayuki
The old name was misleading.

Differential Revision: https://phabricator.services.mozilla.com/D81542
2020-06-30 13:12:39 +00:00
Mirko Brodesser 2937ae1381 Bug 1649121: part 3) Declare some methods in `HTMLEditor` `static`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81541
2020-06-30 13:12:31 +00:00
Mirko Brodesser f52a74862a Bug 1649121: part 2) Factor moving start and end of out `CreateDOMFragmentForPaste`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81540
2020-06-30 13:12:29 +00:00
Mirko Brodesser 9ae430ad1a Bug 1649121: part 1) Add some documentation to `HTMLEditor::CreateDOMFragmentFromPaste`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D81539
2020-06-30 13:12:16 +00:00
Chris Fronk 6f84249b41 Bug 1337953 - Make nsDeque templated on pointer type r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D79629
2020-06-25 02:39:23 +00:00
Masayuki Nakano a240090dfd Bug 1646325 - part 4: Make `WSRunScanner` create `WSFragment` when it's needed r=m_kato
In most methods of `WSRunScanner`, `WSFragment`s are never used.  Therefore,
this patch makes them created when they are necessary.

Depends on D80315

Differential Revision: https://phabricator.services.mozilla.com/D80638
2020-06-24 08:37:26 +00:00
Masayuki Nakano 5ef63f4bd4 Bug 1646325 - part 3: Make `WSFragment` non-double-linked-list r=m_kato
Now, `WSFragment` is managed by `AutoTArray` so that it does not need to
be double-linked-list.

Differential Revision: https://phabricator.services.mozilla.com/D80315
2020-06-24 03:43:05 +00:00
Masayuki Nakano 69d6f854ee Bug 1646325 - part 2: Manage `WSFragment`s with array r=m_kato
`WSFragment` is created at least one instance, and at most 3 instances per
`WSRunScanner` instance.  They can be managed with `AutoTArray` simpler and
we can avoid heap allocation with this approach.

Differential Revision: https://phabricator.services.mozilla.com/D80314
2020-06-24 03:00:07 +00:00
Masayuki Nakano 379f838107 Bug 1646325 - part 1-3: Rewrite remaining part of `WSRunScanner::GetRuns()` with early-return style r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D80313
2020-06-24 01:22:45 +00:00
Masayuki Nakano cc4a5ebe14 Bug 1646325 - part 1-2: Rewrite the new `if` block in `WSRunScanner::GetRuns()` with early-return style r=m_kato
Depends on D80311

Differential Revision: https://phabricator.services.mozilla.com/D80312
2020-06-23 05:13:58 +00:00
Masayuki Nakano 86e3ff72ea Bug 1646325 - part 1-1: Make `WSRunScanner::GetRuns()` handle the case not starting from hard line break first r=m_kato
Part 1-* rewrite `WSRunScanner::GetRuns()` with early-return style, but it's
hard to review if changing it with a patch.

This just swaps the `if` and `else` block because the `else` block is
shorter than the `if` block.

Depends on D79973

Differential Revision: https://phabricator.services.mozilla.com/D80311
2020-06-23 04:46:20 +00:00
Butkovits Atila 7916df7f02 Backed out changeset 5614bcd268d1 (bug 1337953) for bustage at FuzzyLayer.cpp. CLOSED TREE 2020-06-23 11:01:37 +03:00
Chris Fronk cea9cef934 Bug 1337953 - Make nsDeque templated on pointer type r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D79629
2020-06-23 00:58:13 +00:00
Masayuki Nakano fcdef2c8b9 Bug 1646890 - Add automated test for bug 1645983 r=m_kato
This patch adds new test which is based on actual scenario in
Gmail composer.

Differential Revision: https://phabricator.services.mozilla.com/D80310
2020-06-22 14:48:47 +00:00
Masayuki Nakano 6b7588bbe2 Bug 1646296 - part 8: Make stack only classes to group start/end boundary information of `WSRunScanner` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D79973
2020-06-22 14:48:15 +00:00
Kagami Sascha Rosylight 166f2891a2 Bug 1643464 - Part 1: Rename eLeft/eRight to ePrimary/eSecondary r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D80331
2020-06-19 18:02:41 +00:00
tkhan 6ccabd4784 Bug 1602668 - M(1) manifest and test changes. r=kmag,karlt,necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D70362
2020-06-22 19:09:49 +00:00
Masayuki Nakano 8243db7082 Bug 1646296 - part 7: Make `WSRunScanner::InitializeRange*()` template methods r=m_kato
Depends on D79971

Differential Revision: https://phabricator.services.mozilla.com/D79972
2020-06-22 08:12:37 +00:00
Masayuki Nakano 196304c105 Bug 1646296 - part 6: Make `WSRunScanner::InitializeRange*()` stop using the loops which are rarely run twice and more r=m_kato
With the previous patches, we know that the loops in
`WSRunScanner::InitializeRangeStart()` and `WSRunScanner::InitializeRangeEnd()`
rarely run twice and more.  Therefore, we can make use recursive calls instead
of the loop.

Depends on D79970

Differential Revision: https://phabricator.services.mozilla.com/D79971
2020-06-22 06:05:16 +00:00
Masayuki Nakano c1be8ae82a Bug 1646296 - part 5: Make the last `else` block in the loops of `WSRunScanner::InitializeRange*()` handled before the text node case r=m_kato
Similar to the previous patch, this patch moves the last `else` block of
the loops in `WSRunScanner::InitializeRangeStart()` and
`WSRunScanner::InitializeRangeEnd()` to before the text node handling case.
This makes that clearer that the loops are continued only when text node
has no text or only white-spaces.

Depends on D79969

Differential Revision: https://phabricator.services.mozilla.com/D79970
2020-06-22 02:40:41 +00:00
Masayuki Nakano 7666461289 Bug 1646296 - part 4: Make the loops in `WSRunScanner::InitializeRange*()` handle topmost `else` block first r=m_kato
Their topmost `else` blocks mean there is no visible content before/after the
point.  In this case, the initialization is simpler.  So, they should be
handled first, and make the other blocks outdented.

Depends on D79966

Differential Revision: https://phabricator.services.mozilla.com/D79969
2020-06-22 02:11:30 +00:00
Masayuki Nakano 0847d6a6c2 Bug 1646296 - part 3: Create helper methods of `WSRunScanner::InitializeRange*()` to scan a text node r=m_kato
There are duplicated code in both `WSRunScanner::InitializeRangeStart()`
and `WSRunScanner::InitializeRangeEnd()`.  They scan text node to store
first and last NBSP positions and initialize start/end with found visible
character position.  This patch makes the loop clearer.

Depends on D79965

Differential Revision: https://phabricator.services.mozilla.com/D79966
2020-06-19 09:25:35 +00:00
Kagami Sascha Rosylight f424c247ba Bug 1640276 - Part 11: Mark nsINode as const in IsPointInSelection() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D80177
2020-06-19 00:58:40 +00:00
Masayuki Nakano abe7626ff4 Bug 1646296 - part 2: Split `WSRunScanner::GetWSNodes()` r=m_kato
Despite the name, it stores range of white-space sequence and/or start/end
reason.  Initializing start and end are completely independent.  Therefore,
we can move them into independent methods.

Depends on D79964

Differential Revision: https://phabricator.services.mozilla.com/D79965
2020-06-18 07:20:54 +00:00
Masayuki Nakano a852a50071 Bug 1646296 - part 1: Make `WSRunScanner::FindNearestRun()` return `const WSFragment*` instead of `WSFragment*` r=m_kato
The result should never be modified so that it should return `const`-pointer.

Differential Revision: https://phabricator.services.mozilla.com/D79964
2020-06-18 06:02:47 +00:00
Gijs Kruitbosch 222e2d1158 Bug 1644863 - fix trailing whitespace in cross-tree tests, r=emilio,marionette-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D79202
2020-06-17 22:45:31 +00:00
Kris Maglione 3bda67deab Bug 1638153: Part 2 - Fix uses of .rootTreeItem to get top browser window. r=geckoview-reviewers,nika,snorp
Differential Revision: https://phabricator.services.mozilla.com/D75429
2020-06-17 17:17:16 +00:00
Masayuki Nakano d2108a7fcd Bug 1645983 - Check whether `EditorDOMPointInText` is set before calling `IsCharASCIISpace()` r=m_kato
I guess that the `Maybe` is `mOffset` of `EditorDOMPointBase` because new
`Maybe::value()`s are called with checking `Maybe::isSome()`.  So, accessing
`EditorDOMPointBase::mOffset` newly should cause the assertion.

Then, I found a new caller `IsCharASCIISpace()` which calls `Char()` without
validation here:
https://hg.mozilla.org/mozilla-central/diff/289c293af80b12744b5d35c5b8427ba8d8ebf13e/editor/libeditor/WSRunObject.cpp#l1.383

That could be unset, but I cannot reproduce it, but I succeeded to reproduce
similar assertion hit with using empty text node (see the crashtest).  I hope
this fixes the original crash too.

Differential Revision: https://phabricator.services.mozilla.com/D79816
2020-06-17 07:03:25 +00:00
Masayuki Nakano e51cdb3ca3 Bug 1642594 - part 5: Implement first version of new white-space normalizer which simulates Blink's one r=m_kato
This patch tries to implement Blink-compat white-space normalizer for
`HTMLEditor`.

It's difficult to list up our traditional white-space normalization rules
because `WSRunObject` touches white space sequence only when there is not
acceptable case, e.g., an ASCII white-spaces will be adjacent to another
one, and replaces only unacceptable white-space only.  Therefore, whether
white-space sequence may start with either an ASCII white-space or an NBSP.
On the other hand, Blink and WebKit makes white-space sequence always
starts with an NBSP or an ASCII white-space (unfortunately, they behave
differently!).  So, for web-compat, we should simulate Blink's behavior
because either behavior is reasonable but Blink have more market share.

This patch simply adds new white-space normalization path for the new one,
and it's switchable with a pref, and still disabled by default.

The other reason why we should do this is, our traditional white-space
normalizer touches the DOM a lot of times per edit action, and the timing
is both before and after touches the DOM tree.  Therefore, it's difficult
to compute actual deleting range for `InputEvent.getTargetRanges()` and
touching a lot of times causes running mutation event listeners a lot and
creates a lot of transaction class instances.  So, new one have a lot of
merits:

1. Improve web-compat
2. Improve the peformance
3. Improve the security
4. Improve the footprint (but this is now worse then traditional one)
5. Simplify the implementation

The new normalizer is mostly implemented with only 3 `HTMLEditor` methods.

One is `HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces()`.  This is
semi-public method for the edit action handlers.  This takes a range with
2 `EditorDOMPoinInText` to delete the range simply.  This also replaces
surrounding white-space sequence if necessary.  For inserting text case,
this method also handles only white-space normalization when it's called
with collapsed range, i.e., same `EditorDOMPointInText`.  This tries to use
`RepaceTextWithTransaction()` as far as possible to reduce creation cost of
transaction classes and the footprint.

Another one is `HTMLEditor::ExtendRangeToDeleteWithNormalizingWhiteSpaces()`.
This tries to extend the given range to normalize surrounding white-spaces.
This is currently not optimized for footprint because this may include
white-spaces which do not need to be replaced.  This optimization should be
done before shipping, but for now, enabling `InputEvent.getTargetRanges()` in
Nightly channel is more important.  So that it should be done in a follow-up
bug.

The other is `HTMLEditor::GenerateWhitepaceSequence()`.  This creates
normalized white-space sequence with surrounding character information.
For keeping this method simple as far as possible, we shouldn't optimize
the range of generation even in follow-ups.

Finally, the white-space sequence is not tested in mochitests, so that we
can enable this new normalizer when we run mochitests under
`editor/libeditor/tests`.  However, WPT has some tests.  We should keep
them running with current normalizer for checking regression.  Instead,
we should enable the pref only for the new WPT added by the previous patch.

Depends on D78655

Differential Revision: https://phabricator.services.mozilla.com/D78656
2020-06-15 07:37:56 +00:00
Masayuki Nakano e01c0de610 Bug 1642594 - part 4: Stop using "whitespace" in under libeditor r=m_kato
I realized that there is no word "whitespace" in formal English.  This patch
replaces it with "white-space" in comments, and change method names to use
"WhiteSpace".

Depends on D78654

Differential Revision: https://phabricator.services.mozilla.com/D78655
2020-06-10 13:44:10 +00:00
Masayuki Nakano 3d4e1bc4bb Bug 1642594 - part 2: Make `WSRunObject::ReplaceASCIIWhitespacesWithOneNBSP()` take range of collapsible ASCII whitespaces instead of a position in it r=m_kato
This patch makes the method not smart intentionally because we need only the
range without DOM mutation.

Differential Revision: https://phabricator.services.mozilla.com/D77987
2020-06-08 11:31:37 +00:00
Masayuki Nakano 5cfc474a9c Bug 1642594 - part 1: Split `WSRunObject::GetASCIIWhitespacesBounds()` and redesign them r=m_kato
Callers of `WSRunObject::GetASCIIWhitespacesBounds()` may want to scan only
previous or next whitespaces.  Therefore, we can split it to save creation
cost of `EditorDOMPointInText`.

Additionally, this makes them scan whitespace sequence in a text node until
hitting its end for avoiding to use expensive API of `WSRunScanner`.

Differential Revision: https://phabricator.services.mozilla.com/D77986
2020-06-08 11:30:37 +00:00
Ping Chen c055ecfef2 Bug 1636971 - Load EditorOverride.css in HTMLEditor->Init to fix image styles in editor. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D79285
2020-06-12 12:22:12 +00:00
Emilio Cobos Álvarez ef3d21048d Bug 1640623 - Use enum classes for LookAndFeel int and float IDs. r=jmathies,geckoview-reviewers,esawin
Differential Revision: https://phabricator.services.mozilla.com/D76694
2020-06-11 11:27:43 +00:00
Simon Giesecke 82dc9b2271 Bug 1642949 - Replace uses of RemoveElementAt by RemoveLastElement/PopLastElement where possible. r=necko-reviewers,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D78027
2020-06-10 10:46:14 +00:00
Butkovits Atila e3dce68834 Backed out 3 changesets (bug 1643289, bug 1642949) for causing failure at test_headless_screenshot.html. CLOSED TREE
Backed out changeset 98c420f73380 (bug 1643289)
Backed out changeset 9447ea8910aa (bug 1643289)
Backed out changeset 0c827da9d847 (bug 1642949)
2020-06-10 10:07:23 +03:00
Simon Giesecke d419f0ff08 Bug 1642949 - Replace uses of RemoveElementAt by RemoveLastElement/PopLastElement where possible. r=necko-reviewers,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D78027
2020-06-10 05:49:28 +00:00
Kagami Sascha Rosylight c883340a3b Bug 1643495 - Revert contextmenu change in test_bug417418 r=masayuki
This change was only needed when the previous version of the patch for Bug 1632425 wanted to move things into contextmenu event handler. This patch reverts the change as 1) the suggested behavior never landed and 2) opening context menu in a test can cause conflict with other tests.

Differential Revision: https://phabricator.services.mozilla.com/D78673
2020-06-08 23:35:53 +00:00
Masayuki Nakano 72a41b4a70 Bug 1636855 - Disallow to paste longer text than `maxlength` value except in Nightly channel and early Beta r=emilio
Fix of bug 1320229 allowed to paste longer text than `maxlength` attribute of
`<input>` and `<textarea>` because it was thought that the longer text causes
"too long" invalidate state, makes users notified and prevent to submit
form data.

However, according to Bug 1636855 comment 7 (*1), it breaks a major enterprise
web app, SAP, at least because it sends form data without checking validity of
each form data and discards invalid data on server side silently.

According to bug 1636855 comment 24 (*2), one of new behavior's fault is
on Gecko side too.  The style of `<input>` element or `<textarea>` element
which has too long text after pasting is changed when it loses focus.
Therefore, users can post the data before they know pasted data is too
long if sending the form data with `Enter` key or something immediately
after pasting (i.e., without moving focus) web apps handle it by themselves.

On the other hand, the original bug report, bug 1320229, should be solved in
the future especially in password field because users may register password
which is cut by `maxlength` silently and they don't use builtin password
manager, only the pasted password is saved, and then, they won't be able to
login as the account.  This is really long standing issue of the web forms.
An article (*3) warned this to web developers in 2011.  Therefore, we should
keep going advance for solving this issue at least in Nightly channel to get
more feedback from testers and web developers.

1 https://bugzilla.mozilla.org/show_bug.cgi?id=1636855#c7
2 https://bugzilla.mozilla.org/show_bug.cgi?id=1636855#c24
3 https://www.christophermanning.org/writing/dont-use-maxlength-on-password-inputs

Differential Revision: https://phabricator.services.mozilla.com/D78613
2020-06-07 21:29:48 +00:00
Bogdan Tara 86d1eef7a6 Backed out changeset 6e99a3e6c77b (bug 1642588) for test_bug1642588.html failures CLOSED TREE 2020-06-06 02:45:52 +03:00
Masayuki Nakano bb4b3d4e9d Bug 1642270 - Make `EditorBase::MaybeHasMutationEventListeners()` always return `true` in debug build for testing complicated path r=m_kato
According to the telemetry data, almost all web apps in the word do not use
mutation event listeners, but if they are used, editor needs to check
whether modifying node is modified by web apps.  The checking cost may not
cheap in some cases.  Therefore, we check whether the window has at least one
mutation event listeners or not before non-cheap checking.

However, like actual web apps, most our mochitests and WPT do not add
mutation event listeners.  Therefore, such additional checking code is not
tested even though they should work as exactly same as the case when
there are mutation event listeners but they don't touch the DOM.

This patch makes it always return only in debug build for checking the
complicated path.

Differential Revision: https://phabricator.services.mozilla.com/D78173
2020-06-05 19:25:18 +00:00
Kagami Sascha Rosylight e29858d3ad Bug 1642588 - Make Triple click only select within editing host r=masayuki,emilio
Differential Revision: https://phabricator.services.mozilla.com/D78315
2020-06-05 22:45:30 +00:00
Bogdan Tara 1ba73a9900 Backed out changeset 094a2fc0fc50 (bug 1642588) for test_bug1642588.html failures CLOSED TREE 2020-06-05 21:50:36 +03:00
Kagami Sascha Rosylight d02396bd67 Bug 1642588 - Make Triple click only select within editing host r=masayuki,emilio
Differential Revision: https://phabricator.services.mozilla.com/D78315
2020-06-05 13:41:26 +00:00
Kagami Sascha Rosylight 45b185573f Bug 1632425 - Part 3: Triple click to select anchors r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D77683
2020-06-03 23:47:55 +00:00
Kagami Sascha Rosylight c948a3aa98 Bug 1632425 - Part 2: Mark const methods as such r=masayuki
Depends on D77812

Differential Revision: https://phabricator.services.mozilla.com/D77942
2020-06-03 03:08:58 +00:00
Kagami Sascha Rosylight 60c853771e Bug 1632425 - Part 1: Add EditorUtils::IsPointInSelection() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D77812
2020-06-03 03:08:05 +00:00
Razvan Maries a36bb7751f Backed out 3 changesets (bug 1638153) for perma failures on cross-origin-objects.html. CLOSED TREE
Backed out changeset f7aedc92d396 (bug 1638153)
Backed out changeset 07ec713926c6 (bug 1638153)
Backed out changeset 5a656842e241 (bug 1638153)
2020-06-01 23:51:35 +03:00
Kris Maglione b3fcd970ec Bug 1638153: Part 2 - Fix uses of .rootTreeItem to get top browser window. r=geckoview-reviewers,nika,snorp
Differential Revision: https://phabricator.services.mozilla.com/D75429
2020-06-01 17:59:01 +00:00
Emilio Cobos Álvarez 54fd961a29 Bug 1641245 - Make string comparators not virtual. r=froydnj,necko-reviewers,geckoview-reviewers,jgilbert,agi,valentin
There's no use case for stateful comparators, so they can be just plain
function pointers.

This is used in some hot places like CSS selector matching.

Differential Revision: https://phabricator.services.mozilla.com/D77084
2020-05-27 18:11:12 +00:00
Emilio Cobos Álvarez 525520f10b Bug 1640601 - Also reframe the closest non-anonymous root when switching anonymous content from display: none to something else. r=mats
We were dealing with it correctly when switching display from e.g. block
to inline, or such. But we were not dealing with it when the node was
undisplayed.

Handle it properly, and free one frame bit while at it. We can't really
do this for ManualNAC (the editor resizers) because they request a
reframe explicitly.

Differential Revision: https://phabricator.services.mozilla.com/D76679
2020-05-25 23:54:10 +00:00
Emilio Cobos Álvarez 89958b377a Bug 1640605 - Remove IsInAnonymousSubtree / IsRootOfAnonymousSubtree. r=edgar
In favor of the NativeAnonymous versions which they forward to.

Done automatically with:

  rg -l 'IsInAnonymousSubtree' | xargs sed -i 's/IsInAnonymousSubtree/IsInNativeAnonymousSubtree/g'

And removing the function definitions afterwards.

Differential Revision: https://phabricator.services.mozilla.com/D76681
2020-05-25 11:43:51 +00:00
Kagami Sascha Rosylight bc670252a1 Bug 1640276 - Part 7: Mark nsINode as const in IsVisibleBRElement() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76570
2020-05-23 12:40:08 +00:00
Kagami Sascha Rosylight c9c8185160 Bug 1640276 - Part 6: Mark nsINode as const in GetNext/PreviousHTMLElementOrText*() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76569
2020-05-23 12:39:48 +00:00
Kagami Sascha Rosylight 6cafaa3128 Bug 1640276 - Part 5: Mark nsINode as const in GetNext/PreviousGetNextHTMLElementOrTextInternal() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76567
2020-05-23 12:39:36 +00:00
Kagami Sascha Rosylight 6af0a00410 Bug 1640276 - Part 4: Mark nsINode as const in GetNext/Previous*Node() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76565
2020-05-23 12:39:16 +00:00
Kagami Sascha Rosylight 866889e825 Bug 1640276 - Part 3: Mark nsINode as const in GetNext/PreviousNodeInternal() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76564
2020-05-23 12:39:03 +00:00
Kagami Sascha Rosylight 83c35c9040 Bug 1640276 - Part 2: Mark nsINode as const in Find*Node() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76563
2020-05-23 12:38:50 +00:00
Kagami Sascha Rosylight 9eac56104b Bug 1640276 - Part 1: Mark nsINode as const in Is*Root() r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D76562
2020-05-23 12:38:38 +00:00
Masayuki Nakano dd8eff26c2 Bug 1639161 - part 3: Get rid of `nsIEditActionListener::DidDeleteText()` r=m_kato
It's not used by mozilla-central, comm-central nor BlueGriffon, and it cannot
work with replacing content, mutation event listener's changes.  Therefore,
we should remove this for now. If we need to support this **feature** in some
business reasons, we should provide better API than this anyway.

Differential Revision: https://phabricator.services.mozilla.com/D76080
2020-05-21 08:23:04 +00:00
Masayuki Nakano 30d14b828d Bug 1639161 - part 2: Make `WSRunObject` use `HTMLEditor::ReplaceTextWithTransaction()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D76079
2020-05-21 08:22:20 +00:00
Masayuki Nakano 58e73430fb Bug 1639161 - part 1: Create `ReplaceTextTransaction` class r=m_kato
Currently, when `HTMLEditor` replaces text in a text node, `HTMLEditor`
creates a set of `DeleteTextTransaction` and `InsertTextTransaction`.
However, this has bad impact for footprint and causes the callers messy.

This patch creates `ReplaceTextTransaction` instead and
`HTMLEditor::ReplaceTextWithTransaction()` as its wrapper.  Unfortunately,
this becomes not calling `nsIEditActionListener::DidDeleteText()`, however,
this is not used by mozilla-central, comm-central nor BlueGriffon.  IIRC,
it was not removed for some legacy addons of Thunderbird.  Therefore, it
must be okay to remove it.

Differential Revision: https://phabricator.services.mozilla.com/D76078
2020-05-21 02:30:09 +00:00
Olli Pettay 9a394a854e Bug 1637712 - Consider to move *Ancestor* API to nsINode r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D75169
2020-05-20 14:55:15 +00:00
Masayuki Nakano 1a48bee3ed Bug 1627175 - part 19: Move `EditorBase::IsPreformatted()` to `EditorUtils` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D75889
2020-05-20 04:45:42 +00:00
Masayuki Nakano a97bc5aea1 Bug 1639074 - Don't call `EditorDOMPoint::GetPreviousSiblingOfChild()` if the container is not a container element r=m_kato
For warning the potential of callers' bug, `GetPreviousSiblingOfChild()` outputs
warning into the console when its container is not a container element, e.g.,
it's odd trying to get previous sibling of child if the container is a text
node.  Therefore, this patch makes the new caller,
`WSRunScanner::GetPreviousEditableCharPoint()`, check
`CanContainerHaveChildren()` before calling it.

Differential Revision: https://phabricator.services.mozilla.com/D75888
2020-05-20 07:11:17 +00:00
Masayuki Nakano 89060f115e Bug 1637865 - part 5: Clean up `WSRunObject::CheckTrailingNBSPOfRun()` r=m_kato
This patch makes it use early-return style and adds some comments.  Its behavior
should be changed as soon as possible for web-compat.  Therefore, I don't
write current behavior as comment at declaration.

Differential Revision: https://phabricator.services.mozilla.com/D75476
2020-05-19 01:17:10 +00:00
Masayuki Nakano 0fa915de33 Bug 1637865 - part 4: Rename `rightCheck` in `WSRunObject::CheckTrailingNBSPOfRun()` r=m_kato
Although the new name is not true when neither
`maybeNBSPFollowingVisibleContent` nor `isPreviousCharASCIIWhitespace` is true.

Differential Revision: https://phabricator.services.mozilla.com/D75475
2020-05-18 13:00:25 +00:00
Masayuki Nakano 0ff40045be Bug 1637865 - part 3: Rename `leftCheck` in `WSRunObject::CheckTrailingNBSPOfRun()` r=m_kato
Then, the last `if` block runs obviously only when the preceding `if` block
runs.  Therefore, this patch moves it.

Differential Revision: https://phabricator.services.mozilla.com/D75474
2020-05-18 12:59:26 +00:00
Masayuki Nakano b42c1f1076 Bug 1637865 - part 2: Rename `spaceNBSP` in `WSRUnObject::CheckTrailingNBSPOfRun()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D75473
2020-05-18 11:37:37 +00:00
Masayuki Nakano dafe3c5aa7 Bug 1637865 - part 1: Clean up `WSRunObject::ReplacePreviousNBSPIfUnnecessary()` and `WSRunObject::CheckLeadingNBSP()` r=m_kato
They are complicated because of not using early-return style.

Differential Revision: https://phabricator.services.mozilla.com/D75472
2020-05-18 08:33:10 +00:00
Masayuki Nakano c7249ef506 Bug 1637856 - part 2: Get rid of `WSRunScanner::mNodeArray` r=m_kato
`WSRunScanner` scans around given point in `GetWSNodes()` at construction with
using `HTMLEditUtils` methods and caches editable text nodes between
`mStartReasonContent` and `mEndReasonContent`.  However, it's used only by
`GetNextCharPoint()` and `GetPreviousCharPoint()`, and they shouldn't be
referred after changing the DOM tree.  Therefore, we can scan it directly
only when it needs to scan.

The patch rewrites `GetNextCharPoint()` and `GetPreviousCharPoint()` without
`mNodeArray` and removes `mNodeArray` from its member.  This may increase the
cost of scanning next/previous text node, but improves the scan performance
when it does not treat so wide range and they are called with a point whose
container is not a text node.

This patch unexpectedly changes the behavior of them, that causes the fix of
2 failures in `insertlinebreak.html` and `insertparagraph.html`.  According to
debugger, previously GetNextCharPoint()` in
`ScanNextVisibleNodeOrBlockBoundaryFrom()` called point at `<br>` element
returned no next char, then, `ScanNextVisibleNodeOrBlockBoundaryFrom()` returned
end point which is block boundary of `<listing>` element (it is legacy HTML2
element and treated as `<pre>` element internally).  Therefore, the inserted
`<br>` element was misunderstood as invisible `<br>` at end of a block and
inserted another `<br>` element for making it visible.  However, the redesigned
one fixed this bug with searching correct text node.  Therefore, I cannot
keep the buggy behavior in the new designed methods.

Depends on D75470

Differential Revision: https://phabricator.services.mozilla.com/D75471
2020-05-18 06:46:00 +00:00
Masayuki Nakano 714518769f Bug 1637856 - part 1: Move `WSRunObject::DeleteRange()` to `HTMLEditor` r=m_kato
`WSRunObject::DeleteRange()` removes only text nodes which are stored when
`WSRunObject` is created.  Although it removes text nodes if it's removed,
this patch does not take care about it in the new method.  The reason is
the following patch will remove `mNodeArray` and anyway DOM tree modifiers
can check whether they are in proper position before access if it's needed.

Differential Revision: https://phabricator.services.mozilla.com/D75470
2020-05-18 05:12:16 +00:00
Honza Bambas ba42858183 Bug 1535792 - Remove no longer applicable condition disabling test_richtext2.html on linux32 debug, r=jmaher
Differential Revision: https://phabricator.services.mozilla.com/D75162
2020-05-13 18:22:13 +00:00
Emilio Cobos Álvarez b9c1bf761c Bug 312971 - Unprefix -moz-read-write / -moz-read-only. r=edgar
And remove some duplicated tests from WPT.

Differential Revision: https://phabricator.services.mozilla.com/D75231
2020-05-14 16:46:08 +00:00
Mirko Brodesser 91fe215251 Bug 1635709: part 17) Annotate `CellIndexes`'s methods with `MOZ_CAN_RUN_SCRIPT`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D75099
2020-05-14 10:08:44 +00:00
Mirko Brodesser 1f8f4485a5 Bug 1635709: part 16) Replace `GetTableCellLocationFromRange` with `GetTableSelectionMode`. r=masayuki
The location wasn't used from the caller of
`GetTableCellLocationFromRange`.

However, `GetTableCellLocationFromRange`
included flushing frames, this is now done in
`HTMLEditor::CellIndexes::Update`.

Differential Revision: https://phabricator.services.mozilla.com/D75098
2020-05-14 10:08:32 +00:00
Masayuki Nakano 6644f1805c Bug 1627175 - part 18: Move `WSRunScanner::GetNextWSNode()` and `WSRunScanner::GetPreviousWSNode()` to `HTMLEditUtils` r=m_kato
They are returning same meaning value as
`HTMLEditUtils::GetNextLeafContentOrNextBlockElement()` and
`HTMLEditUtils::GetPreviousLeafContentOrPreviousBlockElement()` so that
they can be renamed to same name to overload them.

Depends on D74805

Differential Revision: https://phabricator.services.mozilla.com/D74806
2020-05-12 16:23:08 +00:00
Masayuki Nakano e561b5131a Bug 1627175 - part 17: Move `WSRunScanner::GetPreviousWSNodeInner()` to `HTMLEditUtils` r=m_kato
Similar to the previous patch, this patch moves it into `HTMLEditUtils` with
renaming it to `GetPreviousLeafContentOrPreviousBlockElement()`.

Depends on D74804

Differential Revision: https://phabricator.services.mozilla.com/D74805
2020-05-12 16:14:32 +00:00
Masayuki Nakano 79f63fcc8b Bug 1636747 - Backout the 1st patch of bug 503838 r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D75032
2020-05-13 09:09:32 +00:00
Masayuki Nakano b75955132b Bug 1627175 - part 16: Move `WSRunScanner::GetNextWSNodeInner()` to `HTMLEditUtils` r=m_kato
It looks for next leaf content or next block element for finding "end reason
node" of `WSRunScanner`.  Especially for clearing the latter case, this
patch renames it to `GetNextLeafContentOrNextBlockElement()`.

Differential Revision: https://phabricator.services.mozilla.com/D74804
2020-05-12 15:43:06 +00:00
Masayuki Nakano e317a8bfb7 Bug 1622231 - Make `HTMLEditor::SetInlinePropertyAsAction()` override property if it's called for XUL `cmd_fontFace` with a magic value "tt" r=m_kato
`FontFaceStateCommand::SetState()` called
`HTMLEditor::SetInlinePropertyAsAction()` with `nsGkAtoms::tt` when given value
is "tt".
https://searchfox.org/mozilla-central/rev/bc5737c51b8da4e758cf4db0ddb606f0aea81a7d/editor/libeditor/HTMLEditorCommands.cpp#626-627

However, I accidentally not ported this to
`HTMLEditor::SetInlinePropertyAsAction()`.  Therefore, this patch restores the
old code for the magic value.

Differential Revision: https://phabricator.services.mozilla.com/D74379
2020-05-11 07:30:47 +00:00
Masayuki Nakano 8c859f8589 Bug 1627175 - part 15: Create `HTMLEditUtils::GetFirstLeafChild()` instead of `EditorBase::GetLeftmostChild()` r=m_kato
This is used by `TextEditor::UndoAsAction()` too, so, it might be better to be
in `EditorUtils`.  However, it is completely designed for `HTMLEditor` and
ideally, `UndoAsAction` should be overridden by `HTMLEditor` too and
`TextEditor` should use faster path because of its content is in anonymous
subtree. But we don't have any merit to do that instead of avoiding virtual
call.

Differential Revision: https://phabricator.services.mozilla.com/D74362
2020-05-08 09:49:19 +00:00
Masayuki Nakano 5f4a29365e Bug 1627175 - part 14: Create `HTMLEditUtils::GetLastLeafChild()` instead of `EditorBase::GetRightmostChild()` r=m_kato
Depends on D74204

Differential Revision: https://phabricator.services.mozilla.com/D74361
2020-05-08 04:18:54 +00:00
Masayuki Nakano f358298706 Bug 1627175 - part 13: Get rid of `EditorBase::CreateRange()` r=m_kato
It's currently enough simple and there is only one user.  So, we can get rid
of it.

Differential Revision: https://phabricator.services.mozilla.com/D74204
2020-05-08 01:55:53 +00:00
Masayuki Nakano 8c3ba237c6 Bug 503838 - part 1: Remove following `<br>` element for empty line when it becomes unnecessary with inserting text r=m_kato
`HTMLEditor` does not remove padding `<br>` element for last empty line when
it becomes unnecessary.

This patch removes it when inserting some text into a text node and it's
followed by a padding <br> element.

Differential Revision: https://phabricator.services.mozilla.com/D74203
2020-05-08 01:55:31 +00:00
Mirko Brodesser 193ee7189e Bug 1635709: part 1) Rename `nsFrameSelection::SetCaretBidiLevel` to `SetCaretBidiLevelAndMaybeSchedulePaint`. r=hsivonen
The old name was misleading.

Differential Revision: https://phabricator.services.mozilla.com/D74051
2020-05-06 15:26:07 +00:00
Masayuki Nakano 5ba34b8230 Bug 1633700 - Make `CreateElementTransaction::InsertNewNode()` check the relation between container and child only when the point has child node r=m_kato
I guess that this crash may occur in these conditions:

1. It pointed end of a node, but the node has fewer children at redo.
2. The storing point has already been reset by cycle collector.

So, anyway, the check should be tested only when the point stores a
child node.

This adds WPT tests for related situation.  Although "insertLineBreak" of
Blink and WebKit behave odd when selection is collapsed between 2 elements.

Differential Revision: https://phabricator.services.mozilla.com/D73416
2020-05-07 02:25:03 +00:00
Masayuki Nakano 214c31ebcb Bug 1633797 - Make callers of `EditorBase::DeleteSelectionWithTransaction()` stop calling it if selection is collapsed but the caller tries to delete non-collapsed range r=m_kato
Our editor's deletion code removes nodes step-by-step.  Therefore, even when
somebodies call `DeleteSelectionWithTransaction()` for removing non-collapsed
ranges, they may have already removed all contents in the range.  In such
case, all callers shouldn't call `DeleteSelectionWithTransaction()`.

This makes `test_bug1425997.html` allow to run nexted `execCommand`.  It'll be
disabled even in the release channel, but we should keep testing it for
detecting bug of edge cases (like this bug).  Note that all crashtests which
test nested `execCommand` calls run with allowing it with the pref for same
reason.

Differential Revision: https://phabricator.services.mozilla.com/D73402
2020-05-07 01:23:21 +00:00
Simon Giesecke 5ab15e9640 Bug 1626570 - Improve handling of copying arrays in editor/. r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D73631
2020-05-06 11:15:49 +00:00
Mirko Brodesser 653bcbdc22 Bug 1634663: part 3) Declare callers of `Selection::GetRangeAt` in spellchecking code `const`. r=masayuki
Depends on D73445

Differential Revision: https://phabricator.services.mozilla.com/D73446
2020-05-02 23:45:59 +00:00
Mirko Brodesser b880ce0b21 Bug 1634663: part 2) Declare callers of `GetRangeAt` around `EditorBase` `const`. r=masayuki
Depends on D73444

Differential Revision: https://phabricator.services.mozilla.com/D73445
2020-05-02 23:44:46 +00:00
Masayuki Nakano 2afa55c660 Bug 1540037 - part 15: Rename `HTMLEditor::MoveChildren()` and `HTMLEditor::MoveNodeOrChildren()` to `*WithTransaction()` r=m_kato
The other `Move*()` are not move nodes without transactions.  For making
developers to distinguish the difference, this patch appends `WithTransaction`
postfix like other methods which modify DOM tree with transactions.

Differential Revision: https://phabricator.services.mozilla.com/D72847
2020-04-30 17:47:20 +00:00
Masayuki Nakano 5ae5e8d616 Bug 1540037 - part 14: Move `EditorBase::MoveNodeWithTransaction()` and `EditorBase::MoveNodeToEndWithTransaction()` r=m_kato
They are used only by `HTMLEditor` so that we can move them.

Differential Revision: https://phabricator.services.mozilla.com/D72846
2020-04-30 17:46:37 +00:00
Masayuki Nakano 481f9750ed Bug 1540037 - part 13: Move `EditorBase::MoveChildren()` to `HTMLEditor` r=m_kato
And this patch renames it to `MoveChildrenBetween()` for avoiding overload.

Differential Revision: https://phabricator.services.mozilla.com/D72845
2020-04-30 16:24:20 +00:00
Masayuki Nakano 59230aed04 Bug 1540037 - part 12: Move `EditorBase::MovePreviousSiblings()` to `HTMLEditor` r=m_kato
It's used only by `HTMLEditor` so that we can move it.

Differential Revision: https://phabricator.services.mozilla.com/D72844
2020-04-30 15:52:20 +00:00
Masayuki Nakano 0b304fcbc0 Bug 1540037 - part 11: Move `EditorBase::MoveAllChilren()` to `HTMLEditor` r=m_kato
It's used only by `HTMLEditor` so that we can move it.

Differential Revision: https://phabricator.services.mozilla.com/D72836
2020-04-30 15:31:33 +00:00
Masayuki Nakano 42b619b62e Bug 1540037 - part 10: Move `EditorBase::DoJoinNodes()` to `HTMLEditor` r=m_kato
Then, we can make `JoinNodeTransaction` store `HTMLEditor` instead of
`EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D72835
2020-04-30 15:26:09 +00:00
Masayuki Nakano f8a25cc58e Bug 1540037 - part 9: Move `EditorBase::DoSplitNode()` to `HTMLEditor` r=m_kato
And then, `SplitNodeTransaction` needs to be store `HTMLEditor` instead of
`EditorBase`.

Differential Revision: https://phabricator.services.mozilla.com/D72833
2020-04-30 13:33:40 +00:00
Masayuki Nakano 63f8d6da50 Bug 1540037 - part 8: Move `EditorBase::SplitNodeWithTransaction()` to `HTMLEditor` r=m_kato
Now, it's used only by `HTMLEditor` so that we can move it.

Differential Revision: https://phabricator.services.mozilla.com/D72832
2020-04-30 11:27:33 +00:00
Masayuki Nakano ec22b93111 Bug 1540037 - part 7: Move `EditorBase::PrepareToInsertBRElement()` r=m_kato
Although this is called by
`EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction()`, it's
mainly designed for `HTMLEditor`, but used by `TextEditor` too only when it
puts `<br>` element to the end of its anonymous `<div>` element.  Therefore,
when `TextEditor` calls
`InsertPaddingBRElementForEmptyLastLineWithTransaction()`, `aPointToInsert`
is not in a text node:
https://searchfox.org/mozilla-central/rev/158bac3df3a1890da55bdb6ffdaf9a7ffc0bfb0a/editor/libeditor/TextEditSubActionHandler.cpp#917-918,920

And it means that `PrepareToInsertBRElement()` does nothing:
https://searchfox.org/mozilla-central/rev/158bac3df3a1890da55bdb6ffdaf9a7ffc0bfb0a/editor/libeditor/EditorBase.cpp#1561,1569-1570

Therefore, we can move it into `HTMLEditor` and makes it possible to move
`EditorBase::SplitNodeWithTransaction()` called by `PrepareToInsertBRElement()`.

Differential Revision: https://phabricator.services.mozilla.com/D72831
2020-04-30 10:49:04 +00:00
Masayuki Nakano 6d98bd00c0 Bug 1540037 - part 6: Move `TextEditor::DeleteSelectionAndCreateElement()` and `TextEditor::DeleteSelectionAndPrepareToCreateNode()` to `HTMLEditor` r=m_kato
Both of them are used only by `HTMLEditor` so that we can move them to
`HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D72830
2020-04-30 09:54:55 +00:00
Masayuki Nakano fcaf1940d6 Bug 1627175 - part 12: Get rid of `HTMLEditor::GetCellFromRange()` r=m_kato
Even though the method returns only in specific cases, but the result affects
only one caller, `HTMLEditor::GetNextSelectedTableCellElement()`.  Therefore,
we can create new generic utility method,
`HTMLEditUtils::GetTableCellElementIfOnlyOneSelected()` and get rid of
`HTMLEditor::GetCellFromRange()`.

Note that the warnings in `HTMLEditor::GetCellFromRange()` is just noise for
any callers.  So, this gets rid of the useless spam warnings.

Differential Revision: https://phabricator.services.mozilla.com/D72586
2020-04-30 05:15:38 +00:00
Masayuki Nakano 8a472914a6 Bug 1627175 - part 11: Create `HTMLEditUtils::GetElementIfOnlyOneSelected()` r=m_kato
As an alternative of `HTMLEditor::GetCellFromRange()`, this patch creates more
generic utility method.

Depends on D72296

Differential Revision: https://phabricator.services.mozilla.com/D72585
2020-04-27 16:44:38 +00:00
Masayuki Nakano c3e748608d Bug 1540037 - part 5: Move `EditorBase::JoinNodesWithTransaction()` to `HTMLEditor` r=m_kato
It's used only by `HTMLEditor` so that we can move it into `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D72829
2020-04-30 09:31:11 +00:00
Masayuki Nakano adf7a304f3 Bug 1632726 - part 1: Create utility methods to compute delete range from collapsed selection in `nsFrameSelection` r=smaug
Currently, `EditorBase::ExtendSelectionForDelete()` depends on some
`nsISelectionController` methods to compute extended range for deletion
from collapsed selection.  They are implemented by
`nsFrameSelection::MoveCaret()` and `nsFrameSelection::TakeFocus()`.
Ideally, we should split these methods for computation part and performing
part.  However, they change selection with updating other selection state,
for example, table selection state and bidi information.  Therefore, it's
impossible to split them with simple code.  However, I need to change
`EditorBase::ExtendSelectionForDelete()` just return extended range.

Therefore, this patch creates `nsFrameSelection::PeekOffsetForCaretMove()`
which has the main path in `MoveCaret()` for the `EditorBase` method.

Then, `MoveCaret()` and new `nsFrameSelection::CreateRangeExtendedToSomewhere()`
share the computation code of expanding normal selection.

Finally, this patch wraps `nsFrameSelection::CreateRangeExtendedToSomewhere()`
with new public inline methods for `EditorBase`.

The following patch will remove no-user methods of `nsISelectionController`.

Differential Revision: https://phabricator.services.mozilla.com/D72295
2020-04-30 10:05:35 +00:00
Masayuki Nakano 94a85cde62 Bug 1540037 - part 4: Move `EditorBase::SplitNodeDeepWithTransaction()` to `HTMLEditor` r=m_kato
It's only used by `HTMLEditor` so that we can move it.

Differential Revision: https://phabricator.services.mozilla.com/D72826
2020-04-30 07:29:27 +00:00
Masayuki Nakano c803c1d7be Bug 1540037 - part 3: Move `EditorBase::InsertContainerWithTransaction()` and related methods to `HTMLEditor` r=m_kato
They are not used by `TextEditor` so that we should move them into `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D72825
2020-04-30 06:36:53 +00:00
Masayuki Nakano 878d787eaa Bug 1540037 - part 2: Move `EditorBase::RemoveContainerWithTransaction()` to `HTMLEditor` r=m_kato
Its users are only `HTMLEditor` and `CSSEditUtils` so that we should move it
into `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D72823
2020-04-30 06:36:41 +00:00
Masayuki Nakano c24a8d4f1f Bug 1540037 - part 1: Move `EditorBase::ReplaceContainerWithTransaction()` and related methods to `HTMLEditor` r=m_kato
They are used only by `HTMLEditor` so that we should hide them from
`TextEditor` for making it clearer that they are not used by `TextEditor`.

Note that there are 2 `DeleteNodeWithTransaction()` in `HTMLEditor` class.
One is `EditorBase`'s method and the other is `HTMLEditor`'s method.
`HTMLEditor`'s one is check whether the removing node is editable or not,
but in some cases, we need to move non-editable nodes.  Therefore, this
patch makes `ReplaceContainerWithTransaction()` call `EditorBase`'s one
for keeping current behavior.

Differential Revision: https://phabricator.services.mozilla.com/D72822
2020-04-30 06:35:38 +00:00
Botond Ballo ffdcf19a50 Bug 1633014 - Fix non-unified build errors in editor/. r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D72470
2020-04-27 03:36:57 +00:00
Masayuki Nakano 0440ea1f97 Bug 1632724 - part 5: Remove out params of `EditorBase::CreateTransactionForDelete*()` r=m_kato
The out params mean the last collapsed selection range's result (although,
the meaning is odd and offset and length are not overwritten when there is
another collapsed range and it causes `DeleteNodeTransaction`).  Additionally,
when and only when `DeleteNodeTransaction` and `DeleteTextTransaction` are
added to the `EditAggregationTransaction` created by
`CreateTransactionForSelection()`.  Therefore, same result can be looked for
from its only caller, `DeleteSelectionWithTransaction()`.

Note that this makes the method slower if there are too many selection ranges,
but such case must be rare because:

1. We can assume that users rarely use multiple selection ranges for removing
multiple ranges of content except table.
2. Multiple selection is supported only by Gecko.  Therefore, web apps must
not use multiple selection for this purpose.

So, it must be okay to use this slower approach for making the methods simpler.
If it'd become damage to some benchmarks, let's create faster access to get
transaction type.

Depends on D72293

Differential Revision: https://phabricator.services.mozilla.com/D72294
2020-04-27 01:36:02 +00:00
Masayuki Nakano f3a31a9bda Bug 1632724 - part 4: Rename `HTMLEditor::DeleteSelectionWithTransaction()` r=m_kato
`HTMLEditor::DeleteSelectionWithTransaction()` calls `EditorBase`'s overridden
method and handles `nsIEditor::eStrip` case.  Therefore, we can rename it with
stop calling the `EditorBase::DeleteSelectionWithTransaction()`, and make it
called by `EditorBase::DeleteSelectionWithTransaction()` only when it's
necessary.

Additionally, we can make all internal method callers of editor classes always
set `nsIEditor::eNoStrip` if the instance is `TextEditor`.  This must make
the code easier to understand.

Depends on D72292

Differential Revision: https://phabricator.services.mozilla.com/D72293
2020-04-27 00:36:10 +00:00
Masayuki Nakano 378eb2888e Bug 1632724 - part 3: Make helper methods of `EditorBase::DeleteSelectionWithTransaction()` take new `enum class` instead of `nsIEditor::EDirection` r=m_kato
The parameter is used only by `EditorBase::CreateTxnForDeleteRange()` to
extend collapsed range, but it accepts only `nsIEditor::eNext` and
`nsIEditor::ePrevious`.  Therefore, using `nsIEditor::EDirection` does not
make sense.  Instead, they should use new `enum class`,
`HowToHandleCollapsedRange`.

Depends on D72291

Differential Revision: https://phabricator.services.mozilla.com/D72292
2020-04-26 15:58:35 +00:00
Masayuki Nakano b67f6a5763 Bug 1632724 - part 2: Move `DeleteSelectionWithTransaction()` from `TextEditor` to `EditorBase` since it's used by `HTMLEditor` too r=m_kato
Depends on D72290

Differential Revision: https://phabricator.services.mozilla.com/D72291
2020-04-24 15:22:42 +00:00
Masayuki Nakano 6cbea10c99 Bug 1632724 - part 1: Move common methods for handling delete selection to `EditorBase` r=m_kato
`DeleteSelection*()` are members of `TextEditor`, but they are also used by
`HTMLEditor`.  Therefore, they and pref cache members for them should be
in `EditorBase` too.

Depends on D71911

Differential Revision: https://phabricator.services.mozilla.com/D72290
2020-04-24 14:55:09 +00:00
sanketh b2456e6ee7 Bug 1320229 - allow user pastes longer than input maxlength r=masayuki
Currently, all input (including user pastes) to an input field is truncated to
`maxlength`. This diff disables truncation for user pastes.

When (1) `GetEditAction` is `ePaste`, `ePasteAsQuotation`, `eDrop`, or
`eReplaceText` (ie we are dealing with a paste) and (2) `GetEditActionPrincipal`
is `nullptr` (ie we are dealing with a user edit and not a JS edit), allow a
paste without truncation. That means that, in this case, we will return
`EditActionIgnored` instead of trying to truncate the string.

This behavior is controlled by a new preference `editor.truncate_user_pastes`
which is `false` by default (set in `StaticPrefList.yaml`).

We also modify `editor/libeditor/tests/test_bug603556.html` which currently
expects the output of a paste longer than maxlength to be truncated.

Testing: Created
`editor/libeditor/tests/test_pasting_text_longer_than_maxlength.html` which
checks if a user can paste a password longer than `maxlength` and if the field
is then marked as `tooLong` (this was the original concern of the reporter of
Bug 1320229), and
`editor/libeditor/tests/test_setting_value_longer_than_maxlength_with_setUserInput.html`
which checks if `eReplaceText` has consistent behavior regardless of whether the
field has an associated editor (this test works by calling `setUserInput()`
before and after the element gets focus.) `./mach test editor/libeditor` tests
pass.

Differential Revision: https://phabricator.services.mozilla.com/D71689
2020-04-27 01:29:43 +00:00
Simon Giesecke 9cc891f41f Bug 1628715 - Part 5: Add MOZ_NONNULL_RETURN to infallible nsTArray::InsertElementsAt. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D70403
2020-04-24 13:26:13 +00:00
Masayuki Nakano 09160b3e7b Bug 1632021 - part 4: Get rid of IID of `InsertTextTransaction` and `CompositionTransaction` r=m_kato
`EditTransactionBase::GetAs*Transaction()` should be used instead.

Differential Revision: https://phabricator.services.mozilla.com/D71911
2020-04-23 12:28:39 +00:00
Masayuki Nakano 14c56a78ab Bug 1632021 - part 3: Get rid of `nsIAbsorbingTransaction` r=m_kato
It's inherited only by `PlaceholderTransaction` and used only for QI.
Therefore, we can get rid of it.

Additionally, this makes storing `PlaceholderTransaction` and
`CompositionTransaction` in `PlaceholderTransaction` faster and safer with
`WeakPtr`.

Finally, this makes `PlaceholderTransaction` always have non-null name
because it caused a lot of useless warnings in
`EditAggregationTransaction::GetName()` and
`PlaceholderTransaction::GetTxnName()`.

Differential Revision: https://phabricator.services.mozilla.com/D71910
2020-04-23 10:46:55 +00:00
Masayuki Nakano 47acd7e8de Bug 1632021 - part 2: Add `nsITransaction::GetAsEditTransactionBase()` r=m_kato
In a lot of places in libeditor, we do nothing if given transaction is not
our edit transaction classes' instance.  Therefore, it's better to have
casting virtual method in `nsITransaction` for performance because QI cost
may not be cheap.

Differential Revision: https://phabricator.services.mozilla.com/D71908
2020-04-23 07:02:16 +00:00
Masayuki Nakano 3aa3b37a40 Bug 1632021 - part 1: Add `GetAs*Transaction()` methods to every subclasses of `EditTransactionBase` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D71907
2020-04-23 05:46:43 +00:00
Jonathan Kew d0c11aa6d1 Bug 425915 - Add Thai movement-by-word testcases. r=m_kato
Depends on D71206

Differential Revision: https://phabricator.services.mozilla.com/D71621
2020-04-23 14:19:44 +00:00
Mark Banner 91b65009eb Bug 1549945 - Avoid the need for import-globals-from when (x)html files load scripts via /tests/. r=mossop
When loading from /tests/ we can strip off the /tests/ part and find the file with the rest of the path.

Differential Revision: https://phabricator.services.mozilla.com/D71411
2020-04-20 16:15:11 +00:00
Emilio Cobos Álvarez 31821e1fc4 Bug 1449522 - Remove nsIEditorStyleSheets. r=masayuki,m_kato
Users have much better, easier alternatives, like
DOMWindowUtils.{loadSheetUsingURIString,removeSheet}, which we use to
replace the only caller that exists in mozilla-central (the editor
element, which loads EditorOverride.css).

This allows to clean up the style system and editor. There are other
callers in comm-central, but it seems they can switch to DOMWindowUtils
trivially, as the DOMWindowUtils APIs also use the system principal and
thus they can load any URL.

I'll make sure to give them some time with the migration and/or help
out of course.

Differential Revision: https://phabricator.services.mozilla.com/D71263
2020-04-17 22:54:48 +00:00
Masayuki Nakano 9f7fb5bb0f Bug 1630168 - Make `HTMLEditor` stop adding same runnable method into the queue r=m_kato
When `HTMLEditor` is notified of content changes, it may add a runnable method
`HTMLEditor::OnModifyDocument` or `HTMLEditor::NotifyRootChanged` for each
notification. However, their code do not need running twice nor more. This
could cause performance issues on complicated web apps which sets `innerHTML`
at every key press.

Differential Revision: https://phabricator.services.mozilla.com/D71001
2020-04-16 15:15:26 +00:00
Masayuki Nakano 5a3a0d40e7 Bug 1627175 - part 10: Move `HTMLEditor::GetEnclosingTable()` to `HTMLEditUtils` r=m_kato
Depends on D70883

Differential Revision: https://phabricator.services.mozilla.com/D70884
2020-04-16 14:53:54 +00:00
Masayuki Nakano 29b0030c60 Bug 1627175 - part 9: Move `HTMLEditor::GetBlock()` and `HTMLEditor::GetBlockNodeParent()` to `HTMLEditUtils` r=m_kato
This patch also names the former to `GetInclusiveAncestorBlockElement()` and
the latter to `GetAncestorBlockElement()` for consistency with modern DOM
API names.

Depends on D70882

Differential Revision: https://phabricator.services.mozilla.com/D70883
2020-04-16 14:19:18 +00:00
Masayuki Nakano 1ee4f00529 Bug 1627175 - part 8: Move `EditorBase::IsContainer()` to `HTMLEditUtils` r=m_kato
It's a virtual method which always returns true if `TextEditor`.  Therefore,
we can move it into `HTMLEditUtils` and we can make the only caller of
`EditorBase` check `IsTextEditor()` instead.

Depends on D70880

Differential Revision: https://phabricator.services.mozilla.com/D70882
2020-04-16 10:32:26 +00:00
Masayuki Nakano 5bcef30e8b Bug 1627175 - part 7: Move `EditorBase::IsPaddingBRElementForEmptyLastLine()` to `EditorUtils` r=m_kato
It's also used in `<textarea>` so that it should be in `EditorUtils` rather
than `HTMLEditUtils`.

Depends on D70879

Differential Revision: https://phabricator.services.mozilla.com/D70880
2020-04-16 05:07:13 +00:00
Masayuki Nakano 73992aad12 Bug 1627175 - part 6: Move "can contain" utility methods to `HTMLEditUtils` r=m_kato
Actually, they are used only by `HTMLEditor` because `TextEditor` finally
returns `true` for any cases in `TextEditor`, but the users are overridden by
`HTMLEditor` and never used by `HTMLEditor`.  Therefore, we cam move them
into `HTMLEditUtils`.

Depends on D70878

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

--HG--
extra : moz-landing-system : lando
2020-04-16 04:38:40 +00:00
Masayuki Nakano aeeb323f57 Bug 1627175 - part 5: Get rid of `EditorBase::GetChildOffset()` and `EditorBase::GetNodeLocation()` r=m_kato
Their users should use `EditorDOMPoint` or something instead.

This patch cleans up `EditorBase::DoJoinNodes()` too because of their heavy
user.  It requires only joined nodes because `aParent` is used only for
removing `aContentToJoin`, but we now have `nsINode::Remove()` which does
not require parent node and never fails.

Depends on D70877

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

--HG--
extra : moz-landing-system : lando
2020-04-16 01:21:17 +00:00
Masayuki Nakano 8b3995f814 Bug 1627175 - part 4: Get rid of `EditorBase::IsText()` r=m_kato
A lot of editor code refers `nsINode::IsText()` directly so that we don't
need to keep the too simple editor API anymore.

Depends on D70876

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

--HG--
extra : moz-landing-system : lando
2020-04-15 16:05:30 +00:00
Masayuki Nakano 7d9227e497 Bug 1627175 - part 3: Move `EditorBase::AreNodesSameType()` to `HTMLEditUtils` r=m_kato
It's only non-`HTMLEditor` user is `EditorBase::JoinNodesDeepWithTransaction()`,
but it's called only by `HTMLEditor`.  Therefore, we can move it into
`HTMLEditUtils` and move `EditorBase::JoinNodesDeepWithTransaction()` to
`HTMLEditor`.

Depends on D70875

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

--HG--
extra : moz-landing-system : lando
2020-04-15 15:55:20 +00:00
Masayuki Nakano 4cc133b568 Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once.  Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.

For the former case, we should sort out it with
`EditorUtils::IsEditableContent()`, but for now, this patch moves it to
`HTMLEditUtils::IsSimplyEditable()`.  On the other hand, for the latter case,
we obviously has a bug.  Therefore, this patch creates
`HTMLEditUtils::IsRemovableFromParentNode()` and make it check whether the
removing node is also editable.

Unfortunately, `EditorUtils::IsEditableContent()` needs to take editor type.
But it's most callers are in `HTMLEditor` and most of remains are in
common methods of `EditorBase`.  I guess we could remove this ugly argument
in the future.

Depends on D70874

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

--HG--
extra : moz-landing-system : lando
2020-04-15 15:27:38 +00:00
Masayuki Nakano 7ae8033ee1 Bug 1627175 - part 1: Move `HTMLEditor::IsBlockNode()` into `HTMLEditUtils` r=m_kato
`HTMLEditor::IsBlockNode()` is a virtual method derived from
`EditorBase::IsBlockNode()`.  For the performance, `EditorBase`'s one just
return false for text node and `<br>` element.  However, these check cost
is really cheap in these days.  Therefore, we can make `TextEditor` also
use rich API.

This patch moves `HTMLEditor::NodeIsBlockStatic()` and
`HTMLEditor::NodeIsInlineStatic()` to `HTMLEditUtils`, and removes the wrapper
of the fommer, `HTMLEditor::IsBlockNode()` and `WSRunScanner::IsBlockNode()`.

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

--HG--
extra : moz-landing-system : lando
2020-04-15 13:55:36 +00:00
Cameron McCormack 9e9b510199 Bug 1629474 - Avoid warnings when initializing empty editors. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D70669

--HG--
extra : moz-landing-system : lando
2020-04-13 08:55:41 +00:00
Makoto Kato 67f4ec1ac0 Bug 1628192 - Use more const declarations on editor classes. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D70146

--HG--
extra : moz-landing-system : lando
2020-04-13 01:43:41 +00:00
Masayuki Nakano 39b3ec6675 Bug 1624007 - Don't check `IsSelectionRangeContainerNotContent()` for/in `GetElementOrParentElement*()` r=m_kato
We can relax about `GetElementOrParentElement*()` because they just return
`nullptr` when selection anchor is a `Document` node.

Additionally, this patch renames the internal APIs to the names similar to
modern DOM API.

Finally, this adds automated test for
`nsIHTMLEditor.getElementOrParentByTagName()`.

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

--HG--
extra : moz-landing-system : lando
2020-04-09 10:10:36 +00:00
Masayuki Nakano 9f10b2a2a0 Bug 1627573 - part 4: Mark `CSSEditUtils` methods which refer computed style as `MOZ_CAN_RUN_SCRIPT` r=m_kato
When it refers computed value of style, it may flush pending notifications.
Therefore, they should be marked as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
2020-04-09 10:10:34 +00:00
Masayuki Nakano 32e8f30b27 Bug 1627573 - part 3: Get rid of `CSSEditUtils::GetSpecifiedCSSEquivalentToHTMLInlineStyleSet()` because of unused r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D70150

--HG--
extra : moz-landing-system : lando
2020-04-09 10:08:52 +00:00
Masayuki Nakano ea92dfc783 Bug 1627573 - part 2: Split public methods of `CSSEditUtils` which work with both specified values and computed values r=m_kato
Some methods take `StyleType` to work them with specified values or computed
values.  This method hides `StyleType` into `CSSEditUtils` and splits the
public methods which took `StyleType` to 2 methods, one is for working with
specified values, the other is for working with computed values.

Additionally, this patch fixes some argument name and type.

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

--HG--
extra : moz-landing-system : lando
2020-04-09 10:08:37 +00:00
Masayuki Nakano ac60892e7d Bug 1627573 - part 1: Remove unused `CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet()` overload r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D70148

--HG--
extra : moz-landing-system : lando
2020-04-09 10:08:09 +00:00
Bogdan Tara a81dc418ef Backed out 4 changesets (bug 1627573) for bustages complaining about CSSEditUtils.cpp CLOSED TREE
Backed out changeset 8ced0e6ed31e (bug 1627573)
Backed out changeset 07b5b67c32c2 (bug 1627573)
Backed out changeset 04734d17e8d0 (bug 1627573)
Backed out changeset 77486fd073af (bug 1627573)
2020-04-09 10:58:46 +03:00
Masayuki Nakano 1142d3105a Bug 1627573 - part 4: Mark `CSSEditUtils` methods which refer computed style as `MOZ_CAN_RUN_SCRIPT` r=m_kato
When it refers computed value of style, it may flush pending notifications.
Therefore, they should be marked as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
2020-04-08 15:51:17 +00:00