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 readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { baseUri_ = (String) in.readObject(); cssRules_ = (CSSRuleList) in.readObject(); if (cssRules_ != null) { for (int i = 0; i < cssRules_.getLength(); i++) { final CSSRule cssRule = cssRules_.item(i); if (cssRule instanceof AbstractCSSRuleImpl) { ((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(this); } } } disabled_ = in.readBoolean(); href_ = (String) in.readObject(); media_ = (MediaList) in.readObject(); // TODO ownerNode may not be serializable! // ownerNode = (Node) in.readObject(); readOnly_ = in.readBoolean(); title_ = (String) in.readObject(); }
/** * {@inheritDoc} */ @Override public String getCssText(final CSSFormat format) { final StringBuilder sb = new StringBuilder(); sb.append("@import"); final String href = getHref(); if (null != href) { sb.append(" url(").append(href).append(")"); } final MediaList ml = getMedia(); if (null != ml && ml.getLength() > 0) { sb.append(" ").append(((MediaListImpl) getMedia()).getMediaText(format)); } sb.append(";"); return sb.toString(); }
/** * Matches media. * * @param mediaList * the media list * @param rcontext * the rcontext * @return true, if successful */ public static boolean matchesMedia(MediaList mediaList, UserAgentContext rcontext) { if (mediaList == null) { return true; } int length = mediaList.getLength(); if (length == 0) { return true; } if (rcontext == null) { return false; } for (int i = 0; i < length; i++) { String mediaName = mediaList.item(i); if (rcontext.isMedia(mediaName)) { return true; } } return false; }
/** * 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); }
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { cssRules_ = (CSSRuleList) in.readObject(); if (cssRules_ != null) { for (int i = 0; i < cssRules_.getLength(); i++) { final CSSRule cssRule = cssRules_.item(i); if (cssRule instanceof AbstractCSSRuleImpl) { ((AbstractCSSRuleImpl) cssRule).setParentRule(this); ((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(getParentStyleSheetImpl()); } } } media_ = (MediaList) in.readObject(); }
private boolean equalsMedia(final MediaList ml) { if ((ml == null) || (getLength() != ml.getLength())) { return false; } for (int i = 0; i < getLength(); i++) { final String m1 = item(i); final String m2 = ml.item(i); if (!LangUtils.equals(m1, m2)) { return false; } } return true; }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof MediaList)) { return false; } final MediaList ml = (MediaList) obj; return super.equals(obj) && equalsMedia(ml); }
public void setMedia(final MediaList media) { media_ = media; }
public CSSMediaRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final CSSRule parentRule, final MediaList media) { super(parentStyleSheet, parentRule); media_ = media; }
@Override public MediaList getMedia() { return media_; }
public CSSImportRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final CSSRule parentRule, final String href, final MediaList media) { super(parentStyleSheet, parentRule); href_ = href; media_ = media; }
public MediaList getMedia( ) { return null; }
public MediaList getMedia() { return new MediaListImpl(mediaRule.getMediaQueries(), this.containingStyleSheet); }
/** * @return A list of media to which this style sheet is applicable */ public MediaList getMedia() { return new MediaListImpl(mediaStr, this); }
public MediaList getMedia() { // TODO implement this method throw new UnsupportedOperationException(); }
/** * A list of media types for which this style sheet may be used. */ public MediaList getMedia();
/** * A list of media types for this rule. */ public MediaList getMedia();