MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / isDisplayed

Method isDisplayed

src/main/java/org/htmlunit/html/DomNode.java:685–736  ·  view source on GitHub ↗

Returns true if this node is displayed and can be visible to the user (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes). NOTE: If CSS is org.htmlunit.WebClientOptions#setCssEnabled(boolean) disabled, this method does not ta

()

Source from the content-addressed store, hash-verified

683 * @see #mayBeDisplayed()
684 */
685 public boolean isDisplayed() {
686 if (!mayBeDisplayed()) {
687 return false;
688 }
689
690 final Page page = getPage();
691 final WebWindow window = page.getEnclosingWindow();
692 final WebClient webClient = window.getWebClient();
693 if (webClient.getOptions().isCssEnabled()) {
694 // display: iterate top to bottom, because if a parent is display:none,
695 // there's nothing that a child can do to override it
696 final List<Node> ancestors = getAncestors();
697 final ArrayList<ComputedCssStyleDeclaration> styles = new ArrayList<>(ancestors.size());
698
699 for (final Node node : ancestors) {
700 if (node instanceof HtmlElement elem) {
701 if (elem.isHidden()) {
702 return false;
703 }
704
705 if (elem instanceof HtmlDialog dialog) {
706 if (!dialog.isOpen()) {
707 return false;
708 }
709 }
710 else {
711 final ComputedCssStyleDeclaration style = window.getComputedStyle(elem, null);
712 if (DisplayStyle.NONE.value().equals(style.getDisplay())) {
713 return false;
714 }
715 styles.add(style);
716 }
717 }
718 }
719
720 // visibility: iterate bottom to top, because children can override
721 // the visibility used by parent nodes
722 for (int i = styles.size() - 1; i >= 0; i--) {
723 final ComputedCssStyleDeclaration style = styles.get(i);
724 final String visibility = style.getStyleAttribute(StyleAttributes.Definition.VISIBILITY, true);
725 if (visibility.length() > 5) {
726 if ("visible".equals(visibility)) {
727 return true;
728 }
729 if ("hidden".equals(visibility) || "collapse".equals(visibility)) {
730 return false;
731 }
732 }
733 }
734 }
735 return true;
736 }
737
738 /**
739 * Returns {@code true} if nodes of this type can ever be displayed, {@code false} otherwise. Examples of nodes

Callers 6

isDisplayedMethod · 0.95
appendTextMethod · 0.95
getSelectionMethod · 0.45
clickMethod · 0.45
focusMethod · 0.45

Calls 15

mayBeDisplayedMethod · 0.95
getPageMethod · 0.95
getEnclosingWindowMethod · 0.95
getWebClientMethod · 0.95
getOptionsMethod · 0.95
getAncestorsMethod · 0.95
getComputedStyleMethod · 0.95
getDisplayMethod · 0.95
getStyleAttributeMethod · 0.95
isCssEnabledMethod · 0.80
lengthMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected