Commit Graph
182 Commits
Author SHA1 Message Date
James Teh c7ee86b590 Bug 2021820 part 7: Move cache-domain helpers onto the document accessible. r=eeejay
This is purely refactoring in preparation for allowing print documents to have a set of cache domains which is different to the global set.
The free functions DomainsAreActive and RequestDomainsIfInactive are turned into methods on DocAccessibleParent, and a new EffectiveCacheDomains accessor is added on both DocAccessible and DocAccessibleParent.
The original DomainsAreActive free function remains because it's still required by PlatformShouldTrackFocusedAccLocation on Mac, and passing a DocAccessibleParent to that is awkward.

Differential Revision: https://phabricator.services.mozilla.com/D299959
2026-05-21 01:59:26 +00:00
Daniel Holbert b4e4f5d2f5 Bug 2038733: Use MakeRefPtr to do allocation for local RefPtr variables, in accessible/. r=accessibility-platform-reviewers,Jamie
Differential Revision: https://phabricator.services.mozilla.com/D299763
2026-05-12 07:20:02 +00:00
James Teh a7470d4986 Bug 2027308: Fix handling of empty text leaves. r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D294876
2026-04-22 03:22:20 +00:00
agoloman 8f1db4ce24 Revert "Bug 2027308: Fix handling of empty text leaves. r=eeejay" for causing build bustages @TextLeafRange.cpp.
This reverts commit 2245843e9a.
2026-04-21 00:54:01 +00:00
James Teh 2245843e9a Bug 2027308: Fix handling of empty text leaves. r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D294876
2026-04-21 00:16:33 +00:00
Jonathan Watt 017557984b Bug 2030928. Rename mozilla::ScrollAxis to mozilla::AxisScrollParams. r=credential-management-reviewers,layout-reviewers,emilio,dimi
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
2026-04-14 12:59:21 +00:00
Eitan Isaacson 07c6371f8d Bug 2029743 - Return strong references to content from ToDOMPoint. r=morgan
Differential Revision: https://phabricator.services.mozilla.com/D293153
2026-04-11 22:30:17 +00:00
Sylvestre Ledru eafe8b152d Bug 2023419 - Remove Emacs/Vim modelines from accessible/ r=emilio
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287834
2026-03-18 10:29:47 +00:00
Serban Stanca 5a709d4a9a Revert "Bug 2023419 - Remove Emacs/Vim modelines from accessible/ r=emilio" for causing mochitests failures in browser_action.js.
This reverts commit 2fa4815c8d.
2026-03-17 15:34:26 +00:00
Sylvestre Ledru 2fa4815c8d Bug 2023419 - Remove Emacs/Vim modelines from accessible/ r=emilio
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287834
2026-03-17 09:21:51 +00:00
James Teh 4d33b2b2c2 Bug 2015380 part 2: Don't fire a caret event when the caret moves within a document which isn't focused. r=eeejay
Firing a caret event for an Accessible which doesn't have focus confuses clients, who expect that the caret should be related to the focus.
Prior to bug 2006816, this wasn't as bad because even though we fired the caret event on the wrong Accessible, TextLeafPoint::GetCaret still returned the caret from the focused document.
After bug 2006816, we use the cached caret, so the event and the retrieved caret are both (consistently) incorrect.
To fix this:

1. Make it possible to update the RemoteAccessible cache for the caret via IPDL without firing a caret event.
2. When the caret moves, don't fire a caret event unless it's within the focused document.
3. However, the caret event won't be fired again when the document eventually gets focused, so we still send an IPDL message to update the cached caret in the RemoteAccessible tree.
4. In TextLeafPoint::GetCaret, only use the cached caret if the cached caret Accessible is within the same document as the origin Accessible.

Differential Revision: https://phabricator.services.mozilla.com/D282330
2026-02-11 02:57:50 +00:00
James Teh fca3104d60 Bug 2012651: Fix caret coordinates at the start of a paragraph preceded by a line of other text. r=morgan
This was breaking Text Cursor Indicator when typing into an impacted text box.
This was caused by a cascade of problems:

