Commit Graph
141 Commits
Author SHA1 Message Date
Masayuki Nakano 5c667a6c58 Bug 1752093 - Make HTMLEditUtils::Is*() take const nsIContent& as far as possible r=m_kato
In the historical reason, some of them still take `nsINode*`.  In these
days, converting from `nsINode` to `nsIContent` or `Element` is faster
than before and most callers already use `nsIContent`.  Therefore, we
should make them take `const nsIContent&`.

Only some methods, allowing callers use pointer makes them simpler.
Therefore, only some methods have overloads which take
`const nsIContent*` instead.

Differential Revision: https://phabricator.services.mozilla.com/D265525
2025-09-30 01:31:25 +00:00
Cristina Horotan 8bdbf9625e Revert "Bug 1752093 - Make HTMLEditUtils::Is*() take const nsIContent& as far as possible r=m_kato" for causing assertion in nsINode.h
This reverts commit d7a3d6e49b.
2025-09-26 06:41:47 +00:00
Masayuki Nakano d7a3d6e49b Bug 1752093 - Make HTMLEditUtils::Is*() take const nsIContent& as far as possible r=m_kato
In the historical reason, some of them still take `nsINode*`.  In these
days, converting from `nsINode` to `nsIContent` or `Element` is faster
than before and most callers already use `nsIContent`.  Therefore, we
should make them take `const nsIContent&`.

Only some methods, allowing callers use pointer makes them simpler.
Therefore, only some methods have overloads which take
`const nsIContent*` instead.

Differential Revision: https://phabricator.services.mozilla.com/D265525
2025-09-26 01:07:57 +00:00
Masayuki Nakano 5174ec9e34 Bug 1973655 - part 1: Make the editor module not call DOM API to modify the DOM directly r=m_kato
To distinguish whether a DOM modification is expected one or not, we
need to know what the editor is doing and what is expected result by
the mutation.

This patch adds some wrapper classes of DOM API calls and make all
callers of them except the target is very new node which has not been
connected to any DOM.

Differential Revision: https://phabricator.services.mozilla.com/D260587
2025-08-22 10:58:35 +00:00
Cristina Horotan 377e3caa70 Revert "Bug 1973655 - part 3: Add logging code of mutation via HTMLEditor r=m_kato,smaug,dom-core" for causing buuld bustages on HTMLEditorMutationObserver.cpp
This reverts commit 73d1ab198c.

Revert "Bug 1973655 - part 2: Make `HTMLEditorMutationObserver.cpp` r=m_kato"

This reverts commit 8603a23c33.

Revert "Bug 1973655 - part 1: Make the editor module not call DOM API to modify the DOM directly r=m_kato"

This reverts commit a8abe8d84c.
2025-08-22 08:01:45 +00:00
Masayuki Nakano a8abe8d84c Bug 1973655 - part 1: Make the editor module not call DOM API to modify the DOM directly r=m_kato
To distinguish whether a DOM modification is expected one or not, we
need to know what the editor is doing and what is expected result by
the mutation.

This patch adds some wrapper classes of DOM API calls and make all
callers of them except the target is very new node which has not been
connected to any DOM.

Differential Revision: https://phabricator.services.mozilla.com/D260587
2025-08-22 03:30:56 +00:00
Tom Schuster ffeb0d2ce6 Bug 1975392 - More consistently use underscore in StaticAtom identifier. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D255935
2025-07-03 12:26:51 +00:00
Masayuki Nakano 7714f4b009 Bug 1935923 - part 1: Change HTMLEditor::InsertBRElement to InsertLineBreak r=m_kato
For making most callers can insert either `<br>` or a preformatted linefeed,
the inserter should handle both of them.

This patch makes `PrepareToInsertLineBreak` which is renamed from
`PrepareToInsertBRElement` to check whether the container can have the new
line break.  Then, one test starts failing, but it's okay because it's a
test in `<xmp>` which cannot have any elements, so, `<xmp>` is super legacy
element and must not be used in these days especially in editable content.

