You can set your custom CSS pseudo-classes on the nodes from the AuthorDocument model. These are similar to the normal XML attributes, with the important difference that they are not serialized, and by changing them the document does not create undo and redo edits - the document is considered unmodified. You can use custom pseudo-classes for changing the style of an element (and its children) without altering the document.
In Oxygen XML Editor they are used to hide/show the colspec elements from CALS tables. To take a look at the implementation, see:
Here are some examples:
You can use a non standard (custom) pseudo-class to impose a style change on a specific element. For instance you can have CSS styles matching the custom pseudo-class access-control-user, like the one below:
section {
display:none;
}
section:access-control-user {
display:block;
}
By setting the pseudo-class access-control-user, the element section will become visible by matching the second CSS selector.
*:caret-visited {
color:red;
}
You could create an AuthorCaretListener that sets the caret-visited pseudo-class to the element at the cursor location. The effect will be that all the elements traversed by the cursor become red.
The API that you can use from the CaretListener:
ro.sync.ecss.extensions.api.AuthorDocumentController#setPseudoClass(java.lang.String, ro.sync.ecss.extensions.api.node.AuthorElement) ro.sync.ecss.extensions.api.AuthorDocumentController#removePseudoClass(java.lang.String, ro.sync.ecss.extensions.api.node.AuthorElement)
Pre-defined Author mode operations can be used directly in your framework to work with custom pseudo-classes: