tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit f4606a96abbf412709b9b8d8696c48844f48ef09
parent c550000d83525bfe61795bd2c26e2fc901223b60
Author: Eitan Isaacson <eitan@monotonous.org>
Date:   Fri, 14 Nov 2025 15:59:37 +0000

Bug 1999388 - Don't delimit generated alt content with space when the content is empty. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D272088

Diffstat:
Maccessible/base/nsTextEquivUtils.cpp | 25++++++++++++++++---------
Maccessible/tests/browser/tree/browser_css_alt.js | 2+-
2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/accessible/base/nsTextEquivUtils.cpp b/accessible/base/nsTextEquivUtils.cpp @@ -173,18 +173,25 @@ nsresult nsTextEquivUtils::AppendTextEquivFromContent( nsresult nsTextEquivUtils::AppendTextEquivFromTextContent(nsIContent* aContent, nsAString* aString) { - if (aContent->IsText()) { + if (auto cssAlt = CssAltContent(aContent)) { + AccType type = aContent->GetPrimaryFrame() + ? aContent->GetPrimaryFrame()->AccessibleType() + : AccType::eNoType; + if (type == AccType::eNoType || type == AccType::eTextLeafType) { + // If this is a text leaf, or an empty content, append its alt text here. + // In the case of image alt contents, we will get to those with the + // accessible based subtree name calculation. + cssAlt.AppendToString(*aString); + return NS_OK; + } + } else if (aContent->IsText()) { if (aContent->TextLength() > 0) { nsIFrame* frame = aContent->GetPrimaryFrame(); if (frame) { - if (auto cssAlt = CssAltContent(aContent)) { - cssAlt.AppendToString(*aString); - } else { - nsIFrame::RenderedText text = frame->GetRenderedText( - 0, UINT32_MAX, nsIFrame::TextOffsetType::OffsetsInContentText, - nsIFrame::TrailingWhitespace::DontTrim); - aString->Append(text.mString); - } + nsIFrame::RenderedText text = frame->GetRenderedText( + 0, UINT32_MAX, nsIFrame::TextOffsetType::OffsetsInContentText, + nsIFrame::TrailingWhitespace::DontTrim); + aString->Append(text.mString); } else { // If aContent is an object that is display: none, we have no a frame. aContent->GetAsText()->AppendTextTo(*aString); diff --git a/accessible/tests/browser/tree/browser_css_alt.js b/accessible/tests/browser/tree/browser_css_alt.js @@ -280,7 +280,7 @@ addAccessibleTask( const empty = findAccessibleChildByID(docAcc, "empty"); testAccessibleTree(empty, { role: ROLE_HEADING, - name: "inside alt", + name: "insidealt", children: [ { role: ROLE_TEXT_LEAF, name: "inside" }, { role: ROLE_STATICTEXT, name: "alt" },