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

10465 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano 1a7d5b3f13 Bug 1664969 - Disable async font list initialization under editor/libeditor/tests r=m_kato,jfkthame
According to the debug log and result on tryserver, the frequency of this
test failure becomes higher is caused by bug 1676966.  When global reflow
is kicked during dragging the grabber, the implicit capture is released
forcibly.  Fortunately, editor behavior shouldn't depend on font list
loading system, so, disabling the feature until fixing bug 1688430 is fine.

Differential Revision: https://phabricator.services.mozilla.com/D102889
2021-01-25 10:19:12 +00:00
Makoto Kato d8cdbc5ec4 Bug 1687167 - Move IME handling guide to source tree. r=masayuki DONTBUILD
https://developer.mozilla.org/en-US/docs/Mozilla/IME_handling_guide is
archived content now, So we should move this to
https://firefox-source-docs.mozilla.org/.

Also, I have updated mActionHint and Android section.

Differential Revision: https://phabricator.services.mozilla.com/D102118
2021-01-19 06:07:27 +00:00
Henri Sivonen e9ebba30d8 Bug 1682950 - Skip test_sanitizer_on_paste.html in headless mode. r=saschanaz
Differential Revision: https://phabricator.services.mozilla.com/D101338
2021-01-13 11:30:50 +00:00
Masayuki Nakano 8907ec27b0 Bug 1357365 - part 7: Make `TypeInState::OnSelectionChange` stop keeping link style for new inserting content after content around a link edge is deleted r=m_kato
This is same behavior as the other browsers.  When selection is collapsed to
a edge of a link after deletion, we should stop applying link style to new
inserted content.

Differential Revision: https://phabricator.services.mozilla.com/D101006
2021-01-13 01:56:05 +00:00
Masayuki Nakano 900311e687 Bug 1357365 - part 6: Make `TypeInState::OnSelectionChange()` stop keeping link style when selection is not collapsed and the range is not entirely in a link r=m_kato
When selection is not collapsed and is across link element boundary, we can
assume that user does not try to modify the link text because the other
browsers behave so.  Therefore, we should take the same behavior in this case.

Note that all the new failures of `editing/run/inserttext.html` are passed
only on Gecko.  So, it should be updated in another bug.

Differential Revision: https://phabricator.services.mozilla.com/D101005
2021-01-13 01:55:48 +00:00
Masayuki Nakano 269faceec3 Bug 1357365 - part 5: Make `TypeInState::OnSelectionChange` stop keeping link style for new inserting content when selection is changed by JS r=m_kato,edgar
This is the most important situation.  If selection is collapsed to a edge of a
link, the other browsers does not insert new content into the link.  So, from
the point of view of web developers, this cause should work exactly same as
the other browsers.

Note that the new failures in `editing/run/inserttext.html` are passed only
on Gecko.  So, the test should be updated after fixing this bug.

Differential Revision: https://phabricator.services.mozilla.com/D101004
2021-01-13 01:55:40 +00:00
Masayuki Nakano b12d5c9e83 Bug 1357365 - part 4: Make `TypeInState` stop keeping link style when selection change command is performed, but it didn't change selection r=m_kato,edgar
When caret is not moved but selection change command is fired, it means that
the caret is already set to start or end of editing host.  In this case, we
should stop keeping link style for new inserting content because otherwise,
user cannot exit from the first or last link with arrow keys.

Differential Revision: https://phabricator.services.mozilla.com/D101003
2021-01-13 01:55:32 +00:00
Masayuki Nakano 201d289381 Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.

However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.

Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style.  This helps advanced users who are familiar with keyboard navigatin
in editor.

Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.

Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too.  But a following patch will add a new
reason to notify selection listeners of caused by JS.  So, the problem
will be fixed by the following patch.

Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 01:55:29 +00:00
Masayuki Nakano 4b218fc374 Bug 1357365 - part 2: Make `TypeInState::OnSelectionChange()` stop inserting new content into the link if clicked outside it r=m_kato
When mouse button is clicked outside a link element but caret is positioned
start or end of the link, our traditional behavior keeps inserting new content
into the link.  But this is different from the other browsers, and it does
not make sense to treat such selection change is intended to keep typing in
the link element.

Therefore, this patch makes `TypeInState::OnSelectionChange()` handle
selection change reason is `mousedown` and `mouseup` cases.  However,
it cannot know whether the event was fired in the parent link element or
not.  Therefore, this patch makes `HTMLEditorEventListener` notifies
`TypeInState` of mouse events via `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D101001
2021-01-13 01:55:27 +00:00
Masayuki Nakano 0028b2127b Bug 1357365 - part 1: Rename `HTMLEditor::OnMouseDown()`, `HTMLEditor::OnMouseUp()` and `HTMLEditor::OnMouseMove()` r=m_kato
They were designed for object resizer and grabber to move absolutely positioned
element.  Therefore, they should have better name to explain what they do.
Then, we can create event listener methods for generic cases.

Differential Revision: https://phabricator.services.mozilla.com/D100999
2021-01-13 01:54:17 +00:00
Masayuki Nakano aca200577d Bug 1357365 - part 0-1: Make `test_typing_at_edge_of_anchor.html` test both on `contenteditable` and `designMode` r=m_kato
Currently, the test checks the result only in `contenteditable`, but I'd be
better to do same tests in `designMode` editor too.

Additionally, for detecting regressions of the following patches, it should
check the result of 2nd typing too because inserting text into end of a link
element may cause unlink it.

Differential Revision: https://phabricator.services.mozilla.com/D100997
2021-01-13 01:53:46 +00:00
Kartik Gautam 7ae6aea145 Bug 1684173 - Add newline character at end of files when missing r=sylvestre,geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D100484
2021-01-07 08:53:08 +00:00
Daniel Holbert ac4480af11 Bug 1685231: Fix the typo "ot" in various code-comments (to "to", "of", or "not"). r=mccr8
DONTBUILD because this is a comment-only change and hence doesn't affect
behavior at all.

I ran across this typo in nsPageFrame.cpp, and figured I might as well grep for
it and fix it more comprehensively. And while I'm at it, I also fixed some
neighboring instances of a duplicated word around a linebreak, in
nsXMLContentSerializer.h.

Differential Revision: https://phabricator.services.mozilla.com/D100852
2021-01-06 04:54:51 +00:00
Andi-Bogdan Postelnicu b6b336c821 Bug 1683534 - Make `editor` buildable outside of `unified-build` environment. r=sg
Differential Revision: https://phabricator.services.mozilla.com/D100206
2021-01-04 14:18:50 +00:00
Cosmin Sabou 2978aa00a3 Backed out changeset dbed1cdf588f (bug 1684173) for mochitest plain and devtools failures. a=backout DONTBUILD 2020-12-28 00:43:51 +02:00
Kartik Gautam 775cdec032 Bug 1684173 - Add newline character at end of files when missing r=sylvestre
Depends on D100443

Differential Revision: https://phabricator.services.mozilla.com/D100484
2020-12-27 11:43:41 +00:00
Masayuki Nakano 5599ddec3c Bug 1683226 - part 3: Get rid of pathes for handling plugin from `IMEStateManager`, `IMEContentObserver` and `ContentEventHandler` r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D100102
2020-12-21 05:52:49 +00:00
Masayuki Nakano d27602eee6 Bug 1683226 - part 1: Make `IMEState::Enabled` an enum class r=m_kato,geckoview-reviewers
Before deleting `IMEState::Enabled::PLUGIN`, let's make it an enum class
for making the change safer.  Almost all of this change is done by
"replace" of VSCode.

Differential Revision: https://phabricator.services.mozilla.com/D100100
2020-12-21 05:52:03 +00:00
Emilio Cobos Álvarez 039592f4d8 Bug 1682003 - Avoid UTF-8 -> UTF-16 conversion during CSSOM serialization. r=heycam
This lifts a bunch of string conversions higher up the stack, but allows
us to make the servo code use utf-8 unconditionally, and seemed faster
in my benchmarking (see comment 0).

It should also make a bunch of attribute setters faster too (like
setting .cssText), now that we use UTF8String for them (we couldn't
because we couldn't specify different string types for the getter and
setters).

Differential Revision: https://phabricator.services.mozilla.com/D99590
2020-12-17 14:04:35 +00:00
Henri Sivonen 97959884fc Bug 1666300 test - Test SVG style sanitization on paste. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D93634
2020-11-18 17:18:56 +00:00
Kartik Gautam f7ffcd09fb Bug 1679758 - Remove trailing empty lines r=sylvestre,marionette-reviewers,jgraham
Differential Revision: https://phabricator.services.mozilla.com/D99595
2020-12-15 10:34:54 +00:00
Makoto Kato 832ca9a3d8 Bug 1671764 - Part 2. Respect application/system locale if language code is matched. r=masayuki
When we don't match exactly dictionary name with `lang` attribute, we look for
language name. When looking for language name (ex. en/fr etc), we don't
consider the priority by application/system locale. So if lang=en, it may be
selected by character order. Most case is that en-GB is always selected if it
is installed.

We should respect application/system locale if language name is matched to
current content language before random selection.

Depends on D99336

Differential Revision: https://phabricator.services.mozilla.com/D99337
2020-12-14 03:01:08 +00:00
Makoto Kato ddeba05428 Bug 1671764 - Part 1. Use ACString for dictionary language instead. r=masayuki
Actually, our locale service doesn't use UTF-16 for locale name and it will
be ASCII. Although dictionary name of spell checker is locale/language name,
it still uses UTF-16. To use locale API, I should replace it with `ACString`.

Differential Revision: https://phabricator.services.mozilla.com/D99336
2020-12-14 03:01:05 +00:00
Dorel Luca 7320ae982a Backed out changeset f3aaf04fce3b (bug 1679758) for Devtool failures in browser_styleeditor_syncAddProperty.js. CLOSED TREE 2020-12-13 16:38:21 +02:00
Kartik Gautam caf549c200 Bug 1679758 - Remove trailing empty lines r=sylvestre
Differential Revision: https://phabricator.services.mozilla.com/D99595
2020-12-13 13:28:30 +00:00
Emilio Cobos Álvarez b1964fa19a Bug 1682006 - Don't call Truncate() on the return string in GetPropertyValue. r=xidorn
Turns out this causes a bit of overhead when appending to an AutoString,
because Truncate() calls SetToEmptyBuffer(), which makes it go from
inline-string to buffer string, and next time we append we need to turn
the string from a buffer-based string to an inline string again, which
is some minor, but measurable, work, while profiling some
micro-benchmarks.

Probably we should make Truncate() a no-op for a zero-length string, but
I'll send that separately.

Differential Revision: https://phabricator.services.mozilla.com/D99493
2020-12-12 12:06:06 +00:00
Kagami Sascha Rosylight 8aba7414f7 Bug 1680167 - Part 6: Use RefPtr for nsFocusManager in editor r=masayuki
Depends on D98628

Differential Revision: https://phabricator.services.mozilla.com/D98629
2020-12-03 21:35:20 +00:00
Simon Giesecke dd80614fa0 Bug 1678062 - Remove unnecessary includes. r=andi
Differential Revision: https://phabricator.services.mozilla.com/D97467

Depends on D96561
2020-11-23 16:12:02 +00:00
Simon Giesecke f15895390e Bug 1673931 - Avoid including Element.h from header files.
Differential Revision: https://phabricator.services.mozilla.com/D96535

Depends on D96534
2020-11-23 16:08:40 +00:00
Simon Giesecke 071c7c035f Bug 1676356 - Avoid including PresShell.h from header files. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D96534

Depends on D95184
2020-11-23 16:08:23 +00:00
Simon Giesecke 5bfbb2a572 Bug 1673931 - Avoid including Document.h from header files. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D95046

Depends on D95045
2020-11-23 16:07:43 +00:00
Simon Giesecke 971b645fe3 Bug 1660470 - Add missing include directives/forward declarations. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D87865
2020-11-23 16:21:38 +00:00
Kagami Sascha Rosylight 7db6203754 Bug 1678361 - Return gracely when GetDataTransfer fails r=masayuki
DragEvent::GetDataTransfer() is fallible when memory allocation fails as it lazily constructs DataTransfer. This tries failing gracely when that happens.

Differential Revision: https://phabricator.services.mozilla.com/D97663
2020-11-20 06:04:43 +00:00
Mirko Brodesser 2bd707b236 Bug 1669963: factor some constants and functions for testing the clipboard out. r=ahal
They'll be used by other tests too.

Differential Revision: https://phabricator.services.mozilla.com/D97329
2020-11-17 20:28:48 +00:00
Masayuki Nakano 1edcd70cdd Bug 1676295 - Add WPT to test deleting in/around/across list items r=smaug
There are not enough tests comparing delete operation result and result of
`getTargetRanges()` when selection is in/around/across list item elements.
This patch creates a utility method to make the test body not need to use
Selection API for making simpler tests.

The expected behavior is based on Blink and WebKit unless their behavior is
buggy because their behavior is more reasonable than Gecko's in most cases.

Note that the removing tests are covered by the new tests.

Differential Revision: https://phabricator.services.mozilla.com/D96800
2020-11-14 10:30:31 +00:00
Masayuki Nakano 00b602a0f0 Bug 1627673 - Do null-check the result of `DragEvent::GetDataTransfer()` in `EditorEventListener`` r=smaug
I guess that `DataTransfer::HasType()` is inlined in the opt builds and
actually crashed in `EditorEventListener::DragEventHasSupportingData()`
at accessing `aDragEvent->GetDataTransfer()` result without null-check
because `DataTransfer::mItems` is set to `nullptr` only by the cycle
collector, but it does not make sense to think that it occurs the STR
in bug 1627673 comment 3.

Therefore, this patch adds null-checks in
`EditorEventListener::DragEventHasSupportingData()`.

I have no idea how to test this with automated tests.

Differential Revision: https://phabricator.services.mozilla.com/D96310
2020-11-09 23:39:10 +00:00
Masayuki Nakano c6d7f7e4f8 Bug 1605741 - Make all callers of `HTMLEditor::InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary()` check whether there is a caret or not r=m_kato
`InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary()` checks whether
a line containing `aPointToInsert` requires invisible `<br>` element.
Therefore, `aPointToInsert` must be set and valid.  However, all selection
ranges may be removed by somebody when modifying the DOM tree before that.

Therefore, this patch makes all callers of it check whether they succeeded
to retrieve caret position or not.

Differential Revision: https://phabricator.services.mozilla.com/D96280
2020-11-09 03:01:16 +00:00
Masayuki Nakano 6109e35d9e Bug 1579934 - Make `WhiteSpaceVisibilityKeeper::MergeFirstLineOf*()` stop handling their job if calling `DeleteInvisibleASCIIWhiteSpace()` makes the descendant block position changed r=m_kato
They join first line of a descendant block element into the line at the other
block contains the descendant block.  First of all of their jobs, they call
`DeleteInvisibleASCIIWhiteSpace()` to clean up unnecessary whitespaces at
the other block.  At this time, the point which tells whether the descendant
element is contained in the other block may become invalid if script runs
and it causes changing the DOM tree.  Therefore, they should check the
given point is still valid after calling `DeleteInvisibleASCIIWhiteSpace()`
because `AutoTrackDOMPoint` requires valid point.

Differential Revision: https://phabricator.services.mozilla.com/D95987
2020-11-06 06:38:49 +00:00
Masayuki Nakano 994715338f Bug 1578916 - Add reported testcase to crashtests (the crash was fixed by bug 1627175) r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D95983
2020-11-06 04:07:28 +00:00
Andrew Halberstadt 331bc892dd Bug 1675319 - [manifestparser] Properly support multiline skip-if statements, r=jmaher,extension-reviewers,zombie
This supports one manifestparser expression per line in the 'skip-if',
'fail-if' and 'run-if' keys. As a side effect the:

    skip-if = foo ||
        bar

syntax is no longer supported. Instead it can be:

    skip-if =
        foo  # bug 123
        bar  # bug 456

Differential Revision: https://phabricator.services.mozilla.com/D95927
2020-11-05 19:55:08 +00:00
tobar2018 eb66350c76 Bug 1674609 - HTMLEditorDeleteHandler.cpp: redundant continue statement at the end of loop statement. r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D95669
2020-11-03 22:58:01 +00:00
Masayuki Nakano ec06061862 Bug 1581246 - Add reported testcase as a crashtest (the crash was fixed by bug 1666556) r=m_kato
This does not require recursive call of `execCommand` so that this does not
set the pref.

Depends on D95268

Differential Revision: https://phabricator.services.mozilla.com/D95269
2020-10-30 12:03:59 +00:00
Masayuki Nakano 10b3906382 Bug 1666556 - Make `HTMLEditor` stop accepting focus event when a text control which is an editing host gets focus r=m_kato
`HTMLEditor` ignores input events when a text control element in an editing
host has focus.
https://searchfox.org/mozilla-central/rev/d866b96d74ec2a63f09ee418f048d23f4fd379a2/editor/libeditor/HTMLEditor.cpp#6322

However, focus event does not check it and modifies ancestor limiter of
`Selection` for the document.  And even in this case, public methods for
handling some edit actions are open for `execCommand` requests.  Then,
edit action handlers may set selection outside the elements, but new focus
event to update the selection ancestor limiter will be handled later.
Therefore, until getting next focus event, `HTMLEditor` does not work as
expected since `Selection::*InLimiter()` APIs refuse to change selection.

Ideally, we should make `nsFocusManager` notifies editor of focus change
synchronously, but I cannot fix it quickly because it needs to touch security
sensitive area.  Therefore, this patch makes `HTMLEditor` do not set
ancestor limiter when a text control in any editing host gets focus.

Additionally, this patch makes
`HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::HandleDeleteAtOtherBlockBoundary`
stop handling leaf node deletion if it cannot change caret position.

Differential Revision: https://phabricator.services.mozilla.com/D95268
2020-10-30 13:45:48 +00:00
Masayuki Nakano 1fe9274aa4 Bug 1663725 - Add reported test as a crashtest (the crash bug itself was fixed by bug 1663601) r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D95127
2020-10-30 04:18:36 +00:00
Masayuki Nakano 9b606cfb10 Bug 1624005 - Make `WSScanResult` have error state and make the scan methods of `WSRunScanner` use it when it fails to initialize `TextFragmentData` r=m_kato
The test runs `execCommand("insertHorizontalRule")` when the document node
has no children.  In this case, `TextFragmentData` fails to initialize itself.
In this case, our editor cannot do anything.  Therefore, returning error
in this case must be better.

This patch makes all callers of the scan methods handle the error case unless
the caller cannot return error.

Comparing with Blink, perhaps, we should insert `<html>` and `<body>` element
in this case first and keep doing the requested operation in the future.
Currently, doing it may cause another complicated issue with mutation event
listeners.

Differential Revision: https://phabricator.services.mozilla.com/D95126
2020-10-30 07:33:39 +00:00
Masayuki Nakano e58b93b3d9 Bug 1613521 - Make `NeedsToDispatchBeforeInputEvent()` return false if the edit action requires a clipboard event and it's not dispatched yet r=m_kato
The reason of hitting the assertion is, a clipboard event listener nests
another edit action, initializing the editor, runs, and tries to create an
anonymous `<br>` element with transaction, but it checks whether `beforeinput`
event has already been dispatched or not with the parent edit action data.

For fixing it, this patch adds a flag to edit action data to indicate whether
a clipboard event has already been dispatched or not.  If it's already been
dispatched, it's **okay** to modify the DOM tree.  Ideally, we should put off
modifying the DOM tree after dispatching `beforeinput` event, but this case
does not notify web apps anything so that this patch should be fine.

Although this patch adds a crash test which is attached by the reporter,
it's not reproducible with current editor code because we stopped modifying
native anonymous nodes with transaction, but it depends on the behavior.
Still this assertion hits in `test_clipboard_noeditor.html` intermittently,
but I don't have idea how to reproduce this permanently.  Therefore, this
patch does not contain a test to check to regression actually.

Differential Revision: https://phabricator.services.mozilla.com/D95115
2020-10-30 07:21:40 +00:00
Makoto Kato 85f53704b2 Bug 1673816 - DeleteNodeWithTransaction should allow non-editable node which parent is editable. r=masayuki
Actually, `DeleteNodeWithTransaction` cannot remove non-editable node. But
we should allow it which parent node is ediatble.

Differential Revision: https://phabricator.services.mozilla.com/D94937
2020-10-30 01:38:41 +00:00
Masayuki Nakano 9d40c25ea2 Bug 1673790 - Split `editor/libeditor/HTMLEditSubActionHandler.cpp` r=m_kato
It's too big (+15k lines) and there are 2 groups which does not depend on the
others.  One is getting current state for `Document.queryCommandState` etc.
This is copied to `HTMLEditorState.cpp`.  And the other is delete handlers.
This is copied to `HTMLEditorDeleteHandler.cpp`.

Differential Revision: https://phabricator.services.mozilla.com/D94934
2020-10-28 13:08:34 +00:00
Masayuki Nakano 21fd55f3a4 Bug 1663793 - part 7: Make `runTest()` automatically handle editor value check in the case canceling `beforeinput` r=m_kato
When `beforeinput` event is canceled, the editor content shouldn't be modified.
Therefore, `runTest()` can handle it with caching initial value before
running the test body.

Additionally, this patch makes every test ensure that target editor has focus.
So, finally, each test is now isolated completely.  Developers can run only
a test with commenting out the other tests.

Depends on D94520

Differential Revision: https://phabricator.services.mozilla.com/D94521
2020-10-27 09:10:05 +00:00
Masayuki Nakano 58a805938e Bug 1663793 - part 6: Encapsulate all variables interacting with event listeners into a function r=m_kato
This patch makes all test functions call `runTest()` and it adds event listeners
only while running the function.  Therefore, this makes each test function do:
* initializing for running test
* running test with `runTest` and specifying expected data

Depends on D94519

Differential Revision: https://phabricator.services.mozilla.com/D94520
2020-10-27 08:08:51 +00:00
Masayuki Nakano 4302a60fd8 Bug 1663793 - part 5: Create a common method to check editor content, beforeinput event and input event r=m_kato
Depends on D94518

Differential Revision: https://phabricator.services.mozilla.com/D94519
2020-10-27 04:34:36 +00:00
Masayuki Nakano b6a756a7b5 Bug 1663793 - part 4: Make all test functions take an object for consistency r=m_kato
This allows the following patches will make all functions use batch function
to test with a framework.

Depends on D94517

Differential Revision: https://phabricator.services.mozilla.com/D94518
2020-10-27 03:49:42 +00:00
Masayuki Nakano 8b035a3c62 Bug 1663793 - part 3: Use same function to check canceling "beforeinput" and not canceling it r=m_kato
So, this removes functions named as `*_and_canceling_beforeinput` and
makes corresponding function take an object which has `action` and
`cancelBeforeInput` to reduce dependency on wider scope variables.

Depends on D94516

Differential Revision: https://phabricator.services.mozilla.com/D94517
2020-10-27 01:48:34 +00:00
Masayuki Nakano 50d3d995a4 Bug 1663793 - part 2: Split each chunk into IIFE r=m_kato
Although, still there are dependencies between the functions, this allows
stack has meaningful name where a failure occurs.

Depends on D94515

Differential Revision: https://phabricator.services.mozilla.com/D94516
2020-10-26 13:01:36 +00:00
Masayuki Nakano 3cd4b0ed5d Bug 1663793 - part 1: Make sure description of `ok()`, `is()`, etc. have its own line r=m_kato
Indent level of the tests will be increased.  Therefore, all descriptions
should be in their own lines.

Note that this and following patches rewrite almost all lines in the test
files again and again.  Therefore, it's hard to rebase and existing bugs
will be fixed when I was writing each patch.  So, I'd like reviewers just
put inline comment which should be fixed before landing.  Then, I'll add
a patch to fix them.

Differential Revision: https://phabricator.services.mozilla.com/D94515
2020-10-26 09:11:41 +00:00
Masayuki Nakano 03ae5e76db Bug 1669479 - part 2: Make `HTMLEditor::ComputeTargetRanges()` handle table cell selection mode with new utilities r=m_kato
So, the root cause of this assertion hit was, I forgot to add this path
when I implement the methods to compute target ranges.  Although the other
browsers don't support multiple selection ranges, this patch adds WPTs
for the cases.

Depends on D94241

Differential Revision: https://phabricator.services.mozilla.com/D94242
2020-10-26 09:10:29 +00:00
Masayuki Nakano 7f22e0e96a Bug 1671556 - part 14: Get rid of `HTMLEditor::GetFirstSelectedTableCellElement()`, `HTMLEditor::GetNextSelectedTableCellElement()` and `HTMLEditor::mSelectedCellIndex` r=m_kato
Depends on D94240

Differential Revision: https://phabricator.services.mozilla.com/D94241
2020-10-26 05:53:58 +00:00
Ricky Stewart 02a7b4ebdf Bug 1654103: Standardize on Black for Python code in `mozilla-central`.
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-26 18:34:53 +00:00
Masayuki Nakano 632bea14d4 Bug 1671556 - part 13: Make `HTMLEditor::GetFirstSelectedCellInTable()` stop using `CellAndIndexes` which uses `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
The method is tested by `test_nsITableEditor_getFirstSelectedCellInTable.html`.

And now, nobody uses `CellAndIndexes` so that this patch removes it.

Depends on D94239

Differential Revision: https://phabricator.services.mozilla.com/D94240
2020-10-26 05:53:26 +00:00
Masayuki Nakano 624be44b8c Bug 1671556 - part 12: Make `HTMLEditor::GetSelectedOrParentTableElement()` stop using `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_getSelectedOrParentTableElement.html`.

Depends on D94238

Differential Revision: https://phabricator.services.mozilla.com/D94239
2020-10-26 05:24:12 +00:00
Masayuki Nakano 8a7dfed0fd Bug 1671556 - part 11: Make `HTMLEditor::GetSelectedCellsType()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Depends on D94236

Differential Revision: https://phabricator.services.mozilla.com/D94238
2020-10-26 05:06:59 +00:00
Masayuki Nakano 7a6b5b722c Bug 1671556 - part 10: Make `HTMLEditor::JoinTableCells()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Unfortunately, there is no automated tests for `nsITableEditor.joinTableCells()`
and it'll take a couple of days to write its testcase because of too big
method.  And it's not so important for Firefox (although it's used in
comm-central).  Therefore, this patch skips to check it.

Note that `CellAndIndexes` uses `HTMLEditor::GetFirstSelectedTableCellElement()`
to retrieve first selected cell element and then, it retrieves its indexes.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#4090,4098,4109
Therefore, this patch makes it stop using this simple structure too.

Depends on D94235

Differential Revision: https://phabricator.services.mozilla.com/D94236
2020-10-26 05:04:51 +00:00
Edgar Chen 0c7b507968 Bug 1653457 - Enable editor/libeditor/tests/test_bug1151186.html on fission and cross-origin; r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D94677
2020-10-24 23:25:27 +00:00
Masayuki Nakano 379413947b Bug 1671556 - part 9: Make `HTMLEditor::DeleteSelectedTableRowsWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_deleteTableRow.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94235
2020-10-24 04:14:03 +00:00
Masayuki Nakano c159d456cd Bug 1671556 - part 8: Make `HTMLEditor::DeleteSelectedTableColumnWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_deleteTableColumn.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94234
2020-10-24 04:13:55 +00:00
Masayuki Nakano c3e66c2cd1 Bug 1671556 - part 7: Make `HTMLEditor::DeleteTableCellContentsWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This is tested by `test_nsITableEditor_deleteTableCellContents.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94233
2020-10-24 04:13:43 +00:00
Masayuki Nakano b757a23d31 Bug 1671556 - part 6: Make `HTMLEditor::DeleteTableCellWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
This method is tested by `test_nsITableEditor_deleteTableCell.html`.

Differential Revision: https://phabricator.services.mozilla.com/D94232
2020-10-24 04:13:30 +00:00
Masayuki Nakano d8a219bbef Bug 1671556 - part 5: Make `HTMLEditor::HandleDeleteSelection()` stop using `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D94231
2020-10-24 04:13:17 +00:00
Masayuki Nakano 055932a8ee Bug 1671556 - part 4: Make `HTMLEditor::HTMLWithContextInserter::Run()` stop using `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato
Although it's not tested yet, but I have no idea how to test it.
https://coverage.moz.tools/#revision=latest&path=editor%2Flibeditor%2FHTMLEditorDataTransfer.cpp&view=file&line=545

Differential Revision: https://phabricator.services.mozilla.com/D94230
2020-10-24 04:13:04 +00:00
Masayuki Nakano 8165ffcad7 Bug 1671556 - part 3: Make `HTMLEditor::SetHTMLBackgroundColorWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D94229
2020-10-24 04:12:51 +00:00
Masayuki Nakano d57d81d139 Bug 1671556 - part 2: Replace `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` with `nsITableEditor.getSelectedCells()` r=m_kato
`nsITableEditor.getFirstSelectedCell()` and
`nsITableEditor.getNextSelectedCell()` use `HTMLEditor::mSelectedCellIndex`
via their internal methods.  That makes these API unstable if mutation happens
between the calls.  Therefore, it's really simpler and stabler that there is
an API to return selected table cell elements once.

Therefore this patch creates new API, `nsITableEditor.getSelectedCells()`,
which returns array of selected table cell elements.  And it stops taking
inconsistent behavior of the old API:
1. Even if there is no selection. it does not throw an exception.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#3956-3961
2. Even if it meets selection range in a text node (i.e.,
`nsRange::GetChildAtStartOffset()` returns `nullptr`), this just ignores the
range.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#4041-4047

The following patches will remove their internal methods too.

Differential Revision: https://phabricator.services.mozilla.com/D94228
2020-10-24 04:12:38 +00:00
Masayuki Nakano f450442d99 Bug 1671556 - part 1: Make `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` stop returning selected range with out argument r=m_kato
These APIs are used only in comm-central (not in BlueGriffon) and nobody
refers the out argument which is selected range of the cell selection.
Therefore, we should drop them to make the APIs simpler.

Differential Revision: https://phabricator.services.mozilla.com/D94226
2020-10-24 04:12:15 +00:00
Masayuki Nakano 4482ff7eab Bug 1669479 - part 1: Make `WSRunScanner::TextFragmentData::GetNonCollapsedRangeInTexts()` stop searching text node when given range is collapsed r=m_kato
This is a simple mistake.  If the given range is collapsed, scanning text node
to before/after from collapsed range may create reversed range.

Differential Revision: https://phabricator.services.mozilla.com/D94225
2020-10-24 04:11:56 +00:00
Bogdan Tara da1098d4aa Backed out 10 changesets (bug 1654103, bug 1672023, bug 1518999) for PanZoomControllerTest.touchEventForResult gv-junit failures CLOSED TREE
Backed out changeset ff3fb0b4a512 (bug 1672023)
Backed out changeset e7834b600201 (bug 1654103)
Backed out changeset 807893ca8069 (bug 1518999)
Backed out changeset 13e6b92440e9 (bug 1518999)
Backed out changeset 8b2ac5a6c98a (bug 1518999)
Backed out changeset 575748295752 (bug 1518999)
Backed out changeset 65f07ce7b39b (bug 1518999)
Backed out changeset 4bb80556158d (bug 1518999)
Backed out changeset 8ac8461d7bd7 (bug 1518999)
Backed out changeset e8ba13ee17f5 (bug 1518999)
2020-10-24 03:36:18 +03:00
Ricky Stewart c0cea3b0fa Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-23 20:40:42 +00:00
Henri Sivonen 4362f51641 Bug 1666300 part 2 - Parse into an inert document. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D93478
2020-10-23 12:48:52 +00:00
Mihai Alexandru Michis f0df85d472 Backed out 4 changesets (bug 1671556, bug 1669479) for causing bustages in HTMLEditUtils.h
CLOSED TREE

Backed out changeset 17405d242d1b (bug 1671556)
Backed out changeset fe3735c5aac9 (bug 1671556)
Backed out changeset 585df60d18f9 (bug 1671556)
Backed out changeset e94d989b8cb4 (bug 1669479)
2020-10-23 15:10:04 +03:00
Masayuki Nakano e3ee32aed5 Bug 1671556 - part 3: Make `HTMLEditor::SetHTMLBackgroundColorWithTransaction()` stop using `HTMLEditor::Get(First|Next)SelectedTableCellElement()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D94229
2020-10-23 10:51:20 +00:00
Masayuki Nakano d115dc42a4 Bug 1671556 - part 2: Replace `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` with `nsITableEditor.getSelectedCells()` r=m_kato
`nsITableEditor.getFirstSelectedCell()` and
`nsITableEditor.getNextSelectedCell()` use `HTMLEditor::mSelectedCellIndex`
via their internal methods.  That makes these API unstable if mutation happens
between the calls.  Therefore, it's really simpler and stabler that there is
an API to return selected table cell elements once.

Therefore this patch creates new API, `nsITableEditor.getSelectedCells()`,
which returns array of selected table cell elements.  And it stops taking
inconsistent behavior of the old API:
1. Even if there is no selection. it does not throw an exception.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#3956-3961
2. Even if it meets selection range in a text node (i.e.,
`nsRange::GetChildAtStartOffset()` returns `nullptr`), this just ignores the
range.
https://searchfox.org/mozilla-central/rev/61728de8273c04fe2417c475fc0637e8b79210d7/editor/libeditor/HTMLTableEditor.cpp#4041-4047

The following patches will remove their internal methods too.

Differential Revision: https://phabricator.services.mozilla.com/D94228
2020-10-23 10:51:13 +00:00
Masayuki Nakano 0b038d0a0b Bug 1671556 - part 1: Make `nsITableEditor.getFirstSelectedCell()` and `nsITableEditor.getNextSelectedCell()` stop returning selected range with out argument r=m_kato
These APIs are used only in comm-central (not in BlueGriffon) and nobody
refers the out argument which is selected range of the cell selection.
Therefore, we should drop them to make the APIs simpler.

Differential Revision: https://phabricator.services.mozilla.com/D94226
2020-10-23 10:51:08 +00:00
Masayuki Nakano fdd3d5b1af Bug 1669479 - part 1: Make `WSRunScanner::TextFragmentData::GetNonCollapsedRangeInTexts()` stop searching text node when given range is collapsed r=m_kato
This is a simple mistake.  If the given range is collapsed, scanning text node
to before/after from collapsed range may create reversed range.

Differential Revision: https://phabricator.services.mozilla.com/D94225
2020-10-23 10:51:05 +00:00
Razvan Maries b4044e05f9 Backed out 3 changesets (bug 1666300, bug 1667113) for perma failures on browser_parsable_css.js. CLOSED TREE
Backed out changeset 29c5257d0a06 (bug 1667113)
Backed out changeset 0f0fc78ad521 (bug 1666300)
Backed out changeset 9b0c50269ef7 (bug 1666300)
2020-10-22 14:04:15 +03:00
Henri Sivonen 8439bf4064 Bug 1666300 part 2 - Parse into an inert document. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D93478
2020-10-19 13:42:31 +00:00
Dorel Luca 1ff59cb7a3 Backed out changeset 7558c8821a07 (bug 1654103) for multiple failures. CLOSED TREE 2020-10-22 03:51:06 +03:00
Ricky Stewart 50762dacab Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-21 21:27:27 +00:00
Masayuki Nakano 04027a5656 Bug 1607131 - Make `beforeinput` event for `MozEditableElement.setUserInput()` not cancelable by default r=smaug
Blink and WebKit do not fire `beforeinput` event when user uses build-in
password manager and autocomplete.  But the `inputType` value for this case,
`"insertReplacementText"` is defined as cancelable in the spec, and it's
actually cancelable when it's fired for correcting a word with built-in
spellchecker of them.

For making only our users' autocomplete and password manager not blocked by
web apps, we should make them not cancelable by default, but I think that we
should keep dispatching such non-cancelable `beforeinput` for conforming to
the standard unless we'd get a web-compat report for this.

Differential Revision: https://phabricator.services.mozilla.com/D93206
2020-10-20 00:13:43 +00:00
Kagami Sascha Rosylight 2c5fb988f2 Bug 1615296 - Part 2: Fix MOZ_CAN_RUN_SCRIPT warnings in editor module r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D93599
2020-10-15 19:12:44 +00:00
Masayuki Nakano 049c973fbf Bug 1671197 - Make `HTMLEditor::SelectAllInternal()` select all children of `<body>` element if computed selection root is an ancestor of the `<body>` element r=m_kato
In strictly speaking, we should shrink selection ranges at very first time
of edit action handling.  However, we support multiple selection ranges and
it makes the check cost really expensive, and the code would be really
complicated since ranges cannot be overlapped.  I.e., changing one range
could affect some of the others.

Therefore, this patch changes `HTMLEditor::SelectAllInternal()` instead.
If computed selection root is an ancestor of `<body>` element in HTML document,
it use the `<body>` element instead.

