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

452 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano 4cc133b568 Bug 1627175 - part 2: Move `EditorBase::IsModifiableNode()`, `EditorBase::IsEditable()`, `EditorBase::IsTextElementOrText()` and `EditorBase::IsPaddingBRElementForEmptyEditor()` to `EditorUtils` r=m_kato
Due to the include hell, `EditorBase.h` cannot include `EditorUtils.h`.
Therefore we need these 3 methods once.  Additionally, `IsModifiableNode()`
is really odd method and looks like that it's used for the following 2 purposes:
1. Simply can be editable.
2. Can be removed from parent.

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

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

Depends on D70874

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

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

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

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

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

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

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

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

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

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

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

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

Additionally, this patch fixes some argument name and type.

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

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

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

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

Additionally, this patch fixes some argument name and type.

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

--HG--
extra : moz-landing-system : lando
2020-04-08 13:32:28 +00:00
Chris Peterson 589528cb8d Bug 1625834 - Replace MOZ_MUST_USE with [[nodiscard]] in editor. r=masayuki
Also move MOZ_MUST_USE before function declarations' specifiers and return type. While clang and gcc's __attribute__((warn_unused_result)) can appear before, between, or after function specifiers and return types, the [[nodiscard]] attribute must precede the function specifiers.

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

--HG--
extra : moz-landing-system : lando
2020-04-02 05:43:31 +00:00
Masayuki Nakano 72cf6dc13d Bug 1624011 - Make constructor of `AlignStateAtSelection` not assert when there is no selection ranges r=m_kato
`AlignStateAtSelection` class is instantiated outside of editor class so that
we shouldn't make each user guarantee that there is selection range
(fortunately, the putting off cost is really low).

And as far as I tested, Blink and WebKit does not throw exception when
`Document.qeuryCommand*("justify*")` is called without selection ranges.
So, this patch also prevents exception in this situation.

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

--HG--
extra : moz-landing-system : lando
2020-04-01 06:38:16 +00:00
Arthur Iakab 7e869be20c Backed out changeset 5e89020502f7 (bug 1625834) for causing build bustages
CLOSED TREE
2020-04-01 04:32:11 +03:00
Chris Peterson b469a9d9db Bug 1625834 - Replace MOZ_MUST_USE with [[nodiscard]] in editor. r=masayuki
Also move MOZ_MUST_USE before function declarations' specifiers and return type. While clang and gcc's __attribute__((warn_unused_result)) can appear before, between, or after function specifiers and return types, the [[nodiscard]] attribute must precede the function specifiers.

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

--HG--
extra : moz-landing-system : lando
2020-03-30 06:45:40 +00:00
Masayuki Nakano 74a2dd84e9 Bug 1620504 - part 22-8: Clean up warnings in HTMLStyleEditor.cpp r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D67130

--HG--
extra : moz-landing-system : lando
2020-03-19 12:48:42 +00:00
Masayuki Nakano 87dc9fcfe5 Bug 1620504 - part 22-1: Clean up warnings in `HTMLEditor.cpp` and `HTMLEditor.h` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D66979

--HG--
extra : moz-landing-system : lando
2020-03-18 02:02:17 +00:00
Masayuki Nakano 9c836ea324 Bug 1620504 - part 12: Clean up warnings in EditorEventListener r=m_kato
Depends on D65877

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

--HG--
extra : moz-landing-system : lando
2020-03-10 07:54:29 +00:00
Simon Giesecke dd65843b46 Bug 1613985 - Use default for equivalent-to-default constructors/destructors in editor. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D65287

--HG--
extra : moz-landing-system : lando
2020-03-04 09:10:03 +00:00
Masayuki Nakano f5407e4219 Bug 1616257 - part 3: Make `WSRunScanner::NextVisibleNode()` and `WSRunScanner::PriorVisibleNode()` return stack only class instance which storing the visible node as `nsIContent` r=m_kato
They are really messy because they take a lot of out parameters, and these
out parameter meaning is really unclear.  Therefore, they should return
a stack only class instance which explain the meaning with getter methods.
And also it should store the result node as `nsIContent`.