1. Previously, we explicitly never set mIsEndOfLineInsertionPoint to true at the start of a paragraph. This is exactly the case we're dealing with here and that behaviour is incorrect. Instead, we now have a much narrower check for the specific exception we're trying to detect: the start of the editor.
2. GetCaretRect vertically aligns the rect to the top of the line. To do this, it relies on mIsEndOfLineInsertionPoint being set correctly, which it wasn't previously. Thus, GetCaretRect was using the first character on the next line, resulting in a rect with negative height.
3. UIA calls TextLeafRange::LineRects, which clips the bounds to the content area. Since the caret rect previously had negative height, it was clipped completely and removed. Thus, UIA previously returned no bounds at all.

All of this is fixed by correctly setting mIsEndOfLineInsertionPoint in this case.

Differential Revision: https://phabricator.services.mozilla.com/D281126
2026-02-07 00:49:06 +00:00
James Teh 7ec3f64d4f Bug 2010498 part 2: Use the text content from the subtree when calculating the value of role=textbox/contentEditable, not nsTextEquivUtils. r=morgan
nsTextEquivUtils is for name and description calculation, where we want to consider things like aria-label, compress whitespace, etc.
However, a text box value should reflect the actual text content as closely as possible, just like text APIs; i.e. it shouldn't compress whitespace if it isn't compressed in the visual rendering, nor should it consider things like aria-label.
This required a slight tweak to the editable text tests, since a cleared contentEditable gets a line feed padding character which is exposed as text content but was previously stripped by nsTextEquivUtils.

Differential Revision: https://phabricator.services.mozilla.com/D279971
2026-01-23 06:06:42 +00:00
Cristian Tuns bb09486807 Revert "Bug 2010498 part 4: Don't include the value of HTMLTextFieldAccessibles in the RemoteAccessible cache. r=morgan" for causing build bustages in RemoteAccessible.cpp
This reverts commit 763c1c8083.

Revert "Bug 2010498 part 3: For LocalAccessible, use textbox value calculation for HTML text input/textarea, AKA HTMLTextFieldAccessible. r=morgan"

This reverts commit 1dc286a790.

Revert "Bug 2010498 part 2: Use the text content from the subtree when calculating the value of role=textbox/contentEditable, not nsTextEquivUtils. r=morgan"

This reverts commit 70ca939007.

Revert "Bug 2010498 part 1: Add a11y browser tests for value of <input>, <textarea> and <input type="password"> elements. r=morgan"

This reverts commit ecc02c2433.
2026-01-23 04:49:35 +00:00
James Teh 70ca939007 Bug 2010498 part 2: Use the text content from the subtree when calculating the value of role=textbox/contentEditable, not nsTextEquivUtils. r=morgan
nsTextEquivUtils is for name and description calculation, where we want to consider things like aria-label, compress whitespace, etc.
However, a text box value should reflect the actual text content as closely as possible, just like text APIs; i.e. it shouldn't compress whitespace if it isn't compressed in the visual rendering, nor should it consider things like aria-label.
This required a slight tweak to the editable text tests, since a cleared contentEditable gets a line feed padding character which is exposed as text content but was previously stripped by nsTextEquivUtils.

Differential Revision: https://phabricator.services.mozilla.com/D279971
2026-01-23 04:17:33 +00:00
James Teh ea44e6826a Bug 2006816 part 3: Fix TextLeafPoint::GetCaret for LocalAccessible when the caret is deeper than a direct child of the origin container. r=eeejay
Previously, it used HyperTextAccessible::CaretOffset on the origin container, then ToTextLeafPoint on that offset.
However, offsets can only refer to a direct child.
This meant that ToTextLeafPoint was descending into the direct child using offset 0; i.e. returning the start of the child's content.
This was completely incorrect when the caret wasn't at the start of the child's content.
To fix this, first try using the caret cached by SelectionManager, as that avoids redundant transformation of the caret for each descendant.
If that fails, traverse using CaretOffset on each descendant until we can't go any further.

