com.gargoylesoftware.htmlunit.javascript.host.css
Class CSSStyleSheet

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class CSSStyleSheet
extends SimpleScriptable

A JavaScript object for a Stylesheet.

Version:
$Revision: 7658 $
Author:
Marc Guillemot, Daniel Gredler, Ahmed Ashour
See Also:
MSDN doc, Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
CSSStyleSheet()
          Creates a new empty stylesheet.
CSSStyleSheet(HTMLElement element, org.w3c.dom.css.CSSStyleSheet wrapped, String uri)
          Creates a new stylesheet representing the specified CSS stylesheet.
CSSStyleSheet(HTMLElement element, org.w3c.css.sac.InputSource source, String uri)
          Creates a new stylesheet representing the CSS stylesheet for the specified input source.
 
Method Summary
 int addRule(String selector, String rule)
          Adds a new rule.
 void deleteRule(int position)
          Deletes an existing rule.
 CSSRuleList getCssRules()
          Returns the collection of rules defined in this style sheet.
 String getHref()
          Returns the URL of the stylesheet.
 HTMLElement getOwnerNode()
          For Firefox.
 HTMLElement getOwningElement()
          For Internet Explorer.
 CSSRuleList getRules()
          Retrieves the collection of rules defined in this style sheet.
 String getUri()
          Returns this stylesheet's URI (used to resolved contained @import rules).
 org.w3c.dom.css.CSSStyleSheet getWrappedSheet()
          Returns the wrapped stylesheet.
 int insertRule(String rule, int position)
          Inserts a new rule.
 boolean isActive()
          Returns true if this stylesheet is active, based on the media types it is associated with (if any).
static CSSStyleSheet loadStylesheet(Window window, HTMLElement element, HtmlLink link, String url)
          Loads the stylesheet at the specified link or href.
 void modifyIfNecessary(ComputedCSSStyleDeclaration style, Element element)
          Modifies the specified style object by adding any style rules which apply to the specified element.
 org.w3c.css.sac.SelectorList parseSelectors(org.w3c.css.sac.InputSource source)
          Parses the selectors at the specified input source.
 void removeRule(int position)
          Deletes an existing rule.
static boolean selects(BrowserVersion browserVersion, org.w3c.css.sac.Selector selector, DomElement element)
          Returns true if the specified selector selects the specified element.
static void validateSelectors(org.w3c.css.sac.SelectorList selectorList)
          Validates the list of selectors.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSSStyleSheet

public CSSStyleSheet()
Creates a new empty stylesheet.


CSSStyleSheet

public CSSStyleSheet(HTMLElement element,
                     org.w3c.css.sac.InputSource source,
                     String uri)
Creates a new stylesheet representing the CSS stylesheet for the specified input source.

Parameters:
element - the owning node
source - the input source which contains the CSS stylesheet which this stylesheet host object represents
uri - this stylesheet's URI (used to resolved contained @import rules)

CSSStyleSheet

public CSSStyleSheet(HTMLElement element,
                     org.w3c.dom.css.CSSStyleSheet wrapped,
                     String uri)
Creates a new stylesheet representing the specified CSS stylesheet.

Parameters:
element - the owning node
wrapped - the CSS stylesheet which this stylesheet host object represents
uri - this stylesheet's URI (used to resolved contained @import rules)
Method Detail

getWrappedSheet

public org.w3c.dom.css.CSSStyleSheet getWrappedSheet()
Returns the wrapped stylesheet.

Returns:
the wrapped stylesheet

modifyIfNecessary

public void modifyIfNecessary(ComputedCSSStyleDeclaration style,
                              Element element)
Modifies the specified style object by adding any style rules which apply to the specified element.

Parameters:
style - the style to modify
element - the element to which style rules must apply in order for them to be added to the specified style

loadStylesheet

public static CSSStyleSheet loadStylesheet(Window window,
                                           HTMLElement element,
                                           HtmlLink link,
                                           String url)
Loads the stylesheet at the specified link or href.

Parameters:
window - the current window
element - the parent DOM element
link - the stylesheet's link (may be null if an href is specified)
url - the stylesheet's url (may be null if a link is specified)
Returns:
the loaded stylesheet

selects

public static boolean selects(BrowserVersion browserVersion,
                              org.w3c.css.sac.Selector selector,
                              DomElement element)
Returns true if the specified selector selects the specified element.

Parameters:
browserVersion - the browser version
selector - the selector to test
element - the element to test
Returns:
true if it does apply, false if it doesn't apply

parseSelectors

public org.w3c.css.sac.SelectorList parseSelectors(org.w3c.css.sac.InputSource source)
Parses the selectors at the specified input source. If anything at all goes wrong, this method returns an empty selector list.

Parameters:
source - the source from which to retrieve the selectors to be parsed
Returns:
the selectors parsed from the specified input source

getOwnerNode

public HTMLElement getOwnerNode()
For Firefox.

Returns:
the owner

getOwningElement

public HTMLElement getOwningElement()
For Internet Explorer.

Returns:
the owner

getRules

public CSSRuleList getRules()
Retrieves the collection of rules defined in this style sheet.

Returns:
the collection of rules defined in this style sheet

getCssRules

public CSSRuleList getCssRules()
Returns the collection of rules defined in this style sheet.

Returns:
the collection of rules defined in this style sheet

getHref

public String getHref()
Returns the URL of the stylesheet.

Returns:
the URL of the stylesheet

insertRule

public int insertRule(String rule,
                      int position)
Inserts a new rule.

Parameters:
rule - the CSS rule
position - the position at which to insert the rule
Returns:
the position of the inserted rule
See Also:
DOM level 2

deleteRule

public void deleteRule(int position)
Deletes an existing rule.

Parameters:
position - the position of the rule to be deleted
See Also:
DOM level 2

addRule

public int addRule(String selector,
                   String rule)
Adds a new rule.

Parameters:
selector - the selector name
rule - the rule
Returns:
always return -1 as of MSDN documentation
See Also:
MSDN

removeRule

public void removeRule(int position)
Deletes an existing rule.

Parameters:
position - the position of the rule to be deleted
See Also:
MSDN

getUri

public String getUri()
Returns this stylesheet's URI (used to resolved contained @import rules).

Returns:
this stylesheet's URI (used to resolved contained @import rules)

isActive

public boolean isActive()
Returns true if this stylesheet is active, based on the media types it is associated with (if any).

Returns:
true if this stylesheet is active, based on the media types it is associated with (if any)

validateSelectors

public static void validateSelectors(org.w3c.css.sac.SelectorList selectorList)
                              throws org.w3c.css.sac.CSSException
Validates the list of selectors.

Parameters:
selectorList - the selectors
Throws:
org.w3c.css.sac.CSSException - if a selector is invalid


Copyright © 2002-2012 Gargoyle Software Inc.. All Rights Reserved.