And also this patch adds static methods for them for their users which don't
need `WSRunScanner` instance.

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

--HG--
extra : moz-landing-system : lando
2020-02-25 12:10:04 +00:00
Makoto Kato 1aadd31886 Bug 1359404 - Make IsEmptyNode infaillible. r=masayuki
IsEmptyNode won't return error if parameter is not null. So we shouldn't use
nserror for return value and use assertion to check parameter.

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

--HG--
extra : moz-landing-system : lando
2020-02-19 05:37:13 +00:00
Masayuki Nakano 58a034fe7d Bug 1588688 - part 8: Make `HTMLEditor::DoInsertHTMLWithContext()` and its helper methods use array of `nsIContent` rather than `nsINode` r=m_kato
Finally, this patch makes `HTMLEditor::DoInsertHTMLWithContext()` stop using
array of `nsINode`.

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

--HG--
extra : moz-landing-system : lando
2020-02-14 07:16:27 +00:00
Masayuki Nakano 839d86eece Bug 1588688 - part 7-10: Make `ReplaceOrphanedStructure()` call `CollectListAndTableRelatedElementsAt()` by itself r=m_kato
For guaranteeing the meaning of `aArrayOfListAndTableRelatedElements`,
`ReplaceOrphanedStructure()` should call
`CollectListAndTableRelatedElementsAt()` by itself rather than taking as
a parameter.

Then, what it does becomes a little bit clearer.  Therefore, this patch renames
`ReplaceOrphanedStructure()` to `EnsureBeginsOrEndsWithValidContent()` and
`DiscoverPartialListsAndTables()` to `GetMostAncestorListOrTableElement()`,
and adds a lot of comments.

As far as I've tested by my hand, the behavior is not changed even though
it's really buggy in some cases.  We should fix them after writing automated
tests in another bug.

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

--HG--
extra : moz-landing-system : lando
2020-02-14 05:40:37 +00:00
Masayuki Nakano d389b66f9c Bug 1588688 - part 7-9: Make `ReplaceOrphanedStructure()` call `DiscoverPartialListsAndTables()` by itself r=m_kato
For guaranteeing the meaning of list or `<table>` element in
`ReplaceOrphanedStructure()`, it should call `DiscoverPartialListsAndTables()`.
Then, their meaning becomes clearer than coming from its parameter.

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

--HG--
extra : moz-landing-system : lando
2020-02-14 03:27:16 +00:00
Masayuki Nakano 7656ed2a64 Bug 1588688 - part 7-8: Encapsulate the first and last node fixer into a stack only class r=m_kato
In these patches, we know that there are a lot of helper methods to fix node
list which is created by `SubtreeContentIterator` and will be inserted into
the editor's DOM tree, and they are not used by other places.  So, we can
encapsulate them into a stack only class for making their usage clearer.

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