Differential Revision: https://phabricator.services.mozilla.com/D276963
2025-12-19 07:40:33 +00:00
Eitan Isaacson 6cd265bc11 Bug 2002339 - Only store text attributes when they differ from parent. r=Jamie
Differential Revision: https://phabricator.services.mozilla.com/D274209
2025-12-03 23:20:52 +00:00
serge-sans-paille 7662b3abdc Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch
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
2025-10-21 19:36:01 +00:00
Cristina Horotan 8a1b1970b7 Revert "Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch" for causing Gtest failures on AlreadyAddRefed.h
This reverts commit e98adca292.
2025-10-21 16:16:29 +00:00
serge-sans-paille e98adca292 Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch
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
2025-10-21 15:05:17 +00:00
Cristina Horotan aab924e90d Revert "Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch" for causing build bustage at nsBrowserApp.cpp
This reverts commit fd0ffa193c.
2025-10-21 10:44:13 +00:00
serge-sans-paille fd0ffa193c Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch
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
2025-10-21 09:44:11 +00:00
Narcis Beleuzu e1e6bbb1c9 Revert "Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch" for causing bustages on Document.cpp
This reverts commit b23c15e927.
2025-10-21 06:34:58 +00:00
serge-sans-paille b23c15e927 Bug 1994397 - Remove obsolete Unused.h header r=emilio,tschuster,geckoview-reviewers,extension-reviewers,application-update-reviewers,media-playback-reviewers,webrtc-reviewers,cookie-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,permissions-reviewers,profiles-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers,timhuang,gstoll,TravisLong,bytesized,mstange,karlt,robwu,pehrsons,m_kato,jari,jhirsch
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
2025-10-21 06:01:36 +00:00
James Teh 33be2d8c1c Bug 1981794: Always return insertion point bounds for a collapsed UIA text range. r=eeejay
Previously, UIA had its own code to use the caret rect for the end of line insertion point or a line feed at the end of a textarea.
However, this didn't account for an empty text box.
To fix this, now that we have unified code in TextLeafRange to use the insertion point in all cases where it is necessary, use that instead of UIA specific code.
This involved moving the call to TextLeafPoint::InsertionPointBounds from TextLeafRange::Bounds to TextLeafRange::WalkLineRects, since UIA uses TextLeafRange::LineRects, not TextLeafRange::Bounds.

Differential Revision: https://phabricator.services.mozilla.com/D263045
2025-09-01 23:26:39 +00:00
Lando 1d7ee59270 Bug 1979968: apply code formatting via Lando
# ignore-this-changeset
2025-08-21 23:33:36 +00:00
Eitan Isaacson c5a3e5a49f Bug 1979968 - P2: Introduce TextLeafPoint::InsertionPointBounds. r=Jamie
As mentioned in the bug this method does not return bounds for special insertion points.

The bounds are probably correct 90% of the time, the exceptions are transition points in embedded bidi segments,
among other unforseen situations. These edge cases are things we can probably live with for the time being.

This addition also has a few changes:
1. HyperTextAccessible::TextBounds now returns bounds for identical start and end offsets.
2. TextLeafRange::Bounds now returns the insertion point for a collapsed range.
3. The browser caret rect test now uses the insertion point rect to compare against the caret rect.

Differential Revision: https://phabricator.services.mozilla.com/D259134
2025-08-21 23:33:14 +00:00
Cristian Tuns 66586f2499 Revert "Bug 1979968: apply code formatting via Lando" for causing mochitest failures in browser_caret_rect.js
This reverts commit 2f50728070.

Revert "Bug 1979968 - P2: Introduce TextLeafPoint::InsertionPointBounds. r=Jamie"

This reverts commit ab3aada4d7.

Revert "Bug 1979968 - P1: Cache WritingMode. r=Jamie"

This reverts commit 0aaf695894.
2025-08-20 19:03:21 +00:00
Lando 2f50728070 Bug 1979968: apply code formatting via Lando
# ignore-this-changeset
2025-08-20 18:07:32 +00:00
Eitan Isaacson ab3aada4d7 Bug 1979968 - P2: Introduce TextLeafPoint::InsertionPointBounds. r=Jamie
As mentioned in the bug this method does not return bounds for special insertion points.

