Interface StyleFormattingContext

All Superinterfaces:
DeclarationFormattingContext
All Known Implementing Classes:
DefaultStyleFormattingContext, InlineStyleFormattingContext

public interface StyleFormattingContext extends DeclarationFormattingContext
Define methods for style text formatting.

Different implementations of this interface can provide different style text formatting.

If the rule does not contain a style declaration (of either properties or descriptors), the methods in this interface are not called.

See Also:
  • Method Details

    • deepenCurrentContext

      void deepenCurrentContext()
      This auxiliary method can be used to deepen the indentation at places where the general serialization flow does not give the desired results.

      It is used only by the @font-feature-values rule.

    • endCurrentContext

      void endCurrentContext(CSSRule rule)
      Notify this context that the style was serialized for the given rule.

      It is called before endStyleDeclaration(SimpleWriter).

      Parameters:
      rule - the rule being serialized.
    • endInlinePropertyDeclaration

      void endInlinePropertyDeclaration(SimpleWriter wri) throws IOException
      End an inline property declaration.

      Called after DeclarationFormattingContext.writeSemiColon(SimpleWriter), only from inline styles.

      Parameters:
      wri - the writer to write to.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • endRule

      void endRule(SimpleWriter wri, List<String> trailingComments) throws IOException
      Ends the serialization of a rule.

      It is called after writeRightCurlyBracket(SimpleWriter).

      Parameters:
      wri - the writer to write to.
      trailingComments - the comments that go after the rule.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • endRuleList

      void endRuleList(SimpleWriter wri) throws IOException
      Called after a list of rules is serialized.

      May be used for indentation.

      Parameters:
      wri - the writer to write to.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • endStyleDeclaration

      void endStyleDeclaration(SimpleWriter wri) throws IOException
      End a style declaration.

      Called after endCurrentContext(CSSRule) and before writeRightCurlyBracket(SimpleWriter).

      Parameters:
      wri - the writer to write to.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • setParentContext

      void setParentContext(CSSRule rule)
      Sets the parent of the rule being serialized, if any, providing additional context for the serialization.

      It is called before startRule(SimpleWriter, List). However, this method being called does not guarantee that startRule() will be called.

      Parameters:
      rule - the parent rule. May be null.
    • startRule

      void startRule(SimpleWriter wri, List<String> precedingComments) throws IOException
      Starts the serialization of a rule.

      It is the first stage of the serialization of a rule. For example, in the case of style rules it is called before serializing the rule selector list. At-rules call it before writing the @-rule name.

      Parameters:
      wri - the writer to write to.
      precedingComments - the comments that precede the rule.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • startStyleDeclaration

      void startStyleDeclaration(SimpleWriter wri) throws IOException
      Start a style declaration (of either properties or descriptors).

      Called after writeLeftCurlyBracket(SimpleWriter) and before serializing the style declaration.

      Parameters:
      wri - the writer to write to.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • updateContext

      void updateContext(CSSRule rule)
      Update this context for the given rule.

      For style rules, it is called after serializing the selector list and before writeLeftCurlyBracket(SimpleWriter). At-rules call it after writing the rule name.

      May be used for indentation.

      Parameters:
      rule - the rule being serialized.
    • writeComment

      void writeComment(SimpleWriter wri, String comment) throws IOException
      Serialize a comment that precedes a rule, with the appropriate indent.

      Trailing comments are generally written directly by endRule(SimpleWriter, List) because no indent is necessary.

      Parameters:
      wri - the writer to write to.
      comment - the comment to serialize.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • writeImportantPriority

      void writeImportantPriority(SimpleWriter wri) throws IOException
      Serialize an important priority declaration to a SimpleWriter.

      If the property declaration has important priority, it is called after the value is written and before DeclarationFormattingContext.writeSemiColon(SimpleWriter).

      Parameters:
      wri - the writer.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • writeLeftCurlyBracket

      void writeLeftCurlyBracket(SimpleWriter wri) throws IOException
      Serialize a left curly bracket to a SimpleWriter.

      Called after updateContext(CSSRule) and before startStyleDeclaration(SimpleWriter).

      Parameters:
      wri - the writer.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • writeLevelIndent

      void writeLevelIndent(SimpleWriter wri) throws IOException
      Serialize one level of indentation to a SimpleWriter.
      Parameters:
      wri - the writer.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • writeRightCurlyBracket

      void writeRightCurlyBracket(SimpleWriter wri) throws IOException
      Serialize a right curly bracket to a SimpleWriter.

      Called after endStyleDeclaration(SimpleWriter) and before endRule(SimpleWriter, List).

      Parameters:
      wri - the writer.
      Throws:
      IOException - if an I/O problem happens while writing to the SimpleWriter.
    • writeShorthandValue

      default void writeShorthandValue(SimpleWriter wri, String shorthandName, CSSShorthandValue value) throws IOException
      Serialize a css shorthand value to the given writer.

      Although the CSSShorthandValue type contains priority information, this method only writes the value.

      The default implementation just writes CSSValue.getCssText().

      Parameters:
      wri - the writer.
      shorthandName - the name of the shorthand property whose value is being printed.
      value - the value to write.
      Throws:
      IOException - if an error happened while writing.