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

11613 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano b779eef044 Bug 1874806 - Get rid of `editor.inline_style.range.compatible_with_the_other_browsers` pref r=m_kato
It was added for safer backout of bug 1792386, but it's shipped in 110. So, the
pref is not necessary anymore.

Differential Revision: https://phabricator.services.mozilla.com/D198660
2024-01-18 03:38:18 +00:00
Masayuki Nakano 85697ec93c Bug 1870960 - Make `IMEStateManager` stop using `nsPresContext::GetTextInputHandlingWidget()` as far as possible r=smaug
If given `nsPresContext` is for a lazy loading `<iframe>` and the frame has not
been loaded yet, its `GetTextInputHandlingWidget()` may return `nullptr`.
However, `IMEStateManager::sTextInputHandlingWidget` may have already cache it.
Therefore, `IMEStateManager` should use:
* `sTextInputHandlingWidget` if it's available
* otherwise, `nsPresContext::GetTextInputHandlingWidget()`

Differential Revision: https://phabricator.services.mozilla.com/D197991
2024-01-16 00:09:35 +00:00
Tooru Fujisawa 2e7027b7a9 Bug 1874595 - Use LF in toml file consistently. r=jmaher,devtools-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D198505
2024-01-15 15:21:53 +00:00
Masayuki Nakano be9d19a50f Bug 1873794 - Make `HTMLEditor::SplitAncestorStyledInlineElementsAt` stop splitting ancestors of non-splittable elements r=m_kato
The method does not assume that an inline ancestor is not a splittable, but
it may occur in the edge cases.

I tried to make `HTMLEditor` adjust selection range at starting deletion to
stop handling it or select the most distant unmodifiable element, but it
 requires some expectation changes of tentative WPTs. It should be done in
a separate bug instead.

Differential Revision: https://phabricator.services.mozilla.com/D198345
2024-01-14 03:08:22 +00:00
Masayuki Nakano 3cd6a5f9b9 Bug 1871987 - Make `Document::ExecCommand` treat first call by addon as a user input r=smaug
`beforeinput` event shouldn't be fired if it's caused by JS.  However, we
dispatch it when the call is by chrome script or an addon because there is
no user input emulation API for WebExtension and builtin editors make the
change undoable only when JS changes the editor value with
`Document.execCommand`.  Therefore, addons may want to use
`Document.execCommand` for making the change undoable.

On the other hand, nested calls of `Document.execCommand` makes the error
handlings in editor classes too complicated.  Therefore, we don't allow that.
However, this causes that if web apps intercept `beforeinput` events and
prevents the default and calls `document.execCommand`, the first call of
web apps may be first nested call if the `beforeinput` event is caused by
a call of `Document.execCommand` in addon.

Therefore, this patch makes `Document` stores whether `ExecCommand` is called
by content or chrome/addon.  And if the call is improperly nested, keep stopping
handling the command, but allows if and only if the first call is by
chrome/addon.

Differential Revision: https://phabricator.services.mozilla.com/D198357
2024-01-14 03:06:25 +00:00
Masayuki Nakano 42cfc5d0be Bug 1872428 - Make `AutoMoveOneLineHandler::Run` explicitly ignore caret position when the destination is removed r=m_kato
The test case removes entire the `<output>` during deleting its content and
that occurs during it moves the content in `<div>` into the preceding `<ruby>`.
Therefore, the destination becomes not connected to the document so that it
fails to track the range of moved contents in the document.

Then, the code does not explicitly mark the caret position is not necessary.
So, we just need to do it.

Differential Revision: https://phabricator.services.mozilla.com/D198148
2024-01-12 07:13:30 +00:00
Jeff Muizelaar a1ee18724c Bug 1853986. Let "Don't translate new lines for IME" ride to release. r=masayuki
This is a minimal version. The corresponding code cleanup will
be done in a follow up.

Differential Revision: https://phabricator.services.mozilla.com/D198045
2024-01-10 18:53:21 +00:00
Masayuki Nakano 5eb33582df Bug 1872422 - Make `HTMLEditUtils::IsNeverElementContentsEditableByUser` return `false` for `<picture>` r=m_kato
Invalid children of `<picture>` like text may appear as usual.  Therefore,
they should be editable.

Note that this patch does not fix the root cause of the assertion because
if selection range may cross a remaining element boundary listed in the
method, but I couldn't find a way to fix this with a reasonable size patch.

Differential Revision: https://phabricator.services.mozilla.com/D197988
2024-01-10 01:37:54 +00:00
Masayuki Nakano b59eed054b Bug 1870962 - Make `HTMLEditor::SplitAncestorStyledInlineElementsAt` never drop the "did split" state from the result r=m_kato
Oddly, it returns the latest result as split result. However, in the case,
it splits `<kbd>` under `<button>`, but does not split `<button>`, but the
caller expects that whether it did split or not.

Differential Revision: https://phabricator.services.mozilla.com/D197262
2023-12-27 02:53:44 +00:00
Masayuki Nakano 627e1f9aff Bug 1870222 - part 6: Make `AutoEmptyBlockAncestorDeleter::ScanEmptyBlockInclusiveAncestor` treat non-editable content as visible r=m_kato
It treats non-editable content as invisible. Therefore, if you try to
delete backward/forward from first/last block, Gecko deletes the block with
the non-editable content.

Depends on D196817

Differential Revision: https://phabricator.services.mozilla.com/D196819
2023-12-25 12:54:08 +00:00
Masayuki Nakano bc25bfb070 Bug 1870222 - part 5: Make `HTMLEditor::ClearStyleAt` treat non-editable content as visible r=m_kato
Pasting and inserting HTML clears current style to respect the new style.
Therefore, the old ancestors shouldn't be removed when they have only
non-editable content.

Unfortunately, I have no idea how to test all of the paths which are changed
by this patch. However, I believe the method should always treat non-editable
content as visible.

Differential Revision: https://phabricator.services.mozilla.com/D196817
2023-12-25 12:54:08 +00:00
Masayuki Nakano 3a1fc63ab7 Bug 1870222 - part 4: Make `HTMLEditor` treat non-editable content as visible when splitting a paragraph r=m_kato
Depends on D196815

Differential Revision: https://phabricator.services.mozilla.com/D196816
2023-12-25 12:54:07 +00:00
Masayuki Nakano 85945dea72 Bug 1870222 - part 3: Make `HTMLEditor::AdjustCaretPositionAndEnsurePaddingBRElement` treat non-editable content as visible r=m_kato
If the parent block has only non-editable, it treat the block as invisible and
puts `<br>`. Therefore, deleting content may cause inserting new line in some
cases.

Depends on D196814

Differential Revision: https://phabricator.services.mozilla.com/D196815
2023-12-25 12:54:07 +00:00
Masayuki Nakano 811e10d8a9 Bug 1870222 - part 2: Make `HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal` treat non-editable things as visible r=m_kato
When it cleans up unnecessary new empty inline ancestors, it should treat
non-editable elements in the inline containers as visible.