The bounds are probably correct 90% of the time, the exceptions are transition points in embedded bidi segments,
among other unforseen situations. These edge cases are things we can probably live with for the time being.

This addition also has a few changes:
1. HyperTextAccessible::TextBounds now returns bounds for identical start and end offsets.
2. TextLeafRange::Bounds now returns the insertion point for a collapsed range.
3. The browser caret rect test now uses the insertion point rect to compare against the caret rect.

Differential Revision: https://phabricator.services.mozilla.com/D259134
2025-08-20 18:07:08 +00:00
Cristina Horotan 211b124048 Revert "Bug 1979968: apply code formatting via Lando" for causing ba failures on browser_caret_rect.js
This reverts commit 8a052b055d.

Revert "Bug 1979968 - P2: Introduce TextLeafPoint::InsertionPointBounds. r=Jamie"

This reverts commit a9506fdb9f.

Revert "Bug 1979968 - P1: Cache WritingMode. r=Jamie"

This reverts commit c109d51779.
2025-08-20 00:39:28 +00:00
Lando 8a052b055d Bug 1979968: apply code formatting via Lando
# ignore-this-changeset
2025-08-19 23:47:01 +00:00
Eitan Isaacson a9506fdb9f Bug 1979968 - P2: Introduce TextLeafPoint::InsertionPointBounds. r=Jamie
As mentioned in the bug this method does not return bounds for special insertion points.

The bounds are probably correct 90% of the time, the exceptions are transition points in embedded bidi segments,
among other unforseen situations. These edge cases are things we can probably live with for the time being.

This addition also has a few changes:
1. HyperTextAccessible::TextBounds now returns bounds for identical start and end offsets.
2. TextLeafRange::Bounds now returns the insertion point for a collapsed range.
3. The browser caret rect test now uses the insertion point rect to compare against the caret rect.

Differential Revision: https://phabricator.services.mozilla.com/D259134
2025-08-19 23:46:40 +00:00
James Teh c52d35d7d5 Bug 1976574 part 2: Expose a TextLeafAccessible for CSS alt content when the CSS content is the empty string. r=eeejay
For example: `content: "" / "alt"`

In this case, a pseudo-element is created, but there is no text child.
Previously, we only exposed CSS alt content for a pseudo-element on its child.
To fix this:

1. Teach CssAltContent to work when a pseudo-element itself is provided, not just a pseudo-element's child.
  If a pseudo-element *does* have a child, we ignore the pseudo-element itself because we still want to use the child where possible.
  A pseudo-element itself is not a replaced element, so we also need to skip the frame IsReplaced check for this case.
2. Create a TextLeafAccessible for a pseudo-element itself if appropriate; i.e. it has no children and has CSS alt text.
3. Don't assume that a TextLeafAccessible is backed by a DOM text node in TextLeafRange code, since a TextLeafAccessible might now have a pseudo-element as its DOM node.
4. Teach TextLeafAccessible to return role STATICTEXT if its node is a pseudo-element.

Differential Revision: https://phabricator.services.mozilla.com/D256946
2025-07-23 07:41:56 +00:00
James Teh fce9be89e6 Bug 1977292: GetTextAttributesLocalAcc: Handle the rare case that a client query arrives after the Accessible has been detached from the document but before it is shut down. r=morgan
Differential Revision: https://phabricator.services.mozilla.com/D257212
2025-07-15 21:37:32 +00:00
James Teh 655e5cc576 Bug 1950748 part 3: Don't return a caret inside an editor when no editor is focused. r=morgan
See the code comments for details.

Differential Revision: https://phabricator.services.mozilla.com/D256399
2025-07-14 01:41:01 +00:00
James Teh 9fc540cebb Bug 1950748 part 2: Remove some dead code and add an assertion. r=morgan
As of bug 1901457, the TextLeafPoint constructor can no longer receive TEXT_OFFSET_CARET.
However, a related check was never removed from the constructor.
Remove this check and assert that this offset is never provided.
This is just a correctness fix that makes the code easier to reason about.

