Bug 1484855: Match the 'is rendered' definition from the spec in innerText. r=smaug

This matches other implementations and the spec for fallback content like:

  <canvas><div>abc

(calling div.innerText).

We're treating the <div> as 'rendered' because it's not in a display: none
subtree, but that's not ok, since it is in fact not rendered.

This was added in bug 1226293, and Boris suggested this change, but roc opposed
because it'd be hard to spec properly in comment 15. Looks like the HTML spec
ended up merging roc's innerText spec, and now it's spec'd in terms of 'being
rendered'.

I think IsOrHasAncestorWithDisplayNone just doesn't work in any reasonable way
for stuff out of the flat tree. Thus I think this change is the right thing.

The canvas test fails because of bug 1485076.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2018-08-22 09:05:09 +00:00
Родитель ac0adb0b5e
Коммит 19b0bfc00d
3 изменённых файлов: 16 добавлений и 10 удалений

Просмотреть файл

@ -2894,10 +2894,13 @@ nsGenericHTMLElement::NewURIFromString(const nsAString& aURISpec,
return NS_OK;
}
static bool
IsOrHasAncestorWithDisplayNone(Element* aElement)
// https://html.spec.whatwg.org/#being-rendered
//
// With a gotcha for display contents:
// https://github.com/whatwg/html/issues/3947
static bool IsRendered(const Element& aElement)
{
return !aElement->HasServoData() || Servo_Element_IsDisplayNone(aElement);
return aElement.GetPrimaryFrame() || aElement.IsDisplayContents();
}
void
@ -2958,7 +2961,7 @@ nsGenericHTMLElement::GetInnerText(mozilla::dom::DOMString& aValue,
doc->FlushPendingNotifications(FlushType::Layout);
}
if (IsOrHasAncestorWithDisplayNone(this)) {
if (!IsRendered(*this)) {
GetTextContentInternal(aValue, aError);
} else {
nsRange::GetInnerTextNoFlush(aValue, aError, this);

Просмотреть файл

@ -1,4 +1,7 @@
[getter.html]
[<canvas><div id='target'> contents ok for element not being rendered ("<canvas><div id='target'>abc")]
expected: FAIL
[<rp> ("<div><ruby>abc<rp>(</rp><rt>def</rt><rp>)</rp></ruby>")]
expected: FAIL

Просмотреть файл

@ -75,7 +75,7 @@ testText("<div style='display:none'>abc def", "abc def", "No whitespace compre
testText("<div style='display:none'> abc def ", " abc def ", "No removal of leading/trailing whitespace in display:none container");
testText("<div>123<span style='display:none'>abc", "123", "display:none child not rendered");
testText("<div style='display:none'><span id='target'>abc", "abc", "display:none container with non-display-none target child");
testTextInSVG("<div id='target'>abc", "", "non-display-none child of svg");
testTextInSVG("<div id='target'>abc", "abc", "non-display-none child of svg");
testTextInSVG("<div style='display:none' id='target'>abc", "abc", "display:none child of svg");
testTextInSVG("<div style='display:none'><div id='target'>abc", "abc", "child of display:none child of svg");
@ -132,13 +132,13 @@ testText("<iframe>abc", "", "<iframe> contents ignored");
testText("<iframe><div id='target'>abc", "", "<iframe> contents ignored");
testText("<iframe src='data:text/html,abc'>", "","<iframe> subdocument ignored");
testText("<audio style='display:block'>abc", "", "<audio> contents ignored");
testText("<audio style='display:block'><source id='target' class='poke' style='display:block'>", "", "<audio> contents ignored");
testText("<audio style='display:block'><source id='target' class='poke' style='display:none'>", "abc", "<audio> contents ok if display:none");
testText("<audio style='display:block'><source id='target' class='poke' style='display:block'>", "abc", "<audio> contents ok for element not being rendered");
testText("<audio style='display:block'><source id='target' class='poke' style='display:none'>", "abc", "<audio> contents ok for element not being rendered");
testText("<video>abc", "", "<video> contents ignored");
testText("<video style='display:block'><source id='target' class='poke' style='display:block'>", "", "<video> contents ignored");
testText("<video style='display:block'><source id='target' class='poke' style='display:none'>", "abc", "<video> contents ok if display:none");
testText("<video style='display:block'><source id='target' class='poke' style='display:block'>", "abc", "<video> contents ok for element not being rendered");
testText("<video style='display:block'><source id='target' class='poke' style='display:none'>", "abc", "<video> contents ok for element not being rendered");
testText("<canvas>abc", "", "<canvas> contents ignored");
testText("<canvas><div id='target'>abc", "", "<canvas><div id='target'> contents ignored");
testText("<canvas><div id='target'>abc", "abc", "<canvas><div id='target'> contents ok for element not being rendered");
testText("<img alt='abc'>", "", "<img> alt text ignored");
testText("<img src='about:blank' class='poke'>", "", "<img> contents ignored");