Currently, our editor and document viewer manage `Selection` state and
ranges within their `focus`/`blur` event listeners. However, UI Events
defines that the events should be fired after the focus move finished
[1][2]. Therefore, we need to move the handlers to
`EventTarget::PreHandleEvent` or the event listener of the event target
parent of the window (in the capturing phase of the default event group).
Otherwise, a web content's event listener runs before we maintain the
`Selection`. This patch moves the handlers to
`nsGlobalWindowInner::PreHandleEvent`.
Currently, there are 3 event listeners which maintain the `Selection`.
`nsDocViewerFocusListener`:
This maintains the active `nsFrameSelection` and the display of the
last focused selection only when the document node gets focus. This
patch removes this class and move the code into new static methods of
`nsFrameSelection`.
`HTMLEditor::OnFocus`:
This activates the document `nsFrameSelection` and collapses `Selection`
to the focused element if `Selection` ranges are not in the focused
editing host. This does it even if a text control gets focus even though
the focused `TextEditor` will handle the further user inputs.
`TextEditor::OnFocus`:
This activate the independent `nsFrameSelection`.
These handlers run in the following order:
1. `nsDocViewerFocusListener`
2. `HTMLEditor`
3. `TextEditor`
Therefore, `nsGlobalWindowInner::PreHandleEvent` handles all of them
within this order.
Note that `TextEditor::OnFocus` is now called after `HTMLInputElement`
or `HTMLTextAreaElement` prepares the further `change` event
dispatching. After applying this patch, their `PreHandleEvent` will do
that. Then, `nsGlobalWindowInner::PreHandleEvent` will run because
`PreHandleEvent`s are called in the bubbling phase order. Therefore, the
handling order shouldn't be changed.
1. https://w3c.github.io/uievents/#event-type-focus
2. https://w3c.github.io/uievents/#event-type-blur
Differential Revision: https://phabricator.services.mozilla.com/D292335
Allow detached ranges through the document check in highlight selection
population. Added two WPT reftests verifying highlights paint after
inserting a text node and after inserting a subtree containing a
highlighted range.
Differential Revision: https://phabricator.services.mozilla.com/D297898
The current mozilla::ScrollAxis struct in PresShellForwards.h isn't a simple
axis enum. It carries information about where to scroll to along a specific
axis, and under what conditions that should happen. So 'ScrollAxis' isn't the
best name.
Now we're introducing WebIDL 'ScrollAxis' in bug 1350457:
https://drafts.csswg.org/scroll-animations-1/#scrolltimeline-interface
The extensive use of PresShellForwards.h's ScrollAxis in DOM code makes it
conflict with this new DOM enum. Rather than try to fix this through lots of
explitic namespacing, this patch renames PresShellForwards.h's ScrollAxis.
Differential Revision: https://phabricator.services.mozilla.com/D293485
This reverts commit 88008cd8ca.
Revert "Bug 2012637 - part 8: Make `nsContentUtils::ComparePoints` handle `TreeKind::Flat` and `TreeKind::FlatForSelection` correctly r=smaug,dom-core"
This reverts commit 73e6f6587b.
Revert "Bug 2012637 - part 7: Make `RangeUtils::CompareNodeToRangeBoundaries()` use `nsContentUtils::ComparePoints` with valid point in the tree r=smaug"
This reverts commit 6985d5e80f.
Revert "Bug 2012637 - part 6: Make `nsRange::CutContents()` convert the range boundaries to the ones in the DOM before comparing r=smaug"
This reverts commit 73b585af3d.
Revert "Bug 2012637 - part 5: Delete the default template parameter of `nsContentUtils::ComparePoints` and relatives r=smaug,dom-core"
This reverts commit 1a7f24e5b5.
Revert "Bug 2012637 - part 4: Make `nsContentUtils` use `nsIContent` for taking a child node as a parameter r=smaug"
This reverts commit a6ea8d6824.
Revert "Bug 2012637 - part 3: Add template `nsINode` API which can switch to call API from `TreeKind` r=smaug,dom-core,webidl"
This reverts commit a4211e9df0.
Revert "Bug 2012637 - part 2: Add `TreeKind::FlatForSelection` and change the template parameter of `ChildIteratorBase` to `TreeKind` r=smaug,dom-core"
This reverts commit 0241749ee7.
Revert "Bug 2012637 - part 1: Make `ChildIterBase` template class to re-implement `FlattenedChildIterator` for DOM, Flat and FlatForSelection TreeKind r=smaug,dom-core,layout-reviewers,emilio"
This reverts commit 9e71cb77fb.
They accept any kind of points even if it does not match with the
template parameter's `TreeKind` because the caller wants to check the
relation in different kind of tree. Therefore, any callers need to
consider the `TreeKind` more carefully and clarify the `TreeKind` makes
developers easier to find a bug.
Differential Revision: https://phabricator.services.mozilla.com/D281308
This is a subtle bug where the initial paint of a highlight was wrong.
Before this patch, a highlight `Selection` was created, the highlight `Range`s were added,
and then the `Selection` was added to `nsFrameSelection::mHighlightSelections`.
However, adding the range triggers a paint, which then tried to access the selection
in `mHighlightSelections`, where it wasn't added to yet.
Differential Revision: https://phabricator.services.mozilla.com/D283659
This is a subtle bug where the initial paint of a highlight was wrong.
Before this patch, a highlight `Selection` was created, the highlight `Range`s were added,
and then the `Selection` was added to `nsFrameSelection::mHighlightSelections`.
However, adding the range triggers a paint, which then tried to access the selection
in `mHighlightSelections`, where it wasn't added to yet.
Differential Revision: https://phabricator.services.mozilla.com/D283659
I looked at this because in bug 2014331 I need to mark more pseudos as
element-backed, and it's kinda silly the state our setup is in right
now.
This is all a somewhat historical mess, because in the old style system
pseudo-elements were just atoms, and we had that different types of atom
setup. The source of truth for these right now lives in a header macro
file, which isn't very flexible.
But now we have PseudoStyleType which represents both pseudos and anon
boxes, and is similar to the rust side PseudoElement enum.
Plus, the ::-moz-tree pseudo-elements are defined as anon boxes which
doesn't make any sense, so move them to pseudo-elements while at it.
Unify this in a similar way we treat CSS properties: Source of truth is
in pseudo_elements.toml / anon_boxes.toml, and we generate Rust and C++
as needed. This allows removing the nsStaticAtom subclass thing from
XPCOM, too.
This avoids some nasty duplication around which pseudos are pref-gated
and what not as well.
Differential Revision: https://phabricator.services.mozilla.com/D282076
I looked at this because in bug 2014331 I need to mark more pseudos as
element-backed, and it's kinda silly the state our setup is in right
now.
This is all a somewhat historical mess, because in the old style system
pseudo-elements were just atoms, and we had that different types of atom
setup. The source of truth for these right now lives in a header macro
file, which isn't very flexible.
But now we have PseudoStyleType which represents both pseudos and anon
boxes, and is similar to the rust side PseudoElement enum.
Plus, the ::-moz-tree pseudo-elements are defined as anon boxes which
doesn't make any sense, so move them to pseudo-elements while at it.
Unify this in a similar way we treat CSS properties: Source of truth is
in pseudo_elements.toml / anon_boxes.toml, and we generate Rust and C++
as needed. This allows removing the nsStaticAtom subclass thing from
XPCOM, too.
This avoids some nasty duplication around which pseudos are pref-gated
and what not as well.
Differential Revision: https://phabricator.services.mozilla.com/D282076
The method serializes the selection ranges to update the selection cache
for the OS only on macOS. So, there are a lot of cases to run
`nsHTMLCopyEncoder` only on macOS because repainting selection occurs
immediately after moving focus.
Therefore, we may see assertion failures around `RangeBoundaryBase` and
`nsHTMLCopyEncoder` itself only of debug builds on macOS. However,
the macOS machines in trysever are always busy and we need to wait at
least one day and the developers may not run the tests on macOS before
landing their patches due to the slowness.
For solving these issues, this patch makes it run on any debug builds
on any desktop platforms. So, basically, we don't need to run tests on
macOS on tryserver after landing this in the most cases.
Differential Revision: https://phabricator.services.mozilla.com/D280905
The method serializes the selection ranges to update the selection cache
for the OS only on macOS. So, there are a lot of cases to run
`nsHTMLCopyEncoder` only on macOS because repainting selection occurs
immediately after moving focus.
Therefore, we may see assertion failures around `RangeBoundaryBase` and
`nsHTMLCopyEncoder` itself only of debug builds on macOS. However,
the macOS machines in trysever are always busy and we need to wait at
least one day and the developers may not run the tests on macOS before
landing their patches due to the slowness.
For solving these issues, this patch makes it run on any debug builds
on any desktop platforms. So, basically, we don't need to run tests on
macOS on tryserver after landing this in the most cases.
Differential Revision: https://phabricator.services.mozilla.com/D280905
I'm often confused at `RangeBoundaryIsMutationObserved` and
`RangeBoundaryBase::mIsMutationObserved` due to their names. They are
default to `Yes` or `true`. However, `RangeBoundaryBase` may be used for
temporary objects too without mutation observer. Therefore, they may
lie.
On the other hand, the most usage of
`RangeBoundaryBase::mIsMutationObserved` is, to check whether the
instance points to child node or offset. So, I think they can be changed
to `enum class RangeBoundaryPointsTo { Offset, ChildNode }` and
`mPointingToChildNode`.
Differential Revision: https://phabricator.services.mozilla.com/D279300
This patch does small refactorings like modernizing loops.
In addition, the `StyledRange` struct is moved into the `mozilla::dom`
namespace.
There are no functional changes.
Differential Revision: https://phabricator.services.mozilla.com/D279475
The `StyledRange`s in `Selection` need to be stored sorted by start
position in the DOM. At the same time, the style data needs to be
queried during paint, using a range pointer as key.
Before this patch, the data was stored in an `nsTArray`, which led to
linear lookup times during paint. This could lead to noticeable jank
in situations with many ranges (e.g. CSS Highlight API).
Since the data is key-value-ish, the data structure is changed
to use a sorted array of `AbstractRange`s in addition to a lookup table
for the `TextRangeStyle`s.
This patch tries to keep refactorings to a minimum
and should not change any behavior.
Differential Revision: https://phabricator.services.mozilla.com/D279474
Additionally, this adds some shortcut operators to `FrameAndOffset`.
Therefore, some users of derived structs of `FrameAndOffset` become
simpler.
Differential Revision: https://phabricator.services.mozilla.com/D273716
The other browsers do not support multiple selection ranges. Therefore,
they never split selection ranges to exclude non-selectable nodes.
To align the behavior, we should do so. However, to keep current
look of `Selection` which is similar to Chrome's behavior, we should
make the selection painters ignore normal selections if their content
is not selectable.
Note that this patch allows painting selected text when there are some
IME selections even if `user-select` is `none` because the normal
selection is also a part of IME selections. Although our widget
currently do not use non-collapsed normal selection during a
composition, it may be changed to support new IME in the future.
Differential Revision: https://phabricator.services.mozilla.com/D272187
Now that only root frames have views, we can just use the root frame directly.
This is only used to have a common reference frame for caret position (this
should probably be simpler).
Differential Revision: https://phabricator.services.mozilla.com/D272206
It is replaced by a standard-conforming cast to (void) which is
understood the same by the compiler.
In some cases this could be replaced by `[[maybe_unused]]` but for
expression whose value is ignored, this requires storing to a temporary
variable first, so not going that way.
One notable change is that marking an object of type already_AddRefed as
unused used to implicitly leak memory. This is now made explicit.
Most of the heavy lifting was done through:
$ git grep -l '\<Unused\> <<' | xargs sed -i -e 's/Unused << /(void)/g'
$ git grep -l mozilla/Unused.h | xargs sed -i -e '/mozilla\/Unused.h/ d'
Differential Revision: https://phabricator.services.mozilla.com/D268706
It is replaced by a standard-conforming cast to (void) which is
understood the same by the compiler.
In some cases this could be replaced by `[[maybe_unused]]` but for
expression whose value is ignored, this requires storing to a temporary
variable first, so not going that way.
One notable change is that marking an object of type already_AddRefed as
unused used to implicitly leak memory. This is now made explicit.
Most of the heavy lifting was done through:
$ git grep -l '\<Unused\> <<' | xargs sed -i -e 's/Unused << /(void)/g'
$ git grep -l mozilla/Unused.h | xargs sed -i -e '/mozilla\/Unused.h/ d'
Differential Revision: https://phabricator.services.mozilla.com/D268706
It is replaced by a standard-conforming cast to (void) which is
understood the same by the compiler.
In some cases this could be replaced by `[[maybe_unused]]` but for
expression whose value is ignored, this requires storing to a temporary
variable first, so not going that way.
One notable change is that marking an object of type already_AddRefed as
unused used to implicitly leak memory. This is now made explicit.
Most of the heavy lifting was done through:
$ git grep -l '\<Unused\> <<' | xargs sed -i -e 's/Unused << /(void)/g'
$ git grep -l mozilla/Unused.h | xargs sed -i -e '/mozilla\/Unused.h/ d'
Differential Revision: https://phabricator.services.mozilla.com/D268706
It is replaced by a standard-conforming cast to (void) which is
understood the same by the compiler.
In some cases this could be replaced by `[[maybe_unused]]` but for
expression whose value is ignored, this requires storing to a temporary
variable first, so not going that way.
One notable change is that marking an object of type already_AddRefed as
unused used to implicitly leak memory. This is now made explicit.
Most of the heavy lifting was done through:
$ git grep -l '\<Unused\> <<' | xargs sed -i -e 's/Unused << /(void)/g'
$ git grep -l mozilla/Unused.h | xargs sed -i -e '/mozilla\/Unused.h/ d'
Differential Revision: https://phabricator.services.mozilla.com/D268706
This patch updates all occurrences of the type `nsTextFragment` into its new name, `mozilla::dom::CharacterDataBuffer`.
It also updates the includes, including sorting.
Differential Revision: https://phabricator.services.mozilla.com/D259867
This assertion can be hit when the pref was on and then got
flipped to off. I think this is a legit usecase to set it to null
even if the pref is off. So this assertion doesn't really make sense.
All the callers that set this to non-null have the pref check that
should be enough.
Differential Revision: https://phabricator.services.mozilla.com/D241996