Differential Revision: https://phabricator.services.mozilla.com/D231656
2024-12-22 01:56:38 +00:00
Alexandru Marc 354231000b Backed out 5 changesets (bug 1935923) for causing build bustages @ EditorLineBreak.h CLOSED TREE
Backed out changeset 7c5e9c2afd3b (bug 1935923)
Backed out changeset 95c8aa202651 (bug 1935923)
Backed out changeset e23ec9a7919d (bug 1935923)
Backed out changeset b3b42030356f (bug 1935923)
Backed out changeset 552b6c2fdc22 (bug 1935923)
2024-12-21 02:38:32 +02:00
Masayuki Nakano 2342800bcd Bug 1935923 - part 1: Change HTMLEditor::InsertBRElement to InsertLineBreak r=m_kato
For making most callers can insert either `<br>` or a preformatted linefeed,
the inserter should handle both of them.

This patch makes `PrepareToInsertLineBreak` which is renamed from
`PrepareToInsertBRElement` to check whether the container can have the new
line break.  Then, one test starts failing, but it's okay because it's a
test in `<xmp>` which cannot have any elements, so, `<xmp>` is super legacy
element and must not be used in these days especially in editable content.

Differential Revision: https://phabricator.services.mozilla.com/D231656
2024-12-20 22:13:43 +00:00
longsonr 4a5a611b4e Bug 1929626 - Remove more uses/includes of nsAlgorithm.h r=emilio,win-reviewers,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D228203
2024-11-07 11:09:40 +00:00
Goloman Adrian 74ec3166cc Backed out changeset fe24b8ac5257 (bug 1929626) for causing build bustages @StackArena.cpp. CLOSED TREE 2024-11-07 01:28:24 +02:00
longsonr 975fd89f6c Bug 1929626 - Remove more uses/includes of nsAlgorithm.h r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D228203
2024-11-06 21:15:52 +00:00
Masayuki Nakano adcad1b5be Bug 1920647 - part 1: Make HTMLEditor won't show Gecko specific editing UI in contenteditable=plaintext-only r=m_kato
Depends on D223277

Differential Revision: https://phabricator.services.mozilla.com/D223669
2024-10-01 04:21:54 +00:00
Tiaan Louw aff0f1c4d5 Bug 1817641 - Convert RGBA to AbsoluteColor for computed/animated/resolved CSS colors r=emilio
Computed color values will not be in the correct format, closer to the
one specified by the author.  This also means that colors accross the
code are stored now as AbsoluteColor or StyleAbsoluteColor.  This allows
color space/gamut information to be available for use.

Some animation related test failures had to be changed, because colors
now has greater precision.  Animated a color now causes a lot more
animation updates, which was not initially expected.  See the bug for
discussion.

Differential Revision: https://phabricator.services.mozilla.com/D171021
2023-03-07 11:28:15 +00:00
Masayuki Nakano fe5e0f086b Bug 1815827 - part 4: Get rid of editor.positioning.offset pref r=m_kato
Depends on D169762

Differential Revision: https://phabricator.services.mozilla.com/D169763
2023-02-21 22:54:25 +00:00
Masayuki Nakano 91d4c3ff9b Bug 1801028 - part 14: Make CSSEditUtils::SetCSSEquivalentToHTMLStyle(With|Without)Transaction take EditorElementStyle r=m_kato
This patch creates a base class of `EditorInlineStyle`, the name is
`EditorElementStyle`.  It requires only attribute of HTML.  However, it's
obviously different from `EditorInlineStyle`'s rule which is `mHTMLProperty`
cannot be `nullptr`.  Therefore, the methods which can treat only
`EditorInlineStyle` do not want the data only whose attribute is not `nullptr`.
For solving this issue at build time, this approach is better than renaming
`EditorInlineStyle` and make it have the new mode.

Depends on D162513