--HG--
extra : moz-landing-system : lando
2020-02-14 02:59:32 +00:00
Masayuki Nakano 55963fc5b9 Bug 1588688 - part 7-7: Clean up `HTMLEditor::ReplaceOrphanedStructure()` r=m_kato
Unfortunately, even with this cleaning up, I don't understand what it does
because existing comment and what actually it does seem different.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 09:06:44 +00:00
Masayuki Nakano 784573927c Bug 1588688 - part 7-6: Clean up `HTMLEditor::DiscoverPartialListsAndTables()` r=m_kato
`HTMLEditor::DiscoverPartialListsAndTables()` can be static and we can make
its definition simpler.  However, due to the odd logic, I'm still not sure
what it does.  I'll update it after cleaning up its result user,
`HTMLEditor::ReplaceOrphanedStructure()`.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 08:42:22 +00:00
Masayuki Nakano 817ac3e98e Bug 1588688 - part 7-5: Clean up `HTMLEditor::CreateListOfNodesToPaste()` r=m_kato
`HTMLEditor::CreateListOfNodesToPaste()` can be static and it does not need to
take `DocumentFragment` as an argument if the range is always specified.
For avoiding 2 input path to specify a range, we should make it take only
range boundaries and array of nodes to return the collected nodes.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 04:49:43 +00:00
Masayuki Nakano 3887f29cbc Bug 1588688 - part 7-4: Clean up `HTMLEditor::GetListAndTableParents()` r=m_kato
It can be a static method and does not make sense taking array of nodes as
input argument because it refers only first or last node of the array.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 02:56:25 +00:00
Masayuki Nakano 58164b1ddf Bug 1588688 - part 7-3: Clean up `HTMLEditor::ScanForTableStructure()` r=m_kato
The name does not explain what it does.  Additionally, it should be same style
as `HTMLEditor::IsReplaceableListElement()` for making it easier to understand.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 02:55:53 +00:00
Masayuki Nakano 12ce2b955c Bug 1588688 - part 7-2: Pick list element handling part of `HTMLEditor::ScanForListAndTableStructure()` up r=m_kato
`HTMLEditor::ScanForListAndTableStructure()` is complicated because it has
2 modes, one is for handling list element, the other is for handling table
element.  This patch splits them as 2 methods.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 02:55:20 +00:00
Masayuki Nakano 382f61920c Bug 1588688 - part 7-1: Sort out `HTMLEditor::ScanForListAndTableStructure()` r=m_kato
Helper methods of `HTMLEditor::DoInsertHTMLWithContext()` which uses array of
`nsINode` is really messy and we can make them simpler.  This is first
preparation of a series of refactoring patches of them.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 02:54:47 +00:00
Masayuki Nakano ed10bfc397 Bug 1588688 - part 6: Make `HTMLEditor::CollapseAdjacentTextNodes()` use array of `dom::Text` rather than `nsINode` r=m_kato
`HTMLEditor::CollapseAdjacentTextNodes()` collects editable text nodes first so
that the array can be array of `dom::Text`.  Additionally, using
`DOMSubtreeIterator` instead of `ContentSubtreeIterator` makes the code easier
to understand.

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

--HG--
extra : moz-landing-system : lando
2020-02-13 02:54:45 +00:00
Masayuki Nakano 20807215a4 Bug 1588688 - part 3: Make `HTMLEditor::CollectEditTargetNodes()` and its users use array of `nsIContent` rather than `nsINode` r=m_kato
Unless editor needs to treat document node, all nodes are sub-class of
`nsIContent`.  Therefore, we can make `HTMLEditor::CollectEditTargetNodes()`
return array of `nsIContent` instead of array of `nsINode`.

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

--HG--
extra : moz-landing-system : lando
2020-02-12 05:52:30 +00:00
Masayuki Nakano 450b71f763 Bug 1612085 - part 1: Hide constructor of `nsRange` r=smaug
`nsRange` instances are allocated a lot in the heap especially by editor and
spellchecker.  The allocation cost is too bad for benchmarks.  Therefore,
we should reuse released instances as far as possible.  For managing it in
static factory methods of `nsRange`, we need to hide `nsRange` constructor.

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

--HG--
extra : moz-landing-system : lando
2020-01-30 13:23:35 +00:00
Masayuki Nakano f506f1f653 Bug 1611751 - Remove unused scriptable methods of `nsIHTMLEditor`, `nsIEditorStyleSheets` and `nsITableEditor` r=m_kato
* `nsIHTMLEditor.removeAllInlineProperties`
* `nsIHTMLEditor.increaseFontSize`
* `nsIHTMLEditor.decreaseFontSize`
* `nsIHTMLEditor.setParagraphFormat`
* `nsIHTMLEditor.getBackgroundColorState`
* `nsIHTMLEditor.indent`
* `nsIHTMLEditor.align`
* `nsIEditorStyleSheets.replaceOverrideStyleSheet`
* `nsITableEditor.selectBlockOfCells`