Note that, in HTML document, there should be only one `<body>` element and
only its content should be editable at least for now.  (Note that in XHTML
document, no `<body>` is allowed, multiple `<body>` elements allowed.)

Differential Revision: https://phabricator.services.mozilla.com/D93712
2020-10-16 09:38:56 +00:00
Masayuki Nakano 053daa2052 Bug 1627924 - Make `HTMLEditor::HideGrabberInternal()` reset dragging state r=emilio
When the grabber to move absolutely positioned element is disabled,
`HTMLEditor::HideGrabberInternal()` is called to delete it.  However,
it does not reset dragging state.  Therefore, `mousemove` event listener
will try to handle drag even after the grabber is removed.

This patch makes `HideGrabberInternal()` reset the dragging state to
make the event listener stop handling the drag action.

However, I hit a buggy assertion in `EventStateManager`.  It tries to
set active state to parent of the grabber (in this case, absolutely positioned
element).  However, editable element in `contenteditable` cannot have
active state.  Therefore, `leaf` becomes `nullptr`, but `newleaf` is the
absolutely positioned element.  Therefore, this patch adds this condition
into the `MOZ_ASSERT`.

Differential Revision: https://phabricator.services.mozilla.com/D93632
2020-10-16 02:34:15 +00:00
Magnus Melin 53d4e1215b Bug 1649005 - fix crash when rewrapping an empty message via mozilla::HTMLEditor::InsertTextWithQuotationsInternal. r=masayuki
If empty input, aStringToInsert.First() will crash at https://searchfox.org/mozilla-central/rev/c2e3ac11be4837718c2604e58085fbc8252b69dd/xpcom/string/nsTSubstring.cpp#968

Needed to adjust whether rewrap needs beforeinput handling:
NeedsBeforeInputEventHandling would return false, because rewrap was set not to need that
https://searchfox.org/mozilla-central/rev/803b368879fa332e8e2c1840bf1ec164f7ed2c32/editor/libeditor/EditorBase.h#1152
.. so EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent would assert

rewrap also needs to be allowed for MayEditActionDeleteSelection (not to assert)

Differential Revision: https://phabricator.services.mozilla.com/D93167
2020-10-14 12:55:00 +00:00
Razvan Maries 5d8ff793a4 Backed out changeset c7cca3c4602b (bug 1649005) for perma failures on EditorBase.cpp. CLOSED TREE 2020-10-12 14:55:29 +03:00
Magnus Melin 336b9a62fd Bug 1649005 - fix crash when rewrapping an empty message via mozilla::HTMLEditor::InsertTextWithQuotationsInternal. r=masayuki
If empty input, aStringToInsert.First() will crash at https://searchfox.org/mozilla-central/rev/c2e3ac11be4837718c2604e58085fbc8252b69dd/xpcom/string/nsTSubstring.cpp#968

Differential Revision: https://phabricator.services.mozilla.com/D93167
2020-10-12 11:11:55 +00:00
Masayuki Nakano 498c3f96b9 Bug 1668134 - part 3: Add telemetry probes to collect how percentage of `HTMLEditor` is or is not handled with `beforeinput` event listeners r=smaug data-review=tdsmith
Unfortunately, there is no official way to detect whether browser supports
or not `beforeinput` event in the wild because Chromium does not support
`onbeforeinput` event handler attribute.  On the other hand, we're the
last browser vendor which does not support `beforeinput` event, and we
make `InputEvent.getTargetRanges()` enabled only when `beforeinput` event
because it returns meaningful value only when the event type is `beforeinput`.
So, web apps can detect `beforeinput` event support with checking type of
or existence of it instead.  However, in our experience, it's guessed what
a lot of web apps check whether "Firefox" or not to consider whether it
can use `beforeinput` events.  If so, we need to announce shipping
`beforeinput` event and the way to feature detection before actually shipping
it.  Otherwise, we wouldn't get enough feedback from testers.

First of all for shipping `beforeinput` events, we should collect how much
web apps which use `HTMLEditor` use `beforeinput` event when it's enabled,
and how much web apps use mutation events or mutation observer instead of
`beforeinput` events even when it's enabled.

Honestly, I'd like to collect URLs which don't use `beforeinput` event, but
use mutation events or mutation observer.  But it's really sensitive data
so that I believe that we shouldn't collect it.

Differential Revision: https://phabricator.services.mozilla.com/D92548
2020-10-09 23:54:19 +00:00
Masayuki Nakano 0f46ae6a8e Bug 1668134 - part 2: Make `nsPIDOMWindowInner` have an API to know whether a node is (was) in the window has been observed by web apps with a mutation observer r=smaug
There is similar API in `Document`, but they indicate whether a node has been
observed by any mutation receiver, not only by `MutationObserver` of JS.
However, I'd like to know the percentage of web apps which use
`MutationObserver`, but not use `beforeinput` events.  Therefore, this patch
adds similar API into `nsPIDOMWindowInner` as same as `beforeinput` and
ignores `MutationObserver`s which are created by chrome script and addons.

Differential Revision: https://phabricator.services.mozilla.com/D92547
2020-10-08 02:25:35 +00:00
Masayuki Nakano 8c5fa85517 Bug 1668134 - part 1: Make `nsPIDOMWindowInner` have an API to know whether the window or its descendants has had `beforeinput` event listeners r=smaug
When `HTMLEditor` instances are destroyed, I'd like to collect how much
instances are worked with `beforeinput` event listeners.  Before adding such
telemetry probe, this patch adds methods to set/get whether a `beforeinput`
event listener has had added or not to `nsPIDOMWindowInner`.

Differential Revision: https://phabricator.services.mozilla.com/D92546
2020-10-08 02:25:35 +00:00
Masayuki Nakano 2fde14a338 Bug 1623918 - part 2: Mark `nsINode::GetSelectionRootContent()` and its root callers as `MOZ_CAN_RUN_SCRIPT` as far as possible r=smaug
This patch tries to mark root callers of `nsINode::GetSelectionRootContent()`
which calls `nsINode::GetAnonymousRootElementOfTextEditor()` as far as possible
(and reasonable).

It's used by `ContentEventHandler` so that a lot of methods of
`EventStateManager`, `ContentEventHandler`, `IMEContentObserver` which are main
users of it are also marked as `MOZ_CAN_RUN_SCRIPT`.  I think that this is
reasonable.

On the other hand, it might not be reasonable to mark `IMEStateManager` methods
as `MOZ_CAN_RUN_SCRIPT` for initializing `IMEContentObserver` because
`IMEStateManager` may be able to initialize `IMEContentObserver` asynchronously
and its root callers are in XUL layout code.  Therefore, this patch uses
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for `IMEStateManager` at least for now.

Differential Revision: https://phabricator.services.mozilla.com/D92730
2020-10-09 02:37:47 +00:00
Mirko Brodesser 6ef121943b Bug 1639972: don't insert a node in `InsertNodeIntoProperAncestorWithTransaction` when there's no proper ancestor. r=masayuki
The previous behavior was added in bug 858918. However, it was wrong
when trying to insert a `<tr>` into a `<div contenteditable>`.

After this change, the test in bug 858918 still passes, so that specific
functionality doesn't break. However, the code is complex and one can't
exclude that other functionality breaks. The previous fix already
mentioned the same concern
https://bugzilla.mozilla.org/show_bug.cgi?id=858918#c25.

With this change,
https://searchfox.org/mozilla-central/rev/35245411b9e8a911fe3f5adb0632c3394f8b4ccb/editor/libeditor/HTMLEditorDataTransfer.cpp#938
doesn't insert the `<tr>`, but climbs up the `<tr>`'s ancestors, so that
a `<table>` is inserted. When `designMode = "on"`, this was already
previously the case.

The new code seems more correct, including pasting tables to
`contenteditable` elements working now. Therefore, it seems worth
submitting this patch, despite being unable to exclude regressions by
pure reasoning.

Differential Revision: https://phabricator.services.mozilla.com/D92590
2020-10-08 14:44:44 +00:00
Narcis Beleuzu c163b394ef Backed out 2 changesets (bug 1623918) for crashtest failure on 1623918.html CLOSED TREE
Backed out changeset 519ca1b069e5 (bug 1623918)
Backed out changeset d8a09a5fea47 (bug 1623918)
2020-10-08 12:06:58 +03:00
Masayuki Nakano da386ef224 Bug 1623918 - part 2: Mark `nsINode::GetSelectionRootContent()` and its root callers as `MOZ_CAN_RUN_SCRIPT` as far as possible r=smaug
This patch tries to mark root callers of `nsINode::GetSelectionRootContent()`
which calls `nsINode::GetAnonymousRootElementOfTextEditor()` as far as possible
(and reasonable).

It's used by `ContentEventHandler` so that a lot of methods of
`EventStateManager`, `ContentEventHandler`, `IMEContentObserver` which are main
users of it are also marked as `MOZ_CAN_RUN_SCRIPT`.  I think that this is
reasonable.

On the other hand, it might not be reasonable to mark `IMEStateManager` methods
as `MOZ_CAN_RUN_SCRIPT` for initializing `IMEContentObserver` because
`IMEStateManager` may be able to initialize `IMEContentObserver` asynchronously
and its root callers are in XUL layout code.  Therefore, this patch uses
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for `IMEStateManager` at least for now.

