Commit graph

276 commits

Author SHA1 Message Date
Masayuki Nakano
cd53d5600e Bug 1816581 - part 6: Move the static methods used for moving caret or considering caret geometry into new utility class r=emilio
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
2023-12-27 04:42:12 +00:00
Masayuki Nakano
fe9fef936b Bug 1816581 - part 1: Make CaretAssociationHint an enum class r=emilio
For forward-decl-able.

Differential Revision: https://phabricator.services.mozilla.com/D197283
2023-12-27 04:42:09 +00:00
Masayuki Nakano
e06b33eaa9 Bug 1850938 - Make ContentEventHandler::OnQueryTextRectArray and ContentEventHandler::OnQueryTextRect work with strong pointers again r=smaug
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
2023-09-06 13:55:58 +00:00
Jeff Muizelaar
7e5a2fc8be Bug 1850819 - Let "Don't translate new lines for IME" ride into early beta. r=masayuki
This lets bug 1838355 (a5a62ea631e5) ride into early beta.

Differential Revision: https://phabricator.services.mozilla.com/D187141
2023-08-31 18:34:30 +00:00
Masayuki Nakano
2f8c32b023 Bug 1845215 - part 5: Rename ContentEventHandler::*RawRange* to *SimpleRange* r=smaug
`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
2023-08-10 00:59:29 +00:00
Masayuki Nakano
a8a2324007 Bug 1845215 - part 4: Make ContentEventHandler stop using strong pointers if safe r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D184467
2023-08-10 00:59:29 +00:00
Masayuki Nakano
51043eee4c Bug 1845215 - part 3: Make ContentEventHandler::RawRange a template class r=smaug
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
2023-08-10 00:59:28 +00:00
Masayuki Nakano
17f4ff6134 Bug 1845215 - part 2: Make ContentEventHandler::NodePosition inherits RawRangeBoundary instead of RangeBoundary r=smaug
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
2023-08-10 00:59:28 +00:00
Masayuki Nakano
c204c013dd Bug 1845215 - part 1: Make ContentIteratorBase a template class to work without strong pointers r=smaug
`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
2023-08-10 00:59:28 +00:00
Masayuki Nakano
b2e135f779 Bug 1845445 - Make ContentEventHandler::ShouldBreakLineBefore use nsHTMLTag instead of nsINode::IsAnyOfHTMLElements with a lot of params r=smaug
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
2023-08-09 02:31:50 +00:00
Masayuki Nakano
e4d8451468 Bug 1845904 - Make PresShell::EventHandler::HandleEventWithCurrentEventInfo stop flushing pending notifications if a query content event does not require that r=emilio
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
2023-08-07 05:24:20 +00:00
Jeff Muizelaar
78554540c7 Bug 1838355. Don't translate new lines for IME on Nightly. r=masayuki
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
2023-07-13 03:21:46 +00:00
Masayuki Nakano
765a840831 Bug 1837482 - Make CountNewlinesInXPLength and CountNewlinesInNativeLength not scan TextFragment directly r=smaug
`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
2023-06-14 01:55:59 +00:00
Masayuki Nakano
53f87d35ce Bug 1835353 - Make TextControlState notify IMEContentObserver of setting new value during no frame r=smaug
`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
2023-05-31 12:11:44 +00:00
Jan-Niklas Jaeschke
1bbcb68c33 Bug 1828469, part 1: Prepare RangeBoundaryBase to be able to handle non-MutationObserver Range classes. r=masayuki
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
2023-05-31 08:23:45 +00:00
Noemi Erli
61ed1c4c8c Backed out 3 changesets (bug 1828469) for causing assertion in RangeBoundary.h
Backed out changeset ab92a12ba6ea (bug 1828469)
Backed out changeset 217801294c41 (bug 1828469)
Backed out changeset c78c717e4ec9 (bug 1828469)
2023-05-23 12:10:12 +03:00
Jan-Niklas Jaeschke
39523794fc Bug 1828469, part 1: Prepare RangeBoundaryBase to be able to handle non-MutationObserver Range classes. r=masayuki
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
2023-05-23 06:53:32 +00:00
Jonathan Kew
73d344d188 Bug 1823215 - Use ElementOrArray<T> to simplify the management of glyphrun(s) in gfxTextRun. r=gfx-reviewers,lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D172940
2023-03-19 16:36:06 +00:00
David Shin
e9eaa316b3 Bug 1815729: Replace GetCaretBaseline with GetCaretBlockAxisMetrics. r=emilio
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
2023-02-24 17:26:44 +00:00
Masayuki Nakano
f68bd66a8f Bug 1726297 - part 5: Make ContentEventHandler use common utility methods to compute caret rect from a character rect r=smaug
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
2022-11-11 13:43:24 +00:00
Masayuki Nakano
f7d66877b9 Bug 1726297 - part 4: Make ContentEventHandler::OnQueryTextRectArray fills invisible character rects with caret rect before next visible character r=smaug
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
2022-11-11 13:43:24 +00:00
Masayuki Nakano
5e571d48ed Bug 1726297 - part 3: Make callers of ContentEventHandler::GuessLineBreakerRectAfter use with visible text node r=smaug
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
2022-11-11 13:43:23 +00:00
Masayuki Nakano
15a9cf9619 Bug 1726297 - part 2: Make ContentEventHandler::Get(First|Last)FrameInRangeForTextRect ignore invisible nodes r=smaug
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
2022-11-11 13:43:23 +00:00
Masayuki Nakano
327a2b8e49 Bug 1726297 - part 1: Make GetFrameForTextRect stop warning no primary frame case r=smaug
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
2022-11-11 13:43:23 +00:00
Masayuki Nakano
994759243f Bug 1793694 - part 5: Move EditorUtils::MaskString to TextEditor r=m_kato
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
2022-10-12 02:44:19 +00:00
Masayuki Nakano
0e18b68708 Bug 1770133 - part 5: Make ContentEventHandler store root node as Element* rather than nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D147136
2022-05-26 07:03:20 +00:00
Masayuki Nakano
6440fbddc3 Bug 1770133 - part 4: Make IMEContentObserver use dom::Element instead of nsIContent for root r=m_kato
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
2022-05-26 07:03:20 +00:00
Masayuki Nakano
91e18f14d8 Bug 1760160 - Make ContentCacheInChild stop storing content if editable element has already been blurred r=m_kato
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
2022-04-07 00:58:49 +00:00
Ryan VanderMeulen
7e3d69d382 Bug 1757415 - Undef small in ContentEventHandler.cpp to avoid conflicting with the definition in rpcndr.h from the Windows SDK. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D139849
2022-02-28 21:03:38 +00:00
Masayuki Nakano
69c1675bde Bug 1746104 - part 7: Make eQuerySelectedText event and ContentEventHandler work with no selection ranges r=m_kato
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
2022-02-07 22:33:41 +00:00
Masayuki Nakano
fd30eaf365 Bug 1746104 - part 5-1: Get rid of WidgetQueryContentEvent::Reply::mHasSelection r=m_kato
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
2022-02-07 22:33:37 +00:00
Masayuki Nakano
cfd2352f90 Bug 1741148 - part 11: Make ContentEventHandler use nsINode::ComputeIndexOf() r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D131470
2021-12-09 16:38:24 +00:00
Masayuki Nakano
8cd9308e32 Bug 1741148 - part 7: Make AdjustRangeForSelection() in ContentEventHandler.cpp use Maybe<uint32_t> for treating offset in a DOM node r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D131340
2021-12-09 14:53:06 +00:00
Masayuki Nakano
3816ca9546 Bug 1741148 - part 3: Make users of nsINode::ComputeIndexOf_Deprecated() use nsINode::ComputeIndexOf() if the result is not set to int32_t nor return as int32_t r=smaug
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
2021-12-09 11:55:36 +00:00
Masayuki Nakano
fb2940808f Bug 1741148 - part 2: Re-implement nsINode::ComputeIndexOf as returning Maybe<uint32_t> rather than int32_t r=smaug
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
2021-12-09 09:21:52 +00:00
Masayuki Nakano
f2baf0d9ab Bug 1741148 - part 1: Rename nsINode::ComputeIndexOf to ComputeIndexOf_Deprecated r=smaug
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
2021-12-09 08:32:30 +00:00
Masayuki Nakano
c19aa5aaa5 Bug 1740853 - part 1: Make nsContentUtils::ComparePoints take uint32_t for offset in DOM nodes r=smaug
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
2021-12-09 07:51:45 +00:00
Emilio Cobos Álvarez
ff07ef7e17 Bug 1739464 - Simplify language-dependent font fallback code. r=jfkthame
.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
2021-11-19 16:11:55 +00:00
Masayuki Nakano
6055181ed3 Bug 1734771 - part 12: Make ContentEventHandler::GuessLineBreakerRectAfter() take const Text& instead of nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128149
2021-10-13 23:07:25 +00:00
Masayuki Nakano
aff643f926 Bug 1734771 - part 11: Make ContentEventHandler::SetRawRangeFromFlatTextOffset() take Text** instead of nsIContent** r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128148
2021-10-13 22:09:14 +00:00
Masayuki Nakano
16f869402f Bug 1734771 - part 10: Make ContentEventHandler::ExpandToClusterBoundary() take Text& instead of nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128147
2021-10-13 06:52:04 +00:00
Masayuki Nakano
d0644e942f Bug 1734771 - part 9: Make ContentEventHandler::GetTextLengthInRange() and ContentEventHandler::AppendFontRanges() take const Text& instead of nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128146
2021-10-13 05:22:42 +00:00
Masayuki Nakano
825170c74f Bug 1734771 - part 8: Make ConvertToXPOffset() take const Text& instead of nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128145
2021-10-13 02:54:28 +00:00
Masayuki Nakano
83ee827638 Bug 1734771 - part 7: Get rid of ContentEventHandler::GetNativeTextLengthBefore() due to unused r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128144
2021-10-13 02:54:27 +00:00
Masayuki Nakano
4725f91350 Bug 1734771 - part 6: Make ContentEventHandler::ShouldBreakLineBefore() take const nsIContent& and const nsINode* instead of nsIContent* and nsINode* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128143
2021-10-12 23:52:06 +00:00
Masayuki Nakano
24a6250291 Bug 1734771 - part 5: Make ContentEventHandler::GetNativeTextLength() take const Text& instead of nsIContent* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D128142
2021-10-12 23:05:08 +00:00
Masayuki Nakano
0dc25ff31e Bug 1734771 - part 4: Make ContentEventHandler::GetTextLength() take const Text& instead of nsIContent* r=m_kato
Depends on D128140

Differential Revision: https://phabricator.services.mozilla.com/D128141
2021-10-12 21:31:29 +00:00
Masayuki Nakano
fc532efa09 Bug 1734771 - part 3: Make AppendString() and AppendSubString() take const Text& instead of Text* r=m_kato
Depends on D128139

Differential Revision: https://phabricator.services.mozilla.com/D128140
2021-10-12 15:02:38 +00:00
Masayuki Nakano
893ce2f4de Bug 1734771 - part 2: Make IsContentBR() and IsPaddingBR() take const nsIContent& instead of nsIContent* r=m_kato
Depends on D128138

Differential Revision: https://phabricator.services.mozilla.com/D128139
2021-10-12 14:55:56 +00:00
Masayuki Nakano
63a10f1409 Bug 1734771 - part 1: Make ContentEventHandler::InitRootContent() take const Selection& instead of Selection* r=m_kato
Depends on D127923

Differential Revision: https://phabricator.services.mozilla.com/D128138
2021-10-12 14:41:24 +00:00