Skip to content

JDK and CSS #14

@scientificware

Description

@scientificware

Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g., fonts, colors, spacing) to Web documents.

The state of art

The state of art is defined by CSS Snapshots : The “CSS Snapshot” lists the parts that are ready for implementers.

These snapshots are references to CSS Modules :

Module Names Levels Comments
Syntax 3
Style Attributes
Media Queries
Conditional Rules
Selectors
Namespaces
Cascading and Inheritance
Values and Units
Custom Properties for Cascading Variables
Box Model 3
Color 4
▫️ Color ▶️ rgb and rgba functions 🚧
▫️ Color ▶️ hexadecimal 🚧
▫️ Color ▶️ hsl and hsla functions 🤔
▫️ Color ▶️ color function 🤔
Backgrounds and Borders
Images
Fonts
Writing Modes
Multi_column
Flexible Box
User Interface
Containment
Transforms
Compositing and Blending
Easing Functions
Counter Styles
...

JDK CSS Parser : (Documentation comments of CSSParser.java)

A CSS parser. This works by way of a delegate that implements the CSSParserCallback interface. The delegate is notified of the following events:

  • Import statement: handleImport
  • Selectors handleSelector. This is invoked for each string. For example if the Reader contained p, bar , a {}, the delegate would be notified 4 times, for 'p,' 'bar' ',' and 'a'.
  • When a rule starts, startRule
  • Properties in the rule via the handleProperty. This is invoked one per property/value key, eg font size: foo;, would cause the delegate to be notified once with a value of 'font size'.
  • Values in the rule via the handleValue, this is notified for the total value.
  • When a rule ends, endRule
This will parse much more than CSS 1, and loosely implements the recommendation for Forward-compatible parsing in section 7.1 of the CSS spec found at : http://www.w3.org/TR/REC-CSS1. If an error results in parsing, a RuntimeException will be thrown.

This will preserve case. If the callback wishes to treat certain portions case insensitively (such as selectors), it should use toLowerCase, or something similar.

Parsing something like the following :
(@rule | ruleset | block)*

Terminal Definition Comments
<@rule> ::= (<block> | <identifier>)*; (block with { } ends @rule)
<block> ::= `matching [] () {} (that is, [()] is a block, [(){}{[]}] is a block, ()[] is two blocks)
<identifier> ::= "*" | '*' | anything but a [](){} and whitespace
<ruleset> ::= <selector> <decblock>
<selector> ::= (<identifier> (<block>, except block '{}') )*
<declblock> ::= <declaration>* <block>*
<declaration> ::= (<identifier>* stopping when identifier ends with :) (<identifier>* stopping when identifier ends with ;)
<comments> ::= /* */ can appear any where, and are stripped.
<identifier> ::= - letters, digits, dashes and escaped characters
  • block starts with {, ends with matching },
  • () [] and {} always occur in matching pairs, ' ' and " " also occur in pairs, except " may be

Notes :

  • During the parsing process :
    • Leading and trailing white-spaces (according to Java) in the argument string were removed.
    • Inside () multiple white-space (according to Java) occurences are replaced by only one space character.
    • white-spaces (according to Java) between rgb or rgba and ( are removed.
  • Through WSRead() method, CSSParser.java strips white spaces.
  • White space according to Java, see Character Java specifications.
  • Trough parseDeclaration(), CSSParser.java make the property name to lower case.

JDK StyleSheet CSS Parser : (Documentation comments of StyleSheet.CssParser)

CssParser is the default parser for CSS specifications that get loaded into the StyleSheet.

Metadata

Metadata

Labels

DiscussionDiscussion about project development

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions