From a019566c16b9502bf303cbc514d000f50a28f981 Mon Sep 17 00:00:00 2001 From: Marian-Vasile Laza Date: Wed, 23 Mar 2022 00:03:11 -0700 Subject: [PATCH] Backed out changeset 60cf5a19aa68 (bug 1550644) for causing bc failures on browser_autocomplete_a11y_label.js. --- accessible/base/nsTextEquivUtils.cpp | 50 +++++++++---------- .../tests/mochitest/name/test_general.html | 27 ++-------- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/accessible/base/nsTextEquivUtils.cpp b/accessible/base/nsTextEquivUtils.cpp index d2985c940841..e693bb349f49 100644 --- a/accessible/base/nsTextEquivUtils.cpp +++ b/accessible/base/nsTextEquivUtils.cpp @@ -105,6 +105,26 @@ nsresult nsTextEquivUtils::AppendTextEquivFromContent( nsresult nsTextEquivUtils::AppendTextEquivFromTextContent(nsIContent* aContent, nsAString* aString) { if (aContent->IsText()) { + bool isHTMLBlock = false; + + nsIContent* parentContent = aContent->GetFlattenedTreeParent(); + if (parentContent) { + nsIFrame* frame = parentContent->GetPrimaryFrame(); + if (frame) { + // If this text is inside a block level frame (as opposed to span + // level), we need to add spaces around that block's text, so we don't + // get words jammed together in final name. + const nsStyleDisplay* display = frame->StyleDisplay(); + if (display->IsBlockOutsideStyle() || + display->mDisplay == StyleDisplay::TableCell) { + isHTMLBlock = true; + if (!aString->IsEmpty()) { + aString->Append(char16_t(' ')); + } + } + } + } + if (aContent->TextLength() > 0) { nsIFrame* frame = aContent->GetPrimaryFrame(); if (frame) { @@ -116,6 +136,9 @@ nsresult nsTextEquivUtils::AppendTextEquivFromTextContent(nsIContent* aContent, // If aContent is an object that is display: none, we have no a frame. aContent->GetAsText()->AppendTextTo(*aString); } + if (isHTMLBlock && !aString->IsEmpty()) { + aString->Append(char16_t(' ')); + } } return NS_OK; @@ -161,27 +184,10 @@ nsresult nsTextEquivUtils::AppendFromAccessibleChildren( nsresult nsTextEquivUtils::AppendFromAccessible(Accessible* aAccessible, nsAString* aString) { // XXX: is it necessary to care the accessible is not a document? - bool isHTMLBlock = false; if (aAccessible->IsLocal() && aAccessible->AsLocal()->IsContent()) { - nsIContent* content = aAccessible->AsLocal()->GetContent(); - nsresult rv = AppendTextEquivFromTextContent(content, aString); + nsresult rv = AppendTextEquivFromTextContent( + aAccessible->AsLocal()->GetContent(), aString); if (rv != NS_OK_NO_NAME_CLAUSE_HANDLED) return rv; - if (!content->IsText()) { - nsIFrame* frame = content->GetPrimaryFrame(); - if (frame) { - // If this is a block level frame (as opposed to span level), we need to - // add spaces around that block's text, so we don't get words jammed - // together in final name. - const nsStyleDisplay* display = frame->StyleDisplay(); - if (display->IsBlockOutsideStyle() || - display->mDisplay == StyleDisplay::TableCell) { - isHTMLBlock = true; - if (!aString->IsEmpty()) { - aString->Append(char16_t(' ')); - } - } - } - } } bool isEmptyTextEquiv = true; @@ -214,15 +220,9 @@ nsresult nsTextEquivUtils::AppendFromAccessible(Accessible* aAccessible, // Implementation of h. step if (isEmptyTextEquiv && !text.IsEmpty()) { AppendString(aString, text); - if (isHTMLBlock) { - aString->Append(char16_t(' ')); - } return NS_OK; } - if (!isEmptyTextEquiv && isHTMLBlock) { - aString->Append(char16_t(' ')); - } return rv; } diff --git a/accessible/tests/mochitest/name/test_general.html b/accessible/tests/mochitest/name/test_general.html index 89314712fb0b..552929893625 100644 --- a/accessible/tests/mochitest/name/test_general.html +++ b/accessible/tests/mochitest/name/test_general.html @@ -58,9 +58,10 @@ // spaces) testName("btn_labelledby_mixed_block", "text more text"); - // Gets the name from text nodes contained by html:td. The text nodes - // should not be divided by spaces. - testName("btn_labelledby_mixed_table", "textTEXTtext"); + // Gets the name from text nodes contained by html:td (every text node + // value in the name should be devided by spaces). + // XXX: this case is rather a feature than strong wanted behaviour. + testName("btn_labelledby_mixed_table", "text space text"); // Gets the name from image accessible. testName("btn_labelledby_mixed_img", "text image"); @@ -250,17 +251,6 @@ // Name from subtree of grouping labelled by an ancestor. testName("grouping_labelledby_ancestor", "label"); - // Name from subtree of a container containing text nodes and inline - // elements. There should be no spaces because everyhing is inline. - testName("container_text_inline", "abc"); - // Name from subtree of a container containing text nodes and block - // elements. There should be a space on both sides of the block. - testName("container_text_block", "a b c"); - // Name from subtree of a container containing text nodes and empty - // block elements. There should be space on either side of the blocks, but - // not a double space. - testName("container_text_emptyblock", "a b"); - SimpleTest.finish(); } @@ -397,7 +387,7 @@ - +
textTEXTtexttextspacetext
@@ -721,12 +711,5 @@ This content should not be included in the grouping's label. - - -
abc
- -
a

b

c
- -
a

b