/** * Computes a CSS {@link Value} and performance inheritance if the * specified value is 'inherit'. */ protected Value computeValue(CSSStylableElement elt, String pn, Value v) { ValueManager[] vms = cssEngine.getValueManagers(); int idx = cssEngine.getPropertyIndex(pn); if (idx != -1) { if (v.getCssValueType() == CSSValue.CSS_INHERIT) { elt = CSSEngine.getParentCSSStylableElement(elt); if (elt != null) { return cssEngine.getComputedStyle(elt, null, idx); } return vms[idx].getDefaultValue(); } v = vms[idx].computeValue(elt, null, cssEngine, idx, dummyStyleMap, v); } return v; } }
/** * Clears the view CSS. */ public void clearViewCSS() { defaultView = null; if (cssEngine != null) { cssEngine.dispose(); } cssEngine = null; }
/** * An auxiliary method for getStyleSheets(). */ protected void findStyleSheetNodes(Node n) { if (n instanceof CSSStyleSheetNode) { styleSheetNodes.add(n); } for (Node nd = getCSSFirstChild(n); nd != null; nd = getCSSNextSibling(nd)) { findStyleSheetNodes(nd); } }
/** * Handles a character data modification in the document. */ protected void handleCharacterDataModified(Node n) { if (getCSSParentNode(n) instanceof CSSStyleSheetNode) { // Invalidate all the CSSStylableElements in the document. styleSheetNodes = null; invalidateProperties(document.getDocumentElement(), null, null, true); } }
/** * Returns whether the given CSS property is available on this element. */ public boolean hasProperty(String pn) { AbstractStylableDocument doc = (AbstractStylableDocument) ownerDocument; CSSEngine eng = doc.getCSSEngine(); return eng.getPropertyIndex(pn) != -1 || eng.getShorthandIndex(pn) != -1; }
public CSSEngine createCSSEngine(AbstractStylableDocument doc, CSSContext ctx, ExtendedParser ep, ValueManager [] vms, ShorthandManager [] sms) { ParsedURL durl = ((SVGOMDocument)doc).getParsedURL(); CSSEngine result = new SVGCSSEngine(doc, durl, ep, vms, sms, ctx); URL url = getClass().getResource("resources/UserAgentStyleSheet.css"); if (url != null) { ParsedURL purl = new ParsedURL(url); InputSource is = new InputSource(purl.toString()); result.setUserAgentStyleSheet (result.parseStyleSheet(is, purl, "all")); } return result; }
/** * Returns whether the given CSS property is animatable. */ public boolean isPropertyAnimatable(String pn) { AbstractStylableDocument doc = (AbstractStylableDocument) ownerDocument; CSSEngine eng = doc.getCSSEngine(); int idx = eng.getPropertyIndex(pn); if (idx != -1) { ValueManager[] vms = eng.getValueManagers(); return vms[idx].isAnimatableProperty(); } idx = eng.getShorthandIndex(pn); if (idx != -1) { ShorthandManager[] sms = eng.getShorthandManagers(); return sms[idx].isAnimatableProperty(); } return false; }
/** * <b>DOM</b>: Implements {@link SVGElement#getViewportElement()}. */ public SVGElement getViewportElement() { for (Element e = CSSEngine.getParentCSSStylableElement(this); e != null; e = CSSEngine.getParentCSSStylableElement(e)) { if (e instanceof SVGFitToViewBox) { return (SVGElement)e; } } return null; }
/** * <b>DOM</b>: Implements {@link * org.w3c.dom.css.CSSStyleDeclaration#getPropertyValue(String)}. */ public String getPropertyValue(String propertyName) { int idx = cssEngine.getPropertyIndex(propertyName); if (idx == -1) { return ""; } Value v = cssEngine.getComputedStyle(element, pseudoElement, idx); return v.getCssText(); }
/** * Returns the type of the given property. */ public int getPropertyType(String pn) { AbstractStylableDocument doc = (AbstractStylableDocument) ownerDocument; CSSEngine eng = doc.getCSSEngine(); int idx = eng.getPropertyIndex(pn); if (idx != -1) { ValueManager[] vms = eng.getValueManagers(); return vms[idx].getPropertyType(); } return SVGTypes.TYPE_UNKNOWN; }
/** * Returns the Value associated with this object. */ public Value getValue() { return cssEngine.getComputedStyle(element, pseudoElement, index); } }
private static StyleSheet getUserAgentStyleSheet(CSSEngine engine) { if (defaultRules == null) { URL url = XhtmlCssEngine.class.getResource("default.css"); // TODO: reuse UserAgentStylesheet //URL url = null; // //try { // //url = new URL("file:" + System.getProperty("netbeans.home") + "/ua.css"); // NOI18N // url = new URL("file:/tmp/default.css"); // NOI18N //} catch (java.net.MalformedURLException mue) { // mue.printStackTrace(); //} if (url != null) { InputSource is = new InputSource(url.toString()); defaultRules = engine.parseStyleSheet(is, url, "all", url); defaultRules.setupFilters(); } } return defaultRules; }
/** * Implements {@link * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}. */ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { if (value == DEFAULT_VALUE) { CSSContext ctx = engine.getCSSContext(); value = ctx.getDefaultFontFamily(); } return value; } }
/** * Implements {@link * ValueManager#createStringValue(short,String,CSSEngine)}. */ public Value createStringValue(short type, String value, CSSEngine engine) throws DOMException { switch (type) { case CSSPrimitiveValue.CSS_IDENT: if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) { return ValueConstants.NONE_VALUE; } break; case CSSPrimitiveValue.CSS_URI: return new URIValue(value, resolveURI(engine.getCSSBaseURI(), value)); } throw createInvalidStringTypeDOMException(type); } }
protected void initCSSPropertyIndexes(Element e) { CSSEngine eng = CSSUtilities.getCSSEngine(e); marginTopIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY); marginRightIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY); marginBottomIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY); marginLeftIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY); indentIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_INDENT_PROPERTY); textAlignIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_TEXT_ALIGN_PROPERTY); lineHeightIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_LINE_HEIGHT_PROPERTY); }
public static String getStringProp(StyleMap sm, CSSEngine eng, int pidx) { Value v = sm.getValue(pidx); ValueManager [] vms = eng.getValueManagers(); if (v == null) { ValueManager vm = vms[pidx]; v = vm.getDefaultValue(); } while (v.getCssValueType() == CSSValue.CSS_VALUE_LIST) { v = v.item(0); } return v.getStringValue(); }
/** * Removes event listeners from the DOM and CSS engine. */ protected void removeDOMListeners() { SVGOMDocument doc = (SVGOMDocument)document; doc.removeEventListenerNS (XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMAttrModified", domAttrModifiedEventListener, true); doc.removeEventListenerNS (XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMNodeInserted", domNodeInsertedEventListener, true); doc.removeEventListenerNS (XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMNodeRemoved", domNodeRemovedEventListener, true); doc.removeEventListenerNS (XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMCharacterDataModified", domCharacterDataModifiedEventListener, true); doc.removeAnimatedAttributeListener(animatedAttributeListener); CSSEngine cssEngine = doc.getCSSEngine(); if (cssEngine != null) { cssEngine.removeCSSEngineListener (cssPropertiesChangedListener); cssEngine.dispose(); doc.setCSSEngine(null); } }
/** * Returns the document CSSStyleSheetNodes in a list. This list is * updated as the document is modified. */ public List getStyleSheetNodes() { if (styleSheetNodes == null) { styleSheetNodes = new ArrayList(); selectorAttributes = new HashSet(); // Find all the style-sheets in the document. findStyleSheetNodes(document); int len = styleSheetNodes.size(); for (Object styleSheetNode : styleSheetNodes) { CSSStyleSheetNode ssn; ssn = (CSSStyleSheetNode) styleSheetNode; StyleSheet ss = ssn.getCSSStyleSheet(); if (ss != null) { findSelectorAttributes(selectorAttributes, ss); } } } return styleSheetNodes; }
/** * Returns the next stylable parent of the given element. */ public static CSSStylableElement getParentCSSStylableElement(Element elt) { Node n = getCSSParentNode(elt); while (n != null) { if (n instanceof CSSStylableElement) { return (CSSStylableElement) n; } n = getCSSParentNode(n); } return null; }
protected void findStyleSheetNodes() { // <removing set/getRoot from RaveDocument> // Node root = ((RaveDocument)document).getRoot(); // findStyleSheetNodes(root); // ==== // XXX FIXME Here we need to work with the rendered HTML DOM directly, // there is no interest in the original JSP DOM. // FileObject markupFile = InSyncService.getProvider().getFileObject(document); // if (markupFile != null) { // DocumentFragment df = InSyncService.getProvider().getHtmlDomFragmentForMarkupFile(markupFile); // DocumentFragment df = InSyncService.getProvider().getHtmlDomFragmentForDocument(document); UserAgent userAgent = getUserAgent(); DocumentFragment df = userAgent == null ? null : userAgent.getHtmlDomFragmentForDocument(document); if (df != null) { findStyleSheetNodes(df); return; } // } // XXX Log problem? super.findStyleSheetNodes(); // <removing set/getRoot from RaveDocument> }