public class CascadingStylesheet extends java.lang.Object implements Stylesheet
The style of an element is determined following these steps:
addRule(Selector, Style)
),Element.getParentElement()
),setDefaultStyle(Style)
).Style
).
The result style is complete at the end of the resolution as long as the global style is complete (see
Style.isComplete()
).Constructor and Description |
---|
CascadingStylesheet()
Creates a new cascading stylesheet.
|
Modifier and Type | Method and Description |
---|---|
void |
addRule(Selector selector,
Style style)
Adds a rule: a style applied to the elements matching a selector.
|
Style |
getRuleStyle(Selector selector)
Gets the style associated with a selector.
|
Style |
getStyle(Element element)
Gets the style for the given element.
|
void |
removeRule(Selector selector)
Removes a rule associated with a selector.
|
void |
reset()
Resets the stylesheet to its initial state.
|
void |
resetDefaultStyle()
Resets the default style attributes to their initial value.
|
void |
setDefaultStyle(Style style)
Sets the default style.
|
public CascadingStylesheet()
public Style getStyle(Element element)
Stylesheet
This method should be called in the display thread to avoid concurrency issues.
getStyle
in interface Stylesheet
element
- the element to get the style for.public void setDefaultStyle(Style style)
Stylesheet
It will be used as the root style of the cascading resolution.
If the given style is not complete, only its set attributes override the ones in the current default style.
This method should be called in the display thread to avoid concurrency issues.
setDefaultStyle
in interface Stylesheet
style
- the style.public void resetDefaultStyle()
Stylesheet
This method should be called in the display thread to avoid concurrency issues.
resetDefaultStyle
in interface Stylesheet
public void addRule(Selector selector, Style style)
Stylesheet
If a rule already exists with the same selector, the styles are merged (the attributes of the new one override the attributes of the previous one).
This method should be called in the display thread to avoid concurrency issues.
addRule
in interface Stylesheet
selector
- the selector.style
- the style.public Style getRuleStyle(Selector selector)
Stylesheet
Any modification on the returned style will not affect the style in the stylesheet.
This method should be called in the display thread to avoid concurrency issues.
getRuleStyle
in interface Stylesheet
selector
- the selector.public void removeRule(Selector selector)
Stylesheet
This method should be called in the display thread to avoid concurrency issues.
removeRule
in interface Stylesheet
selector
- the selector.public void reset()
Stylesheet
This method should be called in the display thread to avoid concurrency issues.
reset
in interface Stylesheet