Example usage for org.w3c.dom.stylesheets MediaList getLength

List of usage examples for org.w3c.dom.stylesheets MediaList getLength

Introduction

In this page you can find the example usage for org.w3c.dom.stylesheets MediaList getLength.

Prototype

public int getLength();

Source Link

Document

The number of media in the list.

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.java

/**
 * Returns whether the specified {@link MediaList} is active or not.
 * @param scriptable the scriptable/*from  w w w .j a  va 2  s.c o  m*/
 * @param mediaList the media list
 * @return whether the specified {@link MediaList} is active or not
 */
static boolean isActive(final SimpleScriptable scriptable, final MediaList mediaList) {
    if (mediaList.getLength() == 0) {
        return true;
    }

    for (int i = 0; i < mediaList.getLength(); i++) {
        final MediaQuery mediaQuery = ((MediaListImpl) mediaList).mediaQuery(i);
        boolean isActive = isActive(scriptable, mediaQuery);
        if (mediaQuery.isNot()) {
            isActive = !isActive;
        }
        if (isActive) {
            return true;
        }
    }
    return false;
}