Differential Revision: https://phabricator.services.mozilla.com/D92730
2020-10-08 03:56:51 +00:00
Simon Giesecke 59dd6d410d Bug 1668757 - Fix lifetime extension issues with 0-length literals. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D92179
2020-10-06 15:03:01 +00:00
Masayuki Nakano ec2e1c9705 Bug 1669133 - Get rid of pref to disable `text` event in the default group and telemetry for it r=smaug
The telemetry probe was added in bug 1506434, and it's not necessary anymore
because of the event in the default group was completely disabled in
bug 1288640 (Gecko 65).

Therefore, we can get rid of the pref, and we can take back a room for a
bool member in `nsPIDOMWindowInner` for new telemetry probes which need
to know whether a specific event listener has been added or not.

Depends on D92395

Differential Revision: https://phabricator.services.mozilla.com/D92397
2020-10-05 11:17:17 +00:00
Timothy Nikkel 223e9bb630 Bug 1667612. Factor waitToClearOutAnyPotentialScrolls out from various tests and put it in apz_test_utils.js. r=kats
Differential Revision: https://phabricator.services.mozilla.com/D92318
2020-10-03 15:58:16 +00:00
Masayuki Nakano 49a0527874 Bug 1609291 - Make `AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent()` stop returning error when there is no proper event target of `beforeinput` event r=smaug
`editor/libeditor/tests/test_bug974309.html` and
`editor/libeditor/tests/test_bug1268736.html` start to throw exception if
`beforeinput` event is enabled.  They test XPCOM editor API when a non-editable
element has focus and it's outside of any editing hosts.  In this case,
we shouldn't throw an exception for backward compatibility.  Although the
all callers should stop handling any edit action in this case, let's make
`MaybeDispatchBeforeInputEvent()` return a special success code instead of
an error code for making all callers keep working with traditional paths.

Differential Revision: https://phabricator.services.mozilla.com/D91864
2020-10-01 09:15:19 +00:00
Masayuki Nakano ad49c80971 Bug 1609291 - Fix new failure of `test_bug430392.html` when `beforeinput` is enabled r=smaug
If `beforeinput` event is enabled, the assertion count hitting in
`WSRunScanner::GetEditableBlockParentOrTopmotEditableInlineContent()` becomes 0.
The reason is, `AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent()`
gets `nullptr` as the result of `HTMLEditor.GetInputEventTargetElement()`.
Then, it returns error and every edit action handlers stop handling it.
However, for the main purpose of `beforeinput`, i.e., overriding browsers'
default action, we need to dispatch `beforeinput` event even in such case.
(I.e., web apps may want to do something around the non-editable node.)

Therefore, this patch makes `HTMLEditor.GetInputEventTargetElement()` scan
editing host by itself if `HTMLEditor.GetActiveEditingHost()` returns `nullptr`
due to non-editable focus node.  And also make `test_bug430392.html` check
whether `beforeinput` events and `input` events are fired as expected.

I think that I should add new WPT to check nested editing host cases for
considering `beforeinput` and `input` event target, but I'd like to do it
in another bug for shipping `beforeinput` in Nightly channel as soon as
possible.

Differential Revision: https://phabricator.services.mozilla.com/D91863
2020-10-01 09:15:06 +00:00
Mirko Brodesser 96caedd514 Bug 1665645: add missing `requestFlakyTimeout` call to "editor/libeditor/tests/test_CF_HTML_clipboard.html". r=hsivonen
See <https://bugzilla.mozilla.org/show_bug.cgi?id=1665645#c7> for more
context.

Differential Revision: https://phabricator.services.mozilla.com/D90838
2020-09-28 08:13:33 +00:00
Masayuki Nakano a9cd962def Bug 1658702 - part 22: Get rid of wrong `MOZ_ASSERT`s in `WSRunScanner::GetRangeExtendToContainInvisibleWhiteSpacesAtRangeBoundaries()` r=m_kato
If deleting/replacing range selects a text node, it may shrink the range
to start and end of the text node.  So, the result may not be wider than
the original range.

This behavior is compatible with Blink.

Depends on D90639

Differential Revision: https://phabricator.services.mozilla.com/D90640
2020-09-27 06:02:38 +00:00
Masayuki Nakano d3fe79f0e9 Bug 1658702 - part 21 Initialize target ranges for all edit actions which runs `DeleteSelectionAsSubAction()` r=m_kato
A lot of edit actions calls `DeleteSelectionAsSubAction()` if selection is
not collapsed.  In such case, `getTargetRanges()` should return same result
as when the selection range is simply deleted.

This patch creates 2 methods to consider whether `EditAction` causes
running `DeleteSelectionAsSubAction()` with collapsed selection or
non-collapsed selection.

And makes `DeleteSelectionAsAction()` stop initializing the target ranges
itself.  Instead, makes `AutoEditActionDataSetter` do it immediately before
dispatching `beforeinput` event unless it's been already initialized manually.
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditor.cpp#492
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditor.cpp#731
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditorDataTransfer.cpp#503

The correctness of the new utility methods are tested with new `MOZ_ASSERT`
in `DeleteSelectionAsSubAction()`.

Additionally, this reorganizes `input-events-get-target-ranges-*.html`.
* Moving common code into `input-events-get-target-ranges.js`
* Moving non-collapsed selection cases into `input-events-get-target-ranges-non-collapsed-selection.html`
* Adding "typing a" case into the new test for testing this patch's behavior

Depends on D90542

Differential Revision: https://phabricator.services.mozilla.com/D90639
2020-09-27 04:49:41 +00:00
Mirko Brodesser 6726171836 Bug 1649121: part 95) Update `ElementInfo`'s documentation. r=m_kato
Helps understanding the members.

Differential Revision: https://phabricator.services.mozilla.com/D91145
2020-09-24 17:10:48 +00:00
Masayuki Nakano a2893f0106 Bug 1658702 - part 20: Get rid of all `nsIEditor::EStripWrappers` argument from all methods computing target ranges r=m_kato
Currently, target ranges do not extend the ranges even when deleting empty
parent elements of the range.  Therefore, the frag indicating whether empty
parents removed or not is not necessary for the methods.

Differential Revision: https://phabricator.services.mozilla.com/D90542
2020-09-24 12:47:03 +00:00
Masayuki Nakano 83ade05419 Bug 1658702 - part 19: Make `WSRunScanner::GetRangeForDeletingBlockElementBoundaries()` contain preceding invisible `<br>` element at start of joining blocks range r=m_kato
When joining 2 block elements, the left block element may ends with invisible
`<br>` element or the right block element may follows an invisible `<br>`
element if it's a descendant of the left block element.  In those cases, the
invisible `<br>` element must be start of the target range of the joining
block elements since it'll be deleted.

Differential Revision: https://phabricator.services.mozilla.com/D90541
2020-09-24 12:46:45 +00:00
Masayuki Nakano ddc2f11b46 Bug 1658702 - part 18: Implement the path to compute target ranges when deleting around an invisible `<br>` element r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/HTMLEditSubActionHandler.cpp#3431,3450,3459-3489,3511-3517

However, it seems that this is a dead path in most cases because most tests
added by this patch are handled as non-collapsed range deletion.  The
collapsed range is extended by `AutoRangeArray::ExtendAnchorFocusRangeFor()`.

Differential Revision: https://phabricator.services.mozilla.com/D90540
2020-09-24 12:46:22 +00:00
Masayuki Nakano 82f1264243 Bug 1658702 - part 17: Implement the last path to handle non-collapsed ranges deletion r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4812-4825,4839-4850
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4699-4706,4709,4734-4747

Like mentioned in the first link, the logic is completely broken so that this
just follows the broken logic to return actual "affected ranges".

Differential Revision: https://phabricator.services.mozilla.com/D90214
2020-09-24 12:46:15 +00:00
Mirko Brodesser b49443686f Bug 1649121: part 94) Factor adding flavors in best order out. r=m_kato
This clarifies why the flavors are added in a certain order and why
retrieving the first available one is the best one.

Moreover, this enables previously, accidentally disabled
`NS_WARNING_ASSERTIONS`.

Differential Revision: https://phabricator.services.mozilla.com/D90883
2020-09-24 12:38:09 +00:00
Mirko Brodesser 759a716466 Bug 1649121: part 93) Change `aTransferable` to `mTransferable`. r=m_kato
To adhere the style-guide.

Differential Revision: https://phabricator.services.mozilla.com/D90882
2020-09-24 12:37:57 +00:00
Mirko Brodesser 96f3ba77b4 Bug 1649121: part 92) Factor `HTMLTransferablePreparer` out. r=m_kato
Preparing the transferable has the hidden requirement that the order of
the added flavors matters.

This is the preparation for expressing this in code.

`aTransferable` is renamed in the following commit.

Differential Revision: https://phabricator.services.mozilla.com/D90881
2020-09-24 12:39:59 +00:00
Dorel Luca 1e813d19c8 Backed out 3 changesets (bug 1649121) for Build bustage in editor/libeditor/HTMLEditorDataTransfer.cpp. CLOSED TREE
Backed out changeset eedf67df5cde (bug 1649121)
Backed out changeset 081bc411deaf (bug 1649121)
Backed out changeset 4db50381fa96 (bug 1649121)
2020-09-24 14:53:40 +03:00
Mirko Brodesser c3f9a9042c Bug 1649121: part 94) Factor adding flavors in best order out. r=m_kato
This clarifies why the flavors are added in a certain order and why
retrieving the first available one is the best one.

Moreover, this enables previously, accidentally disabled
`NS_WARNING_ASSERTIONS`.