Depends on D196813

Differential Revision: https://phabricator.services.mozilla.com/D196814
2023-12-25 12:54:06 +00:00
Masayuki Nakano fa2b298f1a Bug 1870222 - part 1: Rename `HTMLEditUtils::EmptyCheckOption::IgnoreEditableState` with inverting the meaning r=m_kato
It means that "treat non-editable things as visible" when it's not set.
However, it's odd.  You must assume that if no option is set, `IsEmpty()` etc
should treat non-editable nodes as visible things.  Therefore, this renames it
to `TreatNonEditableContentAsVisible` and changing all callers of
`HTMLEditUtils::IsEmptyNode`, `HTMLEditUtils::IsEmptyInlineContainer`,
`HTMLEditUtils::IsEmptyBlockElement` and
`HTMLEditUtils::CollectEmptyInlineContainerDescendants`.  So, this does not
change any behavior.

Differential Revision: https://phabricator.services.mozilla.com/D196813
2023-12-25 12:54:06 +00:00
Masayuki Nakano 5f6299d456 Bug 1764895 - part 3: Get rid of `nsIEditor.setShouldTxnSetSelection` r=m_kato DONTBUILD
It allows multiple edit action preserves `Selection` when updating the DOM tree.
However, most callers do not use `finally` to reset the state, and this makes
edit action handling complicated in some edge cases.  Therefore, let's stop
supporting this feature.  If Thunderbird requires the feature, the developers
should request additional param for preserving `Selection` like the preceding
patch.

Depends on D196004

Differential Revision: https://phabricator.services.mozilla.com/D196005
2023-12-14 00:41:20 +00:00
Masayuki Nakano 05bce4692d Bug 1764895 - part 1: Make `nsIEditor.insertNode` and `nsIEditor.deleteNode` take an optional parameter to preserve selection r=m_kato
`nsIEditor.setShouldTxnSetSelection` can preserve selection across multiple
editing.  Therefore, we cannot manage the state only in the stack.

It's used only in comm-central, and used only with `insertNode` and
`deleteNode`.  Therefore, adding new param to them to preserve selection
must be enough.

While I'm writing this patch, I realized that `input` event is not fired
by these methods because nobody set a placeholder transaction.  That may
lead Thunderbird only IME crash bugs due to `IMEContentObserver` is not
notified editor properly.  Therefore, this may fix some Thunderbird only
crashes.

Note that `deleteNode` should not update selection.  However, I'm not 100%
sure that.  Therefore, I add new param to `deleteNode` too.  However,
some reviewers think it's unnecessary, I'll remove it before landing.

Finally, `beforeinput` and `input` caused by the method calls start updating
selection.  However, I think that it should be better behavior.  If Thunderbird
needs to guarantee that selection is set to whether the user expected when
it calls these methods with preserving selection.

Differential Revision: https://phabricator.services.mozilla.com/D196004
2023-12-13 07:50:42 +00:00
Masayuki Nakano 5e7e437fb9 Bug 1868641 - Make `AutoDeleteRangesHandler::ExtendOrShrinkRangeToDelete` not cross flex-item and grid-item boundary r=m_kato
The text input of the multi-select combobox of Slack has the following
structure:
```
<div contenteditable style="display:flex">
  <span class="c-multi_select_input__space">&nbsp;</span>
  <span class="c-multi_select_input__filter_query">text which you typed</span>
  <span class="c-multi_select_input__space" contenteditable="false">&nbsp;<span>
</div>
```

When you do "Select All", they adjust selection to start from start of the
text container `<span>` (i.e., `.c-multi_select_input__filter_query`).
Then, typing new character deletes selection first.  At this time, in the
legacy mode, `AutoDeleteRangesHandler::ExtendOrShrinkRangeToDelete` does not
extend the deleting range because `<span>` is an inline element.  However,
in the new mode, it extends the range because the `<span>` is a block since
it's a flex-item, and selection starts from current block boundary.  Then,
deleting range starts before the text container.  Finally, Gecko removes the
text container and the following non-editable `<span>`. Therefore, typing text
will be inserted as a child of the flex container which is the editing host.
Finally, Slack restores the previous structure and collapse selection to end
of the text.

Currently, Chrome does same thing for normal blocks without flex/gird container.
However, doing i in `AutoDeleteRangesHandler::ExtendOrShrinkRangeToDelete`
causes a lot of regressions. Therefore, this patch tries to avoid only the bug
in Slack. (I think that we need to redesign the deletion handler to fix it.)

Differential Revision: https://phabricator.services.mozilla.com/D195955
2023-12-13 00:51:01 +00:00
Emilio Cobos Álvarez 88c136af5b Bug 1868552 - Make the initial value of -moz-user-focus normal, and make none actually prevent focusability. r=smaug,jwatt
This is tested via the inert tests, effectively, but I can add more
explicit tests.

Remove rules that would otherwise change behavior (the other rules in
the tree apply to XUL elements and serve a purpose).

Differential Revision: https://phabricator.services.mozilla.com/D195645
2023-12-12 13:51:30 +00:00
Masayuki Nakano 78cd50de20 Bug 1868664 - Make `EditorBase::SetTextDirectionTo` use active editing host if it's an `HTMLEditor` r=m_kato
Chrome handles text direction change as a block level format command.  I.e.,
Chrome sets `dir` attributes of enclosing editable blocks of selected leaf
nodes.  However, aligning to this may require a lot of change and Thunderbird
may require the traditional behavior.

On the other hand, it's obviously wrong thing that `Ctrl` + `Shift` + `X` in an
editable element changes the direction of entire the document since the `<body>`
may not be editable.

Therefore, this patch just changes the direction change target from `<body>`
to active editing host if it's an `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D195838
2023-12-11 15:03:01 +00:00
Masayuki Nakano 6eb2ebcafb Bug 1865729 - part 1: Make `AutoMoveOneLineHandler` make `AutoRangeArray` work with `BlockInlineCheck::UseComputedDisplayOutsideStyle` r=m_kato
`AutoMoveOneLineHandler` uses `AutoRangeArray` API for block level edit
sub-actions.  Therefore, the source line is computed with
`BlockInlineCheck::UseHTMLDefaultStyle`.  However, the deletion handler works
with `BlockInlineCheck::UseComputedDisplayOutsideStyle`.  Therefore,
`AutoMoveOneLineHandler` may try to move different range.  In the reported
test case, it tries to move all content under the `<body>` into the
`<a display="table-header-group">` which is contained in the range.  Therefore,
the `movedContentRange` check fails after the destination becomes into an
orphan node which was removed to move.

This patch renames the API and adds a `BlockInlineCheck` parameter to work
with both ways and makes `AutoMoveOneLineHandler` specify
`BlockInlineCheck::UseComputedDisplayOutsideStyle` as same as the other delete
handlers.

