类org.w3c.dom.stylesheets.MediaList源码实例Demo

下面列出了怎么用org.w3c.dom.stylesheets.MediaList的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: HtmlUnit-Android   文件: StyleSheetList.java
/**
 * Verifies if the provided node is a link node pointing to an active stylesheet.
 *
 * @param domNode the mode to check
 * @return true if the provided node is a stylesheet link
 */
public boolean isActiveStyleSheetLink(final DomNode domNode) {
    if (domNode instanceof HtmlLink) {
        final HtmlLink link = (HtmlLink) domNode;
        String rel = link.getRelAttribute();
        if (rel != null) {
            rel = rel.trim();
        }
        if ("stylesheet".equalsIgnoreCase(rel)) {
            final String media = link.getMediaAttribute();
            if (StringUtils.isBlank(media)) {
                return true;
            }
            final WebClient webClient = getWindow().getWebWindow().getWebClient();
            final MediaList mediaList = CSSStyleSheet.parseMedia(webClient.getCssErrorHandler(), media);
            return CSSStyleSheet.isActive(this, mediaList);
        }
    }
    return false;
}
 
源代码2 项目: HtmlUnit-Android   文件: CSSStyleSheet.java
/**
 * Parses the given media string. If anything at all goes wrong, this
 * method returns an empty MediaList list.
 *
 * @param source the source from which to retrieve the media to be parsed
 * @return the media parsed from the specified input source
 */
static MediaList parseMedia(final CSSErrorHandler errorHandler, final String mediaString) {
    MediaList media = media_.get(mediaString);
    if (media != null) {
        return media;
    }

    try {
        final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
        parser.setErrorHandler(errorHandler);

        final InputSource source = new InputSource(new StringReader(mediaString));
        media = new MediaListImpl(parser.parseMedia(source));
        if (media != null) {
            media_.put(mediaString, media);
            return media;
        }
    }
    catch (final Exception e) {
        LOG.error("Error parsing CSS media from '" + mediaString + "': " + e.getMessage(), e);
    }

    media = new MediaListImpl(null);
    media_.put(mediaString, media);
    return media;
}
 
源代码3 项目: HtmlUnit-Android   文件: CSSStyleSheet.java
/**
 * Returns {@code true} if this stylesheet is active, based on the media types it is associated with (if any).
 * @return {@code true} if this stylesheet is active, based on the media types it is associated with (if any)
 */
public boolean isActive() {
    final String media;
    final HtmlElement e = ownerNode_.getDomNodeOrNull();
    if (e instanceof HtmlStyle) {
        final HtmlStyle style = (HtmlStyle) e;
        media = style.getMediaAttribute();
    }
    else if (e instanceof HtmlLink) {
        final HtmlLink link = (HtmlLink) e;
        media = link.getMediaAttribute();
    }
    else {
        return true;
    }

    if (StringUtils.isBlank(media)) {
        return true;
    }

    final WebClient webClient = getWindow().getWebWindow().getWebClient();
    final MediaList mediaList = parseMedia(webClient.getCssErrorHandler(), media);
    return isActive(this, mediaList);
}
 
private void fixPotentialEmptyMaskedMediaRule(ICSSNode node) {
  CSSMediaRule mediaRule = (CSSMediaRule) node;
  IndexedRegion mediaRuleRegion = (IndexedRegion) mediaRule;

  if (!containsEmptyMaskedMediaRule(mediaRule, mediaRuleRegion)) {
    return;
  }

  // Set the range to a valid value (it won't be proper since we don't have
  // any additional words that can be categorized as CSS_MEDIUM.)
  MediaList mediaList = mediaRule.getMedia();
  IStructuredDocumentRegion[] structuredDocumentRegions = structuredDocument.getStructuredDocumentRegions(
      mediaRuleRegion.getStartOffset(), mediaRuleRegion.getLength());

  // The value we set is a 0-length region starting where the next word would
  // have been
  ITextRegion textRegion = new ContextRegion(CSSRegionContexts.CSS_MEDIUM,
      structuredDocumentRegions[0].getEndOffset()
          - structuredDocumentRegions[0].getStartOffset(), 0, 0);

  try {
    callSetRangeRegion(mediaList, structuredDocumentRegions, textRegion);
  } catch (Throwable e) {
    GWTPluginLog.logError(e, "Could not clean up the @else in the CSS model.");
  }
}
 
private void fixPotentialEmptyMaskedMediaRule(ICSSNode node) {
  CSSMediaRule mediaRule = (CSSMediaRule) node;
  IndexedRegion mediaRuleRegion = (IndexedRegion) mediaRule;

  if (!containsEmptyMaskedMediaRule(mediaRule, mediaRuleRegion)) {
    return;
  }

  // Set the range to a valid value (it won't be proper since we don't have
  // any additional words that can be categorized as CSS_MEDIUM.)
  MediaList mediaList = mediaRule.getMedia();
  IStructuredDocumentRegion[] structuredDocumentRegions = structuredDocument.getStructuredDocumentRegions(
      mediaRuleRegion.getStartOffset(), mediaRuleRegion.getLength());

  // The value we set is a 0-length region starting where the next word would
  // have been
  ITextRegion textRegion = new ContextRegion(CSSRegionContexts.CSS_MEDIUM,
      structuredDocumentRegions[0].getEndOffset()
          - structuredDocumentRegions[0].getStartOffset(), 0, 0);

  try {
    callSetRangeRegion(mediaList, structuredDocumentRegions, textRegion);
  } catch (Throwable e) {
    GWTPluginLog.logError(e, "Could not clean up the @else in the CSS model.");
  }
}
 