Differential Revision: https://phabricator.services.mozilla.com/D90883
2020-09-23 14:46:20 +00:00
Mirko Brodesser 2a0b5e8022 Bug 1649121: part 93) Change `aTransferable` to `mTransferable`. r=m_kato
To adhere the style-guide.

Differential Revision: https://phabricator.services.mozilla.com/D90882
2020-09-23 14:46:12 +00:00
Mirko Brodesser 87fbdd3f84 Bug 1649121: part 92) Factor `HTMLTransferablePreparer` out. r=m_kato
Preparing the transferable has the hidden requirement that the order of
the added flavors matters.

This is the preparation for expressing this in code.

`aTransferable` is renamed in the following commit.

Differential Revision: https://phabricator.services.mozilla.com/D90881
2020-09-23 14:46:04 +00:00
Simon Giesecke de7bab0f06 Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D82325
2020-09-23 15:17:15 +00:00
Mirko Brodesser cd6abf059e Bug 1649121: part 91) Document some arguments of some `DataTransfer`-related methods. r=m_kato
A step towards making `HTMLEditor::InsertFromDataTransfer`
understandable.

Differential Revision: https://phabricator.services.mozilla.com/D90689
2020-09-23 08:15:21 +00:00
Mirko Brodesser bd154d5816 Bug 1649121: part 90) Declare some editor methods `const` or `static`. r=m_kato
Simplifies reasoning about them.

Differential Revision: https://phabricator.services.mozilla.com/D90688
2020-09-22 16:03:55 +00:00
Nicholas Nethercote 3d3e201817 Bug 1665258 - Shrink `CSSEquivTable`. r=heycam
Better field packing reduces it from 48 bytes to 40 bytes on 64-bit.

This reduces the memory used by each process by 336 bytes on 64-bit.

Differential Revision: https://phabricator.services.mozilla.com/D90344
2020-09-23 01:08:21 +00:00
Simon Giesecke c8ed33ab9d Bug 1665850 - Remove specifics for reference error types from mozilla::Result. r=emilio,jandem
Also update the documentation on optimizations and representation to
better reflect the current situation.

Differential Revision: https://phabricator.services.mozilla.com/D90662
2020-09-21 13:14:28 +00:00
Simon Giesecke 2e065c64d6 Bug 1665614 - Make mozilla::Result work with non-copyable/non-param error types. r=emilio,jandem
Among other things, there were some misuses of std::forward, and
GenericErrorResult was (presumably accidentally) instatiated with
references as the template argument type, e.g. const nsresult&,
which circumvented the check for not calling it with NS_OK in
ResultExtensions.h

Differential Revision: https://phabricator.services.mozilla.com/D90561
2020-09-21 13:12:48 +00:00
Simon Giesecke f193981fb7 Bug 1665850 - Remove specifics for reference error types from mozilla::Result. r=emilio,jandem
Also update the documentation on optimizations and representation to
better reflect the current situation.

Differential Revision: https://phabricator.services.mozilla.com/D90662
2020-09-21 11:09:09 +00:00
Simon Giesecke 3b0420646e Bug 1665614 - Make mozilla::Result work with non-copyable/non-param error types. r=emilio,jandem
Among other things, there were some misuses of std::forward, and
GenericErrorResult was (presumably accidentally) instatiated with
references as the template argument type, e.g. const nsresult&,
which circumvented the check for not calling it with NS_OK in
ResultExtensions.h

Differential Revision: https://phabricator.services.mozilla.com/D90561
2020-09-21 10:38:19 +00:00
Sylvestre Ledru ec8859e69e Bug 1519636 - Reformat recent changes to the Google coding style r=andi
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D90793
2020-09-20 10:14:09 +00:00
Masayuki Nakano 6551ca6994 Bug 1658702 - part 16: Implement `AutoBlockElementsJoiner::ComputeRangesToDeleteContentInRanges()` and `AutoBlockElementsJoiner::ComputeRangesToJoinBlockElementsInSameParent()` r=m_kato
They need to just call
`AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction()` because
their corresponding methods calls `EditorBase::DeleteRangesWithTransaction()`
and do additional different jobs after that, but the they don't affect the
ranges.

* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4602,4627-4628,4639-4642
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4650,4669-4670,4676-4678,4685-4686

Depends on D90212

Differential Revision: https://phabricator.services.mozilla.com/D90213
2020-09-17 08:39:31 +00:00
Masayuki Nakano 3a879cadbe Bug 1658702 - part 15: Implement shortcut case of `AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges()` r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4500-4527

Depends on D90211

Differential Revision: https://phabricator.services.mozilla.com/D90212
2020-09-17 08:30:10 +00:00
Mirko Brodesser 60e705c860 Bug 1649121: part 88) Declare some methods around `DataTransfer` `const`. r=masayuki
Helps reasoning about them.

Differential Revision: https://phabricator.services.mozilla.com/D90528
2020-09-17 08:52:42 +00:00
Masayuki Nakano bddc344c4c Bug 1658702 - part 14: Implement a path to compute target ranges of `EditorBase::DeleteRangesWithTransaction()` r=m_kato
`HTMLEditor` falls back to `EditorBase::DeleteRangesWithTransaction()` in
some cases, especially when handling non-collapsed ranges.  Therefore, we
need to implement it for the following patches.

The code corresponds to:
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3848-3862
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3355,3371,3374,3376,3386-3387,3392
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3421,3431-3432,3435-3436,3444,3453-3455,3464-3465,3473-3474,3477-3478,3486,3495-3497,3506-3507,3515-3520,3526-3528,3535-3538,3543-3544,3546-3549,3558-3562,3570-3572,3579-3580
* https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/DeleteTextTransaction.cpp#34,49-51,59,69-71

Basically, we don't need to touch the ranges, but if `aDirectionAndAmount` is
`nsIEditor::eNext` or `nsIEditor::ePrevious`, each collapsed range is extened
for:
* previous character (treating only surrogate pair)
* next character (treating only surrogate pair)
* selecting another content node

This logic is much rougher than what `AutoDeleteRangesHandler` and its nested
classes do.  So, `HTMLEditor` should stop using it in the future, but we need
to keep using it for now.

Depends on D90210

Differential Revision: https://phabricator.services.mozilla.com/D90211
2020-09-17 08:29:27 +00:00
Mirko Brodesser 6007e4f7d3 Bug 1649121: part 87) Add minimal documentation to `HTMLEditor::ParseCFHTML`. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D90419
2020-09-16 20:17:47 +00:00
Masayuki Nakano c808508f5a Bug 1664741 - Make `AutoBlockElementsJoiner::DeleteNodesEntirelyInRangeButKeepTableStructure()` check whether it deletes a visible content or not before deleting the contents r=m_kato
Oddly, it checks whether it deletes at least one visible thing after deleting
each content from the DOM tree.  It should be done before deleting from the
DOM tree because all text nodes become visible if they are not in the DOM tree
anymore.

Unfortunately, this change does not fix any automated test result, but the
base logic --only when it does not delete any visible things, join the adjacent
block elements-- sounds reasonable.  Therefore, let's take this change.
Note that without this change, cannot compute "affected ranges" of
`getTargetRanges()` in the case running this method later.

Differential Revision: https://phabricator.services.mozilla.com/D90065
2020-09-17 01:45:30 +00:00
Makoto Kato 0a0fc918b8 Bug 1663638 - Don't use edit transaction for editing UI. r=masayuki
Although we use CSS property for Inline table editing UI, we use edit
transaction for it unfortunately. When hiding this UI, since removing
element doesn't use edit transaction, transaction will be canceled before
showing this UI.

It is unnecessary to use edit transaction for UI, so we shouldn't use it.

Differential Revision: https://phabricator.services.mozilla.com/D90056
2020-09-14 05:10:08 +00:00
Masayuki Nakano 969699a0f3 Bug 1658702 - part 12: Implement paths to compute ranges to delete non-collapsed ranges r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#3531-3537
* https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#4443-4561
* https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#2778-2822

Note that the new failure of `input-events-get-target-ranges-forwarddelete.html`
is mismatch between target range (including the trailing white-space) and
actually deleted range (not including the trailing white-space).  Let's
accept this new failure for now since not so important problem and same test
with backspace has same bug.

Differential Revision: https://phabricator.services.mozilla.com/D89870
2020-09-16 10:55:22 +00:00
Masayuki Nakano e09be3fb17 Bug 1664109 - Fix `!=` operator of `EditorDOMRangeBase` r=m_kato
This is causes taking back bugs in
`WSRunScanner::GetNewInvisibleLeadingWhiteSpaceRangeIfSplittingAt()` and
`WSRunScanner::GetNewInvisibleTrailingWhiteSpaceRangeIfSplittingAt()`  (I.e.,
they were fixed by bug 1647556).  Therefore, this removes the odd `if` blocks
which are pointed with `XXX` comment for avoiding "regressions" (without them,
some WPTs for `InputEvents.getTargetRanges()` become failure).

Depends on D89582

Differential Revision: https://phabricator.services.mozilla.com/D89869
2020-09-16 02:17:33 +00:00
Masayuki Nakano a5c5234e6f Bug 1658702 - part 11: Implement a path to compute target ranges when joining 2 blocks from outer block boundary r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#3679-3697
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#2733-2751
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#4286-4302
* https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#4309-4355