Differential Revision: https://phabricator.services.mozilla.com/D162514
2022-11-25 09:04:35 +00:00
Masayuki Nakano 6a157a88b2 Bug 1793694 - part 1: Move some static inline methods of HTMLEditor to HTMLEditUtils r=m_kato
Depends on D158483

Differential Revision: https://phabricator.services.mozilla.com/D158631
2022-10-12 02:44:17 +00:00
Masayuki Nakano 767307c38d Bug 1791501 - Use EditActionResult as ok type of mozilla::Result r=m_kato
Any callers do not refer "ignored", "handled" and "cancel" state without
checking whether the method returns error or not.  Therefore, error state
can be (and should be) managed by `mozilla::Result`'s error state.

Perhaps, it should store a caret position later because deletion handlers
of `HTMLEditor` use it, but update `Selection` immediately.

Differential Revision: https://phabricator.services.mozilla.com/D158080
2022-09-28 07:21:37 +00:00
Masayuki Nakano 21ac65a3c0 Bug 1791224 - Use CreateNodeResultBase as the ok type of mozilla::Result r=m_kato
Similar to the previous patch, this changes a lot of lines.  However, I think
that it's not so hard to investigate regression point in this patch because
`CreateNodeResultBase` is not used so many times at handling on edit action.

Differential Revision: https://phabricator.services.mozilla.com/D157575
2022-09-28 04:00:19 +00:00
Butkovits Atila b4aaa49444 Backed out changeset 865c5d292958 (bug 1791224) for causing build bustages at Result.h. CLOSED TREE 2022-09-27 11:55:04 +03:00
Masayuki Nakano 099575b4bf Bug 1791224 - Use CreateNodeResultBase as the ok type of mozilla::Result r=m_kato
Similar to the previous patch, this changes a lot of lines.  However, I think
that it's not so hard to investigate regression point in this patch because
`CreateNodeResultBase` is not used so many times at handling on edit action.

Differential Revision: https://phabricator.services.mozilla.com/D157575
2022-09-27 05:12:05 +00:00
Makoto Kato 93b5820110 Bug 1787680 - Part 2. Don't create CSSEditUtils instance. r=masayuki
We can change all methods in `CSSEditUtils` to static method if we add
`HTMLEditor` parameter.

Differential Revision: https://phabricator.services.mozilla.com/D155976
2022-09-01 04:33:36 +00:00
Masayuki Nakano 22625541e2 Bug 1774704 - part 7-1: Make HTMLEditor::EnsureHardLineBeginsWithFirstChildOf and HTMLEditor::EnsureHardLineEndsWithLastChildOf stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152974
2022-08-04 04:19:46 +00:00
Masayuki Nakano fd59099261 Bug 1774704 - part 0: Add automated tests of preserving selection while handling some commands r=m_kato
The following patches touch the logic to restore selection after handling
commands.  However, it seems that they are not tested because I found some
regressions by manual testing, but didn't cause orange on tryserver.

`outdent-preserving-selection.tentative.html` causes a crash due to the
`MOZ_ASSERTION` in `HTMLEditor::HandleOutdentAtSelectionInternal`.  It means
that I misunderstand the logic and had put the assertion.  I should fix it
later with reading the complicated code again.  For now, I just change it
to `NS_WARNING_ASSERTION` instead.

And also `test_cmd_absPos.html` is the first test to check toggling `position`
between `static` and `absolute`.  Therefore, it detects wrong `MOZ_ASSERT`s
which test whether `EditActionData` or `TopLevelEditSubActionData` is created
or not **before** they create them by themselves.  So, this patch removes the
wrong assertions.

Differential Revision: https://phabricator.services.mozilla.com/D152962
2022-08-04 00:21:53 +00:00
Masayuki Nakano 4f89f0e183 Bug 1770877 - part 15: Implement equivalent of HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd r=m_kato
It's always work with `Selection` ranges.  Then, it should be treated within
`AutoRangeArray` which can be initialized with `Selection` ranges automatically.
Then, we can making `HTMLEditor` simpler.