Finally, same thing may happen in
`HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal`.  This patch makes it
check whether the top-level edit sub-action is a block level one or not and
consider `BlockInlineCheck` with the result.

Depends on D194180

Differential Revision: https://phabricator.services.mozilla.com/D194181
2023-11-27 01:46:42 +00:00
Masayuki Nakano 1f8750eb14 Bug 1865729 - part 0: Add logging code of `AutoMoveOneLineHandler` r=m_kato
The class does complicated things and has been reported some assertion failures.
For making the debug faster, let's add the logging code.

Differential Revision: https://phabricator.services.mozilla.com/D194180
2023-11-27 01:46:42 +00:00
Jonathan Watt 15c1a58822 Bug 1866011 p2. Rename nsIDocShell.contentViewer. r=emilio,credential-management-reviewers,devtools-reviewers,sgalich
Differential Revision: https://phabricator.services.mozilla.com/D194370
2023-11-24 09:10:52 +00:00
Jonathan Watt dd64050a07 Bug 1865918 p1. Update HasContentViewer to reflect nsIDocumentViewer's new name. r=emilio
(Snuck in a rename of a similarly named local variable too.)

Differential Revision: https://phabricator.services.mozilla.com/D194287
2023-11-22 13:50:56 +00:00
Jonathan Watt c96a66c3de Bug 1865480. Rename nsIContentViewer to nsIDocumentViewer. r=layout-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D193987
2023-11-21 12:45:59 +00:00
Masayuki Nakano 36504d9a0e Bug 1861231 - Make editor handle user input with original target instead of target r=sefeng,dom-core
In the fallback code for native key bindings and in the inline table handling,
the editor still use `GetDOMEventTarget()` and `IsInUncomposedDoc()` which are
not aware of shadow DOM.

Differential Revision: https://phabricator.services.mozilla.com/D193621
2023-11-21 03:58:01 +00:00
Emilio Cobos Álvarez f27edbd417 Bug 1861730 - Remove transition prefixes from nightly too. r=jwatt
Code like the one from comment 7 seems reasonable. Let's try to disable
prefixed transitions along with prefixed transforms in order to minimize
the compat fallout from CSS zoom.

While I was at it I also fixed the prefixed animation entries in the
property database and crashtests. But those aliases remain enabled.

Differential Revision: https://phabricator.services.mozilla.com/D192129
2023-11-20 12:36:30 +00:00
Cristian Tuns d7102b46e2 Backed out changeset b403bb5b1c83 (bug 1861730) for causing mochitest failures in test_moz_prefixed_properties.html CLOSED TREE 2023-11-19 07:03:19 -05:00
Emilio Cobos Álvarez 0fbcd96216 Bug 1861730 - Remove transition prefixes from nightly too. r=jwatt
Code like the one from comment 7 seems reasonable. Let's try to disable
prefixed transitions along with prefixed transforms in order to minimize
the compat fallout from CSS zoom.

While I was at it I also fixed the prefixed animation entries in the
property database and crashtests. But those aliases remain enabled.

Differential Revision: https://phabricator.services.mozilla.com/D192129
2023-11-19 11:07:57 +00:00
Masayuki Nakano 1a62550191 Bug 1864334 - Make `nsIFrame::MovingCaretToEventPointAllowedIfSecondaryButtonEvent` check whether the right click point is in a selection range first r=emilio
This is a simple mistake of the previous patch. The code path is originally for
a left click handling.  Therefore, there is no check whether the click point is
in a selection range because in that case, left click should collapse selection.
However, the selection should not be collapse when it's a right click in a
selection range because the context menu target is the selection range.

The `ui.mouse.right_click.collapse_selection.stop_if_non_collapsed_selection`
pref is set to `true` by default.  Therefore, the existence of a non-collapsed
selection has hidden this bug.  However, if it's set to `false`, this always
happens.  Additionally, editor does not set ancestor limiter of selection if the
root element is editable [1].  I think that we can now remove this special path,
but it's risky.  Therefore, this patch just adds the new check into the method.

1. https://searchfox.org/mozilla-central/rev/ce4599d3d4e20e34cb6db68f255c3dff1aec246b/editor/libeditor/EditorBase.cpp#5448,5450-5451

Differential Revision: https://phabricator.services.mozilla.com/D193529
2023-11-16 01:26:24 +00:00
Masayuki Nakano 0348ca6476 Bug 1860210 - Make `HTMLEditUtils::GetPreviousEditablePoint` and `HTMLEditUtils::GetNextEditablePoint` check ancestor limiter before getting a sibling of ancestor r=m_kato
They check ancestor limiter when they are climbing up the DOM tree if and only
if the ancestor does not have a sibling.  However, this causes moving into
a sibling of the ancestor limiter.

Differential Revision: https://phabricator.services.mozilla.com/D192528
2023-11-10 01:35:33 +00:00
Masayuki Nakano 4eb06aa944 Bug 1861603 - Make `HTMLEditUtils::IsEmptyNode` refer the computed style r=m_kato
Gecko starts referring computed style to consider whether block or inline and
`HTMLEditUtils::IsEmptyNode` is used with them to check a node like these:
https://searchfox.org/mozilla-central/rev/40d51bef58b8e901d6ab4b60dd280f372a0e417d/editor/libeditor/HTMLEditUtils.h#543,554

However, `IsEmptyNode` still checks only the tag names when the caller wants
to treat "list items" and/or "table cells" are visible (not empty).  Therefore,
this mismatch may cause the assertion failure reported in the bug.

From code design point of view, `HTMLEditUtils::IsListItem` and
`HTMLEditUtils::IsTableCell` should refer the computed style.  However, the
former is mostly used for checking the logical structure of HTML, and in the
latter case, we should keep the table structure even if table cells are styled
as inline because browsers do not support table structure recreation except
the Gecko specific editing UI (called inline table editor).  Therefore, it does
not make sense that we would change them.

Instead, we should change `IsEmptyNode` which is used only for visibility check.
So, using computed style is always reasonable.

Note that this patch changes the behavior in some edge cases.  The method always
treat a list item or a table cell which contains a sub-list or a sub table.
However, I would not like to add new `EmptyCheckOption` for it to check the
complicated style check.  Therefore, this patch changes the behavior to treat
them visible if and only if they have another list item or another table cell.
Basically, `<table>` and list elements should have a least one table cell or
one list item.  Therefore, this change should not appear in the web apps in the
wild.

Differential Revision: https://phabricator.services.mozilla.com/D192442
2023-11-09 00:49:07 +00:00
Masayuki Nakano 197de3d0a2 Bug 1858794 - Make `AutoMoveOneLineHandler` track the new line range while moving content nodes r=m_kato
It moves nodes in a range to new place one by one.  At this time, the moved
position range is not tracked.  Therefore, if the DOM tree is unexpectedly
changed by `HTMLEditor` itself, the range gets broken.  E.g., in this case,
deleting empty inline element causes the range after the source position is
broken.