`HandleDeleteCollapsedSelectionAtCurrentBlockBoundary()` delete leaf content
of the child block when the block is not joined with current block.  For
doing it, it creates another `AutoDeleteRangesHandler` with collapsing selection
in the child block.  Then, it may refer selection for handling bidi text.
Therefore, the computation code which is added by this patch may modify
selection temporarily for the child `AutoDeleteRangeHandler`.  However, the
selection change shouldn't cause running any scrip (even if chrome script)
because it's required only for this hack.  Therefore, this patch blocks all
notifications and selection change events with `AutoHideSelectionChanges`.
Therefore, this patch marks
`AutoBlockElementsJoiner::ComputeRangesToDeleteAtOtherBlockBoundary()` as
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for using `HTMLEditor::CollapseSelectionTo()`.

Differential Revision: https://phabricator.services.mozilla.com/D89582
2020-09-16 05:36:57 +00:00
longsonr dee8245fe3 Bug 1664788 - rewrite nsEditingSession::SetupEditorOnWindow r=masayuki
Avoid converting strings from UTF16 to ASCII

Differential Revision: https://phabricator.services.mozilla.com/D90092
2020-09-15 14:40:54 +00:00
Masayuki Nakano 620c728792 Bug 1658702 - part 10: Implement a path to compute target ranges when joining 2 blocks from current block boundary r=m_kato
This patch corresponds to:
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#3525-3543
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#2710-2719
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#4140-4165
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#5650-5716
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#97-213
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#218-386
* https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#391-480

In `WSRunObject.cpp`, joining 2 blocks code is split to 3 methods, they are
for:

1. left block element is an ancestor of right block element
2. right block element is an ancestor of left block element
3. left block element and right block element are siblings

The reason why they are split to is, they need to move descendants of child
block element or right block element with different logic.  However, this
difference is not a big problem when we compute target ranges because only
the difference is where we need to check whether there are invisible white-
spaces.  Therefore, this patch creates only a utility method in `WSRunScanner`
and makes `AutoInclusiveAncestorBlockElementsJoiner::ComputeRangesToDelete()`
much simpler than `AutoInclusiveAncestorBlockElementsJoiner::Run()`.

Differential Revision: https://phabricator.services.mozilla.com/D89278
2020-09-11 06:24:08 +00:00
Masayuki Nakano d060d644d6 Bug 1663797 - Make delete handler of `HTMLEditor` not try to join `<html>`, `<head>` and `<body>` r=m_kato
It'll fail to join them when its utility methods actually join them.
However, it should be considered earlier timing because the preparation
DOM tree changes before joining them causes creating odd tree (see the
removed cases of the test).  Therefore, we should make them stop handling
deletion before modifying the DOM tree.

Depends on D89579

Differential Revision: https://phabricator.services.mozilla.com/D89580
2020-09-15 07:33:58 +00:00
Masayuki Nakano 7effeb6cde Bug 1663370 - part 9: Make `AutoInclusiveAncestorBlockElementsJoiner::Prepare()` consider whether it will NOT join the elements or not r=m_kato
This makes `AutoInclusiveAncestorBlockElementsJoiner` stores whether `Run()`
will return "ignored" or not when `Prepare()` is called.  And this patch adds
`NS_ASSERTION()` to compare the result of `Run()` and the guess.

Note that this shouldn't used for considering whether its user call or not
`Run()` actually for the risk of regressions and if we do it with current
implementation, some web apps may be broken if they do modify the DOM tree
at white-space adjustment before joining the left and right block elements.

The method will be used by `ComputeTargetRanges()` which will be implemented
by bug 1658702.

Depends on D89578

Differential Revision: https://phabricator.services.mozilla.com/D89579
2020-09-15 06:07:01 +00:00
Masayuki Nakano 9ed84efbc7 Bug 1663370 - part 8: Make `AutoInclusiveAncestorBlockElementsJoiner::Prepare()` scan preceding invisible `<br>` element r=m_kato
When its `Run()` join the block elements, even if it won't move any content
nodes in first line, it may notify the callers as "handled" when there is a
preceding invisible `<br>` element since it needs to delete it in any cases.
Therefore, whether there is or not a preceding invisible `<br>` element is
important to compute target ranges since if there is one, `Run()` won't return
"ignored" and the callers won't delete leaf content instead.

Note that the new assertions are not hit in any tests, but due to searching
preceding invisible `<br>` element in `Prepare()`, expected assertion
count of 2 tests is increased.

Depends on D89577

Differential Revision: https://phabricator.services.mozilla.com/D89578
2020-09-14 13:35:42 +00:00
Masayuki Nakano 4a6cf53eeb Bug 1663370 - part 7: Make `AutoInclusiveAncestorBlockElementsJoiner::Prepare()` check the relation of its `mLeftBlockElement` and `mRightBlockElement` r=m_kato
The relation is important when the class handles both joining them and computing
target ranges.  Additionally, it's required to consider whether it can join the
block elements.  So, it should store the relation when `Prepare()` is called.

Depends on D89576

Differential Revision: https://phabricator.services.mozilla.com/D89577
2020-09-14 11:40:34 +00:00
Masayuki Nakano da0f19a5f3 Bug 1663370 - part 6: Create a method to check whether `HTMLEditor::MoveOneHardLineContents()` returns "handled" or "canceled" r=m_kato
Unfortunately, `HTMLEditor::MoveOneHardLineContents()`,
`HTMLEditor::MoveChildrenWithTransaction()` and
`HTMLEditor::MoveNodeOrChildrenWithTransaction()` return strict result whether
at least one node is moved or not.  Therefore, we need to scan the DOM tree
whether there is at least one content node which can be moved by them for
computing target ranges.

We cannot do same thing for ``HTMLEditor::MoveOneHardLineContents()` because
it split parent elements first and use `ContentSubtreeIterator` which lists
up topmost nodes which are completely in the range, but we need to compute
target ranges without splitting nodes at the range boundaries.  Therefore,
this patch checks whether the line containing specified point has content
except invisible `<br>` element.

The others are simple.  We can use same logic with them.

Finally, this adds `NS_ASSERTION()`s to check whether the computation is done
correctly at running any automated tests on debug build, and I don't see any
failure with them.

Depends on D89575

Differential Revision: https://phabricator.services.mozilla.com/D89576
2020-09-14 10:54:42 +00:00
Masayuki Nakano 6355f06829 Bug 1663370 - part 5: Make helper methods of `AutoInclusiveAncestorBlockElementsJoiner::Run()` use simple constructor of `EditActionResult` when they return error r=m_kato
When they return error, neither "handled" nor "canceled" state is referred.
So, for making the code simpler, we can make them return
`EditActionResult(NS_ERROR_*)` instead of `EditActionIgnored(NS_ERROR_*)`.

Depends on D89574

Differential Revision: https://phabricator.services.mozilla.com/D89575
2020-09-14 07:25:08 +00:00
Masayuki Nakano f081792788 Bug 1663370 - part 4: Sort out "handled" state settings around `AutoInclusiveAncestorBlockElementsJoiner` users r=m_kato
The 2 of them always mark the edit action as "handled", but it's not important
when it's "canceled" or an error.  Therefore, we can make the users simpler
as this patch does.

Depends on D89573

Differential Revision: https://phabricator.services.mozilla.com/D89574
2020-09-14 05:07:48 +00:00
Masayuki Nakano 0e90b72f58 Bug 1663370 - part 3: Use early-return style when `AutoInclusiveAncestorBlockElementsJoiner::Prepare()` returns `false` r=m_kato
Note that in such cases, current code mark the results as both "canceled" and
"handled", but only "canceled" state is important for the root caller.
* https://searchfox.org/mozilla-central/rev/ac142717cc067d875e83e4b1316f004f6e063a46/editor/libeditor/HTMLEditSubActionHandler.cpp#4200-4204
* https://searchfox.org/mozilla-central/rev/ac142717cc067d875e83e4b1316f004f6e063a46/editor/libeditor/HTMLEditSubActionHandler.cpp#3452-3457
* https://searchfox.org/mozilla-central/rev/ac142717cc067d875e83e4b1316f004f6e063a46/editor/libeditor/HTMLEditSubActionHandler.cpp#3100-3125

Depends on D89572

Differential Revision: https://phabricator.services.mozilla.com/D89573
2020-09-14 03:44:54 +00:00
Masayuki Nakano a87c9efc84 Bug 1663370 - part 2: Move `AutoTrackDOMPoint` for `AutoInclusiveAncestorBlockElementsJoiner::Run()` into the minimum scope r=m_kato
Now, `AutoInclusiveAncestorBlockElementsJoiner::Run()` is wrapped by a
small block in every caller.  Therefore, `AutoTrackDOMPoint` for it can
be moved into the small blocks.

Depends on D89571

Differential Revision: https://phabricator.services.mozilla.com/D89572
2020-09-14 01:36:42 +00:00
Masayuki Nakano c326309928 Bug 1663370 - part 1: Make `AutoInclusiveAncestorBlockElementsJoiner::Prepare()` stop returning `EditActionResult` r=m_kato
For making the refactoring patch simpler, `Prepare()` considers the
`EditActionResult` value of its callers instead.  However, this is odd
so that it just return whether the caller should keep working with
it or not as `bool` result.  Then, for the additional information, whether
the caller should consume the edit action handling or not, this patch
adds a new method, `CanJoinBlocks()`.

Depends on D89440

Differential Revision: https://phabricator.services.mozilla.com/D89571
2020-09-14 01:25:52 +00:00