源代码6 项目: FairEmail   文件: HtmlHelper.java
private static boolean isScreenMedia(MediaList media) {
    // https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
    // https://developers.google.com/gmail/design/reference/supported_css#supported_types
    if (media instanceof MediaListImpl) {
        MediaListImpl _media = (MediaListImpl) media;
        for (int i = 0; i < _media.getLength(); i++) {
            String query = _media.mediaQuery(i).getCssText(null);
            if ("all".equals(query) ||
                    "screen".equals(query) || "only screen".equals(query))
                return true;
        }
    } else
        Log.e("Media class=" + media.getClass().getName());
    return false;
}
 
源代码7 项目: HtmlUnit-Android   文件: MediaQueryList.java
/**
 * Returns whether the document currently matches the media query list or not.
 * @return whether the document currently matches the media query list or not
 */
@JsxGetter
public boolean isMatches() {
    final CSSErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler();
    final MediaList mediaList = CSSStyleSheet.parseMedia(errorHandler, media_);
    return CSSStyleSheet.isActive(this, mediaList);
}
 
源代码8 项目: HtmlUnit-Android   文件: StyleMedia.java
/**
 * Returns whether the specified media is supported by the object that displays the document object.
 * @param media the media query
 * @return whether the specified media is supported or not
 */
@JsxFunction
public boolean matchMedium(final String media) {
    final CSSErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler();
    final MediaList mediaList = CSSStyleSheet.parseMedia(errorHandler, media);
    return CSSStyleSheet.isActive(this, mediaList);
}
 
/**
 * Calls the {@link MediaList} <code>setRangeRegion</code> method.
 * 
 * @param mediaList the MediaList object that receives the call
 * @param structuredDocumentRegions the first parameter of the method
 * @param textRegion the second parameter of the method
 * @throws Throwable for safeguarding against any reflection issues (nothing
 *           is logged in this method since it doesn't have proper context of
 *           the scenario)
 */
private static void callSetRangeRegion(MediaList mediaList,
    IStructuredDocumentRegion[] structuredDocumentRegions,
    ITextRegion textRegion) throws Throwable {
  ClassLoader classLoader = CSSSourceFormatter.class.getClassLoader();
  Class<?> cssRegionContainerClass = classLoader.loadClass("org.eclipse.wst.css.core.internal.document.CSSRegionContainer");
  Method declaredMethod = cssRegionContainerClass.getDeclaredMethod(
      "setRangeRegion", IStructuredDocumentRegion.class, ITextRegion.class,
      ITextRegion.class);
  declaredMethod.setAccessible(true);
  declaredMethod.invoke(mediaList, structuredDocumentRegions[0], textRegion,
      textRegion);
}
 
/**
 * Calls the {@link MediaList} <code>setRangeRegion</code> method.
 * 
 * @param mediaList the MediaList object that receives the call
 * @param structuredDocumentRegions the first parameter of the method
 * @param textRegion the second parameter of the method
 * @throws Throwable for safeguarding against any reflection issues (nothing
 *           is logged in this method since it doesn't have proper context of
 *           the scenario)
 */
private static void callSetRangeRegion(MediaList mediaList,
    IStructuredDocumentRegion[] structuredDocumentRegions,
    ITextRegion textRegion) throws Throwable {
  ClassLoader classLoader = CSSSourceFormatter.class.getClassLoader();
  Class<?> cssRegionContainerClass = classLoader.loadClass("org.eclipse.wst.css.core.internal.document.CSSRegionContainer");
  Method declaredMethod = cssRegionContainerClass.getDeclaredMethod(
      "setRangeRegion", IStructuredDocumentRegion.class, ITextRegion.class,
      ITextRegion.class);
  declaredMethod.setAccessible(true);
  declaredMethod.invoke(mediaList, structuredDocumentRegions[0], textRegion,
      textRegion);
}
 
源代码11 项目: birt   文件: StyleSheet.java
public MediaList getMedia( )
{
	return null;
}
 
源代码12 项目: jdk1.8-source-analysis   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码13 项目: jdk1.8-source-analysis   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码14 项目: TencentKona-8   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码15 项目: TencentKona-8   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码16 项目: jdk8u60   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码17 项目: jdk8u60   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码18 项目: JDKSourceCode1.8   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码19 项目: JDKSourceCode1.8   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码20 项目: openjdk-jdk8u   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码21 项目: openjdk-jdk8u   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码22 项目: openjdk-jdk8u-backup   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码23 项目: openjdk-jdk8u-backup   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码24 项目: openjdk-jdk9   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码25 项目: openjdk-jdk9   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码26 项目: Java8CN   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码27 项目: Java8CN   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码28 项目: hottub   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
源代码29 项目: hottub   文件: CSSMediaRule.java
/**
 *  A list of media types for this rule.
 */
public MediaList getMedia();
 
源代码30 项目: openjdk-8-source   文件: CSSImportRule.java
/**
 *  A list of media types for which this style sheet may be used.
 */
public MediaList getMedia();
 
 类所在包
 同包方法