These methods are not used by any Gecko products including comm-central and
BlueGriffon so that we should remove them.  Note that only
`HTMLEditor::GetBackgroundColorState()` is used internally so that we need to
keep it as a public method of `HTMLEditor`.

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

--HG--
extra : moz-landing-system : lando
2020-01-30 08:50:41 +00:00
Masayuki Nakano 7c8295ee19 Bug 1609629 - Make `HTMLEditor::BlobReader` handle `DataTransfer` correctly r=smaug
When file is dropped on `contenteditable` element, the data is `BlobImpl`
instance in e10s mode.  Then, editor tries to insert asynchronously with its
`BlobReader`.  However, currently, `BlobReader` does not have a reference of
`DataTransfer` object for setting `beforeinput` event and `input` event.
Therefore, when you drop file into `contenteditable` element on debug build,
you see hitting `MOZ_ASSERT` because of unexpected null `DataTransfer` object.

This patch makes it store `DataTransfer` object for both `beforeinput` event
and `input` event, and dispatch `beforeinput` event only when it hasn't been
dispatched yet (i.e., not dispatched before it's created).  The case shouldn't
occur, but let's have the fallback path in release builds for avoiding
inconvenience of our users.

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

--HG--
extra : moz-landing-system : lando
2020-01-20 01:41:55 +00:00
Masayuki Nakano 90cd2122dd Bug 970802 - part 5: Make `AutoEditActionDataSetter` created method dispatch "beforeinput" event r=smaug,m_kato
`AutoEditActionDataSetter` is created in the stack when editor's public method
is called and that guarantees lifetime of global objects in editor such as
editor itself, selection controller, etc.

The dispatcher of `beforeinput` event returns `NS_ERROR_EDITOR_ACTION_CANCELED`
if an event is actually dispatched but canceled.  The reason why it's an error
is, editor code must stop handling anything when any methods return error.
So, returning an error code is reasonable in editor module.  But when it's
filtered by `EditorBase::ToGenericNSResult()` at return statement of public
methods, it's converted to `NS_SUCCESS_DOM_NO_OPERATION`.  This avoids throwing
new exception, but editor class users in C++ can distinguish whether each edit
action is canceled or handled.  The reason why we should not throw new
exception from XPCOM API is, without taking care of each caller may break some
our UI (especially for avoiding to break comm-central).  Therefore, this patch
does not make XPCOM methods return error code when `beforeinput` event is
canceled.

In most cases, immediately after creating `AutoEditActionDataSetter` is good
timing to dispatch `beforeinput` event since editor has not touched the DOM
yet.  If `beforeinput` requires `data` or `dataTransfer`, methods need to
dispatch `beforeinput` event after that.  Alhtough this is not a good thing
from point of view of consistency of the code.  However, I have no better
idea.

Note 1: Our implementation does NOT conform to the spec about event order
between `keypress` and `beforeinput` (dispatching `beforeinput` event after
`keypress` event).  However, we follow all other browsers' behavior so that it
must be safe and the spec should be updated for backward compatibility.
Spec issue: https://github.com/w3c/uievents/issues/220

Note 2: Our implementation does NOT conform to the spec about event order
between `compositionupdate` and `beforeinput`.  Our behavior is same as
Safari, but different from Chrome.  This might cause web-compat issues.
However, our behavior does make sense from point of view of consistency of
event spec.  Additionally, at both `compositionupdate` and `beforeinput`,
composition string in editor has not been modified yet.  Therefore, this
may not cause web-compat issues (and I hope so).
Spec issue: https://github.com/w3c/input-events/issues/49

Note that this patch makes editor detect bugs that `beforeinput` event hasn't
been handled yet when it dispatches `input` event or modifying `data` and
`dataTransfer` value are modified after dispatching `beforeinput` event with
`MOZ_ASSERT`s.

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

--HG--
extra : moz-landing-system : lando
2020-01-14 07:18:51 +00:00
Masayuki Nakano 66ca57899f Bug 970802 - part 2: HTML editor command classes shouldn't handle edit actions multiple times r=m_kato
Some HTML editor command classes call `*AsAction()` methods multiple times.
That causes that user needs multiple undo/redo for a command and one command
causes multiple "input" events.  For both compatibility with the other
browsers and making "beforeinput" cancelable, they should call `*AsAction()`
once.  Instead, `HTMLEditor` should handle related element deletion.

This patch makes `HTMLEditor::RemoveInlinePropertyInternal()` remove multiple
elements if its caller allows, and `HTMLEditor::SetInlinePropertyAsAction()`
call `RemoveInlinePropertyInternal()` in some cases.

According to comm-central and BlueGriffon, we can make
`HTMLEditor::RemoveInlineProperty()` also removes the related methods
automatically because comm-central does same thing from script and BlueGriffon
does not use this.  However, we cannot do that for
`HTMLEditor::SetInlineProperty()` because BlueGriffon may call it with any
HTML5 elements and does not expect removing elements in same block at that
time.  If we needed to reduce the overhead of comm-central, we could change
only `RemoveInlineProperty()`, but it would make these APIs behavior
inconsistent.

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

--HG--
extra : moz-landing-system : lando
2020-01-14 07:14:55 +00:00
Razvan Maries 0df75c8122 Backed out 5 changesets (bug 970802) for xpcshell perma fails. CLOSED TREE
Backed out changeset 5511edd700f7 (bug 970802)
Backed out changeset 1fb9cf2264b6 (bug 970802)
Backed out changeset 6b185296c742 (bug 970802)
Backed out changeset ce6853e64ed6 (bug 970802)
Backed out changeset aa9bd45c09b1 (bug 970802)
2020-01-14 04:41:15 +02:00
Masayuki Nakano 00f4c31bb7 Bug 970802 - part 5: Make `AutoEditActionDataSetter` created method dispatch "beforeinput" event r=smaug,m_kato
`AutoEditActionDataSetter` is created in the stack when editor's public method
is called and that guarantees lifetime of global objects in editor such as
editor itself, selection controller, etc.

The dispatcher of `beforeinput` event returns `NS_ERROR_EDITOR_ACTION_CANCELED`
if an event is actually dispatched but canceled.  The reason why it's an error
is, editor code must stop handling anything when any methods return error.
So, returning an error code is reasonable in editor module.  But when it's
filtered by `EditorBase::ToGenericNSResult()` at return statement of public
methods, it's converted to `NS_SUCCESS_DOM_NO_OPERATION`.  This avoids throwing
new exception, but editor class users in C++ can distinguish whether each edit
action is canceled or handled.  The reason why we should not throw new
exception from XPCOM API is, without taking care of each caller may break some
our UI (especially for avoiding to break comm-central).  Therefore, this patch
does not make XPCOM methods return error code when `beforeinput` event is
canceled.

In most cases, immediately after creating `AutoEditActionDataSetter` is good
timing to dispatch `beforeinput` event since editor has not touched the DOM
yet.  If `beforeinput` requires `data` or `dataTransfer`, methods need to
dispatch `beforeinput` event after that.  Alhtough this is not a good thing
from point of view of consistency of the code.  However, I have no better
idea.

Note 1: Our implementation does NOT conform to the spec about event order
between `keypress` and `beforeinput` (dispatching `beforeinput` event after
`keypress` event).  However, we follow all other browsers' behavior so that it
must be safe and the spec should be updated for backward compatibility.
Spec issue: https://github.com/w3c/uievents/issues/220

Note 2: Our implementation does NOT conform to the spec about event order
between `compositionupdate` and `beforeinput`.  Our behavior is same as
Safari, but different from Chrome.  This might cause web-compat issues.
However, our behavior does make sense from point of view of consistency of
event spec.  Additionally, at both `compositionupdate` and `beforeinput`,
composition string in editor has not been modified yet.  Therefore, this
may not cause web-compat issues (and I hope so).
Spec issue: https://github.com/w3c/input-events/issues/49

Note that this patch makes editor detect bugs that `beforeinput` event hasn't
been handled yet when it dispatches `input` event or modifying `data` and
`dataTransfer` value are modified after dispatching `beforeinput` event with
`MOZ_ASSERT`s.

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

--HG--
extra : moz-landing-system : lando
2020-01-14 01:09:45 +00:00
Masayuki Nakano ad13198667 Bug 970802 - part 2: HTML editor command classes shouldn't handle edit actions multiple times r=m_kato
Some HTML editor command classes call `*AsAction()` methods multiple times.
That causes that user needs multiple undo/redo for a command and one command
causes multiple "input" events.  For both compatibility with the other
browsers and making "beforeinput" cancelable, they should call `*AsAction()`
once.  Instead, `HTMLEditor` should handle related element deletion.

This patch makes `HTMLEditor::RemoveInlinePropertyInternal()` remove multiple
elements if its caller allows, and `HTMLEditor::SetInlinePropertyAsAction()`
call `RemoveInlinePropertyInternal()` in some cases.

According to comm-central and BlueGriffon, we can make
`HTMLEditor::RemoveInlineProperty()` also removes the related methods
automatically because comm-central does same thing from script and BlueGriffon
does not use this.  However, we cannot do that for
`HTMLEditor::SetInlineProperty()` because BlueGriffon may call it with any
HTML5 elements and does not expect removing elements in same block at that
time.  If we needed to reduce the overhead of comm-central, we could change
only `RemoveInlineProperty()`, but it would make these APIs behavior
inconsistent.

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

--HG--
extra : moz-landing-system : lando
2020-01-08 09:22:52 +00:00
Masayuki Nakano 70ff2e9875 Bug 1597829 - part 2: Make `TextEditor::OnDrop()` move focus before inserting dropped content r=m_kato
Chrome moves focus to dropped element or editing host containing dropped
element, but we don't do it.  For compatibility with Chrome, it's better to
follow their behavior.  Additionally, this fixes 2 issues.  One is, when
dropping something into non-focused contenteditable element, we've failed to
initialize selection from `TextEditor::PrepareToInsertContent()` because
`pointToInsert` is outside of selection limiter if another editing host
has focus.  The other is, when same case, we've failed to insert dropped
content because edit action handlers of `HTMLEditor` check whether editing
position is in active editing host.

Finally, this patch makes `TextEditor::OnDrop()` cancels to dispatch "input"
event if it fails something before trying to insert dropped content.  Without
this change, `EditorBase::DispatchInputEvent()` tries to dispatch without
proper `data` or `dataTransfer` and that hits `MOZ_ASSERT` in `nsContentUtils`.

Additionally, this fixes an existing bug which `HTMLEditor` may insert `\r`
as-is if it comes from paste or drop.  Otherwise, we need complicated `todo_is`
paths in `test_dragdrop.html`.

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

--HG--
extra : moz-landing-system : lando
2019-12-21 12:28:56 +00:00
Emilio Cobos Álvarez 3c12d374bc Bug 1600362 - Cleanup IntersectionObserver. r=smaug
Initially this was going to be a simple cleanup: Remove some useless namespaces
here and there and so on, remove `using` statements from the header and so on.

But unfortunately, DOMIntersectionObserver.h (which is included in Element.h,
unnecessarily) ended up exposing `Element` unnamespaced to a lot of code, so I
had to fix that.

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

--HG--
extra : moz-landing-system : lando
2019-11-29 20:39:36 +00:00
Sylvestre Ledru 8d2f0d1b1f Bug 1519636 - Reformat recent changes to the Google coding style r=Ehsan
# ignore-this-changeset

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

--HG--
extra : moz-landing-system : lando
2019-11-26 14:35:02 +00:00
Masayuki Nakano a1a0330433 Bug 1593920 - Clean up `HTMLEditor::TabInTable()` with taking `WidgetKeyboardEvent*` and returning `EditActionResult` r=m_kato
With making it take `WidgetKeyboardEvent*`, it won't need to return "handled"
state.  However, when we implement `beforeinput` event, it needs to return
"canceled" state.  Therefore, it should return `EditActionResult`.

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

--HG--
extra : moz-landing-system : lando
2019-11-07 02:59:51 +00:00
Mats Palmgren 6aadfc8aaf Bug 1587141 part 2 - Make execCommand("indent") ignore whitespace when looking for sibling list element. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D48587

--HG--
extra : moz-landing-system : lando
2019-10-14 17:11:00 +00:00
Mats Palmgren c506e40d11 Bug 1587141 part 1 - Share some common code between Handle[CSS|HTML]IndentAtSelectionInternal (idempotent patch). r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D48586

--HG--
extra : moz-landing-system : lando
2019-10-15 04:36:26 +00:00
Masayuki Nakano ac74e89b26 Bug 1566795 - part 6: Make `HTMLEditor::RemoveInlinePropertyInternal()` remove text node style which comes from block parent r=m_kato
Finally, `Document.execCommand()` still does not work fine if selection
starts from very start of block and/or end at very end of block because
`PromoteInlineRange()` extends selection range to contain the
containers, then, `SubtreeContentIterator` won't list up text nodes.

In this case, `RemoveInlinePropertyInternal()` expects that
`RemoveStyleInside()` removes text node style with creating
`<span>` elements.  However, `RemoveStyleInsilde()` only handles
`Element`s and it handles elements from most-descendants.
Therefore, it cannot distinguish whether text node style comes
from removing inline elements or parent block.

This patch makes `RemoveInlinePropertyInternal()` collect
descendant text nodes in the range after handling all nodes in
the range except descendant text nodes, then, check the
final style of descendant text nodes, finally, remove the style
if coming from parent block.

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

--HG--
extra : moz-landing-system : lando
2019-10-09 08:04:34 +00:00
Masayuki Nakano 6a1791bc12 Bug 1566795 - part 3: Clean up `HTMLEditor::RemoveStyleInside()` r=m_kato
Surprisingly, its `aChildOnly` is never set to `true` and if it were set to
`true`, it does unnecessary recursive calls.  Therefore, we can make it
simpler.

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

--HG--
extra : moz-landing-system : lando
2019-10-07 03:33:11 +00:00
Masayuki Nakano 3cc02eccbf Bug 1566795 - part 2: Clean up `HTMLEditor::SplitAboveRange()` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D47859

--HG--
extra : moz-landing-system : lando
2019-10-07 01:11:31 +00:00
Masayuki Nakano 470b292007 Bug 1566795 - part 1: Clean up `HTMLEditor::ClearStyle()`, `HTMLEditor::SplitStyleAbovePoint()` and their callers r=m_kato
Both method take a DOM point with `nsCOMPtr<nsINode>*` and `int32_t*`.
This makes each caller complicated.  Instead, we should use stack only class
to return both `EditorDOMPoint` and `nsresult`.  I name it `EditResult`.

Additionally, this fixes a bug of `HTMLeditor::SplitStyleAboveRange()`.  That
is not tracking new selection start point while it splits elements at end
of given range.  This is detected by the debug assertion in
`ToRawRangeBoundary()` (i.e., this fix is required to pass some tests).

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

--HG--
extra : moz-landing-system : lando
2019-10-07 00:55:02 +00:00