The methods are in `nsCaret`, `nsFrameSelection` and `dom::Selection`. That
makes harder to read, and they are called each other, so, they are reused for
different purpose. Therefore, it must be better to move them into a new class.
Then, the name differences may become more unclear. If you think so, feel free
to request renaming some methods of them.
Differential Revision: https://phabricator.services.mozilla.com/D197288
Only them may run script. Therefore, they need to use `PostContentIterator`
and `SimpleRange` instead of `UnsafePreContentIterator` and `UnsafeSimpleRange`.
Additionally, they use `ContentEventHandler::ConvertFlatTextOffsetToDOMRange`
which returns `DOMRangeAndAdjustedOffsetInFlattenedText` but it stores a range
and a text node with raw pointers. Therefore, it needs to be a template
class to store them with or without strong pointers. Therefore, this patch
makes it and name `UnsafeDOMRangeAndAdjustedOffsetInFlattenedText` for the
raw pointers version.
Then, `ConvertFlatTextOffsetToDOMRange` needs to be a template method too
since it returns `DOMRangeAndAdjustedOffsetInFlattenedText` or
`UnsafeDOMRangeAndAdjustedOffsetInFlattenedText`.
Finally, `GetFirstFrameInRangeForTextRect` and `GetLastFrameInRangeForTextRect`
need to be template methods too because they need to take `SimpleRange` in
the methods, but `UnsafeSimpleRange` in the other methods.
Differential Revision: https://phabricator.services.mozilla.com/D187423
`RawRange` sounds like related to `RawRangeBoundary`, but it now has
`RangeBoundary` members and `UnsafeRawRange` has `RawRangeBoundary`s.
They are helpers for `ContentEventHandler` to work faster than `nsRange`
and `dom::StaticRange` with avoiding to do unnecessary things for
`ContentEventHandler`. Therefore, this patch renames them to `*SimpleRange*`
since they just store two range boundaries and their root node simply.
Differential Revision: https://phabricator.services.mozilla.com/D185626
It's used as both a temporary object in the stack and storing first range
selection range while `ContentEventHandler` handles everything. In the
first case, `ContentEventHandler` won't call any methods marked as
`MOZ_CAN_RUN_SCRIPT`. Therefore, we can make it store only raw `nsINode`
pointer and `RawRangeBoundary`.
Differential Revision: https://phabricator.services.mozilla.com/D184466
It's used for tying a set of node and offset in it in short time and
`ContentEventHandler` does not flush pending things in most paths.
Therefore, it can avoid using `RangeBoundary` for solving its performance
issue.
Differential Revision: https://phabricator.services.mozilla.com/D184442
`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
It's expensive to call `nsINode::IsAnyOfHTMLElements` with a lot of arguments
due to its recursive calls (in this case, called with 30 arguments).
Additionally, the unknown element check with `do_QueryObject` is also expensive.
Once we get an `nsHTMLTag`, we can use a `switch` statement.
Note that I realized `nsHTMLTag_small` is not defined only on Windows if
`nsHTMLTags.h` is included after `rpcndr.h` in the Windows SDK since there is
```
#define small char
```
In the header file. This patch includes the workaround for this issue.
Differential Revision: https://phabricator.services.mozilla.com/D184553
We've already known that `WidgetQueryContentEvent` is dispatched at initializing
a popup menu on macOS (bug 1530188). Therefore, I made the dispatcher under
`widget/cocoa` set `WidgetQueryContentEvent::mNeedLayoutFlush` to `false` to
avoid to flush pending things in `ContentEventHandler`, but
`PresShell::EventHandler` does it.
Differential Revision: https://phabricator.services.mozilla.com/D185264
This translation shows up prominently in the TipTap
Speedometer3 test. Chrome doesn't seem to do this translation
and other Windows programs also show inconsistency around
new lines.
Let's try disabling it on Nightly to check if anything breaks.
Differential Revision: https://phabricator.services.mozilla.com/D183046
`TextFragment::CharAt()` considers whether it's in the 2b-mode or not in each
call in theory. Let's create dependent string for skipping the redundant
checks.
Depends on D180767
Differential Revision: https://phabricator.services.mozilla.com/D180768
`IMEContentObserver` can observe the value changes only while the text control
has anonymous `<div>` element because it observers the DOM mutation. The
anonymous `<div>` is alive (connected) only while the text control element
has a frame (recreated at each reframe). Therefore, `IMEContentObserver`
cannot observe the value changed during reframing.
This patch makes `TextControlState` notify `IMEContentObserver` of setting
new value directly only when it does not have `mBoundFrame`.
Differential Revision: https://phabricator.services.mozilla.com/D179358
In order to support `StaticRange`s, which are not `MutationObserver`s, RangeBoundaries need to have an alternative way of ensuring that `mRef` points to the correct node.
This is now done by validating `mRef` every time `Ref()` is called using the parent and offset.
For performance reasons, this is disabled by default and should only be used for `StaticRange`s.
Differential Revision: https://phabricator.services.mozilla.com/D177892
In order to support `StaticRange`s, which are not `MutationObserver`s, RangeBoundaries need to have an alternative way of ensuring that `mRef` points to the correct node.
This is now done by validating `mRef` every time `Ref()` is called using the parent and offset.
For performance reasons, this is disabled by default and should only be used for `StaticRange`s.
Differential Revision: https://phabricator.services.mozilla.com/D177892
Callers of `GetCaretBaseline` just use it to get offset and size of the caret, so
refactor the shared logic. In the call sites, delay conversion of logical to physical
rect to reduce variable shuffling.
Differential Revision: https://phabricator.services.mozilla.com/D169210
Unfortunately, this class does not fully support bidi text because desktop
IME are typically created for East-Asian languages. Therefore, the new methods
still do not support RTL text cases.
Differential Revision: https://phabricator.services.mozilla.com/D160876
This patch does **not** make `ContentEventHandler` return consistent rect
for invisible text node, however, it should be okay for now because users
cannot put caret into invisible text node and cannot type text into it.
For avoiding the warning spam of `ContentCacheInChild` in automated tests,
`ContentEventHandler::OnQueryTextRectArray` shouldn't give it up correcting
character rects in invisible text nodes. And as mentioned above, using
similar rects to visible character around there is okay. Therefore, this
patch makes `OnQueryTextRectArray` fills invisible text rects with caret
rect before following visible character if they are followed by visible
characters. Otherwise, i.e., if invisible text rects are the last things
in the range, make it use caret rect after the last visible character.
Note that if the range is completely in invisible nodes, the value will be
computed in the fallback part of the method. It still has issues, but it
does not happen so many times in the automated tests. Therefore, this patch
does not treat the case.
Differential Revision: https://phabricator.services.mozilla.com/D160593
It guesses caret rect at end of a text node, i.e., it can work as expected
only when the text node is visible. Therefore, if a text node for computing
the rect is invisible, the callers need to use another fallback path.
Differential Revision: https://phabricator.services.mozilla.com/D160592
The callers of them want to return text rect for first visible thing in the
given range to make IME place UI around there. Therefore, it should ignore
invisible text which won't be interactive with IME.
Differential Revision: https://phabricator.services.mozilla.com/D160591
If a node is invisible (for example, its `display` property is `none`, the node
is a text node whose text only white-spaces and around a block boundary, etc),
the node is not associated with a primary frame is not illegal case. Therefore,
it should stop spamming in the terminal and log in automated tests.
Differential Revision: https://phabricator.services.mozilla.com/D160590
It's the only method which is used outside of the editor module. Therefore,
we can stop exposing `EditorUtils.h` later.
Depends on D158634
Differential Revision: https://phabricator.services.mozilla.com/D158635
The root is always an element node. So, it should take and store the root node
as `dom::Element` rather than `nsIContent`.
Differential Revision: https://phabricator.services.mozilla.com/D147135
It's designed for caching content information of focused editor. However, at
sending focus notification to the main process, the editor may have already
been blurred but `IMEContentObserver` may have not known it yet. In this edge
case, only query selection succeeds since IMEContentObserver still has a cache,
but query the others failed because of root content node check of
`IMEContentObserver::HandleQueryContentEvent`. If a content process meets this
case, it should not send focus notification and stop storing the content since
IME shouldn't get focus nor query non-editable content.
On the other hand, the reported testcase reproduces this with a fuzzing API
called **in** the content process. Therefore, I have no idea how to reproduce
it without the API. That's the reason why this patch does not contain new tests.
Differential Revision: https://phabricator.services.mozilla.com/D141821
Finally, making `WidgetQueryContentEvent::Succeeded` return `true` when there
is no selection when its message is `eQuerySelectedText`, and making
`ContentEventHandler::OnQuerySelectedText` set the no selection range data even
when the queried selection type is "normal. Then, all things which are
changed by the previous patches start to work.
And this patch adds a simple test for `ContentCache` and update tests of
`nsITextInputProcessor`.
Differential Revision: https://phabricator.services.mozilla.com/D137432
It's intended to indicate whether the selection is collapsed or not, but it can
be referred by other members, there is no reasonable user and the name makes
developers confused.
Differential Revision: https://phabricator.services.mozilla.com/D137422
This patch fixes only the cases if the result of `ComputeIndexOf_Deprecated()`
is used as unsigned integer with implicit or explicit cast.
Differential Revision: https://phabricator.services.mozilla.com/D131336
Offset in a node is declared as "unsigned long" by the standards and we don't
limit node can have less than `INT32_MAX`. So it should return `uint32_t`, but
it also needs to represent the case of "not found". For consistency with some
other APIs like `nsContentUtils::ComparePoints`, using `Maybe` must be a good
style rather than `Result<uint32_t, bool>`.
This patch fixes the callers in assertions for example.
Differential Revision: https://phabricator.services.mozilla.com/D131335
It's hard to fix some callers. Therefore, in this bug, we should fix only
simple cases. Therefore, we should rename existing API first.
Differential Revision: https://phabricator.services.mozilla.com/D131334
They are defined as "unsigned long" by the standards. So we should use
`uint32_t` rather than `int32_t` with the methods. However, layout code
uses `int32_t` a lot for representing the offset. Therefore, this patch
adds `*_FixOffset1` etc for the cases which cannot fix easily in this patch.
Differential Revision: https://phabricator.services.mozilla.com/D131110
.fallback is always the default font for the lang group unless we're a
system font (in which case it's "none").
The only reason we need that is because we need to react to
language changes (which affect the initial font).
Simplify the model a bit doing the language lookup in gfxTextRun (this
should avoid allocating a few nsStyleFont structs too.
Depends on D130732
Differential Revision: https://phabricator.services.mozilla.com/D131312