Differential Revision: https://phabricator.services.mozilla.com/D192180
2023-11-01 01:32:40 +00:00
Divyanshu Agrawal 13347e51bb Bug 1857303 - Fire copy event when pressing Ctrl+C on contenteditable without selection. r=sefeng,masayuki
Differential Revision: https://phabricator.services.mozilla.com/D190402
2023-10-27 18:36:02 +00:00
Masayuki Nakano 7e6da5b9b6 Bug 1859245 - part 4: Make `HTMLEditor` handle only the new direction mode r=m_kato
Depends on D191607

Differential Revision: https://phabricator.services.mozilla.com/D191608
2023-10-27 01:57:29 +00:00
Masayuki Nakano 982ddb7a9a Bug 1859245 - part 3: Make `JoinNodesTransaction` and `SplitNodeTransaction` handle only the new direction mode r=m_kato
Depends on D191606

Differential Revision: https://phabricator.services.mozilla.com/D191607
2023-10-27 01:57:29 +00:00
Masayuki Nakano 22a3483011 Bug 1859245 - part 2: Make `HTMLEditor::DoJoinNodes` and `HTMLEditor::DoSplitNode` handle only the new direction mode r=m_kato
Depends on D191605

Differential Revision: https://phabricator.services.mozilla.com/D191606
2023-10-27 01:57:29 +00:00
Masayuki Nakano 7954ac40cc Bug 1859245 - part 1: Make `JoinNodesResult` and `SplitNodeResult` handle only the new direction mode r=m_kato
Depends on D191604

Differential Revision: https://phabricator.services.mozilla.com/D191605
2023-10-27 01:57:28 +00:00
Masayuki Nakano 539c7a6ffc Bug 1244437 - part 4: Make `HTMLEditor::IsFormatElement` return `false` for `<dl>`, `<dt>` and `<dd>` if it's called for XUL paragraph state command r=m_kato
Now, all callers of them do not require to check `<dl>`, `<dt>` and `<dd>` check
if it's in the HTML format block mode.  Therefore, we can move the check into
`HTMLEditor::IsFormatElement` to make the caller side simpler.

Additionally, this patch replaces some places with
`HTMLEditUtils::IsFormatElementForParagraphState` because the paths handle only
XUL paragraph state command with assertion check.

Depends on D190902

Differential Revision: https://phabricator.services.mozilla.com/D191604
2023-10-26 03:45:18 +00:00
Masayuki Nakano f90663350e Bug 1244437 - part 3: Make `formatBlock` command handlers use replace target as the nearest inclusive ancestor format node r=m_kato
Currently, we extend selection to outside block boundaries if selection starts
and/or ends very start/end of block boundaries.  Then, replace most-distant
ancestor format node, but this is odd because the innermost format is applied
to the text and the other browsers targets the innermost ancestor formant node.
Therefore, we should align to them.

Additionally, our replacing code for `<dd>` and `<dt>` has not been implemented
yet.  I guess that the old `HTMLEditUtils::IsFormatNode` returned `false` for
`<dd>`, `<dl>` and `<dt>` and it requires additional work for splitting parent
`<dl>` too.  Now, we can do it with simple code.

Finally, we created new format block element if `<br>` element appears, but
the other browsers moves it into the new format node simply.  Therefore, we
should follow them (about `<blockquote>`, we've already done this within
the different path).

Differential Revision: https://phabricator.services.mozilla.com/D190902
2023-10-26 03:45:18 +00:00
Masayuki Nakano 58bd165afe Bug 1244437 - part 2: Make `ParagraphStateAtSelection` handle `<dl>`, `<dt>` and `<dd>` elements r=m_kato
`Document.execCommand` accepts `dl`, `dt` and `dd` as a format block.  However,
`ParagraphStateAtSelection` ignores them as not a format block element.
Therefore, it causes odd result of `queryCommandValue` after applying the
format.  E.g., `execCommand("dd")` to `<p>[foobar]</p>` correctly updates the
HTML to `<dl><dd>foobar</dd></dl>`, however, `queryCommandValue("dd")` returns
empty string rather than `dd`.

Note that Chromium returns inclusive ancestor format element of common ancestor
of the range.  However, the behavior is odd because it makes the indeterm
state never `true` and the result is not used as the target of format block
command.  So, this patch does not follow them at least for now.

On the other hand, this patch adds special case for `dl`.  With user's
operation in valid HTML structure, selection range never selects `<dl>`
children directly.  However, may cross `<dt>` and `<dd>` elements.
Then, let's return `dl` for compatibility with Chromium because `<dl>`
ancestor may be the format block target.

Differential Revision: https://phabricator.services.mozilla.com/D190901
2023-10-26 03:45:17 +00:00
Masayuki Nakano e302445217 Bug 1244437 - part 1: Make `HTMLEditUtils::IsFormatNode` check same tags as Chromium does r=m_kato
I realized that our `HTMLEditUtils::IsFormatNode` is not maintained different
from the other browsers.  Therefore, only we do not check new elements defined
after HTML 4.01.  This patch aligns the list of the format elements to the
others [1].

Then, this also changes some expectations of `editing/run/formatblock.html`
to align common behavior of the browsers.

Note that we mapped `formatBlock` of `execCommand` to `cmd_paragraphState`,
and the XUL command handles `<blockquote>` in a different path [2] and the
behavior is pretty different from the other formatBlock command implementations.
Therefore, this patch creates new command for `formatBlock` and makes
`HTMLEditor` switch behavior in any places.

1. ba50f40fc4:third_party/WebKit/WebCore/editing/FormatBlockCommand.cpp;l=114-134
2. https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/editor/libeditor/HTMLEditor.cpp#2461-2474

