Skip to content

Commit db9982e

Browse files
committed
[atoms] fix text node children are allways considered as displayed #16284
1 parent 29af98d commit db9982e

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

javascript/atoms/dom.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,12 @@ bot.dom.getCascadedStyle_ = function (elem, styleName) {
452452
* @param {!Element} elem The element to consider.
453453
* @param {boolean} ignoreOpacity Whether to ignore the element's opacity
454454
* when determining whether it is shown.
455-
* @param {function(!Element):boolean} parentsDisplayedFn a function that's used
456-
* to tell if the chain of ancestors are all shown.
455+
* @param {function(!Element):boolean} displayedFn a function that's used
456+
* to tell if the chain of ancestors or descendants are all shown.
457457
* @return {boolean} Whether or not the element is visible.
458458
* @private
459459
*/
460-
bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
460+
bot.dom.isShown_ = function (elem, ignoreOpacity, displayedFn) {
461461
if (!bot.dom.isElement(elem)) {
462462
throw new Error('Argument to isShown must be of type Element');
463463
}
@@ -476,7 +476,7 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
476476
var select = /**@type {Element}*/ (goog.dom.getAncestor(elem, function (e) {
477477
return bot.dom.isElement(e, goog.dom.TagName.SELECT);
478478
}));
479-
return !!select && bot.dom.isShown_(select, true, parentsDisplayedFn);
479+
return !!select && bot.dom.isShown_(select, true, displayedFn);
480480
}
481481

482482
// Image map elements are shown if image that uses it is shown, and
@@ -486,7 +486,7 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
486486
return !!imageMap.image &&
487487
imageMap.rect.width > 0 && imageMap.rect.height > 0 &&
488488
bot.dom.isShown_(
489-
imageMap.image, ignoreOpacity, parentsDisplayedFn);
489+
imageMap.image, ignoreOpacity, displayedFn);
490490
}
491491

492492
// Any hidden input is not shown.
@@ -500,13 +500,7 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
500500
return false;
501501
}
502502

503-
// Any element with hidden/collapsed visibility is not shown.
504-
var visibility = bot.dom.getEffectiveStyle(elem, 'visibility');
505-
if (visibility == 'collapse' || visibility == 'hidden') {
506-
return false;
507-
}
508-
509-
if (!parentsDisplayedFn(elem)) {
503+
if (!displayedFn(elem)) {
510504
return false;
511505
}
512506

@@ -527,6 +521,9 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
527521
var strokeWidth = bot.dom.getEffectiveStyle(e, 'stroke-width');
528522
return !!strokeWidth && (parseInt(strokeWidth, 10) > 0);
529523
}
524+
if (!displayedFn(e)) {
525+
return false;
526+
}
530527
// Zero-sized elements should still be considered to have positive size
531528
// if they have a child element or text node with positive size, unless
532529
// the element has an 'overflow' style of 'hidden'.
@@ -572,14 +569,17 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
572569
*/
573570
bot.dom.isShown = function (elem, opt_ignoreOpacity) {
574571
/**
575-
* Determines whether an element or its parents have `display: none` set
572+
* Determines whether an element or its parents have `display: none` or similar CSS properties set
576573
* @param {!Node} e the element
577574
* @return {!boolean}
578575
*/
579576
function displayed(e) {
580577
if (bot.dom.isElement(e)) {
581578
var elem = /** @type {!Element} */ (e);
582579
if ((bot.dom.getEffectiveStyle(elem, 'display') == 'none')
580+
// Any element with hidden/collapsed visibility is not shown.
581+
|| (bot.dom.getEffectiveStyle(elem, 'visibility') == 'hidden')
582+
|| (bot.dom.getEffectiveStyle(elem, 'visibility') == 'collapse')
583583
|| (bot.dom.getEffectiveStyle(elem, 'content-visibility') == 'hidden')) {
584584
return false;
585585
}

javascript/atoms/test/shown_test.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@
414414
assertFalse(isShown(content));
415415
assertFalse(isShown(findElement({ id: 'b' }, content)));
416416
}
417+
418+
function testNestedTextNode() {
419+
var content = findElement({ id: 'nestedTextNode' });
420+
assertFalse(isShown(content));
421+
}
417422
</script>
418423

419424
<style type="text/css">
@@ -659,6 +664,10 @@
659664
<div id='b'>B</div>
660665
</div>
661666

667+
<div id='nestedTextNode' style='width: 0px; overflow: visible'>
668+
<div style="display: none;">text</div>
669+
</div>
670+
662671
</body>
663672

664673
</html>

0 commit comments

Comments
 (0)