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
Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.
We should still address the spec issues, but this seems to be
an acceptable compromise.
Differential Revision: https://phabricator.services.mozilla.com/D239657
Even in these days, we notify selection listeners of selection changes
**synchronously**. Thus, we need to mark all selection change methods as
`MOZ_CAN_RUN_SCRIPT` even though they are safe in the most cases.
Depends on D241776
Differential Revision: https://phabricator.services.mozilla.com/D241778
It's currently always set to the native anonymous `<div>` for editable content
of text control element. So, it means that it's an independent selection root.
Depends on D241587
Differential Revision: https://phabricator.services.mozilla.com/D241775
This patch fixes multiple points which may cross independent selection
boundaries which is element boundary of the native anonymous `<div>` for
editable content in text controls. The reason why I don't split this patch is,
fixing one of them leads another assertion failure. So, I couldn't pass all
tests with separated patches.
1. `nsFrameTraversal` should take `Element` instead of `nsIFrame` for the
limiter because e.g., inline editing host like `<span contenteditable>` may
have multiple frames if it's wrapped. Therefore, we should make it take
an element as the ancestor limiter, and check it when getting parent frame
or after getting previous or next frame.
2. `nsIFrame::PeekBackwardAndForward` may cross the boundary because it does not
take the anonymous `<div>` element as ancestor limiter of the selection. It's
currently used only for extending selection. Therefore, I rename it to make
it clearer.
3. `SelectionMovementUtils::GetPrevNextBidiLevel` to take the ancestor limiter
for calling `nsIFrame::GetFrameFromDirection()`.
4. `nsINode` should have a method to return the `nsFrameSelection` instance
which manages the selection in the node. This makes the check simpler, and
this is not expensive. Then, for making it clearer, I rename
`TextControlElement::GetConstFrameSelection()` to
`GetIndependentFrameSelection()`.
5. `nsINode::GetSelectionRootContent()` should have an option to return
independent selection root when the node is its host for
`nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()`
6. `nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()` should not
retrieve independent selection root when the given frame is a text control
frame.
7. `RangeUtils` should get parent with checking the independent selection
boundaries.
8. `Selection::Extend` should assert if the destination is managed by its
frame selection to detect a bug.
Differential Revision: https://phabricator.services.mozilla.com/D241587
Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.
We should still address the spec issues, but this seems to be
an acceptable compromise.
Differential Revision: https://phabricator.services.mozilla.com/D239657
Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.
We should still address the spec issues, but this seems to be
an acceptable compromise.
Differential Revision: https://phabricator.services.mozilla.com/D239657
There are some callers of parent/offset version which computes offset before.
However, the offset may not be used. Therefore, the callers should use
`RangeBoundaryBase` version.
Additionally, if only one of the pairs is computed from `RangeBoundaryBase`,
such callers should use the `RangeBoundaryBase` version too because the offset
computation may be skipped. In this case, temporary `RangeBoundaryBase` should
be a `RawRangeBoundary` and whose `aRangeIsMutationObserver` should be set to
`RangeBoundaryIsMutationObserved::No` to avoid immediately to compute the child
node from `aOffset`. I think that this should be default to
`RangeBoundaryIsMutationObserved::No` in the future, but for now, we should just
make the users explicitly set it to `RangeBoundaryIsMutationObserved::No` for
avoiding regressions.
Differential Revision: https://phabricator.services.mozilla.com/D236793
`nsFrameSelection::GetLimiter()` is not `nullptr` only when it's an instance for
an independent selection of a text control. In the case, it's set to the editor
root anonymous `<div>` of the text control. Despite the name, this is already
optimized only for this purpose in `nsFrameSelection::NodeIsInLimiters()`.
Thus, we don't have any problems to make this clearer for the other developers
with renaming some parameter names.
`nsFrameSelection::GetAncestorLimiter()` is also always an `Element`. So,
we can change this to `Element` too.
Differential Revision: https://phabricator.services.mozilla.com/D235254
`AutoRangeArray` is created for making some handlers of the editor classes free
from `Selection` and `nsFrameSelection` while handling the edit actions.
However, the method still depends on `nsFrameSelection` instance since its
callees are instance methods of `nsFrameSelection`.
However, `EditContext` requires completely free methods to compute target
ranges of `beforeinput`. Therefore, we need to make it not depend on
`Selection` nor `nsFrameSelection`.
The common method, `nsFrameSelection::CreateRangeExtendedToSomewhere`, requires
`PresShell`, selection limiter which is set only when the selection is an
independent selection like in a selection for a text control, selection
ancestor limiter which is set only when an editing host has focus, caret
association hint to put caret to end of preceding line or start of following
line if selection range is collapsed at a line break and caret bidi level for
considering caret position around line break in bidi text. They are now stored
by `nsFrameSelection` and modified when selection range is changed in some
cases. Basically, the method is called without updating its ranges and if and
only if it's initialized with `Selection`. So, simply caching the
`nsFrameSelection`'s values solves the issues in the most cases, but this
patch makes `AutoRangeArray` adjust the value only when its `Collapse` is
called because `Selection` automatically updates it and we can compute the
value without `Selection` nor `nsFrameSelection`.
After applying this patch, `AutoRangeArray` has two meanings, one is the
instance is a proxy for `Selection`. The other is a container for a range to
call methods which take pointer or reference to it. To make this differences
checked at build time, this patch creates a new subclass of it, and renamed to
`AutoClonedRangeArray` to make it clearer that what are stored in the array.
Oddly, `AutoRangeArray(nsRange&)` constructor has not been cloned. Therefore,
I make it and its subclass version clone before storing into the array. Then,
one caller needs to change which range should be tracked.
Differential Revision: https://phabricator.services.mozilla.com/D232174
The `nsFrameSelection` class guarantees that all `mDomSelections` are
non-null between creating and unlinking the instance.
Therefore, a nullptr check is typically not necessary when accessing a `Selection` instance.
This patch removes null-checks and instead asserts that a Selection is non-null.
This is done by adding a `MOZ_ASSERT` to `nsFrameSelection::GetSelection()` and
by removing all direct access to `mDomSelections` and
instead routing through `GetSelection()` (or, by adding asserts).
As a side effect, this removes quite a bit of duplicate code.
Note that `nsFrameSelection::GetSelection()` might still return `nullptr`
if being called with an invalid selection type (`eInvalid`, `eNone`, `eHighlight`).
This means that if the selection type is not hard-coded, a nullptr check is still necessary.
Differential Revision: https://phabricator.services.mozilla.com/D230410
The logic of this method was moved into helper methods in part 2 of this patchset.
Now, there was only one caller left.
So, we can easily move the code into the one call site and get rid of the method.
Differential Revision: https://phabricator.services.mozilla.com/D227159
This new helper function can create a range boundary which is moved
by `aAmount` into `aDirection` without requiring to be in a selection.
Differential Revision: https://phabricator.services.mozilla.com/D227146
When `PeekOffsetForCharacter` find a non-editable content, it should never
return the frame because user must want to move caret only in editable content
when the previous position is editable. Additionally, when a non-selectable
frame is skipped, caret will be moved enough, so it should not skip any editable
content. Finally, the found frame may cause a line break. Therefore, this
patch overwrites the result of `SelectablePeekReport::PeekOffsetForCharacter`
from `FOUND` to `CONTINUE_UNSELECTABLE` when non-editable content is found.
The remaining failures of the new WPT should be handled in bug 449685 because
they are caused by no frame for invisible preceding/trailing white spaces around
the block element boundary.
Depends on D223909
Differential Revision: https://phabricator.services.mozilla.com/D224183
There are no callers from JS (looked at the selection region constant
usage in idl and those use nsISelectionController, not this).
If we were to provide this API in the future, it would probably use
ScrollIntoViewOptions or so instead (plus something extra perhaps).
I wanted to remove the weird WehreToScroll percentage impl, but actually
some C++ accessibility code still uses it.
Differential Revision: https://phabricator.services.mozilla.com/D216872
The problems in the testcase are, `nsIFrame::PeekOffsetForLine` returns a frame
for any content node outside the editing host and `nsIFrame::GetLastLeaf`
returns a native anonymous subtree node if the frame is for the native
anonymous subtree root like `<input>` or `<textarea>`.
For fixing the former, the methods need to check whether found frame's editable
state **and** whether the editable node is an inclusive descendant of the
editing host. However, there are complicated cases with inline editing hosts
and elements whose `contenteditable` is set to `false` and this is a new
regression for ESR 128. Therefore, we need to fix this without any behavior
changes as far as possible. Therefore, this patch basically checks only whether
the editing state of found one is editable and/or whether the one is an
inclusive descendant of the editing host to avoid `Selection` moves outside the
editing host. The reaming complicated cases should be handled in new bugs which
blocks bug 1873155.
For fixing the latter, `nsIFrame::GetLastLeaf` needs to check the given frame's
content is a native anonymous subtree root or not.
Differential Revision: https://phabricator.services.mozilla.com/D216371
Also, simplify some callers of `GetScrollTargetFrame()` to drop
`nsIScrollableFrame*` and unnecessary `do_QueryFrame`. We'll continue removing
more `nsIScrollableFrame*` in later parts.
Differential Revision: https://phabricator.services.mozilla.com/D211490
In theory, changing the return type from `nsIFrame*` to `ScrollContainerFrame*`
exposes `ScrollContainerFrame` to the callers who might not needed, but almost
all of the callers in cpp files are already exposed to `nsIScrollableFrame`, as
demonstrated in this patch via replacing the #include from
"nsIScrollableFrame.h" to "ScrollContainerFrame.h", so this is OK.
Some callers can be simplified since we no longer need `do_QueryFrame` to
`nsIScrollableFrame`.
Differential Revision: https://phabricator.services.mozilla.com/D211488
Also, simplify some callers of `GetScrollTargetFrame()` to drop
`nsIScrollableFrame*` and unnecessary `do_QueryFrame`. We'll continue removing
more `nsIScrollableFrame*` in later parts.
Differential Revision: https://phabricator.services.mozilla.com/D211490
In theory, changing the return type from `nsIFrame*` to `ScrollContainerFrame*`
exposes `ScrollContainerFrame` to the callers who might not needed, but almost
all of the callers in cpp files are already exposed to `nsIScrollableFrame`, as
demonstrated in this patch via replacing the #include from
"nsIScrollableFrame.h" to "ScrollContainerFrame.h", so this is OK.
Some callers can be simplified since we no longer need `do_QueryFrame` to
`nsIScrollableFrame`.
Differential Revision: https://phabricator.services.mozilla.com/D211488
Before this patch, the `AutoFrameSelectionBatcher` helper class would always call `NotifySelectionListeners()` for `SelectionType::eNormal`, even if the selection may have originated from Custom Highlight.
This patch moves the information that a change has occurred during batching from `nsFrameSelection` into the `Selection` instance, thus keeping the information per instance instead of globally.
When batching ends, `Selection::NotifySelectionListeners()` is called for all `Selection` instances depending on the flag.
Additionally, `Selection::NotifySelectionListeners()` is updated so that some Listeners (AutoCopyListener, SelectionChangeEvent, AccessibleCaret) are only notified for `SelectionType::eNormal`.
Differential Revision: https://phabricator.services.mozilla.com/D210130
This patch implements the `::target-text` pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.
Differential Revision: https://phabricator.services.mozilla.com/D195687
This patch implements the `::target-text` pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.
Differential Revision: https://phabricator.services.mozilla.com/D195687