History | Edit

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:

  1. [OXYGEN_INSTALL_DIR]/frameworks/docbook/css/cals_table.css (Search for -oxy-visible-colspecs)
  2. The definition of action table.toggle.colspec from the DocBook framework makes use of the pre-defined TogglePseudoClassOperation Author mode operation.

Here are some examples:

Example: Controlling the visibility of a section using a pseudo-class

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.

Example: Coloring the elements at the current cursor location

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.
*:caret-visited {  
  color: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)

Predefined Pseudo-Class Author Mode Operations

Pre-defined Author mode operations can be used directly in your framework to work with custom pseudo-classes:
  1. TogglePseudoClassOperation
  2. SetPseudoClassOperation
  3. RemovePseudoClassOperation