Differential Revision: https://phabricator.services.mozilla.com/D190900
2023-10-26 03:45:17 +00:00
Ajay 6d291d4cd2 Bug 1859355 - Exit EditorEventListener::HandleEvent early when the event can't be handled r=sefeng
Differential Revision: https://phabricator.services.mozilla.com/D191445
2023-10-24 16:33:03 +00:00
Mark Banner 31a45737c0 Bug 1858673 - Remove now unnecessary disabling of ESLint no-unsanitized/* rules from test files. r=freddyb,media-playback-reviewers,credential-management-reviewers,devtools-reviewers,sessionstore-reviewers,places-reviewers,aosmond,sgalich,dao,padenot
Differential Revision: https://phabricator.services.mozilla.com/D190985
2023-10-24 08:48:41 +00:00
Mark Banner 79b35cfc1b Bug 1858673 - Disable no-unsanitized/method and no-unsanitized/property on test files. r=freddyb
Differential Revision: https://phabricator.services.mozilla.com/D190984
2023-10-24 08:48:40 +00:00
Edgar Chen 00d9c6dd66 Bug 1859834 - Update test_paste_no_formatting.html for headless; r=masayuki
As now headless clipboard supports HTML type after bug 1686012.

Differential Revision: https://phabricator.services.mozilla.com/D191281
2023-10-19 05:14:15 +00:00
Masayuki Nakano 86ce739a04 Bug 1858590 - Make `TextEditor::HandleInsertText` stop handling the command for empty string after deleting selection r=m_kato
The handler has an early-return block for the case inserting empty text.
However, it's done before deleting selection, but it should be done after that.

Differential Revision: https://phabricator.services.mozilla.com/D190904
2023-10-19 03:16:08 +00:00
Edgar Chen 8e9d770444 Bug 1686012 - Make Headless clipboard support the HTML type; r=spohl
Differential Revision: https://phabricator.services.mozilla.com/D191195
2023-10-18 08:15:27 +00:00
Emilio Cobos Álvarez 4eb3dda25e Bug 1859427 - Cache number parsers and formatters per language. r=smaug
This makes number localization cheaper / halves the time in the
microbenchmark.

Change the content-language handling to use atoms. This exposes some
interesting inconsistencies but I tried not to change behavior there.

Differential Revision: https://phabricator.services.mozilla.com/D191174
2023-10-17 11:01:13 +00:00
Sylvestre Ledru d0f6c7fc66 Bug 1856795 - Remove redundant member init r=emilio
Done with:
./mach static-analysis check --checks="-*, readability-redundant-member-init" --fix .

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Differential Revision: https://phabricator.services.mozilla.com/D190002
2023-10-15 15:29:02 +00:00
Cristina Horotan 6a90f5eded Backed out 2 changesets (bug 1856795) for causing build bustage at BasicEvents.h CLOSED TREE
Backed out changeset 1d98b028923a (bug 1856795)
Backed out changeset eae2ac93e17c (bug 1856795)
2023-10-14 21:42:14 +03:00
Sylvestre Ledru cc8a0ee742 Bug 1856795 - Remove redundant member init r=emilio
Done with:
./mach static-analysis check --checks="-*, readability-redundant-member-init" --fix .

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Differential Revision: https://phabricator.services.mozilla.com/D190002
2023-10-14 17:34:26 +00:00
Masayuki Nakano 0b01d23e7a Bug 1728433 - Make `WSScanResult::AssertIfInvalidData` check the ancestor block element if the reason is `CurrentBlockBoundary` r=m_kato
As the comment in the method, `CurrentBlockBoundary` may be set when `mContent`
is not a block.  However, it's not allowed that there is an editable block
ancestor of `mContent` in same editing host (in this case, `mContent` should be
the block).  Therefore, it should compute ancestor block element and check
whether it's not in same editing host if `mContent` is editable and connected.

Differential Revision: https://phabricator.services.mozilla.com/D190644
2023-10-13 02:57:08 +00:00
Tom Marble 0cb91fe33e Bug 1855300 - convert .ini manifests to .toml: batch 11 remaining **/mochitest.ini r=jmaher,geckoview-reviewers,extension-reviewers,valentin,credential-management-reviewers,cookie-reviewers,sgalich,m_kato,robwu
Differential Revision: https://phabricator.services.mozilla.com/D190515
2023-10-13 02:32:24 +00:00
Natalia Csoregi 8a80ae0079 Backed out changeset cf6b9d74c2f9 (bug 1857303) for causing failures on test_contenteditable_copy_empty_selection.html CLOSED TREE 2023-10-10 23:41:46 +03:00
Divyanshu Agrawal 4f93faf815 Bug 1857303 - Fire copy event when pressing Ctrl+C on contenteditable without selection. r=sefeng,masayuki
Differential Revision: https://phabricator.services.mozilla.com/D190402
2023-10-10 16:22:48 +00:00
Noemi Erli e4a13185fe Backed out changeset bf2277419073 (bug 1857303) for causing failures in test_contenteditable_copy_empty_selection.html CLOSED TREE 2023-10-10 18:06:45 +03:00
Divyanshu Agrawal fe85654dff Bug 1857303 - Fire copy event when pressing Ctrl+C on contenteditable without selection. r=sefeng,masayuki
Differential Revision: https://phabricator.services.mozilla.com/D190402
2023-10-10 13:58:35 +00:00
Emilio Cobos Álvarez 25c0d10932 Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.

I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).

Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 08:51:12 +00:00
Jan-Niklas Jaeschke 5005fe0cc5 Bug 1840856: Fixed linefeed/linebreak issues for contenteditable. r=masayuki,dom-core
This patch is related to Bug 1840822, which fixes some issues
regarding additional invisible linebreaks needed at the end of
contenteditables.
This patch in particular fixes the case where the user
presses enter at the end of a pre-formatted
contenteditable, e.g.:
```
<span contenteditable style="display:block;white-space:pre-line">[]</span>
```
Prior to this patch, only one `<br>` was added,
the invisible padding linebreak was missing.
With this patch applied, the behaviour should be as expected:
```
<span contenteditable style="display:block;white-space:pre-line">\n<br></span>
```

Differential Revision: https://phabricator.services.mozilla.com/D190217
2023-10-10 08:38:02 +00:00
Masayuki Nakano bccbdc8b58 Bug 1845241 - Make `nsIFrame::HandleEvent` move caret when secondary mouse button down r=edgar,emilio,dom-core
The other browsers move focus and `Selection` whe right click even if the
clicked element is not editable and even if there is a non-collapsed selection.
Fortunately, we already have similar code for the middle button press.
Therefore, we can make it run when the pressed button is the secondary button.

This also fixes bug 416546 and does not resurrect bug 709476.

However, this patch adds 2 prefs for making users customizable.  Our traditional
behavior is, we never collapse non-collapses selection with a right click even
if clicked outside the selection.  This allows users to open context menu for
selected text much easier.  Therefore, even though the behavior is different
from the others, we should keep the traditional behavior, but some users may
want the other browsers' behavior instead.  For them, this should be switchable
by a pref.

Additionally, I'm still not sure collapsing selection with a right click in
non-editable content especially for users using the caret browsing mode.
Therefore, for making things safer, this adds a pref to disable the new behavior
in the non-editable content.

Differential Revision: https://phabricator.services.mozilla.com/D189991
2023-10-10 03:20:21 +00:00
Masayuki Nakano a56eed4600 Bug 1852849 - Make `HTMLEditor::AutoInlineStyleSetter::ExtendOrShrinkRangeToApplyTheStyle` recompute common ancestor of the range if it updates the range r=m_kato
In this case, `<font face="monospace">abc []<br></font>`, the range applying
new style will be extended as `<font face="monospace">abc [<br>}</font>` first.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#1944

Then, the start point should be shrunken and the range should become
`<font face="monospace">abc {<br>}</font>`.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#1977-1978

However, `commonAncestor` is still the text node because it's not updated
after extending the range to include the `<br>`.  Then,
`AutoInlineStyleSetter::GetNextEditableInlineContent` fails to get `<br>`
from the text node.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#1576-1578

