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
()
| 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 |
no test coverage detected