Differential Revision: https://phabricator.services.mozilla.com/D256398
2025-07-14 01:40:58 +00:00
Serban Stanca 8094901790 Revert "Bug 1950748 part 3: Don't return a caret inside an editor when no editor is focused. r=morgan" as requested for causing accessibility crashes (bug 1977012).
This reverts commit aaf970807d.

This reverts commit f5f2e3cf4d.

This reverts commit 5565c5899c.
2025-07-13 21:40:23 +00:00
James Teh aaf970807d Bug 1950748 part 3: Don't return a caret inside an editor when no editor is focused. r=morgan
See the code comments for details.

Differential Revision: https://phabricator.services.mozilla.com/D256399
2025-07-11 06:33:39 +00:00
James Teh f5f2e3cf4d Bug 1950748 part 2: Remove some dead code and add an assertion. r=morgan
As of bug 1901457, the TextLeafPoint constructor can no longer receive TEXT_OFFSET_CARET.
However, a related check was never removed from the constructor.
Remove this check and assert that this offset is never provided.
This is just a correctness fix that makes the code easier to reason about.

Differential Revision: https://phabricator.services.mozilla.com/D256398
2025-07-11 06:33:36 +00:00
James Teh 196046a546 Bug 1958766: Don't change the focus when moving the caret with UIA. r=eeejay
In bug 1951573, I unified the code for setting the caret.
This includes focusing the node at the caret.
Unfortunately, Windows Narrator behaves badly if the focus is changed as a result of setting the caret.
Chromium doesn't move the focus if the caret is moved via UIA, even though it does for caret navigation like Firefox.
ATK in particular still wants the focus to be changed.
Therefore, add an aSetFocus argument to TextLeafRange::SetSelection so this can be configured by the caller.
Change UIA to specify aSetFocus = false.

Differential Revision: https://phabricator.services.mozilla.com/D252030
2025-06-05 02:32:19 +00:00
James Teh f66cf4466a Bug 1951833 part 1: Support line feed characters in TextLeafPoint::CharBounds. r=morgan
Previously, both literal line feed characters in pre-formatted text and HTMl <br> elements returned a rect with 0 width and/or height.
Because of the way CharBounds() was implemented, this also returned 0 for x and y.
This caused problems for clients such as Windows Text Cursor Indicator which need the rectangle for the character at the caret.
Now, we return the correct x and y coordinates.
We also return a minimum width and height of 1 to ensure clients treat it as an actual rectangle.

As part of this, CharBounds() has been refactored slightly for consistency and readability.
As a bonus, this also fixes character bounds for list item bullets (bug 360003), but a test for that will be added in a subsequent patch.

This patch also removes the special case line feed code added to TextLeafRange::WalkLineRects() in bug 1946552, since CharBounds() now handles this.

Differential Revision: https://phabricator.services.mozilla.com/D249709
2025-05-20 23:01:19 +00:00
James Teh 37f125f5e9 Bug 1965607: Gracefully handle anonymous children in TextLeafPoint::ToDOMPoint. r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D248723
2025-05-13 04:53:51 +00:00
James Teh c1029be8ea Bug 1869971: When calculating a DOM point for the end of a non-text node, use the child index for the node after that node. r=eeejay
A TextLeafPoint is always a leaf Accessible and an offset within that Accessible.
When a TextLeafPoint is created for the end of a container and the last Accessible in the container isn't text (e.g. it is an image), TextLeafPoint represents this as offset 1 within the image.
When calculating a DOM point for such a TextLeafPoint, we need to use the child index for the next DOM node.
This indicates to DOM that the point should be positioned after the node.

Differential Revision: https://phabricator.services.mozilla.com/D247874
2025-05-07 04:30:12 +00:00
James Teh 123bc5b115 Bug 1869966 part 3: When calculating a DOM point from a TextLeafPoint for a non-text node, use the child index within the parent, not an offset within the node itself. r=eeejay
For text nodes, DOM points use the character offset within the node itself, just like accessibility does.
For non-text nodes, DOM points use the child index within the parent to specify the position before or after the node.
Previously, TextLeafPoint::ToDOMPoint always used an offset within the node itself.
This meant that when the (exclusive) end point of a range was an image, we converted to a DOM point of offset 0 within the image.
As far as DOM is concerned, this includes the image.
This patch adjusts ToDOMPoint as appropriate.

As part of this, ToDOMPoint now returns a uint32_t instead of an int32_t.
This is because DOM offsets are actually uint32_t and calculating int32_t child indices is deprecated.

Differential Revision: https://phabricator.services.mozilla.com/D247873
2025-05-06 23:12:52 +00:00
James Teh 61546d6b1d Bug 1950740 part 2: TextLeafPoint::GetCaret: Don't assume that CaretAssociationHint::Before means the caret is at the end of a line anywhere but the start of a node. r=morgan
I previously thought that CaretAssociationHint::Before was only used either at the start of a node or at the end of a line.
However, it can also be used if the user clicks any character other than the first in a text node.
To fix this, check if we're at the start of a line for all offsets, not just offset 0.
I didn't do this originally in an attempt to reduce the cases where we must search for lines, but it seems this is unavoidable.
If we run into performance problems here, we might be able to restrict this check to cases where we're at the start of a layout frame.
However, that significantly complicates the code, I'm not entirely certain it will work and it is likely premature optimisation, so I opted not to do that in this patch.

Differential Revision: https://phabricator.services.mozilla.com/D241770
2025-03-18 04:17:33 +00:00
James TehandNathan LaPre e5e9bc657c Bug 1946552: Fix problems and inconsistencies in the calculation of text bounds for a range. r=morgan
There are multiple problems and inconsistencies in the way we previously calculated text bounds in various places:

1. TextLeafRange::WalkLineRects and TextLeafRange::Bounds calculated bounds inclusive of the range end. However, everywhere else, range ends are exclusive.
2. To compensate for this, HyperTextAccessibleBase::TextBounds walked back 1 character from the end before calling TextLeafRange::Bounds. However, other callers (UIA and Mac) didn't do this. Including the range end meant we included the bounds for an additional character or even an entire line in some cases.
3. When lines end with a line feed character, we tried to include this in the bounds calculation. Since line feeds have a 0 rect, this messed up the calculation.
4. Even though WalkLineRects constrained line bounds to the end of the range, the provided sub-ranges were not constrained.

To fix these problems, TextLeafRange::WalkLineRects and TextLeafRange::Bounds now explicitly return bounds and sub-ranges constrained to, but exclusive of, the end of the range.
HyperTextAccessibleBase::TextBounds has been updated accordingly.
The line feed character is ignored when calculating line bounds.

Co-authored-by: Nathan LaPre <[email protected]>

Differential Revision: https://phabricator.services.mozilla.com/D237142
2025-03-14 21:37:47 +00:00
James Teh 4c17052376 Bug 1951573 part 2: Make TextLeafRange::SetSelection perform additional tasks to ensure the selection is set correctly. r=eeejay
HyperTextAccessible::SetSelectionRange (used by SetCaretOffset) performed these tasks, but TextLeafRange::SetSelection didn't.
This meant that the behaviour when setting the caret or selection was different for different OS APIs: IA2 and ATK use HyperTextAccessible::SetCaretOffset, while Mac and UIA use TextLeafRange::SetSelection.
While we aren't aware of any specific bugs impacting users, this is confusing at best and might result in obscure bugs in future.
See the code comments for details.

Differential Revision: https://phabricator.services.mozilla.com/D240275
2025-03-05 23:42:51 +00:00
James Teh a0ea824b48 Bug 1951573 part 1: Make it possible to remove all existing selections when calling TextLeafRange::SetSelection. r=eeejay
Previously, a caller had to first retrieve all selection ranges and then remove them individually.
This makes it awkward to perform a fairly common operation.

Differential Revision: https://phabricator.services.mozilla.com/D240274
2025-03-05 23:42:50 +00:00
Sandor Molnar 8f58d561a2 Backed out changeset 0a39b47ae3c2 (bug 1946552) for causing mochitest failures @ accessible/tests/browser/bounds/browser_test_zoom_text.js & browser_caching_text_bounds.js CLOSED TREE 2025-02-11 08:46:33 +02:00