Finally, the unexpected range computation will reach here with the text editor
and adjust the start of the range to start of the text node.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#420-423

Therefore, the new text which the new style should be applied is jumped to
start of the text node.

Differential Revision: https://phabricator.services.mozilla.com/D190028
2023-10-07 05:56:15 +00:00
Masayuki Nakano dc4686ea4d Bug 1849763 - Make `HTMLEditor::HandleInsertBRElement` suggest caret position as at the invisible <br> if inserted r=jjaschke
If `HTMLEditor::HandleInsertBRElement` inserts an invisible `<br>` element
after a `<br>` element which is requested, new caret position should be
at the invisible `<br>` element.

Differential Revision: https://phabricator.services.mozilla.com/D189997
2023-10-04 07:26:57 +00:00
serge-sans-paille 974e37adf9 Bug 1855955 - Remove useless <iostream> includes r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D189648
2023-09-29 14:15:53 +00:00
Jan Varga c458754592 Bug 1855134 - Move existing MOZ_TRY macros to a dedicated header file; r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D189226
2023-09-28 20:46:07 +00:00
Masayuki Nakano ba6d410ac6 Bug 1851951 - Make `HTMLEditUtils::GetElementOfImmediateBlockBoundary` ignore invisible text node r=m_kato
Without this patch, the following test newly fails:
```
/editing/other/insertparagraph-with-white-space-style.tentative.html?white-space=nowrap&command=insertText
  FAIL <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultparagraphseparator: div) - assert_equals: A <br> should be inserted at end expected "abc<br><br>" but got "abc<br>"
  FAIL <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultparagraphseparator: p) - assert_equals: A <br> should be inserted at end expected "abc<br><br>" but got "abc<br>"
```

The reasons is, the inlined editing host is at end of the `<body>`, therefore,
even though the editing host itself is `inline`, it needs a padding `<br>` to
make it the new line visible.

However, `HTMLEditUtils::GetElementOfImmediateBlockBoundary` does not return
`<body>` because the editing host is followed by `<script>` which has
a text node which is not white-spaces only.  Therefore,
`HTMLEditUtils::IsVisibleBRElement` considers the `<br>` element at end of the
editing host is "visible".

Differential Revision: https://phabricator.services.mozilla.com/D188599
2023-09-27 03:01:26 +00:00
Masayuki Nakano 09514edd73 Bug 1851951 - Make `HTMLEditor` refer computed `display` instead of the HTML default style at considering block or inline element r=m_kato
Blink [1] and WebKit [2] refers `display-outside` value when they consider whether an
element is a block or an inline.

However, our editor refers HTML default style instead.  Therefore, our editor
cannot handle the following cases:
* If a container block is a non-HTML element whose `display` style is `block`.
* If a container `<div>` etc is styled as `inline` and typing `Enter` in it.
* If a container `<span>` is styled as `block` and it ends with spaces.

For making users get better result, we should follow the other browsers.

However, this is too risky change.  Therefore, this patch enables new behavior
only in the Nightly channel and early beta builds to collect feedback from
testers.

The big rules of checking block vs. inline are:
* When we handle block level edit actions such as formatting block, indenting
or outdenting selection, making or removing list, we should keep referring
the HTML default style because the other browsers do so and the commands are
intended for modifying the HTML structure.
* Otherwise, we should refer the computed style of the block.  However, if
working with non-connected elements, we may need a special handling that is
falling back to refer the HTML default style because `HTMLEditorDataTransfer`
work with non-connected document fragments.
* Finally, if we check visibility of collapsible white-spaces and `<br>`s, we
should refer computed style.  However, in this case, we may need to treat
ancestor `inline-block`s as block too, but for siblings, we should refer only
`display-outside`.

1. https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/editing_utilities.cc;l=779;drc=31fb07c05718d671d96c227855bfe97af9e3fb20
2. https://searchfox.org/wubkat/rev/b054636fffeffa0314914a11ce39725a3057131e/Source/WebCore/editing/Editing.cpp#317

Differential Revision: https://phabricator.services.mozilla.com/D188598
2023-09-27 03:01:26 +00:00
Joel Maher 99abb50b8d Bug 1853245 - Migrate .ini manifests to .toml (Batch 7.25). r=aryx,webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D189221
2023-09-26 17:40:01 +00:00
Olli Pettay b632508d71 Bug 1843477, remove main thread only CC macros, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D187146
2023-09-26 12:36:20 +00:00
pommicket 03c8c72db9 Bug 1248186 - prevent focus loss at end of [contenteditable] r=masayuki
Adjust nsFocusManager::GetSelectionLocation so that
it never moves the selection outside of the "ancestor limiter".

Differential Revision: https://phabricator.services.mozilla.com/D186864
2023-09-26 07:45:20 +00:00
Cosmin Sabou baf8a5cf23 Backed out 6 changesets (bug 1843477) for causing hazards failures. CLOSED TREE
Backed out changeset 64b093aa12a9 (bug 1843477)
Backed out changeset bdcd84c938d1 (bug 1843477)
Backed out changeset 05c882dd0d9a (bug 1843477)
Backed out changeset 1de814e5820d (bug 1843477)
Backed out changeset 6a0e19a60a5d (bug 1843477)
Backed out changeset 48942aff586f (bug 1843477)
2023-09-26 05:32:28 +03:00
Olli Pettay ce2ffc54c9 Bug 1843477, remove main thread only CC macros, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D187146
2023-09-25 21:09:00 +00:00
Gregory Pappas 4083653f6a Bug 1851097 - Remove layout.css.moz-document.content.enabled pref r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D187349
2023-09-15 18:08:14 +00:00
Gregory Pappas 16301b7fe2 Bug 1842986 - Remove dom.forms.inputmode pref r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D187421
2023-09-15 16:49:21 +00:00
Tom Marble 9e40a719f2 Bug 1850545 - convert .ini manifests to .toml: batch 3 chrome.ini (bis) r=jmaher,geckoview-reviewers,extension-reviewers,credential-management-reviewers,devtools-reviewers,fxview-reviewers,places-reviewers,profiler-reviewers,m_kato,mak,mtigley
Differential Revision: https://phabricator.services.mozilla.com/D187597
2023-09-13 18:28:32 +00:00
Cosmin Sabou 2b53f8d322 Backed out 3 changesets (bug 1843477) for causing hazards failures on TelemetryFixture.cpp. CLOSED TREE
Backed out changeset 4dd5d8ac600c (bug 1843477)
Backed out changeset e7bc0b63286a (bug 1843477)
Backed out changeset 4f45f40beaf7 (bug 1843477)
2023-09-08 20:21:46 +03:00
Olli Pettay d7c56b8b4f Bug 1843477, remove main thread only CC macros, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D187146
2023-09-08 14:51:48 +00:00
Makoto Kato ef2a0ed90f Bug 1851105 - Use nsAString as parameter for WordBreaker::FindWord. r=TYLin
It is better to use nsAString rather than using pointer directly.

