org.w3c.dom.stylesheets.MediaList Java Examples
The following examples show how to use
org.w3c.dom.stylesheets.MediaList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GssResourceAwareModelRepairer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
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."); } }
Example #2
Source File: CssResourceAwareModelRepairer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
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."); } }
Example #3
Source File: CSSStyleSheet.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * 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); }
Example #4
Source File: CSSStyleSheet.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * 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; }
Example #5
Source File: StyleSheetList.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * 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; }
Example #6
Source File: StyleMedia.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * 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); }
Example #7
Source File: GssResourceAwareModelRepairer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #8
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 5 votes |
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; }
Example #9
Source File: CssResourceAwareModelRepairer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #10
Source File: MediaQueryList.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * 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); }
Example #11
Source File: StyleSheet.java From birt with Eclipse Public License 1.0 | 4 votes |
public MediaList getMedia( ) { return null; }
Example #12
Source File: CSSImportRule.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #13
Source File: CSSMediaRule.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #14
Source File: CSSImportRule.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #15
Source File: CSSMediaRule.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #16
Source File: CSSImportRule.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #17
Source File: CSSMediaRule.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #18
Source File: CSSImportRule.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #19
Source File: CSSMediaRule.java From Java8CN with Apache License 2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #20
Source File: CSSImportRule.java From Java8CN with Apache License 2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #21
Source File: CSSMediaRule.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #22
Source File: CSSImportRule.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #23
Source File: CSSMediaRule.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #24
Source File: CSSImportRule.java From jdk1.8-source-analysis with Apache License 2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #25
Source File: CSSMediaRule.java From openjdk-jdk8u with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #26
Source File: CSSImportRule.java From openjdk-jdk8u with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #27
Source File: CSSMediaRule.java From JDKSourceCode1.8 with MIT License | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #28
Source File: CSSImportRule.java From JDKSourceCode1.8 with MIT License | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
Example #29
Source File: CSSMediaRule.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for this rule. */ public MediaList getMedia();
Example #30
Source File: CSSImportRule.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();