Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions javascript/atoms/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,12 @@ bot.dom.getCascadedStyle_ = function (elem, styleName) {
* @param {!Element} elem The element to consider.
* @param {boolean} ignoreOpacity Whether to ignore the element's opacity
* when determining whether it is shown.
* @param {function(!Element):boolean} parentsDisplayedFn a function that's used
* to tell if the chain of ancestors are all shown.
* @param {function(!Element):boolean} displayedFn a function that's used
* to tell if the chain of ancestors or descendants are all shown.
* @return {boolean} Whether or not the element is visible.
* @private
*/
bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
bot.dom.isShown_ = function (elem, ignoreOpacity, displayedFn) {
if (!bot.dom.isElement(elem)) {
throw new Error('Argument to isShown must be of type Element');
}
Expand All @@ -476,7 +476,7 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
var select = /**@type {Element}*/ (goog.dom.getAncestor(elem, function (e) {
return bot.dom.isElement(e, goog.dom.TagName.SELECT);
}));
return !!select && bot.dom.isShown_(select, true, parentsDisplayedFn);
return !!select && bot.dom.isShown_(select, true, displayedFn);
}

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

// Any hidden input is not shown.
Expand All @@ -506,7 +506,7 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
return false;
}

if (!parentsDisplayedFn(elem)) {
if (!displayedFn(elem)) {
return false;
}

Expand All @@ -527,6 +527,16 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
var strokeWidth = bot.dom.getEffectiveStyle(e, 'stroke-width');
return !!strokeWidth && (parseInt(strokeWidth, 10) > 0);
}

// Any element with hidden/collapsed visibility is not shown.
var visibility = bot.dom.getEffectiveStyle(e, 'visibility');
if (visibility == 'collapse' || visibility == 'hidden') {
return false;
}

if (!displayedFn(e)) {
return false;
}
// Zero-sized elements should still be considered to have positive size
// if they have a child element or text node with positive size, unless
// the element has an 'overflow' style of 'hidden'.
Expand Down Expand Up @@ -572,7 +582,7 @@ bot.dom.isShown_ = function (elem, ignoreOpacity, parentsDisplayedFn) {
*/
bot.dom.isShown = function (elem, opt_ignoreOpacity) {
/**
* Determines whether an element or its parents have `display: none` set
* Determines whether an element or its parents have `display: none` or similar CSS properties set
* @param {!Node} e the element
* @return {!boolean}
*/
Expand Down
9 changes: 9 additions & 0 deletions javascript/atoms/test/shown_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@
assertFalse(isShown(content));
assertFalse(isShown(findElement({ id: 'b' }, content)));
}

function testNestedTextNode() {
var content = findElement({ id: 'nestedTextNode' });
assertFalse(isShown(content));
}
</script>

<style type="text/css">
Expand Down Expand Up @@ -659,6 +664,10 @@
<div id='b'>B</div>
</div>

<div id='nestedTextNode' style='width: 0px; overflow: visible'>
<div style="display: none;">text</div>
</div>

</body>

</html>
Loading