Differential Revision: https://phabricator.services.mozilla.com/D187256
2023-09-08 04:35:38 +00:00
Emilio Cobos Álvarez cc72d328af Bug 1851641 - Fix hiding cursor while typing. r=masayuki
This didn't work properly for non-native key bindings because:

  https://hg.mozilla.org/mozilla-central/rev/8934e6e6ccb6

Moved the DetachedFromEditorOrDefaultPrevented() check before the "hide
cursor" check, rather than after. This was a quick fix, because if we're
detached from the editor, then GetPresContext would assert. But I didn't
realize at the time (since it was a long time since I wrote the patch)
that most events there actually are default-prevented.

To fix this, split the checks. Checks for DetachedFromEditor() first,
and only after potentially hiding the cursor check whether the event is
default-prevented.

Differential Revision: https://phabricator.services.mozilla.com/D187536
2023-09-06 14:01:53 +00:00
Masayuki Nakano 2947020013 Bug 1846997 - Get rid of the tasks checking the legacy join/split direction mode of editor r=m_kato,jmaher,taskgraph-reviewers,gbrown,webdriver-reviewers,jgraham
The new join/split node direction mode seems working well in the wild because
we have no regression reports about it.  Therefore, we won't revert the pref
anymore, thus, the legacy mode behavior check is not required.

Differential Revision: https://phabricator.services.mozilla.com/D186680
2023-09-05 02:21:31 +00:00
Masayuki Nakano 40990b50cf Bug 1850910 - Make `WhiteSpaceVisibilityKeepers::DeleteContentNodeAndJoinTextNodesAroundIt()` return caret point correctly r=m_kato
It returns the result of
`MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange()`, but it suggests
caret position only when it modifies the DOM tree since it does not take the
default caret position.

So, `DeleteContentNodeAndJoinTextNodesAroundIt()` does need to return
`aCaretPoint` with tracking it during DOM mutations if
`MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange()` does not
suggest caret point.

I found this bug when I was trying to fix the unexpected failing of
forward delete at end of the last block in the editing host (bug 1850666)
because changing the error handling anyway cause another error at this line.
https://searchfox.org/mozilla-central/rev/bdd5b85b56885cd48bd91d262647e0d3499b3a27/editor/libeditor/HTMLEditorDeleteHandler.cpp#1652

Therefore, without fixing bug 1850666, I have no idea how to check this fix.

Differential Revision: https://phabricator.services.mozilla.com/D187196
2023-09-05 01:08:59 +00:00
Jeff Muizelaar 7e5a2fc8be Bug 1850819 - Let "Don't translate new lines for IME" ride into early beta. r=masayuki
This lets bug 1838355 (a5a62ea631e5) ride into early beta.

Differential Revision: https://phabricator.services.mozilla.com/D187141
2023-08-31 18:34:30 +00:00
Emilio Cobos Álvarez 124ea3bca7 Bug 1757463 - Avoid getting a pres context when detached from the editor.
MANUAL PUSH: Trivial orange fix CLOSED TREE
2023-08-31 01:21:04 +02:00
Emilio Cobos Álvarez 6fd7a45c30 Bug 1757463 - Implement hide cursor while typing at the DOM+Editor level. r=handyman,masayuki
This only hides the cursor if it's on the page you're editing, but given
that the point of the feature is to move the cursor out of the way, that
seems acceptable (and honestly it feels more of a feature than a bug).

This should work across platforms (though non-windows platforms need
ui.hideCursorWhileTyping=1 in about:config to enable).

Differential Revision: https://phabricator.services.mozilla.com/D171155
2023-08-30 16:50:26 +00:00
Emilio Cobos Álvarez 33968f7c4e Bug 1850293 - Make editable states not intrinsic. r=smaug,masayuki
This one is tricky because form controls, though I think I got it right...

This fixes a pre-existing bug where we're not following the spec for readonly
inside content-editable.

I filed this as bug 1850390 but other browsers match the spec so add a test and
fix it while at it. This allows cheaper checks for readonlyness in a couple
places.

Differential Revision: https://phabricator.services.mozilla.com/D186896
2023-08-30 09:18:31 +00:00
Emilio Cobos Álvarez f9e14a4261 Bug 1539720 - Annotate new reftests as failing with drawSnapshot.
MANUAL PUSH: Orange fix CLOSED TREE
2023-08-23 14:00:28 -04:00
Emilio Cobos Álvarez e15bc40faf Bug 1539720 - Fix caret overflow adjustment computations. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D186366
2023-08-23 16:28:06 +00:00
Masayuki Nakano 81624b1310 Bug 1849080 - Make `HTMLEditor::MaybeCreatePaddingBRElementForEmptyEditor()` start a top level edit sub-action when it considers to modify the DOM tree r=m_kato
It does nothing in most cases because it inserts a `<br>` element only when
the editable `<body>` does not have meaningful content.  Therefore, we can
make it put off to create `AutoEditSubActionNotifier` to save the cost of
some expensive things done by `OnStartToHandleTopLevelEditSubAction()` and
`OnEndHandlingTopLevelEditSubAction()`.

Differential Revision: https://phabricator.services.mozilla.com/D186514
2023-08-23 08:34:33 +00:00
Masayuki Nakano 8224e1138c Bug 1840519 - Make typing surrogate pair behavior switchable with prefs r=m_kato,smaug
A lone surrogate should not appear in `DOMString` at least when the attribute
values of events because of ill-formed UTF-16 string.

`TextEventDispatcher` does not handle surrogate pairs correctly. It should not
split surrogate pairs when it sets `KeyboardEvent.key` value for avoiding the
problem in some DOM API wrappers, e.g., Rust-running-as-wasm.

On the other hand, `.charCode` is an unsigned long attribute and web apps
may use `String.fromCharCode(event.charCode)` to convert the input to string,
and unfortunately, `fromCharCode` does not support Unicode character code
points over `0xFFFF`.  Therefore, we may need to keep dispatching 2 `keypress`
events per surrogate pair for the backward compatibility.

Therefore, this patch creates 2 prefs.  One is for using single-keypress
event model and double-keypress event model.  The other is for the latter,
whether `.key` value never has ill-formed UTF-16 or it's allowed.

If using the single-keypress event model --this is compatible with Safari and
Chrome in non-Windows platforms--, one `keypress` event is dispatched for
typing a surrogate pair.  Then, its `.charCode` is over `0xFFFF` which can
work with `String.fromCodePoint()` instead of `String.fromCharCode()` and
`.key` value is set to simply the surrogate pair (i.e., its length is 2).