Note tha this tries to make it get editing host when the corresponding
public method is called (after dispatched `beforeinput` event if handling a
users' operation).  However, as commented in
`HTMLEditor::SetParagraphFormatAsAction`, it breaks a tricky crash test.
Therefore, only the format block path computes it after the preparation.

Differential Revision: https://phabricator.services.mozilla.com/D149079
2022-06-17 21:28:36 +00:00
Masayuki Nakano 71411e3fb4 Bug 1771448 - part 4: Rename HTMLEditor::GetActiveEditingHost to ComputeEditingHost r=m_kato
It's currently computes the corresponding editing host from the focus node of
`Selection` with climbing up the DOM tree.  So, it does not just return a stored
element.  Therefore, some callers use it multiple times.  For avoiding it, we
should rename it to explain that it computes the editing host.

Note that I think that we should make it takes a node to compute editing host
without `Selection` for solving the case of no selection ranges.  Therefore,
I don't like to include more information into the name.

Differential Revision: https://phabricator.services.mozilla.com/D147504
2022-05-31 03:41:01 +00:00
Masayuki Nakano 3b9dee039a Bug 1771448 - part 3: Get rid of EditorBase::GetEditorRoot r=m_kato
It returns the anonymous `<div>` element if the instance is a `TextEditor`, and
compute editing host otherwise.  So it's unclear what it returns.  Additionally,
all users except `EditorBase::CreateTransactionForCollapsedRange` are the
methods of `HTMLEditor`.  Therefore, we should remove it and unwrap the code
which it's done.

Differential Revision: https://phabricator.services.mozilla.com/D147503
2022-05-31 03:41:01 +00:00
Masayuki Nakano 6536c89a75 Bug 1771448 - part 2: Get rid of EditorBase::IsDescendantOfEditorRoot r=m_kato
With this patch, there are some odd points.  We should investigate them later...

Differential Revision: https://phabricator.services.mozilla.com/D147502
2022-05-31 03:41:01 +00:00
Emilio Cobos Álvarez e48bb99524 Bug 1771564 - Constify ComputedStyle usage in nsComputedDOMStyle. r=dholbert
None of the consumer need to mutate styles, and this saves some ugly
const_casting on the next patch.

Doesn't change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D147555
2022-05-28 01:04:24 +00:00
Masayuki Nakano e274b4ce87 Bug 1766355 - part 7: Rewrite HTMLEditor::RemoveContainerWithTransaction with MoveNodeTransaction and make it stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146403
2022-05-20 09:01:40 +00:00
Kagami Sascha Rosylight 2b3baf8dfe Bug 1767998 - Apply readability-make-member-function-const on editor/libeditor r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D145626
2022-05-13 05:35:25 +00:00
Masayuki Nakano dfde4fb973 Bug 1762115 - part 10: Make HTMLEditor::InsertBRElement stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144653
2022-05-03 01:03:05 +00:00
Masayuki Nakano 0a637c3bb8 Bug 1742933 - part 4: Make HTMLEditor::CreateAndInsertElementWithTransaction() and HTMLEditor::InsertBRElementWithTransaction() work without transactions r=m_kato
At initializing new element which has not been connected, undo transactions
are not necessary because just removing the new element gets same result for
users.  Therefore, they should be able to work without transactions.

Differential Revision: https://phabricator.services.mozilla.com/D140468
2022-03-11 07:18:48 +00:00
Masayuki Nakano 22aa786ab3 Bug 1753508 - Add logger of selection batch r=smaug
This was required for debugging the bug.

Differential Revision: https://phabricator.services.mozilla.com/D139350
2022-03-11 02:24:24 +00:00
Masayuki Nakano 32e770cf82 Bug 1745882 - Move all editor prefs in all.js to StaticPrefList.yaml r=m_kato
Depends on D133729

Differential Revision: https://phabricator.services.mozilla.com/D133730
2021-12-15 05:17:52 +00:00
Emilio Cobos Álvarez 6c9d03dd32 Bug 1723921 - Cleanup nsComputedDOMStyle and related APIs. r=layout-reviewers,jfkthame
This will make implementing the new behavior behind a pref
really straight-forward, and is generally nicer.

Depends on D121858

Differential Revision: https://phabricator.services.mozilla.com/D121705
2021-08-07 09:47:15 +00:00
Masayuki Nakano c17daaadea Bug 1717178 - part 3: Get rid of nsIHTMLObjectResizer.refreshResizers() because of unused r=m_kato
Depends on D118798

Differential Revision: https://phabricator.services.mozilla.com/D118799
2021-06-28 12:08:49 +00:00
Masayuki Nakano 91df477e8c Bug 1717178 - part 2: Get rid of nsIHTMLAbsPosEditor.refreshGrabber() because of unused r=m_kato
Depends on D118797

Differential Revision: https://phabricator.services.mozilla.com/D118798
2021-06-28 12:08:49 +00:00
Masayuki Nakano cdad85b9f3 Bug 1707630 - part 1: Make HTMLEditor::InsertBREelementWithTransaction() return error when it fails r=m_kato
The testcase hits the assertion because `CreateNodeTransaction::DoTransaction()`
returns error, but it's not handled by `HandledInsertParagraphInParagraph()`
so that we should make `InsertBRElementWithTransaction()` and its callees
should return error if they meet unexpected cases.

Depends on D113471

Differential Revision: https://phabricator.services.mozilla.com/D113472
2021-04-28 03:33:25 +00:00
Andi-Bogdan Postelnicu 5d5d183007 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
Masayuki Nakano 8f1d48aa4e 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
Simon Giesecke ab6f0a7137 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
Makoto Kato eabcd2989f 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 622e0d1a98 Bug 1660378 - part 9: Avoid QI for getting nsStyledElement pointer r=smaug
The editor modules does QI too many times when it sets or removes some style
with `execCommand` or XPCOM API.  Therefore, there should be an API to
retrieve `nsStyledElement` pointer from `nsINode*`.

Differential Revision: https://phabricator.services.mozilla.com/D87990
2020-08-26 05:29:06 +00:00
Masayuki Nakano efd0ef0a03 Bug 1660378 - part 6: Make CSSEditUtils::SetCSSProperty() and its callers take nsStyledElement& instead of Element& r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D87987
2020-08-26 04:48:28 +00:00
Masayuki Nakano cda4f82a28 Bug 1660378 - part 2: Make CSSEditUtils::RemoveCSSPoperty() take nsStyledElement& instead of Element& r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D87983
2020-08-26 04:48:16 +00:00
Masayuki Nakano c9e542c37f Bug 1659276 - Make AutoPlaceholderBatch choose whether do or do not ScrollSelectionIntoView r=m_kato
The root cause of this bug is a bug of async `ScrollSelectionIntoView` that
is what it won't be canceled even if web app changes scroll position with
any API.  Fixing it is really risky and this bug affects an existing website.
Therefore, this patch makes the constructors of `AutoPlaceholderBatch` take
whether do or do not `ScrollSelectionIntoView` when it's destructed.  And
makes `HTMLEditor::SetInlinePropertyAsAction()` not request
`ScrollSelectionIntoView` for taking back the traditional behavior.

Note that this patch does not make it an optional argument because it's hard to
guess that it'll run `ScrollSelectionIntoView` automatically.

Differential Revision: https://phabricator.services.mozilla.com/D87819
2020-08-24 06:39:50 +00:00
Simon Giesecke a69d79b6db Bug 1648010 - Replace uses of NS_LITERAL_STRING/NS_LITERAL_CSTRING macros by _ns literals. r=geckoview-reviewers,jgilbert,agi,hsivonen,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D80860
2020-07-01 08:29:29 +00:00
Olli Pettay f41ed32728 Bug 1637712 - Consider to move *Ancestor* API to nsINode r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D75169
2020-05-20 14:55:15 +00:00