If using the double-keypress event model and disallowing ill-formed UTF-16
--this is the new default behavior for both avoiding ill-formed UTF-16 string
creation and keeping backward compatibility with not-maintained web apps using
`String.fromCharCode`--, 2 `keypress` events are dispatched.  `.charCode` for
first one is the code of the high-surrogate, but `.key` is the surrogate pair.
Then, `.charCode` for second one is the low-surrogate and `.key` is empty
string.  In this mode, `TextEditor` and `HTMLEditor` ignores the second
`keypress`.  Therefore, web apps can cancel it only with the first `keypress`,
but it indicates the `keypress` introduces a surrogate pair with `.key`
attribute.

Otherwise, if using the double-keypress event model and allowing ill-formed
UTF-16 --this is the traditional our behavior and compatible with Chrome in
Windows--, 2 `keypress` events are dispatched with same `.charCode` values as
the previous mode, but first `.key` is the high-surrogate and the other's is
the low surrogate.  Therefore, web apps can cancel either one of them or
both of them.

Finally, this patch makes `TextEditor` and `HTMLEditor` handle text input
with `keypress` events properly.  Except in the last mode, `beforeinput` and
`input` events are fired once and their `data` values are the surrogate pair.
On the other hand, in the last mode, 2 sets of `beforeinput` and `input` are
fired and their `.data` values has only the surrogate so that ill-formed
UTF-16 values.

Note that this patch also fixes an issue on Windows.  Windows may send a high
surrogate and a low surrogate with 2 sets of `WM_KEYDOWN` and `WM_KEYUP` whose
virtual keycode is `VK_PACKET` (typically, this occurs with `SendInput` API).
For handling this correctly, this patch changes `NativeKey` class to make it
just store the high surrogate for the first `WM_KEYDOWN` and `WM_KEYUP` and use
it when it'll receive another `WM_KEYDOWN` for a low surrogate.

Differential Revision: https://phabricator.services.mozilla.com/D182142
2023-08-23 01:16:59 +00:00
Cosmin Sabou 99faeda407 Backed out 2 changesets (bug 1539720) for causing caret related failures. CLOSED TREE
Backed out changeset a6a541637edd (bug 1539720)
Backed out changeset 970525aa04f1 (bug 1539720)
2023-08-17 14:16:49 +03:00
Emilio Cobos Álvarez e278cf26ab Bug 1539720 - Fix caret overflow adjustment computations. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D186366
2023-08-17 10:06:10 +00:00
Jan-Niklas Jaeschke 09be4ee8df Bug 1840822, part 3: Don't add a second line break if between block element and end of editing host. r=masayuki,dom-core
This patch deals with this case:
```
<span contenteditable><div>foo</div>[]</span>
```
In this case only one `<br>` should be added since one
line break is already added because of the `<div>` block.

Differential Revision: https://phabricator.services.mozilla.com/D185935
2023-08-16 09:34:50 +00:00
Jan-Niklas Jaeschke df8b4a288b Bug 1840822, part 2: Add an invisible line break at the end of a contenteditable for `InsertLineBreak` case. r=masayuki,dom-core
The logic behind this patch is similar to that of part 1, only that this covers the case where a user triggers a line break instead of a new paragraph (i.e. by pressing [Shift/cmd]+[Enter]).
If the inserted BR element is followed by a block boundary, another BR element is added.

Depends on D182339

Differential Revision: https://phabricator.services.mozilla.com/D182485
2023-08-16 09:34:50 +00:00
Jan-Niklas Jaeschke 9a0cf05339 Bug 1840822, part 1: Add an invisible line break at the end of a contenteditable for `insertParagraph` case. r=masayuki,dom-core
If a user presses <Enter> to add a new paragraph at the end of a contenteditable, a second (invisible) line break has to be added:
`<span contenteditable>foo[]</span>` --> `<span contenteditable>foo<br><br></span>`

This patch deals with contenteditables which do not preformat whitespaces
(i.e. should insert linebreaks, not linefeeds).
The linefeed cases are handled in Bug 1840856.
Also this patch only deals with a code path that uses `insertParagraph`.
The code path that uses `InsertLineBreak` is handled in part 2 of this Bug.

The patch implements a lambda function that inserts a second `<br>` element,
which is called in two situations:
1. The editing host is empty:
  `<span contenteditable>[]</span>`--> `<span contenteditable><br><br></span>`
2. The caret is at a block boundary:
  `<span contenteditable>abc[]</span>` --> `<span contenteditable>abc<br><br></span>`

Differential Revision: https://phabricator.services.mozilla.com/D182339
2023-08-16 09:34:50 +00:00
Sean Feng 4379a8876c Bug 1848409 - Tweak the UpdateDefaultPreventedOnContent call to only special case the HTMLEditorEventListener case r=masayuki,dom-core
Calling `UpdateDefaultPreventedOnContent` separately from
`PreventDefault()` is error-prone. This patch should make it
safer.

Differential Revision: https://phabricator.services.mozilla.com/D186052
2023-08-15 13:46:42 +00:00
Masayuki Nakano c204c013dd Bug 1845215 - part 1: Make `ContentIteratorBase` a template class to work without strong pointers r=smaug
`ContentEventHandler` works with `PostContentIterator` and `PreContentIterator`
when it scans DOM nodes in a range.  While iterating the DOM nodes, script
never runs.  Therefore, we can make `ContentEventHandler` work with new
content iterators which do not store nodes with strong pointers.

This patch makes `ContentIteratorBase` a template class and create new
`UnsafePostContentIterator` and `UnsafePreContentIterator`.  They will
check whether DOM mutation or GC occurs before destruction to detect dangerous
regressions.

Differential Revision: https://phabricator.services.mozilla.com/D184441
2023-08-10 00:59:28 +00:00
CanadaHonk a117230132 Bug 1824121 - Implement the <search> element r=hsivonen,Jamie,emilio
Implemented the new <search> HTML element.
All WPT tests for it now pass (except one for iso-8859-8, not done generally).

A11y role uses just landmark as recommended instead of a new search role (for now).

Co-authored-by: Henri Sivonen <hsivonen@mozilla.com>

Differential Revision: https://phabricator.services.mozilla.com/D176967
2023-08-07 22:11:05 +00:00
Stanca Serban 183a888a39 Backed out 3 changesets (bug 1824121) for causing wpt failures in html5lib_search-element.html. CLOSED TREE
Backed out changeset e3aec91d79e4 (bug 1824121)
Backed out changeset e3a3324b1732 (bug 1824121)
Backed out changeset 6ff5c272ab8e (bug 1824121)
2023-08-07 21:20:18 +03:00
Cosmin Sabou c3bb54bb28 Bug 1824121 - Fix assertion on HTMLEditUtils.cpp. a=test-fix CLOSED TREE 2023-08-07 18:11:19 +03:00
Makoto Kato 7a484e97aa Bug 1719535 - Part 10.2. Update test results of editor with new segmenter. r=masayuki
Depends on D180774

Differential Revision: https://phabricator.services.mozilla.com/D180775
2023-08-07 06:24:01 +00:00